From 26b2d2c0f271c4b9a5cd4f32be280fca2bec452c Mon Sep 17 00:00:00 2001 From: Benjamin Hahn Date: Tue, 16 Jul 2024 22:11:26 -0700 Subject: [PATCH 1/9] include: env: phytec: Create env file for loading and applying overlays The env scripts for loading and applying overlays are identical for many PHYTEC Boards. Create a common env that can be included. The env variables bootenv_addr and fdto_addr are board specific and need to be set in the board specific file. The env variable get_cmd also needs to be set in board specific files and can be set to tftp or dhcp. Signed-off-by: Benjamin Hahn Signed-off-by: Daniel Schultz Reviewed-by: Teresa Remmet Reviewed-by: Wadim Egorov --- include/env/phytec/overlays.env | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 include/env/phytec/overlays.env diff --git a/include/env/phytec/overlays.env b/include/env/phytec/overlays.env new file mode 100644 index 00000000000..febb991f4f5 --- /dev/null +++ b/include/env/phytec/overlays.env @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2024 PHYTEC Messtechnik GmbH + * Author: Benjamin Hahn + */ + +/* Logic to load and apply overlays. Load overlays from bootenv.txt into + * environment and apply those overlays. + * The variables bootenv_addr and fdto_addr are board specific. */ + +bootenv=bootenv.txt +mmc_load_bootenv=load mmc ${mmcdev}:${mmcpart} ${bootenv_addr} ${bootenv} +mmc_load_overlay=load mmc ${mmcdev}:${mmcpart} ${fdto_addr} ${overlay} +mmc_apply_overlays= + fdt address ${fdt_addr}; + if test ${no_overlays} = 0; then + for overlay in ${overlays}; + do; + if run mmc_load_overlay; then + fdt resize ${filesize}; + fdt apply ${fdto_addr}; + fi; + done; + fi; +net_load_bootenv=${get_cmd} ${bootenv_addr} ${bootenv} +net_load_overlay=${get_cmd} ${fdto_addr} ${overlay} +net_apply_overlays= + fdt address ${fdt_addr}; + if test ${no_overlays} = 0; then + for overlay in ${overlays}; + do; + if run net_load_overlay; then + fdt resize ${filesize}; + fdt apply ${fdto_addr}; + fi; + done; + fi; From 0ff9141fb88ee57fa3d994cdee48b32c173d4297 Mon Sep 17 00:00:00 2001 From: Benjamin Hahn Date: Tue, 16 Jul 2024 22:11:27 -0700 Subject: [PATCH 2/9] phycore-imx8mp: Add overlay and bootenv.txt support Add support for loading bootenv.txt as well as loading and applying overlays during boot from mmc and net. ${no_bootenv}: Prevent loading external bootenv.txt environment. Use ${overlays} variable directly from u-boot environment. ${no_overlay}: Do not load overlays defined in ${overlays} variable. Overlays loaded over the extension command are still being applied. Signed-off-by: Benjamin Hahn Signed-off-by: Daniel Schultz Reviewed-by: Teresa Remmet Reviewed-by: Wadim Egorov --- board/phytec/phycore_imx8mp/phycore_imx8mp.env | 15 +++++++++++++++ configs/phycore-imx8mp_defconfig | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/board/phytec/phycore_imx8mp/phycore_imx8mp.env b/board/phytec/phycore_imx8mp/phycore_imx8mp.env index 7f6c5fd2c76..4ed5dc7e272 100644 --- a/board/phytec/phycore_imx8mp/phycore_imx8mp.env +++ b/board/phytec/phycore_imx8mp/phycore_imx8mp.env @@ -1,4 +1,5 @@ #include +#include bootcmd= if test ${dofastboot} = 1; then @@ -16,6 +17,8 @@ bootcmd= fi; fi; console=ttymxc0,115200 +bootenv_addr=0x49100000 +fdto_addr=0x49000000 dofastboot=0 emmc_dev=2 fastboot_raw_partition_all=0 4194304 @@ -32,8 +35,14 @@ mmcargs= mmcautodetect=yes mmcboot= echo Booting from mmc ...; + if test ${no_bootenv} = 0; then + if run mmc_load_bootenv; then + env import -t ${bootenv_addr} ${filesize}; + fi; + fi; run mmcargs; if run loadfdt; then + run mmc_apply_overlays; booti ${loadaddr} - ${fdt_addr}; else echo WARN: Cannot load the DT; @@ -51,9 +60,15 @@ netboot= else setenv get_cmd tftp; fi; + if test ${no_bootenv} = 0; then + if run net_load_bootenv; then + env import -t ${bootenv_addr} ${filesize}; + fi; + fi; ${get_cmd} ${loadaddr} ${image}; run netargs; if ${get_cmd} ${fdt_addr} ${fdt_file}; then + run net_apply_overlays; booti ${loadaddr} - ${fdt_addr}; else echo WARN: Cannot load the DT; diff --git a/configs/phycore-imx8mp_defconfig b/configs/phycore-imx8mp_defconfig index 8dd4963bdc0..da7fe612ca0 100644 --- a/configs/phycore-imx8mp_defconfig +++ b/configs/phycore-imx8mp_defconfig @@ -13,6 +13,7 @@ CONFIG_DM_GPIO=y CONFIG_DEFAULT_DEVICE_TREE="freescale/imx8mp-phyboard-pollux-rdk" CONFIG_SPL_TEXT_BASE=0x920000 CONFIG_TARGET_PHYCORE_IMX8MP=y +CONFIG_OF_LIBFDT_OVERLAY=y CONFIG_SYS_MONITOR_LEN=524288 CONFIG_SPL_MMC=y CONFIG_SPL_SERIAL=y @@ -51,8 +52,6 @@ CONFIG_SPL_POWER=y CONFIG_SPL_WATCHDOG=y CONFIG_HUSH_PARSER=y CONFIG_SYS_PROMPT="u-boot=> " -# CONFIG_CMD_EXPORTENV is not set -# CONFIG_CMD_IMPORTENV is not set # CONFIG_CMD_CRC32 is not set CONFIG_CMD_EEPROM=y CONFIG_SYS_I2C_EEPROM_ADDR_LEN=2 @@ -76,6 +75,7 @@ CONFIG_CMD_EXT2=y CONFIG_CMD_EXT4=y CONFIG_CMD_EXT4_WRITE=y CONFIG_CMD_FAT=y +CONFIG_CMD_FS_GENERIC=y CONFIG_OF_CONTROL=y CONFIG_SPL_OF_CONTROL=y CONFIG_ENV_OVERWRITE=y From 95ab7372f106db079d878e5d1e205d0e9a2fbc04 Mon Sep 17 00:00:00 2001 From: Benjamin Hahn Date: Tue, 16 Jul 2024 22:11:28 -0700 Subject: [PATCH 3/9] phycore_imx93: include common overlays.env Include the common overlays env file for phycore_imx93. The common overlays env file supports disabling loading overlays by setting the no_overlays variable. Signed-off-by: Benjamin Hahn Signed-off-by: Daniel Schultz Reviewed-by: Wadim Egorov --- board/phytec/phycore_imx93/phycore_imx93.env | 25 ++------------------ 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/board/phytec/phycore_imx93/phycore_imx93.env b/board/phytec/phycore_imx93/phycore_imx93.env index 27bfadfa140..09542f5aa7d 100644 --- a/board/phytec/phycore_imx93/phycore_imx93.env +++ b/board/phytec/phycore_imx93/phycore_imx93.env @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */ +#include + image=Image console=ttyLP0 fdt_addr=0x83000000 @@ -7,8 +9,6 @@ fdto_addr=0x830c0000 bootenv_addr=0x83500000 fdt_file=CONFIG_DEFAULT_FDT_FILE ip_dyn=yes -bootenv=bootenv.txt -mmc_load_bootenv=fatload mmc ${mmcdev}:${mmcpart} ${bootenv_addr} ${bootenv} mmcdev=CONFIG_SYS_MMC_ENV_DEV mmcpart=1 mmcroot=2 @@ -17,16 +17,6 @@ mmcargs=setenv bootargs console=${console},${baudrate} earlycon root=/dev/mmcblk${mmcdev}p${mmcroot} ${raucargs} rootwait rw loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image} loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file} -mmc_load_overlay=fatload mmc ${mmcdev}:${mmcpart} ${fdto_addr} ${overlay} -mmc_apply_overlays= - fdt address ${fdt_addr}; - for overlay in ${overlays}; - do; - if run mmc_load_overlay; then - fdt resize ${filesize}; - fdt apply ${fdto_addr}; - fi; - done; mmcboot= echo Booting from mmc ...; if run mmc_load_bootenv; then @@ -42,17 +32,6 @@ mmcboot= nfsroot=/nfs netargs=setenv bootargs console=${console},${baudrate} earlycon root=/dev/nfs ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp -net_load_bootenv=${get_cmd} ${bootenv_addr} ${bootenv} -net_load_overlay=${get_cmd} ${fdto_addr} ${overlay} -net_apply_overlays= - fdt address ${fdt_addr}; - for overlay in ${overlays}; - do; - if run net_load_overlay; then - fdt resize ${filesize}; - fdt apply ${fdto_addr}; - fi; - done; netboot= echo Booting from net ...; run netargs; From 1189bf61cfa9b8b97c5507afd11ee605c9e4edd7 Mon Sep 17 00:00:00 2001 From: Benjamin Hahn Date: Tue, 16 Jul 2024 22:11:29 -0700 Subject: [PATCH 4/9] board: phytec: renaming of variables according to bootstd doc Rename existing environment variables according to the bootstd doc. Renamed variables are fdto_addr, bootenv_addr, fdt_addr and fdt_file. Signed-off-by: Benjamin Hahn Signed-off-by: Daniel Schultz Reviewed-by: Wadim Egorov --- .../phytec/phycore_imx8mp/phycore_imx8mp.env | 20 +++++++++---------- board/phytec/phycore_imx93/phycore_imx93.env | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/board/phytec/phycore_imx8mp/phycore_imx8mp.env b/board/phytec/phycore_imx8mp/phycore_imx8mp.env index 4ed5dc7e272..f8f878e8f3a 100644 --- a/board/phytec/phycore_imx8mp/phycore_imx8mp.env +++ b/board/phytec/phycore_imx8mp/phycore_imx8mp.env @@ -17,17 +17,17 @@ bootcmd= fi; fi; console=ttymxc0,115200 -bootenv_addr=0x49100000 -fdto_addr=0x49000000 +bootenv_addr_r=0x49100000 +fdtoverlay_addr_r=0x49000000 dofastboot=0 emmc_dev=2 fastboot_raw_partition_all=0 4194304 fastboot_raw_partition_bootloader=64 8128 -fdt_addr=0x48000000 -fdt_file=CONFIG_DEFAULT_FDT_FILE +fdt_addr_r=0x48000000 +fdtfile=CONFIG_DEFAULT_FDT_FILE image=Image ip_dyn=yes -loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file} +loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr_r} ${fdtfile} loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image} mmcargs= setenv bootargs console=${console} @@ -37,13 +37,13 @@ mmcboot= echo Booting from mmc ...; if test ${no_bootenv} = 0; then if run mmc_load_bootenv; then - env import -t ${bootenv_addr} ${filesize}; + env import -t ${bootenv_addr_r} ${filesize}; fi; fi; run mmcargs; if run loadfdt; then run mmc_apply_overlays; - booti ${loadaddr} - ${fdt_addr}; + booti ${loadaddr} - ${fdt_addr_r}; else echo WARN: Cannot load the DT; fi; @@ -62,14 +62,14 @@ netboot= fi; if test ${no_bootenv} = 0; then if run net_load_bootenv; then - env import -t ${bootenv_addr} ${filesize}; + env import -t ${bootenv_addr_r} ${filesize}; fi; fi; ${get_cmd} ${loadaddr} ${image}; run netargs; - if ${get_cmd} ${fdt_addr} ${fdt_file}; then + if ${get_cmd} ${fdt_addr_r} ${fdtfile}; then run net_apply_overlays; - booti ${loadaddr} - ${fdt_addr}; + booti ${loadaddr} - ${fdt_addr_r}; else echo WARN: Cannot load the DT; fi; diff --git a/board/phytec/phycore_imx93/phycore_imx93.env b/board/phytec/phycore_imx93/phycore_imx93.env index 09542f5aa7d..ab65cfce5fd 100644 --- a/board/phytec/phycore_imx93/phycore_imx93.env +++ b/board/phytec/phycore_imx93/phycore_imx93.env @@ -4,10 +4,10 @@ image=Image console=ttyLP0 -fdt_addr=0x83000000 -fdto_addr=0x830c0000 -bootenv_addr=0x83500000 -fdt_file=CONFIG_DEFAULT_FDT_FILE +fdt_addr_r=0x83000000 +fdtoverlay_addr_r=0x830c0000 +bootenv_addr_r=0x83500000 +fdtfile=CONFIG_DEFAULT_FDT_FILE ip_dyn=yes mmcdev=CONFIG_SYS_MMC_ENV_DEV mmcpart=1 @@ -16,16 +16,16 @@ mmcautodetect=yes mmcargs=setenv bootargs console=${console},${baudrate} earlycon root=/dev/mmcblk${mmcdev}p${mmcroot} ${raucargs} rootwait rw loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image} -loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file} +loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr_r} ${fdtfile} mmcboot= echo Booting from mmc ...; if run mmc_load_bootenv; then - env import -t ${bootenv_addr} ${filesize}; + env import -t ${bootenv_addr_r} ${filesize}; fi; run mmcargs; if run loadfdt; then run mmc_apply_overlays; - booti ${loadaddr} - ${fdt_addr}; + booti ${loadaddr} - ${fdt_addr_r}; else echo WARN: Cannot load the DT; fi; @@ -41,12 +41,12 @@ netboot= setenv get_cmd tftp; fi; if run net_load_bootenv; then - env import -t ${bootenv_addr} ${filesize}; + env import -t ${bootenv_addr_r} ${filesize}; fi; ${get_cmd} ${loadaddr} ${image}; - if ${get_cmd} ${fdt_addr} ${fdt_file}; then + if ${get_cmd} ${fdt_addr_r} ${fdtfile}; then run net_apply_overlays; - booti ${loadaddr} - ${fdt_addr}; + booti ${loadaddr} - ${fdt_addr_r}; else echo WARN: Cannot load the DT; fi; From 84303dc371fb37c9cbbea124cc341db9ae3162b3 Mon Sep 17 00:00:00 2001 From: Benjamin Hahn Date: Tue, 16 Jul 2024 22:11:30 -0700 Subject: [PATCH 5/9] include: env: phytec: renaming of variables according to bootstd doc Rename existing environment variables according to the bootstd doc. Renamed variables are fdto_addr, bootenv_addr, fdt_addr. Signed-off-by: Benjamin Hahn Signed-off-by: Daniel Schultz Reviewed-by: Wadim Egorov --- include/env/phytec/overlays.env | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/include/env/phytec/overlays.env b/include/env/phytec/overlays.env index febb991f4f5..78721cde654 100644 --- a/include/env/phytec/overlays.env +++ b/include/env/phytec/overlays.env @@ -6,32 +6,33 @@ /* Logic to load and apply overlays. Load overlays from bootenv.txt into * environment and apply those overlays. - * The variables bootenv_addr and fdto_addr are board specific. */ + * The variables bootenv_addr_r and fdtoverlay_addr_r are board specific. + * get_cmd can be either tftp or dhcp. */ bootenv=bootenv.txt -mmc_load_bootenv=load mmc ${mmcdev}:${mmcpart} ${bootenv_addr} ${bootenv} -mmc_load_overlay=load mmc ${mmcdev}:${mmcpart} ${fdto_addr} ${overlay} +mmc_load_bootenv=load mmc ${mmcdev}:${mmcpart} ${bootenv_addr_r} ${bootenv} +mmc_load_overlay=load mmc ${mmcdev}:${mmcpart} ${fdtoverlay_addr_r} ${overlay} mmc_apply_overlays= - fdt address ${fdt_addr}; + fdt address ${fdt_addr_r}; if test ${no_overlays} = 0; then for overlay in ${overlays}; do; if run mmc_load_overlay; then fdt resize ${filesize}; - fdt apply ${fdto_addr}; + fdt apply ${fdtoverlay_addr_r}; fi; done; fi; -net_load_bootenv=${get_cmd} ${bootenv_addr} ${bootenv} -net_load_overlay=${get_cmd} ${fdto_addr} ${overlay} +net_load_bootenv=${get_cmd} ${bootenv_addr_r} ${bootenv} +net_load_overlay=${get_cmd} ${fdtoverlay_addr_r} ${overlay} net_apply_overlays= - fdt address ${fdt_addr}; + fdt address ${fdt_addr_r}; if test ${no_overlays} = 0; then for overlay in ${overlays}; do; if run net_load_overlay; then fdt resize ${filesize}; - fdt apply ${fdto_addr}; + fdt apply ${fdtoverlay_addr_r}; fi; done; fi; From 381580e31bc53d215543088fa0ff5343efc2760d Mon Sep 17 00:00:00 2001 From: Daniel Schultz Date: Tue, 16 Jul 2024 22:11:31 -0700 Subject: [PATCH 6/9] include: env: phytec: Add common mmc boot for K3 SoMs This environment include can be used to boot from a MMC device for PHYTEC's K3-based SoMs. Signed-off-by: Daniel Schultz Reviewed-by: Wadim Egorov --- include/env/phytec/k3_mmc.env | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 include/env/phytec/k3_mmc.env diff --git a/include/env/phytec/k3_mmc.env b/include/env/phytec/k3_mmc.env new file mode 100644 index 00000000000..e1208a6eea1 --- /dev/null +++ b/include/env/phytec/k3_mmc.env @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2024 PHYTEC Messtechnik GmbH + * Author: Daniel Schultz + */ + +/* Logic for TI K3 based SoCs to boot from a MMC device. */ + +mmcargs=setenv bootargs console=${console} earlycon=${earlycon} + root=/dev/mmcblk${mmcdev}p${mmcroot} rootwait rw +loadimage=load mmc ${mmcdev}:${mmcpart} ${loadaddr} Image +loadfdt=load mmc ${mmcdev}:${mmcpart} ${fdt_addr_r} ${fdtfile} +mmcboot=run mmcargs; + mmc dev ${mmcdev}; + mmc rescan; + run loadimage; + run loadfdt; + booti ${loadaddr} - ${fdt_addr_r} From 59d87e6a28d2e1a7a0b064ebf21adfdcd79fe343 Mon Sep 17 00:00:00 2001 From: Daniel Schultz Date: Tue, 16 Jul 2024 22:11:32 -0700 Subject: [PATCH 7/9] include: env: phytec: k3_mmc: Apply overlays during boot Include the overlays.env file and run the apply routine before booting the Kernel. Signed-off-by: Daniel Schultz Reviewed-by: Wadim Egorov --- include/env/phytec/k3_mmc.env | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/env/phytec/k3_mmc.env b/include/env/phytec/k3_mmc.env index e1208a6eea1..3d3595ceb7e 100644 --- a/include/env/phytec/k3_mmc.env +++ b/include/env/phytec/k3_mmc.env @@ -6,6 +6,8 @@ /* Logic for TI K3 based SoCs to boot from a MMC device. */ +#include + mmcargs=setenv bootargs console=${console} earlycon=${earlycon} root=/dev/mmcblk${mmcdev}p${mmcroot} rootwait rw loadimage=load mmc ${mmcdev}:${mmcpart} ${loadaddr} Image @@ -15,4 +17,5 @@ mmcboot=run mmcargs; mmc rescan; run loadimage; run loadfdt; + run mmc_apply_overlays; booti ${loadaddr} - ${fdt_addr_r} From ed9a91fd511bc128d60406d3c47cd0cd75aaea11 Mon Sep 17 00:00:00 2001 From: Daniel Schultz Date: Tue, 16 Jul 2024 22:11:33 -0700 Subject: [PATCH 8/9] board: phytec: phycore_am62x: Use k3_mmc.env logic Use our common environment file to implement MMC boot. Signed-off-by: Daniel Schultz Reviewed-by: Dhruva Gole Reviewed-by: Wadim Egorov --- board/phytec/phycore_am62x/phycore_am62x.env | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/board/phytec/phycore_am62x/phycore_am62x.env b/board/phytec/phycore_am62x/phycore_am62x.env index 2d6475d408f..046bbd22f25 100644 --- a/board/phytec/phycore_am62x/phycore_am62x.env +++ b/board/phytec/phycore_am62x/phycore_am62x.env @@ -1,4 +1,5 @@ #include +#include fdtaddr=0x88000000 loadaddr=0x82000000 @@ -14,13 +15,3 @@ mmcroot=2 mmcpart=1 console=ttyS2,115200n8 earlycon=ns16550a,mmio32,0x02800000 -mmcargs=setenv bootargs console=${console} earlycon=${earlycon} - root=/dev/mmcblk${mmcdev}p${mmcroot} rootwait rw -loadimage=load mmc ${mmcdev}:${mmcpart} ${loadaddr} Image -loadfdt=load mmc ${mmcdev}:${mmcpart} ${fdtaddr} ${fdtfile} -mmcboot=run mmcargs; - mmc dev ${mmcdev}; - mmc rescan; - run loadimage; - run loadfdt; - booti ${loadaddr} - ${fdtaddr} From f1296bfff71b0cbac2241c0d6f1a88468c5af16d Mon Sep 17 00:00:00 2001 From: Daniel Schultz Date: Tue, 16 Jul 2024 22:11:34 -0700 Subject: [PATCH 9/9] board: phytec: phycore_am64x: Use k3_mmc.env logic Use our common environment file to implement MMC boot. Signed-off-by: Daniel Schultz Reviewed-by: Wadim Egorov --- board/phytec/phycore_am64x/phycore_am64x.env | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/board/phytec/phycore_am64x/phycore_am64x.env b/board/phytec/phycore_am64x/phycore_am64x.env index e24a958f51d..18f0fa5b4c3 100644 --- a/board/phytec/phycore_am64x/phycore_am64x.env +++ b/board/phytec/phycore_am64x/phycore_am64x.env @@ -1,3 +1,5 @@ +#include + fdtaddr=0x88000000 loadaddr=0x82000000 scriptaddr=0x80000000 @@ -12,13 +14,3 @@ mmcroot=2 mmcpart=1 console=ttyS2,115200n8 earlycon=ns16550a,mmio32,0x02800000 -mmcargs=setenv bootargs console=${console} earlycon=${earlycon} - root=/dev/mmcblk${mmcdev}p${mmcroot} rootwait rw -loadimage=load mmc ${mmcdev}:${mmcpart} ${loadaddr} Image -loadfdt=load mmc ${mmcdev}:${mmcpart} ${fdtaddr} ${fdtfile} -mmcboot=run mmcargs; - mmc dev ${mmcdev}; - mmc rescan; - run loadimage; - run loadfdt; - booti ${loadaddr} - ${fdtaddr}