arm: spl: prepare for jumping to OPTEE
authorRicardo Salveti <ricardo@foundries.io>
Wed, 20 Oct 2021 12:12:06 +0000 (15:12 +0300)
committerTom Rini <trini@konsulko.com>
Mon, 25 Oct 2021 21:17:24 +0000 (17:17 -0400)
Make sure to (if applicable) flush the D-cache, invalidate I-cache,
and disable MMU and caches before jumping to OPTEE.
This fixes the SDP->SPL->OPTEE boot flow on iMX6Q and most likely on
some other ARM SoCs.

Signed-off-by: Ricardo Salveti <ricardo@foundries.io>
Co-developed-by: Oleksandr Suvorov <oleksandr.suvorov@foundries.io>
Signed-off-by: Oleksandr Suvorov <oleksandr.suvorov@foundries.io>
arch/arm/lib/spl.c
common/spl/spl.c
include/spl.h

index 8e2bdf3..4f9b84b 100644 (file)
@@ -77,3 +77,14 @@ void __noreturn jump_to_image_linux(struct spl_image_info *spl_image)
 }
 #endif /* CONFIG_ARM64 */
 #endif
+
+#if CONFIG_IS_ENABLED(OPTEE_IMAGE)
+void __noreturn jump_to_image_optee(struct spl_image_info *spl_image)
+{
+       /* flush and turn off caches before jumping to OPTEE */
+       cleanup_before_linux();
+
+       spl_optee_entry(NULL, NULL, spl_image->fdt_addr,
+                       (void *)spl_image->entry_point);
+}
+#endif
index a9304d4..0c08da0 100644 (file)
@@ -174,6 +174,14 @@ __weak void spl_board_prepare_for_optee(void *fdt)
 {
 }
 
+#if CONFIG_IS_ENABLED(OPTEE_IMAGE)
+__weak void __noreturn jump_to_image_optee(struct spl_image_info *spl_image)
+{
+       spl_optee_entry(NULL, NULL, spl_image->fdt_addr,
+                       (void *)spl_image->entry_point);
+}
+#endif
+
 __weak void spl_board_prepare_for_boot(void)
 {
        /* Nothing to do! */
@@ -780,8 +788,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
        case IH_OS_TEE:
                debug("Jumping to U-Boot via OP-TEE\n");
                spl_board_prepare_for_optee(spl_image.fdt_addr);
-               spl_optee_entry(NULL, NULL, spl_image.fdt_addr,
-                               (void *)spl_image.entry_point);
+               jump_to_image_optee(&spl_image);
                break;
 #endif
 #if CONFIG_IS_ENABLED(OPENSBI)
index 7ddb2ab..0af0ee3 100644 (file)
@@ -469,6 +469,15 @@ int spl_board_boot_device(u32 boot_device);
 void __noreturn jump_to_image_linux(struct spl_image_info *spl_image);
 
 /**
+ * jump_to_image_linux() - Jump to OP-TEE OS from SPL
+ *
+ * This jumps into OP-TEE OS using the information in @spl_image.
+ *
+ * @spl_image: Image description to set up
+ */
+void __noreturn jump_to_image_optee(struct spl_image_info *spl_image);
+
+/**
  * spl_start_uboot() - Check if SPL should start the kernel or U-Boot
  *
  * This is called by the various SPL loaders to determine whether the board
@@ -759,7 +768,7 @@ struct bl_params *bl2_plat_get_bl31_params_v2_default(uintptr_t bl32_entry,
  * @arg2: device tree address, (ARMv7 standard bootarg #2)
  * @arg3: non-secure entry address (ARMv7 bootarg #0)
  */
-void spl_optee_entry(void *arg0, void *arg1, void *arg2, void *arg3);
+void __noreturn spl_optee_entry(void *arg0, void *arg1, void *arg2, void *arg3);
 
 /**
  * spl_invoke_opensbi - boot using a RISC-V OpenSBI image