All of lore.kernel.org
 help / color / mirror / Atom feed
From: liu.ming50@gmail.com
To: openembedded-core@lists.openembedded.org
Cc: Ming Liu <liu.ming50@gmail.com>
Subject: [PATCH 2/4] kernel.bbclass: make bundle_initramfs to be more flexible
Date: Tue, 15 May 2018 08:11:09 +0200	[thread overview]
Message-ID: <1526364671-29451-3-git-send-email-liu.ming50@gmail.com> (raw)
In-Reply-To: <1526364671-29451-1-git-send-email-liu.ming50@gmail.com>

From: Ming Liu <liu.ming50@gmail.com>

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.

Signen-nff-by: Ming Liu <liu.ming50@gmail.com>
---
 meta/classes/kernel.bbclass | 74 +++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 30 deletions(-)

diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
index 6595a04..6a2f033 100644
--- a/meta/classes/kernel.bbclass
+++ b/meta/classes/kernel.bbclass
@@ -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}"
 
-- 
2.7.4



  parent reply	other threads:[~2018-05-15  6:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-15  6:11 [PATCH 0/4] support initramfs/devicetree bundle for uImage liu.ming50
2018-05-15  6:11 ` [PATCH 1/4] kernel-uimage.bbclass: use boolean to check KEEPUIMAGE liu.ming50
2018-05-15  6:11 ` liu.ming50 [this message]
2018-05-15  6:11 ` [PATCH 3/4] kernel-uimage.bbclass: support initramfs bundle liu.ming50
2018-05-15  6:11 ` [PATCH 4/4] kernel-uimage.bbclass: support devicetree bundle liu.ming50

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=1526364671-29451-3-git-send-email-liu.ming50@gmail.com \
    --to=liu.ming50@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.