43

I am wondering what the boot sequence of the Raspberry Pi is in a typical setup (say NOOBS), from power application (or warm reset if that's different) up to, say, the apparition of the logo; or where that is described.

Beside a most needed general picture of that sequence, I'm most interested in the early stages:

  1. What's the reset vector for the ARM CPU, and how/where is that defined?
  2. From what memory are the first ARM CPU instructions fetched? Where is that, and what technology is used to store this code?
  3. Is that ARM32 or Thumb (or perhaps Jazelle) code? Does that depend on the low order bit of the reset vector?
  4. Is source (or disassembly, or dump) of that early boot code available? If not, is anything technical preventing the use of the JTAG port to determine that? As for legal, I'm ready to assume the risk of trusting my understanding of the law applicable where I live (France), which is that I'm fully allowed to analyze my own computer, at least in the absence of an explicit contractual requirement not to do so.
  5. In what order are peripherals initialized, and by what piece of code?
  6. Beside the ARM CPU, is there some processor/automata running in the BCM2835, and in the affirmative how does its boot sequence relate to the ARM CPU?

I'm ready to dive into the ARM CPU's Technical Reference Manual and BCM2835 ARM Peripherals, or any other doc.

Update: After posting, I found this and this, stating the BCM2835's GPU is acting as a master to the ARM, and is heavily involved in the boot sequence.

fgrieu
  • 543
  • 1
  • 6
  • 9
  • 4
    All I can say that most of that information is closed source, like the source code, the bootloaders and SoC firmware.. For now allot is unknown. You should know one thing. The BCM is a GPU... not a CPU. The bootloader starts in the GPU section, initializes RAM there and hands over to the CPU where is the first place we have access to source code... aka Raspbian. Good Luck. This question is very broad and difficult to answer. – Piotr Kula Oct 31 '13 at 09:40
  • Related: *[What happens during the boot process?](http://raspberrypi.stackexchange.com/questions/1200/what-happens-during-the-boot-process)*. Duplicate? – Peter Mortensen Mar 03 '15 at 21:51

2 Answers2

53

The boot sequence of the Raspberry Pi is basically this:

  1. Stage 1 boot is in the on-chip ROM. Loads Stage 2 in the L2 cache
  2. Stage 2 is bootcode.bin. Enables SDRAM and loads Stage 3
  3. Stage 3 is loader.bin. It knows about the .elf format and loads start.elf
  4. start.elf loads kernel.img. It then also reads config.txt, cmdline.txt and bcm2835.dtb If the dtb file exists, it is loaded at 0×100 & kernel @ 0×8000 If disable_commandline_tags is set it loads kernel @ 0×0 Otherwise it loads kernel @ 0×8000 and put ATAGS at 0×100
  5. kernel.img is then run on the ARM.

Everything is run on the GPU until kernel.img is loaded on the ARM.

I found this diagram quite useful:

Boot Sequence

SG60
  • 59
  • 3
  • 4
  • 2
    Useful. Could it be clarified if the 2nd stage bootloader `bootcode.bin` is code run by the GPU, the ARM (and then which kind of code), or a mix of these? Same for 3rd stage `loader.bin` (if that's not gone, as it appears to be). – fgrieu Nov 08 '13 at 09:22
  • 4
    @fgrieu I've edited the answer to include clarification. ***Everything is run on the GPU until `kernel.img` which is run on the ARM.*** – SG60 Nov 30 '13 at 15:58
  • 4
    According to [this](http://elinux.org/RPi_Software#Overview) `loader.bin` is no longer used. `bootcode.bin` directly loads `start.elf` according to [this Git commit](https://github.com/raspberrypi/firmware/commit/c57ea9dd367f12bf4fb41b7b86806a2dc6281176) – HeatfanJohn May 27 '14 at 16:43
  • @SG60: Can you update your answer with the information from HeatfanJohn? – Peter Mortensen Mar 03 '15 at 21:46
  • Does anyone know about NOOBS boot? apparently there process is slightly different, involving recover.elf and some soft booting antics. I'm curious about getting uboot working at a slightly lower level. – Sam Feb 17 '16 at 15:05
  • Noobs simply runs like a recovery boot of Raspbian, just changing a few files because the normal ones either are missing or the Shift key is being held. – Paul Stelian Aug 17 '19 at 04:59
7

For the new Pi4, the boot flow got some changes as the old bootcode.bin moved from sdcard or /boot to internal 512KB EEPROM

Błażej Michalik
  • 1,223
  • 1
  • 11
  • 16
IMAN4K
  • 191
  • 1
  • 6