summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/live-vm-common.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes-recipe/live-vm-common.bbclass')
-rw-r--r--meta/classes-recipe/live-vm-common.bbclass100
1 files changed, 100 insertions, 0 deletions
diff --git a/meta/classes-recipe/live-vm-common.bbclass b/meta/classes-recipe/live-vm-common.bbclass
new file mode 100644
index 0000000000..b619f3a4be
--- /dev/null
+++ b/meta/classes-recipe/live-vm-common.bbclass
@@ -0,0 +1,100 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7# Some of the vars for vm and live image are conflicted, this function
8# is used for fixing the problem.
9def set_live_vm_vars(d, suffix):
10 vars = ['GRUB_CFG', 'SYSLINUX_CFG', 'ROOT', 'LABELS', 'INITRD']
11 for var in vars:
12 var_with_suffix = var + '_' + suffix
13 if d.getVar(var):
14 bb.warn('Found potential conflicted var %s, please use %s rather than %s' % \
15 (var, var_with_suffix, var))
16 elif d.getVar(var_with_suffix):
17 d.setVar(var, d.getVar(var_with_suffix))
18
19
20EFI = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "1", "0", d)}"
21EFI_PROVIDER ?= "grub-efi"
22EFI_CLASS = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "${EFI_PROVIDER}", "", d)}"
23
24MKDOSFS_EXTRAOPTS ??= "-S 512"
25
26# Include legacy boot if MACHINE_FEATURES includes "pcbios" or if it does not
27# contain "efi". This way legacy is supported by default if neither is
28# specified, maintaining the original behavior.
29def pcbios(d):
30 pcbios = bb.utils.contains("MACHINE_FEATURES", "pcbios", "1", "0", d)
31 if pcbios == "0":
32 pcbios = bb.utils.contains("MACHINE_FEATURES", "efi", "0", "1", d)
33 return pcbios
34
35PCBIOS = "${@pcbios(d)}"
36PCBIOS_CLASS = "${@['','syslinux'][d.getVar('PCBIOS') == '1']}"
37
38# efi_populate_common DEST BOOTLOADER
39efi_populate_common() {
40 # DEST must be the root of the image so that EFIDIR is not
41 # nested under a top level directory.
42 DEST=$1
43
44 install -d ${DEST}${EFIDIR}
45
46 install -m 0644 ${DEPLOY_DIR_IMAGE}/$2-${EFI_BOOT_IMAGE} ${DEST}${EFIDIR}/${EFI_BOOT_IMAGE}
47 EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g')
48 printf 'fs0:%s\%s\n' "$EFIPATH" "${EFI_BOOT_IMAGE}" >${DEST}/startup.nsh
49}
50
51efi_iso_populate() {
52 iso_dir=$1
53 efi_populate $iso_dir
54 # Build a EFI directory to create efi.img
55 mkdir -p ${EFIIMGDIR}/${EFIDIR}
56 cp $iso_dir/${EFIDIR}/* ${EFIIMGDIR}${EFIDIR}
57 cp $iso_dir/${KERNEL_IMAGETYPE} ${EFIIMGDIR}
58
59 EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g')
60 printf 'fs0:%s\%s\n' "$EFIPATH" "${EFI_BOOT_IMAGE}" >${EFIIMGDIR}/startup.nsh
61
62 if [ -f "$iso_dir/initrd" ] ; then
63 cp $iso_dir/initrd ${EFIIMGDIR}
64 fi
65}
66
67efi_hddimg_populate() {
68 efi_populate $1
69}
70
71inherit ${EFI_CLASS}
72inherit ${PCBIOS_CLASS}
73
74populate_kernel() {
75 dest=$1
76 install -d $dest
77
78 # Install bzImage, initrd, and rootfs.img in DEST for all loaders to use.
79 bbnote "Trying to install ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} as $dest/${KERNEL_IMAGETYPE}"
80 if [ -e ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} ]; then
81 install -m 0644 ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} $dest/${KERNEL_IMAGETYPE}
82 else
83 bbwarn "${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} doesn't exist"
84 fi
85
86 # initrd is made of concatenation of multiple filesystem images
87 if [ -n "${INITRD}" ]; then
88 rm -f $dest/initrd
89 for fs in ${INITRD}
90 do
91 if [ -s "$fs" ]; then
92 cat $fs >> $dest/initrd
93 else
94 bbfatal "$fs is invalid. initrd image creation failed."
95 fi
96 done
97 chmod 0644 $dest/initrd
98 fi
99}
100