Now time to study the boot process on Raspberry Pi. Good source to study: R-Pi Boot process

  1. Stage 1 boot is in the on-chip ROM. Loads stage2 in the L2 cache!
  2. Stage 2 is bootcode.bin. Enables SDRAM and loads stage3
  3. Stage 3 is loader.bin. Knows about elf format and load start.elf
  4. start.elf loads kernel.img (also start.elf is the main gpu code).
  • It reads config.txt, cmdline.txt and bcm2835.dtb
  • If the dtb file exists, it is loaded at 0x100 & kernel @ 0x8000
  • Else if disable_commandline_tags is set load kernel @ 0x0
  • Else if load kernel @ 0x8000 and put ATAGS at 0x100
  1. kernel.img, is the first! thing that runs on the ARM processor. We will use u-boot as kernel.img so our config.txt will look as:
1kernel=u-boot.bin

cmdline.txt:

1dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

We will use http://people.freebsd.org/~gonzo/arm/rpi/freebsd-pi-uboot-20120806-netboot.tar.gz u-boot package prepared by Gonzo to make R-Pi to start USB, initialize Serial, initialize Ethernet (remember it is behind USB), get IP via DHCP and can download and start our kernel via TFTP.

To specify IP where kernel should be downloaded from, we need to prepare boot.scr for U-Boot: boot-tftp.cmd:

 1set autoload no
 2set serverip 10.0.55.112
 3set bootfile irpi
 4set loadaddr 7FE0
 5if usb start; then
 6    if dhcp; then
 7        if tftpboot ${loadaddr} irpi; then
 8            go 8000;
 9        fi;
10    fi;
11fi;

Now compile it into boot.scr:

mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n 'U-Boot script' -d boot-tftp.cmd boot.scr

That’s all, now we can write files into FAT boot partition onto SD card, put there generated boot.scr and start R-Pi. Let’s connect wires to FTDI, to USB, start screen on Mac, put SD into R-Pi, start TFTP server, turn power ON and wait:

U-Boot 2012.04.01-00489-gcd2dac2-dirty (Jul 07 2012 - 12:57:03)
 
DRAM:  128 MiB
WARNING: Caches not enabled
MMC:   bcm2835_sdh: 0
Using default environment
 
In:    serial
Out:   serial
Err:   serial
Net:   Net Initialization Skipped
No ethernet found.
Hit any key to stop autoboot:  0
reading uEnv.txt
 
17 bytes read
Importing environment from mmc ...
reading boot.scr
 
274 bytes read
Running bootscript from mmc0 ...
## Executing script at 00008000
(Re)start USB...
USB:   Core Release: 2.80a
scanning bus for devices... 3 USB Device(s) found
       scanning bus for storage devices... 0 Storage Device(s) found
       scanning bus for ethernet devices... 1 Ethernet Device(s) found
Waiting for Ethernet connection... done.
BOOTP broadcast 1
*** Unhandled DHCP Option in OFFER/ACK: 95
BOOTP broadcast 2
*** Unhandled DHCP Option in OFFER/ACK: 95
*** Unhandled DHCP Option in OFFER/ACK: 95
DHCP client bound to address 10.0.55.120
BOOTP broadcast 3
Waiting for Ethernet connection... done.
Using sms0 device
TFTP from server 10.0.55.112; our IP address is 10.0.55.120
Filename 'irpi'.

Great!