corstone1000: fwu metadata and GPT
Subsystems (2)
v3 cover corstone1000: fwu metadata and GPT
Now that the nvmxip block driver is merged we can add on top of it the platform code to use GPT and FWU metadata in the Corstone1000.
But first, push 2 fixes that are needed to make all this work:
- move nvmxip header to include
- setup fwu metadata structures as packed (we have a 32bit writer - Secure enclave Cortex-M0 and a 64bit reader host Cortex-A35)
Cheers,
Rui
v2 [1]-> v3:
Tom Rini:
- fix definition of __packed compilation issue after merge of mkfwumdata tool.
v1 [0]-> v2:
Ilias:
- add Reviewed-by tag in patch 1/6
Heinrich:
- fix test include nvmxip header after the move to include/ in patch 2/6
[0]: https://lore.kernel.org/u-boot/[email protected]/
[1]: https://lore.kernel.org/u-boot/[email protected]/
Rui Miguel Silva (6):
fwu_metadata: make sure structures are packed
nvmxip: move header to include
corstone1000: add fwu-metadata store info
corstone1000: add boot index
corstone1000: set kernel_addr based on boot_idx
corstone1000: add nvmxip, fwu-mdata and gpt options
arch/arm/dts/corstone1000.dtsi | 7 ++-
board/armltd/corstone1000/corstone1000.c | 73 +++++++++++++++++++++-
board/armltd/corstone1000/corstone1000.env | 10 +--
configs/corstone1000_defconfig | 14 ++++-
include/fwu_mdata.h | 7 ++-
{drivers/mtd/nvmxip => include}/nvmxip.h | 0
test/dm/nvmxip.c | 2 +-
7 files changed, 97 insertions(+), 16 deletions(-)
rename {drivers/mtd/nvmxip => include}/nvmxip.h (100%)Signature · 1 line
2.41.0
PATCH v3 1/6 fwu_metadata: make sure structures are packed
The fwu metadata in the metadata partitions should/are packed to guarantee that the info is correct in all platforms. Also the size of them are used to calculate the crc32 and that is important to get it right.
--- include/fwu_mdata.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
include/fwu_mdata.h +4 -3
@@ -6,6 +6,7 @@#if !defined _FWU_MDATA_H_#define _FWU_MDATA_H_ +#include <linux/compiler_attributes.h> #include <efi.h> /**
@@ -22,7 +23,7 @@ struct fwu_image_bank_info {efi_guid_t image_uuid;uint32_t accepted;uint32_t reserved; -}; +} __packed;/** * struct fwu_image_entry - information for a particular type of image
@@ -38,7 +39,7 @@ struct fwu_image_entry {efi_guid_t image_type_uuid;efi_guid_t location_uuid;struct fwu_image_bank_info img_bank_info[CONFIG_FWU_NUM_BANKS ]; -}; +} __packed;/** * struct fwu_mdata - FWU metadata structure for multi-bank updates
@@ -62,6 +63,6 @@ struct fwu_mdata {uint32_t previous_active_index; struct fwu_image_entry img_entry[CONFIG_FWU_NUM_IMAGES_PER_BANK]; -}; +} __packed;#endif /* _FWU_MDATA_H_ */
Signature · 1 line
2.41.0
PATCH v3 2/6 nvmxip: move header to include
In reply to Rui Miguel SilvaMove header to include to allow external code
to get the internal bdev structures to access
block device operations.
as at it, just add the UCLASS_NVMXIP string
so we get the correct output in partitions
listing.
---
{drivers/mtd/nvmxip => include}/nvmxip.h | 0
test/dm/nvmxip.c | 2 +-
2 files changed, 1 insertion(+), 1 deletion(-)
rename {drivers/mtd/nvmxip => include}/nvmxip.h (100%)include/nvmxip.h renamed from drivers/mtd/nvmxip/nvmxip.h +0 -0
test/dm/nvmxip.c +1 -1
@@ -17,7 +17,7 @@#include <linux/bitops.h> #include <test/test.h> #include <test/ut.h> -#include "../../drivers/mtd/nvmxip/nvmxip.h" +#include <nvmxip.h> /* NVMXIP devices described in the device tree */ #define SANDBOX_NVMXIP_DEVICES 2
Signature · 1 line
2.41.0
PATCH v3 3/6 corstone1000: add fwu-metadata store info
In reply to Rui Miguel SilvaAdd fwu-mdata node and handle for the reference
nvmxip-qspi.
--- arch/arm/dts/corstone1000.dtsi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm/dts/corstone1000.dtsi +6 -1
@@ -38,7 +38,7 @@ reg = <0x88200000 0x77e00000>; }; - nvmxip-qspi@08000000 { + nvmxip: nvmxip-qspi@08000000 { compatible = "nvmxip,qspi"; reg = <0x08000000 0x2000000>; lba_shift = <9>;
@@ -106,6 +106,11 @@ method = "smc"; }; + fwu-mdata { + compatible = "u-boot,fwu-mdata-gpt"; + fwu-mdata-store = <&nvmxip>; + }; + soc { compatible = "simple-bus"; #address-cells = <1>;
Signature · 1 line
2.41.0
PATCH v3 4/6 corstone1000: add boot index
In reply to Rui Miguel Silvait is expected that the firmware that runs before u-boot somehow provide the information of the bank for now we will fetch the info from the metadata since the Secure enclave is the one responsible for this information.
--- board/armltd/corstone1000/corstone1000.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
board/armltd/corstone1000/corstone1000.c +17 -1
@@ -8,6 +8,8 @@#include <common.h> #include <cpu_func.h> #include <dm.h> +#include <env.h> +#include <env.h> #include <netdev.h> #include <dm/platform_data/serial_pl01x.h> #include <asm/armv8/mmu.h>
@@ -87,6 +89,20 @@ int dram_init_banksize(void)return 0 ; } -void reset_cpu (void ) +void fwu_plat_get_bootidx (uint *boot_idx) { +int ret; + +/* +* in our platform, the Secure Enclave is the one who controls +* all the boot tries and status, so, every time we get here +* we know that the we are booting from the active index +*/ + ret =fwu_get_active_index (boot_idx); +if (ret <0 ) { + *boot_idx =CONFIG_FWU_NUM_BANKS ; +log_err ("corstone1000: failed to read active index\n" ); + } + +return ret; }
Signature · 1 line
2.41.0
PATCH v3 5/6 corstone1000: set kernel_addr based on boot_idx
In reply to Rui Miguel SilvaWe need to distinguish between boot banks and from which partition to load the kernel+initramfs to memory.
For that, fetch the boot index, fetch the correspondent partition, calculate the correct kernel address and then set the env variable kernel_addr with that value.
--- board/armltd/corstone1000/corstone1000.c | 56 +++++++++++++++++++++++- configs/corstone1000_defconfig | 1 + 2 files changed, 56 insertions(+), 1 deletion(-)
board/armltd/corstone1000/corstone1000.c +55 -1
@@ -5,16 +5,24 @@* Rui Miguel Silva <[email protected]> */ +#include <blk.h> #include <common.h> #include <cpu_func.h> #include <dm.h> #include <env.h> -#include <env.h> #include <netdev.h> +#include <nvmxip.h> +#include <part.h> #include <dm/platform_data/serial_pl01x.h> #include <asm/armv8/mmu.h> #include <asm/global_data.h> +#define CORSTONE1000_KERNEL_PARTS 2 +#define CORSTONE1000_KERNEL_PRIMARY "kernel_primary" +#define CORSTONE1000_KERNEL_SECONDARY "kernel_secondary" + +static int corstone1000_boot_idx; +static struct mm_region corstone1000_mem_map[] = { {/* CVM */
@@ -103,6 +111,52 @@ void fwu_plat_get_bootidx(uint *boot_idx) *boot_idx =CONFIG_FWU_NUM_BANKS ;log_err ("corstone1000: failed to read active index\n" ); } +} + +int board_late_init (void ) +{ +struct disk_partition part_info; +struct udevice *dev, *bdev; +struct nvmxip_plat *plat; +struct blk_desc *desc; +int ret; + + ret =uclass_first_device_err (UCLASS_NVMXIP , &dev); +if (ret <0 ) { +log_err ("Cannot find kernel device\n" ); +return ret; + } + + plat =dev_get_plat (dev); +device_find_first_child (dev, &bdev); + desc =dev_get_uclass_plat (bdev); + ret =fwu_get_active_index (&corstone1000_boot_idx); +if (ret <0 ) { +log_err ("corstone1000: failed to read boot index\n" ); +return ret; + } + +if (!corstone1000_boot_idx) + ret =part_get_info_by_name (desc,CORSTONE1000_KERNEL_PRIMARY , + &part_info); +else + ret =part_get_info_by_name (desc,CORSTONE1000_KERNEL_SECONDARY , + &part_info); + +if (ret <0 ) { +log_err ("failed to fetch kernel partition index: %d\n" , + corstone1000_boot_idx); +return ret; + } + + ret =0 ; + + ret |=env_set_hex ("kernel_addr" , plat->phys_base + + (part_info.start * part_info.blksz)); + ret |=env_set_hex ("kernel_size" , part_info.size * part_info.blksz); + +if (ret <0 ) +log_err ("failed to setup kernel addr and size\n" );return ret; }
configs/corstone1000_defconfig +1 -0
@@ -20,6 +20,7 @@ CONFIG_CONSOLE_RECORD=y CONFIG_LOGLEVEL=7 # CONFIG_DISPLAY_CPUINFO is not set # CONFIG_DISPLAY_BOARDINFO is not set +CONFIG_BOARD_LATE_INIT=y CONFIG_SYS_MAXARGS=64 CONFIG_SYS_CBSIZE=512 # CONFIG_CMD_CONSOLE is not set
Signature · 1 line
2.41.0
PATCH v3 6/6 corstone1000: add nvmxip, fwu-mdata and gpt options
In reply to Rui Miguel SilvaEnable the newest features: nvmxip, fwu-metadata and gpt. Commands to print the partition info, gpt info and fwu metadata will be available.
Adjust also env boot script the address of the bootbank with the new gpt layout, and also remove the not needed kernel address bank0 and bank1 and retrieve function that would test the bank flag before and now we are getting the info from the fwu metadata.
--- board/armltd/corstone1000/corstone1000.c | 1 + board/armltd/corstone1000/corstone1000.env | 10 +--------- configs/corstone1000_defconfig | 13 ++++++++++++- 3 files changed, 14 insertions(+), 10 deletions(-)
board/armltd/corstone1000/corstone1000.c +1 -0
@@ -10,6 +10,7 @@#include <cpu_func.h> #include <dm.h> #include <env.h> +#include <fwu.h> #include <netdev.h> #include <nvmxip.h> #include <part.h>
board/armltd/corstone1000/corstone1000.env +1 -9
@@ -1,13 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0+ */ usb_pgood_delay=250 -boot_bank_flag=0x08002000 -kernel_addr_bank_0=0x083EE000 -kernel_addr_bank_1=0x0936E000 -retrieve_kernel_load_addr= - if itest.l *${boot_bank_flag} == 0; then - setenv kernel_addr $kernel_addr_bank_0; - else - setenv kernel_addr $kernel_addr_bank_1; - fi; +boot_bank_flag=0x08005006 kernel_addr_r=0x88200000
configs/corstone1000_defconfig +12 -1
@@ -15,7 +15,7 @@ CONFIG_DISTRO_DEFAULTS=y CONFIG_BOOTDELAY=3 CONFIG_USE_BOOTARGS=y CONFIG_BOOTARGS="console=ttyAMA0 loglevel=9 ip=dhcp earlyprintk" -CONFIG_BOOTCOMMAND="run retrieve_kernel_load_addr; echo Loading kernel from $kernel_addr to memory ... ; loadm $kernel_addr $kernel_addr_r 0xc00000; usb start; usb reset; run distro_bootcmd; bootefi $kernel_addr_r $fdtcontroladdr;" +CONFIG_BOOTCOMMAND="echo Loading kernel from $kernel_addr to memory ... ; loadm $kernel_addr $kernel_addr_r 0xc00000; usb start; usb reset; run distro_bootcmd; bootefi $kernel_addr_r $fdtcontroladdr;" CONFIG_CONSOLE_RECORD=y CONFIG_LOGLEVEL=7 # CONFIG_DISPLAY_CPUINFO is not set
@@ -24,11 +24,16 @@ CONFIG_BOARD_LATE_INIT=y CONFIG_SYS_MAXARGS=64 CONFIG_SYS_CBSIZE=512 # CONFIG_CMD_CONSOLE is not set +CONFIG_CMD_FWU_METADATA=y CONFIG_CMD_BOOTZ=y CONFIG_SYS_BOOTM_LEN=0x800000 # CONFIG_CMD_XIMG is not set +CONFIG_CMD_NVMXIP=y +CONFIG_CMD_GPT=y +# CONFIG_RANDOM_UUID is not set CONFIG_CMD_LOADM=y # CONFIG_CMD_LOADS is not set +CONFIG_CMD_MMC=y CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set # CONFIG_CMD_NFS is not set
@@ -40,6 +45,8 @@ CONFIG_OF_CONTROL=y CONFIG_VERSION_VARIABLE=y CONFIG_NET_RANDOM_ETHADDR=y CONFIG_REGMAP=y +CONFIG_FWU_MDATA=y +CONFIG_FWU_MDATA_GPT_BLK=y CONFIG_MISC=y # CONFIG_MMC is not set CONFIG_NVMXIP_QSPI=y
@@ -51,6 +58,10 @@ CONFIG_RAM=y CONFIG_DM_RTC=y CONFIG_RTC_EMULATION=y CONFIG_DM_SERIAL=y +CONFIG_SYSRESET=y CONFIG_USB=y CONFIG_USB_ISP1760=y +CONFIG_EFI_CAPSULE_ON_DISK=y +CONFIG_EFI_IGNORE_OSINDICATIONS=y +CONFIG_FWU_MULTI_BANK_UPDATE=y CONFIG_ERRNO_STR=y
Signature · 1 line
2.41.0
Quoted 11 lines · Rui Miguel Silva
Now that the nvmxip block driver is merged we can add on top of it the platform code to use GPT and FWU metadata in the Corstone1000.
But first, push 2 fixes that are needed to make all this work:
- move nvmxip header to include
- setup fwu metadata structures as packed (we have a 32bit writer - Secure enclave Cortex-M0 and a 64bit reader host Cortex-A35)[...]
Applied to u-boot/next, thanks!
Signature · 1 line
Tom