Skip to content

UEFI firmware ​

The UEFI firmware port comes from Mu-Silicium. It supplies the services UniXNU and DarwinBoot use.

For repeated builds, save paths in unixnu.local.toml. After changing boot arguments, rebuild the payload and boot image using the argument workflow. Follow the green-bar diagnosis for a stall at loader handoff.

Procedure ​

  1. Prepare the device's Mu-Silicium checkout, vendor inputs and submodules. Match board.toml to its device configuration, DSC and FD path.
  2. Complete required integration: add each module to the DSC/FDF and map its libraries. The payload needs its RAM-disk, DiskIo and FAT drivers.
  3. Save the firmware path in local build configuration and run the firmware build. Confirm the output FD path and size.
  4. Build the payload, then follow boot-image integration. Check boot/boot.json and the packaged payload before booting.
  5. On the device, confirm the configured menu entry and DarwinBoot handoff using verification. If the entry is absent, work through payload discovery.

CLANGPDB requires matching Clang and LLD releases. CLANG_BIN must contain executable clang, lld-link, llvm-lib and llvm-rc. The firmware toolchain is checked before other requested build stages.

Required integration ​

Build firmware from the UniXNU checkout after selecting the device:

sh
./unixnu defconfig <device>_defconfig -D ../UniXNU-<device>
./unixnu build firmware --uefi ../uefi-<device>

The firmware needs all of these modules in its DSC [Components] and FDF firmware volume:

ModulePurpose
UniXNUPkg/Application/UniXNU/UniXNU.infBoot menu and configuration reader
UniXNUPkg/Driver/UniXNUDxe/UniXNUDxe.infFirmware boot option registration
DarwinBootPkg/Driver/DarwinBoot.infXNU loader
UniXNUPkg/Driver/UniXNURamDiskDxe/UniXNURamDiskDxe.infPublish the Mu-Silicium FDT initrd as a read-only block device
MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.infDisk access for the filesystem driver
FatPkg/EnhancedFatDxe/Fat.infExpose the payload's FAT filesystem

List each path directly under DSC [Components]; use INF <path> in the FDF. Map the shared driver's libraries in DSC [LibraryClasses]:

ini
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
FdtLib|MdePkg/Library/BaseFdtLib/BaseFdtLib.inf

Add PartitionDxe when the payload uses a partition table. The FAT driver also needs the platform's Unicode collation service. The reference firmware's Include/DXE.inc contains these dependencies.

UniXNURamDiskDxe is shared by devices using Mu-Silicium's FDT handoff. Its source is in UniXNU's package/UniXNUPkg/Driver/UniXNURamDiskDxe/. Board memory reservations and memory expansion remain in the firmware platform.

A supplied .fd must contain this integration and match the board's firmware base and size. ./unixnu bootimg --fd <file> packages the supplied firmware. Rebuild the FD after changing its DSC, FDF or drivers.

Build the payload with the selected device's inputs, then pack the image:

sh
./unixnu build payload --unique-chip-id <hex> --trust-cache <file> --data-ramdisk <seed>
./unixnu bootimg --uefi ../uefi-<device> --dtb /path/to/firmware.dtb

Use the options required by the device's payload profile. See payload inputs.

Firmware logs ​

Follow log exporter integration to add Advanced Logger and AdvancedLogDxe, then enable the Tools menu. Use QR capture to save firmware output before storage adaptation and kernel handoff.

Payload discovery ​

The Android bootloader places the FAT payload in RAM and writes /chosen/linux,initrd-start and linux,initrd-end into the firmware FDT. Each property is a 32-bit or 64-bit big-endian address. The range must contain complete 512-byte sectors and remain reserved while UEFI uses it.

Mu-Silicium SEC preserves the incoming FDT address as a UINT64 in the entry-argument HOB (DAEE82E6-8090-4E72-BFB9-78C13CD4E359). UniXNURamDiskDxe reads this handoff and publishes Block I/O. DiskIoDxe and the FAT driver expose EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, allowing UniXNU to read \EFI\UniXNU\unixnu.toml and list its entries.

If the menu appears without the configured entries, check:

  1. boot/boot.json reports a nonzero ramdisk_bytes value.
  2. The FD contains UniXNURamDiskDxe, DiskIoDxe and the FAT driver.
  3. The firmware FDT has valid initrd start and end properties.
  4. The serial log contains UNIXNURAMDISK: initrd block device with a successful status.
  5. The payload FAT volume contains EFI/UniXNU/unixnu.toml and its referenced files.

