This is perhaps one of the most frequently asked questions about uClinux on Cortex-M.
First thing to say is that external RAM is a must for uClinux. However small a Linux configuration, it still requires at least several MBytes of RAM to run from. All Cortex-M devices Emcraft is aware of limit they internal SRAM to hundreds KBytes at best. There is no way uClinux can be run from a single-chip Cortex-M design, as of this writing.
A two-component design (Cortex-M + external RAM) is a possibility for chips that have on-chip non-volatile (Flash) memory, which can be used as a storage for the bootloader and uClinux images. You may select from different types of boot devices. You may boot from: SD/MMC card, serial NOR/NAND Flash, etc.
Regarding the minimal size, there are two separate "footprint" metrics that need to be considered:
Size of the bootable Linux image. In the embedded world it is often comfortable to have the root file system to be built-into the bootable image as initramfs
(instead of mounting the root file system from some other partitions or other device). More specifically, the bootable image is comprised of two major pieces:
Linux kernel itself;
cpio
representation of the root file system, which gets expanded into a RAM-based initramfs and mounted as rootfs when Linux is booting up.
The size of such a bootable image starts at maybe 0.8 MBytes for truly minimal configurations and ranges to whatever, depending on what you have put into your root file system and, to a lesser extent, what configuration options you have enabled in your kernel. For instance, enabling the TCP/IP stack in the kernel increases the image size somewhat substantially.
The size of a practical bootable image, with Ethernet, TCP/IP and a reasonable set of user-space tools and applications configured, would be in a 3-5 MBytes ballpark.
Size of external RAM required for run-time Linux operation. The answer we give to our customers when asked how much RAM is needed is the more the better, but no less than 16 MBytes. Admittedly, it may be possible to run some very basic configurations with rootfs
mounted from NFS or some external device even out of 2 MBytes but frankly this is more of a joke than a configuration one can build a practical uClinux design on.
As the rule of thumb, consider at least 32 MB RAM if your intention is to use uClinux in a serious product. When you approach deployment and it becomes clear that you can fit into less RAM, you might want to downsize to a compatible 16 MB RAM device, however the safe advice is to start with more RAM rather than less. Requirements for embedded applications grow at an incredibly fast rate and it is a sure bet that in a 1-year's time you will be wanting to add new software features to your design. Seeing that you are already considering uClinux for your microcontroller application, you are probably fed up with the "if only I had another 512 MB of RAM" kind of situation MCU developers are used to. If you want Linux and "features", plan for reasonable amounts of RAM.
On a practical side of things, and given the specific context of SDRAM memory used with the STM32H7 microcontrollers, the BOM differences between compatible 16 MB and 32 MB devices are often times quite tolerable. Again, the advice we can give is to play safely and plan for more RAM rather than less.
With that background in mind, here are some footprint numbers for a sample Linux configuration that Emcraft includes in the software distribution. The project is called hello (for "Hello, world") and can be found in the projects/hello directory, relative to the top of the distribution directory.
The kernel configuration of this project is minimalistic, for instance, the TCP/IP stack is disabled. At the application level, this is really a single-process configuration. Specifically, instead of the standard Linux init, the project runs a custom application called hello. The following are relevant snippets from the hello.intramfs
specification file that illustrate how the custom application is installed on the target instead of init.
Code Block |
---|
file /bin/hello ${INSTALL_ROOT}/projects/${SAMPLE}/hello/hello 755 0 0
slink /init /bin/hello 777 0 0 |
The application itself is a simple endless-loop Hello, world C program, except that before entering the loop it prints the content of /proc/meminfo
to stdout
(which is the Linux serial console in this specific configuration). The meminfo
printout gives information on how much memory is available when the application is running.
The application source can be found in projects/hello/hello/hello.c
. For the sake of completeness, here is the full source of that program:
Code Block |
---|
#include <stdio.h>
#include <unistd.h>
#include "hello.h"
#include <sys/mount.h>
int main(int argc, char **argv)
{
char buff[4096];
int rc;
FILE *fp;
printf("Mounting /proc..\n");
if (mount("proc", "/proc", "proc", MS_MGC_VAL, NULL)) {
perror("Unable to mount /proc");
goto xit;
}
if (!(fp = fopen("/proc/meminfo", "r"))) {
perror("fopen");
goto xit;
}
printf("Reading /proc/meminfo:\n");
while (fgets(buff, sizeof(buff), fp)) {
fputs(buff, stdout);
}
printf("Done\n");
while(1) {
printf(HELLO_STRING);
sleep(3);
}
xit:
return -1;
} |
The bootable Linux image ready for installation to non-volatile storage (SD Card) of the STM32H7 (hello.uImage
) is ~800 KBytes in size. This is a multi-file Image: ~770 KBytes is the kernel Image itself, and ~3 KBytes is the Device Tree Blob file.