Patchwork [v2,5/7] bootimage.bbclass, grub-efi.bbclass: Improve EFI & PCBIOS+EFI ISO support

login
register
mail settings
Submitter Jason Wessel
Date Sept. 14, 2013, 12:09 a.m.
Message ID <1379117343-29877-6-git-send-email-jason.wessel@windriver.com>
Download mbox | patch
Permalink /patch/58021/
State New
Headers show

Comments

Jason Wessel - Sept. 14, 2013, 12:09 a.m.
Using the latest mkisofs it is possible to generate 3 different types
of ISO images, which can be used in various scenarios.

1) PCBIOS Only ISO
   - This option remains unchanged by this commit
   - Uses syslinux menus
   - Can be directly copied with dd to a USB device
   - Can be burned to optical media

2) EFI Only ISO
   - Uses grub 2 menus
   - Can be burned to optical media
   - If you want to use this image on a USB device
     extra steps must be taken in order to format the USB
     device with fat32, and copy an EFI loader which will
     in turn load the iso image

3) PCBIOS / EFI ISO
   - This is a hybrid image ISO that will work for case 1 or 2
     as above with the same restrictions and boot menu types
     depending on what type of firmware is installed on
     the hardware or depending on if EFI or "Legacy Boot" is
     enabled on some UEFI firmwares.

The syslinux.bbclass is now always required because that is where the
isohybrid dependencies come from as well as the configuration data for
the isohybrid.  The isohybrid is the secret sauce which allows the ISO
to work as optical media or as a disk image on USB or a HDD/SSD.