The RAM disk driver must be embedded in the firmware so the payload can be discovered before its configuration is read.

Required services ​

ServiceConsumer
EFI_GRAPHICS_OUTPUT_PROTOCOLUniXNU menu, DarwinBoot framebuffer handoff, XNU console
EFI_SIMPLE_TEXT_IN_PROTOCOLUniXNU menu input
EFI_SIMPLE_FILE_SYSTEM_PROTOCOLConfiguration, payload and kernel files
EFI_BLOCK_IO_PROTOCOLUserdata partition and block slices
EFI_SERIAL_IO_PROTOCOLLogs on boards with a UART
EFI_ACPI_TABLE_PROTOCOLOptional ACPI table injection
EFI_FIRMWARE_VOLUME2_PROTOCOLUniXNUDxe boot option registration

A board that lacks one of these services limits the stages it can run. Add the driver to the firmware volume or to the UniXNU payload before the dependent stage.

Mu-Silicium layout ​

Mu-Silicium/
  BootShim/
    BootShim.S
  Resources/
    Configs/<device>.toml
    Scripts/mkbootimg.py
  Platforms/<Vendor>/<device>Pkg/
    <device>.dsc
    <device>.fdf
  Silicon/
  Common/

The UniXNU driver reads Resources/Configs/<name>.toml and <device>.dsc. It uses Resources/Scripts/mkbootimg.py for the boot image.

Device configuration ​

Resources/Configs/<device>.toml supplies the addresses and image parameters:

toml
[boot_shim]
requires_kernel_header = true

[uefi_fd]
base = 0x00000000
size = 0x000000

[boot_image_kernel]
kernel_compression = "gzip"
append_dtb = true

[boot_image]
header_version = 0
base = 0x00000000
kernel_offset = 0x8000
tags_offset = 0x1e00000
pagesize = 4096
KeyMeaning
boot_shim.requires_kernel_headerThe bootloader checks the ARM64 header at the start of the image
uefi_fd.basePhysical address where the firmware volume is loaded
uefi_fd.sizeExact firmware volume size
boot_image_kernel.kernel_compressionCompression of the shim and firmware volume
boot_image_kernel.append_dtbAppend the device tree to the kernel field
boot_image.*Android boot image header parameters

The firmware base and size are compiled into BootShim. They are also checked when the boot image is packed.

DSC and FDF ​

The DSC lists the packages, libraries and components. The FDF places the components in the firmware volume.

UniXNU packages use PACKAGES_PATH:

{uefi}:{tree}/package:{tree}/drivers/DarwinBoot:{edk2}:...

{uefi} is the Mu-Silicium checkout, {tree} is the assembled build tree, and {edk2} is the Mu_Basecore checkout. The board file lists every package path.

UniXNU and DarwinBoot are included through their INFs:

UniXNUPkg/Application/UniXNU/UniXNU.inf
UniXNUPkg/Driver/UniXNUDxe/UniXNUDxe.inf
UniXNUPkg/Driver/UniXNURamDiskDxe/UniXNURamDiskDxe.inf
DarwinBootPkg/Driver/DarwinBoot.inf

Embed these modules in the firmware volume for an initrd payload. Place the configuration and kernel files in the payload FAT volume.

Preflight ​

[firmware] preflight lists scripts in the build tree that run before the EDK II build. A preflight script checks vendor inputs, firmware partitions or board files. --skip-preflight skips them.

Vendor inputs ​

A Mu-Silicium port needs the vendor binaries for the board, for example:

  • UEFI DXE drivers for storage, display, input or power.
  • ACPI tables.
  • Firmware partition images.
  • Configuration data.

The board preflight script validates the files and their hashes.

Submodules and patches ​

Mu-Silicium uses submodules for shared trees. The board file lists the ones it needs:

toml
[firmware]
submodules = ["Common/Mu", "Silicon/Silicium", "Silicon/Qualcomm"]
patches = ["Resources/MuPatches/Gic-Spurious.patch"]

A patch in patches is applied to the shared edk2 tree for the build and reverted afterwards. The driver checks each patch with git apply --check before applying it.

Build ​

With the device repository selected:

sh
./unixnu build firmware --uefi /path/to/Mu-Silicium

The driver:

  1. Runs the preflight scripts.
  2. Initializes the listed submodules.
  3. Builds BaseTools when GenFw is absent.
  4. Applies the board patches.
  5. Runs EDK II build with the DSC, AARCH64, CLANGPDB and the board defines.
  6. Reverts the patches.
  7. Checks the firmware volume size and path.

