Compare commits

..

1 Commits

Author SHA1 Message Date
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

View File

@ -4,7 +4,6 @@
set -e
set -u
set -x
# Print usage message
#
@ -18,58 +17,28 @@ help() {
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_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_le "${1}" "${2}" 2
}
local FILENAME
local OFFSET
# Get little-endian hex dword from binary file
#
get_dword() {
get_le "${1}" "${2}" 4
FILENAME="${1}"
OFFSET="${2}"
od -j "${OFFSET}" -N 2 -A n -t x1 -- "${FILENAME}" | tr -d " "
}
# Get appropriate EFI boot filename for CPU architecture
@ -82,31 +51,31 @@ efi_boot_name() {
FILENAME="${1}"
MZSIG=$(get_word "${FILENAME}" 0)
if [ "${MZSIG}" != "5a4d" ] ; then
if [ "${MZSIG}" != "4d5a" ] ; then
echo "${FILENAME}: invalid MZ header" >&2
exit 1
fi
PEOFF=$(get_byte "${FILENAME}" 0x3c)
PESIG=$(get_word "${FILENAME}" 0x${PEOFF})
if [ "${PESIG}" != "4550" ] ; then
if [ "${PESIG}" != "5045" ] ; then
echo "${FILENAME}: invalid PE header" >&2
exit 1
fi
ARCH=$(get_word "${FILENAME}" $(( 0x${PEOFF} + 4 )) )
case "${ARCH}" in
"014c" )
"4c01" )
echo "BOOTIA32.EFI"
;;
"8664" )
"6486" )
echo "BOOTX64.EFI"
;;
"01c2" )
"c201" )
echo "BOOTARM.EFI"
;;
"6264" )
"6462" )
echo "BOOTLOONGARCH64.EFI"
;;
"aa64" )
"64aa" )
echo "BOOTAA64.EFI"
;;
* )
@ -148,28 +117,6 @@ copy_syslinux_file() {
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
#
OUTFILE=
@ -282,19 +229,24 @@ done
# Configure ISO image, if applicable
#
# Note that the BIOS boot files are required even for an EFI-only ISO,
# since isohybrid will refuse to work without them.
# Note that the BIOS boot files are required even for an EFI-only
# hybrid ISO, since isohybrid will refuse to work without them.
#
if [ -n "${ISOIMG}" ] ; then
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 "ldlinux.c32" "${ISODIR}" 2>/dev/null || true
ISOARGS="${ISOARGS} -no-emul-boot -eltorito-boot isolinux.bin"
ISOARGS="${ISOARGS} -boot-load-size 4 -boot-info-table"
fi
if [ -n "${LKRN}" -a -n "${EFI}" ] ; then
ISOARGS="${ISOARGS} -eltorito-alt-boot"
if [ -n "${EFI}" ] ; then
ISOARGS="${ISOARGS} -eltorito-alt-boot"
fi
fi
if [ -n "${EFI}" ] ; then
ISOARGS="${ISOARGS} -no-emul-boot -e esp.img"
@ -367,8 +319,7 @@ if [ -n "${ISOIMG}" ] ; then
-appid "iPXE - Open Source Network Boot Firmware" \
-publisher "ipxe.org" -sysid "iPXE" -o "${ISOIMG}" \
${ISOARGS} "${ISODIR}"
create_esp "${ISOIMG}"
if isohybrid --version >/dev/null 2>&1 ; then
if [ -n "${ISOHYBRID}" ] ; then
ISOHYBRIDARGS=
if [ -n "${EFI}" ] ; then
ISOHYBRIDARGS="${ISOHYBRIDARGS} --uefi"
@ -376,7 +327,7 @@ if [ -n "${ISOIMG}" ] ; then
if [ -n "${SOURCE_DATE_EPOCH:-}" ] ; then
ISOHYBRIDARGS="${ISOHYBRIDARGS} --id ${SOURCE_DATE_EPOCH}"
fi
isohybrid ${ISOHYBRIDARGS} "${ISOIMG}"
"${ISOHYBRID}" ${ISOHYBRIDARGS} "${ISOIMG}"
fi
fi