Skip to contentSkip to conversation

support initramfs/devicetree bundle for uImage

PATCH New [email protected] 1 participant 5 messages May 15, 2018

lore
Share & tools
lore
#0 lore raw

cover support initramfs/devicetree bundle for uImage

From: Ming Liu <[email protected]>

Ming Liu (4):
kernel-uimage.bbclass: use boolean to check KEEPUIMAGE kernel.bbclass: make bundle_initramfs to be more flexible kernel-uimage.bbclass: support initramfs bundle kernel-uimage.bbclass: support devicetree bundle

 meta/classes/kernel-devicetree-common.bbclass | 21 ++++++++
 meta/classes/kernel-devicetree.bbclass        | 29 +++-------
 meta/classes/kernel-uimage.bbclass            | 78 +++++++++++++++++++++++----
 meta/classes/kernel.bbclass                   | 74 ++++++++++++++-----------
 4 files changed, 138 insertions(+), 64 deletions(-)
 create mode 100644 meta/classes/kernel-devicetree-common.bbclass
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 kernel-uimage.bbclass: use boolean to check KEEPUIMAGE

From: Ming Liu <[email protected]>

It now accepts yes/on/true/1 as positive values.

---
 meta/classes/kernel-uimage.bbclass | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
meta/classes/kernel-uimage.bbclass +3 -3
index 1d8656e..d3d9d77 100644
@@ -9,9 +9,9 @@ python __anonymous () {
         # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal
         # to kernel.bbclass . We override the variable here, since we need
         # to build uImage using the kernel build system if and only if
-        # KEEPUIMAGE == yes. Otherwise, we pack compressed vmlinux into
-        # the uImage .
-        if d.getVar("KEEPUIMAGE") != 'yes':
+        # KEEPUIMAGE == yes|1|true|on. Otherwise, we pack compressed vmlinux
+        # into the uImage .
+        if not oe.types.boolean(d.getVar("KEEPUIMAGE")):
             typeformake = d.getVar("KERNEL_IMAGETYPE_FOR_MAKE") or ""
             if "uImage" in typeformake.split():
                 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', typeformake.replace('uImage', 'vmlinux'))
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/4 kernel.bbclass: make bundle_initramfs to be more flexible

In reply to [email protected]

From: Ming Liu <[email protected]>

Introduce three new variables:
- INITRAMFS_IMAGE_BUNDLE_PREPROCESS_COMMANDS: the command list to be executed before re-compiling kernel with initramfs.
- INITRAMFS_IMAGE_BUNDLE_POSTPROCESS_COMMANDS: the command list to be executed after re-compiling kernel with initramfs.
- KERNEL_IMAGETYPE_BACKUP_UIMAGE: the backup uimage that need to be stored before re-compiling kernel with initramfs.

The main purpose for introducing the above variables is to make bundle_initramfs to be able to be extended by other bbclasses, there is no functional changes.

For instance, while KEEPUIMAGE is set to 'no', currently there is no way to bundle initramfs to kernel for uImage. With this change, we can achieve that by setting INITRAMFS_IMAGE_BUNDLE_POSTPROCESS_COMMANDS and KERNEL_IMAGETYPE_BACKUP_UIMAGE in kernel-uimage.bbclass.

---
 meta/classes/kernel.bbclass | 74 +++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 30 deletions(-)
meta/classes/kernel.bbclass +44 -30
index 6595a04..6a2f033 100644
@@ -184,8 +184,14 @@ KERNEL_EXTRA_ARGS ?= ""
 EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}""
 KERNEL_ALT_IMAGETYPE ??= ""
 
