systemd-boot.bbclass 3.7 KB

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