The output path comes from [firmware] fd:

toml
fd = "Build/<device>Pkg/{target}_CLANGPDB/FV/SILICIUM_UEFI.fd"

For boards selecting bootimg.image.ramdisk_compression = "uefi-chunks", bootimg encodes the FAT in independent 1 MiB UEFI-compressed chunks. The matching UniXNURamDiskDxe reads this format with a 1 MiB cache. ramdisk_max_bytes limits the encoded transfer; boot.json records both the encoding and logical FAT size.

sheng watchdog handoff ​

The sheng profile selects SHENG_BOOT_GUARD=1. Its preflight imports the device's BootResetCore.h into the firmware checkout. SEC verifies the PMIC bootloader reboot reason and arms Gunyah's 30000 ms watchdog. DXE pings every two seconds for a 180-second firmware budget; ExitBootServices sends the final firmware ping.

The matching XNU kernel uses uefi-watchdog=1 and takes over at EARLY_BOOT, pinging every ten seconds. autoreset=<seconds> bounds the run; a zero deadline keeps the watchdog serviced. Keep the firmware and kernel configuration together. The sheng lab builds COFF firmware with LLVM and LLD 22.1.8. CLANG_BIN points to a directory containing that toolchain's clang, lld-link, llvm-lib and llvm-rc.

From the UniXNU checkout, prepare that directory:

sh
brew install llvm@22 lld@22
mkdir -p .cache/edk2-llvm22
for edk2_tool in clang llvm-lib llvm-rc; do
  ln -sf "$(brew --prefix llvm@22)/bin/$edk2_tool" ".cache/edk2-llvm22/$edk2_tool"
done
ln -sf "$(brew --prefix lld@22)/bin/lld-link" .cache/edk2-llvm22/lld-link

Set clang_bin = ".cache/edk2-llvm22" in unixnu.local.toml.

To qualify the early return path, pack a known header-v0 XNU image with the selected firmware and a kernel-entry wait:

sh
python3 ../UniXNU-sheng/scripts/prepare-sheng-watchdog-probe.py \
  /path/to/known-boot.img /path/to/watchdog-probe.img \
  --uefi ../uefi-sheng --fd /path/to/SILICIUM_UEFI.fd \
  --dtb /path/to/sheng.dtb
fastboot -s SERIAL boot /path/to/watchdog-probe.img

The probe waits before EARLY_BOOT and has a 120-second PSCI reset fallback. With firmware fb2b2ae1, fastboot returned 70.503 seconds after the boot command, before that fallback. The elapsed time includes firmware startup; the configured hardware timeout is 30 seconds.

The inherited kernel path pings the already running firmware timer and starts its service thread. patch-sheng-inherited-watchdog.py INPUT OUTPUT --kernel-args "uefi-watchdog=1" qualifies that path on an existing source-built kernel with the matching instruction sequence; boot the result with the inherited-watchdog profile.

External firmware builds ​

A firmware supplied with ./unixnu bootimg --fd <file> needs the same DSC/FDF modules, package paths, board defines and EDK II patches as the selected [firmware] configuration. Check the required integration and use the matching board configuration when packing the image.

Boot image integration ​

unixnu bootimg compiles BootShim with the firmware base and size:

sh
clang --target=aarch64-none-elf -c \
  -DFD_BASE=<base> -DFD_SIZE=<size> \
  -DREQUIRES_KERNEL_HEADER=<0 or 1> \
  BootShim/BootShim.S -o shim.o

It appends the firmware volume, compresses the pair with gzip, appends the device tree and packs the Android boot image.

Verification ​

CheckMethod
Firmware volume sizeThe driver compares the output size with [uefi_fd] size
Shim headerThe driver checks ARM\x64 and the base and size fields
Boot image partsThe driver unpacks the image and compares every part
MenuThe serial log contains UNIXNU: lines
PayloadThe menu lists the xnu entry and DarwinBoot logs the handoff

Adding a UEFI driver ​

A driver can live in the firmware volume or in the payload.

LocationBuildLoad
Firmware volumeAdd the INF to the DSC and FDFFirmware dispatches it, or UniXNUDxe starts the application
PayloadBuild a standalone .efi[[driver]] in unixnu.toml or a kit

See Develop a driver for the load options.

Next steps ​

Released under the BSD-2-Clause-Patent License.