Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # Copyright (C) 2014 Intel Corporation |
| 2 | # |
| 3 | # Released under the MIT license (see COPYING.MIT) |
| 4 | |
| 5 | # gummiboot.bbclass - equivalent of grub-efi.bbclass |
| 6 | # Set EFI_PROVIDER = "gummiboot" to use gummiboot on your live images instead of grub-efi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 7 | # (images built by image-live.bbclass or image-vm.bbclass) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | |
| 9 | do_bootimg[depends] += "${MLPREFIX}gummiboot:do_deploy" |
| 10 | do_bootdirectdisk[depends] += "${MLPREFIX}gummiboot:do_deploy" |
| 11 | |
| 12 | EFIDIR = "/EFI/BOOT" |
| 13 | |
| 14 | GUMMIBOOT_CFG ?= "${S}/loader.conf" |
| 15 | GUMMIBOOT_ENTRIES ?= "" |
| 16 | GUMMIBOOT_TIMEOUT ?= "10" |
| 17 | |
| 18 | # Need UUID utility code. |
| 19 | inherit fs-uuid |
| 20 | |
| 21 | efi_populate() { |
| 22 | DEST=$1 |
| 23 | |
| 24 | EFI_IMAGE="gummibootia32.efi" |
| 25 | DEST_EFI_IMAGE="bootia32.efi" |
| 26 | if [ "${TARGET_ARCH}" = "x86_64" ]; then |
| 27 | EFI_IMAGE="gummibootx64.efi" |
| 28 | DEST_EFI_IMAGE="bootx64.efi" |
| 29 | fi |
| 30 | |
| 31 | install -d ${DEST}${EFIDIR} |
| 32 | # gummiboot requires these paths for configuration files |
| 33 | # they are not customizable so no point in new vars |
| 34 | install -d ${DEST}/loader |
| 35 | install -d ${DEST}/loader/entries |
| 36 | install -m 0644 ${DEPLOY_DIR_IMAGE}/${EFI_IMAGE} ${DEST}${EFIDIR}/${DEST_EFI_IMAGE} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 37 | EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g') |
| 38 | printf 'fs0:%s\%s\n' "$EFIPATH" "$DEST_EFI_IMAGE" >${DEST}/startup.nsh |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | install -m 0644 ${GUMMIBOOT_CFG} ${DEST}/loader/loader.conf |
| 40 | for i in ${GUMMIBOOT_ENTRIES}; do |
| 41 | install -m 0644 ${i} ${DEST}/loader/entries |
| 42 | done |
| 43 | } |
| 44 | |
| 45 | efi_iso_populate() { |
| 46 | iso_dir=$1 |
| 47 | efi_populate $iso_dir |
| 48 | mkdir -p ${EFIIMGDIR}/${EFIDIR} |
| 49 | cp $iso_dir/${EFIDIR}/* ${EFIIMGDIR}${EFIDIR} |
| 50 | cp $iso_dir/vmlinuz ${EFIIMGDIR} |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 51 | EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g') |
| 52 | echo "fs0:${EFIPATH}\\${DEST_EFI_IMAGE}" > ${EFIIMGDIR}/startup.nsh |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | if [ -f "$iso_dir/initrd" ] ; then |
| 54 | cp $iso_dir/initrd ${EFIIMGDIR} |
| 55 | fi |
| 56 | } |
| 57 | |
| 58 | efi_hddimg_populate() { |
| 59 | efi_populate $1 |
| 60 | } |
| 61 | |
| 62 | python build_efi_cfg() { |
| 63 | s = d.getVar("S", True) |
| 64 | labels = d.getVar('LABELS', True) |
| 65 | if not labels: |
| 66 | bb.debug(1, "LABELS not defined, nothing to do") |
| 67 | return |
| 68 | |
| 69 | if labels == []: |
| 70 | bb.debug(1, "No labels, nothing to do") |
| 71 | return |
| 72 | |
| 73 | cfile = d.getVar('GUMMIBOOT_CFG', True) |
| 74 | try: |
| 75 | cfgfile = open(cfile, 'w') |
| 76 | except OSError: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 77 | bb.fatal('Unable to open %s' % cfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | |
| 79 | cfgfile.write('# Automatically created by OE\n') |
| 80 | cfgfile.write('default %s\n' % (labels.split()[0])) |
| 81 | timeout = d.getVar('GUMMIBOOT_TIMEOUT', True) |
| 82 | if timeout: |
| 83 | cfgfile.write('timeout %s\n' % timeout) |
| 84 | else: |
| 85 | cfgfile.write('timeout 10\n') |
| 86 | cfgfile.close() |
| 87 | |
| 88 | for label in labels.split(): |
| 89 | localdata = d.createCopy() |
| 90 | |
| 91 | overrides = localdata.getVar('OVERRIDES', True) |
| 92 | if not overrides: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 93 | bb.fatal('OVERRIDES not defined') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 94 | |
| 95 | entryfile = "%s/%s.conf" % (s, label) |
| 96 | d.appendVar("GUMMIBOOT_ENTRIES", " " + entryfile) |
| 97 | try: |
| 98 | entrycfg = open(entryfile, "w") |
| 99 | except OSError: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 100 | bb.fatal('Unable to open %s' % entryfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 101 | localdata.setVar('OVERRIDES', label + ':' + overrides) |
| 102 | bb.data.update_data(localdata) |
| 103 | |
| 104 | entrycfg.write('title %s\n' % label) |
| 105 | entrycfg.write('linux /vmlinuz\n') |
| 106 | |
| 107 | append = localdata.getVar('APPEND', True) |
| 108 | initrd = localdata.getVar('INITRD', True) |
| 109 | |
| 110 | if initrd: |
| 111 | entrycfg.write('initrd /initrd\n') |
| 112 | lb = label |
| 113 | if label == "install": |
| 114 | lb = "install-efi" |
| 115 | entrycfg.write('options LABEL=%s ' % lb) |
| 116 | if append: |
| 117 | append = replace_rootfs_uuid(d, append) |
| 118 | entrycfg.write('%s' % append) |
| 119 | entrycfg.write('\n') |
| 120 | entrycfg.close() |
| 121 | } |