diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-08-10 14:35:29 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-08-12 15:27:17 +0100 |
commit | fd1517e2b51a170f2427122c6b95396db251d827 (patch) | |
tree | dabfe3e631339c2fc99a9ee7febb0f9c128e325e /meta/classes/kernel-grub.bbclass | |
parent | 10317912ee319ccf7f83605d438b5cbf9663f296 (diff) | |
download | poky-fd1517e2b51a170f2427122c6b95396db251d827.tar.gz |
classes: Update classes to match new bitbake class scope functionality
Move classes to classes-global or classes-recipe as appropriate to take
advantage of new bitbake functionality to check class scope/usage.
(From OE-Core rev: f5c128008365e141082c129417eb72d2751e8045)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/kernel-grub.bbclass')
-rw-r--r-- | meta/classes/kernel-grub.bbclass | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/meta/classes/kernel-grub.bbclass b/meta/classes/kernel-grub.bbclass deleted file mode 100644 index 2325e635e1..0000000000 --- a/meta/classes/kernel-grub.bbclass +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
1 | # | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: MIT | ||
5 | # | ||
6 | |||
7 | # | ||
8 | # While installing a rpm to update kernel on a deployed target, it will update | ||
9 | # the boot area and the boot menu with the kernel as the priority but allow | ||
10 | # you to fall back to the original kernel as well. | ||
11 | # | ||
12 | # - In kernel-image's preinstall scriptlet, it backs up original kernel to avoid | ||
13 | # probable confliction with the new one. | ||
14 | # | ||
15 | # - In kernel-image's postinstall scriptlet, it modifies grub's config file to | ||
16 | # updates the new kernel as the boot priority. | ||
17 | # | ||
18 | |||
19 | python __anonymous () { | ||
20 | import re | ||
21 | |||
22 | preinst = ''' | ||
23 | # Parsing confliction | ||
24 | [ -f "$D/boot/grub/menu.list" ] && grubcfg="$D/boot/grub/menu.list" | ||
25 | [ -f "$D/boot/grub/grub.cfg" ] && grubcfg="$D/boot/grub/grub.cfg" | ||
26 | if [ -n "$grubcfg" ]; then | ||
27 | # Dereference symlink to avoid confliction with new kernel name. | ||
28 | if grep -q "/KERNEL_IMAGETYPE \+root=" $grubcfg; then | ||
29 | if [ -L "$D/boot/KERNEL_IMAGETYPE" ]; then | ||
30 | kimage=`realpath $D/boot/KERNEL_IMAGETYPE 2>/dev/null` | ||
31 | if [ -f "$D$kimage" ]; then | ||
32 | sed -i "s:KERNEL_IMAGETYPE \+root=:${kimage##*/} root=:" $grubcfg | ||
33 | fi | ||
34 | fi | ||
35 | fi | ||
36 | |||
37 | # Rename old kernel if it conflicts with new kernel name. | ||
38 | if grep -q "/KERNEL_IMAGETYPE-${KERNEL_VERSION} \+root=" $grubcfg; then | ||
39 | if [ -f "$D/boot/KERNEL_IMAGETYPE-${KERNEL_VERSION}" ]; then | ||
40 | timestamp=`date +%s` | ||
41 | kimage="$D/boot/KERNEL_IMAGETYPE-${KERNEL_VERSION}-$timestamp-back" | ||
42 | sed -i "s:KERNEL_IMAGETYPE-${KERNEL_VERSION} \+root=:${kimage##*/} root=:" $grubcfg | ||
43 | mv "$D/boot/KERNEL_IMAGETYPE-${KERNEL_VERSION}" "$kimage" | ||
44 | fi | ||
45 | fi | ||
46 | fi | ||
47 | ''' | ||
48 | |||
49 | postinst = ''' | ||
50 | get_new_grub_cfg() { | ||
51 | grubcfg="$1" | ||
52 | old_image="$2" | ||
53 | title="Update KERNEL_IMAGETYPE-${KERNEL_VERSION}-${PV}" | ||
54 | if [ "${grubcfg##*/}" = "grub.cfg" ]; then | ||
55 | rootfs=`grep " *linux \+[^ ]\+ \+root=" $grubcfg -m 1 | \ | ||
56 | sed "s#${old_image}#${old_image%/*}/KERNEL_IMAGETYPE-${KERNEL_VERSION}#"` | ||
57 | |||
58 | echo "menuentry \"$title\" {" | ||
59 | echo " set root=(hd0,1)" | ||
60 | echo "$rootfs" | ||
61 | echo "}" | ||
62 | elif [ "${grubcfg##*/}" = "menu.list" ]; then | ||
63 | rootfs=`grep "kernel \+[^ ]\+ \+root=" $grubcfg -m 1 | \ | ||
64 | sed "s#${old_image}#${old_image%/*}/KERNEL_IMAGETYPE-${KERNEL_VERSION}#"` | ||
65 | |||
66 | echo "default 0" | ||
67 | echo "timeout 30" | ||
68 | echo "title $title" | ||
69 | echo "root (hd0,0)" | ||
70 | echo "$rootfs" | ||
71 | fi | ||
72 | } | ||
73 | |||
74 | get_old_grub_cfg() { | ||
75 | grubcfg="$1" | ||
76 | if [ "${grubcfg##*/}" = "grub.cfg" ]; then | ||
77 | cat "$grubcfg" | ||
78 | elif [ "${grubcfg##*/}" = "menu.list" ]; then | ||
79 | sed -e '/^default/d' -e '/^timeout/d' "$grubcfg" | ||
80 | fi | ||
81 | } | ||
82 | |||
83 | if [ -f "$D/boot/grub/grub.cfg" ]; then | ||
84 | grubcfg="$D/boot/grub/grub.cfg" | ||
85 | old_image=`grep ' *linux \+[^ ]\+ \+root=' -m 1 "$grubcfg" | awk '{print $2}'` | ||
86 | elif [ -f "$D/boot/grub/menu.list" ]; then | ||
87 | grubcfg="$D/boot/grub/menu.list" | ||
88 | old_image=`grep '^kernel \+[^ ]\+ \+root=' -m 1 "$grubcfg" | awk '{print $2}'` | ||
89 | fi | ||
90 | |||
91 | # Don't update grubcfg at first install while old bzImage doesn't exist. | ||
92 | if [ -f "$D/boot/${old_image##*/}" ]; then | ||
93 | grubcfgtmp="$grubcfg.tmp" | ||
94 | get_new_grub_cfg "$grubcfg" "$old_image" > $grubcfgtmp | ||
95 | get_old_grub_cfg "$grubcfg" >> $grubcfgtmp | ||
96 | mv $grubcfgtmp $grubcfg | ||
97 | echo "Caution! Update kernel may affect kernel-module!" | ||
98 | fi | ||
99 | ''' | ||
100 | |||
101 | imagetypes = d.getVar('KERNEL_IMAGETYPES') | ||
102 | imagetypes = re.sub(r'\.gz$', '', imagetypes) | ||
103 | |||
104 | for type in imagetypes.split(): | ||
105 | typelower = type.lower() | ||
106 | preinst_append = preinst.replace('KERNEL_IMAGETYPE', type) | ||
107 | postinst_prepend = postinst.replace('KERNEL_IMAGETYPE', type) | ||
108 | d.setVar('pkg_preinst:kernel-image-' + typelower + ':append', preinst_append) | ||
109 | d.setVar('pkg_postinst:kernel-image-' + typelower + ':prepend', postinst_prepend) | ||
110 | } | ||
111 | |||