Embedded Software Lab. @ SKKU
42
1
Tizen v2.3 Bootup
Embedded Software Lab. @ SKKU
42
2
• Bootloader(U-boot)– Bootloader Overview– U-boot
• Systemd– Systemd Overview– Platform Bootup– Parsing Unit File
Contents
Embedded Software Lab. @ SKKU
42
3
Bootloader(U-boot)
Embedded Software Lab. @ SKKU
42
4
• Bootloader– Pass Machine ID and the boot arguments to
kernel
Tizen Bootup Overview
ROM codePower onBooting device
Bootloader
Kernel
Platform
Embedded Software Lab. @ SKKU
42
5
• What is boot loader ?– A boot loader is the first program which
executes (before the main program i.e. kernel ) whenever a system is initialized
– A boot loader is a computer program that loads the main program (i.e. operating system, kernel ) for the board after completion of the self-tests
• Why boot loader is needed ?– Gives a development environment– Saves cost of flash writers– Give flexibility to load any operating system
What is Bootloader
Embedded Software Lab. @ SKKU
42
6
• What are different types of boot loaders ?– Boot-ROM ( or Pre-Boot Loader)
• Small code which loads First stage boot loader
– First Stage Boot Loader• Small Piece of code that initialize the NAND/MMC &
DRAM controller.
– Second Stage Boot Loader• Primary function of the second-stage boot loader is to
Loading the kernel into RAM or jumping directly to the start of the kernel.
Types of Bootloader
Pre-Bootloader
First-StageBootloader
Second-Stage
BootloaderOS Kernel
Embedded Software Lab. @ SKKU
42
7
Exynos4412
U-boot Loading Process
Internal ROM
Internal SRAM
Cortex-A9
DRAM controller DRAM
Booting Device
(NAND, MMC, SD, USB)
eSSD controller
NAND controller
SD/MMC controller
UART/USB
1st BL2nd BL
OS
iROM code1
2
3
Embedded Software Lab. @ SKKU
42
8
• BL0; iRom code (boot-rom or pre-boot loader)– Simple platform independent code, stored in internal ROM– Initialize basic functions (clock, stack, heap, etc)– Load first stage boot loader (from booting device to
internal SRAM)• BL1; first boot loader
– Simple platform independent code, stored in external memory(booting device)
– Load second boot loader– Initialize NAND/MMC and DRAM controller
• BL2; second boot loader– Platform dependent complex code, stored in external
memory– Initialize clock, UART– Load OS image from booting device to DRAM– Jump to operating system
U-boot Loading Process
Embedded Software Lab. @ SKKU
42
9
Tools to build S-Record or U-boot images
Example code for standalone applications
Filesystem code (cramfs, ext2, jffs2, etc.)
Header files
Files generic to all architectures
Networking code
Power on self test
Real time clock drivers
Machine/arch independent API
Architecture specific files
Board dependent files
Misc architecture independent functions
Code for disk drive partition handling
Documentation
Commonly used device drivers
U-boot Directory Structure
/u-boot
board
common
doc
drivers
include
lib
net
examples
fs
rtc
tools
post
arch
disk
api
/u-boot
Embedded Software Lab. @ SKKU
42
10
1. Disable all interrupts2. Copy any initialized data from ROM to RAM3. Zero the uninitialized data area4. Allocate space for and initialize the stack5. Initialize the processor’s stack pointer6. Create and initialize the heap7. Execute the initializers for all global data8. Enable interrupts9. Call main loop
U-boot Code Sequence
Embedded Software Lab. @ SKKU
42
11U-boot Code Sequence
Setup SP for Early Board Setup
Environment (ASM->C)
Calculate Addresses (SP, Dest, GD) for Relocation
General Relocation
Copy Binary to RAM
Fix Relocation
Clear BSS
Setup SP for Common Board Setup
Setup GD and JUMP toFinal Board Setup
Low Level Initialization
lowlevel_init
cpu_init_crit
Disable MMU
Invalidate and disable Instruction & data
Cache
Disable IRQ &FIQ. Switch to supervisor mode
cpu/armv7/start.Sreset()
Reset CPU and Hardwarecpu/armv7/start.S
_start()
arm/lib/crt0.S_main()
Early Board Setup
arm/lib/crt0.Sboard_init_f()
arm/lib/crt0.Sboard_init_r()board/samsung/
lowlevel_init.Slowlevel_init()
cpu/armv7/start.S relocate_code()
Jump into main loop
Embedded Software Lab. @ SKKU
42
12
• _start() /* Entry point function */• reset() /* Reset CPU configurations */
– save_boot_params() /* Save boot parameters */– Disable the FIQ & IRQ– Switch to supervisor mode– cpu_init_crit()
• Invalidate I, D Cache• Disable I cache if CONFIG_SYS_ICACHE_OFF• Disable MMU• lowlevel_init()
• _main() /* setup initial stack & global data. And jump to C routine for board
initialization */
U-boot Code Sequence
Embedded Software Lab. @ SKKU
42
13
• board_init_f()– arch_cpu_init // basic arch cpu dependent setup– board_early_init_f // early board initialization, UART pin setting– timer_init // initialize timer– env_init // initialize mmc/sdcard environment– init_baudrate // initialize baudrate settings– serial_init // serial communication setup– console_init_f // stage 1 init of console, configure console from
console.c– display_banner // say that we are here, print u-boot banner– print_cpuinfo // display cpu info – checkboard // display board info– init_func_i2c // initialize I2C– dram_init // configure available RAM backs– arm_pci_init
U-boot Code Sequence
Embedded Software Lab. @ SKKU
42
14
• board_init_r()– board_init // setup chipselects specific configuration– logbuff_init_ptrs // initialize default log level– mem_malloc_init // configure malloc area– nand_init mmc_init // initialize flash/mmc– env_relocate // relocate environment or set NULL– stdio_init // setup stdio ready for use– api_init // initialize API– console_init_r // fully init console as a device– arch_misc_init // miscellaneous arch dependent initialization– misc_init_r // miscellaneous platform dependent initialization– interrupt_init // set up exceptions– enable_interrupts // enable exceptions– board_late_init // board late initialization– eth_initialize // setup ethernet– main_loop // jump to main loop & waiting for commands from
console
U-boot Code Sequence
Embedded Software Lab. @ SKKU
42
15U-boot Code Sequence
Jump to kernel image address
main_loop()
Autoboot_mode()
Command_mode()
boot() loads() flash()tftpboot(
)
Input command
Wait for 3 seconds Key pressed within 3 seconds
Embedded Software Lab. @ SKKU
42
16Loading through U-boot
SDRAMSDRAM
RootFile-System
Kernel
Booting deviceBooting device
Kernel Image
Bootloaderuboot
Root File System
Reset
Bootloaderuboot
CPUCPU
Optional compressed
Embedded Software Lab. @ SKKU
42
17
• Packing uImage– When the kernel is complied, mkimage attaches
image_header to kernel image
• Unpacking uImage– Magin number CRC check decompress get board
information kernel booting
Loading through U-boot
#define IH_MAGIC 0x27051956 /* Image Magic Number */ #define IH_NMLEN 32 /* Image Name Length */ typedef struct image_header {
uint32_t ih_magic; /* Image Header Magic Number */uint32_t ih_hcrc; /* Image Header CRC Checksum */uint32_t ih_time; /* Image Creation Timestamp */uint32_t ih_size; /* Image Data Size */uint32_t ih_load; /* Data Load Address */uint32_t ih_ep; /* Entry Point Address */uint32_t ih_dcrc; /* Image Data CRC Checksum */uint8_t ih_os; /* Operating System */uint8_t ih_arch; /* CPU architecture */uint8_t ih_type; /* Image Type */uint8_t ih_comp; /* Compression Type */uint8_t ih_name[IH_NMLEN]; /* Image Name */
} image_header_t;
Embedded Software Lab. @ SKKU
42
18
• Architecture dependent setup– setup_arch() [/arch/arm/kernel/setup.c]
• Exception(or trap) initialization– trap_init() [/arch/arm/kernel/trap.c]
• Interrupt initialization– init_IRQ() [/arch/arm/kernel/irq.c]– sotfirq_init() [/kernel/sotfirq.c]
• Scheduler initialization– sched_init() [/kernel/sched.c]
• Timer initialization– time_init() [/arch/XXX/kernel/time.c]
• Console initialization– console_init() [/driver/char/tty_io.c]
• Module initialization– init_module() [/kernel/module.c]
start_kernel
Embedded Software Lab. @ SKKU
42
19
• Memory & System initialization , Cache & Buffer initialization , File system initialization– kmem_cache_init() [/mm/slab.c]– mem_init() [/arch/a,r/mm/init.c]– kmem_cache_size() [/mm/slab.c]– fork_init() [/kernel/fork.c]– proc_caches_init() [/kernel/fork.c]– vfs_caches_init() [/fs/dcache.c]– buffer_init() [/fs/buffer.c]– page_cache_init() [/mm/filemap.c]– signals_init() [/kernel/signal.c]– proc_root_init() [/fs/proc/root.c]– ipc_init() [/ipc/util.c]
• init process creation– rest_init() [/init/main.c]
start_kernel
Embedded Software Lab. @ SKKU
42
20
Systemd
Embedded Software Lab. @ SKKU
42
21
• Sysvinit– userspace launch (PID 1)– Only one process at a time running– Simply starting the system and then going to sleep
until the next reboot• Systemd
– Default init in Fedora 15 and later Leonard Poettering (2009)
– improve the software framework for expressing dependencies
– allow more processing to be done concurrently or in parallel during system booting
– reduce the computational overhead of the shell.
What is Systemd?
Embedded Software Lab. @ SKKU
42
22
• Systemd in Tizen– System and service manager for tizen platform– Ver. 43 (download
http://www.freedesktop.org/software/systemd/)– Parallelizes service execution– Socket and D-Bus activation for starting services and
daemon– on-demand starting of daemons– Managing the service processes as a group using Linux
cgroup– Supporting automount points– Snapshotting and restoring of services
• Rethinking PID 1– http://0pointer.de/blog/projects/systemd.html
What is Systemd?
Embedded Software Lab. @ SKKU
42
23Systemd Architecture
Embedded Software Lab. @ SKKU
42
24
• systemd Utility – monitoring and controlling systemd itself and its services– systemctl: developers can query or send control commend to the
systemd service manager – systemd-journalctl: utility to see log message
• systemd Target – Tizen boot-up process is split up in various discrete steps and each
step are grouped its unit using 'Target' unit to synchronize point
– The boot-up process is highly parallelized in each target so that the order in which specific target units are reached in not deterministic
• systemd Daemon – system and service manager for Tizen platform– acts as init system– 'systemd' daemon runs as user session with '--user' option– 'systemd-journald' is a system service that collects and stores log
data from the Kernel, from user processes via syslog or STDOUT/STDERR
Systemd Architecture
Embedded Software Lab. @ SKKU
42
25
• systemd Core – manages all units such as service, socket, mount and so on, – stores all log data. – controlled by using systemd utility like 'systemctl'
• systemd library & Linux Kernel – systemd requires to enable 'cgroup' and 'autofs' option in
Kernel configuration– It also depends on dbus and some libraries such as libnotify,
libudev
Systemd Architecture
Embedded Software Lab. @ SKKU
42
26
• Early boot-up scripts– Most of file system are mounted and systemd related daemons are launched
Platform Bootup – sysinit.target
basic.target
sysinit.target
multi-user.target
graphical.target
Kernel
local-fs.target
swap.target
socket.target
csa.mountopt-usr.mountopt.mountresize2fs-root.servicesystemd-remount-fs.serviceusr-share-locale.mounttmp.mountSmack.mount
dev-hugepages.mount systemd-modules-load.servicedev-mqueue.mount systemd-sysctl.serviceinit-conf.service systemd-tmpfiles-setup-dev.servicekmod-static-nodes.service systemd-tmpfiles-setup.servicesys-fs-fuse-connections.mount systemd-udevd.servicesys-kernel-config.mount systemd-udev-trigger.servicesys-kernel-debug.mount systemd-update-utmp.servicesystemd-ask-password-console.path tizen-debug-off.servicesystemd-journald.service tizen-debug-on.servicesystemd-journal-flush.service
dbus.socketsystemd-initctl.socketsystemd-journald.socketsystemd-shutdownd.sockettelnetd.socketudev-control.socketudev-kernel.socket
Tizen-boot.targetTizen-system.targetTizen-runtime.target
Embedded Software Lab. @ SKKU
42
27
• Basic boot-up– All necessary initialization for general purpose daemons are completed
Platform Bootup – basic.target
cleanup-storage.servicesmack.servicetizen-generate-env.servicevconf-setup.serviceklogd.servicesyslogd.servicetizen-init-check.servicexorg.service
basic.target
sysinit.target
multi-user.target
graphical.target
Kernel
Tizen-boot.targetTizen-system.targetTizen-runtime.target
Embedded Software Lab. @ SKKU
42
28
• Prepare Tizen booting– Display booting animation– Execute Launchpad daemon (launcher)
Platform Bootup – Tizen target
tizen-system.target tizen-middleware.targetboot-animation.servicelate-tizen-system.servicewait-lock.servicecheck-mount.servicesilent-animation.service
tizen-boot.target
wm_ready.service
basic.target
sysinit.target
multi-user.target
graphical.target
Kernel
Tizen-boot.targetTizen-system.targetTizen-runtime.target
Embedded Software Lab. @ SKKU
42
29
• Setup a multi-user system which is non-graphical support– Launching platform infrastructure daemons (such as dbus, power manager, gps
manager, telephony daemon, WRT security daemon, media server, systemd-related daemons)
Platform Bootup – multi-user.target
basic.target
sysinit.target
multi-user.target
graphical.target
Kernel
Tizen-boot.targetTizen-system.targetTizen-runtime.target
Embedded Software Lab. @ SKKU
42
30
• Setup a graphical environment– System user session for app privilege daemons such as Enlightenment (window
manager)– Special target for middleware & mobile service
Platform Bootup – graphical.target
core-efl.target
tizen-middleware.target
cbhm.servicee17.serviceindicator.servicescim.servicexrdb.service
bluetooth-frwk.servicetizen-fstrim-user.timerxresources.pathdownload-provider.servicetizen-initial-boot-done.servicezbooting-done.serviceemail-service.servicetizen-journal-flush.servicelaunchpad-process-pool.servicetizen-readahead-replay.service
email.servicepushd.service
basic.target
sysinit.target
multi-user.target
graphical.target
Kernel
Tizen-boot.targetTizen-system.targetTizen-runtime.target
Embedded Software Lab. @ SKKU
42
31
• Systemd– Control is moved from initramfs to systemd of Tizen platform– Run hardware init and fs mount, etc services– Bootup process run several units (.target)
• Different targets can be run in parallel– Many linux distributions adopt systemd as default
• Red Hat Enterprise Linux, CentOS, Fedora, Arch Linux, openSUSE
– Do not use daemon control script (/sbin/init, /etc/init.d/*, /etc/rc*.d)
– /usr/lib/systemd• unit files: service, target, socket, device, mount,
automount, path, snapshot, swap, timer• systemd utilities: systemctl, notify, analyze, cgis, cgtop,
logictl, journalctl, nspawn
Platform Bootup
Embedded Software Lab. @ SKKU
42
32
Kernel
sysinit.target
basic.target
Tizen-boot.target
Systemd
Platform Bootup
entry point
.target vs .service• .target; service grouping• .service; process run
Embedded Software Lab. @ SKKU
42
33
• /usr/lib/systemd/system
• cat sysinit.target
Parsing Unit File – Example (1/8)
target to parse
Embedded Software Lab. @ SKKU
42
34
• Website – http://www.freedesktop.org/wiki/Software/systemd/
• systemd download– http://www.freedesktop.org/software/systemd/
Parsing Unit File – Example (2/8)
manpage
Embedded Software Lab. @ SKKU
42
35Parsing Unit File – Example (3/8)
Can search all functions, units, configurations of systemd
enter target index
Embedded Software Lab. @ SKKU
42
36Parsing Unit File – Example (4/8)
target unit file
Embedded Software Lab. @ SKKU
42
37Parsing Unit File – Example (5/8)
Description on unit file options
Embedded Software Lab. @ SKKU
42
38Parsing Unit File – Example (6/8)
Embedded Software Lab. @ SKKU
42
39Parsing Unit File – Example (7/8)
Embedded Software Lab. @ SKKU
42
40Parsing Unit File – Example (8/8)
• User-aware unit name = “System Initialization”• If emergency is running, wait• Run with local-fs.target, swap.target, • Delayed until local-fs.target, swap.target, emergency.service,
and emergency.target are started up. • User can control service start and stop
Embedded Software Lab. @ SKKU
42
41
• [Unit], [Service], [Install], [Socket], [Swap], [Mount], …– example; telephony.service– [Unit]; general options
• unit name = Telephony daemon• Run after modem.service
– [Service]; process options• Run telephony-daemon as main process
– [Install]; carries installation information for the unit• systemctl enable will create a symlink of multi-user.target.wants
Different Sessions
Embedded Software Lab. @ SKKU
42
42
• systemd official Site http://www.freedesktop.org/wiki/Software/systemd/
• systemd FAQ (written by developer)– http://0pointer.de/blog/projects/the-biggest-myths
References