xilinx: Add support for DTB reselection
Subsystems (4)
cover xilinx: Add support for DTB reselection
Hi,
this series add support for board or board+cc runtime DT selection. EEPROM memory is read and based on that decoded if this is legacy/fru based format and proper DTB is used. There is a need to have all DTBs 64bit aligned. If you don't have it you will end up in exception. But one patch in this series is trying to detect it and panic before you reach it to let you know what's wrong.
Enforcing mkimage/dtb alignment is done based on CONFIG_PHYS_64BIT and affects all 64bit systems but it is also not wrong for them to be properly aligned.
Thanks,
Michal
Changes in v2:
- Update subject and commit message
- Enable 64bit alignment for all - reported by Andre
- Update subject and commit message
- Enable it for all (not just 64bit systems)
- Update if condition for MULTI_DTB
- call fru_capture in non DEBUG mode
- Show detected name as standard message to see what has been chosen
Michal Simek (10):
xilinx: fru: Replace spaces with \0 in detected name
xilinx: Use variable for passing board_name
xilinx: common: Change board_info[] handling
xilinx: common: Free allocated structure
xilinx: Add support for generic board detection
xilinx: zynqmp: Check that DT is 64bit aligned
Makefile: Align fit-dtb.blob and u-boot.itb by 64bits
arm64: dts: Make sure that all DTBs are 64bit aligned
xilinx: zynqmp: Generate different u-boot.itb for MULTI_DTB_FIT
xilinx: common: Enabling generic function for DT reselection
Makefile | 3 + arch/arm/dts/Makefile | 2 +- arch/arm/dts/zynqmp-sm-k26-revA.dts | 3 + arch/arm/mach-zynqmp/mkimage_fit_atf.sh | 47 +++++++ board/xilinx/common/board.c | 158 +++++++++++++++++++----- board/xilinx/zynqmp/zynqmp.c | 3 + 6 files changed, 186 insertions(+), 30 deletions(-)
Signature · 1 line
2.33.0
PATCH 1/10 xilinx: fru: Replace spaces with \0 in detected name
FRU spec expected \0 for unused symbols but unfortunately a lot of boards are using spaces instead of \0. That's why after saving it to desc->name name is checked again and all spaces are converted to \0. This will ensure that names can be used for string manipulations like concatenation.
---
Changes in v2: None
board/xilinx/common/board.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
board/xilinx/common/board.c +5 -1
@@ -168,7 +168,7 @@ static bool xilinx_detect_legacy(u8 *buffer)static int xilinx_read_eeprom_fru (struct udevice *dev,char *name,struct xilinx_board_description *desc) { -int ret, eeprom_size; +int i, ret, eeprom_size;u8 *fru_content;/* FIXME this is shortcut - if eeprom type is wrong it will fail */
@@ -207,6 +207,10 @@ static int xilinx_read_eeprom_fru(struct udevice *dev, char *name, sizeof(desc->manufacturer));strncpy (desc->name, (char *)fru_data.brd.product_name,sizeof (desc->name)); +for (i =0 ; i <sizeof (desc->name); i++) { +if (desc->name[i] ==' ' ) + desc->name[i] ='\0' ; + }strncpy (desc->revision, (char *)fru_data.brd.rev,sizeof (desc->revision)); strncpy(desc->serial, (char *)fru_data.brd.serial_number,
Signature · 1 line
2.33.0
PATCH 2/10 xilinx: Use variable for passing board_name
In reply to Michal SimekUse variable which points to DEVICE_TREE by default. The reason for this change is to enable DTB_RESELECT and MULTI_DTB_FIT where board detection can be used for change DTB at run time. That's why there must be reference in board_fit_config_name_match() via variable instead of hardcoding it which is sufficient for that use case.
---
Changes in v2: None
board/xilinx/common/board.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
board/xilinx/common/board.c +4 -2
@@ -436,11 +436,13 @@ int board_late_init_xilinx(void) }#endif +static char *board_name =DEVICE_TREE ; +int __maybe_unused board_fit_config_name_match (const char *name) { -debug ("%s: Check %s, default %s\n" , __func__, name,DEVICE_TREE ); +debug ("%s: Check %s, default %s\n" , __func__, name, board_name); -if (!strcmp (name,DEVICE_TREE )) +if (!strcmp (name, board_name))return 0 ;return -1 ;
Signature · 1 line
2.33.0
PATCH 3/10 xilinx: common: Change board_info[] handling
In reply to Michal SimekOrigin code was allocating only pointers to struct xilinx_board_description and there was separate allocation for structure self and freeing in case of failure.
The code is directly allocating space for all structures by one calloc to simlify logic.
---
Changes in v2: None
board/xilinx/common/board.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
board/xilinx/common/board.c +6 -17
@@ -68,7 +68,7 @@ struct xilinx_board_description { };static int highest_id =-1 ; -static struct xilinx_board_description **board_info; +static struct xilinx_board_description *board_info;#define XILINX_I2C_DETECTION_BITS sizeof(struct fru_common_hdr)
@@ -280,7 +280,7 @@ static int xilinx_read_eeprom_single(char *name,__maybe_unused int xilinx_read_eeprom (void ) { -int id, ret; +int id;char name_buf[8 ];/* 8 bytes should be enough for nvmem+number */ struct xilinx_board_description *desc;
@@ -289,7 +289,7 @@ __maybe_unused int xilinx_read_eeprom(void)if (highest_id <0 )return -EINVAL ; - board_info =calloc (1 ,sizeof (desc) * highest_id); + board_info =calloc (1 ,sizeof (*desc) * (highest_id +1 ));if (!board_info)return -ENOMEM ;
@@ -300,21 +300,10 @@ __maybe_unused int xilinx_read_eeprom(void)snprintf (name_buf,sizeof (name_buf),"nvmem%d" , id);/* Alloc structure */ - desc = board_info[id]; -if (!desc) { - desc =calloc (1 ,sizeof (*desc)); -if (!desc) -return -ENOMEM ; - - board_info[id] = desc; - } + desc = &board_info[id];/* Ignoring return value for supporting multiple chips */ - ret =xilinx_read_eeprom_single (name_buf, desc); -if (ret) { -free (desc); - board_info[id] =NULL ; - } +xilinx_read_eeprom_single (name_buf, desc); }/*
@@ -400,7 +389,7 @@ int board_late_init_xilinx(void) ret |=env_set_addr ("bootm_size" , (void *)bootm_size);for (id =0 ; id <= highest_id; id++) { - desc = board_info[id]; + desc = &board_info[id];if (desc && desc->header ==EEPROM_HEADER_MAGIC ) {if (desc->manufacturer[0 ]) ret |= env_set_by_index("manufacturer", id,
Signature · 1 line
2.33.0
PATCH 4/10 xilinx: common: Free allocated structure
In reply to Michal SimekThere is no need to keep fru_content around. Free this space.
---
Changes in v2: None
board/xilinx/common/board.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
board/xilinx/common/board.c +7 -5
@@ -185,8 +185,7 @@ static int xilinx_read_eeprom_fru(struct udevice *dev, char *name, eeprom_size);if (ret) {debug ("%s: I2C EEPROM read failed\n" , __func__); -free (fru_content); -return ret; + goto end; }printf ("Xilinx I2C FRU format at %s:\n" , name);
@@ -194,12 +193,13 @@ static int xilinx_read_eeprom_fru(struct udevice *dev, char *name, ret =fru_display (0 );if (ret) {printf ("FRU format decoding failed.\n" ); -return ret; + goto end; }if (desc->header ==EEPROM_HEADER_MAGIC ) {debug ("Information already filled\n" ); -return -EINVAL ; + ret = -EINVAL ; + goto end; }/* It is clear that FRU was captured and structures were filled */
@@ -217,7 +217,9 @@ static int xilinx_read_eeprom_fru(struct udevice *dev, char *name, sizeof(desc->serial)); desc->header =EEPROM_HEADER_MAGIC ; -return 0 ; +end: +free (fru_content); +return ret; }static bool xilinx_detect_fru (u8 *buffer)
Signature · 1 line
2.33.0
PATCH 5/10 xilinx: Add support for generic board detection
In reply to Michal SimekAdd support for changing DT at run time. It is done via board_detection() which returns platform_id and platform_version which can be used via board_name_decode() to compose board_local_name string which corresponds with DT which is should be used.
---
Changes in v2: None
board/xilinx/common/board.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
board/xilinx/common/board.c +31 -0
@@ -463,3 +463,34 @@ int print_cpuinfo(void) return 0; }#endif + +#if CONFIG_IS_ENABLED (DTB_RESELECT ) +char *__maybe_unused __weak board_name_decode (void ) +{ +return NULL ; +} + +bool __maybe_unused __weak board_detection (void ) +{ +return false; +} + +int embedded_dtb_select (void ) +{ +if (board_detection ()) { +char *board_local_name; + + board_local_name =board_name_decode (); +if (board_local_name) { + board_name = board_local_name; +debug ("Detected name: %s\n" , board_name); + +/* Time to change DTB on fly */ +/* Both ways should work here */ +/* fdtdec_resetup(&rescan); */ +fdtdec_setup (); + } + } +return 0 ; +} +#endif
Signature · 1 line
2.33.0
PATCH 6/10 xilinx: zynqmp: Check that DT is 64bit aligned
In reply to Michal SimekDT needs to be 64bit aligned. If it is not fdt64_to_cpu will fail when try to read information about reserved memory. The system ends in exception without any clue what's going it. That's why detect not aligned DT and panic to show where the issue is coming from.
---
Changes in v2: None
board/xilinx/zynqmp/zynqmp.c | 3 +++ 1 file changed, 3 insertions(+)
board/xilinx/zynqmp/zynqmp.c +3 -0
@@ -470,6 +470,9 @@ ulong board_get_usable_ram_top(ulong total_size)phys_addr_t reg;struct lmb lmb; +if (!IS_ALIGNED ((ulong )gd->fdt_blob,0x8 )) +panic ("Not 64bit aligned DT location: %p\n" , gd->fdt_blob); +/* found enough not-reserved memory to relocated U-Boot */ lmb_init (&lmb);lmb_add (&lmb, gd->ram_base, gd->ram_size);
Signature · 1 line
2.33.0
PATCH 7/10 Makefile: Align fit-dtb.blob and u-boot.itb by 64bits
In reply to Michal SimekEnabling MULTI_DTB_FIT and DTB_RESELECT can end up with multi DTBs in FIT image placed and aligned only by 32bits (4bytes). Based on device tree specification:
"Specifically, the memory reservation block shall be aligned to an 8-byte boundary and the structure block to a 4-byte boundary."
is 64bit (8bytes) alignment required. That's why make sure that fit-dtb.blob and u-boot.itb as our primary target images for Xilinx ZynqMP are all 64bit aligned.
---
Changes in v2:
- Update subject and commit message
- Enable 64bit alignment for all - reported by Andre
Makefile | 3 +++ 1 file changed, 3 insertions(+)
Makefile +3 -0
@@ -1169,6 +1169,8 @@ MKIMAGEFLAGS_fit-dtb.blob = -f auto -A $(ARCH) -T firmware -C none -O u-boot \ -a 0 -e 0 -E \ $(patsubst %,-b arch/$(ARCH)/dts/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) -d /dev/null +MKIMAGEFLAGS_fit-dtb.blob += -B 0x8 + ifneq ($(EXT_DTB),) u-boot-fit-dtb.bin: u-boot-nodtb.bin $(EXT_DTB) $(call if_changed,cat)
@@ -1431,6 +1433,7 @@ MKIMAGEFLAGS_u-boot.itb = else MKIMAGEFLAGS_u-boot.itb = -E endif +MKIMAGEFLAGS_u-boot.itb += -B 0x8 ifdef U_BOOT_ITS u-boot.itb: u-boot-nodtb.bin \
Signature · 1 line
2.33.0
Re: [PATCH 07/10] Makefile: Align fit-dtb.blob and u-boot.itb by 64bits
Quoted 8 lines · On Mon, 23 Aug 2021 09:37:54 +0200 Michal Simek <[email protected]> wrote:
Enabling
MULTI_DTB_FITandDTB_RESELECTcan end up with multi DTBs in FIT image placed and aligned only by 32bits (4bytes). Based on device tree specification:
"Specifically, the memory reservation block shall be aligned to an 8-byte boundary and the structure block to a 4-byte boundary."
is 64bit (8bytes) alignment required. That's why make sure that fit-dtb.blob and u-boot.itb as our primary target images for Xilinx ZynqMP are all 64bit aligned.
Indeed, thanks for fixing this!
Quoted 2 lines
Signed-off-by Michal Simek <[email protected]>
Cheers,
Andre
Quoted 30 lines
---
Changes in v2:
- Update subject and commit message
- Enable 64bit alignment for all - reported by AndreMakefile | 3 +++ 1 file changed, 3 insertions(+)Makefile +3
-0@@ -1169,6 +1169,8 @@ MKIMAGEFLAGS_fit-dtb.blob = -f auto -A $(ARCH) -T firmware -C none -O u-boot \ -a 0 -e 0 -E \ $(patsubst %,-b arch/$(ARCH)/dts/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) -d /dev/null +MKIMAGEFLAGS_fit-dtb.blob += -B 0x8 + ifneq ($(EXT_DTB),) u-boot-fit-dtb.bin: u-boot-nodtb.bin $(EXT_DTB) $(call if_changed,cat)@@ -1431,6 +1433,7 @@ MKIMAGEFLAGS_u-boot.itb = else MKIMAGEFLAGS_u-boot.itb = -E endif +MKIMAGEFLAGS_u-boot.itb += -B 0x8 ifdef U_BOOT_ITS u-boot.itb: u-boot-nodtb.bin \
PATCH 8/10 arm64: dts: Make sure that all DTBs are 64bit aligned
In reply to Michal SimekStart of DTB should be 64bit aligned that's why also make sure that end is also 64bit aligned. It is not required but it is nice thing to do.
---
Changes in v2:
- Update subject and commit message
- Enable it for all (not just 64bit systems)
arch/arm/dts/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/dts/Makefile +1 -1
@@ -1127,7 +1127,7 @@ dtb-$(CONFIG_TARGET_EA_LPC3250DEVKITV2) += lpc3250-ea3250.dtb targets += $(dtb-y) # Add any required device tree compiler flags here -DTC_FLAGS += +DTC_FLAGS += -a 0x8 PHONY += dtbs dtbs: $(addprefix $(obj)/, $(dtb-y))
Signature · 1 line
2.33.0
PATCH 9/10 xilinx: zynqmp: Generate different u-boot.itb for MULTI_DTB_FIT
In reply to Michal SimekWhen MULTI_DTB_FIT is enabled fit-dtb.blob fit image is created which contain all DTBs listed by CONFIG_OF_LIST. And with DTB_RELESELECT there is a need to handle it as one file with DTBs in it not as separate DTBs in u-boot.its/itb.
That's why extend mkimage_fit_atf.sh to generate u-boot.itb correctly.
---
Changes in v2:
- Update if condition for MULTI_DTB
arch/arm/mach-zynqmp/mkimage_fit_atf.sh | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
arch/arm/mach-zynqmp/mkimage_fit_atf.sh +47 -0
@@ -111,6 +111,51 @@ cat << __TEE __TEE fi +MULTI_DTB=`awk '/CONFIG_MULTI_DTB_FIT / { print $3 }' include/generated/autoconf.h` + +if [ 1"$MULTI_DTB" -eq 11 ]; then + cat << __FDT_IMAGE_EOF + fdt_1 { + description = "Multi DTB fit image"; + data = /incbin/("fit-dtb.blob"); + type = "flat_dt"; + arch = "arm64"; + compression = "none"; + $DTB_LOAD + hash { + algo = "md5"; + }; + }; + }; + configurations { + default = "config_1"; +__FDT_IMAGE_EOF + +if [ ! -f $BL31 ]; then +cat << __CONF_SECTION1_EOF + config_1 { + description = "Multi DTB without TF-A"; + firmware = "uboot"; + loadables = "fdt_1"; + }; +__CONF_SECTION1_EOF +else +cat << __CONF_SECTION1_EOF + config_1 { + description = "Multi DTB with TF-A"; + firmware = "atf"; + loadables = "uboot", "fdt_1"; + }; +__CONF_SECTION1_EOF +fi + +cat << __ITS_EOF + }; +}; +__ITS_EOF + +else + DEFAULT=1 cnt=1 for dtname in $DT
@@ -181,3 +226,5 @@ cat << __ITS_EOF }; }; __ITS_EOF + +fi
Signature · 1 line
2.33.0
PATCH 10/10 xilinx: common: Enabling generic function for DT reselection
In reply to Michal SimekU-Boot support board detection at run time and based on it change DT. This feature is implemented for SOM Kria platforms which contain two eeproms which contain information about SOM module and CC (Carrier card). Full U-Boot starts with minimal DT file defined by CONFIG_DEFAULT_DEVICE_TREE which is available in multi DTB fit image. It is using default setup of board_name variable initializaed to DEVICE_TREE which corresponds to CONFIG_DEFAULT_DEVICE_TREE option.
When DTB_RESELECT is enabled board_detection() is called. Keep it your mind that this code is called before relocation. board_detection() is calling xilinx_read_eeprom() which fills board_info (xilinx_board_description) structure which are parsed in board_name_decode().
Based on DT configuration and amount of nvmemX aliases name of the board is composed by concatenating CONFIG_SYS_BOARD "-" <board_name> "-rev" <board_revision> "-" <cc_name> "-rev" <cc_revision>.
If CC is not present or more are available it keeps going.
When board name is composed and returned from board_name_decode() it is assigned to board_name variable which is used by board_fit_config_name_match() which is called via fdtdec_setup() when it goes over config options in multi dtb FIT image.
From practical point of view multi DTB image is key point here which has to contain configs for detected combinations. Unfortunately as of now they have to be full DTBs and DTBOs are not supported.
That's why configuration like:
config_X {
description = "zynqmp-board-cc";
fdt = "board", "cc";
};needs to be squashed together with:
fdtoverlay -o zynqmp-board-cc -i arch/arm/dts/zynqmp-board.dtb \arch/arm/dts/zynqmp-cc.dtbo
and only one dtb is in fit:
config_X {
description = "zynqmp-board-cc";
fdt = "board-cc";
};For creating multi DTBs fit image use mkimage -E, e.g.:
mkimage -E -f all.its all.dtb
When DTB_RESELECT is enabled xilinx_read_eeprom() is called before relocation and it uses calloc for getting a buffer. Because this is dynamic memory it is not relocated that's why xilinx_read_eeprom() is called again as the part of board_init(). This second read with calloc buffer placed in proper position board_late_init_xilinx() can setup u-boot variables as before.
---
Changes in v2:
- call fru_capture in non DEBUG mode
- Show detected name as standard message to see what has been chosen
arch/arm/dts/zynqmp-sm-k26-revA.dts | 3 ++ board/xilinx/common/board.c | 84 ++++++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 6 deletions(-)
arch/arm/dts/zynqmp-sm-k26-revA.dts +3 -0
@@ -204,17 +204,20 @@ &i2c1 { status = "okay"; + u-boot,dm-pre-reloc; clock-frequency = <400000>; scl-gpios = <&gpio 24 GPIO_ACTIVE_HIGH>; sda-gpios = <&gpio 25 GPIO_ACTIVE_HIGH>; eeprom: eeprom@50 { /* u46 - also at address 0x58 */ + u-boot,dm-pre-reloc; compatible = "st,24c64", "atmel,24c64"; /* st m24c64 */ reg = <0x50>; /* WP pin EE_WP_EN connected to slg7x644092@68 */ }; eeprom_cc: eeprom@51 { /* required by spec - also at address 0x59 */ + u-boot,dm-pre-reloc; compatible = "st,24c64", "atmel,24c64"; /* st m24c64 */ reg = <0x51>; };
board/xilinx/common/board.c +78 -6
116 lines not on this page · raw message
Signature · 1 line
2.33.0
po 23. 8. 2021 v 9:37 odesílatel Michal Simek <[email protected]> napsal:
Quoted 46 lines
Hi,
this series add support for board or board+cc runtime DT selection. EEPROM memory is read and based on that decoded if this is legacy/fru based format and proper DTB is used. There is a need to have all DTBs 64bit aligned. If you don't have it you will end up in exception. But one patch in this series is trying to detect it and panic before you reach it to let you know what's wrong.
Enforcing mkimage/dtb alignment is done based on
CONFIG_PHYS_64BITand affects all 64bit systems but it is also not wrong for them to be properly aligned.Thanks,
MichalChanges in v2:
- Update subject and commit message
- Enable 64bit alignment for all - reported by Andre
- Update subject and commit message
- Enable it for all (not just 64bit systems)
- Update if condition forMULTI_DTB
- callfru_capturein non DEBUG mode
- Show detected name as standard message to see what has been chosenMichal Simek (10):
xilinx: fru: Replace spaces with \0 in detected name
xilinx: Use variable for passingboard_name
xilinx: common: Change board_info[] handling
xilinx: common: Free allocated structure
xilinx: Add support for generic board detection
xilinx: zynqmp: Check that DT is 64bit aligned
Makefile: Align fit-dtb.blob and u-boot.itb by 64bits
arm64: dts: Make sure that all DTBs are 64bit aligned
xilinx: zynqmp: Generate different u-boot.itb forMULTI_DTB_FIT
xilinx: common: Enabling generic function for DT reselectionMakefile | 3 + arch/arm/dts/Makefile | 2 +- arch/arm/dts/zynqmp-sm-k26-revA.dts | 3 + arch/arm/mach-zynqmp/mkimage_fit_atf.sh | 47 +++++++ board/xilinx/common/board.c | 158 +++++++++++++++++++----- board/xilinx/zynqmp/zynqmp.c | 3 + 6 files changed, 186 insertions(+), 30 deletions(-)
Quoted 3 lines
--
2.33.0
This should have v2 in subject but it has changes in v2.
Simon: Can we extend patman to capture this configuration where you have changes for newer revision then revision of the whole series?
Anyway applied to my tree.
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Xilinx Microblaze Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs