grub-efi-cfg.bbclass 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # grub-efi.bbclass
  2. # Copyright (c) 2011, Intel Corporation.
  3. #
  4. # SPDX-License-Identifier: MIT
  5. # Provide grub-efi specific functions for building bootable images.
  6. # External variables
  7. # ${INITRD} - indicates a list of filesystem images to concatenate and use as an initrd (optional)
  8. # ${ROOTFS} - indicates a filesystem image to include as the root filesystem (optional)
  9. # ${GRUB_GFXSERIAL} - set this to 1 to have graphics and serial in the boot menu
  10. # ${LABELS} - a list of targets for the automatic config
  11. # ${APPEND} - an override list of append strings for each label
  12. # ${GRUB_OPTS} - additional options to add to the config, ';' delimited # (optional)
  13. # ${GRUB_TIMEOUT} - timeout before executing the deault label (optional)
  14. # ${GRUB_ROOT} - grub's root device.
  15. GRUB_SERIAL ?= "console=ttyS0,115200"
  16. GRUB_CFG_VM = "${S}/grub_vm.cfg"
  17. GRUB_CFG_LIVE = "${S}/grub_live.cfg"
  18. GRUB_TIMEOUT ?= "10"
  19. #FIXME: build this from the machine config
  20. GRUB_OPTS ?= "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
  21. GRUB_ROOT ?= "${ROOT}"
  22. GRUB_TITLE ?= ""
  23. APPEND ?= ""
  24. # Uses MACHINE specific KERNEL_IMAGETYPE
  25. PACKAGE_ARCH = "${MACHINE_ARCH}"
  26. # Need UUID utility code.
  27. inherit fs-uuid
  28. python build_efi_cfg() {
  29. import sys
  30. workdir = d.getVar('WORKDIR')
  31. if not workdir:
  32. bb.error("WORKDIR not defined, unable to package")
  33. return
  34. gfxserial = d.getVar('GRUB_GFXSERIAL') or ""
  35. labels = d.getVar('LABELS')
  36. if not labels:
  37. bb.debug(1, "LABELS not defined, nothing to do")
  38. return
  39. if labels == []:
  40. bb.debug(1, "No labels, nothing to do")
  41. return
  42. cfile = d.getVar('GRUB_CFG')
  43. if not cfile:
  44. bb.fatal('Unable to read GRUB_CFG')
  45. try:
  46. cfgfile = open(cfile, 'w')
  47. except OSError:
  48. bb.fatal('Unable to open %s' % cfile)
  49. cfgfile.write('# Automatically created by OE\n')
  50. opts = d.getVar('GRUB_OPTS')
  51. if opts:
  52. for opt in opts.split(';'):
  53. cfgfile.write('%s\n' % opt)
  54. cfgfile.write('default=%s\n' % (labels.split()[0]))
  55. timeout = d.getVar('GRUB_TIMEOUT')
  56. if timeout:
  57. cfgfile.write('timeout=%s\n' % timeout)
  58. else:
  59. cfgfile.write('timeout=50\n')
  60. root = d.getVar('GRUB_ROOT')
  61. if not root:
  62. bb.fatal('GRUB_ROOT not defined')
  63. if gfxserial == "1":
  64. btypes = [ [ " graphics console", "" ],
  65. [ " serial console", d.getVar('GRUB_SERIAL') or "" ] ]
  66. else:
  67. btypes = [ [ "", "" ] ]
  68. for label in labels.split():
  69. localdata = d.createCopy()
  70. overrides = localdata.getVar('OVERRIDES')
  71. if not overrides:
  72. bb.fatal('OVERRIDES not defined')
  73. localdata.need_overrides()
  74. localdata.setVar('OVERRIDES', 'grub_' + label + ':' + overrides)
  75. for btype in btypes:
  76. title = localdata.getVar('GRUB_TITLE')
  77. if not title or len(title) == 0:
  78. title = label
  79. cfgfile.write('\nmenuentry \'%s%s\'{\n' % (title, btype[0]))
  80. lb = label
  81. if label == "install":
  82. lb = "install-efi"
  83. kernel = localdata.getVar('KERNEL_IMAGETYPE')
  84. cfgfile.write('linux /%s LABEL=%s' % (kernel, lb))
  85. cfgfile.write(' %s' % replace_rootfs_uuid(d, root))
  86. append = localdata.getVar('APPEND')
  87. initrd = localdata.getVar('INITRD')
  88. if append:
  89. append = replace_rootfs_uuid(d, append)
  90. cfgfile.write(' %s' % (append))
  91. cfgfile.write(' %s' % btype[1])
  92. cfgfile.write('\n')
  93. if initrd:
  94. cfgfile.write('initrd /initrd')
  95. cfgfile.write('\n}\n')
  96. cfgfile.close()
  97. }
  98. build_efi_cfg[vardepsexclude] += "OVERRIDES"