+INITRAMFS_BASE_NAME ?= "initramfs-${PV}-${PR}-${MACHINE}-${DATETIME}"
+INITRAMFS_BASE_NAME[vardepsexclude] = "DATETIME"
+
+INITRAMFS_IMAGE_BUNDLE_PREPROCESS_COMMANDS ?= "copy_initramfs; backup_kernel_images;"
+INITRAMFS_IMAGE_BUNDLE_POSTPROCESS_COMMANDS ?= "restore_kernel_images;"
+
 copy_initramfs() {
-	echo "Copying initramfs into ./usr ..."
+	echo "Creating a kernel image with a bundled initramfs by copying initramfs into ./usr ..."
 	# In case the directory is not created yet from the first pass compile:
 	mkdir -p ${B}/usr
 	# Find and use the first initramfs image archive type we find
@@ -225,42 +231,50 @@ copy_initramfs() {
 	echo "Finished copy of initramfs into ./usr"
 }
 
+backup_kernel_images() {
+	# Backing up kernel image relies on its type(regular file or symbolic link)
+	tmp_path=""
+	for type in ${KERNEL_IMAGETYPE_FOR_MAKE} ${KERNEL_IMAGETYPE_BACKUP_UIMAGE}; do
+		if [ -h ${KERNEL_OUTPUT_DIR}/$type ] ; then
+			linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$type`
+			realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$type`
+			mv -f $realpath $realpath.bak
+			tmp_path=$tmp_path" "$type"#"$linkpath"#"$realpath
+		elif [ -f ${KERNEL_OUTPUT_DIR}/$type ]; then
+			mv -f ${KERNEL_OUTPUT_DIR}/$type ${KERNEL_OUTPUT_DIR}/$type.bak
+			tmp_path=$tmp_path" "$type"##"
+		fi
+	done
+}
+
+restore_kernel_images() {
+	# Restoring kernel image
+	for tp in $tmp_path ; do
+		type=`echo $tp|cut -d "#" -f 1`
+		linkpath=`echo $tp|cut -d "#" -f 2`
+		realpath=`echo $tp|cut -d "#" -f 3`
+		if [ -n "$realpath" ]; then
+			mv -f $realpath $realpath.initramfs
+			mv -f $realpath.bak $realpath
+			ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$type.initramfs
+		else
+			mv -f ${KERNEL_OUTPUT_DIR}/$type ${KERNEL_OUTPUT_DIR}/$type.initramfs
+			mv -f ${KERNEL_OUTPUT_DIR}/$type.bak ${KERNEL_OUTPUT_DIR}/$type
+		fi
+	done
+}
+
 INITRAMFS_BASE_NAME ?= "initramfs-${PV}-${PR}-${MACHINE}-${DATETIME}"
 INITRAMFS_BASE_NAME[vardepsexclude] = "DATETIME"
 do_bundle_initramfs () {
+	${INITRAMFS_IMAGE_BUNDLE_PREPROCESS_COMMANDS}
+
 	if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
-		echo "Creating a kernel image with a bundled initramfs..."
-		copy_initramfs
-		# Backing up kernel image relies on its type(regular file or symbolic link)
-		tmp_path=""
-		for type in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
-			if [ -h ${KERNEL_OUTPUT_DIR}/$type ] ; then
-				linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$type`
-				realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$type`
-				mv -f $realpath $realpath.bak
-				tmp_path=$tmp_path" "$type"#"$linkpath"#"$realpath
-			elif [ -f ${KERNEL_OUTPUT_DIR}/$type ]; then
-				mv -f ${KERNEL_OUTPUT_DIR}/$type ${KERNEL_OUTPUT_DIR}/$type.bak
-				tmp_path=$tmp_path" "$type"##"
-			fi
-		done
 		use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
 		kernel_do_compile
-		# Restoring kernel image
-		for tp in $tmp_path ; do
-			type=`echo $tp|cut -d "#" -f 1`
-			linkpath=`echo $tp|cut -d "#" -f 2`
-			realpath=`echo $tp|cut -d "#" -f 3`
-			if [ -n "$realpath" ]; then
-				mv -f $realpath $realpath.initramfs
-				mv -f $realpath.bak $realpath
-				ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$type.initramfs
-			else
-				mv -f ${KERNEL_OUTPUT_DIR}/$type ${KERNEL_OUTPUT_DIR}/$type.initramfs
-				mv -f ${KERNEL_OUTPUT_DIR}/$type.bak ${KERNEL_OUTPUT_DIR}/$type
-			fi
-		done
 	fi
+
+	${INITRAMFS_IMAGE_BUNDLE_POSTPROCESS_COMMANDS}
 }
 do_bundle_initramfs[dirs] = "${B}"
 
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/4 kernel-uimage.bbclass: support initramfs bundle

In reply to [email protected]

From: Ming Liu <[email protected]>

Add do_uboot_mkimage to INITRAMFS_IMAGE_BUNDLE_POSTPROCESS_COMMANDS, and add uImage to KERNEL_IMAGETYPE_BACKUP_UIMAGE to support initramfs bundle when KEEPUIMAGE is set negative.

---
 meta/classes/kernel-uimage.bbclass | 4 ++++
 1 file changed, 4 insertions(+)
meta/classes/kernel-uimage.bbclass +4 -0
index d3d9d77..4bd6c7b 100644
@@ -18,6 +18,10 @@ python __anonymous () {
 
             # Enable building of uImage with mkimage
             bb.build.addtask('do_uboot_mkimage', 'do_install', 'do_kernel_link_images', d)
+
+            # Handle uImage initramfs bundle
+            d.prependVar('INITRAMFS_IMAGE_BUNDLE_POSTPROCESS_COMMANDS', 'do_uboot_mkimage; ')
+            d.setVar('KERNEL_IMAGETYPE_BACKUP_UIMAGE', 'uImage')
 }
 
 do_uboot_mkimage[dirs] += "${B}"
Signature · 1 line
2.7.4
#4 lore raw

PATCH 4/4 kernel-uimage.bbclass: support devicetree bundle

In reply to [email protected]

From: Ming Liu <[email protected]>

This patch mainly aims to support devicetree bundle for uImage, when KEEPUIMAGE is set negative, by appending some code to kernel_do_install and kernel_do_deploy to check KERNEL_DEVICETREE_BUNDLE and call uboot-mkimage to regenerate the devicetree bundled image if it's set.

Some common code is moved to kernel-devicetree-common.bbclass as well since they are being referred now in both kernel-devicetree.bbclass and kernel-uimage.bbclass.

---
 meta/classes/kernel-devicetree-common.bbclass | 21 +++++++++
 meta/classes/kernel-devicetree.bbclass        | 29 +++---------
 meta/classes/kernel-uimage.bbclass            | 68 +++++++++++++++++++++++----
 3 files changed, 87 insertions(+), 31 deletions(-)
 create mode 100644 meta/classes/kernel-devicetree-common.bbclass
meta/classes/kernel-devicetree-common.bbclass new file +21 -0
new file mode 100644
index 0000000..2216533
@@ -0,0 +1,21 @@
+
+# Generate kernel+devicetree bundle
+KERNEL_DEVICETREE_BUNDLE ?= "0"
+
+normalize_dtb () {
+	DTB="$1"
+	if echo ${DTB} | grep -q '/dts/'; then
+		bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
+		DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
+	fi
+	echo "${DTB}"
+}
+
+get_real_dtb_path_in_kernel () {
+	DTB="$1"
+	DTB_PATH="${B}/arch/${ARCH}/boot/dts/${DTB}"
+	if [ ! -e "${DTB_PATH}" ]; then
+		DTB_PATH="${B}/arch/${ARCH}/boot/${DTB}"
+	fi
+	echo "${DTB_PATH}"
+}
meta/classes/kernel-devicetree.bbclass +6 -23
index 4f80cc6..00c6210 100644
@@ -1,31 +1,14 @@
 # Support for device tree generation
+inherit kernel-devicetree-common
+
 PACKAGES_append = " \
     ${KERNEL_PACKAGE_NAME}-devicetree \
     ${@[d.getVar('KERNEL_PACKAGE_NAME') + '-image-zimage-bundle', ''][d.getVar('KERNEL_DEVICETREE_BUNDLE') != '1']} \
+    ${@[d.getVar('KERNEL_PACKAGE_NAME') + '-image-uimage-bundle', ''][d.getVar('KERNEL_DEVICETREE_BUNDLE') != '1']} \
 "
 FILES_${KERNEL_PACKAGE_NAME}-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo"
 FILES_${KERNEL_PACKAGE_NAME}-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin"
-
-# Generate kernel+devicetree bundle
-KERNEL_DEVICETREE_BUNDLE ?= "0"
-
-normalize_dtb () {
-	DTB="$1"
-	if echo ${DTB} | grep -q '/dts/'; then
-		bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used."
-		DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'`
-	fi
-	echo "${DTB}"
-}
-
-get_real_dtb_path_in_kernel () {
-	DTB="$1"
-	DTB_PATH="${B}/arch/${ARCH}/boot/dts/${DTB}"
-	if [ ! -e "${DTB_PATH}" ]; then
-		DTB_PATH="${B}/arch/${ARCH}/boot/${DTB}"
-	fi
-	echo "${DTB_PATH}"
-}
+FILES_${KERNEL_PACKAGE_NAME}-image-uimage-bundle = "/${KERNEL_IMAGEDEST}/uImage-*.dtb.bin"
 
 do_configure_append() {
 	if [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
@@ -69,7 +52,7 @@ do_install_append() {
 			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 \
+				cat ${KERNEL_OUTPUT_DIR}/$type \
 					${D}/${KERNEL_IMAGEDEST}/${DTB_BASE_NAME}.${DTB_EXT} \
 					> ${D}/${KERNEL_IMAGEDEST}/$type-${DTB_BASE_NAME}.${DTB_EXT}.bin
 			fi
@@ -94,7 +77,7 @@ do_deploy_append() {
 			ln -sf ${DTB_NAME}.${DTB_EXT} ${DEPLOYDIR}/${DTB_BASE_NAME}.${DTB_EXT}
 
 			if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
-				cat ${DEPLOYDIR}/$type \
+				cat ${KERNEL_OUTPUT_DIR}/$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
meta/classes/kernel-uimage.bbclass +60 -8

87 lines not on this page · raw message

Signature · 1 line
2.7.4