stm32mp1_private.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <drivers/clk.h>
  8. #include <drivers/st/stm32_gpio.h>
  9. #include <drivers/st/stm32_iwdg.h>
  10. #include <lib/mmio.h>
  11. #include <lib/xlat_tables/xlat_tables_v2.h>
  12. #include <libfdt.h>
  13. #include <plat/common/platform.h>
  14. #include <platform_def.h>
  15. #if STM32MP13
  16. #define TAMP_BOOT_MODE_BACKUP_REG_ID U(30)
  17. #endif
  18. #if STM32MP15
  19. #define TAMP_BOOT_MODE_BACKUP_REG_ID U(20)
  20. #endif
  21. /*
  22. * Backup register to store fwu update information.
  23. * It should be writeable only by secure world, but also readable by non secure
  24. * (so it should be in Zone 2).
  25. */
  26. #define TAMP_BOOT_FWU_INFO_REG_ID U(10)
  27. #define TAMP_BOOT_FWU_INFO_IDX_MSK GENMASK(3, 0)
  28. #define TAMP_BOOT_FWU_INFO_IDX_OFF U(0)
  29. #define TAMP_BOOT_FWU_INFO_CNT_MSK GENMASK(7, 4)
  30. #define TAMP_BOOT_FWU_INFO_CNT_OFF U(4)
  31. #if defined(IMAGE_BL2)
  32. #define MAP_SEC_SYSRAM MAP_REGION_FLAT(STM32MP_SYSRAM_BASE, \
  33. STM32MP_SYSRAM_SIZE, \
  34. MT_MEMORY | \
  35. MT_RW | \
  36. MT_SECURE | \
  37. MT_EXECUTE_NEVER)
  38. #elif defined(IMAGE_BL32)
  39. #define MAP_SEC_SYSRAM MAP_REGION_FLAT(STM32MP_SEC_SYSRAM_BASE, \
  40. STM32MP_SEC_SYSRAM_SIZE, \
  41. MT_MEMORY | \
  42. MT_RW | \
  43. MT_SECURE | \
  44. MT_EXECUTE_NEVER)
  45. /* Non-secure SYSRAM is used a uncached memory for SCMI message transfer */
  46. #define MAP_NS_SYSRAM MAP_REGION_FLAT(STM32MP_NS_SYSRAM_BASE, \
  47. STM32MP_NS_SYSRAM_SIZE, \
  48. MT_DEVICE | \
  49. MT_RW | \
  50. MT_NS | \
  51. MT_EXECUTE_NEVER)
  52. #endif
  53. #if STM32MP13
  54. #define MAP_SRAM_ALL MAP_REGION_FLAT(SRAMS_BASE, \
  55. SRAMS_SIZE_2MB_ALIGNED, \
  56. MT_MEMORY | \
  57. MT_RW | \
  58. MT_SECURE | \
  59. MT_EXECUTE_NEVER)
  60. #endif
  61. #define MAP_DEVICE1 MAP_REGION_FLAT(STM32MP1_DEVICE1_BASE, \
  62. STM32MP1_DEVICE1_SIZE, \
  63. MT_DEVICE | \
  64. MT_RW | \
  65. MT_SECURE | \
  66. MT_EXECUTE_NEVER)
  67. #define MAP_DEVICE2 MAP_REGION_FLAT(STM32MP1_DEVICE2_BASE, \
  68. STM32MP1_DEVICE2_SIZE, \
  69. MT_DEVICE | \
  70. MT_RW | \
  71. MT_SECURE | \
  72. MT_EXECUTE_NEVER)
  73. #if defined(IMAGE_BL2)
  74. static const mmap_region_t stm32mp1_mmap[] = {
  75. MAP_SEC_SYSRAM,
  76. #if STM32MP13
  77. MAP_SRAM_ALL,
  78. #endif
  79. MAP_DEVICE1,
  80. #if STM32MP_RAW_NAND
  81. MAP_DEVICE2,
  82. #endif
  83. {0}
  84. };
  85. #endif
  86. #if defined(IMAGE_BL32)
  87. static const mmap_region_t stm32mp1_mmap[] = {
  88. MAP_SEC_SYSRAM,
  89. MAP_NS_SYSRAM,
  90. MAP_DEVICE1,
  91. MAP_DEVICE2,
  92. {0}
  93. };
  94. #endif
  95. void configure_mmu(void)
  96. {
  97. mmap_add(stm32mp1_mmap);
  98. init_xlat_tables();
  99. enable_mmu_svc_mon(0);
  100. }
  101. uintptr_t stm32_get_gpio_bank_base(unsigned int bank)
  102. {
  103. #if STM32MP13
  104. assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_I));
  105. #endif
  106. #if STM32MP15
  107. if (bank == GPIO_BANK_Z) {
  108. return GPIOZ_BASE;
  109. }
  110. assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_K));
  111. #endif
  112. return GPIOA_BASE + (bank * GPIO_BANK_OFFSET);
  113. }
  114. uint32_t stm32_get_gpio_bank_offset(unsigned int bank)
  115. {
  116. #if STM32MP13
  117. assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_I));
  118. #endif
  119. #if STM32MP15
  120. if (bank == GPIO_BANK_Z) {
  121. return 0;
  122. }
  123. assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_K));
  124. #endif
  125. return bank * GPIO_BANK_OFFSET;
  126. }
  127. bool stm32_gpio_is_secure_at_reset(unsigned int bank)
  128. {
  129. #if STM32MP13
  130. return true;
  131. #endif
  132. #if STM32MP15
  133. if (bank == GPIO_BANK_Z) {
  134. return true;
  135. }
  136. return false;
  137. #endif
  138. }
  139. unsigned long stm32_get_gpio_bank_clock(unsigned int bank)
  140. {
  141. #if STM32MP13
  142. assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_I));
  143. #endif
  144. #if STM32MP15
  145. if (bank == GPIO_BANK_Z) {
  146. return GPIOZ;
  147. }
  148. assert((GPIO_BANK_A == 0) && (bank <= GPIO_BANK_K));
  149. #endif
  150. return GPIOA + (bank - GPIO_BANK_A);
  151. }
  152. int stm32_get_gpio_bank_pinctrl_node(void *fdt, unsigned int bank)
  153. {
  154. const char *node_compatible = NULL;
  155. switch (bank) {
  156. case GPIO_BANK_A:
  157. case GPIO_BANK_B:
  158. case GPIO_BANK_C:
  159. case GPIO_BANK_D:
  160. case GPIO_BANK_E:
  161. case GPIO_BANK_F:
  162. case GPIO_BANK_G:
  163. case GPIO_BANK_H:
  164. case GPIO_BANK_I:
  165. #if STM32MP13
  166. node_compatible = "st,stm32mp135-pinctrl";
  167. break;
  168. #endif
  169. #if STM32MP15
  170. case GPIO_BANK_J:
  171. case GPIO_BANK_K:
  172. node_compatible = "st,stm32mp157-pinctrl";
  173. break;
  174. case GPIO_BANK_Z:
  175. node_compatible = "st,stm32mp157-z-pinctrl";
  176. break;
  177. #endif
  178. default:
  179. panic();
  180. }
  181. return fdt_node_offset_by_compatible(fdt, -1, node_compatible);
  182. }
  183. #if STM32MP_UART_PROGRAMMER || !defined(IMAGE_BL2)
  184. /*
  185. * UART Management
  186. */
  187. static const uintptr_t stm32mp1_uart_addresses[8] = {
  188. USART1_BASE,
  189. USART2_BASE,
  190. USART3_BASE,
  191. UART4_BASE,
  192. UART5_BASE,
  193. USART6_BASE,
  194. UART7_BASE,
  195. UART8_BASE,
  196. };
  197. uintptr_t get_uart_address(uint32_t instance_nb)
  198. {
  199. if ((instance_nb == 0U) ||
  200. (instance_nb > ARRAY_SIZE(stm32mp1_uart_addresses))) {
  201. return 0U;
  202. }
  203. return stm32mp1_uart_addresses[instance_nb - 1U];
  204. }
  205. #endif
  206. #if STM32MP_USB_PROGRAMMER
  207. struct gpio_bank_pin_list {
  208. uint32_t bank;
  209. uint32_t pin;
  210. };
  211. static const struct gpio_bank_pin_list gpio_list[] = {
  212. { /* USART2_RX: GPIOA3 */
  213. .bank = 0U,
  214. .pin = 3U,
  215. },
  216. { /* USART3_RX: GPIOB12 */
  217. .bank = 1U,
  218. .pin = 12U,
  219. },
  220. { /* UART4_RX: GPIOB2 */
  221. .bank = 1U,
  222. .pin = 2U,
  223. },
  224. { /* UART5_RX: GPIOB4 */
  225. .bank = 1U,
  226. .pin = 5U,
  227. },
  228. { /* USART6_RX: GPIOC7 */
  229. .bank = 2U,
  230. .pin = 7U,
  231. },
  232. { /* UART7_RX: GPIOF6 */
  233. .bank = 5U,
  234. .pin = 6U,
  235. },
  236. { /* UART8_RX: GPIOE0 */
  237. .bank = 4U,
  238. .pin = 0U,
  239. },
  240. };
  241. void stm32mp1_deconfigure_uart_pins(void)
  242. {
  243. size_t i;
  244. for (i = 0U; i < ARRAY_SIZE(gpio_list); i++) {
  245. set_gpio_reset_cfg(gpio_list[i].bank, gpio_list[i].pin);
  246. }
  247. }
  248. #endif
  249. uint32_t stm32mp_get_chip_version(void)
  250. {
  251. #if STM32MP13
  252. return stm32mp1_syscfg_get_chip_version();
  253. #endif
  254. #if STM32MP15
  255. uint32_t version = 0U;
  256. if (stm32mp1_dbgmcu_get_chip_version(&version) < 0) {
  257. INFO("Cannot get CPU version, debug disabled\n");
  258. return 0U;
  259. }
  260. return version;
  261. #endif
  262. }
  263. uint32_t stm32mp_get_chip_dev_id(void)
  264. {
  265. #if STM32MP13
  266. return stm32mp1_syscfg_get_chip_dev_id();
  267. #endif
  268. #if STM32MP15
  269. uint32_t dev_id;
  270. if (stm32mp1_dbgmcu_get_chip_dev_id(&dev_id) < 0) {
  271. INFO("Use default chip ID, debug disabled\n");
  272. dev_id = STM32MP1_CHIP_ID;
  273. }
  274. return dev_id;
  275. #endif
  276. }
  277. static uint32_t get_part_number(void)
  278. {
  279. static uint32_t part_number;
  280. if (part_number != 0U) {
  281. return part_number;
  282. }
  283. if (stm32_get_otp_value(PART_NUMBER_OTP, &part_number) != 0) {
  284. panic();
  285. }
  286. part_number = (part_number & PART_NUMBER_OTP_PART_MASK) >>
  287. PART_NUMBER_OTP_PART_SHIFT;
  288. part_number |= stm32mp_get_chip_dev_id() << 16;
  289. return part_number;
  290. }
  291. #if STM32MP15
  292. static uint32_t get_cpu_package(void)
  293. {
  294. uint32_t package;
  295. if (stm32_get_otp_value(PACKAGE_OTP, &package) != 0) {
  296. panic();
  297. }
  298. package = (package & PACKAGE_OTP_PKG_MASK) >>
  299. PACKAGE_OTP_PKG_SHIFT;
  300. return package;
  301. }
  302. #endif
  303. void stm32mp_get_soc_name(char name[STM32_SOC_NAME_SIZE])
  304. {
  305. const char *cpu_s, *cpu_r, *pkg;
  306. /* MPUs Part Numbers */
  307. switch (get_part_number()) {
  308. #if STM32MP13
  309. case STM32MP135F_PART_NB:
  310. cpu_s = "135F";
  311. break;
  312. case STM32MP135D_PART_NB:
  313. cpu_s = "135D";
  314. break;
  315. case STM32MP135C_PART_NB:
  316. cpu_s = "135C";
  317. break;
  318. case STM32MP135A_PART_NB:
  319. cpu_s = "135A";
  320. break;
  321. case STM32MP133F_PART_NB:
  322. cpu_s = "133F";
  323. break;
  324. case STM32MP133D_PART_NB:
  325. cpu_s = "133D";
  326. break;
  327. case STM32MP133C_PART_NB:
  328. cpu_s = "133C";
  329. break;
  330. case STM32MP133A_PART_NB:
  331. cpu_s = "133A";
  332. break;
  333. case STM32MP131F_PART_NB:
  334. cpu_s = "131F";
  335. break;
  336. case STM32MP131D_PART_NB:
  337. cpu_s = "131D";
  338. break;
  339. case STM32MP131C_PART_NB:
  340. cpu_s = "131C";
  341. break;
  342. case STM32MP131A_PART_NB:
  343. cpu_s = "131A";
  344. break;
  345. #endif
  346. #if STM32MP15
  347. case STM32MP157C_PART_NB:
  348. cpu_s = "157C";
  349. break;
  350. case STM32MP157A_PART_NB:
  351. cpu_s = "157A";
  352. break;
  353. case STM32MP153C_PART_NB:
  354. cpu_s = "153C";
  355. break;
  356. case STM32MP153A_PART_NB:
  357. cpu_s = "153A";
  358. break;
  359. case STM32MP151C_PART_NB:
  360. cpu_s = "151C";
  361. break;
  362. case STM32MP151A_PART_NB:
  363. cpu_s = "151A";
  364. break;
  365. case STM32MP157F_PART_NB:
  366. cpu_s = "157F";
  367. break;
  368. case STM32MP157D_PART_NB:
  369. cpu_s = "157D";
  370. break;
  371. case STM32MP153F_PART_NB:
  372. cpu_s = "153F";
  373. break;
  374. case STM32MP153D_PART_NB:
  375. cpu_s = "153D";
  376. break;
  377. case STM32MP151F_PART_NB:
  378. cpu_s = "151F";
  379. break;
  380. case STM32MP151D_PART_NB:
  381. cpu_s = "151D";
  382. break;
  383. #endif
  384. default:
  385. cpu_s = "????";
  386. break;
  387. }
  388. /* Package */
  389. #if STM32MP13
  390. /* On STM32MP13, package is not present in OTP */
  391. pkg = "";
  392. #endif
  393. #if STM32MP15
  394. switch (get_cpu_package()) {
  395. case PKG_AA_LFBGA448:
  396. pkg = "AA";
  397. break;
  398. case PKG_AB_LFBGA354:
  399. pkg = "AB";
  400. break;
  401. case PKG_AC_TFBGA361:
  402. pkg = "AC";
  403. break;
  404. case PKG_AD_TFBGA257:
  405. pkg = "AD";
  406. break;
  407. default:
  408. pkg = "??";
  409. break;
  410. }
  411. #endif
  412. /* REVISION */
  413. switch (stm32mp_get_chip_version()) {
  414. case STM32MP1_REV_B:
  415. cpu_r = "B";
  416. break;
  417. #if STM32MP13
  418. case STM32MP1_REV_Y:
  419. cpu_r = "Y";
  420. break;
  421. #endif
  422. case STM32MP1_REV_Z:
  423. cpu_r = "Z";
  424. break;
  425. default:
  426. cpu_r = "?";
  427. break;
  428. }
  429. snprintf(name, STM32_SOC_NAME_SIZE,
  430. "STM32MP%s%s Rev.%s", cpu_s, pkg, cpu_r);
  431. }
  432. void stm32mp_print_cpuinfo(void)
  433. {
  434. char name[STM32_SOC_NAME_SIZE];
  435. stm32mp_get_soc_name(name);
  436. NOTICE("CPU: %s\n", name);
  437. }
  438. void stm32mp_print_boardinfo(void)
  439. {
  440. uint32_t board_id = 0U;
  441. if (stm32_get_otp_value(BOARD_ID_OTP, &board_id) != 0) {
  442. return;
  443. }
  444. if (board_id != 0U) {
  445. stm32_display_board_info(board_id);
  446. }
  447. }
  448. /* Return true when SoC provides a single Cortex-A7 core, and false otherwise */
  449. bool stm32mp_is_single_core(void)
  450. {
  451. #if STM32MP13
  452. return true;
  453. #endif
  454. #if STM32MP15
  455. bool single_core = false;
  456. switch (get_part_number()) {
  457. case STM32MP151A_PART_NB:
  458. case STM32MP151C_PART_NB:
  459. case STM32MP151D_PART_NB:
  460. case STM32MP151F_PART_NB:
  461. single_core = true;
  462. break;
  463. default:
  464. break;
  465. }
  466. return single_core;
  467. #endif
  468. }
  469. /* Return true when device is in closed state */
  470. bool stm32mp_is_closed_device(void)
  471. {
  472. uint32_t value;
  473. if (stm32_get_otp_value(CFG0_OTP, &value) != 0) {
  474. return true;
  475. }
  476. #if STM32MP13
  477. value = (value & CFG0_OTP_MODE_MASK) >> CFG0_OTP_MODE_SHIFT;
  478. switch (value) {
  479. case CFG0_OPEN_DEVICE:
  480. return false;
  481. case CFG0_CLOSED_DEVICE:
  482. case CFG0_CLOSED_DEVICE_NO_BOUNDARY_SCAN:
  483. case CFG0_CLOSED_DEVICE_NO_JTAG:
  484. return true;
  485. default:
  486. panic();
  487. }
  488. #endif
  489. #if STM32MP15
  490. return (value & CFG0_CLOSED_DEVICE) == CFG0_CLOSED_DEVICE;
  491. #endif
  492. }
  493. /* Return true when device supports secure boot */
  494. bool stm32mp_is_auth_supported(void)
  495. {
  496. bool supported = false;
  497. switch (get_part_number()) {
  498. #if STM32MP13
  499. case STM32MP131C_PART_NB:
  500. case STM32MP131F_PART_NB:
  501. case STM32MP133C_PART_NB:
  502. case STM32MP133F_PART_NB:
  503. case STM32MP135C_PART_NB:
  504. case STM32MP135F_PART_NB:
  505. #endif
  506. #if STM32MP15
  507. case STM32MP151C_PART_NB:
  508. case STM32MP151F_PART_NB:
  509. case STM32MP153C_PART_NB:
  510. case STM32MP153F_PART_NB:
  511. case STM32MP157C_PART_NB:
  512. case STM32MP157F_PART_NB:
  513. #endif
  514. supported = true;
  515. break;
  516. default:
  517. break;
  518. }
  519. return supported;
  520. }
  521. uint32_t stm32_iwdg_get_instance(uintptr_t base)
  522. {
  523. switch (base) {
  524. case IWDG1_BASE:
  525. return IWDG1_INST;
  526. case IWDG2_BASE:
  527. return IWDG2_INST;
  528. default:
  529. panic();
  530. }
  531. }
  532. uint32_t stm32_iwdg_get_otp_config(uint32_t iwdg_inst)
  533. {
  534. uint32_t iwdg_cfg = 0U;
  535. uint32_t otp_value;
  536. if (stm32_get_otp_value(HW2_OTP, &otp_value) != 0) {
  537. panic();
  538. }
  539. if ((otp_value & BIT(iwdg_inst + HW2_OTP_IWDG_HW_POS)) != 0U) {
  540. iwdg_cfg |= IWDG_HW_ENABLED;
  541. }
  542. if ((otp_value & BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STOP_POS)) != 0U) {
  543. iwdg_cfg |= IWDG_DISABLE_ON_STOP;
  544. }
  545. if ((otp_value & BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STANDBY_POS)) != 0U) {
  546. iwdg_cfg |= IWDG_DISABLE_ON_STANDBY;
  547. }
  548. return iwdg_cfg;
  549. }
  550. #if defined(IMAGE_BL2)
  551. uint32_t stm32_iwdg_shadow_update(uint32_t iwdg_inst, uint32_t flags)
  552. {
  553. uint32_t otp_value;
  554. uint32_t otp;
  555. uint32_t result;
  556. if (stm32_get_otp_index(HW2_OTP, &otp, NULL) != 0) {
  557. panic();
  558. }
  559. if (stm32_get_otp_value(HW2_OTP, &otp_value) != 0) {
  560. panic();
  561. }
  562. if ((flags & IWDG_DISABLE_ON_STOP) != 0) {
  563. otp_value |= BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STOP_POS);
  564. }
  565. if ((flags & IWDG_DISABLE_ON_STANDBY) != 0) {
  566. otp_value |= BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STANDBY_POS);
  567. }
  568. result = bsec_write_otp(otp_value, otp);
  569. if (result != BSEC_OK) {
  570. return result;
  571. }
  572. /* Sticky lock OTP_IWDG (read and write) */
  573. if ((bsec_set_sr_lock(otp) != BSEC_OK) ||
  574. (bsec_set_sw_lock(otp) != BSEC_OK)) {
  575. return BSEC_LOCK_FAIL;
  576. }
  577. return BSEC_OK;
  578. }
  579. #endif
  580. uintptr_t stm32_get_bkpr_boot_mode_addr(void)
  581. {
  582. return tamp_bkpr(TAMP_BOOT_MODE_BACKUP_REG_ID);
  583. }
  584. #if PSA_FWU_SUPPORT
  585. void stm32mp1_fwu_set_boot_idx(void)
  586. {
  587. clk_enable(RTCAPB);
  588. mmio_clrsetbits_32(tamp_bkpr(TAMP_BOOT_FWU_INFO_REG_ID),
  589. TAMP_BOOT_FWU_INFO_IDX_MSK,
  590. (plat_fwu_get_boot_idx() << TAMP_BOOT_FWU_INFO_IDX_OFF) &
  591. TAMP_BOOT_FWU_INFO_IDX_MSK);
  592. clk_disable(RTCAPB);
  593. }
  594. uint32_t stm32_get_and_dec_fwu_trial_boot_cnt(void)
  595. {
  596. uintptr_t bkpr_fwu_cnt = tamp_bkpr(TAMP_BOOT_FWU_INFO_REG_ID);
  597. uint32_t try_cnt;
  598. clk_enable(RTCAPB);
  599. try_cnt = (mmio_read_32(bkpr_fwu_cnt) & TAMP_BOOT_FWU_INFO_CNT_MSK) >>
  600. TAMP_BOOT_FWU_INFO_CNT_OFF;
  601. assert(try_cnt <= FWU_MAX_TRIAL_REBOOT);
  602. if (try_cnt != 0U) {
  603. mmio_clrsetbits_32(bkpr_fwu_cnt, TAMP_BOOT_FWU_INFO_CNT_MSK,
  604. (try_cnt - 1U) << TAMP_BOOT_FWU_INFO_CNT_OFF);
  605. }
  606. clk_disable(RTCAPB);
  607. return try_cnt;
  608. }
  609. void stm32_set_max_fwu_trial_boot_cnt(void)
  610. {
  611. uintptr_t bkpr_fwu_cnt = tamp_bkpr(TAMP_BOOT_FWU_INFO_REG_ID);
  612. clk_enable(RTCAPB);
  613. mmio_clrsetbits_32(bkpr_fwu_cnt, TAMP_BOOT_FWU_INFO_CNT_MSK,
  614. (FWU_MAX_TRIAL_REBOOT << TAMP_BOOT_FWU_INFO_CNT_OFF) &
  615. TAMP_BOOT_FWU_INFO_CNT_MSK);
  616. clk_disable(RTCAPB);
  617. }
  618. #endif /* PSA_FWU_SUPPORT */