137 #define FLASH_ERASE_TIMEOUT 250
138 #define FLASH_WRITE_TIMEOUT 50
144 #define F_HAS_DUAL_BANK BIT(0)
147 #define F_USE_ALL_WRPXX BIT(1)
149 #define F_HAS_TZ BIT(2)
151 #define F_HAS_L5_FLASH_REGS BIT(3)
154 #define F_QUAD_WORD_PROG BIT(4)
157 #define F_WRP_HAS_LOCK BIT(5)
293 { 0x1000,
"1" }, { 0x1001,
"2" }, { 0x1003,
"3" }, { 0x1007,
"4" }
297 { 0x1000,
"A" }, { 0x1001,
"Z" },
301 { 0x1000,
"A" }, { 0x1001,
"Z" }, { 0x2001,
"Y" },
306 { 0x1000,
"A" }, { 0x1001,
"Z" },
310 { 0x1000,
"A" }, { 0x1001,
"Z" },
330 { 0x1000,
"A/Z" } , { 0x2000,
"B" },
334 { 0x1000,
"A" }, { 0x2000,
"B" },
338 { 0x1000,
"A" }, { 0x1001,
"Z" }, { 0x2001,
"Y" },
342 { 0x1000,
"A" }, { 0x1001,
"Z" }, { 0x2001,
"Y" },
346 { 0x1000,
"A" }, { 0x1001,
"Z" }, { 0x2000,
"B" },
358 { 0x1000,
"A" }, { 0x1001,
"Z" },
362 { 0x1000,
"A" }, { 0x2000,
"B" }, { 0x2001,
"Z" },
366 { 0x1000,
"A" }, { 0x2000,
"B" }, { 0x2001,
"Z" },
370 { 0x1000,
"A" }, { 0x1001,
"Z" }, { 0x1003,
"Y" }, { 0x100F,
"W" },
379 { 0x1000,
"A" }, { 0x2000,
"B" }, { 0x2001,
"Z" },
387 { 0x1000,
"A" }, { 0x1001,
"Z" },
391 { 0x1000,
"A" }, { 0x1001,
"Z" }, { 0x1003,
"Y" }, { 0x2000,
"B" },
392 { 0x2001,
"X" }, { 0x3000,
"C" }, { 0x3001,
"W" }, { 0x3007,
"U" },
396 { 0x3001,
"X" }, { 0x3002,
"W" },
400 { 0x1000,
"A" }, { 0x1001,
"Z" },
408 { 0x1000,
"A" }, { 0x1001,
"Z" },
416 { 0x1000,
"A" }, { 0x2000,
"B" },
436 .device_str =
"STM32L47/L48xx",
437 .max_flash_size_kb = 1024,
439 .flash_regs_base = 0x40022000,
440 .fsize_addr = 0x1FFF75E0,
441 .otp_base = 0x1FFF7000,
448 .device_str =
"STM32U3B/U3Cxx",
449 .max_flash_size_kb = 2048,
451 .flash_regs_base = 0x40022000,
452 .fsize_addr = 0x0BFA07A0,
453 .otp_base = 0x0BFA0000,
460 .device_str =
"STM32L43/L44xx",
461 .max_flash_size_kb = 256,
463 .flash_regs_base = 0x40022000,
464 .fsize_addr = 0x1FFF75E0,
465 .otp_base = 0x1FFF7000,
472 .device_str =
"STM32C01xx",
473 .max_flash_size_kb = 32,
475 .flash_regs_base = 0x40022000,
476 .fsize_addr = 0x1FFF75A0,
477 .otp_base = 0x1FFF7000,
484 .device_str =
"STM32C03xx",
485 .max_flash_size_kb = 32,
487 .flash_regs_base = 0x40022000,
488 .fsize_addr = 0x1FFF75A0,
489 .otp_base = 0x1FFF7000,
496 .device_str =
"STM32C05xx",
497 .max_flash_size_kb = 64,
499 .flash_regs_base = 0x40022000,
500 .fsize_addr = 0x1FFF75A0,
501 .otp_base = 0x1FFF7000,
508 .device_str =
"STM32C071xx",
509 .max_flash_size_kb = 128,
511 .flash_regs_base = 0x40022000,
512 .fsize_addr = 0x1FFF75A0,
513 .otp_base = 0x1FFF7000,
520 .device_str =
"STM32C09xx",
521 .max_flash_size_kb = 256,
523 .flash_regs_base = 0x40022000,
524 .fsize_addr = 0x1FFF75A0,
525 .otp_base = 0x1FFF7000,
532 .device_str =
"STM32U535/U545",
533 .max_flash_size_kb = 512,
536 .flash_regs_base = 0x40022000,
537 .fsize_addr = 0x0BFA07A0,
538 .otp_base = 0x0BFA0000,
545 .device_str =
"STM32G05/G06xx",
546 .max_flash_size_kb = 64,
548 .flash_regs_base = 0x40022000,
549 .fsize_addr = 0x1FFF75E0,
550 .otp_base = 0x1FFF7000,
557 .device_str =
"STM32G07/G08xx",
558 .max_flash_size_kb = 128,
560 .flash_regs_base = 0x40022000,
561 .fsize_addr = 0x1FFF75E0,
562 .otp_base = 0x1FFF7000,
569 .device_str =
"STM32L49/L4Axx",
570 .max_flash_size_kb = 1024,
572 .flash_regs_base = 0x40022000,
573 .fsize_addr = 0x1FFF75E0,
574 .otp_base = 0x1FFF7000,
581 .device_str =
"STM32L45/L46xx",
582 .max_flash_size_kb = 512,
584 .flash_regs_base = 0x40022000,
585 .fsize_addr = 0x1FFF75E0,
586 .otp_base = 0x1FFF7000,
593 .device_str =
"STM32L41/L42xx",
594 .max_flash_size_kb = 128,
596 .flash_regs_base = 0x40022000,
597 .fsize_addr = 0x1FFF75E0,
598 .otp_base = 0x1FFF7000,
605 .device_str =
"STM32G03x/G04xx",
606 .max_flash_size_kb = 64,
608 .flash_regs_base = 0x40022000,
609 .fsize_addr = 0x1FFF75E0,
610 .otp_base = 0x1FFF7000,
617 .device_str =
"STM32G0B/G0Cx",
618 .max_flash_size_kb = 512,
620 .flash_regs_base = 0x40022000,
621 .fsize_addr = 0x1FFF75E0,
622 .otp_base = 0x1FFF7000,
629 .device_str =
"STM32G43/G44xx",
630 .max_flash_size_kb = 128,
632 .flash_regs_base = 0x40022000,
633 .fsize_addr = 0x1FFF75E0,
634 .otp_base = 0x1FFF7000,
641 .device_str =
"STM32G47/G48xx",
642 .max_flash_size_kb = 512,
644 .flash_regs_base = 0x40022000,
645 .fsize_addr = 0x1FFF75E0,
646 .otp_base = 0x1FFF7000,
653 .device_str =
"STM32L4R/L4Sxx",
654 .max_flash_size_kb = 2048,
656 .flash_regs_base = 0x40022000,
657 .fsize_addr = 0x1FFF75E0,
658 .otp_base = 0x1FFF7000,
665 .device_str =
"STM32L4P/L4Qxx",
666 .max_flash_size_kb = 1024,
668 .flash_regs_base = 0x40022000,
669 .fsize_addr = 0x1FFF75E0,
670 .otp_base = 0x1FFF7000,
677 .device_str =
"STM32L55/L56xx",
678 .max_flash_size_kb = 512,
680 .flash_regs_base = 0x40022000,
681 .fsize_addr = 0x0BFA05E0,
682 .otp_base = 0x0BFA0000,
689 .device_str =
"STM32G49/G4Axx",
690 .max_flash_size_kb = 512,
692 .flash_regs_base = 0x40022000,
693 .fsize_addr = 0x1FFF75E0,
694 .otp_base = 0x1FFF7000,
701 .device_str =
"STM32U031xx",
702 .max_flash_size_kb = 64,
704 .flash_regs_base = 0x40022000,
705 .fsize_addr = 0x1FFF3EA0,
706 .otp_base = 0x1FFF6800,
713 .device_str =
"STM32U073/U083xx",
714 .max_flash_size_kb = 256,
716 .flash_regs_base = 0x40022000,
717 .fsize_addr = 0x1FFF6EA0,
718 .otp_base = 0x1FFF6800,
725 .device_str =
"STM32U37/U38xx",
726 .max_flash_size_kb = 1024,
728 .flash_regs_base = 0x40022000,
729 .fsize_addr = 0x0BFA07A0,
730 .otp_base = 0x0BFA0000,
737 .device_str =
"STM32U59/U5Axx",
738 .max_flash_size_kb = 4096,
741 .flash_regs_base = 0x40022000,
742 .fsize_addr = 0x0BFA07A0,
743 .otp_base = 0x0BFA0000,
750 .device_str =
"STM32U57/U58xx",
751 .max_flash_size_kb = 2048,
754 .flash_regs_base = 0x40022000,
755 .fsize_addr = 0x0BFA07A0,
756 .otp_base = 0x0BFA0000,
763 .device_str =
"STM32U5F/U5Gxx",
764 .max_flash_size_kb = 4096,
767 .flash_regs_base = 0x40022000,
768 .fsize_addr = 0x0BFA07A0,
769 .otp_base = 0x0BFA0000,
776 .device_str =
"STM32WBA5x",
777 .max_flash_size_kb = 1024,
780 .flash_regs_base = 0x40022000,
781 .fsize_addr = 0x0BF907A0,
782 .otp_base = 0x0BF90000,
789 .device_str =
"STM32WBA6x",
790 .max_flash_size_kb = 2048,
793 .flash_regs_base = 0x40022000,
794 .fsize_addr = 0x0BFA07A0,
795 .otp_base = 0x0BFA0000,
802 .device_str =
"STM32WBA2x",
803 .max_flash_size_kb = 512,
805 .flash_regs_base = 0x40022000,
806 .fsize_addr = 0x0BF8D7A0,
807 .otp_base = 0x0BF8D000,
814 .device_str =
"STM32WB1x",
815 .max_flash_size_kb = 320,
817 .flash_regs_base = 0x58004000,
818 .fsize_addr = 0x1FFF75E0,
819 .otp_base = 0x1FFF7000,
826 .device_str =
"STM32WB5x",
827 .max_flash_size_kb = 1024,
829 .flash_regs_base = 0x58004000,
830 .fsize_addr = 0x1FFF75E0,
831 .otp_base = 0x1FFF7000,
838 .device_str =
"STM32WB3x",
839 .max_flash_size_kb = 512,
841 .flash_regs_base = 0x58004000,
842 .fsize_addr = 0x1FFF75E0,
843 .otp_base = 0x1FFF7000,
850 .device_str =
"STM32WLE/WL5x",
851 .max_flash_size_kb = 256,
853 .flash_regs_base = 0x58004000,
854 .fsize_addr = 0x1FFF75E0,
855 .otp_base = 0x1FFF7000,
875 bank->driver_priv = stm32l4_info;
877 stm32l4_info->
probed =
false;
891 struct range *ranges,
unsigned int *ranges_count)
894 bool last_bit = 0, cur_bit;
895 for (
unsigned int i = 0; i < nbits; i++) {
898 if (cur_bit && !last_bit) {
900 ranges[*ranges_count - 1].
start = i;
901 ranges[*ranges_count - 1].
end = i;
902 }
else if (cur_bit && last_bit) {
904 ranges[*ranges_count - 1].
end = i;
927 char *str = calloc(1, ranges_count * (24 *
sizeof(
char)) + 1);
930 for (
unsigned int i = 0; i < ranges_count; i++) {
933 if (i < ranges_count - 1)
955 char *op_str = enable ?
"enabled" :
"disabled";
957 LOG_INFO(
"OTP memory (bank #%d) is %s%s for write commands",
959 stm32l4_info->
otp_enabled == enable ?
"already " :
"",
1054 LOG_ERROR(
"timed out waiting for flash");
1096 LOG_DEBUG(
"setting secure block-based areas registers (SECBBxRy) to 0x%08x", value);
1098 const uint8_t secbb_regs[] = {
1104 unsigned int num_secbb_regs =
ARRAY_SIZE(secbb_regs);
1110 num_secbb_regs /= 2;
1112 for (
unsigned int i = 0; i < num_secbb_regs; i++) {
1157 LOG_ERROR(
"flash not unlocked STM32_FLASH_CR: %" PRIx32,
ctrl);
1190 LOG_ERROR(
"options not unlocked STM32_FLASH_CR: %" PRIx32,
ctrl);
1199 int retval, retval2;
1222 stm32l4_info->
probed =
false;
1235 uint32_t value, uint32_t
mask)
1238 uint32_t optiondata;
1239 int retval, retval2;
1247 const uint32_t *saved_flash_regs = stm32l4_info->
flash_regs;
1259 optiondata = (optiondata & ~
mask) | (value &
mask);
1317 int wrp2y_sectors_offset = -1;
1333 wrp2y_sectors_offset = 0;
1340 if (wrp2y_sectors_offset >= 0) {
1362 uint32_t wrp_value = (wrp_start & stm32l4_info->
wrpxxr_mask) | ((wrp_end & stm32l4_info->
wrpxxr_mask) << 16);
1373 for (
unsigned int i = 0; i < n_wrp; i++) {
1392 for (
unsigned int i = 0; i <
bank->num_sectors; i++)
1393 bank->sectors[i].is_protected = 0;
1396 for (
unsigned int i = 0; i < n_wrp; i++) {
1397 if (wrpxy[i].
used) {
1398 for (
int s = wrpxy[i].
first; s <= wrpxy[i].
last; s++)
1399 bank->sectors[s].is_protected = 1;
1410 int retval, retval2;
1412 assert((first <= last) && (last < bank->num_sectors));
1453 for (
unsigned int i = first; i <= last; i++) {
1454 uint32_t erase_flags;
1489 unsigned int first,
unsigned int last)
1494 for (i = first; i <= last; i++) {
1495 if (
bank->sectors[i].is_protected != set)
1497 else if (i == last) {
1498 LOG_INFO(
"The specified sectors are already %s", set ?
"protected" :
"unprotected");
1516 for (i = 0; i < n_wrp; i++) {
1517 if (wrpxy[i].
used) {
1518 for (
int p = wrpxy[i].
first; p <= wrpxy[i].
last; p++)
1525 struct range ranges[n_wrp + 1];
1526 unsigned int ranges_count = 0;
1531 if (ranges_count > 0) {
1533 LOG_DEBUG(
"current protected areas: %s", ranges_str);
1536 LOG_DEBUG(
"current protected areas: none");
1539 for (i = first; i <= last; i++)
1542 for (i = first; i <= last; i++)
1550 if (ranges_count > 0) {
1552 LOG_DEBUG(
"requested areas for protection: %s", ranges_str);
1555 LOG_DEBUG(
"requested areas for protection: none");
1557 if (ranges_count > n_wrp) {
1558 LOG_ERROR(
"cannot set the requested protection "
1559 "(only %u write protection areas are available)" , n_wrp);
1564 for (i = 0; i < n_wrp; i++) {
1570 for (i = 0; i < ranges_count; i++) {
1572 wrpxy[i].
last = ranges[i].
end;
1585 LOG_ERROR(
"cannot protect/unprotect OTP memory");
1626 static const uint8_t stm32l4_flash_write_code[] = {
1627 #include "../../../contrib/loaders/flash/stm32/stm32l4x.inc"
1632 LOG_WARNING(
"no working area available, can't do block memory writes");
1637 sizeof(stm32l4_flash_write_code),
1638 stm32l4_flash_write_code);
1652 LOG_WARNING(
"large enough working area not available, can't do block memory writes");
1661 LOG_ERROR(
"allocating working area failed");
1684 struct stm32l4_loader_params loader_extra_params;
1696 (uint8_t *) &loader_extra_params);
1709 LOG_ERROR(
"error executing stm32l4 flash write algorithm");
1716 LOG_ERROR(
"flash memory write protected");
1719 LOG_ERROR(
"flash write failed = %08" PRIx32, error);
1759 const uint8_t *src =
buffer;
1760 const uint32_t data_width_in_words = stm32l4_info->
data_width / 4;
1790 LOG_ERROR(
"OTP memory is disabled for write commands");
1815 while ((head < tail) && (
offset >= (head + 1)->
offset)) {
1825 LOG_DEBUG(
"data: 0x%08" PRIx32
" - 0x%08" PRIx32
", sectors: 0x%08" PRIx32
" - 0x%08" PRIx32,
1831 while (head < tail) {
1832 if (head->
offset + head->
size != (head + 1)->offset) {
1835 bank->base + (head + 1)->offset - 1);
1867 LOG_WARNING(
"RDP = 0x55, the work-area should be in non-secure RAM (check SAU partitioning)");
1875 LOG_WARNING(
"falling back to programming without a flash loader (slower)");
1905 for (
unsigned int i = 0; i <
ARRAY_SIZE(dbgmcu_idcode); i++) {
1907 if ((retval ==
ERROR_OK) && ((*
id & 0xfff) != 0) && ((*
id & 0xfff) != 0xfff))
1917 LOG_ERROR(
"Flash requires Cortex-M target");
1952 const uint16_t rev_id = stm32l4_info->
idcode >> 16;
1953 for (
unsigned int i = 0; i < part_info->
num_revs; i++) {
1954 if (rev_id == part_info->
revs[i].
rev)
1955 return part_info->
revs[i].
str;
1974 uint16_t flash_size_kb = 0xffff;
1983 LOG_ERROR(
"Flash requires Cortex-M target");
1987 stm32l4_info->
probed =
false;
1994 const uint32_t device_id = stm32l4_info->
idcode & 0xFFF;
2010 const uint16_t rev_id = stm32l4_info->
idcode >> 16;
2012 LOG_INFO(
"device idcode = 0x%08" PRIx32
" (%s - Rev %s : 0x%04x)",
2044 LOG_ERROR(
"BUG: device supported incomplete");
2050 LOG_INFO(
"TZEN = %d : TrustZone %s by option bytes",
2052 stm32l4_info->
tzen ?
"enabled" :
"disabled");
2064 free(
bank->sectors);
2065 bank->num_sectors = 1;
2068 if (!
bank->sectors) {
2069 LOG_ERROR(
"failed to allocate bank sectors");
2073 stm32l4_info->
probed =
true;
2085 if (retval !=
ERROR_OK || flash_size_kb == 0xffff || flash_size_kb == 0
2087 LOG_WARNING(
"STM32 flash size failed, probe inaccurate - assuming %dk flash",
2095 LOG_WARNING(
"overriding size register by configured bank size - MAY CAUSE TROUBLE");
2099 LOG_INFO(
"flash size = %d KiB", flash_size_kb);
2102 assert((flash_size_kb != 0xffff) && flash_size_kb);
2110 int page_size_kb = 0;
2114 switch (device_id) {
2126 num_pages = flash_size_kb / page_size_kb;
2153 num_pages = flash_size_kb / page_size_kb;
2159 num_pages = flash_size_kb / page_size_kb;
2176 num_pages = flash_size_kb / page_size_kb;
2181 num_pages = flash_size_kb / page_size_kb;
2199 num_pages = flash_size_kb / page_size_kb;
2205 num_pages = flash_size_kb / page_size_kb;
2218 num_pages = flash_size_kb / page_size_kb;
2230 num_pages = flash_size_kb / page_size_kb;
2255 num_pages = flash_size_kb / page_size_kb;
2272 num_pages = flash_size_kb / page_size_kb;
2284 num_pages = flash_size_kb / page_size_kb;
2290 num_pages = flash_size_kb / page_size_kb;
2304 if (num_pages == 0) {
2306 LOG_ERROR(
"The specified flash size is less than page size");
2308 LOG_ERROR(
"Flash pages count cannot be zero");
2314 const int gap_size_kb = stm32l4_info->
hole_sectors * page_size_kb;
2316 if (gap_size_kb != 0) {
2317 LOG_INFO(
"gap detected from 0x%08x to 0x%08x",
2319 * page_size_kb * 1024,
2321 * page_size_kb + gap_size_kb) * 1024 - 1);
2337 assert((stm32l4_info->
wrpxxr_mask & 0xFFFF0000) == 0);
2340 free(
bank->sectors);
2342 bank->size = (flash_size_kb + gap_size_kb) * 1024;
2343 bank->num_sectors = num_pages;
2345 if (!
bank->sectors) {
2346 LOG_ERROR(
"failed to allocate bank sectors");
2350 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
2351 bank->sectors[i].offset = i * page_size_kb * 1024;
2355 bank->sectors[i].offset += gap_size_kb * 1024;
2356 bank->sectors[i].size = page_size_kb * 1024;
2357 bank->sectors[i].is_erased = -1;
2358 bank->sectors[i].is_protected = 1;
2361 stm32l4_info->
probed =
true;
2368 if (stm32l4_info->
probed) {
2387 if (stm32l4_info->
optr == optr_cur)
2400 const uint16_t rev_id = stm32l4_info->
idcode >> 16;
2403 if (stm32l4_info->
probed)
2414 int retval, retval2;
2507 uint32_t reg_offset;
2531 uint32_t reg_offset;
2533 uint32_t
mask = 0xFFFFFFFF;
2542 "INFO: a reset or power cycle is required "
2543 "for the new settings to take effect.",
bank->driver->name);
2550 if (CMD_ARGC < 1 || CMD_ARGC > 2)
2560 LOG_ERROR(
"This device does not have a TrustZone");
2572 LOG_INFO(
"Global TrustZone Security is %s", stm32l4_info->
tzen ?
"enabled" :
"disabled");
2579 if (new_tzen == stm32l4_info->
tzen) {
2580 LOG_INFO(
"The requested TZEN is already programmed");
2586 LOG_ERROR(
"TZEN can be set only when RDP level is 0");
2595 LOG_ERROR(
"Deactivation of TZEN is only possible when the RDP is changing to level 0");
2626 command_print(
CMD,
"stm32l4x option load completed. Power-on reset might be required");
2644 LOG_ERROR(
"cannot lock/unlock OTP memory");
2679 LOG_ERROR(
"cannot lock/unlock OTP memory");
2702 if (CMD_ARGC < 1 || CMD_ARGC > 2)
2711 LOG_ERROR(
"OTP memory does not have write protection areas");
2718 if (strcmp(
CMD_ARGV[1],
"bank1") == 0)
2720 else if (strcmp(
CMD_ARGV[1],
"bank2") == 0)
2728 LOG_ERROR(
"this device has no second bank");
2731 LOG_ERROR(
"this device is configured in single bank mode");
2737 unsigned int n_wrp, i;
2748 for (i = 0; i < n_wrp; i++) {
2749 if (wrpxy[i].
used) {
2750 for (
int p = wrpxy[i].
first; p <= wrpxy[i].
last; p++)
2756 struct range ranges[n_wrp];
2757 unsigned int ranges_count = 0;
2761 if (ranges_count > 0) {
2786 if (strcmp(
CMD_ARGV[1],
"enable") == 0)
2788 else if (strcmp(
CMD_ARGV[1],
"disable") == 0)
2790 else if (strcmp(
CMD_ARGV[1],
"show") == 0)
2802 .handler = stm32l4_handle_lock_command,
2805 .help =
"Lock entire flash device.",
2809 .handler = stm32l4_handle_unlock_command,
2812 .help =
"Unlock entire protected flash device.",
2815 .name =
"mass_erase",
2816 .handler = stm32l4_handle_mass_erase_command,
2819 .help =
"Erase entire flash device.",
2822 .name =
"option_read",
2823 .handler = stm32l4_handle_option_read_command,
2825 .usage =
"bank_id reg_offset",
2826 .help =
"Read & Display device option bytes.",
2829 .name =
"option_write",
2830 .handler = stm32l4_handle_option_write_command,
2832 .usage =
"bank_id reg_offset value [mask]",
2833 .help =
"Write device option bit fields with provided value.",
2836 .name =
"trustzone",
2837 .handler = stm32l4_handle_trustzone_command,
2839 .usage =
"<bank_id> [enable|disable]",
2840 .help =
"Configure TrustZone security",
2844 .handler = stm32l4_handle_wrp_info_command,
2846 .usage =
"bank_id [bank1|bank2]",
2847 .help =
"list the protected areas using WRP",
2850 .name =
"option_load",
2851 .handler = stm32l4_handle_option_load_command,
2854 .help =
"Force re-load of device options (will cause device reset).",
2858 .handler = stm32l4_handle_otp_command,
2860 .usage =
"<bank_id> <enable|disable|show>",
2861 .help =
"OTP (One Time Programmable) memory write enable/disable",
2870 .help =
"stm32l4x flash command group",
2880 .flash_bank_command = stm32l4_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)
This defines formats and data structures used to talk to ADIv5 entities.
static struct armv7m_common * target_to_armv7m_safe(struct target *target)
#define ARMV7M_COMMON_MAGIC
Support functions to access arbitrary bits in a byte array.
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.
static int test_bit(unsigned int nr, const volatile unsigned long *addr)
test_bit - Determine whether a bit is set
static void bitmap_zero(unsigned long *dst, unsigned int nbits)
bitmap_zero - Clears all the bits in memory
static void set_bit(unsigned int nr, volatile unsigned long *addr)
set_bit - Set a bit in memory
static void clear_bit(unsigned int nr, volatile unsigned long *addr)
clear_bit - Clear a bit in memory
#define DECLARE_BITMAP(name, bits)
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 CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_ENABLE(in, out)
parses an enable/disable command argument
#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 COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_COMMAND_ARGUMENT_INVALID
static enum cortex_m_impl_part cortex_m_get_impl_part(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_OPERATION_FAILED
#define ERROR_FLASH_DST_OUT_OF_BANK
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.
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
void alive_sleep(uint64_t ms)
#define ERROR_NOT_IMPLEMENTED
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
struct rtt_control ctrl
Control block.
static const struct stm32l4_rev stm32g05_g06xx_revs[]
static const struct stm32l4_rev stm32u3b_u3cxx_revs[]
static const struct stm32l4_rev stm32c071xx_revs[]
static int stm32l4_get_all_wrpxy(struct flash_bank *bank, enum stm32_bank_id dev_bank_id, struct stm32l4_wrp *wrpxy, unsigned int *n_wrp)
static int stm32l4_protect_check(struct flash_bank *bank)
#define FLASH_ERASE_TIMEOUT
static int stm32l4_get_one_wrpxy(struct flash_bank *bank, struct stm32l4_wrp *wrpxy, enum stm32l4_flash_reg_index reg_idx, int offset)
static const struct stm32l4_rev stm32l43_l44xx_revs[]
static const struct stm32l4_rev stm32wba2x_revs[]
static const struct stm32l4_rev stm32u53_u54xx_revs[]
static const struct stm32l4_rev stm32u59_u5axx_revs[]
static const struct command_registration stm32l4_exec_command_handlers[]
static int stm32l4_write_flash_reg(struct flash_bank *bank, uint32_t reg_offset, uint32_t value)
static const uint32_t stm32l4_flash_regs[STM32_FLASH_REG_INDEX_NUM]
@ STM32_FLASH_CR_WLK_INDEX
@ STM32_FLASH_WRP1AR_INDEX
@ STM32_FLASH_WRP2BR_INDEX
@ STM32_FLASH_OPTKEYR_INDEX
@ STM32_FLASH_WRP1BR_INDEX
@ STM32_FLASH_WRP2AR_INDEX
@ STM32_FLASH_REG_INDEX_NUM
static const struct stm32l4_rev stm32c09xx_revs[]
static int stm32l4_perform_obl_launch(struct flash_bank *bank)
static const struct stm32l4_part_info stm32l4_parts[]
static const struct stm32l4_rev stm32wba6x_revs[]
static char * range_print_alloc(struct range *ranges, unsigned int ranges_count)
static int stm32l4_read_idcode(struct flash_bank *bank, uint32_t *id)
static const struct stm32l4_rev stm32g47_g48xx_revs[]
static int stm32l4_read_flash_reg(struct flash_bank *bank, uint32_t reg_offset, uint32_t *value)
static bool stm32l4_otp_is_enabled(struct flash_bank *bank)
#define F_HAS_L5_FLASH_REGS
static const char * get_stm32l4_bank_type_str(struct flash_bank *bank)
static bool stm32l4_is_otp(struct flash_bank *bank)
static int stm32l4_get_flash_cr_with_lock_index(struct flash_bank *bank)
static const struct stm32l4_rev stm32u37_u38xx_revs[]
static int range_print_one(struct range *range, char *str)
static const struct stm32l4_rev stm32g03_g04xx_revs[]
static const struct stm32l4_rev stm32c01xx_revs[]
static const char * device_families
static const struct stm32l4_rev stm32u57_u58xx_revs[]
static const struct command_registration stm32l4_command_handlers[]
static const struct stm32l4_rev stm32l45_l46xx_revs[]
static int stm32l4_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static const struct stm32l4_rev stm32l4p_l4qxx_revs[]
static const struct stm32l4_rev stm32l41_l42xx_revs[]
static int stm32l4_otp_enable(struct flash_bank *bank, bool enable)
static const struct stm32l4_rev stm32l47_l48xx_revs[]
static const struct stm32l4_rev stm32l4r_l4sxx_revs[]
static const struct stm32l4_rev stm32c05xx_revs[]
static int stm32l4_write_option(struct flash_bank *bank, uint32_t reg_offset, uint32_t value, uint32_t mask)
static const struct stm32l4_rev stm32l55_l56xx_revs[]
static const struct stm32l4_rev stm32wb1xx_revs[]
static int stm32l4_wait_status_busy(struct flash_bank *bank, int timeout)
static const struct stm32l4_rev stm32wba5x_revs[]
static int stm32l4_mass_erase(struct flash_bank *bank)
static const char * get_stm32l4_rev_str(struct flash_bank *bank)
static int get_stm32l4_info(struct flash_bank *bank, struct command_invocation *cmd)
COMMAND_HANDLER(stm32l4_handle_mass_erase_command)
static const struct stm32l4_rev stm32_g07_g08xx_revs[]
static const struct stm32l4_rev stm32g43_g44xx_revs[]
static const struct stm32l4_rev stm32c03xx_revs[]
static uint32_t stm32l4_get_flash_reg(struct flash_bank *bank, uint32_t reg_offset)
static const struct stm32l4_rev stm32wle_wl5xx_revs[]
static int stm32l4_protect_same_bank(struct flash_bank *bank, enum stm32_bank_id bank_id, int set, unsigned int first, unsigned int last)
FLASH_BANK_COMMAND_HANDLER(stm32l4_flash_bank_command)
static int stm32l4_set_secbb(struct flash_bank *bank, uint32_t value)
set all FLASH_SECBB registers to the same value
static int stm32l4_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static const struct stm32l4_rev stm32g49_g4axx_revs[]
const struct flash_driver stm32l4x_flash
static int stm32l4_probe(struct flash_bank *bank)
static const uint32_t stm32l5_s_flash_regs[STM32_FLASH_REG_INDEX_NUM]
static int stm32l4_write_block_without_loader(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int stm32l4_read_flash_reg_by_index(struct flash_bank *bank, enum stm32l4_flash_reg_index reg_index, uint32_t *value)
static const struct stm32l4_rev stm32u0xx_revs[]
static int stm32l4_unlock_option_reg(struct flash_bank *bank)
static const uint32_t stm32wl_cpu2_flash_regs[STM32_FLASH_REG_INDEX_NUM]
static int stm32l4_unlock_reg(struct flash_bank *bank)
static int stm32l4_write_all_wrpxy(struct flash_bank *bank, struct stm32l4_wrp *wrpxy, unsigned int n_wrp)
static void stm32l4_sync_rdp_tzen(struct flash_bank *bank)
static const struct stm32l4_rev stm32wb3xx_revs[]
#define FLASH_WRITE_TIMEOUT
static const struct stm32l4_rev stm32wb5xx_revs[]
static void bitmap_to_ranges(unsigned long *bitmap, unsigned int nbits, struct range *ranges, unsigned int *ranges_count)
static const struct stm32l4_rev stm32u5f_u5gxx_revs[]
static const uint32_t stm32l5_ns_flash_regs[STM32_FLASH_REG_INDEX_NUM]
static int stm32l4_write_block(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int stm32l4_write_flash_reg_by_index(struct flash_bank *bank, enum stm32l4_flash_reg_index reg_index, uint32_t value)
static int stm32l4_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
static uint32_t stm32l4_get_flash_reg_by_index(struct flash_bank *bank, enum stm32l4_flash_reg_index reg_index)
static int stm32l4_write_one_wrpxy(struct flash_bank *bank, struct stm32l4_wrp *wrpxy)
static const struct stm32l4_rev stm32l49_l4axx_revs[]
static int stm32l4_auto_probe(struct flash_bank *bank)
static const struct stm32l4_rev stm32g0b_g0cxx_revs[]
#define DEVID_STM32G03_G04XX
#define DEVID_STM32L55_L56XX
#define DEVID_STM32G0B_G0CXX
#define FLASH_SECBB_SECURE
#define FLASH_G0_DUAL_BANK
#define STM32_FLASH_S_BANK_BASE
#define DEVID_STM32G49_G4AXX
#define DEVID_STM32U53_U54XX
#define DEVID_STM32L4R_L4SXX
#define FLASH_L4_DUAL_BANK
#define DEVID_STM32G47_G48XX
#define FLASH_U5_DUALBANK
#define DEVID_STM32U5F_U5GXX
#define STM32_FLASH_BANK_BASE
#define FLASH_G4_DUAL_BANK
#define DEVID_STM32L47_L48XX
#define DEVID_STM32G07_G08XX
#define DEVID_STM32C071XX
#define DEVID_STM32U59_U5AXX
#define DEVID_STM32L49_L4AXX
#define DEVID_STM32L43_L44XX
#define DEVID_STM32L41_L42XX
#define DEVID_STM32U073_U083XX
#define DEVID_STM32WLE_WL5XX
#define DEVID_STM32G05_G06XX
#define DEVID_STM32U031XX
#define DEVID_STM32U37_U38XX
#define FLASH_WRPXYR_UNLOCK
#define DEVID_STM32G43_G44XX
#define UID64_IDS_STM32WL
#define FLASH_SECBB_NON_SECURE
#define STM32L5_REGS_SEC_OFFSET
#define DEVID_STM32U3B_U3CXX
#define DEVID_STM32U57_U58XX
#define DBGMCU_IDCODE_L4_G4
#define DEVID_STM32L4P_L4QXX
#define DEVID_STM32L45_L46XX
uint64_t ap_num
ADIv5: Number of this AP (0~255) ADIv6: Base address of this AP (4k aligned) TODO: to be more coheren...
unsigned int common_magic
struct adiv5_ap * debug_ap
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Provides details of a flash bank, available either on-chip or through a major interface.
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
Describes the geometry and status of a single flash sector within a flash bank.
uint32_t offset
Bus offset from start of the flash chip (in bytes).
uint32_t size
Number of bytes in this flash sector.
unsigned int bank1_sectors
const uint32_t * flash_regs
const struct stm32l4_part_info * part_info
const struct stm32l4_rev * revs
const uint32_t fsize_addr
const uint32_t flash_regs_base
const uint16_t max_flash_size_kb
uint8_t stack[LDR_STACK_SIZE]
enum stm32l4_flash_reg_index reg_idx
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_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_free_working_area(struct target *target, struct working_area *area)
Free a working area.
int target_alloc_working_area_try(struct target *target, uint32_t size, struct working_area **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)
#define ERROR_TARGET_NOT_HALTED
static bool target_was_examined(const struct target *target)
#define ERROR_TARGET_INVALID
#define ERROR_TARGET_NOT_EXAMINED
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
#define ERROR_TARGET_FAILURE
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.