The STM32F7 is a Cortex-M7 microcontroller provided by STMicroelectronics. The evaluation board is called “Discovery board” and it’s equipped with several different peripherals. It’s shipped with 16Mbytes of RAM but unfortunately only 8Mbytes is actually accessible. The reason is that STM selected a 32bit RAM but on the evaluation board only 16 pins are actually connected: so you can address the whole RAM but you can use only half of it 🙂
So today challenge is to boot Linux on a system with only 8Mbytes of RAM. To make this possible I started from the BSP provided by Emcraft Systems. You can download the BSP fro their web site (https://www.emcraft.com/products/503#software). They have some binaries available, but we want to build our own Linux, and we want to run the new 4.2 Kernel. Unfortunately Emcraft doesn’t provided the new Kernel 4.2, so it’s up to us to build it.
As you probably already know, to boot the system we need:
- U-boot
- Kernel (we choose 4.2 version)
- Device Tree
- Filesystem
- Toolchain
We are going to use u-boot and kernel from the Emcraft BSP (compiled with the GNU toolchain for uClinux Cortex-M3/M4), while we are going to create our own filesystem image and toolchain starting from the Buildroot project. The Buildroot project is really great and the guys who work there are even more great (take a look at the site https://buildroot.org).
I’m not going to focus on how you can configure the BSP of Emcraft and how you can flash the bootloader on the board because you can find all the information you need on their web site. For the laziest ones, here below useful links:
- https://www.emcraft.com/stm32f7-discovery-board/connecting-serial-console-to-stm32f7disco
- https://www.emcraft.com/stm32f7-discovery-board/installing-uboot-to-stm32f7-discovery-board
- https://www.emcraft.com/products/413#software
All the files you need to build the system can be downloaded from here:
https://drive.google.com/drive/folders/0B_WsUsojgmE6Mld3eHpaX1lyY0k?usp=sharing
Build U-boot
To build the u-boot you can access the folder of BSP:
~/linux-cortexm-2.1.1
and setting the environment
. ./ACTIVATE.sh
Then you need to change the file:
u-boot/include/configs/stm32f746-discovery.h
with the one in the archive file (STM32F7_lorenx.tar.gz). Then you can run the build:
make clean make distclean make stm32f746-discovery_config make
The u-boot is now ready to be flashed on the board.
Build Kernel 4.2 and Device Tree
In the archive file (STM32F7_lorenx.tar.gz) you can find the right kernel configuration (.config) and the devicetree files. Replace and add the files in the linux folder and build the kernel:
cd linux make ARCH=arm CROSS_COMPILE=arm-uclinuxeabi- uImage make ARCH=arm CROSS_COMPILE=arm-uclinuxeabi- dtbs mkimage -A arm -O linux -T multi -a 0xC0008000 -e 0xC0008001 -C none -d arch/arm/boot/Image:arch/arm/boot/dts/stm32f746-lorenx.dtb uImageMulti
The kernel will be lately loaded by the u-boot through tftp. The setup of a tftp server and the boot via tftp is out of the scope of this post.
Build Buildroot (2016.08.1)
The final step is to build the root fileystem which will be lately flashed on a SD card. The configuration (.config) can be found in the archive file (STM32F7_lorenx.tar.gz).
The filesystem has a very minimal configuration and its footprint is about 2Mbytes. The filesystem can also be customised using the “menuconfig” command provided by buildroot.
My configuration will also build a toolchain which can be used to build applications that can be loaded on the system. The toolchain provides build utilities and also the most important libraries like POSIX threads library. The libpthread is not available in the Cortex-M toolchain downloaded from the Emcraft website, but it is a very important library which is widely used in many applications. The toolchain can be found in the “output/host/usr” folder, and can be customised with any suffix: I have chosen the “inxpect” suffix which is the name of the company I’m currently woking for (great project, take a look http://www.inxpect.com).
After run “make” command you can find the filesystem in the “output/images” folder. Pick the “.cpio” file and decompress it on your SD card. I’ve used a SD card formatted with FAT filesystem: if you want to use the Ext3/4 filesystem remember to add its support in the kernel. My recommendation is to use Ext3/4 filesystem because the files links are preserved: pay attention if you use SD because several links can be broken! You need to replace some files which link to busybox to boot the system with the FAT filesystem: init, mount, sh, login, getty, mkdir, …
Boot the system
The system can be now started. Flash the u-boot on the board, insert the SD card, connect the network, connect your PC to the serial port and power up. Stop the u-boot and configure the environment:
setenv bootargs 'stm32_platform=stm32f7-disco console=ttyS5,115200 root=/dev/mmcblk0p2 rootwait' tftp stm32f7/uImage bootm
The “root” argument depends on how your SD is formatted: I’m using the partition number 2 of the SD card.
While running the system you can experience several OOM (Out Of Memory) errors: this is because the memory is very limited and you don’t have swap (no MMU no swap).
Unfortunately with this configuration we don’t have enough space to run seriously a Linux system: I think that Linux needs at least 16Mbytes of RAM to run properly with this configuration. Maybe with a small upgrade of the RAM things will start to get better…
That’s all…