public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] u-boot-script: Add support for device tree overlays
@ 2018-12-09  9:00 Jan Kiszka
  2018-12-11  8:11 ` Maxim Yu. Osipov
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kiszka @ 2018-12-09  9:00 UTC (permalink / raw)
  To: isar-users

This adds support to the u-boot script for loading device tree overlay
files into the main dtb before the kernel boots. The user just needs to
specify the files in the OVERLAYS variable in /etc/default/u-boot-script
or provide this information via sourceparams 'overlays' to
rootfs-u-boot.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

Developed for / tested against the AM65x (their downstream kernel uses
this). If someone knows a good test case for our in-tree targets, we
should add that. Maybe something for an RasPi?

 meta/recipes-bsp/u-boot-script/files/u-boot-script       |  5 +++++
 .../recipes-bsp/u-boot-script/files/update-u-boot-script | 16 ++++++++++++++++
 meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py     |  3 +++
 3 files changed, 24 insertions(+)

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 ca31b6d..d053d72 100644
--- a/meta/recipes-bsp/u-boot-script/files/u-boot-script
+++ b/meta/recipes-bsp/u-boot-script/files/u-boot-script
@@ -5,6 +5,11 @@ ROOT_PARTITION="\${distro_bootpart}"
 # Make sure to escape $ in u-boot variables, e.g. "\${console}".
 KERNEL_ARGS=""
 
+# Space-separated list of device tree overlay files.
+# Can be absolute paths in root filesystem or relative ones under
+# /usr/lib/linux-image-<KERNEL_VERSION>
+OVERLAYS=""
+
 # Set to "yes" or "1" to leave out initrd, even if present
 NO_INITRD=""
 
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 c613b13..d006a23 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
@@ -37,6 +37,22 @@ yes|1)
 	INITRD_ADDR="\${ramdisk_addr_r}:\${filesize}"
 esac
 
+if [ -n "${OVERLAYS}" ]; then
+	echo "fdt addr \${fdt_addr_r}" >> ${BOOT_CMD}
+	# grant 1 MB to combined device tree
+	echo "fdt resize 0x100000" >> ${BOOT_CMD}
+	echo "setexpr overlay_addr_r \${fdt_addr_r} + 0x100000" >> ${BOOT_CMD}
+	for OVERLAY in ${OVERLAYS}; do
+		if ! echo $OVERLAY | grep -q "^/"; then
+			OVERLAY_PATH=/usr/lib/linux-image-${KERNEL_VERSION}/
+		fi
+		echo "load \${devtype} \${devnum}:${ROOT_PARTITION}" \
+		     "\${overlay_addr_r} ${OVERLAY_PATH}${OVERLAY}" \
+		     >> ${BOOT_CMD}
+		echo "fdt apply \${overlay_addr_r}" >> ${BOOT_CMD}
+	done
+fi
+
 BOOT="bootz"
 if [ "$(uname -m)" = "aarch64" ]; then
 	BOOT="booti"
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 0c7710e..37baea9 100644
--- a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
+++ b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
@@ -9,6 +9,7 @@
 # u-boot-script to boot this rootfs.
 # Recognized sourceparams:
 #  - no_initrd=yes          (disables initrd loading)
+#  - overlays=file.dtbo ... (overlay files)
 #  - script_prepend=cmd;... (prepends U-Boot command)
 
 import glob
@@ -71,6 +72,8 @@ class RootfsUBootPlugin(RootfsPlugin):
                 (cr.rootdev, cr.ks.bootloader.append))
             no_initrd = source_params.get('no_initrd') or ''
             cfg.write('NO_INITRD="%s"\n' % no_initrd)
+            overlays = source_params.get('overlays') or ''
+            cfg.write('OVERLAYS="%s"\n' % overlays)
             script_prepend = source_params.get('script_prepend') or ''
             cfg.write('SCRIPT_PREPEND="%s"\n' % script_prepend)
 
-- 
2.16.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-12-11  8:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-09  9:00 [PATCH] u-boot-script: Add support for device tree overlays Jan Kiszka
2018-12-11  8:11 ` Maxim Yu. Osipov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox