plat_warm_reset.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright 2021 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #include <errno.h>
  8. #include <common/debug.h>
  9. #include <ddr.h>
  10. #ifndef NXP_COINED_BB
  11. #include <flash_info.h>
  12. #include <fspi.h>
  13. #include <fspi_api.h>
  14. #endif
  15. #include <lib/mmio.h>
  16. #include <lib/psci/psci.h>
  17. #ifdef NXP_COINED_BB
  18. #include <snvs.h>
  19. #endif
  20. #include <plat_nv_storage.h>
  21. #include "plat_warm_rst.h"
  22. #include "platform_def.h"
  23. #if defined(IMAGE_BL2)
  24. uint32_t is_warm_boot(void)
  25. {
  26. uint32_t ret = mmio_read_32(NXP_RESET_ADDR + RST_RSTRQSR1_OFFSET)
  27. & ~(RSTRQSR1_SWRR);
  28. const nv_app_data_t *nv_app_data = get_nv_data();
  29. if (ret == 0U) {
  30. INFO("Not a SW(Warm) triggered reset.\n");
  31. return 0U;
  32. }
  33. ret = (nv_app_data->warm_rst_flag == WARM_BOOT_SUCCESS) ? 1 : 0;
  34. if (ret != 0U) {
  35. INFO("Warm Reset was triggered..\n");
  36. } else {
  37. INFO("Warm Reset was not triggered..\n");
  38. }
  39. return ret;
  40. }
  41. #endif
  42. #if defined(IMAGE_BL31)
  43. int prep_n_execute_warm_reset(void)
  44. {
  45. #ifdef NXP_COINED_BB
  46. #if !TRUSTED_BOARD_BOOT
  47. snvs_disable_zeroize_lp_gpr();
  48. #endif
  49. #else
  50. int ret;
  51. uint8_t warm_reset = WARM_BOOT_SUCCESS;
  52. ret = fspi_init(NXP_FLEXSPI_ADDR, NXP_FLEXSPI_FLASH_ADDR);
  53. if (ret != 0) {
  54. ERROR("Failed to initialized driver flexspi-nor.\n");
  55. ERROR("exiting warm-reset request.\n");
  56. return PSCI_E_INTERN_FAIL;
  57. }
  58. /* Sector starting from NV_STORAGE_BASE_ADDR is already
  59. * erased for writing.
  60. */
  61. #if (ERLY_WRM_RST_FLG_FLSH_UPDT)
  62. ret = xspi_write((uint32_t)NV_STORAGE_BASE_ADDR,
  63. &warm_reset,
  64. sizeof(warm_reset));
  65. #else
  66. /* Preparation for writing the Warm reset flag. */
  67. ret = xspi_wren((uint32_t)NV_STORAGE_BASE_ADDR);
  68. /* IP Control Register0 - SF Address to be read */
  69. fspi_out32((NXP_FLEXSPI_ADDR + FSPI_IPCR0),
  70. (uint32_t) NV_STORAGE_BASE_ADDR);
  71. while ((fspi_in32(NXP_FLEXSPI_ADDR + FSPI_INTR) &
  72. FSPI_INTR_IPTXWE_MASK) == 0) {
  73. ;
  74. }
  75. /* Write TX FIFO Data Register */
  76. fspi_out32(NXP_FLEXSPI_ADDR + FSPI_TFDR, (uint32_t) warm_reset);
  77. fspi_out32(NXP_FLEXSPI_ADDR + FSPI_INTR, FSPI_INTR_IPTXWE);
  78. /* IP Control Register1 - SEQID_WRITE operation, Size = 1 Byte */
  79. fspi_out32(NXP_FLEXSPI_ADDR + FSPI_IPCR1,
  80. (uint32_t)(FSPI_WRITE_SEQ_ID << FSPI_IPCR1_ISEQID_SHIFT) |
  81. (uint16_t) sizeof(warm_reset));
  82. /* Trigger XSPI-IP-Write cmd only if:
  83. * - Putting DDR in-self refresh mode is successfully.
  84. * to complete the writing of the warm-reset flag
  85. * to flash.
  86. *
  87. * This code is as part of assembly.
  88. */
  89. #endif
  90. #endif
  91. INFO("Doing DDR Self refresh.\n");
  92. _soc_sys_warm_reset();
  93. /* Expected behaviour is to do the power cycle */
  94. while (1 != 0)
  95. ;
  96. return -1;
  97. }
  98. #endif