Skip to content

Instantly share code, notes, and snippets.

@dries007
Created March 15, 2019 16:59
Show Gist options
  • Save dries007/be896a027d4a14a6f9d4620d258f7d50 to your computer and use it in GitHub Desktop.
Save dries007/be896a027d4a14a6f9d4620d258f7d50 to your computer and use it in GitHub Desktop.
rPi Netboot TFTP setup for OSDev

rPi Netboot TFTP setup

This is not a tutorial, it's some hints to get up and going. All of this assumes you are using Linux. (As you should!)

This setup will let you boot the rPi from a folder on your disk over the network. This makes life much easier if you are iterating over changes. All you need is an easy way to reboot the pi (cable with switch or a switchable power supply).

Based on documentation from rPi foundation.

  1. https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/README.md
  2. https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/net.md
  3. https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/net_tutorial.md

Configure the rPi

On new rPi's (3B+) netboot support is build in, they don't need an SD card to boot from. I do recommend you setup the bootloader debug output via UART, so you don't have to guess what it's doing. For that you do need an SD card.

Older versions need some extra setup. They need an up to date firmware on an SD card, and optionally a configuration file. See documentation linked above or the files in this repository.

PC Configuration

Install dnsmasq to act as a (fake/proxy) DHCP server that tells the rPi where to boot from.

This only works if you plug the rPi into the same network as your PC. I recommend you plug it into a switch along with your PC and the cable to your router.

If you plug the pi directly into your PC (and you use wifi or a second connection for Internet), you'll have to change the configuration to dnsmasq actually hands out IP addresses instead of just acting as proxy. More info on that on the Glorious Arch Wiki

Add to the end of /etc/dnsmasq.conf:

port=0                          # Disable DNS
dhcp-range=192.168.0.255,proxy  # Proxy DHCP to the real server (adjust for your network if it's not 192.168.0.xxx based).
log-dhcp                        # Enabled debug log (so you don't have to guess.)
enable-tftp                     # Enable the required sub-service
tftp-root=/srv/tftp             # Change to suite your needs
pxe-service=0,"Raspberry Pi Boot"  # Required. See rPi foundation docs.

Don't enable tftp-secure, it only adds complexity and you should just turn off dnsmasq when you don't use it.

Use

View logs with journalctl -f -u dnsmasq.service. Don't forget to start dnsmasq, it's best left disabled (no autostart).

The rpi reads files in order:

  1. /<serialnr>/start.elf
  2. /autoboot.txt
  3. /config.txt
  4. /recovery.elf
  5. /start.elf
  6. /fixup.dat

For more details, see the docs. The short version is: Put bootcode.bin, start.elf, and fixup.dat in the TFTP root and it will boot from there.

You also need to supply your kernel image (kernel8.img), and you can optionally supply a file to be loaded after the kernel (in Linux used for the device tree blob). Again, see docs.

Next steps

Definitely use this to get going: "Bare Metal Programming on Raspberry Pi 3" by "bztsrc"

Compiler

Arch Linux packages for 64 bit ARMv8:

aarch64-elf-gcc-linaro-bin and aarch64-elf-newlib-linaro-bin

Add to your bashrc:

export PATH=$PATH:/usr/aarch64-elf/bin

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