juno_bl1_setup.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <errno.h>
  7. #include <common/bl_common.h>
  8. #include <common/debug.h>
  9. #include <common/tbbr/tbbr_img_def.h>
  10. #include <drivers/arm/css/sds.h>
  11. #include <drivers/arm/sp805.h>
  12. #include <plat/arm/common/plat_arm.h>
  13. #include <plat/arm/common/arm_def.h>
  14. #include <plat/common/platform.h>
  15. #include <platform_def.h>
  16. void juno_reset_to_aarch32_state(void);
  17. static int is_watchdog_reset(void)
  18. {
  19. #if !CSS_USE_SCMI_SDS_DRIVER
  20. #define RESET_REASON_WDOG_RESET (0x2)
  21. const uint32_t *reset_flags_ptr = (const uint32_t *)SSC_GPRETN;
  22. if ((*reset_flags_ptr & RESET_REASON_WDOG_RESET) != 0)
  23. return 1;
  24. return 0;
  25. #else
  26. int ret;
  27. uint32_t scp_reset_synd_flags;
  28. ret = sds_init(SDS_SCP_AP_REGION_ID);
  29. if (ret != SDS_OK) {
  30. ERROR("SCP SDS initialization failed\n");
  31. panic();
  32. }
  33. ret = sds_struct_read(SDS_SCP_AP_REGION_ID,
  34. SDS_RESET_SYNDROME_STRUCT_ID,
  35. SDS_RESET_SYNDROME_OFFSET,
  36. &scp_reset_synd_flags,
  37. SDS_RESET_SYNDROME_SIZE,
  38. SDS_ACCESS_MODE_NON_CACHED);
  39. if (ret != SDS_OK) {
  40. ERROR("Getting reset reason from SDS failed\n");
  41. panic();
  42. }
  43. /* Check if the WATCHDOG_RESET_BIT is set in the reset syndrome */
  44. if (scp_reset_synd_flags & SDS_RESET_SYNDROME_AP_WD_RESET_BIT)
  45. return 1;
  46. return 0;
  47. #endif
  48. }
  49. /*******************************************************************************
  50. * The following function checks if Firmware update is needed,
  51. * by checking if TOC in FIP image is valid or watchdog reset happened.
  52. ******************************************************************************/
  53. bool plat_arm_bl1_fwu_needed(void)
  54. {
  55. int32_t nv_flags = (int32_t)mmio_read_32(V2M_SYS_NVFLAGS_ADDR);
  56. /* Check if TOC is invalid or watchdog reset happened. */
  57. return (!arm_io_is_toc_valid() || (((nv_flags == -EAUTH) ||
  58. (nv_flags == -ENOENT)) && is_watchdog_reset()));
  59. }
  60. /*******************************************************************************
  61. * On JUNO update the arg2 with address of SCP_BL2U image info.
  62. ******************************************************************************/
  63. void bl1_plat_set_ep_info(unsigned int image_id,
  64. entry_point_info_t *ep_info)
  65. {
  66. if (image_id == BL2U_IMAGE_ID) {
  67. image_desc_t *image_desc = bl1_plat_get_image_desc(SCP_BL2U_IMAGE_ID);
  68. ep_info->args.arg2 = (unsigned long)&image_desc->image_info;
  69. }
  70. }
  71. /*******************************************************************************
  72. * On Juno clear SYS_NVFLAGS and wait for watchdog reset.
  73. ******************************************************************************/
  74. __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
  75. {
  76. uint32_t nv_flags = mmio_read_32(V2M_SYS_NVFLAGS_ADDR);
  77. /* Clear the NV flags register. */
  78. mmio_write_32((V2M_SYSREGS_BASE + V2M_SYS_NVFLAGSCLR),
  79. nv_flags);
  80. /* Setup the watchdog to reset the system as soon as possible */
  81. sp805_refresh(ARM_SP805_TWDG_BASE, 1U);
  82. while (true)
  83. wfi();
  84. }
  85. #if JUNO_AARCH32_EL3_RUNTIME
  86. void bl1_plat_prepare_exit(entry_point_info_t *ep_info)
  87. {
  88. #if !ARM_DISABLE_TRUSTED_WDOG
  89. /* Disable watchdog before leaving BL1 */
  90. sp805_stop(ARM_SP805_TWDG_BASE);
  91. #endif
  92. juno_reset_to_aarch32_state();
  93. }
  94. #endif /* JUNO_AARCH32_EL3_RUNTIME */
  95. void plat_arm_secure_wdt_start(void)
  96. {
  97. sp805_start(ARM_SP805_TWDG_BASE, ARM_TWDG_LOAD_VAL);
  98. }
  99. void plat_arm_secure_wdt_stop(void)
  100. {
  101. sp805_stop(ARM_SP805_TWDG_BASE);
  102. }