!1 42 Tizen v2.3 Bootup
内容!2 42 Bootloader(U-boot) Bootloader 概述 U-boot Systemd Systemd 概述 Platform Bootup Parsing Unit File
!3 42 Bootloader(U-boot)
Tizen bootup 概述!4 引导加载程序 将机器 id 和启动参数传递给内核 Power on ROM code Booting device Bootloader Kernel Platform
什么是引导加载程序 bootloader!5 引导加载程序是什么? 引导加载程序是当系统初始化时的第 一个执 行程序 ( 在主程序前, 例如内核 ) 引导加载程序是 一个计算机程序, 在 自检完成后加载主程序 ( 即操作系统内核 ) 为什么需要引导加载程序? 给出了 一个开发环境 节省了 flash 读写的成本 给加载任何操作系统提供灵活性
引导加载程序的类型!6 引导加载程序的不同类型是什么? Boot-ROM ( or Pre-Boot Loader) 小代码加载第 一阶段引导加载程序 First Stage Boot Loader 小段代码初始化 NAND/MMC & DRAM 控制器 Second Stage Boot Loader 第 二阶段的引导加载程序的主要功能是内核加载到 RAM 或直接跳跃到内核的开始 Pre-Bootloader First-Stage Bootloader Second-Stage Bootloader OS Kernel
U-boot 加载过程!7 Cortex-A9 Exynos4412 DRAM controller DRAM 1 Internal ROM irom code Internal SRAM essd controller NAND controller SD/MMC controller UART/USB Booting Device (NAND, MMC, SD, USB) 1 st BL 2 2 nd BL 3 OS
U-boot 加载过程!8 BL0; irom code (boot-rom or pre-boot loader) 简单的平台 无关的代码存储在内部 ROM 初始化基本功能 ( 时钟, 栈, 堆, 等等 ) 加载第 一阶段引导加载程序 ( 从启动设备内部存储器 ) BL1; first boot loader 简单的平台 无关的代码存储在外部存储器 ( 引导设备 ) 加载第 二引导加载程序 初始化 NAND/MMC & DRAM 控制器 BL2; second boot loader 平台依赖复杂的代码存储在外部存储器中 初始化时钟,UART 从引导装载操作系统映像 DRAM 的 手段 跳转到操作系统
U-boot 目录结构!9 /u-boot /u-boot api Machine/arch independent API examples Example code for standalone applications arch Architecture specific files fs Filesystem code jffs2, etc.) (cramfs, ext2, board Board dependent files include Header files common Misc architecture independent functions lib Files generic to all architectures disk Code for disk drive partition handling net Networking code doc Documentation post Power on self test drivers Commonly used device drivers rtc Real time clock drivers tools Tools to build S-Record or images U-boot
U-boot 编码顺序!10 1. 禁 用所有中断 2. 从 ROM 将所有初始化数据复制到 RAM 3. 清空未初始化的数据区域 4. 分配和初始化堆栈空间 5. 初始化处理器的堆栈指针 6. 创建并初始化堆 7. 执 行所有全局数据的初始化 8. 启 用中断 9. 调 用主循环
U-boot 编码顺序!11 Reset CPU and Hardware cpu/armv7/start.s _start() Setup SP Board Setup Environment for Early (ASM->C) Disable IRQ &FIQ. supervisor mode cpu/armv7/start.s reset() Switch to arm/lib/crt0.s _main() Early Board Setup General Relocation cpu/armv7/start.s relocate_code() Low Level Initialization arm/lib/crt0.s board_init_f() Copy Binary to RAM cpu_init_crit Invalidate and disable Instruction & data Cache Calculate Addresses (SP, Dest, GD) for Relocation Fix Relocation Clear BSS Disable MMU lowlevel_init board/samsung/lowlevel_init.s lowlevel_init() Setup SP for Common Board Setup Setup GD and JUMP to Final Board Setup arm/lib/crt0.s board_init_r() Jump into main loop
U-boot 编码顺序!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 编码顺序!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 编码顺序!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 编码顺序!15 main_loop() Wait for 3 seconds Key pressed within 3 seconds Input command Command_mode() Autoboot_mode() boot() loads() tftpboot() flash() Jump to kernel image address
通过 U-boot 加载!16 Reset CPU SDRAM Kernel Root File-System Booting device Bootloader uboot Kernel Image Root File System Optional compressed Bootloader uboot
通过 U-boot 加载!17 打包 uimage When the kernel is complied, mkimage attaches image_header to kernel image 解包 uimage Magin number! CRC check! decompress! get board information! kernel booting #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;
start_kernel!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]
!19 start_kernel 内存和系统初始化, 缓存和缓冲初始化, 文件系统初始化 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]
!20 systemd
什么是 systemd?!21 Sysvinit userspace launch (PID 1) 一次只有 一个进程运 行 直接启动系统, 然后 sleep 直到下 一次重新启动 Systemd Default init in Fedora 15 and later Leonard Poettering (2009) 改善软件框架来表达依赖性 允许在系统启动时同时或并 行处理更多的过程 减少计算开销
!22 什么是 systemd? Systemd in Tizen System and service manager for tizen systemd Ver. (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
systemd 体系结构!23
systemd 体系结构!24 systemd Utility 监测和控制 systemd 本 身和它的服务 systemctl 开发 人员可以查询或发送控制命令对 systemd 服务管理者 'systemd-journalctl' 用于查看 日志 文件 systemd target Tizen 启动过程分开在不同的离散步骤, 每个步骤使 用 target 单元同步点来分组单位 每个 目标的启动过程是 高度并 行, 具体 目标单位在这样的顺序下的到达具有不确定性 systemd daemon Tizen 平台系统和服务管理者 作为初始化系统 'systemd' daemonruns 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 体系结构!25 systemd core 管理所有单元如 service, socket, mount 等等, 储存所有的 日志数据. 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
平台启动 sysinit.target!26 早期启动脚本 Most of file system are mounted and systemd related daemons are launched Kernel sysinit.target basic.target bootmode.target multi-user.target graphical.target dev-hugepages.mount dev-mqueue.mount proc-sys-fs-binfmt_misc.automount sys-fs-fuse-connections.mount sys-kernel-config.mount sys-kernel-debug.mount sys-kernel-security.mount systemd-ask-password-console.path systemd-binfmt.service systemd-journald.service systemd-modules-load.service systemd-random-seed-load.service systemd-readahead-collect.service systemd-readahead-replay.service systemd-sysctl.service systemd-tmpfiles-setup.service swap.target -.mount local-fs.target boot.mount csa.mount fsck-root.service media.mount opt-usr.mount opt.mount remount-rootfs.service resize2fs-root.service systemd-remount-api-vfs.service var-run.mount socket.target dbus.socket systemd-initctl.socket systemd-journald.socket systemd-shutdownd.socket telnetd.socket udev-control.socket udev-kernel.socket
平台启动 basic.target!27 基础启动 All necessary initialization for general purpose daemons are completed Kernel sysinit.target basic.target bootmode.target multi-user.target graphical.target opt-var-kdb-db-libsqlfs.service opt-var-kdb-db-smack-labels.service smack-default-labeling.service systemd-tmpfiles-clean.timer tizen-debug-level.service udev-trigger.service udev.service vconf-setup.service
平台启动 bootmote.target!28 选择启动模式 If kernel boot parameter has charger_detect_boot, the platform boots up as charging mode Kernel sysinit.target basic.target bootmode.target multi-user.target graphical.target bootmode-charging.service bootmode-graphical.service
平台启动 multi-user.target!29 设置 一个 无图形 支持的多 用户系统 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 bootmode.target multi-user.target graphical.target alarm-server.service avsystem.service bluetooth-address.service bluetooth-frwk-service.service bluetooth.service dbus.service dlog-main.service dlog-radio.service getty.target gps-manager.service media-server.service nfc-manager.service power-manager.service pulseaudio.service secure-storage.service sensor-framework.service system-server.service systemd-ask-password-wall.path systemd-logind.service systemd-user-sessions.service telephony.service
平台启动 graphical.target!30 设置 一个图形环境 System user session for app privilege daemons such as Enlightenment (window manager) Special target for middleware & mobile service Kernel sysinit.target basic.target ac.service launchpad-reload@app.service user-session@app.service wrt_launchpad_daemon@app.service bootmode.target xorg.service xorg.target tizen-mobile-session.target wrt-preinstall-widgets.service multi-user.target graphical.target core-efl.target boot-animation.service cbhm.service e17.service indicator.service osp-app-service.service quickpanel.service scim.service starter.path xmodmap.service xrdb.service tizen-middleware.target calendar.service contacts-service.service download-provider.service email.service msg-service.service pushd.service sound-server.service
!31 Systemd 分析
平台启动!32 systemd 控制从 initramfs 移动到 Tizen 平台的 systemd Run hardware init and fs mount, etc services 启动流程运 行 几个单元 (.target) 不同的 目标可以并 行运 行 许多 linux 发 行版采 用systemd 作为默认 Red Hat Enterprise Linux, CentOS, Fedora, Arch Linux, opensuse 不要使 用守护进程控制脚本 t(/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
平台启动!33 https://wiki.tizen.org/wiki/porting_guide entry point.target vs.service.target; service grouping.service; process run
解析单元 文件 示例 (1/8)!34 /usr/lib/systemd/system target to parse cat sysinit.target
解析单元 文件 示例 (2/8)!35 Website http://www.freedesktop.org/wiki/software/systemd/ systemd download http://www.freedesktop.org/software/systemd/ manpage
解析单元 文件 示例 (3/8)!36 Can search all function and unit, configuration of systemd enter target index
解析单元 文件 示例 (4/8)!37 target unit file
解析单元 文件 示例 (5/8)!38 Description on unit file option
解析单元 文件 示例 (6/8)!39
解析单元 文件 示例 (7/8)!40
解析单元 文件 示例 (8/8)!41 User awareness unit name = System Initialization If emergency is running, wait Run with local-fs.target, swap.target, sysinit.target.wants Run after local-fs.target, swap.target, emergency.service, emergency.target User can control service start and stop
不同的会话!42 [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]; actual work of unit excute Create telephony.service symlink at multi-user.target.wants
References! systemd official Site http://www.freedesktop.org/wiki/software/ systemd/ systemd FAQ (written by developer) http://0pointer.de/blog/projects/the-biggest-myths