88 #define PART_ID_REG 0x50000000
89 #define IPRSTC1 0x50000008
90 #define REGLOCKADDR 0x50000100
91 #define ISPCON 0x5000C000
92 #define ISPADR 0x5000C004
93 #define ISPDAT 0x5000C008
94 #define ISPCMD 0x5000C00C
95 #define ISPTRG 0x5000C010
97 #define ISPUNKNOWN 0x5000C01C
99 #define IPRSTC_CPU_RST 0x02
101 #define ISPCON_ISPFF 0x40
102 #define ISPCON_LDUEN 0x20
103 #define ISPCON_CFGUEN 0x10
104 #define ISPCON_APUEN 0x08
105 #define ISPCON_BS_LDROM 0x02
106 #define ISPCON_ISPEN 0x01
108 #define ISPCMD_READ 0x00
109 #define ISPCMD_PROGRAM 0x21
110 #define ISPCMD_ERASE 0x22
111 #define ISPCMD_CHIP_ERASE 0x26
113 #define ISPTRG_ISPGO 0x01
115 #define MINI51_APROM_BASE 0x00000000
116 #define MINI51_DATA_BASE 0x0001F000
117 #define MINI51_LDROM_BASE 0x00100000
118 #define MINI51_CONFIG_BASE 0x00300000
120 #define MINI51_KB 1024
121 #define MINI51_PAGE_SIZE 512
122 #define MINI51_TIMEOUT 1000
125 #define ENSURE_OK(status) if (status != ERROR_OK) return status
127 #define MINI51_MAX_FLASH_BANKS 4
141 #define MINI51_BANKS_MINI51(aprom_size) \
143 { {MINI51_APROM_BASE, (aprom_size)}, {MINI51_LDROM_BASE, 2*1024}, {MINI51_CONFIG_BASE, 512} }
145 #define MINI51_BANKS_M051(aprom_size) \
147 { {MINI51_APROM_BASE, (aprom_size)}, {MINI51_DATA_BASE, 4*1024}, {MINI51_LDROM_BASE, 4*1024}, \
148 {MINI51_CONFIG_BASE, 1024} }
214 LOG_INFO(
"device id = 0x%08" PRIx32
"", *part_id);
226 for (
size_t i = 0; i <
sizeof(
mini51_cpu)/
sizeof(mini51_cpu[0]); i++) {
227 if (part_id == mini51_cpu[i].
ppid) {
228 *cpu = &mini51_cpu[i];
229 LOG_INFO(
"device name = %s", (*cpu)->name);
239 for (
size_t i = 0; i < cpu->
n_banks; i++) {
242 LOG_INFO(
"bank base = 0x%08" PRIx32
", size = 0x%08" PRIx32
"", bank->
base, *flash_size);
267 LOG_WARNING(
"Mini51 flash driver: Timeout executing flash command\n");
275 LOG_WARNING(
"Mini51 flash driver: operation failed\n");
337 mini51_info->
probed =
false;
338 bank->driver_priv = mini51_info;
345 LOG_WARNING(
"Mini51 flash driver: protect_check not implemented yet\n");
356 if ((offset & 0x3) || (count & 0x3)) {
357 LOG_WARNING(
"Mini51 flash driver: unaligned access not supported\n");
364 for (uint32_t i = offset; i < offset +
count; i += 4) {
366 memcpy(buffer, &ispdat,
sizeof(ispdat));
368 buffer +=
sizeof(ispdat);
384 for (
int page_start = first; page_start <= last; page_start++) {
396 LOG_WARNING(
"Mini51 flash driver: protect operation not implemented yet\n");
407 if ((offset & 0x3) || (count & 0x3)) {
408 LOG_WARNING(
"Mini51 flash driver: unaligned access not supported\n");
415 for (uint32_t i = offset; i < offset +
count; i += 4) {
416 memcpy(&ispdat, buffer,
sizeof(ispdat));
419 buffer +=
sizeof(ispdat);
436 LOG_WARNING(
"Mini51 flash driver: Failed to detect a known part\n");
442 LOG_WARNING(
"Mini51 flash driver: Failed to detect flash size\n");
450 bank->
size = flash_size;
452 for (
int i = 0; i < num_pages; i++) {
461 mini51_info->
probed =
true;
492 LOG_INFO(
"0x%08" PRIx32
": 0x%08" PRIx32, address, ispdat);
514 LOG_INFO(
"0x%08" PRIx32
": 0x%08" PRIx32, address, ispdat);
540 .handler = mini51_handle_read_isp_command,
543 .help =
"read flash through ISP.",
547 .handler = mini51_handle_write_isp_command,
548 .usage =
"address value",
550 .help =
"write flash through ISP.",
553 .name =
"chip_erase",
554 .handler = mini51_handle_chip_erase_command,
556 .help =
"chip erase.",
565 .help =
"mini51 flash command group",
575 .flash_bank_command = mini51_flash_bank_command,