jtag_tap_t -> struct jtag_tap
[openocd.git] / src / flash / avrf.c
index fc67178b746510b0c93ce900b3176be3ea0e33c2..8bbb616066ec6e8a25b08e72b2765c19f3dd352e 100644 (file)
@@ -56,46 +56,18 @@ avrf_type_t avft_chips_info[] =
        {"atmega128",   0x9702,         256,                            512,                    8,                                      512},
 };
 
-static int avrf_register_commands(struct command_context_s *cmd_ctx);
-static int avrf_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
-static int avrf_erase(struct flash_bank_s *bank, int first, int last);
-static int avrf_protect(struct flash_bank_s *bank, int set, int first, int last);
-static int avrf_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t count);
-static int avrf_probe(struct flash_bank_s *bank);
-static int avrf_auto_probe(struct flash_bank_s *bank);
-//static int avrf_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-static int avrf_protect_check(struct flash_bank_s *bank);
-static int avrf_info(struct flash_bank_s *bank, char *buf, int buf_size);
-
-static int avrf_handle_mass_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-
-extern int avr_jtag_sendinstr(jtag_tap_t *tap, uint8_t *ir_in, uint8_t ir_out);
-extern int avr_jtag_senddat(jtag_tap_t *tap, uint32_t *dr_in, uint32_t dr_out, int len);
-
-extern int mcu_write_ir(jtag_tap_t *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti);
-extern int mcu_write_dr(jtag_tap_t *tap, uint8_t *ir_in, uint8_t *ir_out, int dr_len, int rti);
-extern int mcu_write_ir_u8(jtag_tap_t *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti);
-extern int mcu_write_dr_u8(jtag_tap_t *tap, uint8_t *ir_in, uint8_t ir_out, int dr_len, int rti);
-extern int mcu_write_ir_u16(jtag_tap_t *tap, uint16_t *ir_in, uint16_t ir_out, int ir_len, int rti);
-extern int mcu_write_dr_u16(jtag_tap_t *tap, uint16_t *ir_in, uint16_t ir_out, int dr_len, int rti);
-extern int mcu_write_ir_u32(jtag_tap_t *tap, uint32_t *ir_in, uint32_t ir_out, int ir_len, int rti);
-extern int mcu_write_dr_u32(jtag_tap_t *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len, int rti);
-extern int mcu_execute_queue(void);
-
-flash_driver_t avr_flash =
-{
-       .name = "avr",
-       .register_commands = avrf_register_commands,
-       .flash_bank_command = avrf_flash_bank_command,
-       .erase = avrf_erase,
-       .protect = avrf_protect,
-       .write = avrf_write,
-       .probe = avrf_probe,
-       .auto_probe = avrf_auto_probe,
-       .erase_check = default_flash_mem_blank_check,
-       .protect_check = avrf_protect_check,
-       .info = avrf_info
-};
+int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out);
+int avr_jtag_senddat(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out, int len);
+
+int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti);
+int mcu_write_dr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int dr_len, int rti);
+int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti);
+int mcu_write_dr_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int dr_len, int rti);
+int mcu_write_ir_u16(struct jtag_tap *tap, uint16_t *ir_in, uint16_t ir_out, int ir_len, int rti);
+int mcu_write_dr_u16(struct jtag_tap *tap, uint16_t *ir_in, uint16_t ir_out, int dr_len, int rti);
+int mcu_write_ir_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int ir_len, int rti);
+int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len, int rti);
+int mcu_execute_queue(void);
 
 /* avr program functions */
 static int avr_jtag_reset(avr_common_t *avr, uint32_t reset)
@@ -148,7 +120,7 @@ static int avr_jtagprg_chiperase(avr_common_t *avr)
        avr_jtag_senddat(avr->jtag_info.tap, NULL, 0x3380, AVR_JTAG_REG_ProgrammingCommand_Len);
        avr_jtag_senddat(avr->jtag_info.tap, NULL, 0x3380, AVR_JTAG_REG_ProgrammingCommand_Len);
 
-       do{
+       do {
                poll_value = 0;
                avr_jtag_senddat(avr->jtag_info.tap, &poll_value, 0x3380, AVR_JTAG_REG_ProgrammingCommand_Len);
                if (ERROR_OK != mcu_execute_queue())
@@ -156,7 +128,7 @@ static int avr_jtagprg_chiperase(avr_common_t *avr)
                        return ERROR_FAIL;
                }
                LOG_DEBUG("poll_value = 0x%04" PRIx32 "", poll_value);
-       }while(!(poll_value & 0x0200));
+       } while (!(poll_value & 0x0200));
 
        return ERROR_OK;
 }
