Accessing flash memory from the bootloader
In Chapter 3, All About Bootloaders, I mentioned the need for the bootloader to load kernel binaries and other images from various flash devices, and to perform system maintenance tasks such as erasing and reprogramming flash memory. It follows that the bootloader must have the drivers and infrastructure needed to support read, erase, and write operations on the type of memory you have, whether it be NOR, NAND, or managed. I will use U-Boot in the following examples; other bootloaders follow a similar pattern.
U-Boot and NOR flash
U-Boot has drivers for NOR CFI chips in drivers/mtd
and utilizes various erase
commands to erase memory and cp.b
to copy data byte by byte, programming the flash cells. Suppose that you have NOR flash memory mapped from 0x40000000
to 0x48000000
, of which 4 MiB, starting at 0x40040000
, is a kernel image. Here, you would load a new kernel into flash using these U-Boot commands:
=> tftpboot 100000 uImage...