Generalize PHYTEC Overlay Handling
v2 cover Generalize PHYTEC Overlay Handling
The overlays are specified in the bootenv.txt file that is loaded into the environment. Then these overlays get loaded and applied via a script. These scripts for loading and applying devicetree overlays are identical for many phytec boards.
Create a common overlays.env that can be included.
Add support for devicetree overlays to phycore-imx8mp and include the overlays.env for phycore-imx93.
Rename existing environment variables according to bootstd doc. Move MMC boot logic into a common k3_mmc.env file and include the new overlays.env file as well.
Changes v2:
* Rebased to master and resolved a conflict in
configs/phycore-imx8mp_defconfig.
Benjamin Hahn (5):
include: env: phytec: Create env file for loading and applying
overlays
phycore-imx8mp: Add overlay and bootenv.txt support
phycore_imx93: include common overlays.env
board: phytec: renaming of variables according to bootstd doc
include: env: phytec: renaming of variables according to bootstd doc
Daniel Schultz (4):
include: env: phytec: Add common mmc boot for K3 SoMs
include: env: phytec: k3_mmc: Apply overlays during boot
board: phytec: phycore_am62x: Use k3_mmc.env logic
board: phytec: phycore_am64x: Use k3_mmc.env logic
board/phytec/phycore_am62x/phycore_am62x.env | 11 +---- board/phytec/phycore_am64x/phycore_am64x.env | 12 +---- .../phytec/phycore_imx8mp/phycore_imx8mp.env | 27 ++++++++--- board/phytec/phycore_imx93/phycore_imx93.env | 45 +++++-------------- configs/phycore-imx8mp_defconfig | 4 +- include/env/phytec/k3_mmc.env | 21 +++++++++ include/env/phytec/overlays.env | 38 ++++++++++++++++ 7 files changed, 97 insertions(+), 61 deletions(-) create mode 100644 include/env/phytec/k3_mmc.env create mode 100644 include/env/phytec/overlays.env
Signature · 1 line
2.25.1
PATCH v2 1/9 include: env: phytec: Create env file for loading and applying overlays
From: Benjamin Hahn <[email protected]>
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.
--- include/env/phytec/overlays.env | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 include/env/phytec/overlays.env
include/env/phytec/overlays.env new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2024 PHYTEC Messtechnik GmbH + * Author: Benjamin Hahn <[email protected]> + */ + +/* 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;
Signature · 1 line
2.25.1
PATCH v2 2/9 phycore-imx8mp: Add overlay and bootenv.txt support
In reply to Daniel SchultzFrom: Benjamin Hahn <[email protected]>
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.
--- board/phytec/phycore_imx8mp/phycore_imx8mp.env | 15 +++++++++++++++ configs/phycore-imx8mp_defconfig | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-)
board/phytec/phycore_imx8mp/phycore_imx8mp.env +15 -0
@@ -1,4 +1,5 @@ #include <env/phytec/rauc.env> +#include <env/phytec/overlays.env> 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;
configs/phycore-imx8mp_defconfig +2 -2
@@ -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
Signature · 1 line
2.25.1
PATCH v2 3/9 phycore_imx93: include common overlays.env
In reply to Daniel SchultzFrom: Benjamin Hahn <[email protected]>
Include the common overlays env file for phycore_imx93. The common overlays env file supports disabling loading overlays by setting the no_overlays variable.
--- board/phytec/phycore_imx93/phycore_imx93.env | 25 ++------------------ 1 file changed, 2 insertions(+), 23 deletions(-)
board/phytec/phycore_imx93/phycore_imx93.env +2 -23
@@ -1,5 +1,7 @@ /* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */ +#include <env/phytec/overlays.env> + 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;
Signature · 1 line
2.25.1
PATCH v2 4/9 board: phytec: renaming of variables according to bootstd doc
In reply to Daniel SchultzFrom: Benjamin Hahn <[email protected]>
Rename existing environment variables according to the bootstd doc. Renamed variables are fdto_addr, bootenv_addr, fdt_addr and fdt_file.
--- .../phytec/phycore_imx8mp/phycore_imx8mp.env | 20 +++++++++---------- board/phytec/phycore_imx93/phycore_imx93.env | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-)
board/phytec/phycore_imx8mp/phycore_imx8mp.env +10 -10
@@ -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;
board/phytec/phycore_imx93/phycore_imx93.env +10 -10
@@ -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;
Signature · 1 line
2.25.1
PATCH v2 5/9 include: env: phytec: renaming of variables according to bootstd doc
In reply to Daniel SchultzFrom: Benjamin Hahn <[email protected]>
Rename existing environment variables according to the bootstd doc. Renamed variables are fdto_addr, bootenv_addr, fdt_addr.
--- include/env/phytec/overlays.env | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
include/env/phytec/overlays.env +10 -9
@@ -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;
Signature · 1 line
2.25.1
PATCH v2 6/9 include: env: phytec: Add common mmc boot for K3 SoMs
In reply to Daniel SchultzThis environment include can be used to boot from a MMC device for PHYTEC's K3-based SoMs.
--- include/env/phytec/k3_mmc.env | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 include/env/phytec/k3_mmc.env
include/env/phytec/k3_mmc.env new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2024 PHYTEC Messtechnik GmbH + * Author: Daniel Schultz <[email protected]> + */ + +/* 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}
Signature · 1 line
2.25.1
PATCH v2 7/9 include: env: phytec: k3_mmc: Apply overlays during boot
In reply to Daniel SchultzInclude the overlays.env file and run the apply routine before booting the Kernel.
--- include/env/phytec/k3_mmc.env | 3 +++ 1 file changed, 3 insertions(+)
include/env/phytec/k3_mmc.env +3 -0
@@ -6,6 +6,8 @@ /* Logic for TI K3 based SoCs to boot from a MMC device. */ +#include <env/phytec/overlays.env> + 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}
Signature · 1 line
2.25.1
PATCH v2 8/9 board: phytec: phycore_am62x: Use k3_mmc.env logic
In reply to Daniel SchultzUse our common environment file to implement MMC boot.
--- board/phytec/phycore_am62x/phycore_am62x.env | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
board/phytec/phycore_am62x/phycore_am62x.env +1 -10
@@ -1,4 +1,5 @@ #include <env/ti/k3_dfu.env> +#include <env/phytec/k3_mmc.env> 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}
Signature · 1 line
2.25.1
PATCH v2 9/9 board: phytec: phycore_am64x: Use k3_mmc.env logic
In reply to Daniel SchultzUse our common environment file to implement MMC boot.
--- board/phytec/phycore_am64x/phycore_am64x.env | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
board/phytec/phycore_am64x/phycore_am64x.env +2 -10
@@ -1,3 +1,5 @@ +#include <env/phytec/k3_mmc.env> + 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}
Signature · 1 line
2.25.1
Quoted 11 lines · Daniel Schultz
The overlays are specified in the bootenv.txt file that is loaded into the environment. Then these overlays get loaded and applied via a script. These scripts for loading and applying devicetree overlays are identical for many phytec boards.
Create a common overlays.env that can be included.
Add support for devicetree overlays to phycore-imx8mp and include the overlays.env for phycore-imx93.
Rename existing environment variables according to bootstd doc. Move MMC boot logic into a common k3_mmc.env file and include the new overlays.env file as well.
Quoted 1 line
[...]
Applied to u-boot/master, thanks!
Signature · 1 line
Tom