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. There is no on-chip Flash in i.MX RT1060, so a three-component design (Cortex-M + external non-volatile memory + external RAM) is the only possibility. However, thanks to the i.MX RT1060 internal bootloader (located in a small on-chip ROM) 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 advanced i.MX RT1060 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.
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:
#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 i.MX RT1060 (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.
Here is a snapshot of the boot session for that configuration, as run on the i.MX RT1060 EVK. The kernel runs from SD card and is quite fast (note the 1196 BogoMIPS metrics in the kernel output). Boot time to the application (from the point where U-Boot passes control to the kernel) is less than a second. Notice the 30056 KBytes of unused memory:
[12:27:40.4] U-Boot 2017.09-imxrt-2.5.2 (Nov 22 2017 - 01:47:42 +0300)
[12:27:40.4] CPU: i.MX RT106x at 600MHz
[12:27:40.4] Model: NXP i.RT1060 EVK
[12:27:40.4] DRAM: 32 MiB
[12:27:40.4] MMC: FSL_SDHC: 0
[12:27:40.5] reading uboot.env
[12:27:40.6] Video: 480x272x24
[12:27:40.7] In: serial@40184000
[12:27:40.7] Out: serial@40184000
[12:27:40.7] Err: serial@40184000
[12:27:40.7] Net: eth0: ethernet@402D8000
[12:27:40.7] reading splash-rt1050-series_24.bmp
[12:27:40.8] 391736 bytes read in 109 ms (3.4 MiB/s)
[12:27:40.9] reading mxrt106x-evk.ini
[12:27:41.0] 0 bytes read in 9 ms (0 Bytes/s)
[12:27:41.0] Hit any key to stop autoboot: 0
[12:27:41.0] reading hello.uImage
[12:27:41.2] 792123 bytes read in 198 ms (3.8 MiB/s)
[12:27:41.2] ## Booting kernel from Legacy Image at 80007fc0 ...
[12:27:41.2] Image Name: Linux-4.5.0-00428-g34d61b4a0ecd-
[12:27:41.2] Image Type: ARM Linux Multi-File Image (uncompressed)
[12:27:41.2] Data Size: 792059 Bytes = 773.5 KiB
[12:27:41.2] Load Address: 80008000
[12:27:41.2] Entry Point: 80008001
[12:27:41.2] Contents:
[12:27:41.2] Image 0: 789216 Bytes = 770.7 KiB
[12:27:41.2] Image 1: 2831 Bytes = 2.8 KiB
[12:27:41.2] Verifying Checksum ... OK
[12:27:41.4] ## Flattened Device Tree from multi component Image at 80007FC0
[12:27:41.4] Booting using the fdt at 0x800c8aec
[12:27:41.4] Loading Multi-File Image ... OK
[12:27:41.4] Loading Device Tree to 81e79000, end 81e7cb0e ... OK
[12:27:41.5] Starting kernel ...
[12:27:41.6] Booting Linux on physical CPU 0x0
[12:27:41.9] Linux version 4.5.0-00428-g34d61b4a0ecd-dirty (yur@linux-7d45)
(gcc version 4.7.4 20130508 (prerelease) (20161027-112109- build on
iron.emcraft.com by sergmir) ) #2126 Mon Nov 20 12:26:40 +0400 2017
[12:27:41.9] CPU: ARMv7-M [411fc271] revision 1 (ARMv7M), cr=00000000
[12:27:41.9] CPU: WBA data cache, WBA instruction cache
[12:27:41.9] Machine model: NXP IMXRT1060 board
[12:27:41.9] Built 1 zonelists in Zone order, mobility grouping off.
Total pages: 8128
[12:27:41.9] Kernel command line: console=ttyLP0,115200 consoleblank=0
user_debug=31
ip=192.168.1.101:192.168.1.65::255.255.255.0::eth0:off
[12:27:41.9] PID hash table entries: 128 (order: -3, 512 bytes)
[12:27:41.9] Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
[12:27:41.9] Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
[12:27:41.9] Memory: 30588K/32768K available (555K kernel code,
34K rwdata, 104K rodata,
72K init, 50K bss, 2180K reserved, 0K cma-reserved)
[12:27:41.9] Virtual kernel memory layout:
[12:27:41.9] vector : 0x00000000 - 0x00001000 ( 4 kB)
[12:27:41.9] fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
[12:27:41.9] vmalloc : 0x00000000 - 0xffffffff (4095 MB)
[12:27:41.9] lowmem : 0x80000000 - 0x82000000 ( 32 MB)
[12:27:41.9] .text : 0x80008000 - 0x800ad024 ( 661 kB)
[12:27:41.9] .init : 0x800ae000 - 0x800c0000 ( 72 kB)
[12:27:41.9] .data : 0x800c0000 - 0x800c8ae0 ( 35 kB)
[12:27:41.9] .bss : 0x800c8ae0 - 0x800d56d8 ( 51 kB)
[12:27:41.9] NR_IRQS:16 nr_irqs:16 16
[12:27:41.9] sched_clock: 32 bits at 75MHz, resolution 13ns, wraps every
28633115129ns
[12:27:41.9] clocksource: vf-pit: mask: 0xffffffff max_cycles: 0xffffffff,
max_idle_ns: 25483472618 ns
[12:27:41.9] Calibrating delay loop... 1196.85 BogoMIPS (lpj=5984256)
[12:27:41.9] pid_max: default: 4096 minimum: 301
[12:27:41.9] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[12:27:41.9] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[12:27:41.9] devtmpfs: initialized
[12:27:41.9] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff,
max_idle_ns: 19112604462750000 ns
[12:27:41.9] pinctrl core: initialized pinctrl subsystem
[12:27:41.9] imxrt105x-pinctrl 401f8000.iomuxc: initialized IMX pinctrl driver
[12:27:41.9] clocksource: Switched to clocksource vf-pit
[12:27:41.9] 40184000.serial: ttyLP0 at MMIO 0x40184000 (irq = 34,
base_baud = 375000) is a FSL_LPUART
[12:27:41.9] console [ttyLP0] enabled
[12:27:41.9] Serial: VF610 driver
[12:27:41.9] Freeing unused kernel memory: 72K (800ae000 - 800c0000)
[12:27:41.9] Mounting /proc..
[12:27:41.9] Reading /proc/meminfo:
[12:27:41.9] MemTotal: 30660 kB
[12:27:41.9] MemFree: 30056 kB
[12:27:41.9] MemAvailable: 29024 kB
[12:27:41.9] Buffers: 0 kB
[12:27:41.9] Cached: 32 kB
[12:27:41.9] SwapCached: 0 kB
[12:27:41.9] Active: 0 kB
[12:27:41.9] Inactive: 0 kB
[12:27:41.9] Active(anon): 0 kB
[12:27:41.9] Inactive(anon): 0 kB
[12:27:41.9] Active(file): 0 kB
[12:27:41.9] Inactive(file): 0 kB
[12:27:41.9] Unevictable: 0 kB
[12:27:41.9] Mlocked: 0 kB
[12:27:41.9] MmapCopy: 72 kB
[12:27:41.9] SwapTotal: 0 kB
[12:27:41.9] SwapFree: 0 kB
[12:27:41.9] Dirty: 0 kB
[12:27:41.9] Writeback: 0 kB
[12:27:41.9] AnonPages: 0 kB
[12:27:41.9] Mapped: 0 kB
[12:27:41.9] Shmem: 0 kB
[12:27:41.9] Slab: 392 kB
[12:27:41.9] SReclaimable: 24 kB
[12:27:41.9] SUnreclaim: 368 kB
[12:27:41.9] KernelStack: 96 kB
[12:27:41.9] PageTables: 0 kB
[12:27:41.9] NFS_Unstable: 0 kB
[12:27:41.9] Bounce: 0 kB
[12:27:41.9] WritebackTmp: 0 kB
[12:27:41.9] CommitLimit: 15328 kB
[12:27:41.9] Committed_AS: 0 kB
[12:27:41.9] VmallocTotal: 0 kB
[12:27:41.9] VmallocUsed: 0 kB
[12:27:41.9] VmallocChunk: 0 kB
[12:27:41.9] Done
[12:27:41.9] Hello, IMXRT106X_NXPEVK-Linux!
[12:27:44.8] Hello, IMXRT106X_NXPEVK-Linux!
[12:27:47.8] Hello, IMXRT106X_NXPEVK-Linux!
...