From 849b67b2e4820564b5e5c9bd4bb293c44351c5f3 Mon Sep 17 00:00:00 2001 From: He Zhe Date: Wed, 25 May 2016 04:47:16 -0400 Subject: kernel: Add KERNEL_IMAGETYPES to build multi types kernel at one time Add KERNEL_IMAGETYPES to support building packaging and installing multi types of kernel images, such as zImage uImage, at one time. KERNEL_IMAGETYPE and KERNEL_ALT_IMAGETYPE work as before. Signed-off-by: He Zhe Signed-off-by: Ross Burton --- meta/classes/kernel-grub.bbclass | 44 ++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'meta/classes/kernel-grub.bbclass') diff --git a/meta/classes/kernel-grub.bbclass b/meta/classes/kernel-grub.bbclass index a63f482a91..f7dcc0715a 100644 --- a/meta/classes/kernel-grub.bbclass +++ b/meta/classes/kernel-grub.bbclass @@ -10,41 +10,44 @@ # updates the new kernel as the boot priority. # -pkg_preinst_kernel-image_append () { +python __anonymous () { + import re + + preinst = ''' # Parsing confliction [ -f "$D/boot/grub/menu.list" ] && grubcfg="$D/boot/grub/menu.list" [ -f "$D/boot/grub/grub.cfg" ] && grubcfg="$D/boot/grub/grub.cfg" if [ -n "$grubcfg" ]; then # Dereference symlink to avoid confliction with new kernel name. - if grep -q "/${KERNEL_IMAGETYPE} \+root=" $grubcfg; then - if [ -L "$D/boot/${KERNEL_IMAGETYPE}" ]; then - kimage=`realpath $D/boot/${KERNEL_IMAGETYPE} 2>/dev/null` + if grep -q "/KERNEL_IMAGETYPE \+root=" $grubcfg; then + if [ -L "$D/boot/KERNEL_IMAGETYPE" ]; then + kimage=`realpath $D/boot/KERNEL_IMAGETYPE 2>/dev/null` if [ -f "$D$kimage" ]; then - sed -i "s:${KERNEL_IMAGETYPE} \+root=:${kimage##*/} root=:" $grubcfg + sed -i "s:KERNEL_IMAGETYPE \+root=:${kimage##*/} root=:" $grubcfg fi fi fi # Rename old kernel if it conflicts with new kernel name. - if grep -q "/${KERNEL_IMAGETYPE}-${KERNEL_VERSION} \+root=" $grubcfg; then - if [ -f "$D/boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}" ]; then + if grep -q "/KERNEL_IMAGETYPE-${KERNEL_VERSION} \+root=" $grubcfg; then + if [ -f "$D/boot/KERNEL_IMAGETYPE-${KERNEL_VERSION}" ]; then timestamp=`date +%s` - kimage="$D/boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}-$timestamp-back" - sed -i "s:${KERNEL_IMAGETYPE}-${KERNEL_VERSION} \+root=:${kimage##*/} root=:" $grubcfg - mv "$D/boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}" "$kimage" + kimage="$D/boot/KERNEL_IMAGETYPE-${KERNEL_VERSION}-$timestamp-back" + sed -i "s:KERNEL_IMAGETYPE-${KERNEL_VERSION} \+root=:${kimage##*/} root=:" $grubcfg + mv "$D/boot/KERNEL_IMAGETYPE-${KERNEL_VERSION}" "$kimage" fi fi fi -} +''' -pkg_postinst_kernel-image_prepend () { + postinst = ''' get_new_grub_cfg() { grubcfg="$1" old_image="$2" - title="Update ${KERNEL_IMAGETYPE}-${KERNEL_VERSION}-${PV}" + title="Update KERNEL_IMAGETYPE-${KERNEL_VERSION}-${PV}" if [ "${grubcfg##*/}" = "grub.cfg" ]; then rootfs=`grep " *linux \+[^ ]\+ \+root=" $grubcfg -m 1 | \ - sed "s#${old_image}#${old_image%/*}/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}#"` + sed "s#${old_image}#${old_image%/*}/KERNEL_IMAGETYPE-${KERNEL_VERSION}#"` echo "menuentry \"$title\" {" echo " set root=(hd0,1)" @@ -52,7 +55,7 @@ pkg_postinst_kernel-image_prepend () { echo "}" elif [ "${grubcfg##*/}" = "menu.list" ]; then rootfs=`grep "kernel \+[^ ]\+ \+root=" $grubcfg -m 1 | \ - sed "s#${old_image}#${old_image%/*}/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}#"` + sed "s#${old_image}#${old_image%/*}/KERNEL_IMAGETYPE-${KERNEL_VERSION}#"` echo "default 0" echo "timeout 30" @@ -87,5 +90,16 @@ pkg_postinst_kernel-image_prepend () { mv $grubcfgtmp $grubcfg echo "Caution! Update kernel may affect kernel-module!" fi +''' + + imagetypes = d.getVar('KERNEL_IMAGETYPES', True) + imagetypes = re.sub(r'\.gz$', '', imagetypes) + + for type in imagetypes.split(): + typelower = type.lower() + preinst_append = preinst.replace('KERNEL_IMAGETYPE', type) + postinst_prepend = postinst.replace('KERNEL_IMAGETYPE', type) + d.setVar('pkg_preinst_kernel-image-' + typelower + '_append', preinst_append) + d.setVar('pkg_postinst_kernel-image-' + typelower + '_prepend', postinst_prepend) } -- cgit 1.2.3-korg