Enable TRUSTED_BOARD_BOOT support for LOAD_IMAGE_V2=1
authorYatharth Kochar <yatharth.kochar@arm.com>
Fri, 11 Nov 2016 13:57:50 +0000 (13:57 +0000)
committerYatharth Kochar <yatharth.kochar@arm.com>
Wed, 14 Dec 2016 14:37:53 +0000 (14:37 +0000)
This patch enables TRUSTED_BOARD_BOOT (Authentication and FWU)
support, for AArch64, when LOAD_IMAGE_V2 is enabled.

This patch also enables LOAD_IMAGE_V2 for ARM platforms.

Change-Id: I294a2eebce7a30b6784c80c9d4ac7752808ee3ad
Signed-off-by: Yatharth Kochar <yatharth.kochar@arm.com>
Makefile
bl1/bl1_fwu.c
bl1/tbbr/tbbr_img_desc.c
include/plat/arm/css/common/css_def.h
plat/arm/board/juno/include/platform_def.h
plat/arm/common/arm_common.mk

index 4fbb91403e6fd380c90649c36a2e938d0abf474e..e8716e5668d37e0c2d5e997636ed312386812825 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -122,10 +122,6 @@ ifneq (${GENERATE_COT},0)
         FWU_FIP_DEPS += fwu_certificates
 endif
 
-# For AArch32, enable new version of image loading.
-ifeq (${ARCH},aarch32)
-        LOAD_IMAGE_V2  :=      1
-endif
 
 ################################################################################
 # Toolchain
@@ -294,19 +290,15 @@ ifeq (${NEED_BL33},yes)
         endif
 endif
 
-# TRUSTED_BOARD_BOOT is currently not supported when LOAD_IMAGE_V2 is enabled.
-ifeq (${LOAD_IMAGE_V2},1)
-        ifeq (${TRUSTED_BOARD_BOOT},1)
-                $(error "TRUSTED_BOARD_BOOT is currently not supported \
-                for LOAD_IMAGE_V2=1")
-        endif
-endif
-
-# For AArch32, LOAD_IMAGE_V2 must be enabled.
 ifeq (${ARCH},aarch32)
+    # For AArch32, LOAD_IMAGE_V2 must be enabled.
     ifeq (${LOAD_IMAGE_V2}, 0)
         $(error "For AArch32, LOAD_IMAGE_V2 must be enabled.")
     endif
+    # TRUSTED_BOARD_BOOT is currently not supported for AArch32.
+    ifeq (${TRUSTED_BOARD_BOOT},1)
+        $(error "TRUSTED_BOARD_BOOT is currently not supported for AArch32")
+    endif
 endif
 
 
