What is the Minimal Footprint of uClinux?

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 RT1170, so a three-component design (Cortex-M + external non-volatile memory + external RAM) is the only possibility. However, thanks to the i.MX RT1170 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 RT1170 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 file /lib/ld-uClibc.so.0 ${TOOLS_LIBS}/lib/ld-uClibc.so.0 755 0 0 slink /usr/lib/ld.so.1 /lib/ld-uClibc.so.0 755 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 RT1170 (hello.uImage) is ~5017 KBytes in size. This is a multi-file Image: ~4913 KBytes is the kernel Image itself, and ~9 KBytes is the Device Tree Blob file.

Here is a snapshot of the boot session for that configuration, as run on the i.MX RT1170 EVK. The kernel runs from SD card and is quite fast. Boot time to the application (from the point where U-Boot passes control to the kernel) is less than a second. Notice the 55884 KBytes of unused memory:

## Booting kernel from Legacy Image at 80007fc0 ... Image Name: Linux-6.1.22 Image Type: ARM Linux Multi-File Image (uncompressed) Data Size: 5040978 Bytes = 4.8 MiB Load Address: 80008000 Entry Point: 80008001 Contents: Image 0: 5031392 Bytes = 4.8 MiB Image 1: 9574 Bytes = 9.3 KiB Verifying Checksum ... OK ## Flattened Device Tree from multi component Image at 80007FC0 Booting using the fdt at 0x804d45ec Working FDT set to 804d45ec Loading Multi-File Image Loading Device Tree to 2032a000, end 2032f565 ... OK Working FDT set to 2032a000 Starting kernel ... Booting Linux on physical CPU 0x0 Linux version 6.1.22 (sasha@workbench.emcraft.com) (arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.10) 10.3.1 20210824 (release), GNU ld (GNU Arm Embedded Toolchain 10.3-2021.10) 2.36.1.20210621) #8 Mon Sep 4 03:45:33 UTC 2023 CPU: ARMv7-M [411fc272] revision 2 (ARMv7M), cr=00000000 CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache OF: fdt: Machine model: NXP IMXRT1170 EVK board Reserved memory: created DMA memory pool at 0x83f00000, size 1 MiB OF: reserved mem: initialized node dmapool@83f00000, compatible id shared-dma-pool Zone ranges: Normal [mem 0x0000000080000000-0x0000000083ffffff] Movable zone start for each node Early memory node ranges node 0: [mem 0x0000000080000000-0x0000000083efffff] node 0: [mem 0x0000000083f00000-0x0000000083ffffff] Initmem setup node 0 [mem 0x0000000080000000-0x0000000083ffffff] Built 1 zonelists, mobility grouping on. Total pages: 16256 Kernel command line: ip=192.168.88.89:192.168.88.170:192.168.88.1:255. 255.255.0::eth0:off Unknown kernel command line parameters "ip=192.168.88.89:192.168.88. 170:192.168.88.1:255.255.255.0::eth0:off", will be passed to user space. Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear) Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear) mem auto-init: stack:off, heap alloc:off, heap free:off Memory: 58872K/65536K available (3423K kernel code, 185K rwdata, 908K rodata, 188K init, 95K bss, 6664K reserved, 0K cma-reserved) NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16 Switching to timer-based delay loop, resolution 41ns sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns clocksource: mxc_timer1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=240000) pid_max: default: 4096 minimum: 301 Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear) Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear) devtmpfs: initialized DMA: default coherent area is set clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns futex hash table entries: 16 (order: -5, 192 bytes, linear) pinctrl core: initialized pinctrl subsystem NET: Registered PF_NETLINK/PF_ROUTE protocol family imxrt1170-pinctrl 400e8000.iomuxc: initialized IMX pinctrl driver imxrt1170-pinctrl 40c08000.iomuxc_lpsr: initialized IMX pinctrl driver imxrt1170-pinctrl 40c94000.iomuxc_snvs: initialized IMX pinctrl driver SCSI subsystem initialized usbcore: registered new interface driver usbfs usbcore: registered new interface driver hub usbcore: registered new device driver usb pps_core: LinuxPPS API ver. 1 registered pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it> PTP clock support registered Bluetooth: Core ver 2.22 NET: Registered PF_BLUETOOTH protocol family Bluetooth: HCI device and connection manager initialized Bluetooth: HCI socket layer initialized Bluetooth: L2CAP socket layer initialized Bluetooth: SCO socket layer initialized clocksource: Switched to clocksource mxc_timer1 NET: Registered PF_INET protocol family IP idents hash table entries: 2048 (order: 2, 16384 bytes, linear) tcp_listen_portaddr_hash hash table entries: 1024 (order: 0, 4096 bytes, linear) Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear) TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear) TCP bind hash table entries: 1024 (order: 1, 8192 bytes, linear) TCP: Hash tables configured (established 1024 bind 1024) UDP hash table entries: 256 (order: 0, 4096 bytes, linear) UDP-Lite hash table entries: 256 (order: 0, 4096 bytes, linear) NET: Registered PF_UNIX/PF_LOCAL protocol family RPC: Registered named UNIX socket transport module. RPC: Registered udp transport module. RPC: Registered tcp transport module. RPC: Registered tcp NFSv4.1 backchannel transport module. Bus freq driver module loaded Initialise system trusted keyrings workingset: timestamp_bits=30 max_order=14 bucket_order=0 fuse: init (API version 7.37) Key type asymmetric registered Asymmetric key parser 'x509' registered Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251) io scheduler mq-deadline registered io scheduler kyber registered 4007c000.serial: ttyLP0 at MMIO 0x4007c010 (irq = 447, base_baud = 1500000) is a FSL_LPUART fsl-lpuart 4007c000.serial: Serial: Console lpuart rounded baud ratefrom 187500 to 115200 printk: console [ttyLP0] enabled PPP generic driver version 2.4.2 PPP BSD Compression module registered PPP Deflate Compression module registered usbcore: registered new interface driver rt2800usb usbcore: registered new interface driver cdc_acm cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters usbcore: registered new interface driver uas usbcore: registered new interface driver usb-storage i2c_dev: i2c /dev entries driver usbcore: registered new interface driver btusb sdhci: Secure Digital Host Controller Interface driver sdhci: Copyright(c) Pierre Ossman sdhci-pltfm: SDHCI platform and OF driver helper usbcore: registered new interface driver usbhid usbhid: USB HID core driver NET: Registered PF_PACKET protocol family mmc0 bounce up to 128 segments into one, max segment size 65536 bytes Bluetooth: RFCOMM TTY layer initialized Bluetooth: RFCOMM socket layer initialized Bluetooth: RFCOMM ver 1.11 ARMv7-M VFP coprocessor found VFP: Double precision floating points are supported Loading compiled-in X.509 certificates mmc0: SDHCI controller on 40418000.usdhc [40418000.usdhc] using DMA input: gpio-keys as /devices/platform/gpio-keys/input/input0 cfg80211: Loading compiled-in X.509 certificates for regulatory database cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7' Freeing unused kernel image (initmem) memory: 188K This architecture does not have kernel memory protection. Run /init as init process platform regulatory.0: Direct firmware load for regulatory.db failed with error -2 cfg80211: failed to load regulatory.db Mounting /proc.. Reading /proc/meminfo: MemTotal: 59060 kB MemFree: 55884 kB MemAvailable: 54632 kB Buffers: 0 kB Cached: 184 kB SwapCached: 0 kB Active: 0 kB Inactive: 0 kB Active(anon): 0 kB Inactive(anon): 0 kB Active(file): 0 kB Inactive(file): 0 kB Unevictable: 184 kB Mlocked: 0 kB MmapCopy: 116 kB SwapTotal: 0 kB SwapFree: 0 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 0 kB Mapped: 0 kB Shmem: 0 kB KReclaimable: 392 kB Slab: 2264 kB SReclaimable: 392 kB SUnreclaim: 1872 kB KernelStack: 248 kB PageTables: 0 kB SecPageTables: 0 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 29528 kB Committed_AS: 0 kB VmallocTotal: 0 kB VmallocUsed: 0 kB VmallocChunk: 0 kB Percpu: 64 kB Done Hello, IMXRT117X_NXPEVK-Linux! mmc0: host does not support reading read-only switch, assuming write-enable mmc0: new high speed SDHC card at address 59b4 mmcblk0: mmc0:59b4 USD 7.39 GiB mmcblk0: p1 Hello, IMXRT117X_NXPEVK-Linux! Hello, IMXRT117X_NXPEVK-Linux! Hello, IMXRT117X_NXPEVK-Linux! Hello, IMXRT117X_NXPEVK-Linux! Hello, IMXRT117X_NXPEVK-Linux! Hello, IMXRT117X_NXPEVK-Linux! Hello, IMXRT117X_NXPEVK-Linux! Hello, IMXRT117X_NXPEVK-Linux! ...