Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
Embedded Software Lab. @ SKKU
42
!1
Tizen v2.3 Bootup
Embedded Software Lab. @ SKKU
42
!2
• Bootloader(U-boot) – Bootloader 概述 – U-boot
• Systemd – Systemd 概述 – Platform Bootup – Parsing Unit File
内容
Embedded Software Lab. @ SKKU
42
!3
Bootloader(U-boot)
Embedded Software Lab. @ SKKU
43
!4
• 引导加载程序 – 将机器id和启动参数传递给内核
Tizen bootup 概述
ROM codePower on Booting device
Bootloader
Kernel
Platform
Embedded Software Lab. @ SKKU
43
!5
• 引导加载程序是什么? – 引导加载程序是当系统初始化时的第⼀一个执⾏行程序(在主程序前,例如内核)
– 引导加载程序是⼀一个计算机程序,在⾃自检完成后加载主程序(即操作系统内核)
• 为什么需要引导加载程序? – 给出了⼀一个开发环境 – 节省了flash读写的成本 – 给加载任何操作系统提供灵活性
什么是引导加载程序bootloader
Embedded Software Lab. @ SKKU
43
!6
• 引导加载程序的不同类型是什么? – Boot-ROM ( or Pre-Boot Loader)
• ⼩小代码加载第⼀一阶段引导加载程序
– First Stage Boot Loader • ⼩小段代码初始化 NAND/MMC & DRAM控制器。
– Second Stage Boot Loader • 第⼆二阶段的引导加载程序的主要功能是内核加载到RAM或直接跳跃到内核的开始。
引导加载程序的类型
Pre-Bootloader First-StageBootloader
Second-StageBootloader OS Kernel
Embedded Software Lab. @ SKKU
43
!7
Exynos4412
U-boot 加载过程
Internal ROM
Internal SRAM
Cortex-A9DRAM 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
43
!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 加载过程
Embedded Software Lab. @ SKKU
43
!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 ⺫⽬目录结构
/u-boot
board
common
doc
drivers
include
lib
net
examples
fs
rtc
tools
post
arch
disk
api
/u-boot
Embedded Software Lab. @ SKKU
43
!10
1. 禁⽤用所有中断 2. 从ROM将所有初始化数据复制到RAM 3. 清空未初始化的数据区域 4. 分配和初始化堆栈空间 5. 初始化处理器的堆栈指针 6. 创建并初始化堆 7. 执⾏行所有全局数据的初始化 8. 启⽤用中断 9. 调⽤用主循环
U-boot 编码顺序
Embedded Software Lab. @ SKKU
43
!11
U-boot 编码顺序
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 to Final 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.S reset()
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.S
lowlevel_init()
cpu/armv7/start.S relocate_code()
Jump into main loop
Embedded Software Lab. @ SKKU
43
!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 编码顺序
Embedded Software Lab. @ SKKU
43
!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 编码顺序
Embedded Software Lab. @ SKKU
43
!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 编码顺序
Embedded Software Lab. @ SKKU
43
!15
U-boot 编码顺序
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
43
!16
通过U-boot加载
SDRAM
RootFile-System
Kernel
Booting device
Kernel Image
Bootloaderuboot
Root File System
Reset
Bootloaderuboot
CPU
Optional compressed
Embedded Software Lab. @ SKKU
43
!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
通过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
43
!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
43
!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]
start_kernel
Embedded Software Lab. @ SKKU
43
!20
systemd
Embedded Software Lab. @ SKKU
43
!21
• Sysvinit – userspace launch (PID 1) – ⼀一次只有⼀一个进程运⾏行 – 直接启动系统,然后sleep直到下⼀一次重新启动
• Systemd – Default init in Fedora 15 and later Leonard Poettering (2009) – 改善软件框架来表达依赖性 – 允许在系统启动时同时或并⾏行处理更多的过程 – 减少计算开销。
什么是systemd?
Embedded Software Lab. @ SKKU
43
!22
• 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
什么是systemd?
Embedded Software Lab. @ SKKU
43
!23
systemd 体系结构
Embedded Software Lab. @ SKKU
43
!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 体系结构
Embedded Software Lab. @ SKKU
43
!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
systemd 体系结构
Embedded Software Lab. @ SKKU
43
!26
• 早期启动脚本 – Most of file system are mounted and systemd related daemons are launched
平台启动– sysinit.target
basic.target
sysinit.target
multi-user.target
graphical.target
bootmode.target
Kernel
local-fs.target
swap.target
socket.target
-.mount 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
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 dbus.socket
systemd-initctl.socket systemd-journald.socket systemd-shutdownd.socket telnetd.socket udev-control.socket udev-kernel.socket
Embedded Software Lab. @ SKKU
43
!27
• 基础启动 – All necessary initialization for general purpose daemons are completed
平台启动 – basic.target
basic.target
sysinit.target
multi-user.target
graphical.target
bootmode.target
Kernel
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
Embedded Software Lab. @ SKKU
43
!28
• 选择启动模式 – If kernel boot parameter has ‘charger_detect_boot’, the platform boots up as charging mode
平台启动 – bootmote.target
basic.target
sysinit.target
multi-user.target
graphical.target
bootmode.target
Kernel
bootmode-charging.service bootmode-graphical.service
Embedded Software Lab. @ SKKU
43
!29
• 设置⼀一个⽆无图形⽀支持的多⽤用户系统 – Launching platform infrastructure daemons (such as dbus, power manager, gps manager, telephony daemon,
WRT security daemon, media server, systemd-related daemons)
平台启动 – multi-user.target
basic.target
sysinit.target
multi-user.target
graphical.target
bootmode.target
Kernel
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
Embedded Software Lab. @ SKKU
43
!30
• 设置⼀一个图形环境 – System user session for app privilege daemons such as Enlightenment (window manager) – Special target for middleware & mobile service
平台启动 – graphical.target
basic.target
sysinit.target
multi-user.target
graphical.target
bootmode.target
Kernel
core-efl.target
tizen-middleware.target
boot-animation.service cbhm.service e17.service indicator.service osp-app-service.service quickpanel.service scim.service starter.path xmodmap.service xrdb.service
ac.service [email protected] [email protected] [email protected]
calendar.service contacts-service.service download-provider.service email.service msg-service.service pushd.service sound-server.service
tizen-mobile-session.targetwrt-preinstall-widgets.service
xorg.targetxorg.service
Embedded Software Lab. @ SKKU
43
!31
Systemd 分析
Embedded Software Lab. @ SKKU
43
!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
平台启动
Embedded Software Lab. @ SKKU
43
!33
• https://wiki.tizen.org/wiki/Porting_Guide
平台启动
entry point
.target vs .service• .target; service grouping• .service; process run
Embedded Software Lab. @ SKKU
43
!34
• /usr/lib/systemd/system
• cat sysinit.target
解析单元⽂文件 – ⽰示例 (1/8)
target to parse
Embedded Software Lab. @ SKKU
43
!35
• Website – http://www.freedesktop.org/wiki/software/systemd/
• systemd download – http://www.freedesktop.org/software/systemd/
解析单元⽂文件 – ⽰示例 (2/8)
manpage
Embedded Software Lab. @ SKKU
43
!36
解析单元⽂文件 – ⽰示例 (3/8)
Can search all function and unit, configuration of systemd
enter target index
Embedded Software Lab. @ SKKU
43
!37
解析单元⽂文件 – ⽰示例 (4/8)
target unit file
Embedded Software Lab. @ SKKU
43
!38
解析单元⽂文件 – ⽰示例 (5/8)
Description on unit file option
Embedded Software Lab. @ SKKU
43
!39
解析单元⽂文件 – ⽰示例 (6/8)
Embedded Software Lab. @ SKKU
43
!40
解析单元⽂文件 – ⽰示例 (7/8)
Embedded Software Lab. @ SKKU
43
!41
解析单元⽂文件 – ⽰示例 (8/8)
• 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
Embedded Software Lab. @ SKKU
43
!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
不同的会话
Embedded Software Lab. @ SKKU
43
!43
• systemd official Site http://www.freedesktop.org/wiki/Software/systemd/
• systemd FAQ (written by developer) – http://0pointer.de/blog/projects/the-biggest-myths
References