3. ABOUT THE PRESENTER
• Embedded Software Engineer at Adeneo Embedded
(Bellevue, WA)
Linux / Android
♦ BSP Adaptation
♦ Driver Development
♦ System Integration
Partners with Freescale
5. Quickboot on i.MX6 Introduction
ARE WE TALKING ABOUT FASTBOOT?
This presentation is about quick boot
• Fastboot is the protocol used by Android to communicate
with the bootloader in order to reflash a system on the
device
• Type fastboot into google: 90% hits within first 10 pages
are about android
Warning
Fastboot is not the subject here!
5
6. Quickboot on i.MX6 Introduction
SPEED DOES MATTER
• Critical systems
Automotive: need to handle CAN message within a
specific time frame after boot (typically x100ms)
Monitoring: need to reboot ASAP in case of failure
6
7. Quickboot on i.MX6 Introduction
SPEED DOES MATTER
Consumer are used to previous generation of non-smart
devices that starts immediately
• Consumer products
TV: turn on quickly whenever pressing on the power
button
Phones: deep sleep mode allowing to have a
aggressive power management policy while keeping
responsiveness
7
8. Quickboot on i.MX6 Introduction
SPEED DOES MATTER
It is still possible to cheat
• Display splash screen early in the bootloader (x100ms)
• Animate the splash screen while booting
Those tricks give the end user the illusion of a quick boot, but
this could not apply to critical systems.
8
9. Quickboot on i.MX6 Introduction
SET YOUR GOALS
• Need to have clear goals:
Prioritize features
Set constraints
• Boot-Time optimization = trade-offs
9
10. Quickboot on i.MX6 Introduction
GOAL OF THE PRESENTATION
This presentation aims at:
• Showing different existing technics to optimize boot time
• Explaining how to integrate those technics
• Showing real customer solutions
10
13. Quickboot on i.MX6 Boot Process
BOOT PROCESS
Typical i.MX6 boot process:
• Boot ROM
• U-Boot
• Linux Kernel
• Rootfs:
Linux
Android
13
14. Quickboot on i.MX6 Boot Process
BOOT ROM
• Boot devices:
NOR Flash
NAND Flash
OneNAND Flash
SD/MMC
SATA HDD (only i.MX 6Dual/6Quad)
Serial (I2C/SPI) NOR Flash and EEPROM
14
15. Quickboot on i.MX6 Boot Process
BOOT ROM
• IVT Header
Entry point (fixed offset)
Points to DCD table
• DCD Table
List of init commands
• Boot data
A table indicating the program image offset and size
15
16. Quickboot on i.MX6 Boot Process
MEASUREMENT TOOLS
• Grabserial
Serial output time-stamps
• Bootgraph
Kernel driver graph
• Bootchart
Init scripts graph
16
19. Quickboot on i.MX6 Optimizations
INTUITION
The first things that comes in mind are usually:
• Smaller size
Loads faster (bandwidth of the storage mdevice)
Loads from faster storage (NOR, MMC class 10)
• Remove uneeded features
Smaller system (see above)
Not wasting time
19
20. Quickboot on i.MX6 Optimizations
GENERIC OPTIMIZATIONS
• lpj
If your products are similar, you can set lpj
Gain about 250 ms by skipping the calibration loop
• Stripping init
Start your critical application as soon as possible: rcS
or inittab
An idea may be to try to use your critical application as
init
20
21. Quickboot on i.MX6 Optimizations
GENERIC OPTIMIZATIONS
• flash storage:
NAND, NOR, SD
We usually get really good performance booting from
SD cards, class 4 or class 6, but you will still have to
benchmark
• toolchains
Not all toolchains are created equal. Changing
toolchains, will usually make you gain the last hundred
of ms
21
22. Quickboot on i.MX6 Optimizations
BOOTLOADER
• U-Boot is slow? Get rid of it!
• arm-kernel-shim solutions
• Freescale platforms: configure just a few register then
passing atags
Thanks to BootROM / DCD table
22
23. Quickboot on i.MX6 Optimizations
BOOTLOADER
• Kernel may not initialize every device
relies on the bootloader
• Should we migrate everything to the kernel?
23
24. Quickboot on i.MX6 Optimizations
GENERIC SOLUTIONS
U-Boot Secondary Program Loader (SPL)
• Small binary that fits in SRAM and loads the main U-Boot
into RAM
• Within U-Boot source tree, sharing same code base
• Two scenarios:
Fast path: SPL loads and then starts Linux kernel
Development or maintenance mode: SPL loads
U-Boot
24
25. Quickboot on i.MX6 Optimizations
KERNEL OPTIMIZATIONS
• Remove as many features as possible
The smaller, the faster to copy from storage to RAM
Less features means less initializations
• Not always what you want
What about a full-featured kernel?
• Easy optimizations:
printk and DEBUGFS
try CONFIG_CC_OPTIMIZE_FOR_SIZE=y
SLOB memory allocator
KALLSYMS
25
26. Quickboot on i.MX6 Optimizations
KERNEL OPTIMIZATIONS
• Stripping a lot of features from is not always possible
• Use modules!
Load them when your critical application is ready
Not always possible to compile as module (example:
networking)
• Kernel compression
None
Gzip
LZO
26
27. Quickboot on i.MX6 Optimizations
KERNEL OPTIMIZATIONS
Use of deferred_initcalls
• Kernel stills grows
• Need to patch kernel
see http://elinux.org/Deferred_Initcall
• Need to modify drivers
deferred_module_init
• Will execute some init only when asked for (user-space)
cat /proc/deferred_initcalls
27
28. Quickboot on i.MX6 Optimizations
SMP
• SMP is quite slow to initialize
• UP systems may be faster to boot
• Hotplug the other cores afterwards
/sys/devices/system/cpu/cpuX/online
28
29. Quickboot on i.MX6 Optimizations
ROOTFS
• Multiple challenges when building your rootfs
May not be able to optimize the customer’s application
Even worse, you may not have the sources (blobs)
Sometimes not possible to reduce the size of your
rootfs
29
30. Quickboot on i.MX6 Optimizations
ROOTFS
• Use an initramfs, but use it right!
• For critical tasks only
• Use of uClibc reduces the size
• Use of mklibs to further strip the libs
• Then switch_root or pivot_root to the final rootfs
30
32. Quickboot on i.MX6 Solutions
SOLUTIONS
• Boot from SDcard
• Custom bootloader
• Stripped down kernel
• Start a custom init:
launches critical application (CAN daemon)
calls deferred_initcalls
switch_root to the final rootfs and exec the final init
32
33. Quickboot on i.MX6 Solutions
SOLUTIONS
• Boot from SDcard
• Custom bootloader
• Stripped down kernel
• Start a custom init that launches the OpenGL application
• Rootfs has been stripped using mklibs
• Final image (bootloader + kernel + rootfs): 5.2MB
3MB for HW blobs libraries
No compression
33
34. Quickboot on i.MX6 Solutions
RESULTS
• CAN messages ready for transfer in about 360ms
• OpenGL application is started in 720ms from power on
590ms from reset
34
35. Quickboot on i.MX6 Solutions
NEXT STEPS
• Use of DMA to load the image
• Parallel inits
• Provide a more generic solution
35
38. Quickboot on i.MX6 Demonstrations
SOURCE CODE
• Code for the custom bootloader:
https://github.com/alexandrebelloni/whoosh
• Code for U-Boot SPL: coming soon...
• Main inspiration was http://www.elinux.org/Boot_Time but it
needs some updates
38