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