bootimg: Use the same OS files for each boot method

Fixes [YOCTO #1951]

The do_bootimg code can generate hybrid efi+pcbios images (syslinux and
grub-efi) to boot on platforms with both EFI and legacy BIOS options. The
current implementation copies the kernel, initrd, and rootfs twice,
unnecessarily bloating the image size. This is an especially egregious bug
on -sato images.

Update the classes to use a common install of the kernel, initrd, and rootfs to
the root of the boot media. Grub-efi, syslinux, and isolinux can all reference
this location explicitly with a leading slash.

Tested with an EFI+PCBIOS image in both EFI and PCBIOS boot modes on two
platforms. No ISO image testing was performed.

(From OE-Core rev: 5209016cf4c4c8f649e37dc8857b3fbcfe8dd8c8)

Signed-off-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Darren Hart 2012-02-01 16:15:04 -08:00 committed by Richard Purdie
parent 50a097be16
commit 67cfa74744
3 changed files with 46 additions and 47 deletions

View File

@ -8,13 +8,13 @@
# End result is two things: # End result is two things:
# #
# 1. A .hddimg file which is an msdos filesystem containing syslinux, a kernel, # 1. A .hddimg file which is an msdos filesystem containing syslinux, a kernel,
# an initrd and a rootfs image. These can be written to harddisks directly and # an initrd and a rootfs image. These can be written to harddisks directly and
# also booted on USB flash disks (write them there with dd). # also booted on USB flash disks (write them there with dd).
# #
# 2. A CD .iso image # 2. A CD .iso image
# Boot process is that the initrd will boot and process which label was selected # Boot process is that the initrd will boot and process which label was selected
# in syslinux. Actions based on the label are then performed (e.g. installing to # in syslinux. Actions based on the label are then performed (e.g. installing to
# an hdd) # an hdd)
# External variables (also used by syslinux.bbclass) # External variables (also used by syslinux.bbclass)
@ -29,8 +29,8 @@ do_bootimg[depends] += "dosfstools-native:do_populate_sysroot \
PACKAGES = " " PACKAGES = " "
EXCLUDE_FROM_WORLD = "1" EXCLUDE_FROM_WORLD = "1"
HDDDIR = "${S}/hdd/boot" HDDDIR = "${S}/hddimg"
ISODIR = "${S}/cd" ISODIR = "${S}/iso"
BOOTIMG_VOLUME_ID ?= "boot" BOOTIMG_VOLUME_ID ?= "boot"
BOOTIMG_EXTRA_SPACE ?= "512" BOOTIMG_EXTRA_SPACE ?= "512"
@ -58,6 +58,22 @@ PCBIOS_CLASS = ${@pcbios_class(d)}
inherit ${PCBIOS_CLASS} inherit ${PCBIOS_CLASS}
inherit ${EFI_CLASS} inherit ${EFI_CLASS}
populate() {
DEST=$1
install -d ${DEST}
# Install bzImage, initrd, and rootfs.img in DEST for all loaders to use.
install -m 0644 ${STAGING_DIR_HOST}/kernel/bzImage ${DEST}/vmlinuz
if [ -n "${INITRD}" ] && [ -s "${INITRD}" ]; then
install -m 0644 ${INITRD} ${DEST}/initrd
fi
if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ]; then
install -m 0644 ${ROOTFS} ${DEST}/rootfs.img
fi
}
build_iso() { build_iso() {
# Only create an ISO if we have an INITRD and NOISO was not set # Only create an ISO if we have an INITRD and NOISO was not set
@ -66,7 +82,7 @@ build_iso() {
return return
fi fi
install -d ${ISODIR} populate ${ISODIR}
if [ "${PCBIOS}" = "1" ]; then if [ "${PCBIOS}" = "1" ]; then
syslinux_iso_populate syslinux_iso_populate
@ -95,7 +111,8 @@ build_iso() {
build_hddimg() { build_hddimg() {
# Create an HDD image # Create an HDD image
if [ "${NOHDD}" != "1" ] ; then if [ "${NOHDD}" != "1" ] ; then
install -d ${HDDDIR} populate ${HDDDIR}
if [ "${PCBIOS}" = "1" ]; then if [ "${PCBIOS}" = "1" ]; then
syslinux_hddimg_populate syslinux_hddimg_populate
fi fi

View File

@ -22,39 +22,29 @@ GRUB_TIMEOUT ?= "10"
GRUB_OPTS ?= "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1" GRUB_OPTS ?= "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
EFIDIR = "/EFI/BOOT" EFIDIR = "/EFI/BOOT"
GRUB_HDDDIR = "${HDDDIR}${EFIDIR}"
GRUB_ISODIR = "${ISODIR}${EFIDIR}"
grubefi_populate() { grubefi_populate() {
# DEST must be the root of the image so that EFIDIR is not
# nested under a top level directory.
DEST=$1 DEST=$1
install -d ${DEST} install -d ${DEST}${EFIDIR}
install -m 0644 ${STAGING_DIR_HOST}/kernel/bzImage ${DEST}/vmlinuz
if [ -n "${INITRD}" ] && [ -s "${INITRD}" ]; then
install -m 0644 ${INITRD} ${DEST}/initrd
fi
if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ]; then
install -m 0644 ${ROOTFS} ${DEST}/rootfs.img
fi
GRUB_IMAGE="bootia32.efi" GRUB_IMAGE="bootia32.efi"
if [ "${TARGET_ARCH}" = "x86_64" ]; then if [ "${TARGET_ARCH}" = "x86_64" ]; then
GRUB_IMAGE="bootx64.efi" GRUB_IMAGE="bootx64.efi"
fi fi
install -m 0644 ${DEPLOY_DIR_IMAGE}/${GRUB_IMAGE} ${DEST} install -m 0644 ${DEPLOY_DIR_IMAGE}/${GRUB_IMAGE} ${DEST}${EFIDIR}
install -m 0644 ${GRUBCFG} ${DEST} install -m 0644 ${GRUBCFG} ${DEST}${EFIDIR}
} }
grubefi_iso_populate() { grubefi_iso_populate() {
grubefi_populate ${GRUB_ISODIR} grubefi_populate ${ISODIR}
} }
grubefi_hddimg_populate() { grubefi_hddimg_populate() {
grubefi_populate ${GRUB_HDDDIR} grubefi_populate ${HDDDIR}
} }
python build_grub_cfg() { python build_grub_cfg() {
@ -109,7 +99,7 @@ python build_grub_cfg() {
bb.data.update_data(localdata) bb.data.update_data(localdata)
cfgfile.write('\nmenuentry \'%s\'{\n' % (label)) cfgfile.write('\nmenuentry \'%s\'{\n' % (label))
cfgfile.write('linux ${EFIDIR}/vmlinuz LABEL=%s' % (label)) cfgfile.write('linux /vmlinuz LABEL=%s' % (label))
append = localdata.getVar('APPEND', True) append = localdata.getVar('APPEND', True)
initrd = localdata.getVar('INITRD', True) initrd = localdata.getVar('INITRD', True)
@ -119,7 +109,7 @@ python build_grub_cfg() {
cfgfile.write('\n') cfgfile.write('\n')
if initrd: if initrd:
cfgfile.write('initrd ${EFIDIR}/initrd') cfgfile.write('initrd /initrd')
cfgfile.write('\n}\n') cfgfile.write('\n}\n')
cfgfile.close() cfgfile.close()

View File

@ -18,42 +18,34 @@ do_bootimg[depends] += "syslinux:do_populate_sysroot \
SYSLINUXCFG = "${S}/syslinux.cfg" SYSLINUXCFG = "${S}/syslinux.cfg"
SYSLINUXMENU = "${S}/menu" SYSLINUXMENU = "${S}/menu"
SYSLINUX_ISODIR = "${ISODIR}/isolinux" ISOLINUXDIR = "/isolinux"
SYSLINUX_HDDDIR = "${HDDDIR}" SYSLINUXDIR = "/"
ISO_BOOTIMG = "isolinux/isolinux.bin" ISO_BOOTIMG = "isolinux/isolinux.bin"
ISO_BOOTCAT = "isolinux/boot.cat" ISO_BOOTCAT = "isolinux/boot.cat"
MKISOFS_OPTIONS = "-no-emul-boot -boot-load-size 4 -boot-info-table" MKISOFS_OPTIONS = "-no-emul-boot -boot-load-size 4 -boot-info-table"
syslinux_populate() { syslinux_populate() {
DEST=$1 DEST=$1
CFGNAME=$2 BOOTDIR=$2
CFGNAME=$3
install -d ${DEST} install -d ${DEST}${BOOTDIR}
# Install the kernel, initrd, and rootfs
install -m 0644 ${STAGING_DIR_HOST}/kernel/bzImage ${DEST}/vmlinuz
if [ -n "${INITRD}" ] && [ -s "${INITRD}" ]; then
install -m 0644 ${INITRD} ${DEST}/initrd
fi
if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ]; then
install -m 0644 ${ROOTFS} ${DEST}/rootfs.img
fi
# Install the config files # Install the config files
install -m 0644 ${SYSLINUXCFG} ${DEST}/${CFGNAME} install -m 0644 ${SYSLINUXCFG} ${DEST}${BOOTDIR}/${CFGNAME}
if [ -f ${SYSLINUXMENU} ]; then if [ -f ${SYSLINUXMENU} ]; then
install -m 0644 ${SYSLINUXMENU} ${DEST} install -m 0644 ${SYSLINUXMENU} ${DEST}${BOOTDIR}
fi fi
} }
syslinux_iso_populate() { syslinux_iso_populate() {
syslinux_populate ${SYSLINUX_ISODIR} isolinux.cfg syslinux_populate ${ISODIR} ${ISOLINUXDIR} isolinux.cfg
install -m 0644 ${STAGING_LIBDIR}/syslinux/isolinux.bin ${SYSLINUX_ISODIR} install -m 0644 ${STAGING_LIBDIR}/syslinux/isolinux.bin ${ISODIR}${ISOLINUXDIR}
} }
syslinux_hddimg_populate() { syslinux_hddimg_populate() {
syslinux_populate ${SYSLINUX_HDDDIR} syslinux.cfg syslinux_populate ${HDDDIR} ${SYSLINUXDIR} syslinux.cfg
install -m 0444 ${STAGING_LIBDIR}/syslinux/ldlinux.sys ${SYSLINUX_HDDDIR}/ldlinux.sys install -m 0444 ${STAGING_LIBDIR}/syslinux/ldlinux.sys ${HDDDIR}${SYSLINUXDIR}/ldlinux.sys
} }
syslinux_hddimg_install() { syslinux_hddimg_install() {
@ -187,7 +179,7 @@ python build_syslinux_cfg () {
localdata.setVar('OVERRIDES', label + ':' + overrides) localdata.setVar('OVERRIDES', label + ':' + overrides)
bb.data.update_data(localdata) bb.data.update_data(localdata)
cfgfile.write('LABEL %s\nKERNEL vmlinuz\n' % (label)) cfgfile.write('LABEL %s\nKERNEL /vmlinuz\n' % (label))
append = localdata.getVar('APPEND', 1) append = localdata.getVar('APPEND', 1)
initrd = localdata.getVar('INITRD', 1) initrd = localdata.getVar('INITRD', 1)
@ -196,7 +188,7 @@ python build_syslinux_cfg () {
cfgfile.write('APPEND ') cfgfile.write('APPEND ')
if initrd: if initrd:
cfgfile.write('initrd=initrd ') cfgfile.write('initrd=/initrd ')
cfgfile.write('LABEL=%s '% (label)) cfgfile.write('LABEL=%s '% (label))