index f3338051d9171feea9489e46ea3cbfc81b5c77ba..61f2adb0a8905db1167dbada30e6f6bdd5bbc67f 100644 (file)
@@ -121,7 +121,6 @@ static int bl1_fwu_image_copy(unsigned int image_id,
                        unsigned int flags)
 {
        uintptr_t base_addr;
-       meminfo_t *mem_layout;
 
        /* Get the image descriptor. */
        image_desc_t *image_desc = bl1_plat_get_image_desc(image_id);
@@ -208,15 +207,22 @@ static int bl1_fwu_image_copy(unsigned int image_id,
                        WARN("BL1-FWU: Copy arguments source/size not mapped\n");
                        return -ENOMEM;
                }
-
+#if LOAD_IMAGE_V2
+               /* Check that the image size to load is within limit */
+               if (image_size > image_desc->image_info.image_max_size) {
+                       WARN("BL1-FWU: Image size out of bounds\n");
+                       return -ENOMEM;
+               }
+#else
                /* Find out how much free trusted ram remains after BL1 load */
-               mem_layout = bl1_plat_sec_mem_layout();
+               meminfo_t *mem_layout = bl1_plat_sec_mem_layout();
                if ((image_desc->image_info.image_base < mem_layout->free_base) ||
                         (image_desc->image_info.image_base + image_size >
                          mem_layout->free_base + mem_layout->free_size)) {
                        WARN("BL1-FWU: Memory not available to copy\n");
                        return -ENOMEM;
                }
+#endif
 
                /* Update the image size. */
                image_desc->image_info.image_size = image_size;
index 7651f1c041eb5e5e30a7d6c7d353c8cf71f2de72..e3bd574da56ae69864f1840e41c43ccd9e68b910 100644 (file)
@@ -38,6 +38,9 @@ image_desc_t bl1_tbbr_image_descs[] = {
            SET_STATIC_PARAM_HEAD(image_info, PARAM_IMAGE_BINARY,
                    VERSION_1, image_info_t, 0),
            .image_info.image_base = BL2_BASE,
+#if LOAD_IMAGE_V2
+           .image_info.image_max_size = BL2_LIMIT - BL2_BASE,
+#endif
            SET_STATIC_PARAM_HEAD(ep_info, PARAM_IMAGE_BINARY,
                    VERSION_1, entry_point_info_t, SECURE),
     },
@@ -55,6 +58,9 @@ image_desc_t bl1_tbbr_image_descs[] = {
            SET_STATIC_PARAM_HEAD(image_info, PARAM_IMAGE_BINARY,
                    VERSION_1, image_info_t, 0),
            .image_info.image_base = SCP_BL2U_BASE,
+#if LOAD_IMAGE_V2
+           .image_info.image_max_size = SCP_BL2U_LIMIT - SCP_BL2U_BASE,
+#endif
            SET_STATIC_PARAM_HEAD(ep_info, PARAM_IMAGE_BINARY,
                    VERSION_1, entry_point_info_t, SECURE),
     },
@@ -65,6 +71,9 @@ image_desc_t bl1_tbbr_image_descs[] = {
            SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
                    VERSION_1, image_info_t, 0),
            .image_info.image_base = BL2U_BASE,
+#if LOAD_IMAGE_V2
+           .image_info.image_max_size = BL2U_LIMIT - BL2U_BASE,
+#endif
            SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
                    VERSION_1, entry_point_info_t, SECURE | EXECUTABLE),
            .ep_info.pc = BL2U_BASE,
index 173de1b4d32f9cfbb8d7e96a6887e1b13ee5c6ce..a2fe0d58b2771b37168c1d0571c0a60d93d74148 100644 (file)
  * SCP, it is discarded and BL31 is loaded over the top.
  */
 #define SCP_BL2_BASE                   BL31_BASE
+#define SCP_BL2_LIMIT                  (SCP_BL2_BASE + PLAT_CSS_MAX_SCP_BL2_SIZE)
 
 #define SCP_BL2U_BASE                  BL31_BASE
+#define SCP_BL2U_LIMIT                 (SCP_BL2U_BASE + PLAT_CSS_MAX_SCP_BL2U_SIZE)
 #endif /* CSS_LOAD_SCP_IMAGES */
 
 /* Load address of Non-Secure Image for CSS platform ports */
index 691e2f7775c5f25bd391b048bd7ac85d6ad89bbc..adc4704d6d3bbb0158669b7c81d9feffab4f268e 100644 (file)
  */
 #define PLAT_CSS_MAX_SCP_BL2_SIZE      0x1D000
 
+/*
+ * PLAT_CSS_MAX_SCP_BL2U_SIZE is calculated using the current
+ * SCP_BL2U size plus a little space for growth.
+ */
+#define PLAT_CSS_MAX_SCP_BL2U_SIZE     0x1D000
+
 /*
  * Define a list of Group 1 Secure and Group 0 interrupts as per GICv3
  * terminology. On a GICv2 system or mode, the lists will be merged and treated
index 626b443eeef51765d0d55cd67f319b3bf9ef1495..d0940b8e967f76a24a6d75efc51e4cb1e52d7998 100644 (file)
@@ -97,6 +97,8 @@ ENABLE_PSCI_STAT              :=      1
 # mapping the former as executable and the latter as execute-never.
 SEPARATE_CODE_AND_RODATA       :=      1
 
+# Enable new version of image loading on ARM platforms
+LOAD_IMAGE_V2                  :=      1
 
 PLAT_INCLUDES          +=      -Iinclude/common/tbbr                           \
                                -Iinclude/plat/arm/common