X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Favrf.c;h=b0459093325f142402d515b6354bc781e5402090;hp=fa0df1f17e40739a2d8c0a2c1228f98010f77ff5;hb=712d3fc0fb3ed69342a649d8bbb0d6d901a64720;hpb=310be8a838c9db6b67bc4d6d7d3c7ff41b32af4c diff --git a/src/flash/avrf.c b/src/flash/avrf.c index fa0df1f17e..b045909332 100644 --- a/src/flash/avrf.c +++ b/src/flash/avrf.c @@ -56,49 +56,21 @@ 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, u32 offset, u32 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, u32 *dr_in, u32 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, u16 *ir_in, u16 ir_out, int ir_len, int rti); -extern int mcu_write_dr_u16(jtag_tap_t *tap, u16 *ir_in, u16 ir_out, int dr_len, int rti); -extern int mcu_write_ir_u32(jtag_tap_t *tap, u32 *ir_in, u32 ir_out, int ir_len, int rti); -extern int mcu_write_dr_u32(jtag_tap_t *tap, u32 *ir_in, u32 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(jtag_tap_t *tap, uint8_t *ir_in, uint8_t ir_out); +int avr_jtag_senddat(jtag_tap_t *tap, uint32_t *dr_in, uint32_t dr_out, int len); + +int mcu_write_ir(jtag_tap_t *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti); +int mcu_write_dr(jtag_tap_t *tap, uint8_t *ir_in, uint8_t *ir_out, int dr_len, int rti); +int mcu_write_ir_u8(jtag_tap_t *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti); +int mcu_write_dr_u8(jtag_tap_t *tap, uint8_t *ir_in, uint8_t ir_out, int dr_len, int rti); +int mcu_write_ir_u16(jtag_tap_t *tap, uint16_t *ir_in, uint16_t ir_out, int ir_len, int rti); +int mcu_write_dr_u16(jtag_tap_t *tap, uint16_t *ir_in, uint16_t ir_out, int dr_len, int rti); +int mcu_write_ir_u32(jtag_tap_t *tap, uint32_t *ir_in, uint32_t ir_out, int ir_len, int rti); +int mcu_write_dr_u32(jtag_tap_t *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, u32 reset) +static int avr_jtag_reset(avr_common_t *avr, uint32_t reset) { avr_jtag_sendinstr(avr->jtag_info.tap, NULL, AVR_JTAG_INS_AVR_RESET); avr_jtag_senddat(avr->jtag_info.tap, NULL, reset ,AVR_JTAG_REG_Reset_Len); @@ -106,7 +78,7 @@ static int avr_jtag_reset(avr_common_t *avr, u32 reset) return ERROR_OK; } -static int avr_jtag_read_jtagid(avr_common_t *avr, u32 *id) +static int avr_jtag_read_jtagid(avr_common_t *avr, uint32_t *id) { avr_jtag_sendinstr(avr->jtag_info.tap, NULL, AVR_JTAG_INS_IDCODE); avr_jtag_senddat(avr->jtag_info.tap, id, 0, AVR_JTAG_REG_JTAGID_Len); @@ -140,7 +112,7 @@ static int avr_jtagprg_leaveprogmode(avr_common_t *avr) static int avr_jtagprg_chiperase(avr_common_t *avr) { - u32 poll_value; + uint32_t poll_value; avr_jtag_sendinstr(avr->jtag_info.tap, NULL, AVR_JTAG_INS_PROG_COMMANDS); avr_jtag_senddat(avr->jtag_info.tap, NULL, 0x2380, AVR_JTAG_REG_ProgrammingCommand_Len); @@ -148,22 +120,22 @@ 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()) { return ERROR_FAIL; } - LOG_DEBUG("poll_value = 0x%04X", poll_value); - }while(!(poll_value & 0x0200)); + LOG_DEBUG("poll_value = 0x%04" PRIx32 "", poll_value); + } while (!(poll_value & 0x0200)); return ERROR_OK; } -static int avr_jtagprg_writeflashpage(avr_common_t *avr, uint8_t *page_buf, u32 buf_size, u32 addr, u32 page_size) +static int avr_jtagprg_writeflashpage(avr_common_t *avr, uint8_t *page_buf, uint32_t buf_size, uint32_t addr, uint32_t page_size) { - u32 i, poll_value; + uint32_t i, poll_value; avr_jtag_sendinstr(avr->jtag_info.tap, NULL, AVR_JTAG_INS_PROG_COMMANDS); avr_jtag_senddat(avr->jtag_info.tap, NULL, 0x2310, AVR_JTAG_REG_ProgrammingCommand_Len); @@ -195,26 +167,15 @@ static int avr_jtagprg_writeflashpage(avr_common_t *avr, uint8_t *page_buf, u32 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()) { return ERROR_FAIL; } - LOG_DEBUG("poll_value = 0x%04X", poll_value); - }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"); + LOG_DEBUG("poll_value = 0x%04" PRIx32 "", poll_value); + } while (!(poll_value & 0x0200)); return ERROR_OK; } @@ -249,11 +210,11 @@ static int avrf_protect(struct flash_bank_s *bank, int set, int first, int last) return ERROR_OK; } -static int avrf_write(struct flash_bank_s *bank, uint8_t *buffer, u32 offset, u32 count) +static int avrf_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t count) { target_t *target = bank->target; avr_common_t *avr = target->arch_info; - u32 cur_size, cur_buffer_size, page_size; + uint32_t cur_size, cur_buffer_size, page_size; if (bank->target->state != TARGET_HALTED) { @@ -264,12 +225,12 @@ static int avrf_write(struct flash_bank_s *bank, uint8_t *buffer, u32 offset, u3 page_size = bank->sectors[0].size; if ((offset % page_size) != 0) { - LOG_WARNING("offset 0x%x breaks required %d-byte alignment", offset, page_size); + LOG_WARNING("offset 0x%" PRIx32 " breaks required %" PRIu32 "-byte alignment", offset, page_size); return ERROR_FLASH_DST_BREAKS_ALIGNMENT; } - LOG_DEBUG("offset is 0x%08X", offset); - LOG_DEBUG("count is %d", count); + LOG_DEBUG("offset is 0x%08" PRIx32 "", offset); + LOG_DEBUG("count is %" PRId32 "", count); if (ERROR_OK != avr_jtagprg_enterprogmode(avr)) { @@ -277,7 +238,7 @@ static int avrf_write(struct flash_bank_s *bank, uint8_t *buffer, u32 offset, u3 } cur_size = 0; - while(count > 0) + while (count > 0) { if (count > page_size) { @@ -307,7 +268,7 @@ static int avrf_probe(struct flash_bank_s *bank) avr_common_t *avr = target->arch_info; avrf_type_t *avr_info = NULL; int i; - u32 device_id; + uint32_t device_id; if (bank->target->state != TARGET_HALTED) { @@ -323,10 +284,10 @@ static int avrf_probe(struct flash_bank_s *bank) return ERROR_FAIL; } - LOG_INFO( "device id = 0x%08x", device_id ); + LOG_INFO("device id = 0x%08" PRIx32 "", device_id); if (EXTRACT_MFG(device_id) != 0x1F) { - LOG_ERROR("0x%X is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F); + LOG_ERROR("0x%" PRIx32 " is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F); } for (i = 0; i < (int)(sizeof(avft_chips_info) / sizeof(avft_chips_info[0])); i++) @@ -361,7 +322,7 @@ static int avrf_probe(struct flash_bank_s *bank) else { // chip not supported - LOG_ERROR("0x%X is not support for avr", EXTRACT_PART(device_id)); + LOG_ERROR("0x%" PRIx32 " is not support for avr", EXTRACT_PART(device_id)); avrf_info->probed = 1; return ERROR_FAIL; @@ -388,7 +349,7 @@ static int avrf_info(struct flash_bank_s *bank, char *buf, int buf_size) avr_common_t *avr = target->arch_info; avrf_type_t *avr_info = NULL; int i; - u32 device_id; + uint32_t device_id; if (bank->target->state != TARGET_HALTED) { @@ -402,10 +363,10 @@ static int avrf_info(struct flash_bank_s *bank, char *buf, int buf_size) return ERROR_FAIL; } - LOG_INFO( "device id = 0x%08x", device_id ); + LOG_INFO("device id = 0x%08" PRIx32 "", device_id); if (EXTRACT_MFG(device_id) != 0x1F) { - LOG_ERROR("0x%X is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F); + LOG_ERROR("0x%" PRIx32 " is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F); } for (i = 0; i < (int)(sizeof(avft_chips_info) / sizeof(avft_chips_info[0])); i++) @@ -422,7 +383,7 @@ static int avrf_info(struct flash_bank_s *bank, char *buf, int buf_size) if (avr_info != NULL) { // chip found - snprintf(buf, buf_size, "%s - Rev: 0x%X", avr_info->name, EXTRACT_VER(device_id)); + snprintf(buf, buf_size, "%s - Rev: 0x%" PRIx32 "", avr_info->name, EXTRACT_VER(device_id)); return ERROR_OK; } else @@ -456,7 +417,6 @@ static int avrf_mass_erase(struct flash_bank_s *bank) static int avrf_handle_mass_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - 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, + };