[2/3] u-boot-script: add support to use builtin dt

Message ID 20230904055133.1851073-3-felix.moessbauer@siemens.com
State Accepted, archived
Headers show
Series Extend u-boot-script for DT overlays | expand

Commit Message

MOESSBAUER, Felix Sept. 4, 2023, 5:51 a.m. UTC
This patch adds support to use the u-boot builtin device tree instead of
the one from the rootfs / linux. This enables the use of dt overlays
even if the corresponding device tree in the kernel is not compiled with
symbol support (u-boot builtin DTBs always have symbol information).

To use the builtin dt, add the WKS sourceparam "builtin_dt=yes" to the
rootfs-u-boot sourcer.

Co-developed-by: Florian Bezdeka <florian.bezdeka@siemens.com>
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 .../u-boot-script/files/u-boot-script            |  3 +++
 .../u-boot-script/files/update-u-boot-script     | 16 ++++++++++++----
 .../lib/wic/plugins/source/rootfs-u-boot.py      |  3 +++
 3 files changed, 18 insertions(+), 4 deletions(-)

Comments

Jan Kiszka Sept. 4, 2023, 6:05 a.m. UTC | #1
On 04.09.23 07:51, Felix Moessbauer wrote:
> This patch adds support to use the u-boot builtin device tree instead of
> the one from the rootfs / linux. This enables the use of dt overlays
> even if the corresponding device tree in the kernel is not compiled with
> symbol support (u-boot builtin DTBs always have symbol information).
> 
> To use the builtin dt, add the WKS sourceparam "builtin_dt=yes" to the
> rootfs-u-boot sourcer.
> 
> Co-developed-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  .../u-boot-script/files/u-boot-script            |  3 +++
>  .../u-boot-script/files/update-u-boot-script     | 16 ++++++++++++----
>  .../lib/wic/plugins/source/rootfs-u-boot.py      |  3 +++
>  3 files changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/meta/recipes-bsp/u-boot-script/files/u-boot-script b/meta/recipes-bsp/u-boot-script/files/u-boot-script
> index d053d721..a11212c0 100644
> --- a/meta/recipes-bsp/u-boot-script/files/u-boot-script
> +++ b/meta/recipes-bsp/u-boot-script/files/u-boot-script
> @@ -15,3 +15,6 @@ NO_INITRD=""
>  
>  # U-boot commands to prepend to boot script
>  SCRIPT_PREPEND=""
> +
> +# use u-boot builtin device tree
> +BUILTIN_DT="no"
> diff --git a/meta/recipes-bsp/u-boot-script/files/update-u-boot-script b/meta/recipes-bsp/u-boot-script/files/update-u-boot-script
> index 1d9c6d45..2eb6097c 100755
> --- a/meta/recipes-bsp/u-boot-script/files/update-u-boot-script
> +++ b/meta/recipes-bsp/u-boot-script/files/update-u-boot-script
> @@ -33,10 +33,18 @@ echo "${SCRIPT_PREPEND}" >> ${BOOT_CMD}
>  
>  echo "setenv bootargs ${KERNEL_ARGS}" >> ${BOOT_CMD}
>  
> -echo "echo Loading /usr/lib/linux-image-${KERNEL_VERSION}/\${fdtfile}..." \
> -     >> ${BOOT_CMD}
> -echo "load \${devtype} \${devnum}:${ROOT_PARTITION} \${fdt_addr_r}" \
> -     "/usr/lib/linux-image-${KERNEL_VERSION}/\${fdtfile}" >> ${BOOT_CMD}
> +if [ "${BUILTIN_DT}" = "yes" ]; then
> +	echo "echo Loading builtin device tree..." \
> +	     >> ${BOOT_CMD}
> +	echo "fdt addr \${fdtcontroladdr}" >> ${BOOT_CMD}
> +	echo "fdt move \${fdtcontroladdr} \${fdt_addr_r}" >> ${BOOT_CMD}

