Ch2 Bootloader
Ch2 Bootloader
Ch2 Bootloader
Undefined instruction
the processor cannot recognize the currently execution instruction
Prefetch Abort
Fetch an instruction from an illegal address
Data Abort
A data transfer instr. try to load or store data at an illegal address
IRQ: The processor IRQ pin is asserted and the I bit in CPSR is clear FIQ: The processor FIQ pin is asserted and the F bit in CPSR is clear
6
(1)
Memory
7
Branch instruction (x2) Status Register Transfer instruction (x2) Exception Generating instructions (x2)
8
10
11
Bootloader Overview
Bootstrapping
When system is powered on, the first piece of code (called bootstrapping) initializes basic hardware and then bring up OS kernel. It can be included in a bootloader, or in OS directly.
12
Bootloader Overview
Bootloader Selection
The Processor architectures and platforms that it supports The OS that it supports Debugging abilities, Stability and Portability Functionalities: simple bootup, or with monitoring capability and lots of drivers support. The medium they are installed in usually ROM, EEPROM or Flash The storage device from which the kernel image is downloaded host PC, local Flash, disk, CF, etc. The device and protocol by which the kernel image is transmitted Serial port, USB, ethernet, IDE, etc. The 'host-side' software used to transmit the kernel image if it is coming from an external device/machine. 'sleep' reset support Not to do a normal reboot if this was a sleep wakeup.
13
Part- I: Startup
Make U-Boot
Check the target boards supported by U-Boot
vi /u-boot-1.1.2/makefile :
smdk2410_config : unconfig @./mkconfig $(@:_config=) arm arm920t smdk2410 NULL s3c24x0
Make u-boot
[root@test u-boot-1.1.2]# make ELF format : Motorola S-Record -Map u-boot.map o u-boot arm-linux-objcopy --gap-fill=0xff O srec u-boot u-boot.srec arm-linux-objcopy --gap-fill=0xff O binary u-boot u-boot.bin
plain binary
15
Part- I:
UBoot Startup
_start: 1. setup exception vector table, and each handler 1. 2. 3. 4. set SVC mode turn off watchdog disable all IRQs set System Clock (data sheet 7-22)
reset:
cpu_init_crit:
memsetup:
1. flush I and D cache 2. flush TLB 3. disable MMU stuff and caches In /board/smdk2410/memsetup.S 1. enable and set memory 2. return to /cpu/arm920t/start.S 1. return to reset:
16
cpu_init_crit:
reset:
Part- I:
UBoot Startup
reset: 1. Setup C environment and run on RAM - copy U-Boot code/ initialized data to RAM
from: _start: 0x0, Flash base to: _TEXT_BASE, 0x33F80000, Entry on RAM size: _armboot_start ~ bss_start (0x33F80000) (0x33F9-8558)
relocate:
start_armboot()
main_loop()
In common/main.c
In lib_arm/board.c 1. Flash initialization 2. Init environment 3. Set IP addr 4. Set MAC addr 5. Devices initialize 6. Console initialize 7. Enable interrupts 8. Enable Ethernet
In C code
17
Part- I:
Linker Descriptor
U-boot-1.1.2 /board/smdk2410/u-boot.lds
U-boot-1.1.2/board/smdk2410/config.mk
TEXT_BASE = 0x33F8000 UBoot entry point address
18
Part- I:
U-boot-1.1.2 /cpu/arm920t/start.S
19
Part- I:
U-boot-1.1.2 /cpu/arm920t/start.S
20
Part- I:
U-boot-1.1.2 /cpu/arm920t/start.S
21
Part- I:
U-boot-1.1.2 /cpu/arm920t/start.S
22
Part- I:
U-boot-1.1.2 /cpu/arm920t/start.S
/lib_arm/board.c
23
Part- I:
U-boot-1.1.2 /cpu/arm920t/start.S
/board/smdk2410/memsetup.S
24
Part- I:
U-boot-1.1.2 /board/smdk2410/memsetup.S
r0 as src (SMRDARA addr on Flash) r1 as dest (BWSCON reg addr) r2 as copy length (13 words)
.. ..
13 words
......
25
UBoot Commands
help / ?
- boot default, i.e., run bootcmd - boot from an ELF image in memory - boot application image from memory - boot image via network using BootP/TFTP - boot image via network using TFTP protocol - start application at address addr - memory copy - memory display - memory modify - simple RAM test
Boot
cp md mm mtest
Memory
- erase FLASH memory - print FLASH memory information - enable or disable FLASH write protection - list all images found in flash - set environment variables - save environment variables (on flash) - print environment variables
Flash
Environment variables
26
Part- II:
EX.2 # tftp
Part- II:
U-boot-1.1.2 /common/main.c
Y
run_command(s) len = readline() run_command() cmdtp = find_cmd() (cmdtp->cmd) ()
If booting is NOT aborted by the user during the initial bootdelay seconds, it will run the commands pre-set in bootcmd automatically. Otherwise it will run the commands input by user in the run-time. In common/command.c Look up commands in the command table call function to do the command
28
Downloading
downloads the Kernel and RFS from an external device, often under the control of that device. This is the mode that is used to first install the Kernel and RFS, and for subsequent updates.
29
Part- III:
2. Initialize devices
Part- III:
CPU mode
All forms of interrupts must be disabled (IRQs and FIQs) CPU must be in SVC mode
Cache, MMU
MMU must be off D-cache must be off and no any stale data (I-Cache can be on/off)
Device
DMA to/from devices should be quiesced.
31
Part- III:
The loader must pass at a minimum the size and location of the system memory (specified in ATAG_MEM).
A minimum Tagged list: ATAG_CORE, ATAG_MEM, ATAG_NONE.
Part- III:
start
Tagged list
:
ATAG_NONE
end
Note:
For some embedded systems, the tagged list is hard-coded in the Kernel. In such case, the bootloader does not need to setup it.
33
Part- III:
Reference http://www.arm.linux.org.uk/developer/booting.php
34
Part- III:
Usage:
mkimage A arch O os T type C compress a loadaddr e entrypoint \ n name d data_file[:data_file] outputimage
Example 1: Kernel
[root@test tftpboot]# gzip -9 < Image > Image.gz [root@test tftpboot]# mkimage n Kernel 2.4.18 A arm O linux \
> T kernel C gzip a 30008000 e 30008000 \ > -d Image.gz vmlinux-2.4.18.img
Example 2: Kernel+RFS
[root@test tftpboot]# mkimage n Kernel+initrd 2.4.18 A arm O linux \
> T multi C gzip a 30008000 e 30008000 \ > -d Image.gz:initrd.gz multi-2.4.18.img
35
Part- III:
U-boot-1.1.2 /include/image.h
Image header
36
Part- III:
U-boot-1.1.2 /common/cmd_bootm.c
Uncompress image using gzip or bzip2 based on ih_comp For IH_TYPE_STANDALONE, run from its hdr->ih_ep; Otherwise, handle it later For IH_OS_LINUX, run do_bootm_linux(), which is in /lib_arm/ armlinux.c
37
Part- III:
U-boot-1.1.2 /lib_arm/armlinux.c
see P.xx for whats bootargs If initrd exists, load it as well disable interrupts turn off I/D-cache flush I/D-cache ARM uses r0~r3 for function parameters. So, this will make r0 = 0 r1 = arch_number r2 = boot_params before startup Kernel
38
LinuxBIOS (http://www.acl.lanl.gov/linuxbios/index.html)
replacing the normal BIOS with fast boot from a cold start.
ROLO (ftp://www.elinos.com/pub/elinos/rolo/)
By SYSGO. Capable of booting directly from ROM without BIOS.
SYSLINUX (http://syslinux.zytor.com/)
It is a lightweight bootloaders for floppy media.
NILO (http://nilo.sourceforge.net/)
it is the Network Interface Loader. NILO will boot Linux, FreeBSD, Windows 95/98/NT4 and support the Intel PXE standard.
40
IPAQ (http://www.handhelds.org/Compaq/iPAQH3600/OSloader.html)
A bootloader, which can boot Linux from Windows CE.
Yaboot (http://penguinppc.org/projects/yaboot/)
It works on "New" class PowerMacs (iMac and later) only.
References
ARM7TDMI Technical Reference Manual http://www.eecs.umich.edu/~tnm/power/ARM7TDMIvE.pdf Samsung S3C2410X 32-Bit RISC Microprocessor users manual http://www.samsung.com/Products/Semiconductor/SystemLSI/ MobileSolutions/MobileASSP/MobileComputing/S3C2410X/um_ s3c2410s_rev12_030428.pdf U-Boot source code http://sourceforge.net/projects/u-boot Related documents: PPCBoot: http://ppcboot.sourceforge.net ARMBoot: http://armboot.sourceforge.net ARM Linux Kernel Boot Requirement http://www.arm.linux.org.uk/developer/booting.php
42