1 42 Tizen v 2 3 Bootup Embedded
1 42 Tizen v 2. 3 Bootup Embedded Software Lab. @ SKKU
Contents 2 42 • Bootloader(U-boot) – Bootloader Overview – U-boot • Systemd – Systemd Overview – Platform Bootup – Parsing Unit File Embedded Software Lab. @ SKKU
3 42 Bootloader(U-boot) Embedded Software Lab. @ SKKU
Tizen Bootup Overview 4 42 • Bootloader – Pass Machine ID and the boot arguments to kernel Power on ROM code Bootloader Kernel Platform Embedded Software Lab. @ SKKU Booting device
What is Bootloader 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 Embedded Software Lab. @ SKKU 42
Types of Bootloader 6 42 • 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. Pre. Bootloader First-Stage Bootloader Second-Stage Bootloader Embedded Software Lab. @ SKKU OS Kernel
U-boot Loading Process 7 42 Exynos 4412 Cortex-A 9 Internal ROM 1 i. ROM code Internal SRAM DRAM controller DRAM e. SSD controller Booting Device (NAND, MMC, SD, USB) NAND controller SD/MMC controller UART/USB Embedded Software Lab. @ SKKU 2 1 st BL 2 nd BL 3 OS
U-boot Loading Process • BL 0; i. Rom 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) • BL 1; first boot loader – Simple platform independent code, stored in external memory(booting device) – Load second boot loader – Initialize NAND/MMC and DRAM controller • BL 2; 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 Embedded Software Lab. @ SKKU 8 42
U-boot Directory Structure /u-boot 9 42 /u-boot api Machine/arch independent API arch Architecture specific files board Board dependent files examples fs include Misc architecture independent functions lib disk Code for disk drive partition handling net doc Documentation post common drivers Commonly used device drivers rtc tools Example code for standalone applications Filesystem code (cramfs, ext 2, jffs 2, etc. ) Header files Files generic to all architectures Networking code Power on self test Real time clock drivers Tools to build S-Record or -boot images Embedded Software Lab. @ SKKU U
U-boot Code Sequence 1. 2. 3. 4. 5. 6. 7. 8. 9. Disable all interrupts Copy any initialized data from ROM to RAM Zero the uninitialized data area Allocate space for and initialize the stack Initialize the processor’s stack pointer Create and initialize the heap Execute the initializers for all global data Enable interrupts Call main loop Embedded Software Lab. @ SKKU 10 42
U-boot Code Sequence Reset CPU and Hardware cpu/armv 7/start. S _start() Disable IRQ &FIQ. Switch to supervisor mode cpu/armv 7/start. S reset() Low Level Initialization 11 42 Setup SP for Early Board Setup Environment (ASM->C) arm/lib/crt 0. S _main() Early Board Setup arm/lib/crt 0. S board_init_f() General Relocation cpu/armv 7/start. S relocate_code() Copy Binary to RAM cpu_init_crit Invalidate and disable Instruction & data Cache Disable MMU Calculate Addresses (SP, Dest, GD) for Relocation Fix Relocation Clear BSS Setup SP for Common Board Setup GD and JUMP to Final Board Setup lowlevel_init arm/lib/crt 0. S board_init_r() board/samsung/lowlevel_init. S lowlevel_init() Jump into main loop Embedded Software Lab. @ SKKU
U-boot Code Sequence • • _start() reset() – – save_boot_params() /* Save boot parameters */ Disable the FIQ & IRQ Switch to supervisor mode cpu_init_crit() • • • /* Entry point function */ /* Reset CPU configurations */ 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 */ Embedded Software Lab. @ SKKU 12 42
U-boot Code Sequence • board_init_f() – – – – arch_cpu_init board_early_init_f timer_init env_init_baudrate serial_init console_init_f display_banner print_cpuinfo checkboard init_func_i 2 c dram_init arm_pci_init // basic arch cpu dependent setup // early board initialization, UART pin setting // initialize timer // initialize mmc/sdcard environment // initialize baudrate settings // serial communication setup // stage 1 init of console, configure console from console. c // say that we are here, print u-boot banner // display cpu info // display board info // initialize I 2 C // configure available RAM backs Embedded Software Lab. @ SKKU 13 42
U-boot Code Sequence • board_init_r() – – – – board_init logbuff_init_ptrs mem_malloc_init nand_init mmc_init env_relocate stdio_init api_init console_init_r arch_misc_init_r interrupt_init enable_interrupts board_late_init eth_initialize main_loop // setup chipselects specific configuration // initialize default log level // configure malloc area // initialize flash/mmc // relocate environment or set NULL // setup stdio ready for use // initialize API // fully init console as a device // miscellaneous arch dependent initialization // miscellaneous platform dependent initialization // set up exceptions // enable exceptions // board late initialization // setup ethernet // jump to main loop & waiting for commands from console Embedded Software Lab. @ SKKU 14 42
U-boot Code Sequence 15 42 main_loop() Wait for 3 seconds Key pressed within 3 seconds Input command Command_mode() Autoboot_mode() boot() loads() Jump to kernel image address Embedded Software Lab. @ SKKU tftpboot() flash()
Loading through U-boot 16 42 SDRAM Reset CPU Kernel Root File-System Booting device Bootloader uboot Kernel Image Root File System Optional compressed Embedded Software Lab. @ SKKU
Loading through U-boot 17 • Packing u. Image – When the kernel is complied, mkimage attaches image_header to kernel image • Unpacking u. Image – Magin number CRC check decompress get board information kernel booting #define IH_MAGIC 0 x 27051956 /* Image Magic Number */ #define IH_NMLEN 32 /* Image Name Length */ typedef struct image_header { uint 32_t ih_magic; /* Image Header Magic Number */ uint 32_t ih_hcrc; /* Image Header CRC Checksum */ uint 32_t ih_time; /* Image Creation Timestamp */ uint 32_t ih_size; /* Image Data Size */ uint 32_t ih_load; /* Data Load Address */ uint 32_t ih_ep; /* Entry Point Address */ uint 32_t ih_dcrc; /* Image Data CRC Checksum */ uint 8_t ih_os; /* Operating System */ uint 8_t ih_arch; /* CPU architecture */ uint 8_t ih_type; /* Image Type */ uint 8_t ih_comp; /* Compression Type */ uint 8_t ih_name[IH_NMLEN]; /* Image Name */ } image_header_t; Embedded Software Lab. @ SKKU 42
start_kernel • Architecture dependent setup – setup_arch() [/arch/arm/kernel/setup. c] • Exception(or trap) initialization – trap_init() [/arch/arm/kernel/trap. c] • Interruptinitialization – init_IRQ() [/arch/arm/kernel/irq. c] – sotfirq_init() [/kernel/sotfirq. c] • Schedulerinitialization – sched_init() [/kernel/sched. c] • Timer initialization – time_init() [/arch/XXX/kernel/time. c] • Consoleinitialization – console_init() [/driver/char/tty_io. c] • Moduleinitialization – init_module() [/kernel/module. c] Embedded Software Lab. @ SKKU 18 42
start_kernel • 42 Memory &System initialization , Cache. Buffer & initialization , File system initialization – – – • 19 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] Embedded Software Lab. @ SKKU
20 42 Systemd Embedded Software Lab. @ SKKU
What is Systemd? 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. Embedded Software Lab. @ SKKU 42
What is Systemd? 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: //0 pointer. de/blog/projects/systemd. html Embedded Software Lab. @ SKKU 42
Systemd Architecture Embedded Software Lab. @ SKKU 23 42
Systemd Architecture 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 Embedded Software Lab. @ SKKU 42
Systemd Architecture • 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 Embedded Software Lab. @ SKKU 25 42
Platform Bootup – sysinit. target • Early boot-up scripts – Most of file system are mounted and systemd related daemons are launched Kernel sysinit. target basic. target Tizen-boot. target Tizen-system. target Tizen-runtime. target multi-user. target graphical. target dev-hugepages. mount systemd-modules-load. service dev-mqueue. mount systemd-sysctl. service init-conf. service systemd-tmpfiles-setupdev. service kmod-static-nodes. service systemd-tmpfiles-setup. service sys-fs-fuse-connections. mount systemd-udevd. service sys-kernel-config. mount systemd-udev-trigger. service sys-kernel-debug. mount systemd-update-utmp. service systemd-ask-passwordconsole. path tizen-debugoff. service systemd-journald. service tizen-debug-on. service systemd-journal-flush. service local-fs. target csa. mount opt-usr. mount opt. mount resize 2 fs-root. service systemd-remount-fs. service usr-share-locale. mount tmp. mount Smack. mount swap. target Embedded Software Lab. @ SKKU socket. target dbus. socket systemd-initctl. socket systemd-journald. socket systemd-shutdownd. socket telnetd. socket udev-control. socket udev-kernel. socket 26 42
Platform Bootup – basic. target • Basic boot-up – All necessary initialization for general purpose daemons are completed Kernel sysinit. target basic. target Tizen-boot. target Tizen-system. target Tizen-runtime. target multi-user. target graphical. target cleanup-storage. service smack. service tizen-generate-env. service vconf-setup. service klogd. service syslogd. service tizen-init-check. service xorg. service Embedded Software Lab. @ SKKU 27 42
Platform Bootup – Tizen target • 28 Prepare Tizen booting – Display booting animation – Execute Launchpad daemon (launcher) Kernel sysinit. target basic. target Tizen-boot. target Tizen-system. target Tizen-runtime. target multi-user. target graphical. target tizen-boot. target wm_ready. service tizen-system. target boot-animation. service late-tizen-system. service wait-lock. service check-mount. service silent-animation. service Embedded Software Lab. @ SKKU tizen-middleware. target wrt_launchpad_daemon@app. service 42
Platform Bootup – multi-user. target • 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) Kernel sysinit. target basic. target Tizen-boot. target Tizen-system. target Tizen-runtime. target multi-user. target graphical. target ac. service msg-server. service alarm-server. service calendar-serviced. service nfc-manager. service pkgmgr_recovery. service pulseaudio. service connman. service quickpanel. service contacts-service resourced. service crash-manager. service secure-storage. service data-provider-master. service dbus. service deviced. service smack-rules. service dlog_logger. service sound-server. path getty. target starter. service ghost. service systemd-ask-passwordwall. path gstreamer-registry. service telephony-daemon. service indicator. service launchpad-preload. service tizenid. service lbs-server. service media-server. service messageportd. service wrt-security-daemon. service Embedded Software Lab. @ SKKU 42
Platform Bootup – graphical. target • 30 Setup a graphical environment – System user session for app privilege daemons such as Enlightenment (window manager) – Special target for middleware & mobile service Kernel sysinit. target core-efl. target basic. target Tizen-boot. target Tizen-system. target Tizen-runtime. target multi-user. target graphical. target bluetooth-frwk. service tizen-fstrim-user. timer xresources. path download-provider. service tizen-initial-boot-done. service zbooting-done. service email-service tizen-journal-flush. service launchpad-process-pool. service tizen-readahead-replay. service Embedded Software Lab. @ SKKU cbhm. service e 17. service indicator. service scim. service xrdb. service tizen-middleware. target email. service pushd. service 42
Platform Bootup 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, Cent. OS, Fedora, Arch Linux, open. SUSE – 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 Embedded Software Lab. @ SKKU 42
Platform Bootup 32 42 Kernel Systemd sysinit. target basic. target Tizen-boot. target entry point . target vs. service • . target; service grouping • . service; process run Embedded Software Lab. @ SKKU
Parsing Unit File – Example (1/8) • /usr/lib/systemd/system target to parse • cat sysinit. target Embedded Software Lab. @ SKKU 33 42
Parsing Unit File – Example (2/8) • Website – http: //www. freedesktop. org/wiki/Software/systemd/ • systemd download – http: //www. freedesktop. org/software/systemd/ manpage Embedded Software Lab. @ SKKU 34 42
Parsing Unit File – Example (3/8) Can search all functions, units, configurations of systemd enter target index Embedded Software Lab. @ SKKU 35 42
Parsing Unit File – Example (4/8) target unit file Embedded Software Lab. @ SKKU 36 42
Parsing Unit File – Example (5/8) Description on unit file options Embedded Software Lab. @ SKKU 37 42
Parsing Unit File – Example (6/8) Embedded Software Lab. @ SKKU 38 42
Parsing Unit File – Example (7/8) Embedded Software Lab. @ SKKU 39 42
Parsing 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 40 42
Different Sessions • [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 enablewill create a symlink of multi-user. target. wants Embedded Software Lab. @ SKKU 41 42
References • systemd official Site http: //www. freedesktop. org/wiki/Software/systemd/ • systemd FAQ (written by developer) – http: //0 pointer. de/blog/projects/the-biggest-myths Embedded Software Lab. @ SKKU 42 42
- Slides: 42