Do we actually have to copy the U-Boot DT around? Why not updating
fdt_addr_r instead? Open question, didn't check the implications yet.

Jan

> +else
> +	echo "echo Loading /usr/lib/linux-image-${KERNEL_VERSION}/\${fdtfile}..." \
> +	     >> ${BOOT_CMD}
> +	echo "load \${devtype} \${devnum}:${ROOT_PARTITION} \${fdt_addr_r}" \
> +	     "/usr/lib/linux-image-${KERNEL_VERSION}/\${fdtfile}" >> ${BOOT_CMD}
> +fi
> +
>  echo "echo Loading /boot/${KERNEL_FILE}-${KERNEL_VERSION}..." >> ${BOOT_CMD}
>  echo "load \${devtype} \${devnum}:\${distro_bootpart} \${kernel_addr_r}" \
>       "/boot/${KERNEL_FILE}-${KERNEL_VERSION}" >> ${BOOT_CMD}
> diff --git a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
> index 0b4f9eec..93600dc2 100644
> --- a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
> +++ b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
> @@ -10,6 +10,7 @@
>  # Recognized sourceparams:
>  #  - no_initrd=yes          (disables initrd loading)
>  #  - overlays=file.dtbo ... (overlay files)
> +#  - builtin_dt=no          (use DT from uboot instead of kernel)
>  #  - script_prepend=cmd;... (prepends U-Boot command)
>  
>  import glob
> @@ -82,6 +83,8 @@ class RootfsUBootPlugin(RootfsPlugin):
>              cfg.write('NO_INITRD="%s"\n' % no_initrd)
>              overlays = source_params.get('overlays') or ''
>              cfg.write('OVERLAYS="%s"\n' % overlays)
> +            builtin_dt = source_params.get('builtin_dt') or ''
> +            cfg.write('BUILTIN_DT="%s"\n' % builtin_dt)
>              script_prepend = source_params.get('script_prepend') or ''
>              # remove escapes from $\{var\} that are needed to avoid expansion by wic
>              script_prepend = re.sub(r'\$\\{([^\\]+)\\}', r'${\1}', script_prepend)
MOESSBAUER, Felix Sept. 4, 2023, 7:09 a.m. UTC | #2
On Mon, 2023-09-04 at 08:05 +0200, Jan Kiszka wrote:
> On 04.09.23 07:51, Felix Moessbauer wrote:
> > This patch adds support to use the u-boot builtin device tree
> > instead of
> > the one from the rootfs / linux. This enables the use of dt
> > overlays
> > even if the corresponding device tree in the kernel is not compiled
> > with
> > symbol support (u-boot builtin DTBs always have symbol
> > information).
> > 
> > To use the builtin dt, add the WKS sourceparam "builtin_dt=yes" to
> > the
> > rootfs-u-boot sourcer.
> > 
> > Co-developed-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> > Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> > ---
> >  .../u-boot-script/files/u-boot-script            |  3 +++
> >  .../u-boot-script/files/update-u-boot-script     | 16
> > ++++++++++++----
> >  .../lib/wic/plugins/source/rootfs-u-boot.py      |  3 +++
> >  3 files changed, 18 insertions(+), 4 deletions(-)
> > 
> > diff --git a/meta/recipes-bsp/u-boot-script/files/u-boot-script
> > b/meta/recipes-bsp/u-boot-script/files/u-boot-script
> > index d053d721..a11212c0 100644
> > --- a/meta/recipes-bsp/u-boot-script/files/u-boot-script
> > +++ b/meta/recipes-bsp/u-boot-script/files/u-boot-script
> > @@ -15,3 +15,6 @@ NO_INITRD=""
> >  
> >  # U-boot commands to prepend to boot script
> >  SCRIPT_PREPEND=""
> > +
> > +# use u-boot builtin device tree
> > +BUILTIN_DT="no"
> > diff --git a/meta/recipes-bsp/u-boot-script/files/update-u-boot-
> > script b/meta/recipes-bsp/u-boot-script/files/update-u-boot-script
> > index 1d9c6d45..2eb6097c 100755
> > --- a/meta/recipes-bsp/u-boot-script/files/update-u-boot-script
> > +++ b/meta/recipes-bsp/u-boot-script/files/update-u-boot-script
> > @@ -33,10 +33,18 @@ echo "${SCRIPT_PREPEND}" >> ${BOOT_CMD}
> >  
> >  echo "setenv bootargs ${KERNEL_ARGS}" >> ${BOOT_CMD}
> >  
> > -echo "echo Loading /usr/lib/linux-image-
> > ${KERNEL_VERSION}/\${fdtfile}..." \
> > -     >> ${BOOT_CMD}
> > -echo "load \${devtype} \${devnum}:${ROOT_PARTITION}
> > \${fdt_addr_r}" \
> > -     "/usr/lib/linux-image-${KERNEL_VERSION}/\${fdtfile}" >>
> > ${BOOT_CMD}
> > +if [ "${BUILTIN_DT}" = "yes" ]; then
> > +       echo "echo Loading builtin device tree..." \
> > +            >> ${BOOT_CMD}
> > +       echo "fdt addr \${fdtcontroladdr}" >> ${BOOT_CMD}
> > +       echo "fdt move \${fdtcontroladdr} \${fdt_addr_r}" >>
> > ${BOOT_CMD}
> 
> Do we actually have to copy the U-Boot DT around? Why not updating
> fdt_addr_r instead? Open question, didn't check the implications yet.

