X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fflash%2Fnor%2Fstellaris.c;h=9763644c5c45e46a31157effa3f547e7e4cc05d0;hb=ef14384b681af4f731f768bb866457832af6925f;hp=27b66325a363d48be00310d428cf6189b94adade;hpb=571db89aa13554d5c5e38e88233927d3149edc3a;p=openocd.git diff --git a/src/flash/nor/stellaris.c b/src/flash/nor/stellaris.c index 27b66325a3..9763644c5c 100644 --- a/src/flash/nor/stellaris.c +++ b/src/flash/nor/stellaris.c @@ -16,9 +16,7 @@ * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + * along with this program. If not, see . * ***************************************************************************/ /*************************************************************************** @@ -507,12 +505,12 @@ static int get_stellaris_info(struct flash_bank *bank, char *buf, int buf_size) printed = snprintf(buf, buf_size, "did1: 0x%8.8" PRIx32 ", arch: 0x%4.4" PRIx32 - ", eproc: %s, ramsize: %ik, flashsize: %ik\n", + ", eproc: %s, ramsize: %" PRIu32 "k, flashsize: %" PRIu32 "k\n", stellaris_info->did1, stellaris_info->did1, "ARMv7M", stellaris_info->sramsiz, - stellaris_info->num_pages * stellaris_info->pagesize / 1024); + (uint32_t)(stellaris_info->num_pages * stellaris_info->pagesize / 1024)); buf += printed; buf_size -= printed; @@ -602,7 +600,7 @@ static void stellaris_read_clock_info(struct flash_bank *bank) LOG_DEBUG("Stellaris PLLCFG %" PRIx32 "", pllcfg); stellaris_info->rcc = rcc; - stellaris_info->rcc = rcc2; + stellaris_info->rcc2 = rcc2; sysdiv = (rcc >> 23) & 0xF; usesysdiv = (rcc >> 22) & 0x1; @@ -805,12 +803,11 @@ static int stellaris_protect_check(struct flash_bank *bank) stellaris->num_pages; uint32_t fmppe_addr; int status = ERROR_OK; - unsigned i; if (stellaris->did1 == 0) return ERROR_FLASH_BANK_NOT_PROBED; - for (i = 0; i < (unsigned) bank->num_sectors; i++) + for (unsigned int i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_protected = -1; /* Read each Flash Memory Protection Program Enable (FMPPE) register @@ -830,7 +827,7 @@ static int stellaris_protect_check(struct flash_bank *bank) uint32_t fmppe; target_read_u32(target, fmppe_addr, &fmppe); - for (i = 0; i < 32 && lockbitnum + i < lockbitcnt; i++) { + for (unsigned int i = 0; i < 32 && lockbitnum + i < lockbitcnt; i++) { bool protect = !(fmppe & (1 << i)); if (bits_per_page) { bank->sectors[page++].is_protected = protect; @@ -846,9 +843,9 @@ static int stellaris_protect_check(struct flash_bank *bank) return status; } -static int stellaris_erase(struct flash_bank *bank, int first, int last) +static int stellaris_erase(struct flash_bank *bank, unsigned int first, + unsigned int last) { - int banknr; uint32_t flash_fmc, flash_cris; struct stellaris_flash_bank *stellaris_info = bank->driver_priv; struct target *target = bank->target; @@ -861,10 +858,10 @@ static int stellaris_erase(struct flash_bank *bank, int first, int last) if (stellaris_info->did1 == 0) return ERROR_FLASH_BANK_NOT_PROBED; - if ((first < 0) || (last < first) || (last >= (int)stellaris_info->num_pages)) + if ((last < first) || (last >= stellaris_info->num_pages)) return ERROR_FLASH_SECTOR_INVALID; - if ((first == 0) && (last == ((int)stellaris_info->num_pages-1))) + if ((first == 0) && (last == (stellaris_info->num_pages - 1))) return stellaris_mass_erase(bank); /* Refresh flash controller timing */ @@ -879,7 +876,7 @@ static int stellaris_erase(struct flash_bank *bank, int first, int last) * it might want to process those IRQs. */ - for (banknr = first; banknr <= last; banknr++) { + for (unsigned int banknr = first; banknr <= last; banknr++) { /* Address is first word in page */ target_write_u32(target, FLASH_FMA, banknr * stellaris_info->pagesize); /* Write erase command */ @@ -904,7 +901,8 @@ static int stellaris_erase(struct flash_bank *bank, int first, int last) return ERROR_OK; } -static int stellaris_protect(struct flash_bank *bank, int set, int first, int last) +static int stellaris_protect(struct flash_bank *bank, int set, + unsigned int first, unsigned int last) { struct stellaris_flash_bank *stellaris = bank->driver_priv; struct target *target = bank->target; @@ -954,7 +952,7 @@ static int stellaris_protect(struct flash_bank *bank, int set, int first, int la else fmppe_addr = SCB_BASE | FMPPE; - int page = 0; + unsigned int page = 0; unsigned int lockbitnum, lockbitcnt = flash_sizek / 2; /* Every lock bit always corresponds to a 2k region */ for (lockbitnum = 0; lockbitnum < lockbitcnt; lockbitnum += 32) { @@ -1065,7 +1063,7 @@ static int stellaris_write_block(struct flash_bank *bank, &write_algorithm) != ERROR_OK) { LOG_DEBUG("no working area for block memory writes"); return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; - }; + } /* plus a buffer big enough for this data */ if (wcount * 4 < buffer_size) @@ -1080,7 +1078,7 @@ static int stellaris_write_block(struct flash_bank *bank, } LOG_DEBUG("retry target_alloc_working_area(%s, size=%u)", target_name(target), (unsigned) buffer_size); - }; + } target_write_buffer(target, write_algorithm->address, sizeof(stellaris_write_code), @@ -1261,7 +1259,7 @@ static int stellaris_probe(struct flash_bank *bank) bank->size = stellaris_info->num_pages * stellaris_info->pagesize; bank->num_sectors = stellaris_info->num_pages; bank->sectors = calloc(bank->num_sectors, sizeof(struct flash_sector)); - for (int i = 0; i < bank->num_sectors; i++) { + for (unsigned int i = 0; i < bank->num_sectors; i++) { bank->sectors[i].offset = i * stellaris_info->pagesize; bank->sectors[i].size = stellaris_info->pagesize; bank->sectors[i].is_erased = -1; @@ -1323,8 +1321,6 @@ static int stellaris_mass_erase(struct flash_bank *bank) COMMAND_HANDLER(stellaris_handle_mass_erase_command) { - int i; - if (CMD_ARGC < 1) return ERROR_COMMAND_SYNTAX_ERROR; @@ -1335,12 +1331,12 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command) if (stellaris_mass_erase(bank) == ERROR_OK) { /* set all sectors as erased */ - for (i = 0; i < bank->num_sectors; i++) + for (unsigned int i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stellaris mass erase complete"); + command_print(CMD, "stellaris mass erase complete"); } else - command_print(CMD_CTX, "stellaris mass erase failed"); + command_print(CMD, "stellaris mass erase failed"); return ERROR_OK; } @@ -1357,6 +1353,7 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command) COMMAND_HANDLER(stellaris_handle_recover_command) { struct flash_bank *bank; + struct arm *arm; int retval; if (CMD_ARGC != 0) @@ -1385,12 +1382,13 @@ COMMAND_HANDLER(stellaris_handle_recover_command) } adapter_assert_reset(); + arm = target_to_arm(bank->target); for (int i = 0; i < 5; i++) { - retval = dap_to_swd(bank->target); + retval = dap_to_swd(arm->dap); if (retval != ERROR_OK) goto done; - retval = dap_to_jtag(bank->target); + retval = dap_to_jtag(arm->dap); if (retval != ERROR_OK) goto done; } @@ -1441,7 +1439,7 @@ static const struct command_registration stellaris_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -struct flash_driver stellaris_flash = { +const struct flash_driver stellaris_flash = { .name = "stellaris", .commands = stellaris_command_handlers, .flash_bank_command = stellaris_flash_bank_command, @@ -1454,4 +1452,5 @@ struct flash_driver stellaris_flash = { .erase_check = default_flash_blank_check, .protect_check = stellaris_protect_check, .info = get_stellaris_info, + .free_driver_priv = default_flash_free_driver_priv, };