live-vm-common.bbclass 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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
  7. if d.getVar(var):
  8. bb.warn('Found potential conflicted var %s, please use %s rather than %s' % \
  9. (var, var_with_suffix, var))
  10. elif d.getVar(var_with_suffix):
  11. d.setVar(var, d.getVar(var_with_suffix))
  12. EFI = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "1", "0", d)}"
  13. EFI_PROVIDER ?= "grub-efi"
  14. EFI_CLASS = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "${EFI_PROVIDER}", "", d)}"
  15. MKDOSFS_EXTRAOPTS ??= "-S 512"
  16. # Include legacy boot if MACHINE_FEATURES includes "pcbios" or if it does not
  17. # contain "efi". This way legacy is supported by default if neither is
  18. # specified, maintaining the original behavior.
  19. def pcbios(d):
  20. pcbios = bb.utils.contains("MACHINE_FEATURES", "pcbios", "1", "0", d)
  21. if pcbios == "0":
  22. pcbios = bb.utils.contains("MACHINE_FEATURES", "efi", "0", "1", d)
  23. return pcbios
  24. PCBIOS = "${@pcbios(d)}"
  25. PCBIOS_CLASS = "${@['','syslinux'][d.getVar('PCBIOS') == '1']}"
  26. # efi_populate_common DEST BOOTLOADER
  27. efi_populate_common() {
  28. # DEST must be the root of the image so that EFIDIR is not
  29. # nested under a top level directory.
  30. DEST=$1
  31. install -d ${DEST}${EFIDIR}
  32. install -m 0644 ${DEPLOY_DIR_IMAGE}/$2-${EFI_BOOT_IMAGE} ${DEST}${EFIDIR}/${EFI_BOOT_IMAGE}
  33. EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g')
  34. printf 'fs0:%s\%s\n' "$EFIPATH" "${EFI_BOOT_IMAGE}" >${DEST}/startup.nsh
  35. }
  36. efi_iso_populate() {
  37. iso_dir=$1
  38. efi_populate $iso_dir
  39. # Build a EFI directory to create efi.img
  40. mkdir -p ${EFIIMGDIR}/${EFIDIR}
  41. cp $iso_dir/${EFIDIR}/* ${EFIIMGDIR}${EFIDIR}
  42. cp $iso_dir/${KERNEL_IMAGETYPE} ${EFIIMGDIR}
  43. EFIPATH=$(echo "${EFIDIR}" | sed 's/\//\\/g')
  44. printf 'fs0:%s\%s\n' "$EFIPATH" "${EFI_BOOT_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. inherit ${EFI_CLASS}
  53. inherit ${PCBIOS_CLASS}
  54. populate_kernel() {
  55. dest=$1
  56. install -d $dest
  57. # Install bzImage, initrd, and rootfs.img in DEST for all loaders to use.
  58. bbnote "Trying to install ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} as $dest/${KERNEL_IMAGETYPE}"
  59. if [ -e ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} ]; then
  60. install -m 0644 ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} $dest/${KERNEL_IMAGETYPE}
  61. else
  62. bbwarn "${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} doesn't exist"
  63. fi
  64. # initrd is made of concatenation of multiple filesystem images
  65. if [ -n "${INITRD}" ]; then
  66. rm -f $dest/initrd
  67. for fs in ${INITRD}
  68. do
  69. if [ -s "$fs" ]; then
  70. cat $fs >> $dest/initrd
  71. else
  72. bbfatal "$fs is invalid. initrd image creation failed."
  73. fi
  74. done
  75. chmod 0644 $dest/initrd
  76. fi
  77. }