> For the complete documentation index, see [llms.txt](https://breakpoint-journal.gitbook.io/breakpoint/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://breakpoint-journal.gitbook.io/breakpoint/embedded-systems/embedded-linux-boot-process.md).

# Embedded Linux Boot Process

In this post I provide some context on how embedded linux boot loaders work. This content was mostly taken from Tomaz Zaman's video linked below so please take a look at that too for more information!

## Embedded Storage Devices

### What is eMMC?

<figure><img src="https://2618442973-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmGhYQRY1OEeL4zywZ9zS%2Fuploads%2FSFKwGuf19akIUTWYw09g%2Fimage.png?alt=media&amp;token=62eb6cd7-85ee-4543-a54e-4e41a6d5ed6a" alt="" width="375"><figcaption></figcaption></figure>

An eMMC (embedded MultiMedia Card) is a standard chip commonly found in SD cards. This kind of chip is not removable as it is soldered onto the device's PCB. This component not only contains storage, but also provides a dedicated controller for reading and writing to the chip along with wear-leveling and power-saving protection as flash storage can be very sensitive. The eMMC only needs to expose a bus for the Linux OS to communicate with given that all these features are built into the card itself.

> Wear leveling is a technique used in SSDs to evenly distribute write and erase cycles across all memory cells, prolonging the drive’s lifespan and maintaining performance.

Generally, the eMMC exposes three traces to the CPU for communication:

1. Command
2. Clock
3. Data

However, there are cases where the eMMC only connects via one trace, which is known as a 1-bit bus. In more modern cards there are up to eight traces to the CPU meaning we can transmit 8-bits at a time. Upon startup, one trace will be responsible for negotiating the baud rate and initializing the other lines to work in parallel.

### What is Raw NAND Flash?

<figure><img src="https://2618442973-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmGhYQRY1OEeL4zywZ9zS%2Fuploads%2FmHAUKPXXmj9ANR1PUMHn%2Fimage.png?alt=media&amp;token=fc40fc23-1b35-40ec-ac08-a15e4f91845f" alt=""><figcaption></figcaption></figure>

Unlike eMMC, Raw NAND Flash requires a separate controller for reading and writing to the storage, whether that's one that's integrated into the CPU or as a separate standalone component

### What is NOR Flash?

Relative to raw NAND flash, NOR is much more durable and performant, and consequently, more expensive. For context, 64MB NOR flash chips are $5, while 32GB eMMCs are $15. Despite their limited capacity, NOR Flash chips come in handy as backup storage devices, containing minimal bootloaders and OS distributions in the unfortunate case where you eMMC chips are no longer functional. See this section of the [video](https://youtu.be/FYbYBtywBnQ?si=xbyZz7BtOeEel31a\&t=426) for an example of how one would utilize a JTAG to communicate with the device.

## Example Bootloader Walkthrough

<figure><img src="https://2618442973-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmGhYQRY1OEeL4zywZ9zS%2Fuploads%2F4lPIbot0kKyOcKLybd7I%2Fimage.png?alt=media&amp;token=b73fb41c-0737-455f-bdad-0f3dbda22d89" alt="" width="545"><figcaption></figcaption></figure>

> [How Linux Boots on an Embedded Device - part 1](https://www.youtube.com/watch?v=FYbYBtywBnQ)

1. CPU Bootloader - responsible for initializing the correct protocol and pins that the second bootloader code will execute upon. For example, if the NOR flash on a PCB contains the second bootloader, then the CPU bootloader will initialize the pins to the NOR flash chip.
2. The second bootloader stored on the NOR flash is responsible for initializing the RAM and executing the third bootloader
3. The third bootloader is responsible for initializing U-Boot
   1. There are separate phases of each bootloader, for example, in the image above BL2 kicks off BL31 (you can think of as BootLoader 3.1) as well as BL32. BL32 is generally reserved for **secure boot** which you can find out more about [here](https://www.youtube.com/redirect?event=video_description\&redir_token=QUFFLUhqbUJVa0FockUyM1Fralp0SktJMnNCRzBDSlV6Z3xBQ3Jtc0ttNElUaTloV1VHQ09GWXp3bFZ6NzA2QUdyV1RXSE45TlgzdkQySmtfX1hyM1NaX25iQkRSbWlpVGk0ZFRfcFRtdzhQb3NOTEhyaXNSLVZFcG5iQ1dhY2d2UklsZER3aW1pY2lfWkJDekJJYmdBQlFzYw\&q=https%3A%2F%2Ftrustedfirmware-a.readthedocs.io%2Fen%2Flatest%2Fdesign%2Ffirmware-design.html\&v=FYbYBtywBnQ).
4. U-Boot provides an interactive interface for the bootloading stage

**What is that Reset Configuration Word (RCW)?**

Note that the RCW isn't common to all embedded boards. The RCW reset code word (Reset Configuration Word) is a crucial component in embedded systems, particularly in SoCs (System on Chips). It resides in non-volatile memory (like NOR, QSPI, or SDHC) and allows for the configuration of various parameters, such as core frequencies and block frequencies, to support a high degree of configurability. The RCW enables flexibility to accommodate a large number of configuration parameters, making it essential for the operation and performance of the SoC.&#x20;

[<br>](https://www.bing.com/ck/a?!&\&p=66a40a8c9d07cb1adf36dac46fefc024ea85ba5756c779866fd85ba2206b4b39JmltdHM9MTc3ODI4NDgwMA\&ptn=3\&ver=2\&hsh=4\&fclid=03e91e11-41ce-615a-19f3-0c77403360ca\&u=a1L2NvcGlsb3RzZWFyY2g_cT13aGF0K2lzK3FzcGkmZm9ybT1DU0JSQU5E\&ntb=1)**What is QSPI?**

**QSPI (Quad Serial Peripheral Interface)** is a communication protocol or bus that uses four data lines instead of one, allowing for **faster data transfer rates**. It is commonly used to interface microcontrollers with external flash memory and other peripherals requiring high-speed serial communication. QSPI is particularly useful in applications that involve memory-intensive data, such as multimedia.

**How does one download a bootloader onto a device?**

U-Boot provides some methods for completing this via a [TFTP ](https://www.youtube.com/redirect?event=video_description\&redir_token=QUFFLUhqbkVyZWxoS3JTMU54OU8zaU1iQlMya3g5VFM5Z3xBQ3Jtc0trWXhBamJBVTRlLWJRdWdHeHFwcXFwSW5hbk9wRkpZOEZCcVNEVXpxZVFJOWdQQVFyMTVaZXNIRmIxRmtFdU1ialNKcGJnOFZwd2xBWTJHamcycnVCb2p3M293c1NSWTN2OTBya3ZRbTJSdUNQV2pKWQ\&q=https%3A%2F%2Fwww.baeldung.com%2Flinux%2Ftftp-server-install-configure-test\&v=FYbYBtywBnQ)server.

## Resources

* [How Linux Boots on an Embedded Device - part 1](https://www.youtube.com/watch?v=FYbYBtywBnQ)

## Glossary

| TERM | DEFINITION                       |
| ---- | -------------------------------- |
| eMMC | Embedded MultiMedia Card         |
| RCW  | Reset Configuration Word         |
| QSPI | Quad Serial Peripheral Interface |
