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