Week 3 · Lecture outline
The boot ROM and the SRAM stage
Modules 3: The boot ROM and 4: Loading the bootloader into SRAM. Lab: Lab 3, boot ROM and the SRAM stage. Due: Lab 2.
Learning goals
By the end of the week a student can:
- Say what the boot ROM is, where it runs, and why it cannot be changed.
- Explain the boot-media order, the boot select switch and USB boot mode.
- Explain why the first stage runs from on-chip SRAM, and what it has to do before anything larger can load.
- Pick out the boot ROM's and the first stage's lines in their own boot log.
Lecture 1, block 1: the first instruction
- When reset is released, the CPU starts at a fixed address inside the system-on-chip.
- The code there, the boot ROM or mask ROM, is part of the silicon, written at the factory.
- It cannot be changed or erased, which is why a board with broken firmware or boot media can always be brought back.
- Its whole job: find the first stage of the bootloader and start it.
Lecture 1, block 2: where it looks
- Boot sources in a fixed order, such as SPI flash, eMMC and the SD card.
- Both course boards have a boot select switch that changes which source is tried first; the schematic's boot page shows how.
- From the first source with a valid image, it reads a small first stage and checks its header; on a secured device, its signature too, against keys held in fuses.
- It copies the first stage into on-chip SRAM and jumps to it.
Lecture 1, block 3: USB boot mode
- No valid image anywhere, or the power-on way in (Solitude's USB boot button held; Das Frite's boot select switch at USB, which skips the SPI flash): the boot ROM waits for a computer to send the first stage over USB.
- The Libre Computer app uses this to start and recover a board, and its
lc bootcommand sends a build of your own the same way. - When U-Boot is running,
lc bootrom resetat its prompt restarts the board in USB boot mode with no button; the power-on way stays the way in when U-Boot does not start. - This is the recovery path for the rest of the course.
Lecture 2, block 1: why the first stage is small
- On-chip SRAM works from power-on with no setup, but holds only tens to hundreds of kilobytes.
- DRAM is thousands of times larger but does nothing until it is configured.
- So the boot is split: a small first stage in SRAM sets up clocks and the serial console, brings up DRAM and loads the larger stages into it.
Lecture 2, block 2: an open first stage
- Names differ by project: U-Boot's early stages are the TPL and the SPL, Arm's Trusted Firmware calls this one BL2. In Libre Computer's open chain the SRAM stage is the TPL, which brings up DRAM and loads an SPL that runs from DRAM. Both course boards ship this open chain in their SPI flash, so the week 1 log's first stage is a published build of it; the one students build runs when started over USB.
- libretech-builder-simple builds Libre Computer's open boot chain from source for both course boards; on Solitude, memory training still runs Amlogic's binary DDR code and PHY training firmware.
- Students read the stage that runs in SRAM, change it, rebuild it and boot their own build over USB.
- Their build is loaded into SRAM and writes nothing to the board's storage.
Lecture 2, block 3: reading the log
- Mark the lines printed before any code from SPI flash or the boot media ran: the boot ROM's.
- Find where the boot ROM stops printing and the first stage starts.
- Use the boot chain diagram to place each stage and the memory it runs from.
Board demo
- Power on with the console open and point out the boot ROM's lines as they scroll.
- Power the board off (shut it down with
sudo poweroffif Linux is running, wait for the halt, then unplug it), flip the boot select switch, power on again, and compare what the boot ROM prints. Put the switch back. - Put the board in USB boot mode at power-on (Solitude: hold the USB boot button; Das Frite: the boot select switch at USB), connect the bench PC running the Libre Computer app to the USB Type-C port, and let it send the open first stage; the board starts without its own firmware.
- Start the board over USB with a first stage built on the bench PC, with one added console line, and find the line on the console.
Check questions
Why can a board whose bootloader in SPI flash has been overwritten still be recovered?
The boot ROM is fixed in the silicon and cannot be changed or erased. With no valid image, or put in USB boot mode at power-on (Solitude's USB boot button, Das Frite's boot select switch at USB), it waits in USB boot mode for a computer to send a first stage over USB.
Why does the first stage run from on-chip SRAM rather than DRAM?
SRAM works from power-on with no setup, while DRAM does nothing until it is configured. Bringing DRAM up is the first stage's main job, so it has to run somewhere else first, and fit in that small SRAM.