public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: isar-users <isar-users@googlegroups.com>
Subject: [PATCH 4/5] Add u-boot script generator
Date: Wed,  6 Jun 2018 13:58:51 +0200	[thread overview]
Message-ID: <7a07b823f595c4b49cb69f824436ff60efa98612.1528286332.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1528286332.git.jan.kiszka@siemens.com>
In-Reply-To: <cover.1528286332.git.jan.kiszka@siemens.com>

From: Jan Kiszka <jan.kiszka@siemens.com>

In order to use upstream U-Boot default envs for booting Isar images, we
either need an extlinux script - can be provided by Debian u-boot-menu
from buster - or some boot.scr. The latter has the advantage of skipping
the interactive stage of a kernel selection, specifically when there is
only one kernel on an image, and allowing for injection of custom U-Boot
commands.

This package generates the needed boot.scr, using the installed kernel
package and the rootfs parameters found in the target's /etc/fstab. It
is able to update itself when the kernel package is changed on the
target. Further kernel parameters and custom U-Boot commands can be
configured on the target via /etc/default/u-boot-script. This also
allows to opt-out from using an initramfs when the kernel does not need
one to boot properly.

Furthermore, the package recipe can evaluate and bootloader --append=...
line from the WKS_FILE used for the target and inject those kernel
parameters into the deployed /etc/default/u-boot-script.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 meta/recipes-bsp/u-boot-script/files/u-boot-script |  9 ++++
 .../u-boot-script/files/update-u-boot-script       | 58 ++++++++++++++++++++++
 .../u-boot-script/files/zz-u-boot-script           |  3 ++
 .../recipes-bsp/u-boot-script/u-boot-script_1.0.bb | 53 ++++++++++++++++++++
 4 files changed, 123 insertions(+)
 create mode 100644 meta/recipes-bsp/u-boot-script/files/u-boot-script
 create mode 100755 meta/recipes-bsp/u-boot-script/files/update-u-boot-script
 create mode 100755 meta/recipes-bsp/u-boot-script/files/zz-u-boot-script
 create mode 100644 meta/recipes-bsp/u-boot-script/u-boot-script_1.0.bb