The final DT needs to be in RAM at a location with some free tail
space, so we can resize it to later apply the overlays. This holds true
for the fdt_addr_r, but not necessarily for fdtcontroladdr.

Felix

> 
> Jan
> 
> > +else
> > +       echo "echo Loading /usr/lib/linux-image-
> > ${KERNEL_VERSION}/\${fdtfile}..." \
> > +            >> ${BOOT_CMD}
> > +       echo "load \${devtype} \${devnum}:${ROOT_PARTITION}
> > \${fdt_addr_r}" \
> > +            "/usr/lib/linux-image-${KERNEL_VERSION}/\${fdtfile}"
> > >> ${BOOT_CMD}
> > +fi
> > +
> >  echo "echo Loading /boot/${KERNEL_FILE}-${KERNEL_VERSION}..." >>
> > ${BOOT_CMD}
> >  echo "load \${devtype} \${devnum}:\${distro_bootpart}
> > \${kernel_addr_r}" \
> >       "/boot/${KERNEL_FILE}-${KERNEL_VERSION}" >> ${BOOT_CMD}
> > diff --git a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
> > b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
> > index 0b4f9eec..93600dc2 100644
> > --- a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
> > +++ b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
> > @@ -10,6 +10,7 @@
> >  # Recognized sourceparams:
> >  #  - no_initrd=yes          (disables initrd loading)
> >  #  - overlays=file.dtbo ... (overlay files)
> > +#  - builtin_dt=no          (use DT from uboot instead of kernel)
> >  #  - script_prepend=cmd;... (prepends U-Boot command)
> >  
> >  import glob
> > @@ -82,6 +83,8 @@ class RootfsUBootPlugin(RootfsPlugin):
> >              cfg.write('NO_INITRD="%s"\n' % no_initrd)
> >              overlays = source_params.get('overlays') or ''
> >              cfg.write('OVERLAYS="%s"\n' % overlays)
> > +            builtin_dt = source_params.get('builtin_dt') or ''
> > +            cfg.write('BUILTIN_DT="%s"\n' % builtin_dt)
> >              script_prepend = source_params.get('script_prepend')
> > or ''
> >              # remove escapes from $\{var\} that are needed to
> > avoid expansion by wic
> >              script_prepend = re.sub(r'\$\\{([^\\]+)\\}', r'${\1}',
> > script_prepend)
>

Patch

diff --git a/meta/recipes-bsp/u-boot-script/files/u-boot-script b/meta/recipes-bsp/u-boot-script/files/u-boot-script
index d053d721..a11212c0 100644
--- a/meta/recipes-bsp/u-boot-script/files/u-boot-script
+++ b/meta/recipes-bsp/u-boot-script/files/u-boot-script
@@ -15,3 +15,6 @@  NO_INITRD=""
 
 # U-boot commands to prepend to boot script
 SCRIPT_PREPEND=""
+
+# use u-boot builtin device tree
+BUILTIN_DT="no"
diff --git a/meta/recipes-bsp/u-boot-script/files/update-u-boot-script b/meta/recipes-bsp/u-boot-script/files/update-u-boot-script
index 1d9c6d45..2eb6097c 100755
--- a/meta/recipes-bsp/u-boot-script/files/update-u-boot-script
+++ b/meta/recipes-bsp/u-boot-script/files/update-u-boot-script
@@ -33,10 +33,18 @@  echo "${SCRIPT_PREPEND}" >> ${BOOT_CMD}
 
 echo "setenv bootargs ${KERNEL_ARGS}" >> ${BOOT_CMD}
 
-echo "echo Loading /usr/lib/linux-image-${KERNEL_VERSION}/\${fdtfile}..." \
-     >> ${BOOT_CMD}
-echo "load \${devtype} \${devnum}:${ROOT_PARTITION} \${fdt_addr_r}" \
-     "/usr/lib/linux-image-${KERNEL_VERSION}/\${fdtfile}" >> ${BOOT_CMD}
+if [ "${BUILTIN_DT}" = "yes" ]; then
+	echo "echo Loading builtin device tree..." \
+	     >> ${BOOT_CMD}
+	echo "fdt addr \${fdtcontroladdr}" >> ${BOOT_CMD}
+	echo "fdt move \${fdtcontroladdr} \${fdt_addr_r}" >> ${BOOT_CMD}
+else
+	echo "echo Loading /usr/lib/linux-image-${KERNEL_VERSION}/\${fdtfile}..." \
+	     >> ${BOOT_CMD}
+	echo "load \${devtype} \${devnum}:${ROOT_PARTITION} \${fdt_addr_r}" \
+	     "/usr/lib/linux-image-${KERNEL_VERSION}/\${fdtfile}" >> ${BOOT_CMD}
+fi
+
 echo "echo Loading /boot/${KERNEL_FILE}-${KERNEL_VERSION}..." >> ${BOOT_CMD}
 echo "load \${devtype} \${devnum}:\${distro_bootpart} \${kernel_addr_r}" \
      "/boot/${KERNEL_FILE}-${KERNEL_VERSION}" >> ${BOOT_CMD}
diff --git a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
index 0b4f9eec..93600dc2 100644
--- a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
+++ b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
@@ -10,6 +10,7 @@ 
 # Recognized sourceparams:
 #  - no_initrd=yes          (disables initrd loading)
 #  - overlays=file.dtbo ... (overlay files)
+#  - builtin_dt=no          (use DT from uboot instead of kernel)
 #  - script_prepend=cmd;... (prepends U-Boot command)
 
 import glob
@@ -82,6 +83,8 @@  class RootfsUBootPlugin(RootfsPlugin):
             cfg.write('NO_INITRD="%s"\n' % no_initrd)
             overlays = source_params.get('overlays') or ''
             cfg.write('OVERLAYS="%s"\n' % overlays)
+            builtin_dt = source_params.get('builtin_dt') or ''
+            cfg.write('BUILTIN_DT="%s"\n' % builtin_dt)
             script_prepend = source_params.get('script_prepend') or ''
             # remove escapes from $\{var\} that are needed to avoid expansion by wic
             script_prepend = re.sub(r'\$\\{([^\\]+)\\}', r'${\1}', script_prepend)