@@ -195,7 +167,7 @@ static int avr_jtagprg_writeflashpage(avr_common_t *avr, uint8_t *page_buf, uint
        avr_jtag_senddat(avr->jtag_info.tap, NULL, 0x3700, AVR_JTAG_REG_ProgrammingCommand_Len);
        avr_jtag_senddat(avr->jtag_info.tap, NULL, 0x3700, AVR_JTAG_REG_ProgrammingCommand_Len);
 
-       do{
+       do {
                poll_value = 0;
                avr_jtag_senddat(avr->jtag_info.tap, &poll_value, 0x3700, AVR_JTAG_REG_ProgrammingCommand_Len);
                if (ERROR_OK != mcu_execute_queue())
@@ -203,23 +175,12 @@ static int avr_jtagprg_writeflashpage(avr_common_t *avr, uint8_t *page_buf, uint
                        return ERROR_FAIL;
                }
                LOG_DEBUG("poll_value = 0x%04" PRIx32 "", poll_value);
-       }while(!(poll_value & 0x0200));
+       } while (!(poll_value & 0x0200));
 
        return ERROR_OK;
 }
 
-/* interface command */
-static int avrf_register_commands(struct command_context_s *cmd_ctx)
-{
-       command_t *avr_cmd = register_command(cmd_ctx, NULL, "avr", NULL, COMMAND_ANY, "avr flash specific commands");
-
-       register_command(cmd_ctx, avr_cmd, "mass_erase", avrf_handle_mass_erase_command, COMMAND_EXEC,
-                                        "mass erase device");
-
-       return ERROR_OK;
-}
-
-static int avrf_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
+FLASH_BANK_COMMAND_HANDLER(avrf_flash_bank_command)
 {
        avrf_flash_bank_t *avrf_info;
 
@@ -277,7 +238,7 @@ static int avrf_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offse
        }
 
        cur_size = 0;
-       while(count > 0)
+       while (count > 0)
        {
                if (count > page_size)
                {
@@ -323,7 +284,7 @@ static int avrf_probe(struct flash_bank_s *bank)
                return ERROR_FAIL;
        }
 
-       LOG_INFO( "device id = 0x%08" PRIx32 "", device_id );
+       LOG_INFO("device id = 0x%08" PRIx32 "", device_id);
        if (EXTRACT_MFG(device_id) != 0x1F)
        {
                LOG_ERROR("0x%" PRIx32 " is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F);
@@ -402,7 +363,7 @@ static int avrf_info(struct flash_bank_s *bank, char *buf, int buf_size)
                return ERROR_FAIL;
        }
 
-       LOG_INFO( "device id = 0x%08" PRIx32 "", device_id );
+       LOG_INFO("device id = 0x%08" PRIx32 "", device_id);
        if (EXTRACT_MFG(device_id) != 0x1F)
        {
                LOG_ERROR("0x%" PRIx32 " is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F);
@@ -454,9 +415,8 @@ static int avrf_mass_erase(struct flash_bank_s *bank)
        return ERROR_OK;
 }
 
-static int avrf_handle_mass_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(avrf_handle_mass_erase_command)
 {
-       flash_bank_t *bank;
        int i;
 
        if (argc < 1)
@@ -465,12 +425,10 @@ static int avrf_handle_mass_erase_command(struct command_context_s *cmd_ctx, cha
                return ERROR_OK;
        }
 
-       bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
-       if (!bank)
-       {
-               command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
-               return ERROR_OK;
-       }
+       flash_bank_t *bank;
+       int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+       if (ERROR_OK != retval)
+               return retval;
 
        if (avrf_mass_erase(bank) == ERROR_OK)
        {
@@ -490,3 +448,29 @@ static int avrf_handle_mass_erase_command(struct command_context_s *cmd_ctx, cha
        LOG_DEBUG("%s", __FUNCTION__);
        return ERROR_OK;
 }
+
+static int avrf_register_commands(struct command_context_s *cmd_ctx)
+{
+       command_t *avr_cmd = register_command(cmd_ctx, NULL, "avr",
+                       NULL, COMMAND_ANY, "avr flash specific commands");
+
+       register_command(cmd_ctx, avr_cmd, "mass_erase",
+                       avrf_handle_mass_erase_command, COMMAND_EXEC,
+                       "mass erase device");
+
+       return ERROR_OK;
+}
+
+flash_driver_t avr_flash = {
+               .name = "avr",
+               .register_commands = &avrf_register_commands,
+               .flash_bank_command = &avrf_flash_bank_command,
+               .erase = &avrf_erase,
+               .protect = &avrf_protect,
+               .write = &avrf_write,
+               .probe = &avrf_probe,
+               .auto_probe = &avrf_auto_probe,
+               .erase_check = &default_flash_mem_blank_check,
+               .protect_check = &avrf_protect_check,
+               .info = &avrf_info,
+       };

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)