Tizen V2.3 Bootup
Total Page:16
File Type:pdf, Size:1020Kb
!1 42 Tizen v2.3 Bootup Embedded Software Lab. @ SKKU 内容 !2 42 • Bootloader(U-boot) – Bootloader 概述 – U-boot • Systemd – Systemd 概述 – Platform Bootup – Parsing Unit File Embedded Software Lab. @ SKKU !3 42 Bootloader(U-boot) Embedded Software Lab. @ SKKU !4 Tizen bootup 概述 43 • 引导加载程序 – 将机器 id和启动参数传递给内核 Power on ROM code Booting device Bootloader Kernel Platform Embedded Software Lab. @ SKKU !5 什么是引导加载程序 bootloader 43 • 引导加载程序是什么 ? – 引导加载程序是当系统初始化时的第⼀个执⾏程序 (在主程 序前,例如内核 ) – 引导加载程序是⼀个计算机程序 ,在⾃检完成后加载主程序 (即操作系统内核 ) • 为什么需要引导加载程序 ? – 给出了⼀个开发环境 – 节省了 flash读写的成本 – 给加载任何操作系统提供灵活性 Embedded Software Lab. @ SKKU !6 引导加载程序的类型 43 • 引导加载程序的不同类型是什么 ? – Boot-ROM ( or Pre-Boot Loader) • ⼩代码加载第⼀阶段引导加载程序 – First Stage Boot Loader • ⼩段代码初始化 NAND/MMC & DRAM控制器。 – Second Stage Boot Loader • 第⼆阶段的引导加载程序的主要功能是内核加载到 RAM或直接跳跃到 内核的开始。 First-Stage Second-Stage Pre-Bootloader OS Kernel Bootloader Bootloader Embedded Software Lab. @ SKKU !7 U-boot 加载过程 43 Exynos4412 DRAM controller DRAM Cortex-A9 eSSD controller Internal ROM 1 iROM code Booting Device NAND controller (NAND, MMC, SD, USB) 1st BL SD/MMC controller 2 2nd BL Internal SRAM 3 OS UART/USB Embedded Software Lab. @ SKKU !8 U-boot 加载过程 43 • BL0; iRom code (boot-rom or pre-boot loader) – 简单的平台⽆关的代码存储在内部 ROM – 初始化基本功能 (时钟 ,栈 ,堆 ,等等 ) – 加载第⼀阶段引导加载程序 (从启动设备内部存储器 ) • BL1; first boot loader – 简单的平台⽆关的代码存储在外部存储器 (引导设备 ) – 加载第⼆引导加载程序 – 初始化 NAND/MMC & DRAM控制器 • BL2; second boot loader – 平台依赖复杂的代码存储在外部存储器中 – 初始化时钟 ,UART – 从引导装载操作系统映像 DRAM的⼿段 – 跳转到操作系统 Embedded Software Lab. @ SKKU !9 U-boot ⺫录结构 43 /u-boot /u-boot api examples Machine/arch independent API Example code for standalone applications arch Architecture specific files fs Filesystem code (cramfs, ext2, jffs2, etc.) board include Board dependent files Header files common Misc architecture independent functions lib Files generic to all architectures disk net Code for disk drive partition handling Networking code doc post Documentation Power on self test drivers Commonly used device drivers rtc Real time clock drivers tools Tools to build S-Record or U-boot images Embedded Software Lab. @ SKKU !10 U-boot 编码顺序 43 1. 禁⽤所有中断 2. 从 ROM将所有初始化数据复制到 RAM 3. 清空未初始化的数据区域 4. 分配和初始化堆栈空间 5. 初始化处理器的堆栈指针 6. 创建并初始化堆 7. 执⾏所有全局数据的初始化 8. 启⽤中断 9. 调⽤主循环 Embedded Software Lab. @ SKKU !11 U-boot 编码顺序 43 Reset CPU and Hardware cpu/armv7/start.S _start() Setup SP for Early Board Setup Environment (ASM->C) Disable IRQ &FIQ. Switch to supervisor mode General Relocation arm/lib/crt0.S cpu/armv7/start.S _main() reset() cpu/armv7/start.S Early Board Setup relocate_code() arm/lib/crt0.S Low Level Initialization board_init_f() Copy Binary to RAM cpu_init_crit Calculate Addresses (SP, Dest, GD) for Fix Relocation Invalidate and disable Relocation Instruction & data Cache Clear BSS Disable MMU Setup SP for Common Board Setup Setup GD and JUMP to Final Board Setup lowlevel_init arm/lib/crt0.S board/samsung/lowlevel_init.S board_init_r() lowlevel_init() Jump into main loop Embedded Software Lab. @ SKKU !12 U-boot 编码顺序 43 • _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 */ Embedded Software Lab. @ SKKU !13 U-boot 编码顺序 43 • 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 Embedded Software Lab. @ SKKU !14 U-boot 编码顺序 43 • 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 Embedded Software Lab. @ SKKU !15 U-boot 编码顺序 43 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 Embedded Software Lab. @ SKKU !16 通过 U-boot加载 43 SDRAM Reset CPU Kernel Root File-System Booting device Bootloader uboot Bootloader uboot Kernel Image Optional compressed Root File System Embedded Software Lab. @ SKKU !17 通过 U-boot加载 43 • 打包 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; Embedded Software Lab. @ SKKU !18 start_kernel 43 • 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] Embedded Software Lab. @ SKKU !19 start_kernel 43 • 内存和系统初始化 ,缓存和缓冲初始化 ,⽂件系统初始化 – 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 43 systemd Embedded Software Lab. @ SKKU !21 什么是 systemd? 43 • Sysvinit – userspace launch (PID 1) – ⼀次只有⼀个进程运⾏ – 直接启动系统 ,然后 sleep直到下⼀次重新启动 • Systemd – Default init in Fedora 15 and later Leonard Poettering (2009) – 改善软件框架来表达依赖性 – 允许在系统启动时同时或并⾏处理更多的过程 – 减少计算开销。 Embedded Software Lab. @ SKKU !22 什么是 systemd? 43 • Systemd in Tizen – System and service manager for tizen systemd – 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 Embedded Software Lab. @ SKKU !23 systemd 体系结构 43 Embedded Software Lab. @ SKKU !24 systemd 体系结构 43 • 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 Embedded Software Lab. @ SKKU !25 systemd 体系结构 43 • 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 Embedded Software Lab. @ SKKU !26 平台启动 – sysinit.target 43 • 早期启动脚本 – Most of file system are mounted and systemd related daemons are launched Kernel sysinit.target -.mount local-fs.target boot.mount dev-hugepages.mount csa.mount dev-mqueue.mount basic.target fsck-root.service proc-sys-fs-binfmt_misc.automount media.mount sys-fs-fuse-connections.mount opt-usr.mount sys-kernel-config.mount bootmode.target opt.mount sys-kernel-debug.mount remount-rootfs.service sys-kernel-security.mount resize2fs-root.service systemd-ask-password-console.path systemd-remount-api-vfs.service multi-user.target systemd-binfmt.service var-run.mount systemd-journald.service systemd-modules-load.service graphical.target systemd-random-seed-load.service