summaryrefslogtreecommitdiff
path: root/efi/efi_build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'efi/efi_build.sh')
-rw-r--r--efi/efi_build.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/efi/efi_build.sh b/efi/efi_build.sh
new file mode 100644
index 0000000..51f0ff9
--- /dev/null
+++ b/efi/efi_build.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+# Собирает болваночный bootx64.efi (PE32+) ПОРТИРОВАННЫМ тулчейном 6a/6c/6l.
+# Предварительно: ./fetch_ref.sh (достаёт pe64.s/efi.h/mem.h из 9legacy).
+# Требует: BINDIR с 6a/6c/6l (по умолч. ../bin) и PLAN9SRC (плановские include).
+set -e
+cd "$(dirname "$0")"
+BINDIR="${BINDIR:-$PWD/../bin}"
+: "${PLAN9SRC:?export PLAN9SRC — нужны плановские include (amd64/include, sys/include)}"
+IMAGEBASE=0x8000
+export objtype=amd64
+
+[ -f pe64.s ] || { echo "нет pe64.s — сначала ./fetch_ref.sh"; exit 1; }
+# минимальный pe64: MZ+PE заголовки + entry + eficall (без загрузчика ядра)
+head -162 pe64.s > pe64min.s
+
+rm -f *.6 *.out bootx64.efi
+echo "1) 6a pe64min.s"; "$BINDIR/6a" -DIMAGEBASE=$IMAGEBASE pe64min.s
+echo "2) 6c hello.c"; "$BINDIR/6c" -I"$PLAN9SRC/amd64/include" -I"$PLAN9SRC/sys/include" hello.c
+echo "3) 6l link"; "$BINDIR/6l" -l -s -R1 -T$IMAGEBASE -o bootx64.out pe64min.6 hello.6
+echo "4) dd strip 40b (plan9 a.out header) -> PE32+"
+dd if=bootx64.out bs=1 skip=40 of=bootx64.efi 2>/dev/null
+
+echo "bootx64.efi: $(ls -la bootx64.efi | awk '{print $5}') байт"
+python3 - <<'PY'
+d=open('bootx64.efi','rb').read(); po=int.from_bytes(d[0x3c:0x40],'little'); o=po+24
+ok = d[:2]==b'MZ' and d[po:po+4]==b'PE\x00\x00' \
+ and int.from_bytes(d[po+4:po+6],'little')==0x8664 \
+ and int.from_bytes(d[o:o+2],'little')==0x20b \
+ and int.from_bytes(d[o+68:o+70],'little')==10
+print("PE32+ x64 EFI_APPLICATION:", "OK" if ok else "BAD")
+PY
+echo "ESP-образ: python3 mkesp.py bootx64.efi esp.img"