32 {0x00000000, 0x00002000, -1, -1},
33 {0x00002000, 0x00002000, -1, -1},
34 {0x00004000, 0x00002000, -1, -1},
35 {0x00006000, 0x00002000, -1, -1},
36 {0x00008000, 0x00008000, -1, -1},
37 {0x00010000, 0x00008000, -1, -1},
38 {0x00018000, 0x00008000, -1, -1},
39 {0x00020000, 0x00008000, -1, -1},
40 {0x00028000, 0x00008000, -1, -1},
41 {0x00030000, 0x00008000, -1, -1},
42 {0x00038000, 0x00002000, -1, -1},
43 {0x0003A000, 0x00002000, -1, -1},
44 {0x0003C000, 0x00002000, -1, -1},
45 {0x0003E000, 0x00002000, -1, -1},
48 #define TMS470R1A256_NUM_SECTORS \
49 ARRAY_SIZE(tms470r1a256_sectors)
52 {0x00000000, 0x00002000, -1, -1},
53 {0x00002000, 0x00002000, -1, -1},
54 {0x00004000, 0x00002000, -1, -1},
55 {0x00006000, 0x00002000, -1, -1},
58 #define TMS470R1A288_BANK0_NUM_SECTORS \
59 ARRAY_SIZE(tms470r1a288_bank0_sectors)
62 {0x00040000, 0x00010000, -1, -1},
63 {0x00050000, 0x00010000, -1, -1},
64 {0x00060000, 0x00010000, -1, -1},
65 {0x00070000, 0x00010000, -1, -1},
68 #define TMS470R1A288_BANK1_NUM_SECTORS \
69 ARRAY_SIZE(tms470r1a288_bank1_sectors)
72 {0x00000000, 0x00002000, -1, -1},
73 {0x00002000, 0x00002000, -1, -1},
74 {0x00004000, 0x00004000, -1, -1},
75 {0x00008000, 0x00004000, -1, -1},
76 {0x0000C000, 0x00004000, -1, -1},
77 {0x00010000, 0x00004000, -1, -1},
78 {0x00014000, 0x00004000, -1, -1},
79 {0x00018000, 0x00002000, -1, -1},
80 {0x0001C000, 0x00002000, -1, -1},
81 {0x0001E000, 0x00002000, -1, -1},
84 #define TMS470R1A384_BANK0_NUM_SECTORS \
85 ARRAY_SIZE(tms470r1a384_bank0_sectors)
88 {0x00020000, 0x00008000, -1, -1},
89 {0x00028000, 0x00008000, -1, -1},
90 {0x00030000, 0x00008000, -1, -1},
91 {0x00038000, 0x00008000, -1, -1},
94 #define TMS470R1A384_BANK1_NUM_SECTORS \
95 ARRAY_SIZE(tms470r1a384_bank1_sectors)
98 {0x00040000, 0x00008000, -1, -1},
99 {0x00048000, 0x00008000, -1, -1},
100 {0x00050000, 0x00008000, -1, -1},
101 {0x00058000, 0x00008000, -1, -1},
104 #define TMS470R1A384_BANK2_NUM_SECTORS \
105 ARRAY_SIZE(tms470r1a384_bank2_sectors)
113 uint32_t device_ident_reg;
114 uint32_t silicon_version;
115 uint32_t technology_family;
117 uint32_t part_number;
118 const char *part_name;
128 LOG_INFO(
"device_ident_reg = 0x%08" PRIx32
"", device_ident_reg);
130 if ((device_ident_reg & 7) == 0) {
131 LOG_WARNING(
"Cannot identify target as a TMS470 family.");
135 silicon_version = (device_ident_reg >> 12) & 0xF;
136 technology_family = (device_ident_reg >> 11) & 1;
137 rom_flash = (device_ident_reg >> 10) & 1;
138 part_number = (device_ident_reg >> 3) & 0x7f;
142 bank->num_sectors = 0;
150 switch (part_number) {
152 part_name =
"TMS470R1A256";
154 if (
bank->base >= 0x00040000) {
155 LOG_ERROR(
"No %s flash bank contains base address "
162 bank->base = 0x00000000;
163 bank->size = 256 * 1024;
172 part_name =
"TMS470R1A288";
174 if (
bank->base < 0x00008000) {
176 bank->base = 0x00000000;
177 bank->size = 32 * 1024;
184 }
else if ((
bank->base >= 0x00040000) && (
bank->base < 0x00080000)) {
186 bank->base = 0x00040000;
187 bank->size = 256 * 1024;
196 part_name,
bank->base);
202 part_name =
"TMS470R1A384";
204 if (
bank->base < 0x00020000) {
206 bank->base = 0x00000000;
207 bank->size = 128 * 1024;
214 }
else if ((
bank->base >= 0x00020000) && (
bank->base < 0x00040000)) {
216 bank->base = 0x00020000;
217 bank->size = 128 * 1024;
224 }
else if ((
bank->base >= 0x00040000) && (
bank->base < 0x00060000)) {
226 bank->base = 0x00040000;
227 bank->size = 128 * 1024;
236 part_name,
bank->base);
242 LOG_WARNING(
"Could not identify part 0x%02" PRIx32
" as a member of the TMS470 family.",
251 LOG_INFO(
"Identified %s, ver=%d, core=%s, nvmem=%s.",
253 (
int)(silicon_version),
254 (technology_family ?
"1.8v" :
"3.3v"),
255 (rom_flash ?
"rom" :
"flash"));
284 for (i = 0; i < 4; i++) {
303 "using flash keys 0x%08" PRIx32
", 0x%08" PRIx32
", 0x%08" PRIx32
", 0x%08" PRIx32
"",
315 0xFFFFFFFF, 0xFFFFFFFF,};
318 0x00000000, 0x00000000,};
321 0xf0fff0ff, 0xf0fff0ff};
324 0x0000ffff, 0x0000ffff};
338 LOG_ERROR(
"osc_megahertz must be positive and non-zero!");
374 LOG_INFO(
"tms470 fmbbusy = 0x%08" PRIx32
" -> %s",
376 fmbbusy & 0x8000 ?
"unlocked" :
"LOCKED");
384 uint32_t glbctrl, fmmstat;
393 if (!(fmmstat & 0x08)) {
395 uint32_t fmbptr, fmbac2, orig_fmregopt;
403 }
while (!(fmbptr & 0x0200));
413 for (i = 0; i < 4; i++) {
422 LOG_INFO(
"tms470 writing fmpkey = 0x%08" PRIx32
"", key_set[i]);
432 for (i = 0; i < 4; i++) {
457 const uint32_t *p_key_sets[5];
458 unsigned int i, key_set_count;
475 for (i = 0; i < key_set_count; i++) {
477 LOG_INFO(
"tms470 flash is unlocked");
482 LOG_WARNING(
"tms470 could not unlock flash memory protection level 2");
490 uint32_t fmmac2, fmmac1, fmmaxep, k, delay, glbctrl, sysclk;
501 fmmac2 |= (tms470_info->
ordinal & 7);
503 LOG_DEBUG(
"set fmmac2 = 0x%04" PRIx32
"", fmmac2);
511 LOG_DEBUG(
"set fmmac1 = 0x%04" PRIx32
"", fmmac1);
529 LOG_DEBUG(
"set fmmaxcp = 0x%04x", 0xf000 + 2000);
535 if (fmmaxep == 0xf000) {
536 fmmaxep = 0xf000 + 4095;
540 fmmaxep = 0xa000 + 4095;
545 LOG_DEBUG(
"set fmmaxep = 0x%04" PRIx32
"", fmmaxep);
562 sysclk = (
plldis ? 1 : (glbctrl & 0x08) ? 4 : 8) *
osc_mhz / (1 + (glbctrl & 7));
563 delay = (sysclk > 10) ? (sysclk + 1) / 2 : 5;
565 LOG_DEBUG(
"set fmpsetup = 0x%04" PRIx32
"", (delay << 4) | (delay << 8));
570 k = delay | (delay << 8);
572 LOG_DEBUG(
"set fmpvevaccess = 0x%04" PRIx32
"", k);
579 LOG_DEBUG(
"set fmpchold = 0x%04" PRIx32
"", k);
581 LOG_DEBUG(
"set fmpvevhold = 0x%04" PRIx32
"", k);
583 LOG_DEBUG(
"set fmpvevsetup = 0x%04" PRIx32
"", k);
590 LOG_DEBUG(
"set fmcvaccess = 0x%04" PRIx32
"", k);
595 k = 0x3000 | delay * 20;
597 LOG_DEBUG(
"set fmcsetup = 0x%04" PRIx32
"", k);
602 k = (delay * 20) << 2;
604 LOG_DEBUG(
"set fmehold = 0x%04" PRIx32
"", k);
610 LOG_DEBUG(
"set fmpwidth = 0x%04" PRIx32
"", delay * 8);
612 LOG_DEBUG(
"set fmcwidth = 0x%04" PRIx32
"", delay * 1000);
614 LOG_DEBUG(
"set fmewidth = 0x%04" PRIx32
"", delay * 5400);
628 LOG_DEBUG(
"set fmmstat = 0x%04" PRIx32
"", fmmstat);
630 if (fmmstat & 0x0080) {
631 LOG_WARNING(
"tms470 flash command: erase still active after busy clear.");
635 if (fmmstat & 0x0040) {
636 LOG_WARNING(
"tms470 flash command: program still active after busy clear.");
640 if (fmmstat & 0x0020) {
641 LOG_WARNING(
"tms470 flash command: invalid data command.");
645 if (fmmstat & 0x0010) {
646 LOG_WARNING(
"tms470 flash command: program, erase or validate sector failed.");
650 if (fmmstat & 0x0008) {
651 LOG_WARNING(
"tms470 flash command: voltage instability detected.");
655 if (fmmstat & 0x0006) {
656 LOG_WARNING(
"tms470 flash command: command suspend detected.");
660 if (fmmstat & 0x0001) {
661 LOG_WARNING(
"tms470 flash command: sector was locked.");
672 uint32_t glbctrl, orig_fmregopt, fmbsea, fmbseb, fmmstat;
674 uint32_t flash_addr =
bank->base +
bank->sectors[sector].offset;
683 LOG_DEBUG(
"set glbctrl = 0x%08" PRIx32
"", glbctrl | 0x10);
700 LOG_DEBUG(
"set fmbsea = 0x%04" PRIx32
"", fmbsea | (1 << sector));
704 LOG_DEBUG(
"set fmbseb = 0x%04" PRIx32
"", fmbseb | (1 << (sector - 16)));
706 bank->sectors[sector].is_protected = 0;
712 LOG_DEBUG(
"write *(uint16_t *)0x%08" PRIx32
"=0x0040", flash_addr);
714 LOG_DEBUG(
"write *(uint16_t *)0x%08" PRIx32
"=0x0020", flash_addr);
716 LOG_DEBUG(
"write *(uint16_t *)0x%08" PRIx32
"=0xffff", flash_addr);
724 if (fmmstat & 0x0100)
726 }
while (fmmstat & 0x0100);
732 LOG_DEBUG(
"set fmbsea = 0x%04" PRIx32
"", fmbsea);
733 bank->sectors[sector].is_protected = fmbsea & (1 << sector) ? 0 : 1;
736 LOG_DEBUG(
"set fmbseb = 0x%04" PRIx32
"", fmbseb);
737 bank->sectors[sector].is_protected = fmbseb & (1 << (sector - 16)) ? 0 : 1;
740 LOG_DEBUG(
"set fmregopt = 0x%08" PRIx32
"", orig_fmregopt);
742 LOG_DEBUG(
"set glbctrl = 0x%08" PRIx32
"", glbctrl);
753 .
name =
"flash_keyset",
754 .usage =
"<key0> <key1> <key2> <key3>",
755 .handler = tms470_handle_flash_keyset_command,
757 .help =
"tms470 flash_keyset <key0> <key1> <key2> <key3>",
760 .name =
"osc_megahertz",
762 .handler = tms470_handle_osc_megahertz_command,
764 .help =
"tms470 osc_megahertz <MHz>",
769 .handler = tms470_handle_plldis_command,
771 .help =
"tms470 plldis <0/1>",
779 .help =
"TI tms470 flash command group",
801 if ((first >=
bank->num_sectors) || (last >=
bank->num_sectors) ||
803 LOG_ERROR(
"Sector range %u to %u invalid.", first, last);
811 for (
unsigned int sector = first; sector <= last; sector++) {
812 LOG_INFO(
"Erasing tms470 bank %u sector %u...", tms470_info->
ordinal, sector);
817 LOG_ERROR(
"tms470 could not erase flash sector.");
820 LOG_INFO(
"sector erased successfully.");
833 uint32_t fmmac2, fmbsea, fmbseb;
842 if ((first >=
bank->num_sectors) || (last >=
bank->num_sectors) ||
844 LOG_ERROR(
"Sector range %u to %u invalid.", first, last);
856 for (
unsigned int sector = 0; sector <
bank->num_sectors; sector++) {
858 fmbsea = set ? fmbsea & ~(1 << sector) : fmbsea | (1 << sector);
859 bank->sectors[sector].is_protected = set ? 1 : 0;
861 fmbseb = set ? fmbseb &
862 ~(1 << (sector - 16)) : fmbseb | (1 << (sector - 16));
863 bank->sectors[sector].is_protected = set ? 1 : 0;
879 uint32_t glbctrl, fmbac2, orig_fmregopt, fmbsea, fmbseb, fmmaxpp, fmmstat;
918 for (i = 0; i <
count; i += 2) {
920 uint16_t word = (((uint16_t)
buffer[i]) << 8) | (uint16_t)
buffer[i + 1];
922 if (word != 0xffff) {
923 LOG_INFO(
"writing 0x%04x at 0x%08" PRIx32
"", word,
addr);
938 if (fmmstat & 0x0100)
940 }
while (fmmstat & 0x0100);
942 if (fmmstat & 0x3ff) {
943 LOG_ERROR(
"fmstat = 0x%04" PRIx32
"", fmmstat);
945 "Could not program word 0x%04x at address 0x%08" PRIx32
".",
970 LOG_WARNING(
"Cannot communicate... target not halted.");
993 uint32_t fmmac2, fmbac2, glbctrl, orig_fmregopt;
994 static uint8_t
buffer[64 * 1024];
1031 for (
unsigned int sector = 0; sector <
bank->num_sectors; sector++) {
1032 uint32_t i,
addr =
bank->base +
bank->sectors[sector].offset;
1034 LOG_INFO(
"checking flash bank %u sector %u", tms470_info->
ordinal, sector);
1038 bank->sectors[sector].is_erased = 1;
1039 for (i = 0; i <
bank->sectors[sector].size; i++) {
1041 bank->sectors[sector].is_erased = 0;
1045 if (
bank->sectors[sector].is_erased != 1) {
1068 uint32_t fmmac2, fmbsea, fmbseb;
1085 for (
unsigned int sector = 0; sector <
bank->num_sectors; sector++) {
1089 protected = fmbsea & (1 << sector) ? 0 : 1;
1090 bank->sectors[sector].is_protected =
protected;
1092 protected = fmbseb & (1 << (sector - 16)) ? 0 : 1;
1093 bank->sectors[sector].is_protected =
protected;
1099 protected ?
"protected" :
"not protected");
1137 if (!
bank->driver_priv)
1148 .flash_bank_command = tms470_flash_bank_command,
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_FLASH_SECTOR_INVALID
#define ERROR_FLASH_SECTOR_NOT_ERASED
#define ERROR_FLASH_OPERATION_FAILED
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
void alive_sleep(uint64_t ms)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
target_addr_t addr
Start address to search for the control block.
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Provides details of a flash bank, available either on-chip or through a major interface.
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
Describes the geometry and status of a single flash sector within a flash bank.
uint32_t technology_family
uint32_t device_ident_reg
int target_write_u16(struct target *target, target_addr_t address, uint16_t value)
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
#define ERROR_TARGET_NOT_HALTED
static const struct flash_sector tms470r1a384_bank2_sectors[]
static int tms470_read_part_info(struct flash_bank *bank)
static int tms470_unlock_flash(struct flash_bank *bank)
static const uint32_t flash_keys_mix1[]
#define TMS470R1A384_BANK0_NUM_SECTORS
static const struct flash_sector tms470r1a384_bank1_sectors[]
static const struct command_registration tms470_any_command_handlers[]
static int tms470_flash_status(struct flash_bank *bank)
static int tms470_probe(struct flash_bank *bank)
static const uint32_t flash_keys_mix2[]
static int tms470_check_flash_unlocked(struct target *target)
static int tms470_try_flash_keys(struct target *target, const uint32_t *key_set)
static int tms470_protect_check(struct flash_bank *bank)
#define TMS470R1A256_NUM_SECTORS
#define TMS470R1A288_BANK0_NUM_SECTORS
static int tms470_flash_initialize_internal_state_machine(struct flash_bank *bank)
static int tms470_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
#define TMS470R1A288_BANK1_NUM_SECTORS
FLASH_BANK_COMMAND_HANDLER(tms470_flash_bank_command)
static int tms470_auto_probe(struct flash_bank *bank)
static int tms470_erase_sector(struct flash_bank *bank, int sector)
static const struct flash_sector tms470r1a256_sectors[]
static const struct flash_sector tms470r1a384_bank0_sectors[]
#define TMS470R1A384_BANK2_NUM_SECTORS
static const uint32_t flash_keys_all_zeros[]
COMMAND_HANDLER(tms470_handle_flash_keyset_command)
static const uint32_t flash_keys_all_ones[]
static uint32_t flash_keys[4]
static const struct flash_sector tms470r1a288_bank1_sectors[]
#define TMS470R1A384_BANK1_NUM_SECTORS
static int get_tms470_info(struct flash_bank *bank, struct command_invocation *cmd)
static int tms470_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static int tms470_erase_check(struct flash_bank *bank)
static int tms470_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
const struct flash_driver tms470_flash
static const struct command_registration tms470_command_handlers[]
static const struct flash_sector tms470r1a288_bank0_sectors[]