Skip to content

Instantly share code, notes, and snippets.

@shift
Created December 2, 2020 09:21
Show Gist options
  • Select an option

  • Save shift/98f43d98ce5e47e374fa46bf67b6a3b1 to your computer and use it in GitHub Desktop.

Select an option

Save shift/98f43d98ce5e47e374fa46bf67b6a3b1 to your computer and use it in GitHub Desktop.

Revisions

  1. shift created this gist Dec 2, 2020.
    95 changes: 95 additions & 0 deletions rpi4_eufi_booting_flatcar.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,95 @@
    # 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.