1 Commits
Author SHA1 Message Date
Michael Brown dd68e283f8 [build] Allow for building EFI ISOs without syslinux
The isohybrid tool (that creates a partition table to describe the ESP
embedded within the ISO image) relies upon the existence of the
x86-only isolinux.bin file.  This file may not be available on non-x86
build hosts.

We already allow for the possibility that isohybrid may not be present
on the build host, in which case we fall back to creating a non-hybrid
ISO image.  Make a similar allowance for the possibility that the
isolinux.bin file may not be present: require its existence only if we
are attempting to build a BIOS-bootable image, or if we will be
attempting to use isohybrid to create a hybrid ISO image.

Reported-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2023-07-10 13:51:33 +01:00
+34 -83
View File
@@ -4,7 +4,6 @@
set -e set -e
set -u set -u
set -x
# Print usage message # Print usage message
# #
@@ -18,58 +17,28 @@ help() {
echo " -s SCRIPT use executable script" echo " -s SCRIPT use executable script"
} }
# Get big-endian hex value from binary file
#
get_be() {
local FILENAME
local OFFSET
local LEN
FILENAME="${1}"
OFFSET="${2}"
LEN="${3}"
od -j "${OFFSET}" -N "${LEN}" -A n -t x1 -- "${FILENAME}" | tr -d " "
}
# Get little-endian hex value from binary file
#
get_le() {
local FILENAME
local OFFSET
local LEN
local BYTE
local VALUE
FILENAME="${1}"
OFFSET="${2}"
LEN="${3}"
VALUE=""
while [ "${LEN}" -gt 0 ] ; do
LEN=$(( "${LEN}" - 1 ))
BYTE=$(get_be "${FILENAME}" $(( "${OFFSET}" + "${LEN}" )) 1)
VALUE="${VALUE}${BYTE}"
done
echo "${VALUE}"
}
# Get hex byte from binary file # Get hex byte from binary file
# #
get_byte() { get_byte() {
get_be "${1}" "${2}" 1 local FILENAME
local OFFSET
FILENAME="${1}"
OFFSET="${2}"
od -j "${OFFSET}" -N 1 -A n -t x1 -- "${FILENAME}" | tr -d " "
} }
# Get little-endian hex word from binary file # Get hex word from binary file
# #
get_word() { get_word() {
get_le "${1}" "${2}" 2 local FILENAME
} local OFFSET
# Get little-endian hex dword from binary file FILENAME="${1}"
# OFFSET="${2}"
get_dword() {
get_le "${1}" "${2}" 4 od -j "${OFFSET}" -N 2 -A n -t x1 -- "${FILENAME}" | tr -d " "
} }
# Get appropriate EFI boot filename for CPU architecture # Get appropriate EFI boot filename for CPU architecture
@@ -82,31 +51,31 @@ efi_boot_name() {
FILENAME="${1}" FILENAME="${1}"
MZSIG=$(get_word "${FILENAME}" 0) MZSIG=$(get_word "${FILENAME}" 0)
if [ "${MZSIG}" != "5a4d" ] ; then if [ "${MZSIG}" != "4d5a" ] ; then
echo "${FILENAME}: invalid MZ header" >&2 echo "${FILENAME}: invalid MZ header" >&2
exit 1 exit 1
fi fi
PEOFF=$(get_byte "${FILENAME}" 0x3c) PEOFF=$(get_byte "${FILENAME}" 0x3c)
PESIG=$(get_word "${FILENAME}" 0x${PEOFF}) PESIG=$(get_word "${FILENAME}" 0x${PEOFF})
if [ "${PESIG}" != "4550" ] ; then if [ "${PESIG}" != "5045" ] ; then
echo "${FILENAME}: invalid PE header" >&2 echo "${FILENAME}: invalid PE header" >&2
exit 1 exit 1
fi fi
ARCH=$(get_word "${FILENAME}" $(( 0x${PEOFF} + 4 )) ) ARCH=$(get_word "${FILENAME}" $(( 0x${PEOFF} + 4 )) )
case "${ARCH}" in case "${ARCH}" in
"014c" ) "4c01" )
echo "BOOTIA32.EFI" echo "BOOTIA32.EFI"
;; ;;
"8664" ) "6486" )
echo "BOOTX64.EFI" echo "BOOTX64.EFI"
;; ;;
"01c2" ) "c201" )
echo "BOOTARM.EFI" echo "BOOTARM.EFI"
;; ;;
"6264" ) "6462" )
echo "BOOTLOONGARCH64.EFI" echo "BOOTLOONGARCH64.EFI"
;; ;;
"aa64" ) "64aa" )
echo "BOOTAA64.EFI" echo "BOOTAA64.EFI"
;; ;;
* ) * )
@@ -148,28 +117,6 @@ copy_syslinux_file() {
return 1 return 1
} }
# Create EFI boot partition
#
create_esp() {
local FILENAME
local BOOTCAT
local PLATFORM
local START
local COUNT
FILENAME="${1}"
BOOTCAT=$(( 0x$(get_dword "${FILENAME}" 0x8847) * 0x800 ))
PLATFORM=$(get_byte "${FILENAME}" $(( ${BOOTCAT} + 0x01 )) )
if [ "${PLATFORM}" != "ef" ] ; then
echo "${FILENAME}: missing EFI boot catalog" >&2
exit 1
fi
START=$(( 0x$(get_dword "${FILENAME}" $(( ${BOOTCAT} + 0x28 )) ) * 4 ))
COUNT=$(( 0x$(get_word "${FILENAME}" $(( ${BOOTCAT} + 0x26 )) ) * 4 ))
echo "${START},${COUNT},0xef;" | sfdisk -f -w never "${FILENAME}"
}
# Parse command-line options # Parse command-line options
# #
OUTFILE= OUTFILE=
@@ -282,19 +229,24 @@ done
# Configure ISO image, if applicable # Configure ISO image, if applicable
# #
# Note that the BIOS boot files are required even for an EFI-only ISO, # Note that the BIOS boot files are required even for an EFI-only
# since isohybrid will refuse to work without them. # hybrid ISO, since isohybrid will refuse to work without them.
# #
if [ -n "${ISOIMG}" ] ; then if [ -n "${ISOIMG}" ] ; then
ISOARGS="-J -R -l" ISOARGS="-J -R -l"
if [ -n "${LKRN}" ] ; then if isohybrid --version >/dev/null 2>&1 ; then
ISOHYBRID=isohybrid
else
ISOHYBRID=
fi
if [ -n "${LKRN}" -o -n "${ISOHYBRID}" ] ; then
copy_syslinux_file "isolinux.bin" "${ISODIR}" copy_syslinux_file "isolinux.bin" "${ISODIR}"
copy_syslinux_file "ldlinux.c32" "${ISODIR}" 2>/dev/null || true copy_syslinux_file "ldlinux.c32" "${ISODIR}" 2>/dev/null || true
ISOARGS="${ISOARGS} -no-emul-boot -eltorito-boot isolinux.bin" ISOARGS="${ISOARGS} -no-emul-boot -eltorito-boot isolinux.bin"
ISOARGS="${ISOARGS} -boot-load-size 4 -boot-info-table" ISOARGS="${ISOARGS} -boot-load-size 4 -boot-info-table"
fi if [ -n "${EFI}" ] ; then
if [ -n "${LKRN}" -a -n "${EFI}" ] ; then ISOARGS="${ISOARGS} -eltorito-alt-boot"
ISOARGS="${ISOARGS} -eltorito-alt-boot" fi
fi fi
if [ -n "${EFI}" ] ; then if [ -n "${EFI}" ] ; then
ISOARGS="${ISOARGS} -no-emul-boot -e esp.img" ISOARGS="${ISOARGS} -no-emul-boot -e esp.img"
@@ -367,8 +319,7 @@ if [ -n "${ISOIMG}" ] ; then
-appid "iPXE - Open Source Network Boot Firmware" \ -appid "iPXE - Open Source Network Boot Firmware" \
-publisher "ipxe.org" -sysid "iPXE" -o "${ISOIMG}" \ -publisher "ipxe.org" -sysid "iPXE" -o "${ISOIMG}" \
${ISOARGS} "${ISODIR}" ${ISOARGS} "${ISODIR}"
create_esp "${ISOIMG}" if [ -n "${ISOHYBRID}" ] ; then
if isohybrid --version >/dev/null 2>&1 ; then
ISOHYBRIDARGS= ISOHYBRIDARGS=
if [ -n "${EFI}" ] ; then if [ -n "${EFI}" ] ; then
ISOHYBRIDARGS="${ISOHYBRIDARGS} --uefi" ISOHYBRIDARGS="${ISOHYBRIDARGS} --uefi"
@@ -376,7 +327,7 @@ if [ -n "${ISOIMG}" ] ; then
if [ -n "${SOURCE_DATE_EPOCH:-}" ] ; then if [ -n "${SOURCE_DATE_EPOCH:-}" ] ; then
ISOHYBRIDARGS="${ISOHYBRIDARGS} --id ${SOURCE_DATE_EPOCH}" ISOHYBRIDARGS="${ISOHYBRIDARGS} --id ${SOURCE_DATE_EPOCH}"
fi fi
isohybrid ${ISOHYBRIDARGS} "${ISOIMG}" "${ISOHYBRID}" ${ISOHYBRIDARGS} "${ISOIMG}"
fi fi
fi fi