Skip to content

Instantly share code, notes, and snippets.

@shift
Created December 2, 2020 09:21
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shift/98f43d98ce5e47e374fa46bf67b6a3b1 to your computer and use it in GitHub Desktop.
Save shift/98f43d98ce5e47e374fa46bf67b6a3b1 to your computer and use it in GitHub Desktop.
UEFI/iPXE booting Raspberry Pi for Flatcar Linux

UEFI/iPXE booting Raspberry Pi for Flatcar Linux

Download and compile the following https://github.com/pftf/RPi4.git. I made the following change to edk2-platforms to always enable 3GB RAM+ as TFTP booting this seems to cause issues with it remembering the options.

diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4/RPi4.dsc
index c481c35342..4b495b1fe8 100644
--- a/Platform/RaspberryPi/RPi4/RPi4.dsc
+++ b/Platform/RaspberryPi/RPi4/RPi4.dsc
@@ -495,7 +495,7 @@
   # Supporting > 3GB of memory.
   #
   gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|L"RamMoreThan3GB"|gConfigDxeFormSetGuid|0x0|0
-  gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|L"RamLimitTo3GB"|gConfigDxeFormSetGuid|0x0|1
+  gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|L"RamLimitTo3GB"|gConfigDxeFormSetGuid|0x0|0
 
   #
   # Device Tree and ACPI selection.

Grab the RPI_EFI.fd, Shell.efi, UiApp.efi files from the Build/RPi4/RELEASE_GCC5/FV/ directory. Download https://github.com/raspberrypi/firmware/raw/master/boot/{start4.elf,bcm2711-rpi-4-b.dtb,overlays/miniuart-bt.dtbo} Create a config.txt with the following

arm_64bit=1
enable_uart=1
uart_2ndstage=1
enable_gic=1
armstub=RPI_EFI.fd
disable_commandline_tags=1
disable_overscan=1
device_tree_address=0x1f0000
device_tree_end=0x200000
dtoverlay=miniuart-bt

Compile iPXE for ARM64 and embed the following ipxe script into it

#!ipxe
# see https://ipxe.org/docs
# see https://ipxe.org/settings

# show the system information.
# NB you can run "config" to interactively see all the possible variables.
echo Platform..... ${platform}
echo Architecture. ${buildarch}
echo Product...... ${smbios/product}
echo Manufacturer. ${smbios/manufacturer}
echo Asset........ ${smbios/asset}
echo UUID......... ${smbios/uuid}
echo Serial....... ${smbios/serial}

# show the available network interfaces.
echo Network interfaces:
ifstat

echo Configuring net0 ${net0/mac} (${net0/chip}) from dhcp...
:retry_ifconf
ifconf --configurator dhcp net0 || goto retry_ifconf
echo MAC address.. ${net0/mac}
echo IP address... ${net0/ip}
echo Subnet mask.. ${net0/netmask}
echo Gateway...... ${net0/gateway}
echo DNS.......... ${net0/dns}
echo Hostname..... ${hostname}
echo Domain....... ${domain}
echo Next Server.. ${next-server}
echo Filename..... ${filename}

# we need to set the time from ntp because the pi does not have an rtc.
# NB having the correct time is a requirement to use TLS.
echo Getting the current time from ntp...
:retry_ntp
ntp pool.ntp.org || goto retry_ntp
echo Unix Time.... ${unixtime}

chain --autofree tftp://${next-server}/${filename}

Create pxelinux with the following

#!ipxe
## Flatcar Linux
#set base-url http://alpha.release.flatcar-linux.net/arm64-usr/current
set base-url http://192.168.1.94
kernel ${base-url}/flatcar_production_pxe.vmlinuz initrd=flatcar_production_pxe_image.cpio.gz flatcar.first_boot=1 initrd ${base-url}/flatcar_production_pxe_image.cpio.gz
boot

Or modify it redirect to your matchbox server.

Place the efi files onto an sdcard formatted FAT, I got the smallest SD cards I could find as the data is less than 1MB. And the other files onto your tftp server.

I was unable to find a way to iPXE boot without the sdcard for the EFI files, this is probably possable, let me know if you find a way of doing it.

@anthr76
Copy link

anthr76 commented Dec 11, 2020

The maintainers over at netboot.xyz are looking at ways to natively iPXE sd-card less

@shift
Copy link
Author

shift commented Dec 13, 2020

@anthr76 Nice. I know that vmware on arm has already managed this. I tried a few different ways but in the end I just paid 20EUR for 10x128MB sdcards, smallest available on amazon.de.

@nochristrequired
Copy link

I was able to follow this - thank you @shift for sharing.
Ran into this issue after the first successful boot - flatcar/Flatcar#375 and I'll see what I can do to help.

@RikiReal
Copy link

RikiReal commented Apr 4, 2023

Sorry for necro posting but I found this pftf/RPi4#106.
It's about booting the UEFI firmware and there is a link to a blog about booting a pi without a sd-card.
Thought it might be relevant.

@shift
Copy link
Author

shift commented Apr 4, 2023

Yeah, when I posted this it wasn't possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment