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.
 
 
 
 
 
 

690 lines
19 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  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 "lpc2000.h"
  24. #include "flash.h"
  25. #include "target.h"
  26. #include "log.h"
  27. #include "armv4_5.h"
  28. #include "algorithm.h"
  29. #include "binarybuffer.h"
  30. #include <stdlib.h>
  31. #include <string.h>
  32. /* flash programming support for Philips LPC2xxx devices
  33. * currently supported devices:
  34. * variant 1 (lpc2000_v1):
  35. * - 2104|5|6
  36. * - 2114|9
  37. * - 2124|9
  38. * - 2194
  39. * - 2212|4
  40. * - 2292|4
  41. *
  42. * variant 2 (lpc2000_v2):
  43. * - 213x
  44. * - 214x
  45. */
  46. int lpc2000_register_commands(struct command_context_s *cmd_ctx);
  47. int lpc2000_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
  48. int lpc2000_erase(struct flash_bank_s *bank, int first, int last);
  49. int lpc2000_protect(struct flash_bank_s *bank, int set, int first, int last);
  50. int lpc2000_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
  51. int lpc2000_probe(struct flash_bank_s *bank);
  52. int lpc2000_erase_check(struct flash_bank_s *bank);
  53. int lpc2000_protect_check(struct flash_bank_s *bank);
  54. int lpc2000_info(struct flash_bank_s *bank, char *buf, int buf_size);
  55. int lpc2000_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  56. flash_driver_t lpc2000_flash =
  57. {
  58. .name = "lpc2000",
  59. .register_commands = lpc2000_register_commands,
  60. .flash_bank_command = lpc2000_flash_bank_command,
  61. .erase = lpc2000_erase,
  62. .protect = lpc2000_protect,
  63. .write = lpc2000_write,
  64. .probe = lpc2000_probe,
  65. .erase_check = lpc2000_erase_check,
  66. .protect_check = lpc2000_protect_check,
  67. .info = lpc2000_info
  68. };
  69. int lpc2000_register_commands(struct command_context_s *cmd_ctx)
  70. {
  71. command_t *lpc2000_cmd = register_command(cmd_ctx, NULL, "lpc2000", NULL, COMMAND_ANY, NULL);
  72. register_command(cmd_ctx, lpc2000_cmd, "part_id", lpc2000_handle_part_id_command, COMMAND_EXEC,
  73. "print part id of lpc2000 flash bank <num>");
  74. return ERROR_OK;
  75. }
  76. int lpc2000_build_sector_list(struct flash_bank_s *bank)
  77. {
  78. lpc2000_flash_bank_t *lpc2000_info = bank->driver_priv;
  79. if (lpc2000_info->variant == 1)
  80. {
  81. int i = 0;
  82. u32 offset = 0;
  83. /* variant 1 has different layout for 128kb and 256kb flashes */
  84. if (bank->size == 128 * 1024)
  85. {
  86. bank->num_sectors = 16;
  87. bank->sectors = malloc(sizeof(flash_sector_t) * 16);
  88. for (i = 0; i < 16; i++)
  89. {
  90. bank->sectors[i].offset = offset;
  91. bank->sectors[i].size = 8 * 1024;
  92. offset += bank->sectors[i].size;
  93. bank->sectors[i].is_erased = -1;
  94. bank->sectors[i].is_protected = 1;
  95. }
  96. }
  97. else if (bank->size == 256 * 1024)
  98. {
  99. bank->num_sectors = 18;
  100. bank->sectors = malloc(sizeof(flash_sector_t) * 18);
  101. for (i = 0; i < 8; i++)
  102. {
  103. bank->sectors[i].offset = offset;
  104. bank->sectors[i].size = 8 * 1024;
  105. offset += bank->sectors[i].size;
  106. bank->sectors[i].is_erased = -1;
  107. bank->sectors[i].is_protected = 1;
  108. }
  109. for (i = 8; i < 10; i++)
  110. {
  111. bank->sectors[i].offset = offset;
  112. bank->sectors[i].size = 64 * 1024;
  113. offset += bank->sectors[i].size;
  114. bank->sectors[i].is_erased = -1;
  115. bank->sectors[i].is_protected = 1;
  116. }
  117. for (i = 10; i < 18; i++)
  118. {
  119. bank->sectors[i].offset = offset;
  120. bank->sectors[i].size = 8 * 1024;
  121. offset += bank->sectors[i].size;
  122. bank->sectors[i].is_erased = -1;
  123. bank->sectors[i].is_protected = 1;
  124. }
  125. }
  126. else
  127. {
  128. ERROR("BUG: unknown bank->size encountered");
  129. exit(-1);
  130. }
  131. }
  132. else if (lpc2000_info->variant == 2)
  133. {
  134. int num_sectors;
  135. int i;
  136. u32 offset = 0;
  137. /* variant 2 has a uniform layout, only number of sectors differs */
  138. switch (bank->size)
  139. {
  140. case 32 * 1024:
  141. num_sectors = 8;
  142. break;
  143. case 64 * 1024:
  144. num_sectors = 9;
  145. break;
  146. case 128 * 1024:
  147. num_sectors = 11;
  148. break;
  149. case 256 * 1024:
  150. num_sectors = 15;
  151. break;
  152. case 500 * 1024:
  153. num_sectors = 27;
  154. break;
  155. default:
  156. ERROR("BUG: unknown bank->size encountered");
  157. exit(-1);
  158. break;
  159. }
  160. bank->num_sectors = num_sectors;
  161. bank->sectors = malloc(sizeof(flash_sector_t) * num_sectors);
  162. for (i = 0; i < num_sectors; i++)
  163. {
  164. if ((i >= 0) && (i < 8))
  165. {
  166. bank->sectors[i].offset = offset;
  167. bank->sectors[i].size = 4 * 1024;
  168. offset += bank->sectors[i].size;
  169. bank->sectors[i].is_erased = -1;
  170. bank->sectors[i].is_protected = 1;
  171. }
  172. if ((i >= 8) && (i < 22))
  173. {
  174. bank->sectors[i].offset = offset;
  175. bank->sectors[i].size = 32 * 1024;
  176. offset += bank->sectors[i].size;
  177. bank->sectors[i].is_erased = -1;
  178. bank->sectors[i].is_protected = 1;
  179. }
  180. if ((i >= 22) && (i < 27))
  181. {
  182. bank->sectors[i].offset = offset;
  183. bank->sectors[i].size = 4 * 1024;
  184. offset += bank->sectors[i].size;
  185. bank->sectors[i].is_erased = -1;
  186. bank->sectors[i].is_protected = 1;
  187. }
  188. }
  189. }
  190. else
  191. {
  192. ERROR("BUG: unknown lpc2000_info->variant encountered");
  193. exit(-1);
  194. }
  195. return ERROR_OK;
  196. }
  197. /* call LPC2000 IAP function
  198. * uses 172 bytes working area
  199. * 0x0 to 0x7: jump gate (BX to thumb state, b -2 to wait)
  200. * 0x8 to 0x1f: command parameter table
  201. * 0x20 to 0x2b: command result table
  202. * 0x2c to 0xac: stack (only 128b needed)
  203. */
  204. int lpc2000_iap_call(flash_bank_t *bank, int code, u32 param_table[5], u32 result_table[2])
  205. {
  206. lpc2000_flash_bank_t *lpc2000_info = bank->driver_priv;
  207. target_t *target = lpc2000_info->target;
  208. mem_param_t mem_params[2];
  209. reg_param_t reg_params[5];
  210. armv4_5_algorithm_t armv4_5_info;
  211. u32 status_code;
  212. /* regrab previously allocated working_area, or allocate a new one */
  213. if (!lpc2000_info->iap_working_area)
  214. {
  215. u8 jump_gate[8];
  216. /* make sure we have a working area */
  217. if (target_alloc_working_area(target, 172, &lpc2000_info->iap_working_area) != ERROR_OK)
  218. {
  219. ERROR("no working area specified, can't write LPC2000 internal flash");
  220. return ERROR_FLASH_OPERATION_FAILED;
  221. }
  222. /* write IAP code to working area */
  223. target_buffer_set_u32(target, jump_gate, ARMV4_5_BX(12));
  224. target_buffer_set_u32(target, jump_gate + 4, ARMV4_5_B(0xfffffe, 0));
  225. target->type->write_memory(target, lpc2000_info->iap_working_area->address, 4, 2, jump_gate);
  226. }
  227. armv4_5_info.common_magic = ARMV4_5_COMMON_MAGIC;
  228. armv4_5_info.core_mode = ARMV4_5_MODE_SVC;
  229. armv4_5_info.core_state = ARMV4_5_STATE_ARM;
  230. /* command parameter table */
  231. init_mem_param(&mem_params[0], lpc2000_info->iap_working_area->address + 8, 4 * 6, PARAM_OUT);
  232. target_buffer_set_u32(target, mem_params[0].value, code);
  233. target_buffer_set_u32(target, mem_params[0].value + 0x4, param_table[0]);
  234. target_buffer_set_u32(target, mem_params[0].value + 0x8, param_table[1]);
  235. target_buffer_set_u32(target, mem_params[0].value + 0xc, param_table[2]);
  236. target_buffer_set_u32(target, mem_params[0].value + 0x10, param_table[3]);
  237. target_buffer_set_u32(target, mem_params[0].value + 0x14, param_table[4]);
  238. init_reg_param(&reg_params[0], "r0", 32, PARAM_OUT);
  239. buf_set_u32(reg_params[0].value, 0, 32, lpc2000_info->iap_working_area->address + 0x8);
  240. /* command result table */
  241. init_mem_param(&mem_params[1], lpc2000_info->iap_working_area->address + 0x20, 4 * 3, PARAM_IN);
  242. init_reg_param(&reg_params[1], "r1", 32, PARAM_OUT);
  243. buf_set_u32(reg_params[1].value, 0, 32, lpc2000_info->iap_working_area->address + 0x20);
  244. /* IAP entry point */
  245. init_reg_param(&reg_params[2], "r12", 32, PARAM_OUT);
  246. buf_set_u32(reg_params[2].value, 0, 32, 0x7ffffff1);
  247. /* IAP stack */
  248. init_reg_param(&reg_params[3], "r13_svc", 32, PARAM_OUT);
  249. buf_set_u32(reg_params[3].value, 0, 32, lpc2000_info->iap_working_area->address + 0xac);
  250. /* return address */
  251. init_reg_param(&reg_params[4], "lr_svc", 32, PARAM_OUT);
  252. buf_set_u32(reg_params[4].value, 0, 32, lpc2000_info->iap_working_area->address + 0x4);
  253. target->type->run_algorithm(target, 2, mem_params, 5, reg_params, lpc2000_info->iap_working_area->address, lpc2000_info->iap_working_area->address + 0x4, 10000, &armv4_5_info);
  254. status_code = buf_get_u32(mem_params[1].value, 0, 32);
  255. result_table[0] = target_buffer_get_u32(target, mem_params[1].value);
  256. result_table[1] = target_buffer_get_u32(target, mem_params[1].value + 4);
  257. destroy_mem_param(&mem_params[0]);
  258. destroy_mem_param(&mem_params[1]);
  259. destroy_reg_param(&reg_params[0]);
  260. destroy_reg_param(&reg_params[1]);
  261. destroy_reg_param(&reg_params[2]);
  262. destroy_reg_param(&reg_params[3]);
  263. destroy_reg_param(&reg_params[4]);
  264. return status_code;
  265. }
  266. int lpc2000_iap_blank_check(struct flash_bank_s *bank, int first, int last)
  267. {
  268. u32 param_table[5];
  269. u32 result_table[2];
  270. int status_code;
  271. int i;
  272. if ((first < 0) || (last > bank->num_sectors))
  273. return ERROR_FLASH_SECTOR_INVALID;
  274. for (i = first; i <= last; i++)
  275. {
  276. /* check single sector */
  277. param_table[0] = param_table[1] = i;
  278. status_code = lpc2000_iap_call(bank, 53, param_table, result_table);
  279. switch (status_code)
  280. {
  281. case ERROR_FLASH_OPERATION_FAILED:
  282. return ERROR_FLASH_OPERATION_FAILED;
  283. case LPC2000_CMD_SUCCESS:
  284. bank->sectors[i].is_erased = 1;
  285. break;
  286. case LPC2000_SECTOR_NOT_BLANK:
  287. bank->sectors[i].is_erased = 0;
  288. break;
  289. case LPC2000_INVALID_SECTOR:
  290. bank->sectors[i].is_erased = 0;
  291. break;
  292. case LPC2000_BUSY:
  293. return ERROR_FLASH_BUSY;
  294. break;
  295. default:
  296. ERROR("BUG: unknown LPC2000 status code");
  297. exit(-1);
  298. }
  299. }
  300. return ERROR_OK;
  301. }
  302. /* flash_bank lpc2000 <base> <size> 0 0 <lpc_variant> <target#> <cclk> [calc_checksum]
  303. */
  304. int lpc2000_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
  305. {
  306. lpc2000_flash_bank_t *lpc2000_info;
  307. if (argc < 8)
  308. {
  309. WARNING("incomplete flash_bank lpc2000 configuration");
  310. return ERROR_FLASH_BANK_INVALID;
  311. }
  312. lpc2000_info = malloc(sizeof(lpc2000_flash_bank_t));
  313. bank->driver_priv = lpc2000_info;
  314. if (strcmp(args[5], "lpc2000_v1") == 0)
  315. {
  316. lpc2000_info->variant = 1;
  317. lpc2000_info->cmd51_dst_boundary = 512;
  318. lpc2000_info->cmd51_can_256b = 0;
  319. lpc2000_info->cmd51_can_8192b = 1;
  320. }
  321. else if (strcmp(args[5], "lpc2000_v2") == 0)
  322. {
  323. lpc2000_info->variant = 2;
  324. lpc2000_info->cmd51_dst_boundary = 256;
  325. lpc2000_info->cmd51_can_256b = 1;
  326. lpc2000_info->cmd51_can_8192b = 0;
  327. }
  328. else
  329. {
  330. ERROR("unknown LPC2000 variant");
  331. free(lpc2000_info);
  332. return ERROR_FLASH_BANK_INVALID;
  333. }
  334. lpc2000_info->target = get_target_by_num(strtoul(args[6], NULL, 0));
  335. if (!lpc2000_info->target)
  336. {
  337. ERROR("no target '%s' configured", args[6]);
  338. exit(-1);
  339. }
  340. lpc2000_info->iap_working_area = NULL;
  341. lpc2000_info->cclk = strtoul(args[7], NULL, 0);
  342. lpc2000_info->calc_checksum = 0;
  343. lpc2000_build_sector_list(bank);
  344. if (argc >= 9)
  345. {
  346. if (strcmp(args[8], "calc_checksum") == 0)
  347. lpc2000_info->calc_checksum = 1;
  348. }
  349. return ERROR_OK;
  350. }
  351. int lpc2000_erase(struct flash_bank_s *bank, int first, int last)
  352. {
  353. lpc2000_flash_bank_t *lpc2000_info = bank->driver_priv;
  354. u32 param_table[5];
  355. u32 result_table[2];
  356. int status_code;
  357. if (lpc2000_info->target->state != TARGET_HALTED)
  358. {
  359. return ERROR_TARGET_NOT_HALTED;
  360. }
  361. if ((first < 0) || (last < first) || (last >= bank->num_sectors))
  362. {
  363. return ERROR_FLASH_SECTOR_INVALID;
  364. }
  365. param_table[0] = first;
  366. param_table[1] = last;
  367. param_table[2] = lpc2000_info->cclk;
  368. /* Prepare sectors */
  369. status_code = lpc2000_iap_call(bank, 50, param_table, result_table);
  370. switch (status_code)
  371. {
  372. case ERROR_FLASH_OPERATION_FAILED:
  373. return ERROR_FLASH_OPERATION_FAILED;
  374. case LPC2000_CMD_SUCCESS:
  375. break;
  376. case LPC2000_INVALID_SECTOR:
  377. return ERROR_FLASH_SECTOR_INVALID;
  378. break;
  379. default:
  380. WARNING("lpc2000 prepare sectors returned %i", status_code);
  381. return ERROR_FLASH_OPERATION_FAILED;
  382. }
  383. /* Erase sectors */
  384. status_code = lpc2000_iap_call(bank, 52, param_table, result_table);
  385. switch (status_code)
  386. {
  387. case ERROR_FLASH_OPERATION_FAILED:
  388. return ERROR_FLASH_OPERATION_FAILED;
  389. case LPC2000_CMD_SUCCESS:
  390. break;
  391. case LPC2000_INVALID_SECTOR:
  392. return ERROR_FLASH_SECTOR_INVALID;
  393. break;
  394. default:
  395. WARNING("lpc2000 erase sectors returned %i", status_code);
  396. return ERROR_FLASH_OPERATION_FAILED;
  397. }
  398. return ERROR_OK;
  399. }
  400. int lpc2000_protect(struct flash_bank_s *bank, int set, int first, int last)
  401. {
  402. /* can't protect/unprotect on the lpc2000 */
  403. return ERROR_OK;
  404. }
  405. int lpc2000_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
  406. {
  407. lpc2000_flash_bank_t *lpc2000_info = bank->driver_priv;
  408. target_t *target = lpc2000_info->target;
  409. u32 dst_min_alignment;
  410. u32 bytes_remaining = count;
  411. u32 bytes_written = 0;
  412. int first_sector = 0;
  413. int last_sector = 0;
  414. u32 param_table[5];
  415. u32 result_table[2];
  416. int status_code;
  417. int i;
  418. working_area_t *download_area;
  419. if (lpc2000_info->target->state != TARGET_HALTED)
  420. {
  421. return ERROR_TARGET_NOT_HALTED;
  422. }
  423. /* allocate a working area */
  424. if (target_alloc_working_area(target, 4096, &download_area) != ERROR_OK)
  425. {
  426. ERROR("no working area specified, can't write LPC2000 internal flash");
  427. return ERROR_FLASH_OPERATION_FAILED;
  428. }
  429. if (offset + count > bank->size)
  430. return ERROR_FLASH_DST_OUT_OF_BANK;
  431. if (lpc2000_info->cmd51_can_256b)
  432. dst_min_alignment = 256;
  433. else
  434. dst_min_alignment = 512;
  435. if (offset % dst_min_alignment)
  436. {
  437. WARNING("offset 0x%x breaks required alignment 0x%x", offset, dst_min_alignment);
  438. return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
  439. }
  440. for (i = 0; i < bank->num_sectors; i++)
  441. {
  442. if (offset >= bank->sectors[i].offset)
  443. first_sector = i;
  444. if (offset + CEIL(count, dst_min_alignment) * dst_min_alignment > bank->sectors[i].offset)
  445. last_sector = i;
  446. }
  447. DEBUG("first_sector: %i, last_sector: %i", first_sector, last_sector);
  448. /* check if exception vectors should be flashed */
  449. if ((offset == 0) && (count >= 0x20) && lpc2000_info->calc_checksum)
  450. {
  451. u32 checksum = 0;
  452. int i = 0;
  453. for (i = 0; i < 8; i++)
  454. {
  455. DEBUG("0x%2.2x: 0x%8.8x", i * 4, buf_get_u32(buffer + (i * 4), 0, 32));
  456. if (i != 5)
  457. checksum += buf_get_u32(buffer + (i * 4), 0, 32);
  458. }
  459. checksum = 0 - checksum;
  460. DEBUG("checksum: 0x%8.8x", checksum);
  461. buf_set_u32(buffer + 0x14, 0, 32, checksum);
  462. }
  463. while (bytes_remaining > 0)
  464. {
  465. u32 thisrun_bytes;
  466. if (bytes_remaining >= 4096)
  467. thisrun_bytes = 4096;
  468. else if (bytes_remaining >= 1024)
  469. thisrun_bytes = 1024;
  470. else if ((bytes_remaining >= 512) || (!lpc2000_info->cmd51_can_256b))
  471. thisrun_bytes = 512;
  472. else
  473. thisrun_bytes = 256;
  474. /* Prepare sectors */
  475. param_table[0] = first_sector;
  476. param_table[1] = last_sector;
  477. status_code = lpc2000_iap_call(bank, 50, param_table, result_table);
  478. switch (status_code)
  479. {
  480. case ERROR_FLASH_OPERATION_FAILED:
  481. return ERROR_FLASH_OPERATION_FAILED;
  482. case LPC2000_CMD_SUCCESS:
  483. break;
  484. case LPC2000_INVALID_SECTOR:
  485. return ERROR_FLASH_SECTOR_INVALID;
  486. break;
  487. default:
  488. WARNING("lpc2000 prepare sectors returned %i", status_code);
  489. return ERROR_FLASH_OPERATION_FAILED;
  490. }
  491. if (bytes_remaining >= thisrun_bytes)
  492. {
  493. if (target_write_buffer(lpc2000_info->target, download_area->address, thisrun_bytes, buffer + bytes_written) != ERROR_OK)
  494. {
  495. target_free_working_area(target, download_area);
  496. return ERROR_FLASH_OPERATION_FAILED;
  497. }
  498. }
  499. else
  500. {
  501. u8 *last_buffer = malloc(thisrun_bytes);
  502. int i;
  503. memcpy(last_buffer, buffer + bytes_written, bytes_remaining);
  504. for (i = bytes_remaining; i < thisrun_bytes; i++)
  505. last_buffer[i] = 0xff;
  506. target_write_buffer(lpc2000_info->target, download_area->address, thisrun_bytes, last_buffer);
  507. free(last_buffer);
  508. }
  509. DEBUG("writing 0x%x bytes to address 0x%x", thisrun_bytes, bank->base + offset + bytes_written);
  510. /* Write data */
  511. param_table[0] = bank->base + offset + bytes_written;
  512. param_table[1] = download_area->address;
  513. param_table[2] = thisrun_bytes;
  514. param_table[3] = lpc2000_info->cclk;
  515. status_code = lpc2000_iap_call(bank, 51, param_table, result_table);
  516. switch (status_code)
  517. {
  518. case ERROR_FLASH_OPERATION_FAILED:
  519. return ERROR_FLASH_OPERATION_FAILED;
  520. case LPC2000_CMD_SUCCESS:
  521. break;
  522. case LPC2000_INVALID_SECTOR:
  523. return ERROR_FLASH_SECTOR_INVALID;
  524. break;
  525. default:
  526. WARNING("lpc2000 returned %i", status_code);
  527. return ERROR_FLASH_OPERATION_FAILED;
  528. }
  529. if (bytes_remaining > thisrun_bytes)
  530. bytes_remaining -= thisrun_bytes;
  531. else
  532. bytes_remaining = 0;
  533. bytes_written += thisrun_bytes;
  534. }
  535. target_free_working_area(target, download_area);
  536. return ERROR_OK;
  537. }
  538. int lpc2000_probe(struct flash_bank_s *bank)
  539. {
  540. /* we can't probe on an lpc2000
  541. * if this is an lpc2xxx, it has the configured flash
  542. */
  543. return ERROR_OK;
  544. }
  545. int lpc2000_erase_check(struct flash_bank_s *bank)
  546. {
  547. lpc2000_flash_bank_t *lpc2000_info = bank->driver_priv;
  548. if (lpc2000_info->target->state != TARGET_HALTED)
  549. {
  550. return ERROR_TARGET_NOT_HALTED;
  551. }
  552. return lpc2000_iap_blank_check(bank, 0, bank->num_sectors - 1);
  553. }
  554. int lpc2000_protect_check(struct flash_bank_s *bank)
  555. {
  556. /* sectors are always protected */
  557. return ERROR_OK;
  558. }
  559. int lpc2000_info(struct flash_bank_s *bank, char *buf, int buf_size)
  560. {
  561. lpc2000_flash_bank_t *lpc2000_info = bank->driver_priv;
  562. snprintf(buf, buf_size, "lpc2000 flash driver variant: %i, clk: %i", lpc2000_info->variant, lpc2000_info->cclk);
  563. return ERROR_OK;
  564. }
  565. int lpc2000_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  566. {
  567. flash_bank_t *bank;
  568. u32 param_table[5];
  569. u32 result_table[2];
  570. int status_code;
  571. lpc2000_flash_bank_t *lpc2000_info;
  572. if (argc < 1)
  573. {
  574. command_print(cmd_ctx, "usage: lpc2000 part_id <num>");
  575. return ERROR_OK;
  576. }
  577. bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
  578. if (!bank)
  579. {
  580. command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
  581. return ERROR_OK;
  582. }
  583. lpc2000_info = bank->driver_priv;
  584. if (lpc2000_info->target->state != TARGET_HALTED)
  585. {
  586. return ERROR_TARGET_NOT_HALTED;
  587. }
  588. if ((status_code = lpc2000_iap_call(bank, 54, param_table, result_table)) != 0x0)
  589. {
  590. if (status_code == ERROR_FLASH_OPERATION_FAILED)
  591. {
  592. command_print(cmd_ctx, "no sufficient working area specified, can't access LPC2000 IAP interface");
  593. return ERROR_OK;
  594. }
  595. command_print(cmd_ctx, "lpc2000 IAP returned status code %i", status_code);
  596. }
  597. else
  598. {
  599. command_print(cmd_ctx, "lpc2000 part id: 0x%8.8x", result_table[0]);
  600. }
  601. return ERROR_OK;
  602. }