diff --git a/meta/recipes-bsp/u-boot-script/files/u-boot-script b/meta/recipes-bsp/u-boot-script/files/u-boot-script
new file mode 100644
index 0000000..53cc613
--- /dev/null
+++ b/meta/recipes-bsp/u-boot-script/files/u-boot-script
@@ -0,0 +1,9 @@
+# Arguments to append to kernel command line.
+# Make sure to escape $ in u-boot variables, e.g. "\${console}".
+KERNEL_ARGS_APPEND=""
+
+# Set to "yes" or "1" to leave out initrd, even if present
+NO_INITRD=""
+
+# U-boot commands to prepend to boot script
+SCRIPT_PREPEND=""
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
new file mode 100755
index 0000000..4ce74bb
--- /dev/null
+++ b/meta/recipes-bsp/u-boot-script/files/update-u-boot-script
@@ -0,0 +1,58 @@
+#!/bin/sh
+#
+# Boot script generator for U-Boot
+#
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2018
+#
+# SPDX-License-Identifier: MIT
+
+set -e
+
+if [ -f /etc/default/u-boot-script ]; then
+	. /etc/default/u-boot-script
+fi
+
+ROOT_PART="\${distro_bootpart}"
+
+while read DEV MOUNT_POINT REST; do
+	if echo ${DEV} | grep -q "^#"; then
+		continue
+	fi
+	if [ "${MOUNT_POINT}" = "/" ]; then
+		ROOT_DEV=${DEV}
+		ROOT_PART=$(echo ${DEV} | sed 's/.*[^0-9]\([0-9]*\)$/\1/')
+	fi
+done < /etc/fstab
+
+BOOT_CMD=$(mktemp)
+
+KERNEL_VERSION=$(linux-version list | linux-version sort --reverse | head -1)
+
+echo "${SCRIPT_PREPEND}" >> ${BOOT_CMD}
+
+echo "setenv bootargs root=${ROOT_DEV} ${KERNEL_ARGS_APPEND}" >> ${BOOT_CMD}
+
+echo "load \${devtype} \${devnum}:${ROOT_PART} \${fdt_addr_r}" \
+     "/usr/lib/linux-image-${KERNEL_VERSION}/\${fdtfile}" >> ${BOOT_CMD}
+echo "load \${devtype} \${devnum}:\${distro_bootpart} \${kernel_addr_r}" \
+     "/boot/vmlinuz-${KERNEL_VERSION}" >> ${BOOT_CMD}
+
+case "${NO_INITRD}" in
+yes|1)
+	INITRD_ADDR="-"
+	;;
+*)
+	RAMDISK_SIZE=$(printf %x \
+		$(stat -c %s /boot/initrd.img-${KERNEL_VERSION}))
+	echo "load \${devtype} \${devnum}:\${distro_bootpart}" \
+	     "\${ramdisk_addr_r} /boot/initrd.img-${KERNEL_VERSION}" \
+	     >> ${BOOT_CMD}
+	INITRD_ADDR="\${ramdisk_addr_r}:${RAMDISK_SIZE}"
+esac
+
+echo "bootz \${kernel_addr_r} ${INITRD_ADDR} \${fdt_addr_r}" >> ${BOOT_CMD}
+
+mkimage -T script -A invalid -C none -d ${BOOT_CMD} /boot/boot.scr > /dev/null
+
+rm ${BOOT_CMD}
diff --git a/meta/recipes-bsp/u-boot-script/files/zz-u-boot-script b/meta/recipes-bsp/u-boot-script/files/zz-u-boot-script
new file mode 100755
index 0000000..cf4cc5a
--- /dev/null
+++ b/meta/recipes-bsp/u-boot-script/files/zz-u-boot-script
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+update-u-boot-script
diff --git a/meta/recipes-bsp/u-boot-script/u-boot-script_1.0.bb b/meta/recipes-bsp/u-boot-script/u-boot-script_1.0.bb
new file mode 100644
index 0000000..490c306
--- /dev/null
+++ b/meta/recipes-bsp/u-boot-script/u-boot-script_1.0.bb
@@ -0,0 +1,53 @@
+# Boot script generator for U-Boot
+#
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2018
+#
+# SPDX-License-Identifier: MIT
+
+inherit dpkg-raw
+
+DESCRIPTION = "Boot script generator for U-Boot"
+
+SRC_URI = " \
+    file://update-u-boot-script \
+    file://u-boot-script \
+    file://zz-u-boot-script"
+
+DEBIAN_DEPENDS = "u-boot-tools, linux-image-${KERNEL_NAME}"
+
+do_install() {
+	# Find WKS_FILE specified for the current target.
+	WKS_DIRS=$(dirname $(which wic))/lib/wic/canned-wks
+	for LAYER in ${BBLAYERS}; do
+		WKS_DIRS="${WKS_DIRS} ${LAYER}/scripts/lib/wic/canned-wks"
+	done
+	for DIR in ${WKS_DIRS}; do
+		if [ -f ${DIR}/${WKS_FILE}.wks ]; then
+			WKS_PATH=${DIR}/${WKS_FILE}.wks
+			break
+		fi
+	done
+
+	# Transfer --append parameters from a bootloader entry in the wks file
+	# to the packaged /etc/default/u-boot-script.
+	if [ -n ${WKS_PATH} ]; then
+		APPEND=$(grep "^bootloader " ${WKS_PATH} | \
+			 sed 's/.* --append=\([^ $]*\).*/\1/')
+		sed -i 's|\(^KERNEL_ARGS_APPEND=\).*|\1'${APPEND}'|' \
+			${WORKDIR}/u-boot-script
+	fi
+
+	sudo rm -rf ${D}/etc ${D}/usr
+
+	install -v -d ${D}/usr/sbin
+	install -v -m 755 ${WORKDIR}/update-u-boot-script ${D}/usr/sbin/
+
+	install -v -d ${D}/etc/default
+	install -v -m 644 ${WORKDIR}/u-boot-script ${D}/etc/default/
+
+	install -v -d ${D}/etc/kernel/postinst.d
+	install -v -m 755 ${WORKDIR}/zz-u-boot-script ${D}/etc/kernel/postinst.d
+
+	sudo chown -R root:root ${D}/etc ${D}/usr
+}
-- 
2.13.7


  parent reply	other threads:[~2018-06-06 11:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-06 11:58 [PATCH 0/5] Enable U-Boot-based images, add Banana Pi demo Jan Kiszka
2018-06-06 11:58 ` [PATCH 1/5] Add DISTRO and DISTRO_ARCH as OVERRIDES suffixes Jan Kiszka
2018-06-06 11:58 ` [PATCH 2/5] buildchroot: Break up wic build deps into common and arch-specific ones Jan Kiszka
2018-06-06 11:58 ` [PATCH 3/5] Set up target image fstab prior to installing any packages Jan Kiszka
2018-06-07  6:38   ` Claudius Heine
2018-06-06 11:58 ` Jan Kiszka [this message]
2018-06-06 18:31   ` [PATCH 4/5] Add u-boot script generator Jan Kiszka
2018-06-06 18:48   ` Jan Kiszka
2018-06-06 11:58 ` [PATCH 5/5] Add Banana Pi SD-card image Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7a07b823f595c4b49cb69f824436ff60efa98612.1528286332.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox