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.

Signen-nff-by: Ming Liu <[email protected]>
---
 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

-- 
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Reply via email to