73 #define FCF_ADDRESS 0x00000400
77 #define FCF_FDPROT 0xf
80 #define FLEXRAM 0x14000000
82 #define MSCM_OCMDR0 0x40001400
83 #define MSCM_OCMDR1 0x40001404
84 #define FMC_PFB01CR 0x4001f004
85 #define FTFX_FSTAT 0x40020000
86 #define FTFX_FCNFG 0x40020001
87 #define FTFX_FCCOB3 0x40020004
88 #define FTFX_FPROT3 0x40020010
89 #define FTFX_FDPROT 0x40020017
90 #define SIM_BASE 0x40047000
91 #define SIM_BASE_KL28 0x40074000
92 #define SIM_COPC 0x40048100
94 #define WDOG_BASE 0x40052000
95 #define WDOG32_KE1X 0x40052000
96 #define WDOG32_KL28 0x40076000
97 #define SMC_PMCTRL 0x4007E001
98 #define SMC_PMSTAT 0x4007E003
99 #define SMC32_PMCTRL 0x4007E00C
100 #define SMC32_PMSTAT 0x4007E014
101 #define PMC_REGSC 0x4007D002
102 #define MC_PMCTRL 0x4007E003
103 #define MCM_PLACR 0xF000300C
106 #define SIM_SOPT1_OFFSET 0x0000
107 #define SIM_SDID_OFFSET 0x1024
108 #define SIM_FCFG1_OFFSET 0x104c
109 #define SIM_FCFG2_OFFSET 0x1050
111 #define WDOG_STCTRLH_OFFSET 0
112 #define WDOG32_CS_OFFSET 0
115 #define PM_STAT_RUN 0x01
116 #define PM_STAT_VLPR 0x04
117 #define PM_CTRL_RUNM_RUN 0x00
120 #define FTFX_CMD_BLOCKSTAT 0x00
121 #define FTFX_CMD_SECTSTAT 0x01
122 #define FTFX_CMD_LWORDPROG 0x06
123 #define FTFX_CMD_SECTERASE 0x09
124 #define FTFX_CMD_SECTWRITE 0x0b
125 #define FTFX_CMD_MASSERASE 0x44
126 #define FTFX_CMD_PGMPART 0x80
127 #define FTFX_CMD_SETFLEXRAM 0x81
149 #define KINETIS_SOPT1_RAMSIZE_MASK 0x0000F000
150 #define KINETIS_SOPT1_RAMSIZE_K24FN1M 0x0000B000
152 #define KINETIS_SDID_K_SERIES_MASK 0x0000FFFF
154 #define KINETIS_SDID_DIEID_MASK 0x00000F80
156 #define KINETIS_SDID_DIEID_K22FN128 0x00000680
157 #define KINETIS_SDID_DIEID_K22FN256 0x00000A80
158 #define KINETIS_SDID_DIEID_K22FN512 0x00000E80
159 #define KINETIS_SDID_DIEID_K24FN256 0x00000700
161 #define KINETIS_SDID_DIEID_K24FN1M 0x00000300
168 #define KINETIS_K_SDID_TYPE_MASK 0x00000FF0
169 #define KINETIS_K_SDID_K10_M50 0x00000000
170 #define KINETIS_K_SDID_K10_M72 0x00000080
171 #define KINETIS_K_SDID_K10_M100 0x00000100
172 #define KINETIS_K_SDID_K10_M120 0x00000180
173 #define KINETIS_K_SDID_K11 0x00000220
174 #define KINETIS_K_SDID_K12 0x00000200
175 #define KINETIS_K_SDID_K20_M50 0x00000010
176 #define KINETIS_K_SDID_K20_M72 0x00000090
177 #define KINETIS_K_SDID_K20_M100 0x00000110
178 #define KINETIS_K_SDID_K20_M120 0x00000190
179 #define KINETIS_K_SDID_K21_M50 0x00000230
180 #define KINETIS_K_SDID_K21_M120 0x00000330
181 #define KINETIS_K_SDID_K22_M50 0x00000210
182 #define KINETIS_K_SDID_K22_M120 0x00000310
183 #define KINETIS_K_SDID_K30_M72 0x000000A0
184 #define KINETIS_K_SDID_K30_M100 0x00000120
185 #define KINETIS_K_SDID_K40_M72 0x000000B0
186 #define KINETIS_K_SDID_K40_M100 0x00000130
187 #define KINETIS_K_SDID_K50_M72 0x000000E0
188 #define KINETIS_K_SDID_K51_M72 0x000000F0
189 #define KINETIS_K_SDID_K53 0x00000170
190 #define KINETIS_K_SDID_K60_M100 0x00000140
191 #define KINETIS_K_SDID_K60_M150 0x000001C0
192 #define KINETIS_K_SDID_K70_M150 0x000001D0
194 #define KINETIS_K_REVID_MASK 0x0000F000
195 #define KINETIS_K_REVID_SHIFT 12
197 #define KINETIS_SDID_SERIESID_MASK 0x00F00000
198 #define KINETIS_SDID_SERIESID_K 0x00000000
199 #define KINETIS_SDID_SERIESID_KL 0x00100000
200 #define KINETIS_SDID_SERIESID_KE 0x00200000
201 #define KINETIS_SDID_SERIESID_KW 0x00500000
202 #define KINETIS_SDID_SERIESID_KV 0x00600000
204 #define KINETIS_SDID_SUBFAMID_SHIFT 24
205 #define KINETIS_SDID_SUBFAMID_MASK 0x0F000000
206 #define KINETIS_SDID_SUBFAMID_KX0 0x00000000
207 #define KINETIS_SDID_SUBFAMID_KX1 0x01000000
208 #define KINETIS_SDID_SUBFAMID_KX2 0x02000000
209 #define KINETIS_SDID_SUBFAMID_KX3 0x03000000
210 #define KINETIS_SDID_SUBFAMID_KX4 0x04000000
211 #define KINETIS_SDID_SUBFAMID_KX5 0x05000000
212 #define KINETIS_SDID_SUBFAMID_KX6 0x06000000
213 #define KINETIS_SDID_SUBFAMID_KX7 0x07000000
214 #define KINETIS_SDID_SUBFAMID_KX8 0x08000000
216 #define KINETIS_SDID_FAMILYID_SHIFT 28
217 #define KINETIS_SDID_FAMILYID_MASK 0xF0000000
218 #define KINETIS_SDID_FAMILYID_K0X 0x00000000
219 #define KINETIS_SDID_FAMILYID_K1X 0x10000000
220 #define KINETIS_SDID_FAMILYID_K2X 0x20000000
221 #define KINETIS_SDID_FAMILYID_K3X 0x30000000
222 #define KINETIS_SDID_FAMILYID_K4X 0x40000000
223 #define KINETIS_SDID_FAMILYID_K5X 0x50000000
224 #define KINETIS_SDID_FAMILYID_K6X 0x60000000
225 #define KINETIS_SDID_FAMILYID_K7X 0x70000000
226 #define KINETIS_SDID_FAMILYID_K8X 0x80000000
227 #define KINETIS_SDID_FAMILYID_KL8X 0x90000000
230 #define KINETIS_SDID_PROJECTID_MASK KINETIS_SDID_DIEID_MASK
231 #define KINETIS_SDID_PROJECTID_KE1XF 0x00000080
232 #define KINETIS_SDID_PROJECTID_KE1XZ 0x00000100
244 #define KINETIS_SDID_S32K_SERIES_MASK 0xFF000000
245 #define KINETIS_SDID_S32K_SERIES_K11X 0x11000000
246 #define KINETIS_SDID_S32K_SERIES_K14X 0x14000000
248 #define KINETIS_SDID_S32K_DERIVATE_MASK 0x00F00000
249 #define KINETIS_SDID_S32K_DERIVATE_KXX2 0x00200000
250 #define KINETIS_SDID_S32K_DERIVATE_KXX3 0x00300000
251 #define KINETIS_SDID_S32K_DERIVATE_KXX4 0x00400000
252 #define KINETIS_SDID_S32K_DERIVATE_KXX5 0x00500000
253 #define KINETIS_SDID_S32K_DERIVATE_KXX6 0x00600000
254 #define KINETIS_SDID_S32K_DERIVATE_KXX8 0x00800000
256 #define KINETIS_SDID_S32K_FEATURE_CSEC 0x00000080
278 #define KINETIS_MAX_BANKS 4u
389 #define MDM_REG_STAT 0x00
390 #define MDM_REG_CTRL 0x04
391 #define MDM_REG_ID 0xfc
393 #define MDM_STAT_FMEACK (1<<0)
394 #define MDM_STAT_FREADY (1<<1)
395 #define MDM_STAT_SYSSEC (1<<2)
396 #define MDM_STAT_SYSRES (1<<3)
397 #define MDM_STAT_FMEEN (1<<5)
398 #define MDM_STAT_BACKDOOREN (1<<6)
399 #define MDM_STAT_LPEN (1<<7)
400 #define MDM_STAT_VLPEN (1<<8)
401 #define MDM_STAT_LLSMODEXIT (1<<9)
402 #define MDM_STAT_VLLSXMODEXIT (1<<10)
403 #define MDM_STAT_CORE_HALTED (1<<16)
404 #define MDM_STAT_CORE_SLEEPDEEP (1<<17)
405 #define MDM_STAT_CORESLEEPING (1<<18)
407 #define MDM_CTRL_FMEIP (1<<0)
408 #define MDM_CTRL_DBG_DIS (1<<1)
409 #define MDM_CTRL_DBG_REQ (1<<2)
410 #define MDM_CTRL_SYS_RES_REQ (1<<3)
411 #define MDM_CTRL_CORE_HOLD_RES (1<<4)
412 #define MDM_CTRL_VLLSX_DBG_REQ (1<<5)
413 #define MDM_CTRL_VLLSX_DBG_ACK (1<<6)
414 #define MDM_CTRL_VLLSX_STAT_ACK (1<<7)
416 #define MDM_ACCESS_TIMEOUT 500
444 LOG_DEBUG(
"MDM: failed to queue a write request");
470 LOG_DEBUG(
"MDM: failed to queue a read request");
487 uint32_t
mask, uint32_t value, uint32_t timeout_ms)
491 int64_t ms_timeout =
timeval_ms() + timeout_ms;
522 LOG_ERROR(
"Cannot perform halt with a high-level adapter");
535 LOG_DEBUG(
"MDM: failed to read MDM_REG_STAT");
552 LOG_DEBUG(
"MDM: halt succeeded after %d attempts.", tries);
565 LOG_ERROR(
"MDM: failed to clear MDM_REG_CTRL");
582 LOG_ERROR(
"Cannot perform reset with a high-level adapter");
588 LOG_ERROR(
"MDM: failed to write MDM_REG_CTRL");
594 LOG_ERROR(
"MDM: failed to assert reset");
600 LOG_ERROR(
"MDM: failed to clear MDM_REG_CTRL");
622 LOG_ERROR(
"Cannot perform mass erase with a high-level adapter");
642 if (retval !=
ERROR_OK && !has_srst) {
643 LOG_ERROR(
"MDM: failed to assert reset");
644 goto deassert_reset_and_exit;
661 int cnt_mass_erase_disabled = 0;
664 bool man_reset_requested =
false;
670 if (!man_reset_requested && ms_elapsed > 100) {
671 LOG_INFO(
"MDM: Press RESET button now if possible.");
672 man_reset_requested =
true;
675 if (ms_elapsed > 3000) {
676 LOG_ERROR(
"MDM: waiting for mass erase conditions timed out.");
677 LOG_INFO(
"Mass erase of a secured MCU is not possible without hardware reset.");
678 LOG_INFO(
"Connect SRST, use 'reset_config srst_only' and retry.");
679 goto deassert_reset_and_exit;
689 cnt_mass_erase_disabled++;
690 if (cnt_mass_erase_disabled > 10) {
691 LOG_ERROR(
"MDM: mass erase is disabled");
692 goto deassert_reset_and_exit;
702 }
while (cnt_ready < 32);
711 LOG_ERROR(
"MDM: failed to start mass erase");
712 goto deassert_reset_and_exit;
724 goto deassert_reset_and_exit;
742 LOG_ERROR(
"MDM: failed to clear MDM_REG_CTRL");
748 deassert_reset_and_exit:
774 LOG_WARNING(
"Cannot check flash security status with a high-level adapter");
790 LOG_ERROR(
"MDM: failed to read ID register");
817 LOG_ERROR(
"MDM: failed to read MDM_REG_STAT");
828 int secured_score = 0, flash_not_ready_score = 0;
838 for (
unsigned int i = 0; i < 32; i++) {
845 LOG_DEBUG(
"MDM: dap_run failed when validating secured state");
848 for (
unsigned int i = 0; i < 32; i++) {
852 flash_not_ready_score++;
856 if (flash_not_ready_score <= 8 && secured_score > 24) {
859 LOG_WARNING(
"*********** ATTENTION! ATTENTION! ATTENTION! ATTENTION! **********");
861 LOG_WARNING(
"**** Your Kinetis MCU is in secured state, which means that, ****");
862 LOG_WARNING(
"**** with exception for very basic communication, JTAG/SWD ****");
863 LOG_WARNING(
"**** interface will NOT work. In order to restore its ****");
864 LOG_WARNING(
"**** functionality please issue 'kinetis mdm mass_erase' ****");
865 LOG_WARNING(
"**** command, power cycle the MCU and restart OpenOCD. ****");
867 LOG_WARNING(
"*********** ATTENTION! ATTENTION! ATTENTION! ATTENTION! **********");
869 }
else if (flash_not_ready_score > 24) {
871 LOG_WARNING(
"**** Your Kinetis MCU is probably locked-up in RESET/WDOG loop. ****");
872 LOG_WARNING(
"**** Common reason is a blank flash (at least a reset vector). ****");
873 LOG_WARNING(
"**** Issue 'kinetis mdm halt' command or if SRST is connected ****");
874 LOG_WARNING(
"**** and configured, use 'reset halt' ****");
875 LOG_WARNING(
"**** If MCU cannot be halted, it is likely secured and running ****");
876 LOG_WARNING(
"**** in RESET/WDOG loop. Issue 'kinetis mdm mass_erase' ****");
879 LOG_INFO(
"MDM: Chip is unsecured. Continuing.");
912 return (sim_fcfg1 >> shift) & 0x0f;
917 for (
int i = 0; i < argc; i++) {
918 if (strcmp(argv[i],
"-sim-base") == 0) {
921 }
else if (strcmp(argv[i],
"-s32k") == 0) {
924 LOG_ERROR(
"Unsupported flash bank option %s", argv[i]);
991 unsigned int num_blocks;
994 char base_name[69],
name[87], num[11];
1005 strncpy(base_name,
bank->name,
sizeof(base_name) - 1);
1006 base_name[
sizeof(base_name) - 1] =
'\0';
1007 p = strstr(base_name,
".pflash");
1012 snprintf(
name,
sizeof(
name),
"%s.pflash0", base_name);
1019 base_name[
sizeof(base_name) - 1] =
'\0';
1020 p = strstr(base_name,
".cpu");
1025 for (
unsigned int bank_idx = 1; bank_idx < num_blocks; bank_idx++) {
1026 k_bank = &(k_chip->
banks[bank_idx]);
1034 if (bank_idx < k_chip->num_pflash_blocks) {
1037 snprintf(num,
sizeof(num),
"%u", bank_idx);
1041 snprintf(num,
sizeof(num),
"%u",
1051 bank->default_padded_value =
bank->erased_value = 0xff;
1054 snprintf(
name,
sizeof(
name),
"%s.%s%s",
1055 base_name,
class, num);
1098 wdog_algorithm->
address + code_size - 2,
1104 LOG_ERROR(
"Error executing Kinetis WDOG unlock algorithm");
1121 static const uint8_t kinetis_unlock_wdog_code[] = {
1122 #include "../../../contrib/loaders/watchdog/armv7m_kinetis_wdog.inc"
1129 if ((wdog & 0x1) == 0) {
1133 LOG_INFO(
"Disabling Kinetis watchdog (initial WDOG_STCTRLH = 0x%04" PRIx16
")", wdog);
1143 LOG_INFO(
"WDOG_STCTRLH = 0x%04" PRIx16, wdog);
1152 static const uint8_t kinetis_unlock_wdog_code[] = {
1153 #include "../../../contrib/loaders/watchdog/armv7m_kinetis_wdog32.inc"
1160 if ((wdog_cs & 0x80) == 0)
1163 LOG_INFO(
"Disabling Kinetis watchdog (initial WDOG_CS 0x%08" PRIx32
")", wdog_cs);
1173 if ((wdog_cs & 0x80) == 0)
1176 LOG_ERROR(
"Cannot disable Kinetis watchdog (WDOG_CS 0x%08" PRIx32
"), issue 'reset init'", wdog_cs);
1199 case KINETIS_WDOG_K:
1202 case KINETIS_WDOG_COP:
1207 if ((sim_copc & 0xc) == 0)
1210 LOG_INFO(
"Disabling Kinetis watchdog (initial SIM_COPC 0x%02" PRIx8
")", sim_copc);
1219 if ((sim_copc & 0xc) == 0)
1222 LOG_ERROR(
"Cannot disable Kinetis watchdog (SIM_COPC 0x%02" PRIx8
"), issue 'reset init'", sim_copc);
1225 case KINETIS_WDOG32_KE1X:
1228 case KINETIS_WDOG32_KL28:
1254 LOG_ERROR(
"Flash operation failed, illegal command");
1257 }
else if (fstat & 0x10)
1258 LOG_ERROR(
"Flash operation failed, protection violated");
1260 else if (fstat & 0x40)
1261 LOG_ERROR(
"Flash operation failed, read collision");
1263 else if (fstat & 0x80)
1285 for (
unsigned int i = 0; i < 50; i++) {
1294 if ((fstat & 0x80) == 0) {
1298 if (fstat != 0x80) {
1307 #include "../../../contrib/loaders/flash/kinetis/kinetis_flash.inc"
1312 uint32_t
offset, uint32_t wcount)
1320 uint32_t end_address;
1329 LOG_WARNING(
"no working area available, can't do block memory writes");
1341 LOG_WARNING(
"large enough working area not available, can't do block memory writes");
1349 LOG_ERROR(
"allocating working area failed");
1376 end_address =
buf_get_u32(reg_params[0].value, 0, 32);
1378 LOG_ERROR(
"Error writing flash at %08" PRIx32, end_address);
1388 LOG_ERROR(
"Error executing kinetis Flash programming algorithm");
1406 LOG_ERROR(
"Protection setting is possible with 'kinetis fcf_source protection' only!");
1410 if (!
bank->prot_blocks ||
bank->num_prot_blocks == 0) {
1411 LOG_ERROR(
"No protection possible for current bank!");
1415 for (
unsigned int i = first; i <
bank->num_prot_blocks && i <= last; i++)
1416 bank->prot_blocks[i].is_protected = set;
1418 LOG_INFO(
"Protection bits will be written at the next FCF sector erase or write.");
1419 LOG_INFO(
"Do not issue 'flash info' command until protection is written,");
1420 LOG_INFO(
"doing so would re-read protection status from MCU.");
1452 LOG_ERROR(
"Protection checks for FlexRAM not supported");
1457 for (
unsigned int i = 0; i <
bank->num_prot_blocks; i++) {
1458 if ((fprot >> b) & 1)
1459 bank->prot_blocks[i].is_protected = 0;
1461 bank->prot_blocks[i].is_protected = 1;
1472 uint32_t fprot = 0xffffffff;
1473 uint8_t fsec = 0xfe;
1474 uint8_t fdprot = 0xff;
1475 unsigned int num_blocks;
1476 uint32_t pflash_bit;
1490 for (
unsigned int bank_idx = 0; bank_idx < num_blocks; bank_idx++) {
1491 k_bank = &(k_chip->
banks[bank_idx]);
1492 bank_iter = k_bank->
bank;
1495 LOG_WARNING(
"Missing bank %u configuration, FCF protection flags may be incomplete", bank_idx);
1503 LOG_ERROR(
"BUG: PFLASH bank %u has no protection blocks",
1506 LOG_DEBUG(
"skipping FLEX_NVM bank %u with no prot blocks (EE bkp only)",
1513 LOG_ERROR(
"BUG: bank %u has NULL protection blocks array",
1521 fprot &= ~pflash_bit;
1529 fdprot &= ~dflash_bit;
1545 uint8_t fccob4, uint8_t fccob5, uint8_t fccob6, uint8_t fccob7,
1546 uint8_t fccob8, uint8_t fccob9, uint8_t fccoba, uint8_t fccobb,
1547 uint8_t *ftfx_fstat)
1549 uint8_t
command[12] = {faddr & 0xff, (faddr >> 8) & 0xff, (faddr >> 16) & 0xff, fcmd,
1550 fccob7, fccob6, fccob5, fccob4,
1551 fccobb, fccoba, fccob9, fccob8};
1578 *ftfx_fstat = fstat;
1580 if ((fstat & 0xf0) != 0x80) {
1581 LOG_DEBUG(
"ftfx command failed FSTAT: %02X FCCOB: %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X",
1606 *pmstat = stat32 & 0xff;
1649 LOG_INFO(
"Switching from VLPR to RUN mode.");
1667 for (
unsigned int i = 100; i > 0; i--) {
1677 LOG_ERROR(
"Flash operation not possible in current run mode: SMC_PMSTAT: 0x%x", pmstat);
1678 LOG_ERROR(
"Issue a 'reset init' command.");
1688 case KINETIS_CACHE_K:
1694 case KINETIS_CACHE_L:
1699 case KINETIS_CACHE_MSCM:
1704 case KINETIS_CACHE_MSCM2:
1732 if ((first >
bank->num_sectors) || (last >
bank->num_sectors))
1740 for (
unsigned int i = first; i <= last; i++) {
1743 0, 0, 0, 0, 0, 0, 0, 0,
NULL);
1754 LOG_WARNING(
"Flash Configuration Field erased, DO NOT reset or power off the device");
1755 LOG_WARNING(
"until correct FCF is programmed or MCU gets security lock.");
1762 LOG_WARNING(
"Flash Configuration Field write failed");
1784 if (ftfx_fcnfg & (1 << 1))
1789 0, 0, 0, 0, 0, 0, 0, 0,
NULL);
1798 if (ftfx_fcnfg & (1 << 1))
1811 uint8_t *buffer_aligned =
NULL;
1818 uint32_t prog_section_chunk_bytes = k_bank->
sector_size >> 8;
1822 uint32_t
size = prog_size_bytes -
offset % prog_size_bytes;
1823 uint32_t align_begin =
offset % prog_section_chunk_bytes;
1825 uint32_t size_aligned;
1826 uint16_t chunk_count;
1832 align_end = (align_begin +
size) % prog_section_chunk_bytes;
1834 align_end = prog_section_chunk_bytes - align_end;
1836 size_aligned = align_begin +
size + align_end;
1837 chunk_count = size_aligned / prog_section_chunk_bytes;
1839 if (
size != size_aligned) {
1841 if (!buffer_aligned)
1842 buffer_aligned = malloc(prog_size_bytes);
1844 memset(buffer_aligned, 0xff, size_aligned);
1845 memcpy(buffer_aligned + align_begin,
buffer,
size);
1848 4, size_aligned / 4, buffer_aligned);
1852 bank->base +
offset, align_begin, align_end);
1855 4, size_aligned / 4,
buffer);
1862 LOG_ERROR(
"target_write_memory failed");
1869 chunk_count>>8, chunk_count, 0, 0,
1870 0, 0, 0, 0, &ftfx_fstat);
1878 if (ftfx_fstat & 0x01) {
1883 LOG_ERROR(
"Flash write immediately after the end of Flash Config Field shows error");
1884 LOG_ERROR(
"because the flash memory is 256 bits wide (data were written correctly).");
1885 LOG_ERROR(
"Either change the linker script to add a gap of 16 bytes after FCF");
1886 LOG_ERROR(
"or set 'kinetis fcf_source write'");
1897 free(buffer_aligned);
1906 bool fallback =
false;
1913 LOG_INFO(
"This device supports Program Longword execution only.");
1918 LOG_WARNING(
"FlexRAM not ready, fallback to slow longword write.");
1929 uint8_t *new_buffer =
NULL;
1933 LOG_ERROR(
"offset 0x%" PRIx32
" breaks the required alignment",
offset);
1938 uint32_t old_count =
count;
1939 count = (old_count | 3) + 1;
1940 new_buffer = malloc(
count);
1942 LOG_ERROR(
"odd number of bytes to write and no memory "
1943 "for padding buffer");
1946 LOG_INFO(
"odd number of bytes to write (%" PRIu32
"), extending to %" PRIu32
" "
1947 "and padding with 0xff", old_count,
count);
1948 memset(new_buffer + old_count, 0xff,
count - old_count);
1952 uint32_t words_remaining =
count / 4;
1962 LOG_WARNING(
"couldn't use block writes, falling back to single "
1965 while (words_remaining) {
1972 0, 0, 0, 0, &ftfx_fstat);
1980 if (ftfx_fstat & 0x01)
1993 LOG_ERROR(
"Flash write strategy not implemented");
2006 bool set_fcf =
false;
2007 bool fcf_in_data_valid =
false;
2008 bool fcf_differs =
false;
2029 if (offset < bank->sectors[sect].
offset +
bank->sectors[sect].size
2039 if (fcf_in_data_valid) {
2041 if (memcmp(fcf_in_data, fcf_buffer, 8)) {
2043 LOG_INFO(
"Setting of backdoor key is not supported in mode 'kinetis fcf_source protection'.");
2047 LOG_INFO(
"Flash protection requested in the programmed file differs from current setting.");
2051 LOG_INFO(
"Data flash protection requested in the programmed file differs from current setting.");
2053 if ((fcf_in_data[
FCF_FSEC] & 3) != 2) {
2054 fcf_in_data_valid =
false;
2055 LOG_INFO(
"Device security requested in the programmed file! Write denied.");
2058 LOG_INFO(
"Strange unsecure mode 0x%02" PRIx8
2059 " requested in the programmed file, set FSEC = 0x%02" PRIx8
2060 " in the startup code!",
2065 LOG_INFO(
"FOPT requested in the programmed file differs from current setting, set 'kinetis fopt 0x%02"
2066 PRIx8
"'.", fcf_in_data[
FCF_FOPT]);
2072 fcf_in_data_valid =
false;
2073 LOG_INFO(
"Cannot re-program FCF. Expect verify errors at FCF (0x400-0x40f).");
2075 LOG_INFO(
"Trying to re-program FCF.");
2077 LOG_INFO(
"Flash re-programming may fail on this device!");
2083 if (set_fcf && !fcf_in_data_valid) {
2102 LOG_WARNING(
"Flash Configuration Field written.");
2103 LOG_WARNING(
"Reset or power off the device to make settings effective.");
2122 uint8_t fcfg1_eesize, fcfg1_depart;
2123 uint32_t ee_size = 0;
2124 uint32_t pflash_size_k, nvm_size_k, dflash_size_k;
2125 unsigned int generation = 0, subseries = 0, derivate = 0;
2133 k_chip->
flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR;
2144 generation = (k_chip->
sim_sdid) >> 28 & 0x0f;
2145 subseries = (k_chip->
sim_sdid) >> 24 & 0x0f;
2146 derivate = (k_chip->
sim_sdid) >> 20 & 0x0f;
2231 LOG_ERROR(
"Unsupported S32K1xx-series");
2244 fcfg1_depart = (k_chip->
sim_fcfg1 >> 12) & 0x0f;
2245 fcfg1_eesize = (k_chip->
sim_fcfg1 >> 16) & 0x0f;
2246 if (fcfg1_eesize <= 9)
2247 ee_size = (16 << (10 - fcfg1_eesize));
2248 if (fcfg1_depart == 0xf) {
2252 if (generation == 1 && subseries == 4 && derivate == 8) {
2253 LOG_WARNING(
"DEPART 0b1111 on S32K148: assuming 512 KiB DFlash. This is only valid if a PGMPART"
2254 " has been previously launched. Use DEPART 0b0000 to avoid this warning.");
2259 }
else if ((fcfg1_depart & 0x8) == 0) {
2267 if (fcfg1_depart & 0x7)
2268 k_chip->
dflash_size = 4096 << (fcfg1_depart & 0x7);
2273 snprintf(k_chip->
name,
sizeof(k_chip->
name),
"S32K%u%u%u",
2274 generation, subseries, derivate);
2282 nvm_size_k = k_chip->
nvm_size / 1024;
2285 LOG_INFO(
"%u FlexNVM banks: %" PRIu32
" KiB total, %" PRIu32
" KiB available as data flash, %"
2286 PRIu32
" bytes FlexRAM",
2302 uint8_t fcfg1_nvmsize, fcfg1_pfsize, fcfg1_eesize, fcfg1_depart;
2303 uint8_t fcfg2_pflsh;
2304 uint32_t ee_size = 0;
2305 uint32_t pflash_size_k, nvm_size_k, dflash_size_k;
2306 uint32_t pflash_size_m;
2307 unsigned int num_blocks = 0;
2308 unsigned int maxaddr_shift = 13;
2311 unsigned int familyid = 0, subfamid = 0;
2312 unsigned int cpu_mhz = 120;
2313 bool use_nvm_marking =
false;
2314 char flash_marking[12], nvm_marking[2];
2353 k_chip->
flash_support = FS_PROGRAM_LONGWORD | FS_PROGRAM_SECTOR;
2366 k_chip->
flash_support = FS_PROGRAM_LONGWORD | FS_PROGRAM_SECTOR;
2382 k_chip->
flash_support = FS_PROGRAM_LONGWORD | FS_PROGRAM_SECTOR;
2391 k_chip->
flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR;
2401 k_chip->
flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR;
2404 LOG_ERROR(
"Unsupported K-family FAMID");
2410 use_nvm_marking =
true;
2427 strcat(
name,
" Rev 1.x");
2440 use_nvm_marking =
true;
2465 k_chip->
flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR;
2479 LOG_ERROR(
"Unsupported Kinetis K22 DIEID");
2492 k_chip->
flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR;
2508 k_chip->
flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR;
2519 k_chip->
flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR | FS_ECC;
2530 k_chip->
flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR | FS_ECC;
2540 k_chip->
flash_support = FS_PROGRAM_LONGWORD | FS_NO_CMD_BLOCKSTAT;
2549 k_chip->
flash_support = FS_PROGRAM_LONGWORD | FS_NO_CMD_BLOCKSTAT;
2552 use_nvm_marking =
false;
2553 snprintf(
name,
sizeof(
name),
"MKL8%uZ%%s7",
2558 LOG_ERROR(
"Unsupported Kinetis FAMILYID SUBFAMID");
2561 if (
name[0] ==
'\0')
2562 snprintf(
name,
sizeof(
name),
"MK%u%uF%%s%u",
2563 familyid, subfamid, cpu_mhz / 10);
2591 snprintf(
name,
sizeof(
name),
"MKL%u%uZ%%s%u",
2592 familyid, subfamid, cpu_mhz / 10);
2628 LOG_ERROR(
"Unsupported KW FAMILYID SUBFAMID");
2630 snprintf(
name,
sizeof(
name),
"MKW%u%uZ%%s%u",
2631 familyid, subfamid, cpu_mhz / 10);
2644 strcpy(
name,
"MKV10Z%s7");
2653 strcpy(
name,
"MKV11Z%s7");
2684 k_chip->
flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR | FS_WIDTH_256BIT | FS_ECC;
2691 LOG_ERROR(
"Unsupported KV FAMILYID SUBFAMID");
2694 if (
name[0] ==
'\0')
2695 snprintf(
name,
sizeof(
name),
"MKV%u%uF%%s%u",
2696 familyid, subfamid, cpu_mhz / 10);
2711 k_chip->
flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR;
2715 snprintf(
name,
sizeof(
name),
"MKE%u%uZ%%s%u",
2716 familyid, subfamid, cpu_mhz / 10);
2727 k_chip->
flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR;
2731 snprintf(
name,
sizeof(
name),
"MKE%u%uF%%s%u",
2732 familyid, subfamid, cpu_mhz / 10);
2736 LOG_ERROR(
"Unsupported KE FAMILYID SUBFAMID");
2758 LOG_DEBUG(
"SDID: 0x%08" PRIX32
" FCFG1: 0x%08" PRIX32
" FCFG2: 0x%08" PRIX32, k_chip->
sim_sdid,
2761 fcfg1_nvmsize = (uint8_t)((k_chip->
sim_fcfg1 >> 28) & 0x0f);
2762 fcfg1_pfsize = (uint8_t)((k_chip->
sim_fcfg1 >> 24) & 0x0f);
2763 fcfg1_eesize = (uint8_t)((k_chip->
sim_fcfg1 >> 16) & 0x0f);
2764 fcfg1_depart = (uint8_t)((k_chip->
sim_fcfg1 >> 8) & 0x0f);
2766 fcfg2_pflsh = (uint8_t)((k_chip->
sim_fcfg2 >> 23) & 0x01);
2770 if (num_blocks == 0)
2776 LOG_WARNING(
"MAXADDR1 is zero, number of flash banks adjusted to 1");
2779 LOG_WARNING(
"MAXADDR1 is non zero, number of flash banks adjusted to 2");
2784 switch (fcfg1_nvmsize) {
2790 k_chip->
nvm_size = 1 << (14 + (fcfg1_nvmsize >> 1));
2804 switch (fcfg1_eesize) {
2815 ee_size = (16 << (10 - fcfg1_eesize));
2822 switch (fcfg1_depart) {
2840 k_chip->
dflash_size = 4096 << (fcfg1_depart & 0x7);
2848 switch (fcfg1_pfsize) {
2859 k_chip->
pflash_size = 1 << (14 + (fcfg1_pfsize >> 1));
2877 LOG_WARNING(
"SIM_FCFG1 PFSIZE = 0xf: please check if pflash is %" PRIu32
" KB", k_chip->
pflash_size>>10);
2898 if (use_nvm_marking) {
2900 nvm_marking[1] =
'\0';
2902 nvm_marking[0] =
'\0';
2905 pflash_size_m = pflash_size_k / 1024;
2907 snprintf(flash_marking,
sizeof(flash_marking),
"%s%" PRIu32
"M0xxx", nvm_marking, pflash_size_m);
2909 snprintf(flash_marking,
sizeof(flash_marking),
"%s%" PRIu32
"xxx", nvm_marking, pflash_size_k);
2911 snprintf(k_chip->
name,
sizeof(k_chip->
name),
name, flash_marking);
2912 LOG_INFO(
"Kinetis %s detected: %u flash blocks", k_chip->
name, num_blocks);
2915 nvm_size_k = k_chip->
nvm_size / 1024;
2917 LOG_INFO(
"%u FlexNVM banks: %" PRIu32
" KiB total, %" PRIu32
" KiB available as data flash, %"
2918 PRIu32
" bytes FlexRAM", k_chip->
num_nvm_blocks, nvm_size_k, dflash_size_k, ee_size);
2932 uint8_t fcfg2_maxaddr0, fcfg2_pflsh, fcfg2_maxaddr1;
2933 unsigned int num_blocks, first_nvm_bank;
2972 size_k =
bank->size / 1024;
2973 LOG_DEBUG(
"Kinetis bank %u: %" PRIu32
"k PFlash, FTFx base 0x%08" PRIx32
", sect %" PRIu32,
2978 unsigned int nvm_ord = k_bank->
bank_number - first_nvm_bank;
3006 if (
bank->size > limit) {
3008 LOG_DEBUG(
"FlexNVM bank %u limited to 0x%08" PRIx32
" due to active EEPROM backup",
3012 size_k =
bank->size / 1024;
3013 LOG_DEBUG(
"Kinetis bank %u: %" PRIu32
"k FlexNVM, FTFx base 0x%08" PRIx32
", sect %" PRIu32,
3017 LOG_ERROR(
"Cannot determine parameters for bank %u, only %u banks on device",
3024 fcfg2_pflsh = (uint8_t)((k_chip->
sim_fcfg2 >> 23) & 0x01);
3025 fcfg2_maxaddr0 = (uint8_t)((k_chip->
sim_fcfg2 >> 24) & 0x7f);
3026 fcfg2_maxaddr1 = (uint8_t)((k_chip->
sim_fcfg2 >> 16) & 0x7f);
3029 LOG_WARNING(
"MAXADDR0 0x%02" PRIx8
" check failed,"
3030 " please report to OpenOCD mailing list", fcfg2_maxaddr0);
3034 LOG_WARNING(
"MAXADDR1 0x%02" PRIx8
" check failed,"
3035 " please report to OpenOCD mailing list", fcfg2_maxaddr1);
3039 LOG_WARNING(
"FlexNVM MAXADDR1 0x%02" PRIx8
" check failed,"
3040 " please report to OpenOCD mailing list", fcfg2_maxaddr1);
3044 free(
bank->sectors);
3047 free(
bank->prot_blocks);
3051 LOG_ERROR(
"Unknown sector size for bank %u",
bank->bank_number);
3057 if (
bank->num_sectors > 0) {
3064 if (!
bank->prot_blocks)
3068 bank->num_prot_blocks = 0;
3080 if (k_bank && k_bank->
probed)
3088 const char *bank_class_names[] = {
3089 "(ANY)",
"PFlash",
"FlexNVM",
"FlexRAM"
3094 uint32_t size_k =
bank->size / 1024;
3122 bool block_dirty =
true;
3126 if (use_block_cmd && k_bank->
flash_class == FC_FLEX_NVM) {
3129 if (fcfg1_depart != 0xf && fcfg1_depart != 0)
3130 use_block_cmd =
false;
3133 if (use_block_cmd) {
3136 0, 0, 0, 0, 0, 0, 0, 0, &ftfx_fstat);
3140 else if ((ftfx_fstat & 0x01) == 0)
3141 block_dirty =
false;
3146 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
3150 1, 0, 0, 0, 0, 0, 0, 0, &ftfx_fstat);
3153 bank->sectors[i].is_erased = !(ftfx_fstat & 0x01);
3155 LOG_DEBUG(
"Ignoring error on PFlash sector blank-check");
3157 bank->sectors[i].is_erased = -1;
3162 for (
unsigned int i = 0; i <
bank->num_sectors; i++)
3163 bank->sectors[i].is_erased = 1;
3166 LOG_WARNING(
"kinetis_blank_check not supported yet for FlexRAM");
3177 unsigned int bank_idx;
3178 unsigned int num_blocks, first_nvm_bank;
3179 unsigned long par, log2 = 0, ee1 = 0, ee2 = 0;
3180 enum { SHOW_INFO, DF_SIZE, EEBKP_SIZE } sz_type = SHOW_INFO;
3182 uint8_t load_flex_ram = 1;
3183 uint8_t ee_size_code = 0x3f;
3184 uint8_t flex_nvm_partition_code = 0;
3185 uint8_t ee_split = 3;
3186 uint8_t csec_key_size = 0;
3198 if (strcmp(
CMD_ARGV[0],
"dataflash") == 0)
3200 else if (strcmp(
CMD_ARGV[0],
"eebkp") == 0)
3201 sz_type = EEBKP_SIZE;
3204 while (par >> (log2 + 3))
3214 switch (flex_nvm_partition_code) {
3235 command_print(
CMD,
"data flash %d KB", 4 << (flex_nvm_partition_code & 7));
3241 command_print(
CMD,
"Unsupported EEPROM backup size code 0x%02" PRIx8, flex_nvm_partition_code);
3246 flex_nvm_partition_code = 0x8 | log2;
3250 flex_nvm_partition_code = log2;
3257 ee1 = ee2 = eex / 2;
3263 enable = ee1 + ee2 > 0;
3265 for (log2 = 2; ; log2++) {
3266 if (ee1 + ee2 == (16u << 10) >> log2)
3268 if (ee1 + ee2 > (16u << 10) >> log2 || log2 >= 9) {
3281 else if (ee1 * 7 == ee2)
3283 else if (ee1 != ee2) {
3288 ee_size_code = log2 | ee_split << 4;
3297 unsigned int csec_keys;
3300 switch (csec_keys) {
3319 if (csec_key_size) {
3333 if (ee1 + ee2 == 0 || load_flex_ram) {
3334 command_print(
CMD,
"CSEc keys require EEPROM with FlexRAM loading during reset");
3341 ee_size_code &= 0x0f;
3343 LOG_INFO(
"DEPART 0x%" PRIx8
", EEPROM size code 0x%" PRIx8,
3344 flex_nvm_partition_code, ee_size_code);
3356 ee_size_code, flex_nvm_partition_code, 0, 0,
3365 for (bank_idx = first_nvm_bank; bank_idx < num_blocks; bank_idx++)
3369 command_print(
CMD,
"FlexNVM banks will be re-probed to set new data flash size.");
3379 if (strcmp(
CMD_ARGV[0],
"write") == 0)
3381 else if (strcmp(
CMD_ARGV[0],
"protection") == 0)
3390 LOG_WARNING(
"BEWARE: incorrect flash configuration may permanently lock the device.");
3392 command_print(
CMD,
"Protection info writes to Flash Configuration Field enabled.");
3393 command_print(
CMD,
"Arbitrary FCF writes disabled. Mode safe from unwanted locking of the device.");
3426 .
name =
"check_security",
3428 .help =
"Check status of device security lock",
3430 .handler = kinetis_check_flash_security_status,
3435 .help =
"Issue a halt via the MDM-AP",
3437 .handler = kinetis_mdm_halt,
3440 .name =
"mass_erase",
3442 .help =
"Issue a complete flash erase via the MDM-AP",
3444 .handler = kinetis_mdm_mass_erase,
3449 .help =
"Issue a reset via the MDM-AP",
3451 .handler = kinetis_mdm_reset,
3460 .help =
"MDM-AP command group",
3465 .
name =
"disable_wdog",
3467 .help =
"Disable the watchdog timer",
3469 .handler = kinetis_disable_wdog_handler,
3472 .name =
"nvm_partition",
3474 .help =
"Show/set data flash or EEPROM backup size in kilobytes,"
3475 " set two EEPROM sizes in bytes, FlexRAM loading during reset"
3476 " and number of CSEc keys",
3477 .usage =
"('info'|'dataflash' size|'eebkp' size) [eesize1 eesize2] ['on'|'off'] [csec_keys]",
3478 .handler = kinetis_nvm_partition,
3481 .name =
"fcf_source",
3483 .help =
"Use protection as a source for Flash Configuration Field or allow writing arbitrary values to the FCF"
3484 " Mode 'protection' is safe from unwanted locking of the device.",
3485 .usage =
"['protection'|'write']",
3486 .handler = kinetis_fcf_source_handler,
3491 .help =
"FCF_FOPT value source in 'kinetis fcf_source protection' mode",
3493 .handler = kinetis_fopt_handler,
3496 .name =
"create_banks",
3498 .help =
"Driver creates additional banks if device with two/four flash blocks is probed",
3499 .handler = kinetis_create_banks_handler,
3509 .help =
"Kinetis flash controller commands",
3521 .flash_bank_command = kinetis_flash_bank_command,
void init_reg_param(struct reg_param *param, const char *reg_name, uint32_t size, enum param_direction direction)
void destroy_reg_param(struct reg_param *param)
struct adiv5_ap * dap_get_ap(struct adiv5_dap *dap, uint64_t ap_num)
int dap_put_ap(struct adiv5_ap *ap)
This defines formats and data structures used to talk to ADIv5 entities.
static int dap_queue_ap_read(struct adiv5_ap *ap, unsigned int reg, uint32_t *data)
Queue an AP register read.
static int dap_queue_ap_write(struct adiv5_ap *ap, unsigned int reg, uint32_t data)
Queue an AP register write.
static int dap_run(struct adiv5_dap *dap)
Perform all queued DAP operations, and clear any errors posted in the CTRL_STAT register when they ar...
#define ARMV7M_COMMON_MAGIC
Support functions to access arbitrary bits in a byte array.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
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 COMMAND_PARSE_ON_OFF(in, out)
parses an on/off command argument
#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_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_COMMAND_ARGUMENT_INVALID
static struct cortex_m_common * target_to_cm(struct target *target)
uint64_t buffer
Pointer to data buffer to send over SPI.
uint32_t size
Size of dw_spi_transaction::buffer.
uint32_t buffer_size
Size of dw_spi_program::buffer.
uint32_t address
Starting address. Sector aligned.
#define ERROR_FLASH_OPER_UNSUPPORTED
#define ERROR_FLASH_BANK_INVALID
#define ERROR_FLASH_OPERATION_FAILED
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
struct flash_sector * alloc_block_array(uint32_t offset, uint32_t size, unsigned int num_blocks)
Allocate and fill an array of sectors or protection blocks.
void flash_bank_add(struct flash_bank *bank)
Adds a new NOR bank to the global list of banks.
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
struct flash_bank * flash_bank_list(void)
void jtag_poll_set_enabled(bool value)
Assign flag reporting whether JTAG polling is disallowed.
int adapter_deassert_reset(void)
enum reset_types jtag_get_reset_config(void)
int adapter_assert_reset(void)
#define KINETIS_SOPT1_RAMSIZE_K24FN1M
#define KINETIS_K_SDID_K60_M100
#define KINETIS_SDID_DIEID_K22FN256
#define KINETIS_SDID_SERIESID_MASK
static int kinetis_probe_chip_s32k(struct kinetis_chip *k_chip)
static int kinetis_protect_check(struct flash_bank *bank)
#define KINETIS_K_SDID_K22_M50
#define KINETIS_SDID_PROJECTID_KE1XF
#define KINETIS_SDID_FAMILYID_SHIFT
#define FTFX_CMD_SECTERASE
static int kinetis_create_missing_banks(struct kinetis_chip *k_chip)
#define KINETIS_SDID_SUBFAMID_MASK
static int kinetis_info(struct flash_bank *bank, struct command_invocation *cmd)
#define KINETIS_SDID_SERIESID_KL
#define KINETIS_SDID_S32K_SERIES_MASK
static int kinetis_blank_check(struct flash_bank *bank)
#define KINETIS_K_SDID_K21_M120
#define KINETIS_K_SDID_K30_M100
#define KINETIS_K_SDID_K12
#define KINETIS_K_SDID_K40_M72
static int kinetis_write_block(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t wcount)
#define FTFX_CMD_SETFLEXRAM
static int kinetis_probe(struct flash_bank *bank)
#define KINETIS_SDID_FAMILYID_K1X
#define KINETIS_SDID_SUBFAMID_KX6
#define KINETIS_MAX_BANKS
#define MDM_CTRL_CORE_HOLD_RES
static int kinetis_chip_options(struct kinetis_chip *k_chip, int argc, const char *argv[])
#define KINETIS_SDID_S32K_SERIES_K14X
static int kinetis_disable_wdog32(struct target *target, uint32_t wdog_base)
#define KINETIS_SDID_FAMILYID_K3X
#define KINETIS_K_SDID_K60_M150
#define KINETIS_SDID_DIEID_K24FN1M
#define KINETIS_SDID_FAMILYID_MASK
#define KINETIS_K_REVID_MASK
#define KINETIS_K_SDID_K20_M100
static int kinetis_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
#define KINETIS_K_SDID_K22_M120
#define KINETIS_SDID_PROJECTID_MASK
static const uint8_t kinetis_flash_write_code[]
static const struct kinetis_type kinetis_types_old[]
#define KINETIS_SDID_FAMILYID_KL8X
#define KINETIS_SDID_FAMILYID_K5X
COMMAND_HANDLER(kinetis_mdm_halt)
static int kinetis_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int kinetis_fill_fcf(struct flash_bank *bank, uint8_t *fcf)
#define KINETIS_K_SDID_K40_M100
#define KINETIS_SDID_SERIESID_K
#define KINETIS_SDID_SERIESID_KV
#define KINETIS_SDID_S32K_DERIVATE_KXX8
static const struct command_registration kinetis_exec_command_handlers[]
#define KINETIS_SDID_SUBFAMID_KX2
#define FTFX_CMD_BLOCKSTAT
#define KINETIS_K_SDID_TYPE_MASK
#define KINETIS_K_SDID_K70_M150
static int kinetis_make_ram_ready(struct target *target)
#define KINETIS_SDID_FAMILYID_K4X
#define KINETIS_K_SDID_K53
static int kinetis_probe_chip(struct kinetis_chip *k_chip)
#define KINETIS_SDID_DIEID_MASK
#define KINETIS_K_REVID_SHIFT
#define KINETIS_SDID_PROJECTID_KE1XZ
static int kinetis_disable_wdog_kx(struct target *target)
#define KINETIS_SDID_S32K_FEATURE_CSEC
static int kinetis_ftfx_clear_error(struct target *target)
#define KINETIS_SDID_S32K_DERIVATE_KXX5
#define KINETIS_SDID_SERIESID_KW
static int kinetis_check_run_mode(struct kinetis_chip *k_chip)
#define KINETIS_SDID_K_SERIES_MASK
#define KINETIS_SDID_SUBFAMID_KX8
#define KINETIS_SDID_S32K_DERIVATE_KXX4
#define KINETIS_SDID_S32K_DERIVATE_KXX3
#define KINETIS_K_SDID_K10_M100
#define KINETIS_SDID_SUBFAMID_KX7
static int kinetis_write_inner(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
#define KINETIS_SDID_FAMILYID_K8X
static int kinetis_auto_probe(struct flash_bank *bank)
#define KINETIS_K_SDID_K20_M120
#define KINETIS_SDID_SUBFAMID_SHIFT
#define KINETIS_SDID_SUBFAMID_KX0
static int kinetis_ftfx_command(struct target *target, uint8_t fcmd, uint32_t faddr, uint8_t fccob4, uint8_t fccob5, uint8_t fccob6, uint8_t fccob7, uint8_t fccob8, uint8_t fccob9, uint8_t fccoba, uint8_t fccobb, uint8_t *ftfx_fstat)
#define KINETIS_SDID_SUBFAMID_KX3
#define KINETIS_K_SDID_K10_M120
#define KINETIS_SDID_FAMILYID_K0X
static void kinetis_invalidate_flash_cache(struct kinetis_chip *k_chip)
#define KINETIS_SDID_FAMILYID_K2X
static int kinetis_write_sections(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static uint8_t kinetis_fcfg1_depart(enum kinetis_chip_type chip_type, uint32_t sim_fcfg1)
const struct flash_driver kinetis_flash
#define KINETIS_K_SDID_K30_M72
static const uint32_t kinetis_known_mdm_ids[]
#define KINETIS_SDID_SUBFAMID_KX5
FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
static int kinetis_mdm_read_register(struct adiv5_dap *dap, unsigned int reg, uint32_t *result)
static void kinetis_free_driver_priv(struct flash_bank *bank)
#define KINETIS_SDID_SUBFAMID_KX1
#define KINETIS_K_SDID_K11
#define KINETIS_K_SDID_K20_M72
#define KINETIS_SDID_S32K_SERIES_K11X
static int kinetis_ftfx_prepare(struct target *target)
#define KINETIS_SDID_DIEID_K22FN128
#define KINETIS_K_SDID_K10_M50
#define FTFX_CMD_SECTSTAT
#define KINETIS_SDID_S32K_DERIVATE_MASK
static bool allow_fcf_writes
static struct kinetis_chip * kinetis_get_chip(struct target *target)
static int kinetis_mdm_write_register(struct adiv5_dap *dap, unsigned int reg, uint32_t value)
#define FTFX_CMD_LWORDPROG
#define KINETIS_K_SDID_K10_M72
static int kinetis_disable_wdog(struct kinetis_chip *k_chip)
#define KINETIS_SDID_DIEID_K22FN512
#define KINETIS_SDID_S32K_DERIVATE_KXX2
#define KINETIS_SDID_DIEID_K24FN256
#define KINETIS_SDID_SERIESID_KE
#define MDM_ACCESS_TIMEOUT
static int kinetis_mdm_poll_register(struct adiv5_dap *dap, unsigned int reg, uint32_t mask, uint32_t value, uint32_t timeout_ms)
static int kinetis_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
#define KINETIS_K_SDID_K51_M72
static const struct command_registration kinetis_command_handler[]
static int kinetis_read_pmstat(struct kinetis_chip *k_chip, uint8_t *pmstat)
#define KINETIS_SOPT1_RAMSIZE_MASK
static int kinetis_disable_wdog_algo(struct target *target, size_t code_size, const uint8_t *code, uint32_t wdog_base)
#define KINETIS_SDID_FAMILYID_K6X
static int kinetis_ftfx_decode_error(uint8_t fstat)
#define KINETIS_K_SDID_K50_M72
#define KINETIS_SDID_S32K_DERIVATE_KXX6
#define FTFX_CMD_SECTWRITE
#define KINETIS_K_SDID_K21_M50
static const struct command_registration kinetis_security_command_handlers[]
#define KINETIS_K_SDID_K20_M50
#define MDM_CTRL_SYS_RES_REQ
#define WDOG_STCTRLH_OFFSET
#define KINETIS_SDID_SUBFAMID_KX4
void alive_sleep(uint64_t ms)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
#define FLASH_WRITE_GAP_SECTOR
This represents an ARM Debug Interface (v5) Access Port (AP).
struct adiv5_dap * dap
DAP this AP belongs to.
This represents an ARM Debug Interface (v5) Debug Access Port (DAP).
const struct dap_ops * ops
struct adiv5_dap * dap
For targets conforming to ARM Debug Interface v5, this handle references the Debug Access Port (DAP) ...
unsigned int common_magic
When run_command is called, a new instance will be created on the stack, filled with the proper value...
struct armv7m_common armv7m
Provides details of a flash bank, available either on-chip or through a major interface.
unsigned int num_prot_blocks
The number of protection blocks in this bank.
const struct flash_driver * driver
Driver for this bank.
void * driver_priv
Private driver storage pointer.
struct flash_sector * prot_blocks
Array of protection blocks, allocated and initialized by the flash driver.
struct flash_bank * next
The next flash bank on this chip.
struct target * target
Target to which this bank belongs.
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...
int is_protected
Indication of protection status: 0 = unprotected/unlocked, 1 = protected/locked, other = unknown.
enum kinetis_chip::@10 watchdog_type
unsigned int nvm_sector_size
struct kinetis_flash_bank banks[KINETIS_MAX_BANKS]
enum kinetis_chip_type chip_type
unsigned int num_nvm_blocks
enum kinetis_chip::@8 flash_support
unsigned int pflash_sector_size
enum kinetis_chip::@9 cache_type
enum kinetis_chip::@11 sysmodectrlr_type
unsigned int max_flash_prog_size
unsigned int num_pflash_blocks
uint32_t fcfg2_maxaddr0_shifted
uint32_t fcfg2_maxaddr1_shifted
enum kinetis_flash_bank::@7 flash_class
struct kinetis_chip * k_chip
uint32_t protection_block
int(* deassert_reset)(struct target *target)
The implementation is responsible for polling the target such that target->state reflects the state c...
int(* assert_reset)(struct target *target)
struct target_type * type
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int target_write_u8(struct target *target, target_addr_t address, uint8_t value)
int target_read_u8(struct target *target, target_addr_t address, uint8_t *value)
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
uint32_t target_get_working_area_avail(struct target *target)
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
int target_poll(struct target *target)
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
int target_read_u16(struct target *target, target_addr_t address, uint16_t *value)
int target_run_flash_async_algorithm(struct target *target, const uint8_t *buffer, uint32_t count, int block_size, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t buffer_start, uint32_t buffer_size, uint32_t entry_point, uint32_t exit_point, void *arch_info)
Streams data to a circular buffer on target intended for consumption by code running asynchronously o...
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
struct target * get_current_target(struct command_context *cmd_ctx)
#define ERROR_TARGET_NOT_HALTED
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.