X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fflash%2Fnor%2Fambiqmicro.c;h=162e1bb789c63e2b72b3ad2565f0ad7194998b83;hb=3d135a5c70db67ed13cc93eeab0b700f6ef8a412;hp=1e2a4b176ca460ab3b959fb17ce0aa145a9260f5;hpb=ef14384b681af4f731f768bb866457832af6925f;p=openocd.git diff --git a/src/flash/nor/ambiqmicro.c b/src/flash/nor/ambiqmicro.c index 1e2a4b176c..162e1bb789 100644 --- a/src/flash/nor/ambiqmicro.c +++ b/src/flash/nor/ambiqmicro.c @@ -92,7 +92,7 @@ static const uint32_t apollo_sram_size[] = { struct ambiqmicro_flash_bank { /* chip id register */ - uint32_t probed; + bool probed; const char *target_name; uint8_t target_class; @@ -123,7 +123,7 @@ static struct { uint8_t class; uint8_t partno; const char *partname; -} ambiqmicroParts[6] = { +} ambiqmicro_parts[6] = { {0xFF, 0x00, "Unknown"}, {0x01, 0x00, "Apollo"}, {0x02, 0x00, "Apollo2"}, @@ -132,7 +132,7 @@ static struct { {0x05, 0x00, "Apollo"}, }; -static char *ambiqmicroClassname[6] = { +static char *ambiqmicro_classname[6] = { "Unknown", "Apollo", "Apollo2", "Unknown", "Unknown", "Apollo" }; @@ -156,38 +156,33 @@ FLASH_BANK_COMMAND_HANDLER(ambiqmicro_flash_bank_command) ambiqmicro_info->target_name = "Unknown target"; /* part wasn't probed yet */ - ambiqmicro_info->probed = 0; + ambiqmicro_info->probed = false; return ERROR_OK; } -static int get_ambiqmicro_info(struct flash_bank *bank, char *buf, int buf_size) +static int get_ambiqmicro_info(struct flash_bank *bank, struct command_invocation *cmd) { struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv; - int printed; char *classname; - if (ambiqmicro_info->probed == 0) { + if (!ambiqmicro_info->probed) { LOG_ERROR("Target not probed"); return ERROR_FLASH_BANK_NOT_PROBED; } /* Check class name in range. */ - if (ambiqmicro_info->target_class < sizeof(ambiqmicroClassname)) - classname = ambiqmicroClassname[ambiqmicro_info->target_class]; + if (ambiqmicro_info->target_class < sizeof(ambiqmicro_classname)) + classname = ambiqmicro_classname[ambiqmicro_info->target_class]; else - classname = ambiqmicroClassname[0]; + classname = ambiqmicro_classname[0]; - printed = snprintf(buf, - buf_size, - "\nAmbiq Micro information: Chip is " + command_print_sameline(cmd, "\nAmbiq Micro information: Chip is " "class %d (%s) %s\n", ambiqmicro_info->target_class, classname, ambiqmicro_info->target_name); - if ((printed < 0)) - return ERROR_BUF_TOO_SMALL; return ERROR_OK; } @@ -200,24 +195,24 @@ static int ambiqmicro_read_part_info(struct flash_bank *bank) { struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv; struct target *target = bank->target; - uint32_t PartNum = 0; + uint32_t part_num = 0; int retval; /* * Read Part Number. */ - retval = target_read_u32(target, 0x40020000, &PartNum); + retval = target_read_u32(target, 0x40020000, &part_num); if (retval != ERROR_OK) { - LOG_ERROR("status(0x%x):Could not read PartNum.\n", retval); - /* Set PartNum to default device */ - PartNum = 0; + LOG_ERROR("status(0x%x):Could not read part_num.\n", retval); + /* Set part_num to default device */ + part_num = 0; } - LOG_DEBUG("Part number: 0x%x", PartNum); + LOG_DEBUG("Part number: 0x%" PRIx32, part_num); /* * Determine device class. */ - ambiqmicro_info->target_class = (PartNum & 0xFF000000) >> 24; + ambiqmicro_info->target_class = (part_num & 0xFF000000) >> 24; switch (ambiqmicro_info->target_class) { case 1: /* 1 - Apollo */ @@ -225,9 +220,9 @@ static int ambiqmicro_read_part_info(struct flash_bank *bank) bank->base = bank->bank_number * 0x40000; ambiqmicro_info->pagesize = 2048; ambiqmicro_info->flshsiz = - apollo_flash_size[(PartNum & 0x00F00000) >> 20]; + apollo_flash_size[(part_num & 0x00F00000) >> 20]; ambiqmicro_info->sramsiz = - apollo_sram_size[(PartNum & 0x000F0000) >> 16]; + apollo_sram_size[(part_num & 0x000F0000) >> 16]; ambiqmicro_info->num_pages = ambiqmicro_info->flshsiz / ambiqmicro_info->pagesize; if (ambiqmicro_info->num_pages > 128) { @@ -253,14 +248,14 @@ static int ambiqmicro_read_part_info(struct flash_bank *bank) } - if (ambiqmicro_info->target_class < ARRAY_SIZE(ambiqmicroParts)) + if (ambiqmicro_info->target_class < ARRAY_SIZE(ambiqmicro_parts)) ambiqmicro_info->target_name = - ambiqmicroParts[ambiqmicro_info->target_class].partname; + ambiqmicro_parts[ambiqmicro_info->target_class].partname; else ambiqmicro_info->target_name = - ambiqmicroParts[0].partname; + ambiqmicro_parts[0].partname; - LOG_DEBUG("num_pages: %d, pagesize: %d, flash: %d, sram: %d", + LOG_DEBUG("num_pages: %" PRIu32 ", pagesize: %" PRIu32 ", flash: %" PRIu32 ", sram: %" PRIu32, ambiqmicro_info->num_pages, ambiqmicro_info->pagesize, ambiqmicro_info->flshsiz, @@ -280,7 +275,7 @@ static int ambiqmicro_protect_check(struct flash_bank *bank) uint32_t i; - if (ambiqmicro->probed == 0) { + if (!ambiqmicro->probed) { LOG_ERROR("Target not probed"); return ERROR_FLASH_BANK_NOT_PROBED; } @@ -304,7 +299,7 @@ static int check_flash_status(struct target *target, uint32_t address) } /* target flash failed, unknown cause. */ if (retflash != 0) { - LOG_ERROR("Flash not happy: status(0x%x)", retflash); + LOG_ERROR("Flash not happy: status(0x%" PRIx32 ")", retflash); return ERROR_FLASH_OPERATION_FAILED; } return ERROR_OK; @@ -371,7 +366,7 @@ static int ambiqmicro_mass_erase(struct flash_bank *bank) return ERROR_TARGET_NOT_HALTED; } - if (ambiqmicro_info->probed == 0) { + if (!ambiqmicro_info->probed) { LOG_ERROR("Target not probed"); return ERROR_FLASH_BANK_NOT_PROBED; } @@ -432,14 +427,14 @@ static int ambiqmicro_erase(struct flash_bank *bank, unsigned int first, { struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv; struct target *target = bank->target; - uint32_t retval = ERROR_OK; + int retval; if (bank->target->state != TARGET_HALTED) { LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; } - if (ambiqmicro_info->probed == 0) { + if (!ambiqmicro_info->probed) { LOG_ERROR("Target not probed"); return ERROR_FLASH_BANK_NOT_PROBED; } @@ -615,7 +610,7 @@ static int ambiqmicro_write_block(struct flash_bank *bank, break; } - LOG_DEBUG("address = 0x%08x", address); + LOG_DEBUG("address = 0x%08" PRIx32, address); retval = ambiqmicro_exec_command(target, FLASH_PROGRAM_MAIN_FROM_SRAM, 0x1000000c); CHECK_STATUS(retval, "error executing ambiqmicro flash write algorithm"); @@ -641,7 +636,7 @@ static int ambiqmicro_write_block(struct flash_bank *bank, static int ambiqmicro_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { - uint32_t retval; + int retval; /* try using a block write */ retval = ambiqmicro_write_block(bank, buffer, offset, count); @@ -654,12 +649,12 @@ static int ambiqmicro_write(struct flash_bank *bank, const uint8_t *buffer, static int ambiqmicro_probe(struct flash_bank *bank) { struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv; - uint32_t retval; + int retval; /* If this is a ambiqmicro chip, it has flash; probe() is just * to figure out how much is present. Only do it once. */ - if (ambiqmicro_info->probed == 1) { + if (ambiqmicro_info->probed) { LOG_INFO("Target already probed"); return ERROR_OK; } @@ -672,10 +667,7 @@ static int ambiqmicro_probe(struct flash_bank *bank) if (retval != ERROR_OK) return retval; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); /* provide this for the benefit of the NOR flash framework */ bank->size = ambiqmicro_info->pagesize * ambiqmicro_info->num_pages; @@ -691,7 +683,7 @@ static int ambiqmicro_probe(struct flash_bank *bank) /* * Part has been probed. */ - ambiqmicro_info->probed = 1; + ambiqmicro_info->probed = true; return retval; } @@ -701,7 +693,7 @@ static int ambiqmicro_otp_program(struct flash_bank *bank, { struct target *target = NULL; struct ambiqmicro_flash_bank *ambiqmicro_info = NULL; - uint32_t retval = ERROR_OK; + int retval; ambiqmicro_info = bank->driver_priv; target = bank->target; @@ -711,7 +703,7 @@ static int ambiqmicro_otp_program(struct flash_bank *bank, return ERROR_TARGET_NOT_HALTED; } - if (ambiqmicro_info->probed == 0) { + if (!ambiqmicro_info->probed) { LOG_ERROR("Target not probed"); return ERROR_FLASH_BANK_NOT_PROBED; } @@ -760,7 +752,7 @@ static int ambiqmicro_otp_program(struct flash_bank *bank, /* * Program OTP. */ - LOG_INFO("Programming OTP offset 0x%08x", offset); + LOG_INFO("Programming OTP offset 0x%08" PRIx32, offset); /* * passed pc, addr = ROM function, handle breakpoints, not debugging. @@ -781,7 +773,7 @@ COMMAND_HANDLER(ambiqmicro_handle_mass_erase_command) return ERROR_COMMAND_SYNTAX_ERROR; struct flash_bank *bank; - uint32_t retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); + int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); if (ERROR_OK != retval) return retval; @@ -801,7 +793,7 @@ COMMAND_HANDLER(ambiqmicro_handle_page_erase_command) { struct flash_bank *bank; uint32_t first, last; - uint32_t retval; + int retval; if (CMD_ARGC < 3) return ERROR_COMMAND_SYNTAX_ERROR; @@ -829,7 +821,7 @@ COMMAND_HANDLER(ambiqmicro_handle_program_otp_command) { struct flash_bank *bank; uint32_t offset, count; - uint32_t retval; + int retval; if (CMD_ARGC < 3) return ERROR_COMMAND_SYNTAX_ERROR; @@ -837,7 +829,7 @@ COMMAND_HANDLER(ambiqmicro_handle_program_otp_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], offset); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], count); - command_print(CMD, "offset=0x%08x count=%d", offset, count); + command_print(CMD, "offset=0x%08" PRIx32 " count=%" PRIu32, offset, count); CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);