Skip to contentSkip to conversation

kernel-devicetree.bbclass: Add support to generate append to kernel

PATCH In review Otavio Salvador 3 participants 5 messages Sep 21, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v9 1/1 kernel-devicetree.bbclass: Add support to generate append to kernel

The are use cases where the Device Tree appended to the kernel is convinient, so we generate the bundle concatenating the kernel (and potentionally the initramfs) and the Device Tree binaries.

To enable it, set KERNEL_DEVICETREE_BUNDLE variable to '1'

---

Changes in v9:
- Rework to not use tasks
- Keep MIPS support addition for later

Changes in v8:
- rework append support to support ARM and MIPS (obi)

Changes in v7:
- simplified code
- rename bundle to use .bin extension

Changes in v5:
- add support for initramfs bundle

Changes in v4:
- new patch

 meta/classes/kernel-devicetree.bbclass | 52 +++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
meta/classes/kernel-devicetree.bbclass +51 -1
index 72814ca224..6e08be4b70 100644
@@ -1,6 +1,13 @@
 # Support for device tree generation
-PACKAGES_append = " kernel-devicetree"
+PACKAGES_append = " \
+    kernel-devicetree \
+    ${@['kernel-image-zimage-bundle', ''][d.getVar('KERNEL_DEVICETREE_BUNDLE') != '1']} \
+"
 FILES_kernel-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo"
+FILES_kernel-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin"
+
+# Generate kernel+devicetree bundle
+KERNEL_DEVICETREE_BUNDLE ?= "0"
 
 normalize_dtb () {
 	DTB="$1"
@@ -20,6 +27,28 @@ get_real_dtb_path_in_kernel () {
 	echo "${DTB_PATH}"
 }
 
+do_configure_append() {
+	if [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
+		if echo ${KERNEL_IMAGETYPE_FOR_MAKE} | grep -q 'zImage'; then
+			case "${ARCH}" in
+				"arm")
+				config="${B}/.config"
+				if ! grep -q 'CONFIG_ARM_APPENDED_DTB=y' $config; then
+					bbwarn 'CONFIG_ARM_APPENDED_DTB is NOT enabled in the kernel. Enabling it to allow the kernel to boot with the Device Tree appended!'
+					sed -i "/CONFIG_ARM_APPENDED_DTB[ =]/d" $config
+					echo "CONFIG_ARM_APPENDED_DTB=y" >> $config
+					echo "# CONFIG_ARM_ATAG_DTB_COMPAT is not set" >> $config
+				fi
+				;;
+				*)
+				bberror "KERNEL_DEVICETREE_BUNDLE is not supported for ${ARCH}. Currently it is only supported for 'ARM'."
+			esac
+		else
+			bberror 'The KERNEL_DEVICETREE_BUNDLE requires the KERNEL_IMAGETYPE to contain zImage.'
+		fi
+	fi
+}
+
 do_compile_append() {
 	for DTB in ${KERNEL_DEVICETREE}; do
 		DTB=`normalize_dtb "${DTB}"`
@@ -38,6 +67,12 @@ do_install_append() {
 			symlink_name=${type}"-"${KERNEL_IMAGE_SYMLINK_NAME}
 			DTB_SYMLINK_NAME=`echo ${symlink_name} | sed "s/${MACHINE}/${DTB_BASE_NAME}/g"`
 			ln -sf ${DTB_BASE_NAME}.${DTB_EXT} ${D}/${KERNEL_IMAGEDEST}/devicetree-${DTB_SYMLINK_NAME}.${DTB_EXT}
+
+			if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
+				cat ${D}/${KERNEL_IMAGEDEST}/$type \
+					${D}/${KERNEL_IMAGEDEST}/${DTB_BASE_NAME}.${DTB_EXT} \
+					> ${D}/${KERNEL_IMAGEDEST}/$type-${DTB_BASE_NAME}.${DTB_EXT}.bin
+			fi
 		done
 	done
 }
@@ -57,6 +92,21 @@ do_deploy_append() {
 			install -m 0644 ${DTB_PATH} ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT}
 			ln -sf ${DTB_NAME}.${DTB_EXT} ${DEPLOYDIR}/${DTB_SYMLINK_NAME}.${DTB_EXT}
 			ln -sf ${DTB_NAME}.${DTB_EXT} ${DEPLOYDIR}/${DTB_BASE_NAME}.${DTB_EXT}
+
+			if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
+				cat ${DEPLOYDIR}/$type \
+					${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT} \
+					> ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT}.bin
+				ln -sf ${DTB_NAME}.${DTB_EXT}.bin ${DEPLOYDIR}/$type-${DTB_BASE_NAME}.${DTB_EXT}.bin
+
+				if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then
+					cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \
+						${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT} \
+						> ${DEPLOYDIR}/${type}-${INITRAMFS_BASE_NAME}-${DTB_BASE_NAME}.${DTB_EXT}.bin
+					ln -sf ${type}-${INITRAMFS_BASE_NAME}-${DTB_BASE_NAME}.${DTB_EXT}.bin \
+					       ${DEPLOYDIR}/${type}-initramfs-${DTB_BASE_NAME}.${DTB_EXT}-${MACHINE}.bin
+				fi
+			fi
 		done
 	done
 }
Signature · 1 line
2.14.1
#1 lore raw
Quoted 7 lines · Otavio Salvador

The are use cases where the Device Tree appended to the kernel is convinient, so we generate the bundle concatenating the kernel (and potentionally the initramfs) and the Device Tree binaries.

