]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Add %.usb target for building EFI-bootable USB (or other) disk images
authorMichael Brown <mcb30@ipxe.org>
Sat, 5 Dec 2015 23:54:10 +0000 (23:54 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 7 Dec 2015 13:08:22 +0000 (13:08 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/i386/Makefile.efi
src/arch/x86/Makefile.efi
src/arch/x86_64/Makefile.efi
src/util/genefidsk [new file with mode: 0755]

index aa809eb5df90ebe53dd8e2c51927034520e54087..37ede65ace3cc29215f1cff9b54ed69fab4e8413 100644 (file)
@@ -8,6 +8,10 @@ ELF2EFI                = $(ELF2EFI32)
 #
 CFLAGS         += -malign-double
 
+# Specify EFI boot file
+#
+EFI_BOOT_FILE  = bootia32.efi
+
 # Include generic EFI Makefile
 #
 MAKEDEPS       += arch/x86/Makefile.efi
index f73bc7d5dc4c53e796fc95226aca563fd1124ebf..c4bc2308c37ff3cd08678326c477c4963c006fca 100644 (file)
@@ -40,3 +40,7 @@ $(BIN)/%.efirom : $(BIN)/%.efidrv $(EFIROM)
 $(BIN)/efidrv.cab : $(BIN)/alldrv.efis # $(ALL_drv.efi) is not yet defined
        $(QM)$(ECHO) "  [CAB] $@"
        $(Q)$(LCAB) -n -q $(ALL_drv.efi) $@
+
+$(BIN)/%.usb : $(BIN)/%.efi
+       $(QM)$(ECHO) "  [GENEFIDSK] $@"
+       $(Q)bash util/genefidsk -o $@ -b $(EFI_BOOT_FILE) $<
index 26b7127803aca889fdb8613468b9497b7e7a6936..12408f862eb1bfce2e205a9d48e51db976ac9609 100644 (file)
@@ -8,6 +8,10 @@ CFLAGS         += -mno-red-zone
 #
 ELF2EFI                = $(ELF2EFI64)
 
+# Specify EFI boot file
+#
+EFI_BOOT_FILE  = bootx64.efi
+
 # Include generic EFI Makefile
 #
 MAKEDEPS       += arch/x86/Makefile.efi
diff --git a/src/util/genefidsk b/src/util/genefidsk
new file mode 100755 (executable)
index 0000000..7064f99
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/sh
+#
+# Generate an EFI bootable disk image
+
+set -e
+
+function help() {
+       echo "Usage: ${0} [OPTIONS] <ipxe.efi>"
+       echo
+       echo "where OPTIONS are:"
+       echo " -h       Show this help"
+       echo " -b       Specify boot file name (e.g. bootx64.efi)"
+       echo " -o FILE  Save disk image to file"
+}
+
+BOOT=bootx64.efi
+
+while getopts "hb:o:" opt; do
+       case ${opt} in
+               h)
+                       help
+                       exit 0
+                       ;;
+               b)
+                       BOOT="${OPTARG}"
+                       ;;
+               o)
+                       OUT="${OPTARG}"
+                       ;;
+       esac
+done
+
+shift $((OPTIND - 1))
+IN=$1
+
+if [ -z "${IN}" ]; then
+       echo "${0}: no input file given" >&2
+       help
+       exit 1
+fi
+
+if [ -z "${OUT}" ]; then
+       echo "${0}: no output file given" >&2
+       help
+       exit 1
+fi
+
+# Create sparse output file
+rm -f ${OUT}
+truncate -s 1440K ${OUT}
+
+# Format disk
+mformat -i ${OUT} -f 1440 ::
+
+# Create directory structure
+mmd -i ${OUT} ::efi
+mmd -i ${OUT} ::efi/boot
+
+# Copy bootable image
+mcopy -i ${OUT} ${IN} ::efi/boot/${BOOT}