blob: e26fd34e868b137219ac1fdf4821ebb869a365de [file] [log] [blame]
Andrew Geissler2edf0642023-09-11 08:24:07 -04001From fa7ab9b40babee29d2aadb267dfce7a96f8989d4 Mon Sep 17 00:00:00 2001
Andrew Geissler2daf84b2023-03-31 09:57:23 -05002From: Mohamed Omar Asaker <mohamed.omarasaker@arm.com>
3Date: Mon, 9 Jan 2023 13:59:06 +0000
4Subject: [PATCH] feat(corstone1000): bl2 loads fip based on metadata
5
6Previously bl2 was reading the boot_index directly with a hard coded
7address and then set the fip image spec with fip offsets base based on
8the boot_index value.
9This commit removes this logic and rely on PSA_FWU_SUPPORT
10which reads the fip partition based on the active firmware bank written in
11metadata.
12
13Note: fip partition contains signature area at the begining. Hence, the fip
14image starts at fip partition + fip signature area size.
15
16Upstream-Status: Pending
17Signed-off-by: Mohamed Omar Asaker <mohamed.omarasaker@arm.com>
Andrew Geissler2daf84b2023-03-31 09:57:23 -050018---
19 bl2/bl2_main.c | 4 +++
20 .../corstone1000/common/corstone1000_plat.c | 32 ++++++-------------
21 .../common/include/platform_def.h | 12 +++----
22 tools/cert_create/Makefile | 4 +--
23 tools/fiptool/Makefile | 4 +--
24 5 files changed, 24 insertions(+), 32 deletions(-)
25
26diff --git a/bl2/bl2_main.c b/bl2/bl2_main.c
Andrew Geissler2edf0642023-09-11 08:24:07 -040027index ce83692e0ebc..1a9febc007b2 100644
Andrew Geissler2daf84b2023-03-31 09:57:23 -050028--- a/bl2/bl2_main.c
29+++ b/bl2/bl2_main.c
Andrew Geissler2edf0642023-09-11 08:24:07 -040030@@ -87,6 +87,10 @@ void bl2_main(void)
Andrew Geissler2daf84b2023-03-31 09:57:23 -050031 /* Perform remaining generic architectural setup in S-EL1 */
32 bl2_arch_setup();
33
34+#if ARM_GPT_SUPPORT
35+ partition_init(GPT_IMAGE_ID);
36+#endif
37+
38 #if PSA_FWU_SUPPORT
39 fwu_init();
40 #endif /* PSA_FWU_SUPPORT */
41diff --git a/plat/arm/board/corstone1000/common/corstone1000_plat.c b/plat/arm/board/corstone1000/common/corstone1000_plat.c
Andrew Geissler2edf0642023-09-11 08:24:07 -040042index 0235f8b8474c..7f9708a82489 100644
Andrew Geissler2daf84b2023-03-31 09:57:23 -050043--- a/plat/arm/board/corstone1000/common/corstone1000_plat.c
44+++ b/plat/arm/board/corstone1000/common/corstone1000_plat.c
45@@ -33,36 +33,17 @@ const mmap_region_t plat_arm_mmap[] = {
46 static void set_fip_image_source(void)
47 {
48 const struct plat_io_policy *policy;
49- /*
50- * metadata for firmware update is written at 0x0000 offset of the flash.
51- * PLAT_ARM_BOOT_BANK_FLAG contains the boot bank that TF-M is booted.
52- * As per firmware update spec, at a given point of time, only one bank
53- * is active. This means, TF-A should boot from the same bank as TF-M.
54- */
55- volatile uint32_t *boot_bank_flag = (uint32_t *)(PLAT_ARM_BOOT_BANK_FLAG);
56-
57- if (*boot_bank_flag > 1) {
58- VERBOSE("Boot_bank is set higher than possible values");
59- }
60-
61- VERBOSE("Boot bank flag = %u.\n\r", *boot_bank_flag);
62
63 policy = FCONF_GET_PROPERTY(arm, io_policies, FIP_IMAGE_ID);
64
65 assert(policy != NULL);
66 assert(policy->image_spec != 0UL);
67
68+ /* FIP Partition contains Signature area at the begining which TF-A doesn't expect */
69 io_block_spec_t *spec = (io_block_spec_t *)policy->image_spec;
70+ spec->offset += FIP_SIGNATURE_AREA_SIZE;
71+ spec->length -= FIP_SIGNATURE_AREA_SIZE;
72
73- if ((*boot_bank_flag) == 0) {
74- VERBOSE("Booting from bank 0: fip offset = 0x%lx\n\r",
75- PLAT_ARM_FIP_BASE_BANK0);
76- spec->offset = PLAT_ARM_FIP_BASE_BANK0;
77- } else {
78- VERBOSE("Booting from bank 1: fip offset = 0x%lx\n\r",
79- PLAT_ARM_FIP_BASE_BANK1);
80- spec->offset = PLAT_ARM_FIP_BASE_BANK1;
81- }
82 }
83
84 void bl2_platform_setup(void)
85@@ -75,6 +56,13 @@ void bl2_platform_setup(void)
86 set_fip_image_source();
87 }
88
89+void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
90+ u_register_t arg2, u_register_t arg3)
91+{
92+ arm_bl2_early_platform_setup((uintptr_t)arg0, (meminfo_t *)arg1);
93+ NOTICE("CS1k: early at bl2_platform_setup\n");
94+}
95+
96 /* corstone1000 only has one always-on power domain and there
97 * is no power control present
98 */
99diff --git a/plat/arm/board/corstone1000/common/include/platform_def.h b/plat/arm/board/corstone1000/common/include/platform_def.h
Andrew Geissler2edf0642023-09-11 08:24:07 -0400100index 584d485f3ea7..0bfab05a482b 100644
Andrew Geissler2daf84b2023-03-31 09:57:23 -0500101--- a/plat/arm/board/corstone1000/common/include/platform_def.h
102+++ b/plat/arm/board/corstone1000/common/include/platform_def.h
103@@ -173,16 +173,16 @@
104
105 /* NOR Flash */
106
107-#define PLAT_ARM_BOOT_BANK_FLAG UL(0x08002000)
108-#define PLAT_ARM_FIP_BASE_BANK0 UL(0x081EF000)
109-#define PLAT_ARM_FIP_BASE_BANK1 UL(0x0916F000)
110-#define PLAT_ARM_FIP_MAX_SIZE UL(0x1ff000) /* 1.996 MB */
111-
112 #define PLAT_ARM_NVM_BASE V2M_FLASH0_BASE
113 #define PLAT_ARM_NVM_SIZE (SZ_32M) /* 32 MB */
114+#define PLAT_ARM_FIP_MAX_SIZE UL(0x1ff000) /* 1.996 MB */
115
116-#define PLAT_ARM_FLASH_IMAGE_BASE PLAT_ARM_FIP_BASE_BANK0
117+#define PLAT_ARM_FLASH_IMAGE_BASE UL(0x08000000)
118 #define PLAT_ARM_FLASH_IMAGE_MAX_SIZE PLAT_ARM_FIP_MAX_SIZE
119+#define PLAT_ARM_FIP_OFFSET_IN_GPT (0x86000)
120+
121+/* FIP Information */
122+#define FIP_SIGNATURE_AREA_SIZE (0x1000) /* 4 KB */
123
124 /*
125 * Some data must be aligned on the biggest cache line size in the platform.
126diff --git a/tools/cert_create/Makefile b/tools/cert_create/Makefile
Andrew Geissler2edf0642023-09-11 08:24:07 -0400127index 042e844626bd..45b76a022f91 100644
Andrew Geissler2daf84b2023-03-31 09:57:23 -0500128--- a/tools/cert_create/Makefile
129+++ b/tools/cert_create/Makefile
Andrew Geissler2edf0642023-09-11 08:24:07 -0400130@@ -78,8 +78,8 @@ INC_DIR += -I ./include -I ${PLAT_INCLUDE} -I ${OPENSSL_DIR}/include
Andrew Geissler2daf84b2023-03-31 09:57:23 -0500131 # directory. However, for a local build of OpenSSL, the built binaries are
132 # located under the main project directory (i.e.: ${OPENSSL_DIR}, not
133 # ${OPENSSL_DIR}/lib/).
134-LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
135-LIB := -lssl -lcrypto
136+LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS}
137+LIB := -lssl -lcrypto ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS}
138
139 HOSTCC ?= gcc
140
141diff --git a/tools/fiptool/Makefile b/tools/fiptool/Makefile
Andrew Geissler2edf0642023-09-11 08:24:07 -0400142index 2ebee33931ba..dcfd314bee89 100644
Andrew Geissler2daf84b2023-03-31 09:57:23 -0500143--- a/tools/fiptool/Makefile
144+++ b/tools/fiptool/Makefile
Andrew Geissler2edf0642023-09-11 08:24:07 -0400145@@ -39,7 +39,7 @@ HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
Andrew Geissler2daf84b2023-03-31 09:57:23 -0500146 # directory. However, for a local build of OpenSSL, the built binaries are
147 # located under the main project directory (i.e.: ${OPENSSL_DIR}, not
148 # ${OPENSSL_DIR}/lib/).
149-LDLIBS := -L${OPENSSL_DIR}/lib -L${OPENSSL_DIR} -lcrypto
150+LDLIBS := -L${OPENSSL_DIR}/lib -L${OPENSSL_DIR} -lcrypto ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS} ${BUILD_LDFLAGS}
151
152 ifeq (${V},0)
153 Q := @
Andrew Geissler2edf0642023-09-11 08:24:07 -0400154@@ -47,7 +47,7 @@ else
Andrew Geissler2daf84b2023-03-31 09:57:23 -0500155 Q :=
156 endif
157
158-INCLUDE_PATHS := -I../../include/tools_share -I${OPENSSL_DIR}/include
159+INCLUDE_PATHS := -I../../include/tools_share -I${OPENSSL_DIR}/include ${BUILD_CFLAGS} ${BUILD_CFLAGS} ${BUILD_CFLAGS} ${BUILD_CFLAGS} ${BUILD_CFLAGS} ${BUILD_CFLAGS}
160
161 HOSTCC ?= gcc
162