X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fflash%2Fmflash.c;h=bf759c97ab57527fd851664262bbf682bb8cfe4e;hb=111b7a6a9dbd68c906b8a8dff6e6c34d780297db;hp=cfcb8ec63cfa8be47ad8e01151eee9781ec070c3;hpb=dc575dc5bf8cb597a0e9a47794744ae6b1928087;p=openocd diff --git a/src/flash/mflash.c b/src/flash/mflash.c index cfcb8ec6..bf759c97 100644 --- a/src/flash/mflash.c +++ b/src/flash/mflash.c @@ -474,8 +474,8 @@ static int mg_mflash_read_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt residue = sect_cnt % 256; for (i = 0; i < quotient; i++) { - LOG_DEBUG("mflash: sect num : %" PRIu32 " buff : 0x%0lx", sect_num, - (unsigned long)buff_ptr); + LOG_DEBUG("mflash: sect num : %" PRIu32 " buff : %p", + sect_num, buff_ptr); ret = mg_mflash_do_read_sects(buff_ptr, sect_num, 256); if (ret != ERROR_OK) return ret; @@ -485,8 +485,8 @@ static int mg_mflash_read_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt } if (residue) { - LOG_DEBUG("mflash: sect num : %" PRIx32 " buff : %0lx", sect_num, - (unsigned long)buff_ptr); + LOG_DEBUG("mflash: sect num : %" PRIx32 " buff : %p", + sect_num, buff_ptr); return mg_mflash_do_read_sects(buff_ptr, sect_num, residue); } @@ -517,7 +517,7 @@ static int mg_mflash_do_write_sects(void *buff, uint32_t sect_num, uint32_t sect ret = target_write_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr); if (ret != ERROR_OK) return ret; - + buff_ptr += MG_MFLASH_SECTOR_SIZE; ret = target_write_u8(target, mflash_bank->base + MG_REG_OFFSET + MG_REG_COMMAND, mg_io_cmd_confirm_write); @@ -552,7 +552,7 @@ static int mg_mflash_write_sects(void *buff, uint32_t sect_num, uint32_t sect_cn residue = sect_cnt % 256; for (i = 0; i < quotient; i++) { - LOG_DEBUG("mflash: sect num : %" PRIu32 "buff : %p", sect_num, + LOG_DEBUG("mflash: sect num : %" PRIu32 "buff : %p", sect_num, buff_ptr); ret = mg_mflash_do_write_sects(buff_ptr, sect_num, 256, mg_io_cmd_write); if (ret != ERROR_OK) @@ -563,7 +563,7 @@ static int mg_mflash_write_sects(void *buff, uint32_t sect_num, uint32_t sect_cn } if (residue) { - LOG_DEBUG("mflash: sect num : %" PRIu32 " buff : %p", sect_num, + LOG_DEBUG("mflash: sect num : %" PRIu32 " buff : %p", sect_num, buff_ptr); return mg_mflash_do_write_sects(buff_ptr, sect_num, residue, mg_io_cmd_write); } @@ -716,7 +716,7 @@ static int mg_write_cmd(struct command_context_s *cmd_ctx, char *cmd, char **arg return ERROR_COMMAND_SYNTAX_ERROR; } - address = strtoul(args[2], NULL, 0); + COMMAND_PARSE_NUMBER(u32, args[2], address); ret = fileio_open(&fileio, args[1], FILEIO_READ, FILEIO_BINARY); if (ret != ERROR_OK) @@ -741,10 +741,10 @@ static int mg_write_cmd(struct command_context_s *cmd_ctx, char *cmd, char **arg goto mg_write_cmd_err; address += MG_FILEIO_CHUNK; } - + if (res) { if ((ret = fileio_read(&fileio, res, buffer, &buf_cnt)) != ERROR_OK) - goto mg_write_cmd_err; + goto mg_write_cmd_err; if ((ret = mg_mflash_write(address, buffer, res)) != ERROR_OK) goto mg_write_cmd_err; } @@ -783,13 +783,13 @@ static int mg_dump_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args return ERROR_COMMAND_SYNTAX_ERROR; } - address = strtoul(args[2], NULL, 0); - size = strtoul(args[3], NULL, 0); + COMMAND_PARSE_NUMBER(u32, args[2], address); + COMMAND_PARSE_NUMBER(u32, args[3], size); ret = fileio_open(&fileio, args[1], FILEIO_WRITE, FILEIO_BINARY); if (ret != ERROR_OK) return ret; - + buffer = malloc(MG_FILEIO_CHUNK); if (!buffer) { fileio_close(&fileio); @@ -798,7 +798,7 @@ static int mg_dump_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args cnt = size / MG_FILEIO_CHUNK; res = size % MG_FILEIO_CHUNK; - + duration_start_measure(&duration); for (i = 0; i < cnt; i++) { @@ -809,7 +809,7 @@ static int mg_dump_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args goto mg_dump_cmd_err; address += MG_FILEIO_CHUNK; } - + if (res) { if ((ret = mg_mflash_read(address, buffer, res)) != ERROR_OK) goto mg_dump_cmd_err; @@ -834,8 +834,8 @@ mg_dump_cmd_err: free(duration_text); free(buffer); fileio_close(&fileio); - - return ret; + + return ret; } static int mg_set_feature(mg_feature_id feature, mg_feature_val config) @@ -1229,7 +1229,7 @@ int mg_config_cmd(struct command_context_s *cmd_ctx, char *cmd, switch (argc) { case 2: - if (!strcmp(args[1], "boot")) + if (!strcmp(args[1], "boot")) return mg_boot_config(); else if (!strcmp(args[1], "storage")) return mg_storage_config(); @@ -1238,7 +1238,9 @@ int mg_config_cmd(struct command_context_s *cmd_ctx, char *cmd, break; case 3: if (!strcmp(args[1], "pll")) { - fin = strtoul(args[2], NULL, 0); + unsigned long freq; + COMMAND_PARSE_NUMBER(ulong, args[2], freq); + fin = freq; if (fin > MG_PLL_CLK_OUT) { LOG_ERROR("mflash: input freq. is too large"); @@ -1252,7 +1254,7 @@ int mg_config_cmd(struct command_context_s *cmd_ctx, char *cmd, return ERROR_MG_INVALID_PLL; } - LOG_INFO("mflash: Fout=%" PRIu32 " Hz, feedback=%u," + LOG_INFO("mflash: Fout=%" PRIu32 " Hz, feedback=%u," "indiv=%u, outdiv=%u, lock=%u", (uint32_t)fout, pll.feedback_div, pll.input_div, pll.output_div, @@ -1288,7 +1290,6 @@ int mflash_init_drivers(struct command_context_s *cmd_ctx) static int mg_bank_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { target_t *target; - char *str; int i; if (argc < 4) @@ -1303,7 +1304,9 @@ static int mg_bank_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args } mflash_bank = calloc(sizeof(mflash_bank_t), 1); - mflash_bank->base = strtoul(args[1], NULL, 0); + COMMAND_PARSE_NUMBER(u32, args[1], mflash_bank->base); + /// @todo Verify how this parsing should work, then document it. + char *str; mflash_bank->rst_pin.num = strtoul(args[2], &str, 0); if (*str) mflash_bank->rst_pin.port[0] = (uint16_t)tolower(str[0]);