X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Favrf.c;h=8bbb616066ec6e8a25b08e72b2765c19f3dd352e;hp=fc67178b746510b0c93ce900b3176be3ea0e33c2;hb=42ef503d37b18d907da16d26e99167566d5aabd1;hpb=940703e16c523b74de2c7ed38f1c622289627ccc diff --git a/src/flash/avrf.c b/src/flash/avrf.c index fc67178b74..8bbb616066 100644 --- a/src/flash/avrf.c +++ b/src/flash/avrf.c @@ -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, + };