Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | # Copyright (C) 2016 Intel Corporation |
| 2 | # |
| 3 | # Released under the MIT license (see COPYING.MIT) |
| 4 | |
| 5 | # systemd-boot.bbclass - The "systemd-boot" is essentially the gummiboot merged into systemd. |
| 6 | # The original standalone gummiboot project is dead without any more |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7 | # maintenance. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 8 | # |
| 9 | # Set EFI_PROVIDER = "systemd-boot" to use systemd-boot on your live images instead of grub-efi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 | # (images built by image-live.bbclass) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 11 | |
| 12 | do_bootimg[depends] += "${MLPREFIX}systemd-boot:do_deploy" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 13 | |
| 14 | EFIDIR = "/EFI/BOOT" |
| 15 | |
| 16 | SYSTEMD_BOOT_CFG ?= "${S}/loader.conf" |
| 17 | SYSTEMD_BOOT_ENTRIES ?= "" |
| 18 | SYSTEMD_BOOT_TIMEOUT ?= "10" |
| 19 | |
| 20 | # Need UUID utility code. |
| 21 | inherit fs-uuid |
| 22 | |
| 23 | efi_populate() { |
| 24 | DEST=$1 |
| 25 | |
| 26 | EFI_IMAGE="systemd-bootia32.efi" |
| 27 | DEST_EFI_IMAGE="bootia32.efi" |
| 28 | if [ "${TARGET_ARCH}" = "x86_64" ]; then |
| 29 | EFI_IMAGE="systemd-bootx64.efi" |
| 30 | DEST_EFI_IMAGE="bootx64.efi" |
| 31 | fi |
| 32 | |
| 33 | install -d ${DEST}${EFIDIR} |
| 34 | # systemd-boot requires these paths for configuration files |
| 35 | # they are not customizable so no point in new vars |
| 36 | install -d ${DEST}/loader |
| 37 | install -d ${DEST}/loader/entries |
| 38 | install -m 0644 ${DEPLOY_DIR_IMAGE}/${EFI_IMAGE} ${DEST}${EFIDIR}/${DEST_EFI_IMAGE} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 39 | EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g') |
| 40 | printf 'fs0:%s\%s\n' "$EFIPATH" "$DEST_EFI_IMAGE" >${DEST}/startup.nsh |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 41 | install -m 0644 ${SYSTEMD_BOOT_CFG} ${DEST}/loader/loader.conf |
| 42 | for i in ${SYSTEMD_BOOT_ENTRIES}; do |
| 43 | install -m 0644 ${i} ${DEST}/loader/entries |
| 44 | done |
| 45 | } |
| 46 | |
| 47 | efi_iso_populate() { |
| 48 | iso_dir=$1 |
| 49 | efi_populate $iso_dir |
| 50 | mkdir -p ${EFIIMGDIR}/${EFIDIR} |
| 51 | cp $iso_dir/${EFIDIR}/* ${EFIIMGDIR}${EFIDIR} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 52 | cp -r $iso_dir/loader ${EFIIMGDIR} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 53 | cp $iso_dir/vmlinuz ${EFIIMGDIR} |
| 54 | EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g') |
| 55 | echo "fs0:${EFIPATH}\\${DEST_EFI_IMAGE}" > ${EFIIMGDIR}/startup.nsh |
| 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 | |
| 65 | python build_efi_cfg() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 66 | s = d.getVar("S") |
| 67 | labels = d.getVar('LABELS') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 68 | if not labels: |
| 69 | bb.debug(1, "LABELS not defined, nothing to do") |
| 70 | return |
| 71 | |
| 72 | if labels == []: |
| 73 | bb.debug(1, "No labels, nothing to do") |
| 74 | return |
| 75 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 76 | cfile = d.getVar('SYSTEMD_BOOT_CFG') |
| 77 | cdir = os.path.dirname(cfile) |
| 78 | if not os.path.exists(cdir): |
| 79 | os.makedirs(cdir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 80 | try: |
| 81 | cfgfile = open(cfile, 'w') |
| 82 | except OSError: |
| 83 | bb.fatal('Unable to open %s' % cfile) |
| 84 | |
| 85 | cfgfile.write('# Automatically created by OE\n') |
| 86 | cfgfile.write('default %s\n' % (labels.split()[0])) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 87 | timeout = d.getVar('SYSTEMD_BOOT_TIMEOUT') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 88 | if timeout: |
| 89 | cfgfile.write('timeout %s\n' % timeout) |
| 90 | else: |
| 91 | cfgfile.write('timeout 10\n') |
| 92 | cfgfile.close() |
| 93 | |
| 94 | for label in labels.split(): |
| 95 | localdata = d.createCopy() |
| 96 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 97 | overrides = localdata.getVar('OVERRIDES') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 98 | if not overrides: |
| 99 | bb.fatal('OVERRIDES not defined') |
| 100 | |
| 101 | entryfile = "%s/%s.conf" % (s, label) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 102 | if not os.path.exists(s): |
| 103 | os.makedirs(s) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 104 | d.appendVar("SYSTEMD_BOOT_ENTRIES", " " + entryfile) |
| 105 | try: |
| 106 | entrycfg = open(entryfile, "w") |
| 107 | except OSError: |
| 108 | bb.fatal('Unable to open %s' % entryfile) |
| 109 | localdata.setVar('OVERRIDES', label + ':' + overrides) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 110 | |
| 111 | entrycfg.write('title %s\n' % label) |
| 112 | entrycfg.write('linux /vmlinuz\n') |
| 113 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 114 | append = localdata.getVar('APPEND') |
| 115 | initrd = localdata.getVar('INITRD') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 116 | |
| 117 | if initrd: |
| 118 | entrycfg.write('initrd /initrd\n') |
| 119 | lb = label |
| 120 | if label == "install": |
| 121 | lb = "install-efi" |
| 122 | entrycfg.write('options LABEL=%s ' % lb) |
| 123 | if append: |
| 124 | append = replace_rootfs_uuid(d, append) |
| 125 | entrycfg.write('%s' % append) |
| 126 | entrycfg.write('\n') |
| 127 | entrycfg.close() |
| 128 | } |