Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
U-Boot: the loader started by HakiOS's U-Boot from RAM, as an alternative to Silicium's UEFI
shimoku748ca1a9bef360
diff --git a/Makefile b/Makefileindex d44af8f..a4da578 100644--- a/Makefile+++ b/Makefile@@ -16,6 +16,9 @@# make doctor check this machine and a phone on adb for what HakiOS needs (tools/doctor.sh)# make esp an EFI system partition tree in build/esp: the loader and a payload it reads itself,# to copy to a FAT32 volume (UEFI-native boot, no fastboot; docs/uefi-boot.md)+# make u-boot HakiOS's U-Boot for $(DEVICE) (uefi/u-boot/apply.sh, uefi/u-boot/build.sh; docs/u-boot.md)+# make u-boot-img hakios-u-boot.img: U-Boot as a boot image for fastboot boot, starting the loader from RAM+# make qemu-u-boot make qemu-open's payload booted the phone's way: U-Boot, the hakios command, bootefi## Configuration, the way Linux's make does it (configs/, tools/hakios-config.py; docs/configs.md):# make redwood_defconfig .config from configs/defconfig + redwood_defconfig (devices/redwood/configs/), which is@@ -49,8 +52,10 @@ endifIMAGE_OPTS ?= REST=1ESP_DIR ?= build/espPAYLOAD ?= qemu/payload.bin+# make u-boot-img: the payload put in the image's ramdisk with the loader (none: U-Boot waits for them over fastboot)+UBOOT_PAYLOAD ?=-.PHONY: devices help unpack images kernel loader loader-open hello qemu qemu-open phone prebuilt clean all doctor defconfig config savedefconfig esp+.PHONY: devices help unpack images kernel loader loader-open hello qemu qemu-open qemu-u-boot u-boot u-boot-img phone prebuilt clean all doctor defconfig config savedefconfig esphelp:@awk '{ if (!/^#/) exit; sub(/^# ?/, ""); print }' Makefile@@ -101,6 +106,23 @@ qemu-open: kernel loader-open helloramdisk=userland/hello --cmdline "$(ARGS_OPEN)"qemu/run.sh $(SECS) | tee logs/qemu-open.log+# HakiOS's U-Boot (docs/u-boot.md): the phone's ABL starts it from RAM (fastboot boot), and it starts the loader from+# memory; nothing is flashed. u-boot/ is made once by uefi/u-boot/apply.sh, with every device's U-Boot files.+u-boot:+ [ -d u-boot ] || uefi/u-boot/apply.sh+ uefi/u-boot/build.sh $(DEVICE)++u-boot-img:+ tools/mkubootimg.py -d $(DEVICE) $(if $(wildcard $(UBOOT_PAYLOAD)),-p $(UBOOT_PAYLOAD))++qemu-u-boot: kernel loader-open hello+ [ -f u-boot/build-qemu/u-boot.bin ] || { [ -d u-boot ] || uefi/u-boot/apply.sh; uefi/u-boot/build.sh qemu; }+ mkdir -p logs+ xnuloader/mkpayload.py -o qemu/payload.bin \+ kernel=hakios-kernel \+ ramdisk=userland/hello --cmdline "$(ARGS_OPEN)"+ qemu/run-u-boot.sh $(SECS) | tee logs/qemu-u-boot.log+phone:[ ! -f .config ] || tools/hakios-config.py checkXL_SB_DELAY=8 $(RUNNER_BASE) tools/modem-cycle.sh "$(ARGS)" $(SECS)diff --git a/devices/qemu/u-boot/files/configs/hakios_qemu_defconfig b/devices/qemu/u-boot/files/configs/hakios_qemu_defconfignew file mode 100644index 0000000..123adf4--- /dev/null+++ b/devices/qemu/u-boot/files/configs/hakios_qemu_defconfig@@ -0,0 +1,10 @@+# HakiOS's U-Boot on QEMU's virt machine: the phone's way of starting (the hakios command: the loader and its payload+# from memory, bootefi) on a machine anyone has. qemu/run-u-boot.sh puts the HKUB container in memory at 0x50000000,+# where a phone's ABL would have put its ramdisk.+#include "qemu_arm64_defconfig"++CONFIG_CMD_HAKIOS=y+CONFIG_BOOTDELAY=0+CONFIG_BOOTCOMMAND="hakios load 0x50000000 && hakios boot"+# (a host tool that needs GnuTLS, and capsules are not used here)+# CONFIG_TOOLS_MKEFICAPSULE is not setdiff --git a/docs/getting-started/phone.md b/docs/getting-started/phone.mdindex 5f5e4ce..9edd01a 100644--- a/docs/getting-started/phone.md+++ b/docs/getting-started/phone.md@@ -16,6 +16,9 @@ that you create yourself, and nowhere else. [What is written, exactly](../concep- `adb` and `fastboot` on the PC (Google's platform-tools; on Windows, see [Windows](../windows.md));- the images of [iOS in QEMU](qemu.md#ios-in-qemu) (`userland/system.apfs`), and `make loader` done once;- the phone's own firmware, pulled from it (below). It is the vendor's and is never in the repositories.+- the firmware that starts the loader: HakiOS's U-Boot (`make u-boot`, open source only: [U-Boot](../u-boot.md)), or+ Silicium's UEFI built with your phone's own vendor drivers (`uefi/README.md`). `xl` takes Silicium's when it is built, else+ U-Boot's (`XL_FIRMWARE=` to choose). Either is started from RAM.## Step by stepdiff --git a/docs/index.md b/docs/index.mdindex 19a4915..9e4a777 100644--- a/docs/index.md+++ b/docs/index.md@@ -11,6 +11,7 @@ Where to start:- [On the phone](getting-started/phone.md): the POCO X5 Pro 5G, in RAM with `fastboot boot`, back to Android with a reboot.- [Port a device](porting/index.md): a device is a repository of its own over the common one: a defconfig, a status file, itsdrivers.+- [U-Boot](u-boot.md): the loader started by U-Boot instead of Silicium's UEFI, from RAM, with nothing of the vendor's.- [Reference](reference/drivers.md): every driver, configuration symbol and boot argument, made from the source.## What worksdiff --git a/docs/reference/tools.md b/docs/reference/tools.mdindex 92489b2..c0e8a71 100644--- a/docs/reference/tools.md+++ b/docs/reference/tools.md@@ -16,6 +16,8 @@ Every `make` target is a script below it; run the script itself for its options| `make phone` | a session on the phone with the `.config`'s arguments || `make firmware` | the phone's firmware off the phone (`devices/$(DEVICE)/pull-firmware.sh`) || `make esp` | an EFI system partition tree for a UEFI-native boot ([UEFI boot](../uefi-boot.md)) |+| `make u-boot` / `make u-boot-img` | HakiOS's U-Boot for `$(DEVICE)` / it as a boot image for `fastboot boot` that starts the loader from RAM ([U-Boot](../u-boot.md)) |+| `make qemu-u-boot` | `make qemu-open`'s payload booted the phone's way: U-Boot, the hakios command, `bootefi` ([U-Boot](../u-boot.md)) || `make prebuilt` | refresh `prebuilt/` from what was built || `make clean` | the build output of the kernel, loader and images || `make NAME_defconfig` | `.config` from a defconfig of any repository (`FRAGMENTS="open trace"` on top) |@@ -34,6 +36,7 @@ Every `make` target is a script below it; run the script itself for its options| `docs-gen.py` | the pages of this documentation made from the source | || `drivers-check.py` | `drivers/map` and `drivers/*/conf` agree | [Drivers in the configuration](../drivers-config.md) || `make-kernel.sh` | the kernel build `make kernel` runs, judged by what failed | [Building](../getting-started/building.md) |+| `mkubootimg.py` | HakiOS's U-Boot as an Android boot image, with the loader and a payload in its ramdisk (an `HKUB` container); or the container alone | [U-Boot](../u-boot.md) || `kernel-version.py` | the kernel's version string, `kernel.ver` | [Versioning](../versioning.md) || `provenance-check.py` | nothing in the tree that must not be, and every piece of code that can write to a phone declared | || `metallib.py` | a `.metallib` taken apart | [AIR](../air.md) |diff --git a/docs/u-boot.md b/docs/u-boot.mdnew file mode 100644index 0000000..018da11--- /dev/null+++ b/docs/u-boot.md@@ -0,0 +1,129 @@+# U-Boot++HakiOS's loader can be started by **Das U-Boot** instead of Project Silicium's UEFI. The phone's own bootloader (ABL) starts+U-Boot from RAM with `fastboot boot`, U-Boot finds the loader and its payload **in memory** and starts the loader as a UEFI+application. Nothing is flashed: not `boot`, not any other partition, and a reboot gives the phone back to Android.++Status in one line: **works in QEMU (checked, the whole chain to the kernel's user space); built for the phone, not yet tried on+it.** The sections below say exactly what was run.++## Why++| | Silicium (`mkxnuimg.py`) | U-Boot (`tools/mkubootimg.py`) |+|---|---|---|+| What it is made of | Mu-Silicium and the **phone vendor's own UEFI drivers**, which are not in the repositories: you extract them from your own phone first | open source only: U-Boot's Qualcomm support and the phone's device tree |+| Where the loader comes from | the payload the boot shim copies to `0xF0000000` | the boot image's ramdisk, or U-Boot's own fastboot: the hakios command copies the payload to `0xF0000000` |+| A new loader or payload | a new boot image and `fastboot boot` through ABL again | the same, or sent to the running U-Boot over USB (below), without going back through ABL |+| `xl` (run, ramdisk, log, screenshot) | yes | yes: U-Boot provides the same USB protocol the loader uses under Qualcomm's UEFI |++## The chain++```+ABL ──fastboot boot──> U-Boot (RAM) ──hakios load──> payload at 0xF0000000, loader.efi ──bootefi──> loader ──> XNU+ │ ▲+ └── no payload in the image ────┘ fastboot stage x.hkub; fastboot oem run:hakios load fastboot+```++- **The boot image** (`tools/mkubootimg.py`): the kernel is `gzip(u-boot.bin)` with the phone's Android device tree appended,+ exactly what ABL expects for Silicium's image (header version 1); the ramdisk is an `HKUB` container with the loader and a payload,+ or nothing.+- **U-Boot's device tree** (`devices/redwood/u-boot/files/dts/upstream/src/arm64/qcom/sm7325-xiaomi-redwood.dts`): the panel's+ framebuffer at `0xE1000000` as ABL left it (the loader knows the phone by that address), the keys, USB as a device, UFS, and every+ carve-out of the Android device tree and of Silicium's memory map. The size of RAM is not in it: ABL writes it into the device+ tree it hands over and U-Boot reads it from there.+- **`0xF0000000`, 64 MiB** is reserved in that device tree (`hakios-payload`): nothing in U-Boot takes it, the hakios command+ writes the payload there, and the loader's memory window stays clear of it, as under Silicium.+- **The hakios command** (`uefi/u-boot/files/cmd/hakios.c`):++ | | |+ |---|---|+ | `hakios load` | from the ramdisk ABL loaded (the device tree ABL handed over says where) |+ | `hakios load fastboot` | what the host sent last with `fastboot stage` |+ | `hakios load ADDR [SIZE]` | from anywhere in RAM; a container or a payload says its own size |+ | `hakios boot` | `bootefi` the loader |+ | `hakios info` | what is in memory |++ It takes an `HKUB` container, a bare XNUP payload or a bare `loader.efi`. A payload with an entry `loader.efi` (the one+ `xl enter` makes) brings its loader with it. Every entry of a container carries a CRC-32, and a damaged one is never started.+- **Qualcomm's USB device protocol** (`uefi/u-boot/files/lib/efi_loader/efi_qcom_usb.c`): the loader talks fastboot to the host+ through `EFI_USB_DEVICE_PROTOCOL`, the interface of Qualcomm's UEFI (published in its open-source ABL). U-Boot provides it on its+ own USB gadget stack: the control endpoint is answered from the loader's descriptors, the loader sees its bulk transfers and the+ cable's state. So `xl` works unchanged.+- **What U-Boot will not do**: write the phone's storage. Capsule updates are off (they flash a partition) and U-Boot's watchdog is+ not started (the loader has its own, and keeps U-Boot's boot services while the kernel runs).++## Build++```sh+tools/hakios-device.py sync # devices/redwood and uefi/, as for everything else+make u-boot # = uefi/u-boot/apply.sh (U-Boot at uefi/u-boot/BASE into u-boot/) + uefi/u-boot/build.sh redwood+```++`uefi/u-boot/build.sh` needs an AArch64 GCC (`aarch64-linux-gnu-gcc`, or Arm's `aarch64-none-elf-gcc` from+developer.arm.com; `CROSS_COMPILE=` to name another). The result is `u-boot/build-redwood/u-boot.bin`.++## Run++**With `xl`**, as always:++```sh+XL_FIRMWARE=u-boot ./xl enter # without XL_FIRMWARE: Silicium when its image is built, else U-Boot+./xl ramdisk userland/system.apfs+./xl run+```++**One image, loader and payload inside:**++```sh+xnuloader/mkpayload.py -o payload.bin kernel=hakios-kernel ramdisk=userland/hello --cmdline "-v"+make u-boot-img UBOOT_PAYLOAD=payload.bin # hakios-u-boot.img+fastboot boot hakios-u-boot.img+```++**U-Boot first, then anything over its fastboot** (no new boot image for a new kernel):++```sh+make u-boot-img # no payload: U-Boot waits for the host+fastboot boot hakios-u-boot.img+tools/mkubootimg.py -p payload.bin -c x.hkub # the container alone+fastboot stage x.hkub+fastboot oem run:"hakios load fastboot"+fastboot continue # hakios boot+```++U-Boot's fastboot shows as Google's `18d1:4ee0` (the loader's own is `18d1:d00d`); `fastboot oem console` reads U-Boot's log.+Hold **volume down** while U-Boot starts for its menu (start, fastboot, what is in memory, a shell over USB serial).++## Try it in QEMU (nothing of Apple's)++```sh+make qemu-u-boot # make qemu-open's kernel, loader and hello, booted by U-Boot: qemu/run-u-boot.sh+```++`qemu/run-u-boot.sh` puts an `HKUB` container at `0x50000000` (where a phone's ABL would have put the ramdisk) and boots+`u-boot/build-qemu/u-boot.bin` (`devices/qemu/u-boot/files/configs/hakios_qemu_defconfig`). What it printed (U-Boot 2026.07, the+prebuilt kernel and `hello`):++```+hakios: payload of 16825792 bytes at 0xf0000000+hakios: loader of 65536 bytes at 0x1bd510000+== XNULOADER v3 ==+platform qemu-virt+phys window f4000000 size c8000000, claim status 0+Hello from user space on Darwin!+kernel returned: log at f7bdc9c0, 21629 bytes+```++The same as under edk2 (`qemu/run.sh`), line for line where they are comparable. A bare payload with `loader.efi` in it was run the+same way and gave the same.++## On the phone: what is known and what is not++- U-Boot builds for `redwood` (`hakios_redwood_defconfig`), and the boot image is made the way Silicium's is, which ABL takes.+- **Not yet run on the phone.** What is unknown until it is: that ABL starts it (U-Boot's Linux header instead of the shim's), that+ ABL's memory node is what U-Boot expects, that U-Boot's UFS driver brings the storage up after ABL, and that the DWC3 gadget+ enumerates (`dr_mode = "peripheral"`, high speed). If U-Boot hangs, the menu (volume down) and `fastboot oem console` are the+ ways in; [U-Boot's own notes on phones](https://docs.u-boot.org/en/latest/board/qualcomm/phones.html) say how to bisect a hang.+- What the loader asks Qualcomm's UEFI for and U-Boot does not have: the charger protocols (the loader goes on without the battery+ reading) and `EFI_CPU_ARCH_PROTOCOL` (the loader's exception hook is not installed; a fault in the loader resets the phone instead of+ being logged).diff --git a/docs/uefi-boot.md b/docs/uefi-boot.mdindex 6f137df..6bc7cf9 100644--- a/docs/uefi-boot.md+++ b/docs/uefi-boot.md@@ -61,3 +61,5 @@ A file that is not a payload gives `is not a payload (no XNUP at its start)`, anManager (or a UEFI that boots from a volume) before it can be.- Whether Silicium leaves `0xF0000000` free at the point where the loader runs is not known.- The way to a phone that does not need a host today is the boot image itself, in a boot slot: `docs/install.md`.+- Another UEFI on the phone, all of it open source: HakiOS's U-Boot, started from RAM by ABL, which takes the loader and the+ payload from memory and starts the loader with `bootefi` ([U-Boot](u-boot.md)).diff --git a/qemu/run-u-boot.sh b/qemu/run-u-boot.shnew file mode 100755index 0000000..4b390dd--- /dev/null+++ b/qemu/run-u-boot.sh@@ -0,0 +1,26 @@+#!/bin/bash+# Boot the XNU loader + kernel payload under QEMU the way the phone does with HakiOS's U-Boot: U-Boot (not edk2) is+# the firmware, the loader and its payload are in memory before it starts (an HKUB container at 0x50000000, where a+# phone's ABL would have put its ramdisk), and the hakios command puts the payload at 0xF0000000 and starts the loader.+# usage: run-u-boot.sh [seconds] [extra qemu args...]+# env: QEMU_U_BOOT U-Boot for QEMU (default ../u-boot/build-qemu/u-boot.bin: uefi/u-boot/apply.sh qemu &&+# uefi/u-boot/build.sh qemu)+# QEMU_SMP, QEMU_MEM, QEMU_TB_MB as for run.sh+cd "$(dirname "$0")"+T=${1:-20}; shift+UB=${QEMU_U_BOOT:-../u-boot/build-qemu/u-boot.bin}+[ -f "$UB" ] || { echo "run-u-boot.sh: no $UB (uefi/u-boot/apply.sh qemu && uefi/u-boot/build.sh qemu)"; exit 1; }+[ -f payload.bin ] || { echo "run-u-boot.sh: no payload.bin (make qemu-open makes one)"; exit 1; }+L=../xnuloader/loader.efi; [ -f $L ] || L=../prebuilt/loader.efi+python3 - payload.bin $L u-boot.hkub <<'PY' || exit 1+import os, sys+sys.path.insert(0, os.path.join('..', 'tools'))+from mkubootimg import container+payload, loader, out = sys.argv[1:4]+open(out, 'wb').write(container([('payload', open(payload, 'rb').read()), ('loader', open(loader, 'rb').read())]))+PY+timeout "$T" qemu-system-aarch64 -M virt,gic-version=3 -cpu cortex-a76 -smp ${QEMU_SMP:-1} -m ${QEMU_MEM:-6G} \+ -accel tcg,tb-size=${QEMU_TB_MB:-384} \+ -bios "$UB" \+ -device loader,file=u-boot.hkub,addr=0x50000000,force-raw=on \+ -display none -serial stdio -monitor none -no-reboot "$@" 2>&1diff --git a/tools/mkubootimg.py b/tools/mkubootimg.pynew file mode 100755index 0000000..a7ee06a--- /dev/null+++ b/tools/mkubootimg.py@@ -0,0 +1,114 @@+#!/usr/bin/env python3+"""+HakiOS's U-Boot as an Android boot image for `fastboot boot`: started from RAM by the phone's own bootloader (ABL),+nothing flashed. U-Boot takes the HakiOS loader and its payload from the image's ramdisk and starts them from memory+(the hakios command, uefi/u-boot/files/cmd/hakios.c); the boot partition is never read or written.++ kernel = gzip(u-boot.bin) + the phone's Android device tree (what ABL expects, as for Silicium's image)+ ramdisk = an "HKUB" container: loader.efi and an XNUP payload (or nothing: U-Boot then waits for them over fastboot)++The same container on its own (-c) is what the host sends to a U-Boot that is already running:++ fastboot stage x.hkub && fastboot oem run:"hakios load fastboot" && fastboot continue++ HKUB, little-endian: u32 magic "HKUB", u32 version 1, u32 count, u32 header size,+ count x { char name[16]; u32 offset; u32 size; u32 crc32; u32 reserved }, entries 4 KiB aligned++usage: mkubootimg.py [-d DEVICE] [-u u-boot.bin] [-l loader.efi] [-p payload.bin] [-o out.img] [-c out.hkub]+ mkubootimg.py -p payload.bin -c x.hkub the container alone+"""+import argparse, gzip, os, struct, subprocess, sys, zlib++HERE = os.path.dirname(os.path.abspath(__file__))+ROOT = os.path.dirname(HERE)+HKUB_MAGIC, HKUB_VERSION = b'HKUB', 1+PAYLOAD_MAX = 0x04000000 - 0x100000 # the loader's payload area less the panic log (xnuloader/loader.c)+++def container(entries):+ """entries: [(name, bytes)] -> an HKUB container"""+ header_size = 16 + 32 * len(entries)+ offset = (header_size + 0xfff) & ~0xfff+ table, body = b'', b''+ for name, data in entries:+ assert len(name) < 16+ table += struct.pack('<16sIIII', name.encode(), offset + len(body), len(data), zlib.crc32(data), 0)+ body += data + b'\0' * (-len(data) % 0x1000)+ head = struct.pack('<4sIII', HKUB_MAGIC, HKUB_VERSION, len(entries), header_size) + table+ return head + b'\0' * (offset - len(head)) + body+++def main():+ ap = argparse.ArgumentParser(description=__doc__.split('\n\n')[0])+ ap.add_argument('-d', '--device', default='redwood')+ ap.add_argument('-u', '--u-boot', help='default: u-boot/build-DEVICE/u-boot.bin, else devices/DEVICE/prebuilt/u-boot.bin')+ ap.add_argument('-l', '--loader', help='loader.efi (default: xnuloader/loader.efi, else prebuilt/loader.efi)')+ ap.add_argument('-p', '--payload', help='an XNUP payload (xnuloader/mkpayload.py)')+ ap.add_argument('-o', '--output', help='the boot image (default: hakios-u-boot.img)')+ ap.add_argument('-c', '--container', help='write the HKUB container on its own (for fastboot stage); without -o, only it')+ ap.add_argument('--no-ramdisk', action='store_true', help='U-Boot only: it waits for the loader over fastboot')+ args = ap.parse_args()++ dev = os.path.join(ROOT, 'devices', args.device)+ ub = args.u_boot+ if not ub:+ for c in (os.path.join(ROOT, 'u-boot', f'build-{args.device}', 'u-boot.bin'),+ os.path.join(dev, 'prebuilt', 'u-boot.bin')):+ if os.path.isfile(c):+ ub = c+ break+ else:+ sys.exit(f'mkubootimg.py: no u-boot.bin for {args.device}: uefi/u-boot/apply.sh {args.device} && '+ f'uefi/u-boot/build.sh {args.device}')+ loader = args.loader+ if not loader:+ loader = os.path.join(ROOT, 'xnuloader', 'loader.efi')+ if not os.path.isfile(loader):+ loader = os.path.join(ROOT, 'prebuilt', 'loader.efi')+ dtb = os.path.join(dev, 'prebuilt', 'device-tree.dtb')+ mkbootimg = os.path.join(dev, 'prebuilt', 'mkbootimg.py')+ for path in (ub, loader, dtb, mkbootimg):+ if not os.path.isfile(path):+ sys.exit(f'mkubootimg.py: {path} not found')++ u_boot = open(ub, 'rb').read()+ # ABL starts it as an arm64 Linux kernel: the header's magic "ARM\x64" at 0x38+ if u_boot[0x38:0x3c] != b'ARM\x64':+ sys.exit(f'mkubootimg.py: {ub} has no Linux image header (CONFIG_LINUX_KERNEL_IMAGE_HEADER)')++ entries = []+ if not args.no_ramdisk:+ efi = open(loader, 'rb').read()+ if efi[:2] != b'MZ':+ sys.exit(f'mkubootimg.py: {loader} is not a UEFI application')+ if args.payload:+ data = open(args.payload, 'rb').read()+ if data[:4] != b'XNUP' or len(data) > PAYLOAD_MAX:+ sys.exit(f'mkubootimg.py: {args.payload}: not an XNUP payload, or over {PAYLOAD_MAX} bytes')+ entries.append(('payload', data))+ # after the payload: a loader.efi the payload carries (xl enter's) gives way to this one+ entries.append(('loader', efi))+ hkub = container(entries) if entries else b''+ if args.container:+ open(args.container, 'wb').write(hkub)+ print(f'{args.container}: {len(hkub)} bytes ({", ".join(n for n, _ in entries)})')+ if not args.output:+ return # the container alone, for a U-Boot that is already running++ out = args.output or os.path.join(ROOT, 'hakios-u-boot.img')+ kernel, ramdisk = out + '.kernel~', out + '.ramdisk~'+ open(kernel, 'wb').write(gzip.compress(u_boot, 6) + open(dtb, 'rb').read())+ # no container: one zero byte for ABL, which hakios load does not take, so U-Boot waits for the host instead+ open(ramdisk, 'wb').write(hkub or b'\0')+ try:+ subprocess.check_call([sys.executable, mkbootimg, '--kernel', kernel, '--ramdisk', ramdisk,+ '--header_version', '1', '-o', out])+ finally:+ os.unlink(kernel)+ os.unlink(ramdisk)+ print(f'{out}: {os.path.getsize(out)} bytes (u-boot {len(u_boot)}, ramdisk {len(hkub)}: '+ f'{", ".join(f"{n} {len(d)}" for n, d in entries) or "none"})')+++if __name__ == '__main__':+ main()diff --git a/xl b/xlindex 7de0132..eebf9e1 100755--- a/xl+++ b/xl@@ -34,6 +34,8 @@# there from Android): a long session of runs never waits for Android to start# XL_REBOOT_AFTER=1 when the run is over, send the phone back to Android (it charges there; in the loader it does not,# and its screen stays on: a phone left in the loader overnight is a flat one by morning)+# XL_FIRMWARE=u-boot|silicium what the phone's bootloader starts the loader with (default: Silicium's UEFI when its+# image is built, else HakiOS's U-Boot: docs/u-boot.md); either way from RAM, nothing is flashed# XL_SB_DELAY seconds SpringBoard waits before it starts (default 8; see userland/src/inject_sb.c)# Among XL_CMDLINE, for the phone: bootcpu=7 runs the kernel on the biggest core instead of# the small one the firmware starts on (the loader then watches from the first core, and a@@ -119,6 +121,20 @@ recover_phone() {return 1}+# What the phone's bootloader starts the loader with: Project Silicium's UEFI (mkxnuimg.py) or HakiOS's U-Boot+# (tools/mkubootimg.py, docs/u-boot.md). XL_FIRMWARE says which; without it, Silicium's when its image has been built+# (it is made from the phone's own vendor drivers and is not in the repository), else U-Boot's.+firmware() {+ case "${XL_FIRMWARE:-}" in+ u-boot|silicium) echo "$XL_FIRMWARE"; return ;;+ esac+ if [ -f Mu-Silicium/Build/redwoodPkg/RELEASE_CLANGPDB/FV/SILICIUM_UEFI.fd ] || [ -f devices/redwood/prebuilt/SILICIUM_UEFI.fd ]; then+ echo silicium+ else+ echo u-boot+ fi+}+enter() {case "$(state)" inloader) return 0 ;;@@ -129,8 +145,11 @@ enter() {[ "$(state)" = absent ] && { echo "xl: phone not reachable"; return 1; }enter; return ;;esac- xnuloader/mkpayload.py -o usb-payload.bin loader.efi=$L --usb >/dev/null &&- ./mkxnuimg.py -p usb-payload.bin -o xnu-usb.img >/dev/null || { echo "xl: image build failed"; return 1; }+ xnuloader/mkpayload.py -o usb-payload.bin loader.efi=$L --usb >/dev/null || { echo "xl: payload build failed"; return 1; }+ case "$(firmware)" in+ u-boot) tools/mkubootimg.py -d "${DEVICE:-redwood}" -l $L -p usb-payload.bin -o xnu-usb.img >/dev/null ;;+ *) ./mkxnuimg.py -p usb-payload.bin -o xnu-usb.img >/dev/null ;;+ esac || { echo "xl: image build failed ($(firmware))"; return 1; }# Right after the phone enters fastboot the first "boot" is sometimes not taken: try twice.local tryfor try in 1 2; do