X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fflash%2Ftms470.c;h=91f0cc0f26fe52daa81230eb08cba6841326bbd2;hb=66add57aa5bae147b7996840a2287f3547b4b8ea;hp=008961139f1c2d40196c2470fdbed13f57eeb8fb;hpb=4486a8f81426056ffd1b17f13f85619b1b83837f;p=openocd.git diff --git a/src/flash/tms470.c b/src/flash/tms470.c index 008961139f..91f0cc0f26 100644 --- a/src/flash/tms470.c +++ b/src/flash/tms470.c @@ -26,16 +26,16 @@ #include #include -int tms470_register_commands(struct command_context_s *cmd_ctx); -int tms470_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank); -int tms470_erase(struct flash_bank_s *bank, int first, int last); -int tms470_protect(struct flash_bank_s *bank, int set, int first, int last); -int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count); -int tms470_probe(struct flash_bank_s *bank); -int tms470_auto_probe(struct flash_bank_s *bank); -int tms470_erase_check(struct flash_bank_s *bank); -int tms470_protect_check(struct flash_bank_s *bank); -int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size); +static int tms470_register_commands(struct command_context_s *cmd_ctx); +static int tms470_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank); +static int tms470_erase(struct flash_bank_s *bank, int first, int last); +static int tms470_protect(struct flash_bank_s *bank, int set, int first, int last); +static int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count); +static int tms470_probe(struct flash_bank_s *bank); +static int tms470_auto_probe(struct flash_bank_s *bank); +static int tms470_erase_check(struct flash_bank_s *bank); +static int tms470_protect_check(struct flash_bank_s *bank); +static int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size); flash_driver_t tms470_flash = { .name = "tms470", @@ -73,7 +73,7 @@ const flash_sector_t TMS470R1A256_SECTORS[] = { }; #define TMS470R1A256_NUM_SECTORS \ - (sizeof(TMS470R1A256_SECTORS)/sizeof(TMS470R1A256_SECTORS[0])) + (sizeof(TMS470R1A256_SECTORS)/sizeof(TMS470R1A256_SECTORS[0])) const flash_sector_t TMS470R1A288_BANK0_SECTORS[] = { {0x00000000, 0x00002000, -1, -1}, @@ -83,7 +83,7 @@ const flash_sector_t TMS470R1A288_BANK0_SECTORS[] = { }; #define TMS470R1A288_BANK0_NUM_SECTORS \ - (sizeof(TMS470R1A288_BANK0_SECTORS)/sizeof(TMS470R1A288_BANK0_SECTORS[0])) + (sizeof(TMS470R1A288_BANK0_SECTORS)/sizeof(TMS470R1A288_BANK0_SECTORS[0])) const flash_sector_t TMS470R1A288_BANK1_SECTORS[] = { {0x00040000, 0x00010000, -1, -1}, @@ -93,11 +93,47 @@ const flash_sector_t TMS470R1A288_BANK1_SECTORS[] = { }; #define TMS470R1A288_BANK1_NUM_SECTORS \ - (sizeof(TMS470R1A288_BANK1_SECTORS)/sizeof(TMS470R1A288_BANK1_SECTORS[0])) + (sizeof(TMS470R1A288_BANK1_SECTORS)/sizeof(TMS470R1A288_BANK1_SECTORS[0])) + +const flash_sector_t TMS470R1A384_BANK0_SECTORS[] = { + {0x00000000, 0x00002000, -1, -1}, + {0x00002000, 0x00002000, -1, -1}, + {0x00004000, 0x00004000, -1, -1}, + {0x00008000, 0x00004000, -1, -1}, + {0x0000C000, 0x00004000, -1, -1}, + {0x00010000, 0x00004000, -1, -1}, + {0x00014000, 0x00004000, -1, -1}, + {0x00018000, 0x00002000, -1, -1}, + {0x0001C000, 0x00002000, -1, -1}, + {0x0001E000, 0x00002000, -1, -1}, +}; + +#define TMS470R1A384_BANK0_NUM_SECTORS \ + (sizeof(TMS470R1A384_BANK0_SECTORS)/sizeof(TMS470R1A384_BANK0_SECTORS[0])) + +const flash_sector_t TMS470R1A384_BANK1_SECTORS[] = { + {0x00020000, 0x00008000, -1, -1}, + {0x00028000, 0x00008000, -1, -1}, + {0x00030000, 0x00008000, -1, -1}, + {0x00038000, 0x00008000, -1, -1}, +}; + +#define TMS470R1A384_BANK1_NUM_SECTORS \ + (sizeof(TMS470R1A384_BANK1_SECTORS)/sizeof(TMS470R1A384_BANK1_SECTORS[0])) + +const flash_sector_t TMS470R1A384_BANK2_SECTORS[] = { + {0x00040000, 0x00008000, -1, -1}, + {0x00048000, 0x00008000, -1, -1}, + {0x00050000, 0x00008000, -1, -1}, + {0x00058000, 0x00008000, -1, -1}, +}; + +#define TMS470R1A384_BANK2_NUM_SECTORS \ + (sizeof(TMS470R1A384_BANK2_SECTORS)/sizeof(TMS470R1A384_BANK2_SECTORS[0])) /* ---------------------------------------------------------------------- */ -int tms470_read_part_info(struct flash_bank_s *bank) +static int tms470_read_part_info(struct flash_bank_s *bank) { tms470_flash_bank_t *tms470_info = bank->driver_priv; target_t *target = bank->target; @@ -116,11 +152,11 @@ int tms470_read_part_info(struct flash_bank_s *bank) /* read and parse the device identification register */ target_read_u32(target, 0xFFFFFFF0, &device_ident_reg); - INFO("device_ident_reg=0x%08x", device_ident_reg); + LOG_INFO("device_ident_reg=0x%08x", device_ident_reg); if ((device_ident_reg & 7) == 0) { - WARNING("Cannot identify target as a TMS470 family."); + LOG_WARNING("Cannot identify target as a TMS470 family."); return ERROR_FLASH_OPERATION_FAILED; } @@ -142,7 +178,7 @@ int tms470_read_part_info(struct flash_bank_s *bank) if (bank->base >= 0x00040000) { - ERROR("No %s flash bank contains base address 0x%08x.", part_name, bank->base); + LOG_ERROR("No %s flash bank contains base address 0x%08x.", part_name, bank->base); return ERROR_FLASH_OPERATION_FAILED; } tms470_info->ordinal = 0; @@ -160,7 +196,7 @@ int tms470_read_part_info(struct flash_bank_s *bank) case 0x2b: part_name = "TMS470R1A288"; - if ((bank->base >= 0x00000000) && (bank->base < 0x00008000)) + if (bank->base < 0x00008000) { tms470_info->ordinal = 0; bank->base = 0x00000000; @@ -188,13 +224,62 @@ int tms470_read_part_info(struct flash_bank_s *bank) } else { - ERROR("No %s flash bank contains base address 0x%08x.", part_name, bank->base); + LOG_ERROR("No %s flash bank contains base address 0x%08x.", part_name, bank->base); + return ERROR_FLASH_OPERATION_FAILED; + } + break; + + case 0x2d: + part_name = "TMS470R1A384"; + + if (bank->base < 0x00020000) + { + tms470_info->ordinal = 0; + bank->base = 0x00000000; + bank->size = 128 * 1024; + bank->num_sectors = TMS470R1A384_BANK0_NUM_SECTORS; + bank->sectors = malloc(sizeof(TMS470R1A384_BANK0_SECTORS)); + if (!bank->sectors) + { + return ERROR_FLASH_OPERATION_FAILED; + } + (void)memcpy(bank->sectors, TMS470R1A384_BANK0_SECTORS, sizeof(TMS470R1A384_BANK0_SECTORS)); + } + else if ((bank->base >= 0x00020000) && (bank->base < 0x00040000)) + { + tms470_info->ordinal = 1; + bank->base = 0x00020000; + bank->size = 128 * 1024; + bank->num_sectors = TMS470R1A384_BANK1_NUM_SECTORS; + bank->sectors = malloc(sizeof(TMS470R1A384_BANK1_SECTORS)); + if (!bank->sectors) + { + return ERROR_FLASH_OPERATION_FAILED; + } + (void)memcpy(bank->sectors, TMS470R1A384_BANK1_SECTORS, sizeof(TMS470R1A384_BANK1_SECTORS)); + } + else if ((bank->base >= 0x00040000) && (bank->base < 0x00060000)) + { + tms470_info->ordinal = 2; + bank->base = 0x00040000; + bank->size = 128 * 1024; + bank->num_sectors = TMS470R1A384_BANK2_NUM_SECTORS; + bank->sectors = malloc(sizeof(TMS470R1A384_BANK2_SECTORS)); + if (!bank->sectors) + { + return ERROR_FLASH_OPERATION_FAILED; + } + (void)memcpy(bank->sectors, TMS470R1A384_BANK2_SECTORS, sizeof(TMS470R1A384_BANK2_SECTORS)); + } + else + { + LOG_ERROR("No %s flash bank contains base address 0x%08x.", part_name, bank->base); return ERROR_FLASH_OPERATION_FAILED; } break; default: - WARNING("Could not identify part 0x%02x as a member of the TMS470 family.", part_number); + LOG_WARNING("Could not identify part 0x%02x as a member of the TMS470 family.", part_number); return ERROR_FLASH_OPERATION_FAILED; } @@ -205,7 +290,7 @@ int tms470_read_part_info(struct flash_bank_s *bank) bank->chip_width = 32; bank->bus_width = 32; - INFO("Identified %s, ver=%d, core=%s, nvmem=%s.", part_name, silicon_version, (technology_family ? "1.8v" : "3.3v"), (rom_flash ? "rom" : "flash")); + LOG_INFO("Identified %s, ver=%d, core=%s, nvmem=%s.", part_name, silicon_version, (technology_family ? "1.8v" : "3.3v"), (rom_flash ? "rom" : "flash")); tms470_info->device_ident_reg = device_ident_reg; tms470_info->silicon_version = silicon_version; @@ -224,10 +309,10 @@ int tms470_read_part_info(struct flash_bank_s *bank) /* ---------------------------------------------------------------------- */ -u32 keysSet = 0; -u32 flashKeys[4]; +static u32 keysSet = 0; +static u32 flashKeys[4]; -int tms470_handle_flash_keyset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int tms470_handle_flash_keyset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { if (argc > 4) { @@ -245,7 +330,7 @@ int tms470_handle_flash_keyset_command(struct command_context_s *cmd_ctx, char * if (1 != sscanf(&args[i][start], "%x", &flashKeys[i])) { command_print(cmd_ctx, "could not process flash key %s", args[i]); - ERROR("could not process flash key %s", args[i]); + LOG_ERROR("could not process flash key %s", args[i]); return ERROR_INVALID_ARGUMENTS; } } @@ -270,27 +355,27 @@ int tms470_handle_flash_keyset_command(struct command_context_s *cmd_ctx, char * return ERROR_OK; } -const u32 FLASH_KEYS_ALL_ONES[] = { 0xFFFFFFFF, 0xFFFFFFFF, +static const u32 FLASH_KEYS_ALL_ONES[] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, }; -const u32 FLASH_KEYS_ALL_ZEROS[] = { 0x00000000, 0x00000000, +static const u32 FLASH_KEYS_ALL_ZEROS[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, }; -const u32 FLASH_KEYS_MIX1[] = { 0xf0fff0ff, 0xf0fff0ff, +static const u32 FLASH_KEYS_MIX1[] = { 0xf0fff0ff, 0xf0fff0ff, 0xf0fff0ff, 0xf0fff0ff }; -const u32 FLASH_KEYS_MIX2[] = { 0x0000ffff, 0x0000ffff, +static const u32 FLASH_KEYS_MIX2[] = { 0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff }; /* ---------------------------------------------------------------------- */ -int oscMHz = 12; +static int oscMHz = 12; -int tms470_handle_osc_megahertz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int tms470_handle_osc_megahertz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { if (argc > 1) { @@ -304,7 +389,7 @@ int tms470_handle_osc_megahertz_command(struct command_context_s *cmd_ctx, char if (oscMHz <= 0) { - ERROR("osc_megahertz must be positive and non-zero!"); + LOG_ERROR("osc_megahertz must be positive and non-zero!"); command_print(cmd_ctx, "osc_megahertz must be positive and non-zero!"); oscMHz = 12; return ERROR_INVALID_ARGUMENTS; @@ -317,9 +402,9 @@ int tms470_handle_osc_megahertz_command(struct command_context_s *cmd_ctx, char /* ---------------------------------------------------------------------- */ -int plldis = 0; +static int plldis = 0; -int tms470_handle_plldis_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int tms470_handle_plldis_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { if (argc > 1) { @@ -339,18 +424,18 @@ int tms470_handle_plldis_command(struct command_context_s *cmd_ctx, char *cmd, c /* ---------------------------------------------------------------------- */ -int tms470_check_flash_unlocked(target_t * target) +static int tms470_check_flash_unlocked(target_t * target) { u32 fmbbusy; target_read_u32(target, 0xFFE89C08, &fmbbusy); - INFO("tms470 fmbbusy=0x%08x -> %s", fmbbusy, fmbbusy & 0x8000 ? "unlocked" : "LOCKED"); + LOG_INFO("tms470 fmbbusy=0x%08x -> %s", fmbbusy, fmbbusy & 0x8000 ? "unlocked" : "LOCKED"); return fmbbusy & 0x8000 ? ERROR_OK : ERROR_FLASH_OPERATION_FAILED; } /* ---------------------------------------------------------------------- */ -int tms470_try_flash_keys(target_t * target, const u32 * key_set) +static int tms470_try_flash_keys(target_t * target, const u32 * key_set) { u32 glbctrl, fmmstat; int retval = ERROR_FLASH_OPERATION_FAILED; @@ -372,7 +457,7 @@ int tms470_try_flash_keys(target_t * target, const u32 * key_set) do { target_read_u32(target, 0xFFE8A814, &fmbptr); - usleep(1000); + alive_sleep(1); } while (!(fmbptr & 0x0200)); @@ -394,7 +479,7 @@ int tms470_try_flash_keys(target_t * target, const u32 * key_set) */ target_read_u32(target, 0x00001FF0 + 4 * i, &tmp); - INFO("tms470 writing fmpkey=0x%08x", key_set[i]); + LOG_INFO("tms470 writing fmpkey=0x%08x", key_set[i]); target_write_u32(target, 0xFFE89C0C, key_set[i]); } @@ -428,7 +513,7 @@ int tms470_try_flash_keys(target_t * target, const u32 * key_set) /* ---------------------------------------------------------------------- */ -int tms470_unlock_flash(struct flash_bank_s *bank) +static int tms470_unlock_flash(struct flash_bank_s *bank) { target_t *target = bank->target; const u32 *p_key_sets[5]; @@ -456,18 +541,18 @@ int tms470_unlock_flash(struct flash_bank_s *bank) { if (tms470_try_flash_keys(target, p_key_sets[i]) == ERROR_OK) { - INFO("tms470 flash is unlocked"); + LOG_INFO("tms470 flash is unlocked"); return ERROR_OK; } } - WARNING("tms470 could not unlock flash memory protection level 2"); + LOG_WARNING("tms470 could not unlock flash memory protection level 2"); return ERROR_FLASH_OPERATION_FAILED; } /* ---------------------------------------------------------------------- */ -int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *bank) +static int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *bank) { u32 fmmac2, fmmac1, fmmaxep, k, delay, glbctrl, sysclk; target_t *target = bank->target; @@ -482,7 +567,7 @@ int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *bank) fmmac2 &= ~0x0007; fmmac2 |= (tms470_info->ordinal & 7); target_write_u32(target, 0xFFE8BC04, fmmac2); - DEBUG("set fmmac2=0x%04x", fmmac2); + LOG_DEBUG("set fmmac2=0x%04x", fmmac2); /* * Disable level 1 sector protection by setting bit 15 of FMMAC1. @@ -490,25 +575,25 @@ int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *bank) target_read_u32(target, 0xFFE8BC00, &fmmac1); fmmac1 |= 0x8000; target_write_u32(target, 0xFFE8BC00, fmmac1); - DEBUG("set fmmac1=0x%04x", fmmac1); + LOG_DEBUG("set fmmac1=0x%04x", fmmac1); /* * FMTCREG=0x2fc0; */ target_write_u32(target, 0xFFE8BC10, 0x2fc0); - DEBUG("set fmtcreg=0x2fc0"); + LOG_DEBUG("set fmtcreg=0x2fc0"); /* * MAXPP=50 */ target_write_u32(target, 0xFFE8A07C, 50); - DEBUG("set fmmaxpp=50"); + LOG_DEBUG("set fmmaxpp=50"); /* * MAXCP=0xf000+2000 */ target_write_u32(target, 0xFFE8A084, 0xf000 + 2000); - DEBUG("set fmmaxcp=0x%04x", 0xf000 + 2000); + LOG_DEBUG("set fmmaxcp=0x%04x", 0xf000 + 2000); /* * configure VHV @@ -518,22 +603,22 @@ int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *bank) { fmmaxep = 0xf000 + 4095; target_write_u32(target, 0xFFE8A80C, 0x9964); - DEBUG("set fmptr3=0x9964"); + LOG_DEBUG("set fmptr3=0x9964"); } else { fmmaxep = 0xa000 + 4095; target_write_u32(target, 0xFFE8A80C, 0x9b64); - DEBUG("set fmptr3=0x9b64"); + LOG_DEBUG("set fmptr3=0x9b64"); } target_write_u32(target, 0xFFE8A080, fmmaxep); - DEBUG("set fmmaxep=0x%04x", fmmaxep); + LOG_DEBUG("set fmmaxep=0x%04x", fmmaxep); /* * FMPTR4=0xa000 */ target_write_u32(target, 0xFFE8A810, 0xa000); - DEBUG("set fmptr4=0xa000"); + LOG_DEBUG("set fmptr4=0xa000"); /* * FMPESETUP, delay parameter selected based on clock frequency. @@ -547,56 +632,56 @@ int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *bank) sysclk = (plldis ? 1 : (glbctrl & 0x08) ? 4 : 8) * oscMHz / (1 + (glbctrl & 7)); delay = (sysclk > 10) ? (sysclk + 1) / 2 : 5; target_write_u32(target, 0xFFE8A018, (delay << 4) | (delay << 8)); - DEBUG("set fmpsetup=0x%04x", (delay << 4) | (delay << 8)); + LOG_DEBUG("set fmpsetup=0x%04x", (delay << 4) | (delay << 8)); /* * FMPVEVACCESS, based on delay. */ k = delay | (delay << 8); target_write_u32(target, 0xFFE8A05C, k); - DEBUG("set fmpvevaccess=0x%04x", k); + LOG_DEBUG("set fmpvevaccess=0x%04x", k); /* * FMPCHOLD, FMPVEVHOLD, FMPVEVSETUP, based on delay. */ k <<= 1; target_write_u32(target, 0xFFE8A034, k); - DEBUG("set fmpchold=0x%04x", k); + LOG_DEBUG("set fmpchold=0x%04x", k); target_write_u32(target, 0xFFE8A040, k); - DEBUG("set fmpvevhold=0x%04x", k); + LOG_DEBUG("set fmpvevhold=0x%04x", k); target_write_u32(target, 0xFFE8A024, k); - DEBUG("set fmpvevsetup=0x%04x", k); + LOG_DEBUG("set fmpvevsetup=0x%04x", k); /* * FMCVACCESS, based on delay. */ k = delay * 16; target_write_u32(target, 0xFFE8A060, k); - DEBUG("set fmcvaccess=0x%04x", k); + LOG_DEBUG("set fmcvaccess=0x%04x", k); /* * FMCSETUP, based on delay. */ k = 0x3000 | delay * 20; target_write_u32(target, 0xFFE8A020, k); - DEBUG("set fmcsetup=0x%04x", k); + LOG_DEBUG("set fmcsetup=0x%04x", k); /* * FMEHOLD, based on delay. */ k = (delay * 20) << 2; target_write_u32(target, 0xFFE8A038, k); - DEBUG("set fmehold=0x%04x", k); + LOG_DEBUG("set fmehold=0x%04x", k); /* * PWIDTH, CWIDTH, EWIDTH, based on delay. */ target_write_u32(target, 0xFFE8A050, delay * 8); - DEBUG("set fmpwidth=0x%04x", delay * 8); + LOG_DEBUG("set fmpwidth=0x%04x", delay * 8); target_write_u32(target, 0xFFE8A058, delay * 1000); - DEBUG("set fmcwidth=0x%04x", delay * 1000); + LOG_DEBUG("set fmcwidth=0x%04x", delay * 1000); target_write_u32(target, 0xFFE8A054, delay * 5400); - DEBUG("set fmewidth=0x%04x", delay * 5400); + LOG_DEBUG("set fmewidth=0x%04x", delay * 5400); return result; } @@ -610,47 +695,47 @@ int tms470_flash_status(struct flash_bank_s *bank) u32 fmmstat; target_read_u32(target, 0xFFE8BC0C, &fmmstat); - DEBUG("set fmmstat=0x%04x", fmmstat); + LOG_DEBUG("set fmmstat=0x%04x", fmmstat); if (fmmstat & 0x0080) { - WARNING("tms470 flash command: erase still active after busy clear."); + LOG_WARNING("tms470 flash command: erase still active after busy clear."); result = ERROR_FLASH_OPERATION_FAILED; } if (fmmstat & 0x0040) { - WARNING("tms470 flash command: program still active after busy clear."); + LOG_WARNING("tms470 flash command: program still active after busy clear."); result = ERROR_FLASH_OPERATION_FAILED; } if (fmmstat & 0x0020) { - WARNING("tms470 flash command: invalid data command."); + LOG_WARNING("tms470 flash command: invalid data command."); result = ERROR_FLASH_OPERATION_FAILED; } if (fmmstat & 0x0010) { - WARNING("tms470 flash command: program, erase or validate sector failed."); + LOG_WARNING("tms470 flash command: program, erase or validate sector failed."); result = ERROR_FLASH_OPERATION_FAILED; } if (fmmstat & 0x0008) { - WARNING("tms470 flash command: voltage instability detected."); + LOG_WARNING("tms470 flash command: voltage instability detected."); result = ERROR_FLASH_OPERATION_FAILED; } if (fmmstat & 0x0006) { - WARNING("tms470 flash command: command suspend detected."); + LOG_WARNING("tms470 flash command: command suspend detected."); result = ERROR_FLASH_OPERATION_FAILED; } if (fmmstat & 0x0001) { - WARNING("tms470 flash command: sector was locked."); + LOG_WARNING("tms470 flash command: sector was locked."); result = ERROR_FLASH_OPERATION_FAILED; } @@ -659,7 +744,7 @@ int tms470_flash_status(struct flash_bank_s *bank) /* ---------------------------------------------------------------------- */ -int tms470_erase_sector(struct flash_bank_s *bank, int sector) +static int tms470_erase_sector(struct flash_bank_s *bank, int sector) { u32 glbctrl, orig_fmregopt, fmbsea, fmbseb, fmmstat; target_t *target = bank->target; @@ -672,12 +757,12 @@ int tms470_erase_sector(struct flash_bank_s *bank, int sector) */ target_read_u32(target, 0xFFFFFFDC, &glbctrl); target_write_u32(target, 0xFFFFFFDC, glbctrl | 0x10); - DEBUG("set glbctrl=0x%08x", glbctrl | 0x10); + LOG_DEBUG("set glbctrl=0x%08x", glbctrl | 0x10); /* Force normal read mode. */ target_read_u32(target, 0xFFE89C00, &orig_fmregopt); target_write_u32(target, 0xFFE89C00, 0); - DEBUG("set fmregopt=0x%08x", 0); + LOG_DEBUG("set fmregopt=0x%08x", 0); (void)tms470_flash_initialize_internal_state_machine(bank); @@ -689,13 +774,13 @@ int tms470_erase_sector(struct flash_bank_s *bank, int sector) { target_read_u32(target, 0xFFE88008, &fmbsea); target_write_u32(target, 0xFFE88008, fmbsea | (1 << sector)); - DEBUG("set fmbsea=0x%04x", fmbsea | (1 << sector)); + LOG_DEBUG("set fmbsea=0x%04x", fmbsea | (1 << sector)); } else { target_read_u32(target, 0xFFE8800C, &fmbseb); target_write_u32(target, 0xFFE8800C, fmbseb | (1 << (sector - 16))); - DEBUG("set fmbseb=0x%04x", fmbseb | (1 << (sector - 16))); + LOG_DEBUG("set fmbseb=0x%04x", fmbseb | (1 << (sector - 16))); } bank->sectors[sector].is_protected = 0; @@ -703,11 +788,11 @@ int tms470_erase_sector(struct flash_bank_s *bank, int sector) * clear status regiser, sent erase command, kickoff erase */ target_write_u16(target, flashAddr, 0x0040); - DEBUG("write *(u16 *)0x%08x=0x0040", flashAddr); + LOG_DEBUG("write *(u16 *)0x%08x=0x0040", flashAddr); target_write_u16(target, flashAddr, 0x0020); - DEBUG("write *(u16 *)0x%08x=0x0020", flashAddr); + LOG_DEBUG("write *(u16 *)0x%08x=0x0020", flashAddr); target_write_u16(target, flashAddr, 0xffff); - DEBUG("write *(u16 *)0x%08x=0xffff", flashAddr); + LOG_DEBUG("write *(u16 *)0x%08x=0xffff", flashAddr); /* * Monitor FMMSTAT, busy until clear, then check and other flags for @@ -718,7 +803,7 @@ int tms470_erase_sector(struct flash_bank_s *bank, int sector) target_read_u32(target, 0xFFE8BC0C, &fmmstat); if (fmmstat & 0x0100) { - usleep(1000); + alive_sleep(1); } } while (fmmstat & 0x0100); @@ -728,19 +813,19 @@ int tms470_erase_sector(struct flash_bank_s *bank, int sector) if (sector < 16) { target_write_u32(target, 0xFFE88008, fmbsea); - DEBUG("set fmbsea=0x%04x", fmbsea); + LOG_DEBUG("set fmbsea=0x%04x", fmbsea); bank->sectors[sector].is_protected = fmbsea & (1 << sector) ? 0 : 1; } else { target_write_u32(target, 0xFFE8800C, fmbseb); - DEBUG("set fmbseb=0x%04x", fmbseb); + LOG_DEBUG("set fmbseb=0x%04x", fmbseb); bank->sectors[sector].is_protected = fmbseb & (1 << (sector - 16)) ? 0 : 1; } target_write_u32(target, 0xFFE89C00, orig_fmregopt); - DEBUG("set fmregopt=0x%08x", orig_fmregopt); + LOG_DEBUG("set fmregopt=0x%08x", orig_fmregopt); target_write_u32(target, 0xFFFFFFDC, glbctrl); - DEBUG("set glbctrl=0x%08x", glbctrl); + LOG_DEBUG("set glbctrl=0x%08x", glbctrl); if (result == ERROR_OK) { @@ -754,7 +839,7 @@ int tms470_erase_sector(struct flash_bank_s *bank, int sector) Implementation of Flash Driver Interfaces ---------------------------------------------------------------------- */ -int tms470_register_commands(struct command_context_s *cmd_ctx) +static int tms470_register_commands(struct command_context_s *cmd_ctx) { command_t *tms470_cmd = register_command(cmd_ctx, NULL, "tms470", NULL, COMMAND_ANY, "applies to TI tms470 family"); @@ -767,13 +852,14 @@ int tms470_register_commands(struct command_context_s *cmd_ctx) /* ---------------------------------------------------------------------- */ -int tms470_erase(struct flash_bank_s *bank, int first, int last) +static int tms470_erase(struct flash_bank_s *bank, int first, int last) { tms470_flash_bank_t *tms470_info = bank->driver_priv; int sector, result = ERROR_OK; if (bank->target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; } @@ -781,7 +867,7 @@ int tms470_erase(struct flash_bank_s *bank, int first, int last) if ((first < 0) || (first >= bank->num_sectors) || (last < 0) || (last >= bank->num_sectors) || (first > last)) { - ERROR("Sector range %d to %d invalid.", first, last); + LOG_ERROR("Sector range %d to %d invalid.", first, last); return ERROR_FLASH_SECTOR_INVALID; } @@ -793,18 +879,18 @@ int tms470_erase(struct flash_bank_s *bank, int first, int last) for (sector = first; sector <= last; sector++) { - INFO("Erasing tms470 bank %d sector %d...", tms470_info->ordinal, sector); + LOG_INFO("Erasing tms470 bank %d sector %d...", tms470_info->ordinal, sector); result = tms470_erase_sector(bank, sector); if (result != ERROR_OK) { - ERROR("tms470 could not erase flash sector."); + LOG_ERROR("tms470 could not erase flash sector."); break; } else { - INFO("sector erased successfully."); + LOG_INFO("sector erased successfully."); } } @@ -813,7 +899,7 @@ int tms470_erase(struct flash_bank_s *bank, int first, int last) /* ---------------------------------------------------------------------- */ -int tms470_protect(struct flash_bank_s *bank, int set, int first, int last) +static int tms470_protect(struct flash_bank_s *bank, int set, int first, int last) { tms470_flash_bank_t *tms470_info = bank->driver_priv; target_t *target = bank->target; @@ -822,6 +908,7 @@ int tms470_protect(struct flash_bank_s *bank, int set, int first, int last) if (target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; } @@ -829,7 +916,7 @@ int tms470_protect(struct flash_bank_s *bank, int set, int first, int last) if ((first < 0) || (first >= bank->num_sectors) || (last < 0) || (last >= bank->num_sectors) || (first > last)) { - ERROR("Sector range %d to %d invalid.", first, last); + LOG_ERROR("Sector range %d to %d invalid.", first, last); return ERROR_FLASH_SECTOR_INVALID; } @@ -864,20 +951,22 @@ int tms470_protect(struct flash_bank_s *bank, int set, int first, int last) /* ---------------------------------------------------------------------- */ -int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count) +static int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count) { target_t *target = bank->target; u32 glbctrl, fmbac2, orig_fmregopt, fmbsea, fmbseb, fmmaxpp, fmmstat; - int i, result = ERROR_OK; + int result = ERROR_OK; + u32 i; if (target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; } tms470_read_part_info(bank); - INFO("Writing %d bytes starting at 0x%08x", count, bank->base + offset); + LOG_INFO("Writing %d bytes starting at 0x%08x", count, bank->base + offset); /* set GLBCTRL.4 */ target_read_u32(target, 0xFFFFFFDC, &glbctrl); @@ -911,7 +1000,7 @@ int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count) if (word != 0xffff) { - INFO("writing 0x%04x at 0x%08x", word, addr); + LOG_INFO("writing 0x%04x at 0x%08x", word, addr); /* clear status register */ target_write_u16(target, addr, 0x0040); @@ -929,22 +1018,22 @@ int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count) target_read_u32(target, 0xFFE8BC0C, &fmmstat); if (fmmstat & 0x0100) { - usleep(1000); + alive_sleep(1); } } while (fmmstat & 0x0100); if (fmmstat & 0x3ff) { - ERROR("fmstat=0x%04x", fmmstat); - ERROR("Could not program word 0x%04x at address 0x%08x.", word, addr); + LOG_ERROR("fmstat=0x%04x", fmmstat); + LOG_ERROR("Could not program word 0x%04x at address 0x%08x.", word, addr); result = ERROR_FLASH_OPERATION_FAILED; break; } } else { - INFO("skipping 0xffff at 0x%08x", addr); + LOG_INFO("skipping 0xffff at 0x%08x", addr); } } @@ -960,18 +1049,18 @@ int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count) /* ---------------------------------------------------------------------- */ -int tms470_probe(struct flash_bank_s *bank) +static int tms470_probe(struct flash_bank_s *bank) { if (bank->target->state != TARGET_HALTED) { - WARNING("Cannot communicate... target not halted."); + LOG_WARNING("Cannot communicate... target not halted."); return ERROR_TARGET_NOT_HALTED; } return tms470_read_part_info(bank); } -int tms470_auto_probe(struct flash_bank_s *bank) +static int tms470_auto_probe(struct flash_bank_s *bank) { tms470_flash_bank_t *tms470_info = bank->driver_priv; @@ -982,7 +1071,7 @@ int tms470_auto_probe(struct flash_bank_s *bank) /* ---------------------------------------------------------------------- */ -int tms470_erase_check(struct flash_bank_s *bank) +static int tms470_erase_check(struct flash_bank_s *bank) { target_t *target = bank->target; tms470_flash_bank_t *tms470_info = bank->driver_priv; @@ -992,6 +1081,7 @@ int tms470_erase_check(struct flash_bank_s *bank) if (target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; } @@ -1033,7 +1123,7 @@ int tms470_erase_check(struct flash_bank_s *bank) { u32 i, addr = bank->base + bank->sectors[sector].offset; - INFO("checking flash bank %d sector %d", tms470_info->ordinal, sector); + LOG_INFO("checking flash bank %d sector %d", tms470_info->ordinal, sector); target_read_buffer(target, addr, bank->sectors[sector].size, buffer); @@ -1042,8 +1132,8 @@ int tms470_erase_check(struct flash_bank_s *bank) { if (buffer[i] != 0xff) { - WARNING("tms470 bank %d, sector %d, not erased.", tms470_info->ordinal, sector); - WARNING("at location 0x%08x: flash data is 0x%02x.", addr + i, buffer[i]); + LOG_WARNING("tms470 bank %d, sector %d, not erased.", tms470_info->ordinal, sector); + LOG_WARNING("at location 0x%08x: flash data is 0x%02x.", addr + i, buffer[i]); bank->sectors[sector].is_erased = 0; break; @@ -1057,7 +1147,7 @@ int tms470_erase_check(struct flash_bank_s *bank) } else { - INFO("sector erased"); + LOG_INFO("sector erased"); } } @@ -1072,7 +1162,7 @@ int tms470_erase_check(struct flash_bank_s *bank) /* ---------------------------------------------------------------------- */ -int tms470_protect_check(struct flash_bank_s *bank) +static int tms470_protect_check(struct flash_bank_s *bank) { target_t *target = bank->target; tms470_flash_bank_t *tms470_info = bank->driver_priv; @@ -1081,6 +1171,7 @@ int tms470_protect_check(struct flash_bank_s *bank) if (target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; } @@ -1111,7 +1202,7 @@ int tms470_protect_check(struct flash_bank_s *bank) bank->sectors[sector].is_protected = protected; } - DEBUG("bank %d sector %d is %s", tms470_info->ordinal, sector, protected ? "protected" : "not protected"); + LOG_DEBUG("bank %d sector %d is %s", tms470_info->ordinal, sector, protected ? "protected" : "not protected"); } return result; @@ -1119,7 +1210,7 @@ int tms470_protect_check(struct flash_bank_s *bank) /* ---------------------------------------------------------------------- */ -int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size) +static int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size) { int used = 0; tms470_flash_bank_t *tms470_info = bank->driver_priv; @@ -1153,7 +1244,7 @@ int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size) * [options...] */ -int tms470_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +static int tms470_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) { bank->driver_priv = malloc(sizeof(tms470_flash_bank_t));