|Installing Linux Images to Internal Flash|
This note explains how to install images to the internal Flash of the STM32F429. With a bootable Linux image installed to the Flash, you can boot Linux on the STM32F429 with no user intervention. This corresponds to a deployment mode for an embedded device. Whenever a power or reset occurs, Linux boots from the internal Flash automatically and then starts performing whatever operation a specific application is designed for.
As explained in Running U-Boot, the U-Boot firmware is run from the internal Flash. Also, U-Boot takes some portion of the internal Flash to store its environment variables. The Flash memory map maintained by U-Boot on the STM32F429 Discovery is as follows:
As can be seen from the above table, there is a 1792 KBytes area in Flash that is unused by U-Boot. The most obvious use for that area is storage for a bootable Linux image. Conceivably it can be used for something else too, for instance to host some file system.
Let's see how to install a bootable Linux image to the Flash and then boot Linux from the installed image. We will use the prebuilt networking.uImage included in the Emcraft software distribution in the below example.
The procedure is based on the U-Boot command called cptf (from "copy to flash"). cptf allows to copy a memory buffer to the internal Flash and has the following synopsis:
cptf dst src size [reset]
dst is an address in the internal Flash, for instance, for a bootable Linux image it will typically be 0x08040000. src is a buffer that gets copied to the Flash. size is the size of the buffer. reset is an optional binary (0 or 1, 0 by default) that specifies whether cptf shall reset the target immediately after installing the buffer to the Flash. The text below will provide concrete examples of how cptf is used to install a Linux image to the Flash.
If you have your STM32F429 connected to the Ethernet (refer to Connecting to Ethernet on the STM32F429 Discovery) and your network is configured for TFTP download (refer to Loading Linux Images via Ethernet and TFTP), installation to Flash is very simple. This is done as follows:
On the host, copy networking.uImage to the TFTP directory:
$ cp networking.uImage /tftpboot/vlad/
On the target, tell U-Boot that you will be using the specific image in follow-up commands:
STM32F429-DISCO> setenv image vlad/networking.uImage
Run the update command to load the image via TFTP and install it to the internal Flash:
STM32F429-DISCO> run update
To clarify, update is really a convinience short-cut to the following command sequence:
STM32F429-DISCO> print update
envmaddr is defined as shown below so when the update invocation completes you have the image installed to the unused area of the internal Flash (offset 256 KBytes from the beginning of the Flash):
STM32F429-DISCO> print envmaddr
If you do not have the Ethernet connection on your Discovery board, you can use UART to download a Linux image to the target. It is not as convienient as Ethernet (download takes minutes), however it works.
Refer to Connecting serial console to the STM32F429 Discovery and Loading Linux images over UART for information on how to set up the UART connection and the basics of UART-based download, respectively.
Here is a shell / kermit script that you can use on the host to install a networking.uImage to the STM32F429 via UART:
$ vi uartinstall-stm32f429.script
Change the file mode to make the script an executable file:
$ chmod +x uartinstall-stm32f429.script
Copy the sample Linux image (networking.uImage) to the host directory you will be running the shell script from.
Then run the script to download the image to the target via UART and install it to the internal Flash:
It will take 3 minutes to download the image at 115.2Kps but finally it will get to the target. The next command in the script programs the image to the unused area of the internal Flash (offset 256 KBytes):
STM32F429-DISCO> installing uImage
Regardless of whether you have installed the image via Ethernet or UART, the next reset will boot the image from the image in Flash. This is defined by the bootcmd command, which essentailly calls bootm on an image at 0x08040000 (offset 256 KBytes from the beginning of the Flash):
STM32F429-DISCO> print bootcmd
Refer to Running U-Boot for how to control the bootdelay variable in U-Boot.