Booting uClinux on SmartFusion2 in 0.5 Seconds |
Fast-booting Linux on SmartFusion2 Watch this video to see how Linux (uClinux) boots up on SmartFusion2 from power-up to the interactive shell in about 0.5 seconds. The hardware platform is Emcraft Systems' M2S-FG484 system-on-module (SOM) plugged into the SOM-BSB-EXT baseboard. Both Cortex-M3 and LPDDR are configured to run at 142 MHz. PCLK0 is set to a 1/2 of the main clock (71 MHz), allowing to run SPI_0 and access the SPI Flash at up to 35.5 MHz. The on-chip cache is enabled by software for LPDDR. The Linux configuration used in this demo targets a typical "data harvesting" device. Support for the SPI controller, SPI Flash, Flash partitioning and JFFS2 are all enabled in the kernel. As soon as Linux comes up to the shell, a data harvesting application (or any number of such applications) can be started from the /etc/rc start-up script, collecting data from various sensors and logging collected data into the on-module SPI Flash. As can be seen from the above video, it takes uClinux only 0.5 seconds from power-up / reset to the point where data harvesting can commence. Linux Bootstrap Sequence The Linux boostrap can be described by the following sequence:
Installing the Demo The procedure described here explains how to install the bootable Linux image (fastboot.uImage) to the target. Here is how you can build and install the bootable Linux image from the project sources (fastboot.tgz), having installed them on top of the Emcraft Systems SmartFusion2 uClinux distribution. Note: The Linux image and the sample project have been built and validated in context of the Emcraft Systems Release 1.14.3. If you are using a different release, some porting changes may be needed. Understanding the Demo Here is a detailed description of the demo. The first message printed by U-Boot after power-up/reset is as follows: U-Boot 2010.03-cortexm-1.14.3 (Nov 04 2015 - 13:06:17) U-Boot proceeds with initialization of the target and reports various characteristics of the hardware platform: CPU : SmartFusion®2 SoC (Cortex-M3 Hard IP) U-Boot then waits for the number of seconds defined by the bootdelay environment variable before proceeding to execute a bootup sequence defined by the bootcmd variable. If the user presses any key while in the bootdelay loop, U-Boot interrupts the boot-up sequence and enters the interactive command monitor. Initially we set bootdelay to 3. Hit any key to stop autoboot: 0 Now, this is the point when the bootdelay loop has expired and the bootcmd commands sequence is being executed. On SmartFusion2, the first action bootcmd performs is loading a bootable Linux image from the SPI Flash to the LPDDR: 16384 KiB S25FL128S_64K at 0:0 is now current device Then a bootm command is called upon the image loaded into DDR. What this command does is, parse the image header, figure out the image type and size, optionally verify the checksum and pass control to the kernel entry point: ## Booting kernel from Legacy Image at a0007fc0 ... This is where U-Boot is done and the Linux kernel starts running: Starting kernel ... The following are the first messages printed by the kernel: Linux version 2.6.33-arm1 (vlad @ocean.emcraft.com) (gcc version 4.4.1 (Sourcery G++ Lite 2010q1-189) ) #79 Thu Dec 27 11:32:17 +0400 2012 Note the kernel input arguments passed by U-Boot to the kernel. This is defined by bootargs in U-Boot: Kernel command line: m2s_platform=m2s-fg484-som console=ttyS0,115200 panic=10 The kernel proceeds to set the memory up. We have 64 MB of LPDDR to run Linux from: Memory: 64MB = 64MB total Then the kernel runs the so-called "calibration loop" in order to calculate loops-in-jiffies also referred to as lpj. The lpj value is used by the kernel to implement various delays. Note that as part of the calibration loop, the kernel also calculates the BogoMIPS value, which is a Linux approximation of the MIPS (Million Instructions Per Second) metric: Calibrating delay loop... 132.30 BogoMIPS (lpj=661504) The UART device driver and the serial console are initialized: Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled The SPI device driver is started and the SPI Flash is partitioned onto 3 separate logical partitions. Each partition can be accesses as a separate logical device by user-space code: m25p80 spi0.0: s25fl129p1 (16384 Kbytes) The initramfs root filesystem is mounted and init, which is the first user-space process, is launched: init started: BusyBox v1.17.0 (2012-12-14 10:29:39 +0400) init proceeds to execute a start-up command-line sequence defined by the /etc/rc script. In our application, we have /etc/rc contain a single command (echo "Data harvesting can commence"), which results in the output below: Data harvesting can commence And finally, init starts the interactive command shell: / # Configuring for Fast-Boot To achieve the ~0.5 seconds boot times shown in the above video, you will need to specifically configure U-Boot. Note that each of the configuration steps described below is optional, in the sense that if you don't perform a certain optimization step, the demo will still boot on the target, although slightly slower than it would otherwise. From the U-Boot prompt, do the following:
M2S-FG484-SOM> set verify no M2S-FG484-SOM> set args ${args} lpj=661504 M2S-FG484-SOM> set args ${args} quiet=quiet M2S-FG484-SOM> set bootdelay 0 M2S-FG484-SOM> saveenv U-Boot 2010.03-cortexm-1.14.3 (Nov 04 2015 - 13:06:17) Restoring Default Configuration Please step through the following procedure to restore the default configuration:
U-Boot 2010.03-cortexm-1.14.3 (Nov 04 2015 - 13:06:17) M2S-FG484-SOM> print args |