summaryrefslogtreecommitdiffstats
path: root/meta/classes/kernel-grub.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/kernel-grub.bbclass')
-rw-r--r--meta/classes/kernel-grub.bbclass44
1 files changed, 29 insertions, 15 deletions
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 @@
10# updates the new kernel as the boot priority. 10# updates the new kernel as the boot priority.
11# 11#
12 12
13pkg_preinst_kernel-image_append () { 13python __anonymous () {
14 import re
15
16 preinst = '''
14 # Parsing confliction 17 # Parsing confliction
15 [ -f "$D/boot/grub/menu.list" ] && grubcfg="$D/boot/grub/menu.list" 18 [ -f "$D/boot/grub/menu.list" ] && grubcfg="$D/boot/grub/menu.list"
16 [ -f "$D/boot/grub/grub.cfg" ] && grubcfg="$D/boot/grub/grub.cfg" 19 [ -f "$D/boot/grub/grub.cfg" ] && grubcfg="$D/boot/grub/grub.cfg"
17 if [ -n "$grubcfg" ]; then 20 if [ -n "$grubcfg" ]; then
18 # Dereference symlink to avoid confliction with new kernel name. 21 # Dereference symlink to avoid confliction with new kernel name.
19 if grep -q "/${KERNEL_IMAGETYPE} \+root=" $grubcfg; then 22 if grep -q "/KERNEL_IMAGETYPE \+root=" $grubcfg; then
20 if [ -L "$D/boot/${KERNEL_IMAGETYPE}" ]; then 23 if [ -L "$D/boot/KERNEL_IMAGETYPE" ]; then
21 kimage=`realpath $D/boot/${KERNEL_IMAGETYPE} 2>/dev/null` 24 kimage=`realpath $D/boot/KERNEL_IMAGETYPE 2>/dev/null`
22 if [ -f "$D$kimage" ]; then 25 if [ -f "$D$kimage" ]; then
23 sed -i "s:${KERNEL_IMAGETYPE} \+root=:${kimage##*/} root=:" $grubcfg 26 sed -i "s:KERNEL_IMAGETYPE \+root=:${kimage##*/} root=:" $grubcfg
24 fi 27 fi
25 fi 28 fi
26 fi 29 fi
27 30
28 # Rename old kernel if it conflicts with new kernel name. 31 # Rename old kernel if it conflicts with new kernel name.
29 if grep -q "/${KERNEL_IMAGETYPE}-${KERNEL_VERSION} \+root=" $grubcfg; then 32 if grep -q "/KERNEL_IMAGETYPE-${KERNEL_VERSION} \+root=" $grubcfg; then
30 if [ -f "$D/boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}" ]; then 33 if [ -f "$D/boot/KERNEL_IMAGETYPE-${KERNEL_VERSION}" ]; then
31 timestamp=`date +%s` 34 timestamp=`date +%s`
32 kimage="$D/boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}-$timestamp-back" 35 kimage="$D/boot/KERNEL_IMAGETYPE-${KERNEL_VERSION}-$timestamp-back"
33 sed -i "s:${KERNEL_IMAGETYPE}-${KERNEL_VERSION} \+root=:${kimage##*/} root=:" $grubcfg 36 sed -i "s:KERNEL_IMAGETYPE-${KERNEL_VERSION} \+root=:${kimage##*/} root=:" $grubcfg
34 mv "$D/boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}" "$kimage" 37 mv "$D/boot/KERNEL_IMAGETYPE-${KERNEL_VERSION}" "$kimage"
35 fi 38 fi
36 fi 39 fi
37 fi 40 fi
38} 41'''
39 42
40pkg_postinst_kernel-image_prepend () { 43 postinst = '''
41 get_new_grub_cfg() { 44 get_new_grub_cfg() {
42 grubcfg="$1" 45 grubcfg="$1"
43 old_image="$2" 46 old_image="$2"
44 title="Update ${KERNEL_IMAGETYPE}-${KERNEL_VERSION}-${PV}" 47 title="Update KERNEL_IMAGETYPE-${KERNEL_VERSION}-${PV}"
45 if [ "${grubcfg##*/}" = "grub.cfg" ]; then 48 if [ "${grubcfg##*/}" = "grub.cfg" ]; then
46 rootfs=`grep " *linux \+[^ ]\+ \+root=" $grubcfg -m 1 | \ 49 rootfs=`grep " *linux \+[^ ]\+ \+root=" $grubcfg -m 1 | \
47 sed "s#${old_image}#${old_image%/*}/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}#"` 50 sed "s#${old_image}#${old_image%/*}/KERNEL_IMAGETYPE-${KERNEL_VERSION}#"`
48 51
49 echo "menuentry \"$title\" {" 52 echo "menuentry \"$title\" {"
50 echo " set root=(hd0,1)" 53 echo " set root=(hd0,1)"
@@ -52,7 +55,7 @@ pkg_postinst_kernel-image_prepend () {
52 echo "}" 55 echo "}"
53 elif [ "${grubcfg##*/}" = "menu.list" ]; then 56 elif [ "${grubcfg##*/}" = "menu.list" ]; then
54 rootfs=`grep "kernel \+[^ ]\+ \+root=" $grubcfg -m 1 | \ 57 rootfs=`grep "kernel \+[^ ]\+ \+root=" $grubcfg -m 1 | \
55 sed "s#${old_image}#${old_image%/*}/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}#"` 58 sed "s#${old_image}#${old_image%/*}/KERNEL_IMAGETYPE-${KERNEL_VERSION}#"`
56 59
57 echo "default 0" 60 echo "default 0"
58 echo "timeout 30" 61 echo "timeout 30"
@@ -87,5 +90,16 @@ pkg_postinst_kernel-image_prepend () {
87 mv $grubcfgtmp $grubcfg 90 mv $grubcfgtmp $grubcfg
88 echo "Caution! Update kernel may affect kernel-module!" 91 echo "Caution! Update kernel may affect kernel-module!"
89 fi 92 fi
93'''
94
95 imagetypes = d.getVar('KERNEL_IMAGETYPES', True)
96 imagetypes = re.sub(r'\.gz$', '', imagetypes)
97
98 for type in imagetypes.split():
99 typelower = type.lower()
100 preinst_append = preinst.replace('KERNEL_IMAGETYPE', type)
101 postinst_prepend = postinst.replace('KERNEL_IMAGETYPE', type)
102 d.setVar('pkg_preinst_kernel-image-' + typelower + '_append', preinst_append)
103 d.setVar('pkg_postinst_kernel-image-' + typelower + '_prepend', postinst_prepend)
90} 104}
91 105