aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2021-01-19 23:47:44 +0000
committerMichael Brown <mcb30@ipxe.org>2021-01-19 23:49:58 +0000
commit117353815595c46a29a3aebec966ab94f6a4b3c8 (patch)
treef894a939c56908954f2befcdd3e1103cb32a5145
parent3a9621a6fb9d7fda9dcab9efde6b5c586ceda470 (diff)
downloadipxe-117353815595c46a29a3aebec966ab94f6a4b3c8.zip
ipxe-117353815595c46a29a3aebec966ab94f6a4b3c8.tar.gz
ipxe-117353815595c46a29a3aebec966ab94f6a4b3c8.tar.bz2
[build] Allow genfsimg to be used on third party UEFI binaries
Extract the PE header offset from the MZ header rather than assuming a fixed offset as used in the binaries created by the iPXE build system. This allows genfsimg to be used to create bootable filesystem images from third party UEFI binaries such as the UEFI shell. Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rwxr-xr-xsrc/util/genfsimg24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/util/genfsimg b/src/util/genfsimg
index a1fad24..5d0a2bd 100755
--- a/src/util/genfsimg
+++ b/src/util/genfsimg
@@ -16,6 +16,18 @@ help() {
echo " -p PAD pad filesystem (in kB)"
}
+# Get hex byte from binary file
+#
+get_byte() {
+ local FILENAME
+ local OFFSET
+
+ FILENAME="${1}"
+ OFFSET="${2}"
+
+ od -j "${OFFSET}" -N 1 -A n -t x1 -- "${FILENAME}" | tr -d " "
+}
+
# Get hex word from binary file
#
get_word() {
@@ -37,12 +49,18 @@ efi_boot_name() {
FILENAME="${1}"
- PESIG=$(get_word "${FILENAME}" 192)
+ MZSIG=$(get_word "${FILENAME}" 0)
+ 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}" != "5045" ] ; then
- echo "${FILENAME}: not an EFI executable" >&2
+ echo "${FILENAME}: invalid PE header" >&2
exit 1
fi
- ARCH=$(get_word "${FILENAME}" 196)
+ ARCH=$(get_word "${FILENAME}" $(( "0x${PEOFF}" + 4 )) )
case "${ARCH}" in
"4c01" )
echo "BOOTIA32.EFI"