You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1192 lines
35 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2007,2008 by Christopher Kilgour *
  3. * techie |_at_| whiterocker |_dot_| com *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include "imp.h"
  24. /* ----------------------------------------------------------------------
  25. * Internal Support, Helpers
  26. * ---------------------------------------------------------------------- */
  27. struct tms470_flash_bank {
  28. unsigned ordinal;
  29. /* device identification register */
  30. uint32_t device_ident_reg;
  31. uint32_t silicon_version;
  32. uint32_t technology_family;
  33. uint32_t rom_flash;
  34. uint32_t part_number;
  35. const char *part_name;
  36. };
  37. static const struct flash_sector TMS470R1A256_SECTORS[] = {
  38. {0x00000000, 0x00002000, -1, -1},
  39. {0x00002000, 0x00002000, -1, -1},
  40. {0x00004000, 0x00002000, -1, -1},
  41. {0x00006000, 0x00002000, -1, -1},
  42. {0x00008000, 0x00008000, -1, -1},
  43. {0x00010000, 0x00008000, -1, -1},
  44. {0x00018000, 0x00008000, -1, -1},
  45. {0x00020000, 0x00008000, -1, -1},
  46. {0x00028000, 0x00008000, -1, -1},
  47. {0x00030000, 0x00008000, -1, -1},
  48. {0x00038000, 0x00002000, -1, -1},
  49. {0x0003A000, 0x00002000, -1, -1},
  50. {0x0003C000, 0x00002000, -1, -1},
  51. {0x0003E000, 0x00002000, -1, -1},
  52. };
  53. #define TMS470R1A256_NUM_SECTORS \
  54. ARRAY_SIZE(TMS470R1A256_SECTORS)
  55. static const struct flash_sector TMS470R1A288_BANK0_SECTORS[] = {
  56. {0x00000000, 0x00002000, -1, -1},
  57. {0x00002000, 0x00002000, -1, -1},
  58. {0x00004000, 0x00002000, -1, -1},
  59. {0x00006000, 0x00002000, -1, -1},
  60. };
  61. #define TMS470R1A288_BANK0_NUM_SECTORS \
  62. ARRAY_SIZE(TMS470R1A288_BANK0_SECTORS)
  63. static const struct flash_sector TMS470R1A288_BANK1_SECTORS[] = {
  64. {0x00040000, 0x00010000, -1, -1},
  65. {0x00050000, 0x00010000, -1, -1},
  66. {0x00060000, 0x00010000, -1, -1},
  67. {0x00070000, 0x00010000, -1, -1},
  68. };
  69. #define TMS470R1A288_BANK1_NUM_SECTORS \
  70. ARRAY_SIZE(TMS470R1A288_BANK1_SECTORS)
  71. static const struct flash_sector TMS470R1A384_BANK0_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},
  82. };
  83. #define TMS470R1A384_BANK0_NUM_SECTORS \
  84. ARRAY_SIZE(TMS470R1A384_BANK0_SECTORS)
  85. static const struct flash_sector TMS470R1A384_BANK1_SECTORS[] = {
  86. {0x00020000, 0x00008000, -1, -1},
  87. {0x00028000, 0x00008000, -1, -1},
  88. {0x00030000, 0x00008000, -1, -1},
  89. {0x00038000, 0x00008000, -1, -1},
  90. };
  91. #define TMS470R1A384_BANK1_NUM_SECTORS \
  92. ARRAY_SIZE(TMS470R1A384_BANK1_SECTORS)
  93. static const struct flash_sector TMS470R1A384_BANK2_SECTORS[] = {
  94. {0x00040000, 0x00008000, -1, -1},
  95. {0x00048000, 0x00008000, -1, -1},
  96. {0x00050000, 0x00008000, -1, -1},
  97. {0x00058000, 0x00008000, -1, -1},
  98. };
  99. #define TMS470R1A384_BANK2_NUM_SECTORS \
  100. ARRAY_SIZE(TMS470R1A384_BANK2_SECTORS)
  101. /* ---------------------------------------------------------------------- */
  102. static int tms470_read_part_info(struct flash_bank *bank)
  103. {
  104. struct tms470_flash_bank *tms470_info = bank->driver_priv;
  105. struct target *target = bank->target;
  106. uint32_t device_ident_reg;
  107. uint32_t silicon_version;
  108. uint32_t technology_family;
  109. uint32_t rom_flash;
  110. uint32_t part_number;
  111. const char *part_name;
  112. /* we shall not rely on the caller in this test, this function allocates memory,
  113. thus and executing the code more than once may cause memory leak */
  114. if (tms470_info->device_ident_reg)
  115. return ERROR_OK;
  116. /* read and parse the device identification register */
  117. target_read_u32(target, 0xFFFFFFF0, &device_ident_reg);
  118. LOG_INFO("device_ident_reg = 0x%08" PRIx32 "", device_ident_reg);
  119. if ((device_ident_reg & 7) == 0) {
  120. LOG_WARNING("Cannot identify target as a TMS470 family.");
  121. return ERROR_FLASH_OPERATION_FAILED;
  122. }
  123. silicon_version = (device_ident_reg >> 12) & 0xF;
  124. technology_family = (device_ident_reg >> 11) & 1;
  125. rom_flash = (device_ident_reg >> 10) & 1;
  126. part_number = (device_ident_reg >> 3) & 0x7f;
  127. if (bank->sectors) {
  128. free(bank->sectors);
  129. bank->sectors = NULL;
  130. }
  131. /*
  132. * If the part number is known, determine if the flash bank is valid
  133. * based on the base address being within the known flash bank
  134. * ranges. Then fixup/complete the remaining fields of the flash
  135. * bank structure.
  136. */
  137. switch (part_number) {
  138. case 0x0a:
  139. part_name = "TMS470R1A256";
  140. if (bank->base >= 0x00040000) {
  141. LOG_ERROR("No %s flash bank contains base address 0x%08" PRIx32 ".",
  142. part_name,
  143. bank->base);
  144. return ERROR_FLASH_OPERATION_FAILED;
  145. }
  146. tms470_info->ordinal = 0;
  147. bank->base = 0x00000000;
  148. bank->size = 256 * 1024;
  149. bank->num_sectors = TMS470R1A256_NUM_SECTORS;
  150. bank->sectors = malloc(sizeof(TMS470R1A256_SECTORS));
  151. if (!bank->sectors)
  152. return ERROR_FLASH_OPERATION_FAILED;
  153. (void)memcpy(bank->sectors, TMS470R1A256_SECTORS, sizeof(TMS470R1A256_SECTORS));
  154. break;
  155. case 0x2b:
  156. part_name = "TMS470R1A288";
  157. if (bank->base < 0x00008000) {
  158. tms470_info->ordinal = 0;
  159. bank->base = 0x00000000;
  160. bank->size = 32 * 1024;
  161. bank->num_sectors = TMS470R1A288_BANK0_NUM_SECTORS;
  162. bank->sectors = malloc(sizeof(TMS470R1A288_BANK0_SECTORS));
  163. if (!bank->sectors)
  164. return ERROR_FLASH_OPERATION_FAILED;
  165. (void)memcpy(bank->sectors, TMS470R1A288_BANK0_SECTORS,
  166. sizeof(TMS470R1A288_BANK0_SECTORS));
  167. } else if ((bank->base >= 0x00040000) && (bank->base < 0x00080000)) {
  168. tms470_info->ordinal = 1;
  169. bank->base = 0x00040000;
  170. bank->size = 256 * 1024;
  171. bank->num_sectors = TMS470R1A288_BANK1_NUM_SECTORS;
  172. bank->sectors = malloc(sizeof(TMS470R1A288_BANK1_SECTORS));
  173. if (!bank->sectors)
  174. return ERROR_FLASH_OPERATION_FAILED;
  175. (void)memcpy(bank->sectors, TMS470R1A288_BANK1_SECTORS,
  176. sizeof(TMS470R1A288_BANK1_SECTORS));
  177. } else {
  178. LOG_ERROR("No %s flash bank contains base address 0x%08" PRIx32 ".",
  179. part_name, bank->base);
  180. return ERROR_FLASH_OPERATION_FAILED;
  181. }
  182. break;
  183. case 0x2d:
  184. part_name = "TMS470R1A384";
  185. if (bank->base < 0x00020000) {
  186. tms470_info->ordinal = 0;
  187. bank->base = 0x00000000;
  188. bank->size = 128 * 1024;
  189. bank->num_sectors = TMS470R1A384_BANK0_NUM_SECTORS;
  190. bank->sectors = malloc(sizeof(TMS470R1A384_BANK0_SECTORS));
  191. if (!bank->sectors)
  192. return ERROR_FLASH_OPERATION_FAILED;
  193. (void)memcpy(bank->sectors, TMS470R1A384_BANK0_SECTORS,
  194. sizeof(TMS470R1A384_BANK0_SECTORS));
  195. } else if ((bank->base >= 0x00020000) && (bank->base < 0x00040000)) {
  196. tms470_info->ordinal = 1;
  197. bank->base = 0x00020000;
  198. bank->size = 128 * 1024;
  199. bank->num_sectors = TMS470R1A384_BANK1_NUM_SECTORS;
  200. bank->sectors = malloc(sizeof(TMS470R1A384_BANK1_SECTORS));
  201. if (!bank->sectors)
  202. return ERROR_FLASH_OPERATION_FAILED;
  203. (void)memcpy(bank->sectors, TMS470R1A384_BANK1_SECTORS,
  204. sizeof(TMS470R1A384_BANK1_SECTORS));
  205. } else if ((bank->base >= 0x00040000) && (bank->base < 0x00060000)) {
  206. tms470_info->ordinal = 2;
  207. bank->base = 0x00040000;
  208. bank->size = 128 * 1024;
  209. bank->num_sectors = TMS470R1A384_BANK2_NUM_SECTORS;
  210. bank->sectors = malloc(sizeof(TMS470R1A384_BANK2_SECTORS));
  211. if (!bank->sectors)
  212. return ERROR_FLASH_OPERATION_FAILED;
  213. (void)memcpy(bank->sectors, TMS470R1A384_BANK2_SECTORS,
  214. sizeof(TMS470R1A384_BANK2_SECTORS));
  215. } else {
  216. LOG_ERROR("No %s flash bank contains base address 0x%08" PRIx32 ".",
  217. part_name, bank->base);
  218. return ERROR_FLASH_OPERATION_FAILED;
  219. }
  220. break;
  221. default:
  222. LOG_WARNING("Could not identify part 0x%02x as a member of the TMS470 family.",
  223. (unsigned)part_number);
  224. return ERROR_FLASH_OPERATION_FAILED;
  225. }
  226. /* turn off memory selects */
  227. target_write_u32(target, 0xFFFFFFE4, 0x00000000);
  228. target_write_u32(target, 0xFFFFFFE0, 0x00000000);
  229. bank->chip_width = 32;
  230. bank->bus_width = 32;
  231. LOG_INFO("Identified %s, ver=%d, core=%s, nvmem=%s.",
  232. part_name,
  233. (int)(silicon_version),
  234. (technology_family ? "1.8v" : "3.3v"),
  235. (rom_flash ? "rom" : "flash"));
  236. tms470_info->device_ident_reg = device_ident_reg;
  237. tms470_info->silicon_version = silicon_version;
  238. tms470_info->technology_family = technology_family;
  239. tms470_info->rom_flash = rom_flash;
  240. tms470_info->part_number = part_number;
  241. tms470_info->part_name = part_name;
  242. /*
  243. * Disable reset on address access violation.
  244. */
  245. target_write_u32(target, 0xFFFFFFE0, 0x00004007);
  246. return ERROR_OK;
  247. }
  248. /* ---------------------------------------------------------------------- */
  249. static uint32_t keysSet;
  250. static uint32_t flashKeys[4];
  251. COMMAND_HANDLER(tms470_handle_flash_keyset_command)
  252. {
  253. if (CMD_ARGC > 4)
  254. return ERROR_COMMAND_SYNTAX_ERROR;
  255. else if (CMD_ARGC == 4) {
  256. int i;
  257. for (i = 0; i < 4; i++) {
  258. int start = (0 == strncmp(CMD_ARGV[i], "0x", 2)) ? 2 : 0;
  259. if (1 != sscanf(&CMD_ARGV[i][start], "%" SCNx32 "", &flashKeys[i])) {
  260. command_print(CMD_CTX, "could not process flash key %s",
  261. CMD_ARGV[i]);
  262. LOG_ERROR("could not process flash key %s", CMD_ARGV[i]);
  263. return ERROR_COMMAND_SYNTAX_ERROR;
  264. }
  265. }
  266. keysSet = 1;
  267. } else if (CMD_ARGC != 0) {
  268. command_print(CMD_CTX, "tms470 flash_keyset <key0> <key1> <key2> <key3>");
  269. return ERROR_COMMAND_SYNTAX_ERROR;
  270. }
  271. if (keysSet) {
  272. command_print(CMD_CTX,
  273. "using flash keys 0x%08" PRIx32 ", 0x%08" PRIx32 ", 0x%08" PRIx32 ", 0x%08" PRIx32 "",
  274. flashKeys[0],
  275. flashKeys[1],
  276. flashKeys[2],
  277. flashKeys[3]);
  278. } else
  279. command_print(CMD_CTX, "flash keys not set");
  280. return ERROR_OK;
  281. }
  282. static const uint32_t FLASH_KEYS_ALL_ONES[] = { 0xFFFFFFFF, 0xFFFFFFFF,
  283. 0xFFFFFFFF, 0xFFFFFFFF,};
  284. static const uint32_t FLASH_KEYS_ALL_ZEROS[] = { 0x00000000, 0x00000000,
  285. 0x00000000, 0x00000000,};
  286. static const uint32_t FLASH_KEYS_MIX1[] = { 0xf0fff0ff, 0xf0fff0ff,
  287. 0xf0fff0ff, 0xf0fff0ff};
  288. static const uint32_t FLASH_KEYS_MIX2[] = { 0x0000ffff, 0x0000ffff,
  289. 0x0000ffff, 0x0000ffff};
  290. /* ---------------------------------------------------------------------- */
  291. static int oscMHz = 12;
  292. COMMAND_HANDLER(tms470_handle_osc_megahertz_command)
  293. {
  294. if (CMD_ARGC > 1)
  295. return ERROR_COMMAND_SYNTAX_ERROR;
  296. else if (CMD_ARGC == 1)
  297. sscanf(CMD_ARGV[0], "%d", &oscMHz);
  298. if (oscMHz <= 0) {
  299. LOG_ERROR("osc_megahertz must be positive and non-zero!");
  300. command_print(CMD_CTX, "osc_megahertz must be positive and non-zero!");
  301. oscMHz = 12;
  302. return ERROR_COMMAND_SYNTAX_ERROR;
  303. }
  304. command_print(CMD_CTX, "osc_megahertz=%d", oscMHz);
  305. return ERROR_OK;
  306. }
  307. /* ---------------------------------------------------------------------- */
  308. static int plldis;
  309. COMMAND_HANDLER(tms470_handle_plldis_command)
  310. {
  311. if (CMD_ARGC > 1)
  312. return ERROR_COMMAND_SYNTAX_ERROR;
  313. else if (CMD_ARGC == 1) {
  314. sscanf(CMD_ARGV[0], "%d", &plldis);
  315. plldis = plldis ? 1 : 0;
  316. }
  317. command_print(CMD_CTX, "plldis=%d", plldis);
  318. return ERROR_OK;
  319. }
  320. /* ---------------------------------------------------------------------- */
  321. static int tms470_check_flash_unlocked(struct target *target)
  322. {
  323. uint32_t fmbbusy;
  324. target_read_u32(target, 0xFFE89C08, &fmbbusy);
  325. LOG_INFO("tms470 fmbbusy = 0x%08" PRIx32 " -> %s",
  326. fmbbusy,
  327. fmbbusy & 0x8000 ? "unlocked" : "LOCKED");
  328. return fmbbusy & 0x8000 ? ERROR_OK : ERROR_FLASH_OPERATION_FAILED;
  329. }
  330. /* ---------------------------------------------------------------------- */
  331. static int tms470_try_flash_keys(struct target *target, const uint32_t *key_set)
  332. {
  333. uint32_t glbctrl, fmmstat;
  334. int retval = ERROR_FLASH_OPERATION_FAILED;
  335. /* set GLBCTRL.4 */
  336. target_read_u32(target, 0xFFFFFFDC, &glbctrl);
  337. target_write_u32(target, 0xFFFFFFDC, glbctrl | 0x10);
  338. /* only perform the key match when 3VSTAT is clear */
  339. target_read_u32(target, 0xFFE8BC0C, &fmmstat);
  340. if (!(fmmstat & 0x08)) {
  341. unsigned i;
  342. uint32_t fmbptr, fmbac2, orig_fmregopt;
  343. target_write_u32(target, 0xFFE8BC04, fmmstat & ~0x07);
  344. /* wait for pump ready */
  345. do {
  346. target_read_u32(target, 0xFFE8A814, &fmbptr);
  347. alive_sleep(1);
  348. } while (!(fmbptr & 0x0200));
  349. /* force max wait states */
  350. target_read_u32(target, 0xFFE88004, &fmbac2);
  351. target_write_u32(target, 0xFFE88004, fmbac2 | 0xff);
  352. /* save current access mode, force normal read mode */
  353. target_read_u32(target, 0xFFE89C00, &orig_fmregopt);
  354. target_write_u32(target, 0xFFE89C00, 0x00);
  355. for (i = 0; i < 4; i++) {
  356. uint32_t tmp;
  357. /* There is no point displaying the value of tmp, it is
  358. * filtered by the chip. The purpose of this read is to
  359. * prime the unlocking logic rather than read out the value.
  360. */
  361. target_read_u32(target, 0x00001FF0 + 4 * i, &tmp);
  362. LOG_INFO("tms470 writing fmpkey = 0x%08" PRIx32 "", key_set[i]);
  363. target_write_u32(target, 0xFFE89C0C, key_set[i]);
  364. }
  365. if (ERROR_OK == tms470_check_flash_unlocked(target)) {
  366. /*
  367. * There seems to be a side-effect of reading the FMPKEY
  368. * register in that it re-enables the protection. So we
  369. * re-enable it.
  370. */
  371. for (i = 0; i < 4; i++) {
  372. uint32_t tmp;
  373. target_read_u32(target, 0x00001FF0 + 4 * i, &tmp);
  374. target_write_u32(target, 0xFFE89C0C, key_set[i]);
  375. }
  376. retval = ERROR_OK;
  377. }
  378. /* restore settings */
  379. target_write_u32(target, 0xFFE89C00, orig_fmregopt);
  380. target_write_u32(target, 0xFFE88004, fmbac2);
  381. }
  382. /* clear config bit */
  383. target_write_u32(target, 0xFFFFFFDC, glbctrl);
  384. return retval;
  385. }
  386. /* ---------------------------------------------------------------------- */
  387. static int tms470_unlock_flash(struct flash_bank *bank)
  388. {
  389. struct target *target = bank->target;
  390. const uint32_t *p_key_sets[5];
  391. unsigned i, key_set_count;
  392. if (keysSet) {
  393. key_set_count = 5;
  394. p_key_sets[0] = flashKeys;
  395. p_key_sets[1] = FLASH_KEYS_ALL_ONES;
  396. p_key_sets[2] = FLASH_KEYS_ALL_ZEROS;
  397. p_key_sets[3] = FLASH_KEYS_MIX1;
  398. p_key_sets[4] = FLASH_KEYS_MIX2;
  399. } else {
  400. key_set_count = 4;
  401. p_key_sets[0] = FLASH_KEYS_ALL_ONES;
  402. p_key_sets[1] = FLASH_KEYS_ALL_ZEROS;
  403. p_key_sets[2] = FLASH_KEYS_MIX1;
  404. p_key_sets[3] = FLASH_KEYS_MIX2;
  405. }
  406. for (i = 0; i < key_set_count; i++) {
  407. if (tms470_try_flash_keys(target, p_key_sets[i]) == ERROR_OK) {
  408. LOG_INFO("tms470 flash is unlocked");
  409. return ERROR_OK;
  410. }
  411. }
  412. LOG_WARNING("tms470 could not unlock flash memory protection level 2");
  413. return ERROR_FLASH_OPERATION_FAILED;
  414. }
  415. /* ---------------------------------------------------------------------- */
  416. static int tms470_flash_initialize_internal_state_machine(struct flash_bank *bank)
  417. {
  418. uint32_t fmmac2, fmmac1, fmmaxep, k, delay, glbctrl, sysclk;
  419. struct target *target = bank->target;
  420. struct tms470_flash_bank *tms470_info = bank->driver_priv;
  421. int result = ERROR_OK;
  422. /*
  423. * Select the desired bank to be programmed by writing BANK[2:0] of
  424. * FMMAC2.
  425. */
  426. target_read_u32(target, 0xFFE8BC04, &fmmac2);
  427. fmmac2 &= ~0x0007;
  428. fmmac2 |= (tms470_info->ordinal & 7);
  429. target_write_u32(target, 0xFFE8BC04, fmmac2);
  430. LOG_DEBUG("set fmmac2 = 0x%04" PRIx32 "", fmmac2);
  431. /*
  432. * Disable level 1 sector protection by setting bit 15 of FMMAC1.
  433. */
  434. target_read_u32(target, 0xFFE8BC00, &fmmac1);
  435. fmmac1 |= 0x8000;
  436. target_write_u32(target, 0xFFE8BC00, fmmac1);
  437. LOG_DEBUG("set fmmac1 = 0x%04" PRIx32 "", fmmac1);
  438. /*
  439. * FMTCREG = 0x2fc0;
  440. */
  441. target_write_u32(target, 0xFFE8BC10, 0x2fc0);
  442. LOG_DEBUG("set fmtcreg = 0x2fc0");
  443. /*
  444. * MAXPP = 50
  445. */
  446. target_write_u32(target, 0xFFE8A07C, 50);
  447. LOG_DEBUG("set fmmaxpp = 50");
  448. /*
  449. * MAXCP = 0xf000 + 2000
  450. */
  451. target_write_u32(target, 0xFFE8A084, 0xf000 + 2000);
  452. LOG_DEBUG("set fmmaxcp = 0x%04x", 0xf000 + 2000);
  453. /*
  454. * configure VHV
  455. */
  456. target_read_u32(target, 0xFFE8A080, &fmmaxep);
  457. if (fmmaxep == 0xf000) {
  458. fmmaxep = 0xf000 + 4095;
  459. target_write_u32(target, 0xFFE8A80C, 0x9964);
  460. LOG_DEBUG("set fmptr3 = 0x9964");
  461. } else {
  462. fmmaxep = 0xa000 + 4095;
  463. target_write_u32(target, 0xFFE8A80C, 0x9b64);
  464. LOG_DEBUG("set fmptr3 = 0x9b64");
  465. }
  466. target_write_u32(target, 0xFFE8A080, fmmaxep);
  467. LOG_DEBUG("set fmmaxep = 0x%04" PRIx32 "", fmmaxep);
  468. /*
  469. * FMPTR4 = 0xa000
  470. */
  471. target_write_u32(target, 0xFFE8A810, 0xa000);
  472. LOG_DEBUG("set fmptr4 = 0xa000");
  473. /*
  474. * FMPESETUP, delay parameter selected based on clock frequency.
  475. *
  476. * According to the TI App Note SPNU257 and flashing code, delay is
  477. * int((sysclk(MHz) + 1) / 2), with a minimum of 5. The system
  478. * clock is usually derived from the ZPLL module, and selected by
  479. * the plldis global.
  480. */
  481. target_read_u32(target, 0xFFFFFFDC, &glbctrl);
  482. sysclk = (plldis ? 1 : (glbctrl & 0x08) ? 4 : 8) * oscMHz / (1 + (glbctrl & 7));
  483. delay = (sysclk > 10) ? (sysclk + 1) / 2 : 5;
  484. target_write_u32(target, 0xFFE8A018, (delay << 4) | (delay << 8));
  485. LOG_DEBUG("set fmpsetup = 0x%04" PRIx32 "", (delay << 4) | (delay << 8));
  486. /*
  487. * FMPVEVACCESS, based on delay.
  488. */
  489. k = delay | (delay << 8);
  490. target_write_u32(target, 0xFFE8A05C, k);
  491. LOG_DEBUG("set fmpvevaccess = 0x%04" PRIx32 "", k);
  492. /*
  493. * FMPCHOLD, FMPVEVHOLD, FMPVEVSETUP, based on delay.
  494. */
  495. k <<= 1;
  496. target_write_u32(target, 0xFFE8A034, k);
  497. LOG_DEBUG("set fmpchold = 0x%04" PRIx32 "", k);
  498. target_write_u32(target, 0xFFE8A040, k);
  499. LOG_DEBUG("set fmpvevhold = 0x%04" PRIx32 "", k);
  500. target_write_u32(target, 0xFFE8A024, k);
  501. LOG_DEBUG("set fmpvevsetup = 0x%04" PRIx32 "", k);
  502. /*
  503. * FMCVACCESS, based on delay.
  504. */
  505. k = delay * 16;
  506. target_write_u32(target, 0xFFE8A060, k);
  507. LOG_DEBUG("set fmcvaccess = 0x%04" PRIx32 "", k);
  508. /*
  509. * FMCSETUP, based on delay.
  510. */
  511. k = 0x3000 | delay * 20;
  512. target_write_u32(target, 0xFFE8A020, k);
  513. LOG_DEBUG("set fmcsetup = 0x%04" PRIx32 "", k);
  514. /*
  515. * FMEHOLD, based on delay.
  516. */
  517. k = (delay * 20) << 2;
  518. target_write_u32(target, 0xFFE8A038, k);
  519. LOG_DEBUG("set fmehold = 0x%04" PRIx32 "", k);
  520. /*
  521. * PWIDTH, CWIDTH, EWIDTH, based on delay.
  522. */
  523. target_write_u32(target, 0xFFE8A050, delay * 8);
  524. LOG_DEBUG("set fmpwidth = 0x%04" PRIx32 "", delay * 8);
  525. target_write_u32(target, 0xFFE8A058, delay * 1000);
  526. LOG_DEBUG("set fmcwidth = 0x%04" PRIx32 "", delay * 1000);
  527. target_write_u32(target, 0xFFE8A054, delay * 5400);
  528. LOG_DEBUG("set fmewidth = 0x%04" PRIx32 "", delay * 5400);
  529. return result;
  530. }
  531. /* ---------------------------------------------------------------------- */
  532. static int tms470_flash_status(struct flash_bank *bank)
  533. {
  534. struct target *target = bank->target;
  535. int result = ERROR_OK;
  536. uint32_t fmmstat;
  537. target_read_u32(target, 0xFFE8BC0C, &fmmstat);
  538. LOG_DEBUG("set fmmstat = 0x%04" PRIx32 "", fmmstat);
  539. if (fmmstat & 0x0080) {
  540. LOG_WARNING("tms470 flash command: erase still active after busy clear.");
  541. result = ERROR_FLASH_OPERATION_FAILED;
  542. }
  543. if (fmmstat & 0x0040) {
  544. LOG_WARNING("tms470 flash command: program still active after busy clear.");
  545. result = ERROR_FLASH_OPERATION_FAILED;
  546. }
  547. if (fmmstat & 0x0020) {
  548. LOG_WARNING("tms470 flash command: invalid data command.");
  549. result = ERROR_FLASH_OPERATION_FAILED;
  550. }
  551. if (fmmstat & 0x0010) {
  552. LOG_WARNING("tms470 flash command: program, erase or validate sector failed.");
  553. result = ERROR_FLASH_OPERATION_FAILED;
  554. }
  555. if (fmmstat & 0x0008) {
  556. LOG_WARNING("tms470 flash command: voltage instability detected.");
  557. result = ERROR_FLASH_OPERATION_FAILED;
  558. }
  559. if (fmmstat & 0x0006) {
  560. LOG_WARNING("tms470 flash command: command suspend detected.");
  561. result = ERROR_FLASH_OPERATION_FAILED;
  562. }
  563. if (fmmstat & 0x0001) {
  564. LOG_WARNING("tms470 flash command: sector was locked.");
  565. result = ERROR_FLASH_OPERATION_FAILED;
  566. }
  567. return result;
  568. }
  569. /* ---------------------------------------------------------------------- */
  570. static int tms470_erase_sector(struct flash_bank *bank, int sector)
  571. {
  572. uint32_t glbctrl, orig_fmregopt, fmbsea, fmbseb, fmmstat;
  573. struct target *target = bank->target;
  574. uint32_t flashAddr = bank->base + bank->sectors[sector].offset;
  575. int result = ERROR_OK;
  576. /*
  577. * Set the bit GLBCTRL4 of the GLBCTRL register (in the System
  578. * module) to enable writing to the flash registers }.
  579. */
  580. target_read_u32(target, 0xFFFFFFDC, &glbctrl);
  581. target_write_u32(target, 0xFFFFFFDC, glbctrl | 0x10);
  582. LOG_DEBUG("set glbctrl = 0x%08" PRIx32 "", glbctrl | 0x10);
  583. /* Force normal read mode. */
  584. target_read_u32(target, 0xFFE89C00, &orig_fmregopt);
  585. target_write_u32(target, 0xFFE89C00, 0);
  586. LOG_DEBUG("set fmregopt = 0x%08x", 0);
  587. (void)tms470_flash_initialize_internal_state_machine(bank);
  588. /*
  589. * Select one or more bits in FMBSEA or FMBSEB to disable Level 1
  590. * protection for the particular sector to be erased/written.
  591. */
  592. if (sector < 16) {
  593. target_read_u32(target, 0xFFE88008, &fmbsea);
  594. target_write_u32(target, 0xFFE88008, fmbsea | (1 << sector));
  595. LOG_DEBUG("set fmbsea = 0x%04" PRIx32 "", fmbsea | (1 << sector));
  596. } else {
  597. target_read_u32(target, 0xFFE8800C, &fmbseb);
  598. target_write_u32(target, 0xFFE8800C, fmbseb | (1 << (sector - 16)));
  599. LOG_DEBUG("set fmbseb = 0x%04" PRIx32 "", fmbseb | (1 << (sector - 16)));
  600. }
  601. bank->sectors[sector].is_protected = 0;
  602. /*
  603. * clear status regiser, sent erase command, kickoff erase
  604. */
  605. target_write_u16(target, flashAddr, 0x0040);
  606. LOG_DEBUG("write *(uint16_t *)0x%08" PRIx32 "=0x0040", flashAddr);
  607. target_write_u16(target, flashAddr, 0x0020);
  608. LOG_DEBUG("write *(uint16_t *)0x%08" PRIx32 "=0x0020", flashAddr);
  609. target_write_u16(target, flashAddr, 0xffff);
  610. LOG_DEBUG("write *(uint16_t *)0x%08" PRIx32 "=0xffff", flashAddr);
  611. /*
  612. * Monitor FMMSTAT, busy until clear, then check and other flags for
  613. * ultimate result of the operation.
  614. */
  615. do {
  616. target_read_u32(target, 0xFFE8BC0C, &fmmstat);
  617. if (fmmstat & 0x0100)
  618. alive_sleep(1);
  619. } while (fmmstat & 0x0100);
  620. result = tms470_flash_status(bank);
  621. if (sector < 16) {
  622. target_write_u32(target, 0xFFE88008, fmbsea);
  623. LOG_DEBUG("set fmbsea = 0x%04" PRIx32 "", fmbsea);
  624. bank->sectors[sector].is_protected = fmbsea & (1 << sector) ? 0 : 1;
  625. } else {
  626. target_write_u32(target, 0xFFE8800C, fmbseb);
  627. LOG_DEBUG("set fmbseb = 0x%04" PRIx32 "", fmbseb);
  628. bank->sectors[sector].is_protected = fmbseb & (1 << (sector - 16)) ? 0 : 1;
  629. }
  630. target_write_u32(target, 0xFFE89C00, orig_fmregopt);
  631. LOG_DEBUG("set fmregopt = 0x%08" PRIx32 "", orig_fmregopt);
  632. target_write_u32(target, 0xFFFFFFDC, glbctrl);
  633. LOG_DEBUG("set glbctrl = 0x%08" PRIx32 "", glbctrl);
  634. if (result == ERROR_OK)
  635. bank->sectors[sector].is_erased = 1;
  636. return result;
  637. }
  638. /*----------------------------------------------------------------------
  639. * Implementation of Flash Driver Interfaces
  640. *---------------------------------------------------------------------- */
  641. static const struct command_registration tms470_any_command_handlers[] = {
  642. {
  643. .name = "flash_keyset",
  644. .usage = "<key0> <key1> <key2> <key3>",
  645. .handler = tms470_handle_flash_keyset_command,
  646. .mode = COMMAND_ANY,
  647. .help = "tms470 flash_keyset <key0> <key1> <key2> <key3>",
  648. },
  649. {
  650. .name = "osc_megahertz",
  651. .usage = "<MHz>",
  652. .handler = tms470_handle_osc_megahertz_command,
  653. .mode = COMMAND_ANY,
  654. .help = "tms470 osc_megahertz <MHz>",
  655. },
  656. {
  657. .name = "plldis",
  658. .usage = "<0 | 1>",
  659. .handler = tms470_handle_plldis_command,
  660. .mode = COMMAND_ANY,
  661. .help = "tms470 plldis <0/1>",
  662. },
  663. COMMAND_REGISTRATION_DONE
  664. };
  665. static const struct command_registration tms470_command_handlers[] = {
  666. {
  667. .name = "tms470",
  668. .mode = COMMAND_ANY,
  669. .help = "TI tms470 flash command group",
  670. .usage = "",
  671. .chain = tms470_any_command_handlers,
  672. },
  673. COMMAND_REGISTRATION_DONE
  674. };
  675. /* ---------------------------------------------------------------------- */
  676. static int tms470_erase(struct flash_bank *bank, int first, int last)
  677. {
  678. struct tms470_flash_bank *tms470_info = bank->driver_priv;
  679. int sector, result = ERROR_OK;
  680. if (bank->target->state != TARGET_HALTED) {
  681. LOG_ERROR("Target not halted");
  682. return ERROR_TARGET_NOT_HALTED;
  683. }
  684. tms470_read_part_info(bank);
  685. if ((first < 0) || (first >= bank->num_sectors) || (last < 0) ||
  686. (last >= bank->num_sectors) || (first > last)) {
  687. LOG_ERROR("Sector range %d to %d invalid.", first, last);
  688. return ERROR_FLASH_SECTOR_INVALID;
  689. }
  690. result = tms470_unlock_flash(bank);
  691. if (result != ERROR_OK)
  692. return result;
  693. for (sector = first; sector <= last; sector++) {
  694. LOG_INFO("Erasing tms470 bank %d sector %d...", tms470_info->ordinal, sector);
  695. result = tms470_erase_sector(bank, sector);
  696. if (result != ERROR_OK) {
  697. LOG_ERROR("tms470 could not erase flash sector.");
  698. break;
  699. } else
  700. LOG_INFO("sector erased successfully.");
  701. }
  702. return result;
  703. }
  704. /* ---------------------------------------------------------------------- */
  705. static int tms470_protect(struct flash_bank *bank, int set, int first, int last)
  706. {
  707. struct tms470_flash_bank *tms470_info = bank->driver_priv;
  708. struct target *target = bank->target;
  709. uint32_t fmmac2, fmbsea, fmbseb;
  710. int sector;
  711. if (target->state != TARGET_HALTED) {
  712. LOG_ERROR("Target not halted");
  713. return ERROR_TARGET_NOT_HALTED;
  714. }
  715. tms470_read_part_info(bank);
  716. if ((first < 0) || (first >= bank->num_sectors) || (last < 0) ||
  717. (last >= bank->num_sectors) || (first > last)) {
  718. LOG_ERROR("Sector range %d to %d invalid.", first, last);
  719. return ERROR_FLASH_SECTOR_INVALID;
  720. }
  721. /* enable the appropriate bank */
  722. target_read_u32(target, 0xFFE8BC04, &fmmac2);
  723. target_write_u32(target, 0xFFE8BC04, (fmmac2 & ~7) | tms470_info->ordinal);
  724. /* get the original sector proection flags for this bank */
  725. target_read_u32(target, 0xFFE88008, &fmbsea);
  726. target_read_u32(target, 0xFFE8800C, &fmbseb);
  727. for (sector = 0; sector < bank->num_sectors; sector++) {
  728. if (sector < 16) {
  729. fmbsea = set ? fmbsea & ~(1 << sector) : fmbsea | (1 << sector);
  730. bank->sectors[sector].is_protected = set ? 1 : 0;
  731. } else {
  732. fmbseb = set ? fmbseb &
  733. ~(1 << (sector - 16)) : fmbseb | (1 << (sector - 16));
  734. bank->sectors[sector].is_protected = set ? 1 : 0;
  735. }
  736. }
  737. /* update the protection bits */
  738. target_write_u32(target, 0xFFE88008, fmbsea);
  739. target_write_u32(target, 0xFFE8800C, fmbseb);
  740. return ERROR_OK;
  741. }
  742. /* ---------------------------------------------------------------------- */
  743. static int tms470_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
  744. {
  745. struct target *target = bank->target;
  746. uint32_t glbctrl, fmbac2, orig_fmregopt, fmbsea, fmbseb, fmmaxpp, fmmstat;
  747. int result = ERROR_OK;
  748. uint32_t i;
  749. if (target->state != TARGET_HALTED) {
  750. LOG_ERROR("Target not halted");
  751. return ERROR_TARGET_NOT_HALTED;
  752. }
  753. tms470_read_part_info(bank);
  754. LOG_INFO("Writing %" PRId32 " bytes starting at 0x%08" PRIx32 "", count, bank->base +
  755. offset);
  756. /* set GLBCTRL.4 */
  757. target_read_u32(target, 0xFFFFFFDC, &glbctrl);
  758. target_write_u32(target, 0xFFFFFFDC, glbctrl | 0x10);
  759. (void)tms470_flash_initialize_internal_state_machine(bank);
  760. /* force max wait states */
  761. target_read_u32(target, 0xFFE88004, &fmbac2);
  762. target_write_u32(target, 0xFFE88004, fmbac2 | 0xff);
  763. /* save current access mode, force normal read mode */
  764. target_read_u32(target, 0xFFE89C00, &orig_fmregopt);
  765. target_write_u32(target, 0xFFE89C00, 0x00);
  766. /*
  767. * Disable Level 1 protection for all sectors to be erased/written.
  768. */
  769. target_read_u32(target, 0xFFE88008, &fmbsea);
  770. target_write_u32(target, 0xFFE88008, 0xffff);
  771. target_read_u32(target, 0xFFE8800C, &fmbseb);
  772. target_write_u32(target, 0xFFE8800C, 0xffff);
  773. /* read MAXPP */
  774. target_read_u32(target, 0xFFE8A07C, &fmmaxpp);
  775. for (i = 0; i < count; i += 2) {
  776. uint32_t addr = bank->base + offset + i;
  777. uint16_t word = (((uint16_t) buffer[i]) << 8) | (uint16_t) buffer[i + 1];
  778. if (word != 0xffff) {
  779. LOG_INFO("writing 0x%04x at 0x%08" PRIx32 "", word, addr);
  780. /* clear status register */
  781. target_write_u16(target, addr, 0x0040);
  782. /* program flash command */
  783. target_write_u16(target, addr, 0x0010);
  784. /* burn the 16-bit word (big-endian) */
  785. target_write_u16(target, addr, word);
  786. /*
  787. * Monitor FMMSTAT, busy until clear, then check and other flags
  788. * for ultimate result of the operation.
  789. */
  790. do {
  791. target_read_u32(target, 0xFFE8BC0C, &fmmstat);
  792. if (fmmstat & 0x0100)
  793. alive_sleep(1);
  794. } while (fmmstat & 0x0100);
  795. if (fmmstat & 0x3ff) {
  796. LOG_ERROR("fmstat = 0x%04" PRIx32 "", fmmstat);
  797. LOG_ERROR(
  798. "Could not program word 0x%04x at address 0x%08" PRIx32 ".",
  799. word,
  800. addr);
  801. result = ERROR_FLASH_OPERATION_FAILED;
  802. break;
  803. }
  804. } else
  805. LOG_INFO("skipping 0xffff at 0x%08" PRIx32 "", addr);
  806. }
  807. /* restore */
  808. target_write_u32(target, 0xFFE88008, fmbsea);
  809. target_write_u32(target, 0xFFE8800C, fmbseb);
  810. target_write_u32(target, 0xFFE88004, fmbac2);
  811. target_write_u32(target, 0xFFE89C00, orig_fmregopt);
  812. target_write_u32(target, 0xFFFFFFDC, glbctrl);
  813. return result;
  814. }
  815. /* ---------------------------------------------------------------------- */
  816. static int tms470_probe(struct flash_bank *bank)
  817. {
  818. if (bank->target->state != TARGET_HALTED) {
  819. LOG_WARNING("Cannot communicate... target not halted.");
  820. return ERROR_TARGET_NOT_HALTED;
  821. }
  822. return tms470_read_part_info(bank);
  823. }
  824. static int tms470_auto_probe(struct flash_bank *bank)
  825. {
  826. struct tms470_flash_bank *tms470_info = bank->driver_priv;
  827. if (tms470_info->device_ident_reg)
  828. return ERROR_OK;
  829. return tms470_probe(bank);
  830. }
  831. /* ---------------------------------------------------------------------- */
  832. static int tms470_erase_check(struct flash_bank *bank)
  833. {
  834. struct target *target = bank->target;
  835. struct tms470_flash_bank *tms470_info = bank->driver_priv;
  836. int sector, result = ERROR_OK;
  837. uint32_t fmmac2, fmbac2, glbctrl, orig_fmregopt;
  838. static uint8_t buffer[64 * 1024];
  839. if (target->state != TARGET_HALTED) {
  840. LOG_ERROR("Target not halted");
  841. return ERROR_TARGET_NOT_HALTED;
  842. }
  843. if (!tms470_info->device_ident_reg)
  844. tms470_read_part_info(bank);
  845. /* set GLBCTRL.4 */
  846. target_read_u32(target, 0xFFFFFFDC, &glbctrl);
  847. target_write_u32(target, 0xFFFFFFDC, glbctrl | 0x10);
  848. /* save current access mode, force normal read mode */
  849. target_read_u32(target, 0xFFE89C00, &orig_fmregopt);
  850. target_write_u32(target, 0xFFE89C00, 0x00);
  851. /* enable the appropriate bank */
  852. target_read_u32(target, 0xFFE8BC04, &fmmac2);
  853. target_write_u32(target, 0xFFE8BC04, (fmmac2 & ~7) | tms470_info->ordinal);
  854. /* TCR = 0 */
  855. target_write_u32(target, 0xFFE8BC10, 0x2fc0);
  856. /* clear TEZ in fmbrdy */
  857. target_write_u32(target, 0xFFE88010, 0x0b);
  858. /* save current wait states, force max */
  859. target_read_u32(target, 0xFFE88004, &fmbac2);
  860. target_write_u32(target, 0xFFE88004, fmbac2 | 0xff);
  861. /*
  862. * The TI primitives inspect the flash memory by reading one 32-bit
  863. * word at a time. Here we read an entire sector and inspect it in
  864. * an attempt to reduce the JTAG overhead.
  865. */
  866. for (sector = 0; sector < bank->num_sectors; sector++) {
  867. if (bank->sectors[sector].is_erased != 1) {
  868. uint32_t i, addr = bank->base + bank->sectors[sector].offset;
  869. LOG_INFO("checking flash bank %d sector %d", tms470_info->ordinal, sector);
  870. target_read_buffer(target, addr, bank->sectors[sector].size, buffer);
  871. bank->sectors[sector].is_erased = 1;
  872. for (i = 0; i < bank->sectors[sector].size; i++) {
  873. if (buffer[i] != 0xff) {
  874. LOG_WARNING("tms470 bank %d, sector %d, not erased.",
  875. tms470_info->ordinal,
  876. sector);
  877. LOG_WARNING(
  878. "at location 0x%08" PRIx32 ": flash data is 0x%02x.",
  879. addr + i,
  880. buffer[i]);
  881. bank->sectors[sector].is_erased = 0;
  882. break;
  883. }
  884. }
  885. }
  886. if (bank->sectors[sector].is_erased != 1) {
  887. result = ERROR_FLASH_SECTOR_NOT_ERASED;
  888. break;
  889. } else
  890. LOG_INFO("sector erased");
  891. }
  892. /* reset TEZ, wait states, read mode, GLBCTRL.4 */
  893. target_write_u32(target, 0xFFE88010, 0x0f);
  894. target_write_u32(target, 0xFFE88004, fmbac2);
  895. target_write_u32(target, 0xFFE89C00, orig_fmregopt);
  896. target_write_u32(target, 0xFFFFFFDC, glbctrl);
  897. return result;
  898. }
  899. /* ---------------------------------------------------------------------- */
  900. static int tms470_protect_check(struct flash_bank *bank)
  901. {
  902. struct target *target = bank->target;
  903. struct tms470_flash_bank *tms470_info = bank->driver_priv;
  904. int sector, result = ERROR_OK;
  905. uint32_t fmmac2, fmbsea, fmbseb;
  906. if (target->state != TARGET_HALTED) {
  907. LOG_ERROR("Target not halted");
  908. return ERROR_TARGET_NOT_HALTED;
  909. }
  910. if (!tms470_info->device_ident_reg)
  911. tms470_read_part_info(bank);
  912. /* enable the appropriate bank */
  913. target_read_u32(target, 0xFFE8BC04, &fmmac2);
  914. target_write_u32(target, 0xFFE8BC04, (fmmac2 & ~7) | tms470_info->ordinal);
  915. target_read_u32(target, 0xFFE88008, &fmbsea);
  916. target_read_u32(target, 0xFFE8800C, &fmbseb);
  917. for (sector = 0; sector < bank->num_sectors; sector++) {
  918. int protected;
  919. if (sector < 16) {
  920. protected = fmbsea & (1 << sector) ? 0 : 1;
  921. bank->sectors[sector].is_protected = protected;
  922. } else {
  923. protected = fmbseb & (1 << (sector - 16)) ? 0 : 1;
  924. bank->sectors[sector].is_protected = protected;
  925. }
  926. LOG_DEBUG("bank %d sector %d is %s",
  927. tms470_info->ordinal,
  928. sector,
  929. protected ? "protected" : "not protected");
  930. }
  931. return result;
  932. }
  933. /* ---------------------------------------------------------------------- */
  934. static int get_tms470_info(struct flash_bank *bank, char *buf, int buf_size)
  935. {
  936. int used = 0;
  937. struct tms470_flash_bank *tms470_info = bank->driver_priv;
  938. if (!tms470_info->device_ident_reg)
  939. tms470_read_part_info(bank);
  940. if (!tms470_info->device_ident_reg) {
  941. (void)snprintf(buf, buf_size, "Cannot identify target as a TMS470\n");
  942. return ERROR_FLASH_OPERATION_FAILED;
  943. }
  944. used =
  945. snprintf(buf, buf_size, "\ntms470 information: Chip is %s\n",
  946. tms470_info->part_name);
  947. buf += used;
  948. buf_size -= used;
  949. snprintf(buf, buf_size, "Flash protection level 2 is %s\n",
  950. tms470_check_flash_unlocked(bank->target) == ERROR_OK ? "disabled" : "enabled");
  951. return ERROR_OK;
  952. }
  953. /* ---------------------------------------------------------------------- */
  954. /*
  955. * flash bank tms470 <base> <size> <chip_width> <bus_width> <target>
  956. * [options...]
  957. */
  958. FLASH_BANK_COMMAND_HANDLER(tms470_flash_bank_command)
  959. {
  960. bank->driver_priv = malloc(sizeof(struct tms470_flash_bank));
  961. if (!bank->driver_priv)
  962. return ERROR_FLASH_OPERATION_FAILED;
  963. (void)memset(bank->driver_priv, 0, sizeof(struct tms470_flash_bank));
  964. return ERROR_OK;
  965. }
  966. struct flash_driver tms470_flash = {
  967. .name = "tms470",
  968. .commands = tms470_command_handlers,
  969. .flash_bank_command = tms470_flash_bank_command,
  970. .erase = tms470_erase,
  971. .protect = tms470_protect,
  972. .write = tms470_write,
  973. .read = default_flash_read,
  974. .probe = tms470_probe,
  975. .auto_probe = tms470_auto_probe,
  976. .erase_check = tms470_erase_check,
  977. .protect_check = tms470_protect_check,
  978. .info = get_tms470_info,
  979. };