To enable it, set KERNEL_DEVICETREE_BUNDLE variable to '1'

[snip]

meta/classes/kernel-devicetree.bbclass line 7

Quoted 13 lines
meta/classes/kernel-devicetree.bbclass +5 -1
index 72814ca224..6e08be4b70 100644
@@ -1,6 +1,13 @@
 # Support for device tree generation
-PACKAGES_append = " kernel-devicetree"
+PACKAGES_append = " \
+    kernel-devicetree \
+    ${@['kernel-image-zimage-bundle', ''][d.getVar('KERNEL_DEVICETREE_BUNDLE') != '1']} \
+"
 FILES_kernel-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo"
+FILES_kernel-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin"

Frankly, the most common use case today for still needing to concat the dtb to the zImage is for very legacy U-Boot where 'bootz' doesn't exist, so we need uImage (which is in turn why we need to patch the kernel build process, or manually run mkimage, it must be (zImage + dtb) + uImage-header).

Signature · 1 line
Tom
#2 lore raw
Quoted 21 lines · Tom Rini
Quoted 7 lines · Otavio Salvador

The are use cases where the Device Tree appended to the kernel is convinient, so we generate the bundle concatenating the kernel (and potentionally the initramfs) and the Device Tree binaries.

To enable it, set KERNEL_DEVICETREE_BUNDLE variable to '1'

[snip]

Quoted 11 lines
meta/classes/kernel-devicetree.bbclass +4 -1
index 72814ca224..6e08be4b70 100644
@@ -1,6 +1,13 @@
 # Support for device tree generation
-PACKAGES_append = " kernel-devicetree"
+PACKAGES_append = " \
+    kernel-devicetree \
+    ${@['kernel-image-zimage-bundle', ''][d.getVar('KERNEL_DEVICETREE_BUNDLE') != '1']} \
+"
Quoted 8 lines

meta/classes/kernel-devicetree.bbclass line 7

Quoted 2 lines
meta/classes/kernel-devicetree.bbclass +1 -0
 FILES_kernel-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo"
+FILES_kernel-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin"

Frankly, the most common use case today for still needing to concat the dtb to the zImage is for very legacy U-Boot where 'bootz' doesn't exist, so we need uImage (which is in turn why we need to patch the kernel build process, or manually run mkimage, it must be (zImage + dtb) + uImage-header).

There is also the use case of a single binary to boot. We use it in a customer project and we found it quite useful.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
#3 lore raw
Quoted 31 lines · Otavio Salvador
Quoted 21 lines · Tom Rini
Quoted 7 lines · Otavio Salvador

The are use cases where the Device Tree appended to the kernel is convinient, so we generate the bundle concatenating the kernel (and potentionally the initramfs) and the Device Tree binaries.

To enable it, set KERNEL_DEVICETREE_BUNDLE variable to '1'

[snip]

Quoted 11 lines
meta/classes/kernel-devicetree.bbclass +4 -1
index 72814ca224..6e08be4b70 100644
@@ -1,6 +1,13 @@
 # Support for device tree generation
-PACKAGES_append = " kernel-devicetree"
+PACKAGES_append = " \
+    kernel-devicetree \
+    ${@['kernel-image-zimage-bundle', ''][d.getVar('KERNEL_DEVICETREE_BUNDLE') != '1']} \
+"
Quoted 8 lines

meta/classes/kernel-devicetree.bbclass line 7

Quoted 2 lines
meta/classes/kernel-devicetree.bbclass +1 -0
 FILES_kernel-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo"
+FILES_kernel-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin"

Frankly, the most common use case today for still needing to concat the dtb to the zImage is for very legacy U-Boot where 'bootz' doesn't exist, so we need uImage (which is in turn why we need to patch the kernel build process, or manually run mkimage, it must be (zImage + dtb) + uImage-header).

Quoted 2 lines

There is also the use case of a single binary to boot. We use it in a customer project and we found it quite useful.

That's what FIT is for.

Signature · 1 line
Tom
#4 lore raw
Quoted 32 lines · Tom Rini
Quoted 31 lines · Otavio Salvador
Quoted 29 lines · Tom Rini
Quoted 7 lines · Otavio Salvador

The are use cases where the Device Tree appended to the kernel is convinient, so we generate the bundle concatenating the kernel (and potentionally the initramfs) and the Device Tree binaries.

To enable it, set KERNEL_DEVICETREE_BUNDLE variable to '1'

[snip]

meta/classes/kernel-devicetree.bbclass line 7

Quoted 13 lines
meta/classes/kernel-devicetree.bbclass +5 -1
index 72814ca224..6e08be4b70 100644
@@ -1,6 +1,13 @@
 # Support for device tree generation
-PACKAGES_append = " kernel-devicetree"
+PACKAGES_append = " \
+    kernel-devicetree \
+    ${@['kernel-image-zimage-bundle', ''][d.getVar('KERNEL_DEVICETREE_BUNDLE') != '1']} \
+"
 FILES_kernel-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo"
+FILES_kernel-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin"

Frankly, the most common use case today for still needing to concat the dtb to the zImage is for very legacy U-Boot where 'bootz' doesn't exist, so we need uImage (which is in turn why we need to patch the kernel build process, or manually run mkimage, it must be (zImage + dtb) + uImage-header).

Quoted 4 lines
Quoted 2 lines

There is also the use case of a single binary to boot. We use it in a customer project and we found it quite useful.

That's what FIT is for.

Without U-Boot.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750