Juno: Change the Firmware update detect mechanism
authorSoby Mathew <soby.mathew@arm.com>
Wed, 7 Mar 2018 11:32:04 +0000 (11:32 +0000)
committerSoby Mathew <soby.mathew@arm.com>
Thu, 8 Mar 2018 09:44:05 +0000 (09:44 +0000)
Previously, Juno used to depend on the SSC_GPRETN register to inform
about the reset syndrome. This method was removed when SCP migrated
to the SDS framework. But even the SDS framework doesn't report the
reset syndrome correctly and hence Juno failed to enter Firmware
update mode if BL2 authentication failed.

In addition to that, the error code populated in V2M_SYS_NVFLAGS register
does not seem to be retained any more on Juno across resets. This could
be down to the motherboard firmware not doing the necessary to preserve
the value.

Hence this patch modifies the Juno platform to use the same mechanism to
trigger firmware update as FVP which is to corrupt the FIP TOC on
authentication failure. The implementation in `fvp_err.c` is made common
for ARM platforms and is moved to the new `arm_err.c` file in
plat/arm/common folder. The BL1 and BL2 mmap table entries for Juno
are modified to allow write to the Flash memory address.

Change-Id: Ica7d49a3e8a46a90efd4cf340f19fda3b549e945
Signed-off-by: Soby Mathew <soby.mathew@arm.com>
plat/arm/board/common/board_css_common.c
plat/arm/board/fvp/fvp_bl1_setup.c
plat/arm/board/fvp/fvp_err.c [deleted file]
plat/arm/board/fvp/platform.mk
plat/arm/board/juno/juno_bl1_setup.c
plat/arm/board/juno/juno_err.c [deleted file]
plat/arm/board/juno/platform.mk
plat/arm/common/arm_bl1_setup.c
plat/arm/common/arm_common.mk
plat/arm/common/arm_err.c [new file with mode: 0644]

index 032ebdf7ec04381b8baa9c4bcf9b1d5a86f76c39..c1c3e66a64c5ba4546e98fa3ab4024880c9b5a93 100644 (file)
@@ -14,7 +14,7 @@
 #ifdef IMAGE_BL1
 const mmap_region_t plat_arm_mmap[] = {
        ARM_MAP_SHARED_RAM,
-       V2M_MAP_FLASH0_RO,
+       V2M_MAP_FLASH0_RW,
        V2M_MAP_IOFPGA,
        CSS_MAP_DEVICE,
        SOC_CSS_MAP_DEVICE,
@@ -28,7 +28,7 @@ const mmap_region_t plat_arm_mmap[] = {
 #ifdef IMAGE_BL2
 const mmap_region_t plat_arm_mmap[] = {
        ARM_MAP_SHARED_RAM,
-       V2M_MAP_FLASH0_RO,
+       V2M_MAP_FLASH0_RW,
 #ifdef PLAT_ARM_MEM_PROT_ADDR
        ARM_V2M_MAP_MEM_PROTECT,
 #endif
index d50c20a1dc60c2bc43594346b7d1a4eacd5292f1..4b2a340b0c45a4e4e5f26d6be7200c3df5082e61 100644 (file)
@@ -30,16 +30,3 @@ void bl1_early_platform_setup(void)
         */
        fvp_interconnect_enable();
 }
-
-/*******************************************************************************
- * The following function checks if Firmware update is needed,
- * by checking if TOC in FIP image is valid or not.
- ******************************************************************************/
-unsigned int bl1_plat_get_next_image_id(void)
-{
-       if (!arm_io_is_toc_valid())
-               return NS_BL1U_IMAGE_ID;
-
-       return BL2_IMAGE_ID;
-}
-
diff --git a/plat/arm/board/fvp/fvp_err.c b/plat/arm/board/fvp/fvp_err.c
deleted file mode 100644 (file)
index d9ad517..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <arch_helpers.h>
-#include <board_arm_def.h>
-#include <debug.h>
-#include <errno.h>
-#include <norflash.h>
-#include <platform.h>
-#include <stdint.h>
-
-/*
- * FVP error handler
- */
-void plat_error_handler(int err)
-{
-       int ret;
-
-       switch (err) {
-       case -ENOENT:
-       case -EAUTH:
-               /* Image load or authentication error. Erase the ToC */
-               INFO("Erasing FIP ToC from flash...\n");
-               nor_unlock(PLAT_ARM_FIP_BASE);
-               ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
-               if (ret) {
-                       ERROR("Cannot erase ToC\n");
-               } else {
-                       INFO("Done\n");
-               }
-               break;
-       default:
-               /* Unexpected error */
-               break;
-       }
-
-       /* Loop until the watchdog resets the system */
-       for (;;)
-               wfi();
-}
index 3dca4c2ac87e21435c79260b23718aeac0d23b1d..bb7753822ce81f4adc4ee619ca2b7d2d7d923673 100644 (file)
@@ -124,7 +124,6 @@ BL1_SOURCES         +=      drivers/io/io_semihosting.c                     \
                                lib/semihosting/${ARCH}/semihosting_call.S      \
                                plat/arm/board/fvp/${ARCH}/fvp_helpers.S        \
                                plat/arm/board/fvp/fvp_bl1_setup.c              \
-                               plat/arm/board/fvp/fvp_err.c                    \
                                plat/arm/board/fvp/fvp_io_storage.c             \
                                plat/arm/board/fvp/fvp_trusted_boot.c           \
                                ${FVP_CPU_LIBS}                                 \
@@ -135,7 +134,6 @@ BL2_SOURCES         +=      drivers/io/io_semihosting.c                     \
                                lib/semihosting/semihosting.c                   \
                                lib/semihosting/${ARCH}/semihosting_call.S      \
                                plat/arm/board/fvp/fvp_bl2_setup.c              \
-                               plat/arm/board/fvp/fvp_err.c                    \
                                plat/arm/board/fvp/fvp_io_storage.c             \
                                plat/arm/board/fvp/fvp_trusted_boot.c           \
                                ${FVP_SECURITY_SOURCES}
index 7c026bcb796a7192335aff96f5971b2d1c6060f5..836a67255d428025a077f6ef63a77c48038d3f61 100644 (file)
 #include <tbbr_img_def.h>
 #include <v2m_def.h>
 
-#define RESET_REASON_WDOG_RESET                (0x2)
-
 void juno_reset_to_aarch32_state(void);
 
-
-/*******************************************************************************
- * The following function checks if Firmware update is needed,
- * by checking if TOC in FIP image is valid or watchdog reset happened.
- ******************************************************************************/
-unsigned int bl1_plat_get_next_image_id(void)
-{
-       unsigned int *reset_flags_ptr = (unsigned int *)SSC_GPRETN;
-       unsigned int *nv_flags_ptr = (unsigned int *)
-                       (V2M_SYSREGS_BASE + V2M_SYS_NVFLAGS);
-       /*
-        * Check if TOC is invalid or watchdog reset happened.
-        */
-       if ((arm_io_is_toc_valid() != 1) ||
-               ((*reset_flags_ptr & RESET_REASON_WDOG_RESET) &&
-               ((*nv_flags_ptr == -EAUTH) || (*nv_flags_ptr == -ENOENT))))
-               return NS_BL1U_IMAGE_ID;
-
-       return BL2_IMAGE_ID;
-}
-
 /*******************************************************************************
  * On JUNO update the arg2 with address of SCP_BL2U image info.
  ******************************************************************************/
diff --git a/plat/arm/board/juno/juno_err.c b/plat/arm/board/juno/juno_err.c
deleted file mode 100644 (file)
index 0fe7016..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <arch_helpers.h>
-#include <errno.h>
-#include <platform.h>
-#include <v2m_def.h>
-
-#define V2M_SYS_NVFLAGS_ADDR           (V2M_SYSREGS_BASE + V2M_SYS_NVFLAGS)
-
-/*
- * Juno error handler
- */
-void plat_error_handler(int err)
-{
-       uint32_t *flags_ptr = (uint32_t *)V2M_SYS_NVFLAGS_ADDR;
-
-       /* Propagate the err code in the NV-flags register */
-       *flags_ptr = err;
-
-       /* Loop until the watchdog resets the system */
-       for (;;)
-               wfi();
-}
index 70d690922b12215c56c06a686997091c5b54d7f4..656fc14c748af1aa47b0ecd5d5bbfab04319301e 100644 (file)
@@ -49,12 +49,10 @@ BL1_SOURCES         +=      lib/cpus/aarch64/cortex_a53.S           \
                                lib/cpus/aarch64/cortex_a57.S           \
                                lib/cpus/aarch64/cortex_a72.S           \
                                plat/arm/board/juno/juno_bl1_setup.c    \
-                               plat/arm/board/juno/juno_err.c          \
                                ${JUNO_INTERCONNECT_SOURCES}            \
                                ${JUNO_SECURITY_SOURCES}
 
-BL2_SOURCES            +=      plat/arm/board/juno/juno_err.c          \
-                               plat/arm/board/juno/juno_bl2_setup.c    \
+BL2_SOURCES            +=      plat/arm/board/juno/juno_bl2_setup.c    \
                                ${JUNO_SECURITY_SOURCES}
 
 BL2U_SOURCES           +=      ${JUNO_SECURITY_SOURCES}
index 3a30eca6703aa544c7b78e36b352f3bbfb698895..379e87df2928cf73fe3d10690b3ff90bcaa2c0bc 100644 (file)
@@ -145,3 +145,15 @@ void bl1_plat_prepare_exit(entry_point_info_t *ep_info)
        sev();
 #endif
 }
+
+/*******************************************************************************
+ * The following function checks if Firmware update is needed,
+ * by checking if TOC in FIP image is valid or not.
+ ******************************************************************************/
+unsigned int bl1_plat_get_next_image_id(void)
+{
+       if (!arm_io_is_toc_valid())
+               return NS_BL1U_IMAGE_ID;
+
+       return BL2_IMAGE_ID;
+}
index b3462ab8a3e983d02989367f5ae88e207df987a5..015e454a125c3ef8f40258666df0e9f847109654 100644 (file)
@@ -137,6 +137,7 @@ BL1_SOURCES         +=      drivers/arm/sp805/sp805.c                       \
                                drivers/io/io_storage.c                         \
                                plat/arm/common/arm_bl1_setup.c                 \
                                plat/arm/common/arm_dyn_cfg.c                   \
+                               plat/arm/common/arm_err.c                       \
                                plat/arm/common/arm_io_storage.c
 ifdef EL3_PAYLOAD_BASE
 # Need the arm_program_trusted_mailbox() function to release secondary CPUs from
@@ -150,6 +151,7 @@ BL2_SOURCES         +=      drivers/delay_timer/delay_timer.c               \
                                drivers/io/io_memmap.c                          \
                                drivers/io/io_storage.c                         \
                                plat/arm/common/arm_bl2_setup.c                 \
+                               plat/arm/common/arm_err.c                       \
                                plat/arm/common/arm_io_storage.c
 
 # Add `libfdt` and Arm common helpers required for Dynamic Config
diff --git a/plat/arm/common/arm_err.c b/plat/arm/common/arm_err.c
new file mode 100644 (file)
index 0000000..59c5861
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch_helpers.h>
+#include <board_arm_def.h>
+#include <console.h>
+#include <debug.h>
+#include <errno.h>
+#include <norflash.h>
+#include <platform.h>
+#include <stdint.h>
+
+/*
+ * ARM common implementation for error handler
+ */
+void plat_error_handler(int err)
+{
+       int ret;
+
+       switch (err) {
+       case -ENOENT:
+       case -EAUTH:
+               /* Image load or authentication error. Erase the ToC */
+               INFO("Erasing FIP ToC from flash...\n");
+               nor_unlock(PLAT_ARM_FIP_BASE);
+               ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
+               if (ret != 0) {
+                       ERROR("Cannot erase ToC\n");
+               } else {
+                       INFO("Done\n");
+               }
+               break;
+       default:
+               /* Unexpected error */
+               break;
+       }
+
+       (void)console_flush();
+
+       /* Loop until the watchdog resets the system */
+       for (;;)
+               wfi();
+}