[YOCTO #4100]

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
---
 meta/classes/bootimg.bbclass  |   33 +++++++++++++++++++++------------
 meta/classes/grub-efi.bbclass |    8 ++++++++
 2 files changed, 29 insertions(+), 12 deletions(-)
Darren Hart - Sept. 16, 2013, 5:30 p.m.
On Fri, 2013-09-13 at 19:09 -0500, Jason Wessel wrote:
> Using the latest mkisofs it is possible to generate 3 different types
> of ISO images, which can be used in various scenarios.
> 
> 1) PCBIOS Only ISO
>    - This option remains unchanged by this commit
>    - Uses syslinux menus
>    - Can be directly copied with dd to a USB device
>    - Can be burned to optical media
> 
> 2) EFI Only ISO
>    - Uses grub 2 menus
>    - Can be burned to optical media
>    - If you want to use this image on a USB device
>      extra steps must be taken in order to format the USB
>      device with fat32, and copy an EFI loader which will
>      in turn load the iso image
> 
> 3) PCBIOS / EFI ISO
>    - This is a hybrid image ISO that will work for case 1 or 2
>      as above with the same restrictions and boot menu types
>      depending on what type of firmware is installed on
>      the hardware or depending on if EFI or "Legacy Boot" is
>      enabled on some UEFI firmwares.
> 
> The syslinux.bbclass is now always required because that is where the
> isohybrid dependencies come from as well as the configuration data for
> the isohybrid.  The isohybrid is the secret sauce which allows the ISO
> to work as optical media or as a disk image on USB or a HDD/SSD.
> 
> [YOCTO #4100]
> 
> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
> ---
>  meta/classes/bootimg.bbclass  |   33 +++++++++++++++++++++------------
>  meta/classes/grub-efi.bbclass |    8 ++++++++
>  2 files changed, 29 insertions(+), 12 deletions(-)
> 
> diff --git a/meta/classes/bootimg.bbclass b/meta/classes/bootimg.bbclass
> index bd211fb..756a287 100644
> --- a/meta/classes/bootimg.bbclass
> +++ b/meta/classes/bootimg.bbclass
> @@ -32,6 +32,7 @@ EXCLUDE_FROM_WORLD = "1"
>  
>  HDDDIR = "${S}/hddimg"
>  ISODIR = "${S}/iso"
> +EFIIMGDIR = "${S}/efi_img"
>  
>  BOOTIMG_VOLUME_ID   ?= "boot"
>  BOOTIMG_EXTRA_SPACE ?= "512"
> @@ -48,15 +49,10 @@ def pcbios(d):
>          pcbios = base_contains("MACHINE_FEATURES", "efi", "0", "1", d)
>      return pcbios
>  
> -def pcbios_class(d):
> -    if d.getVar("PCBIOS", True) == "1":
> -        return "syslinux"
> -    return ""
> -
>  PCBIOS = "${@pcbios(d)}"
> -PCBIOS_CLASS = "${@pcbios_class(d)}"
>  
> -inherit ${PCBIOS_CLASS}
> +# The syslinux is required for the isohybrid command and boot catalog
> +inherit syslinux
>  inherit ${EFI_CLASS}
>  
>  populate() {
> @@ -90,21 +86,34 @@ build_iso() {
>  	fi
>  	if [ "${EFI}" = "1" ]; then
>  		grubefi_iso_populate
> +		build_fat_img ${EFIIMGDIR} ${ISODIR}/efi.img
>  	fi
>  
> -	if [ "${PCBIOS}" = "1" ]; then
> +	# EFI only
> +	if [ "${PCBIOS}" != "1" ] && [ "${EFI}" = "1" ] ; then
> +		mkdir -p ${ISODIR}/${ISOLINUXDIR}
> +		install -m 0644 ${STAGING_DATADIR}/syslinux/isolinux.bin ${ISODIR}${ISOLINUXDIR}

If it's EFI-only, we copy isolinux.bin over? I was under the impression
isolinux.bin was a PCBIOS thing (specifically an executable that
wouldn't even work in an EFI environment). How is this used with an
EFI-only image? What am I missing?

> +	fi
> +
> +	if [ "${PCBIOS}" = "1" ] && [ "${EFI}" != "1" ] ; then
> +		# PCBIOS only media
>  		mkisofs -V ${BOOTIMG_VOLUME_ID} \
>  		        -o ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso \
>  			-b ${ISO_BOOTIMG} -c ${ISO_BOOTCAT} -r \
>  			${MKISOFS_OPTIONS} ${ISODIR}
>  	else
> -		bbnote "EFI-only ISO images are untested, please provide feedback."
> -		mkisofs -V ${BOOTIMG_VOLUME_ID} \
> +		# EFI only OR EFI+PCIBIOS

Nit: s/PCIBIOS/PCBIOS/

...

Thanks,
Jason Wessel - Sept. 17, 2013, 11:08 a.m.
On 09/16/2013 12:30 PM, Darren Hart wrote:
> On Fri, 2013-09-13 at 19:09 -0500, Jason Wessel wrote:
>> -	if [ "${PCBIOS}" = "1" ]; then
>> +	# EFI only
>> +	if [ "${PCBIOS}" != "1" ] && [ "${EFI}" = "1" ] ; then
>> +		mkdir -p ${ISODIR}/${ISOLINUXDIR}
>> +		install -m 0644 ${STAGING_DATADIR}/syslinux/isolinux.bin ${ISODIR}${ISOLINUXDIR}
> 
> If it's EFI-only, we copy isolinux.bin over? I was under the impression
> isolinux.bin was a PCBIOS thing (specifically an executable that
> wouldn't even work in an EFI environment). How is this used with an
> EFI-only image? What am I missing?


There is a bug/feature in the isohybrid that requires it to be in the catalog.  I couldn't figure out how to work around it, so I left it in there.  The EFI firmware skips right over it anyway.  I can add a comment to the bbclass to this effect.



> 
>> +	fi
>> +
>> +	if [ "${PCBIOS}" = "1" ] && [ "${EFI}" != "1" ] ; then
>> +		# PCBIOS only media
>>  		mkisofs -V ${BOOTIMG_VOLUME_ID} \
>>  		        -o ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso \
>>  			-b ${ISO_BOOTIMG} -c ${ISO_BOOTCAT} -r \
>>  			${MKISOFS_OPTIONS} ${ISODIR}
>>  	else
>> -		bbnote "EFI-only ISO images are untested, please provide feedback."
>> -		mkisofs -V ${BOOTIMG_VOLUME_ID} \
>> +		# EFI only OR EFI+PCIBIOS
> 
> Nit: s/PCIBIOS/PCBIOS/


Oops, all fixed in v3. :-)

Jason.

Patch

diff --git a/meta/classes/bootimg.bbclass b/meta/classes/bootimg.bbclass
index bd211fb..756a287 100644
--- a/meta/classes/bootimg.bbclass
+++ b/meta/classes/bootimg.bbclass
@@ -32,6 +32,7 @@  EXCLUDE_FROM_WORLD = "1"
 
 HDDDIR = "${S}/hddimg"
 ISODIR = "${S}/iso"
+EFIIMGDIR = "${S}/efi_img"
 
 BOOTIMG_VOLUME_ID   ?= "boot"
 BOOTIMG_EXTRA_SPACE ?= "512"
@@ -48,15 +49,10 @@  def pcbios(d):
         pcbios = base_contains("MACHINE_FEATURES", "efi", "0", "1", d)
     return pcbios
 
-def pcbios_class(d):
-    if d.getVar("PCBIOS", True) == "1":
-        return "syslinux"
-    return ""
-
 PCBIOS = "${@pcbios(d)}"
-PCBIOS_CLASS = "${@pcbios_class(d)}"
 
-inherit ${PCBIOS_CLASS}
+# The syslinux is required for the isohybrid command and boot catalog
+inherit syslinux
 inherit ${EFI_CLASS}
 
 populate() {
@@ -90,21 +86,34 @@  build_iso() {
 	fi
 	if [ "${EFI}" = "1" ]; then
 		grubefi_iso_populate
+		build_fat_img ${EFIIMGDIR} ${ISODIR}/efi.img
 	fi
 
-	if [ "${PCBIOS}" = "1" ]; then
+	# EFI only
+	if [ "${PCBIOS}" != "1" ] && [ "${EFI}" = "1" ] ; then
+		mkdir -p ${ISODIR}/${ISOLINUXDIR}
+		install -m 0644 ${STAGING_DATADIR}/syslinux/isolinux.bin ${ISODIR}${ISOLINUXDIR}
+	fi
+
+	if [ "${PCBIOS}" = "1" ] && [ "${EFI}" != "1" ] ; then
+		# PCBIOS only media
 		mkisofs -V ${BOOTIMG_VOLUME_ID} \
 		        -o ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso \
 			-b ${ISO_BOOTIMG} -c ${ISO_BOOTCAT} -r \
 			${MKISOFS_OPTIONS} ${ISODIR}
 	else
-		bbnote "EFI-only ISO images are untested, please provide feedback."
-		mkisofs -V ${BOOTIMG_VOLUME_ID} \
+		# EFI only OR EFI+PCIBIOS
+		mkisofs -A ${BOOTIMG_VOLUME_ID} -V ${BOOTIMG_VOLUME_ID} \
 		        -o ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso \
-			-r ${ISODIR}
+			-b ${ISO_BOOTIMG} -c ${ISO_BOOTCAT} \
+			-r ${MKISOFS_OPTIONS} \
+			-eltorito-alt-boot -eltorito-platform efi \
+			-b efi.img -no-emul-boot \
+			${ISODIR}
+		isohybrid_args="-u"
 	fi
 
-	isohybrid ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso
+	isohybrid $isohybrid_args ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso
 
 	cd ${DEPLOY_DIR_IMAGE}
 	rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.iso
diff --git a/meta/classes/grub-efi.bbclass b/meta/classes/grub-efi.bbclass
index c6f5d4e..c21babb 100644
--- a/meta/classes/grub-efi.bbclass
+++ b/meta/classes/grub-efi.bbclass
@@ -41,6 +41,14 @@  grubefi_populate() {
 
 grubefi_iso_populate() {
 	grubefi_populate ${ISODIR}
+	# Build a EFI directory to create efi.img
+	mkdir -p ${EFIIMGDIR}/${EFIDIR}
+	cp ${ISODIR}/${EFIDIR}/* ${EFIIMGDIR}${EFIDIR}
+	cp ${ISODIR}/vmlinuz ${EFIIMGDIR}
+	echo "EFI\\BOOT\\${GRUB_IMAGE}" > ${EFIIMGDIR}/startup.nsh
+	if [ -f "${ISODIR}/initrd" ] ; then
+		cp ${ISODIR}/initrd ${EFIIMGDIR}
+	fi
 }
 
 grubefi_hddimg_populate() {