From: http://blog.csdn.net/allen6268198/article/details/12905425A10/A20 bootloader loading Process Analysis
Note: as the A10 and A20 in the loading bootloader process is basically consistent, the following only A20 narrative, but also applicable to A10. In addition, in the case of no need to distinguish between Cubieboard1 and CUBIEBOARD2, collectively referred to as Cubieboard, and now generally referred to the SD card is the micro SD cards, that is, TF card, for the difference from the general traditional SD card, this article generally uses the TF card description, But the same as the usual said SD card.
The boot process for A20 can be divided into 5 steps: Boot Rom,spl,uboot,kernel,rootfilesystem. This article focuses on the mirroring loading and booting process, and analyzes the boot Rom→spl→uboot→kernel startup process.
When the system is power up, the ARM processor starts executing instructions from address 0x000000 at Reset, mapping the on-board ROM or flash to this address. A20 the boot device selector is cured in a 32KB rom inside the CPU, the default boot sequence is SD card0,nand flash,sd card2,spi NOR FLASH. In addition, an external boot selection pin allows it to jump to USB boot mode. Typically, start the Select Pin state to connect the 50K internal pull-up resistor. After power-on, the boot code stored in the boot ROM is executed and the boot selection PIN status is automatically detected. The USB boot mode is selected only when the PIN status is low.
After selecting the boot device, the bootloader program is loaded and executed, and the CPU copies or maps the bootloader program to memory and executes the first instruction of bootloader. By reading the official Uboot-burning method, it was found that A20 was loaded with Uboot SPL prior to booting the system through Uboot. What is SPL? By consulting the official website of Uboot, SPL is a mini-version of the Uboot, all spelled for second program Loader. For the internal sram<64k of the SOC, use it to load the full Uboot program to the SDRAM and boot the system with the full uboot load kernel. Where SRAM generally refers to the internal CPU L1/L2 or external L2 cache, which is the boot ROM, and SDRAM generally refers to memory.
The SPL program flow is as follows:
- Initializing ARM processors
- Initializing the serial console
- Configure the clock and the most basic crossover
- Initialize SDRAM
- Configuring the PIN multiplexing feature
- Initiate device initialization (that is, the boot device selected above)
- Loading the full Uboot program and handing over control
To start the device selector flowchart:
Figure out the above concept, you can know that Cubieboard factory has been burned to write the Nandflash program, that is, at the start of the use of Nandflash. Now, based on the above steps of the A20, we try to start the system with the SD Card0 (i.e., the TF card in the Cubieboard card slot).
Environment preparation
The host environment used in this article is Kubuntu 12.10, but in general, the commands involved below should apply to the Debian-based (X) Ubuntu series.
In order not to cause confusion, we make the following agreement:
- Working directory is $WORK _dir
- Commands are executed as root user
The author's settings are as follows:
work_dir=/Home/itviewer/src
Download the necessary tool software
git binfmt-support libusb-1.0-0-dev pkg-configapt-get install GCC-ARM-LINUX-GNUEABIHF
Download source code
Download Spl,u-boot,linux kernel source from GitHub. Note that Linux-sunxi is over 3.8G and takes the longest time. If you've ever downloaded the code, remember to use git pull to update it later, as the code warehouse changes every day.
$WORK _dirgit clone git://github.com/linux-sunxi/u-boot-sunxi.gitgit clone git://github.com /cubieboard2/linux-sunxigit clone git://github.com/linux-sunxi/sunxi-tools.git git clone git://github.com/linux-sunxi/sunxi-boards.git
Compiling uboot
$WORK _dircross_compile=arm-linux-gnueabihf-
Get U-boot-sunxi-with-spl.bin (also generate a few other files, here we only use this file, note that the above Cubieboard2, the latest code needs to capitalize the first letter)
Compiling kernel
$WORK _dir-j4 uimage modules
Get the kernel file Arch/arm/boot/uimage (there are other kernel modules that are not used here for the time being)
Generate BOOT.SCR and Script.bin
Before Uboot and kernel are written to the TF card, we need to compile and generate two boot parameter files: BOOT.SCR and Script.bin.
Generate BOOT.SCR
What is BOOT.SCR?
According to the data description (Https://github.com/linux-sunxi/u-boot-sunxi/wiki#bootscr-support), U-boot will be found in the first partition (FAT/EXTX format) when it is started/ BOOT.SCR or/BOOT/BOOT.SCR files, BOOT.SCR can contain uboot commands for loading script.bin,kernel,initrd (optional) and setting kernel boot parameters.
How is BOOT.SCR generated?
Create a new Boot.cmd file in the $work_dir directory and add the following:
setenv Bootargs Console=ttys0,115200 noinitrd disp. Screen0_output_mode=edid: 1280x1024p60 Init=/init root=/dev/mmcblk0p2 rootfstype=ext4 rootwait Panic=Ten ${extra 0x43000000 boot/script0x48000000 boot0x48000000
Detailed Explanation:
1. The first line above sets the Bootargs start parameter of Uboot, the format is parameter = value, the different parameters are separated by spaces, where
- console=ttys0,115200 meaning to use a specific serial port ttyS0, the baud rate is 115200
- NOINITRD meaning not to use RAMDisk (memory disk)
- Init=/init meaning the first script that runs in the system after the kernel is set up
- ROOT=/DEV/MMCBLK0P2 meaning that the location of the specified Rootfs is the second partition of a TF card
- ROOTFSTYPE=EXT4 meaning for root file system type
- Rootwait means to wait for the device to/DEV/MMCBLK0P2 ready before attempting to mount the Rootfs
- PANIC=10 Pass kernel parameter, wait 10 seconds after panic (kernel critical error) to restart
- Screen0_output_mode Setting the appropriate screen display resolution
More parameters can be found by viewing the Linux kernel source directory under the Documentation/kernel-parameters.txt file
2. The second and third behaviors load script.bin and kernel uimage to the specified memory address. Fatload is an instruction that loads Linux kernel into memory in U-boot.
Basic usage: fatload <interface> <dev[:p art]> <addr> <filename> <bytes>
- Interface: The interface used, such as: MMC, USB
- dev [:p art]: Files stored devices such as: IDE 0:1
- Addr: The start address of the mount to memory.
- FileName: The file name of the mount.
- The number of bytes bytes:copy.
3. Line fourth BOOTM is used to load the kernel image to the specified address
After saving the file, execute the following command to generate the BOOT.SCR:
-D boot. cmd boot. SCR
Generate Script.bin
What is Script.bin?
Script.bin is a binary configuration file for a specific target board that is driven or livesuit by a fully-focused SOC kernel, and contains information on how to set up various peripherals, ports, and I/O pins based on the a10/a20 target version.
The corresponding readable text file format is Fex, which can be converted between binary and text files using Sunxi-tools. For more information on the Fex configuration, refer to Http://linux-sunxi.org/Fex_Guide
How is Script.bin generated?
First you need to compile Sunxi-tools:
$WORK _dir/sunxi-tools make
Get Fex2bin, Bin2fex and other files, wherein Fex2bin can *.fex file generation *.bin file. Conversely Bin2fex can generate a readable *.fex file for the resulting *.bin file.
Then compile the build Script.bin:
$WORK _dir/sunxi-boards/sys_config/a20$WORK _dir/sunxi-tools/fex2bin cubieboard2.fex Script.bin
Burn write Uboot and kernel to TF card
Above wordy so much, in fact is in order to uboot and kernel burn write to TF card and can start, OK, let us start from the partition first:
When the A20 chip is on, it will read the 1M content in front of the SD card to get bootloader, so we need to write u-boot to the first 1M interval of the SD card.
The details of the SD card layout are as follows:
starting |
size |
Use |
0 |
8KB |
Storing content such as partition tables |
8 |
24KB |
SPL Loader |
32 |
512KB |
U-boot |
544 |
128KB |
Environment |
672 |
352KB |
Keep |
1024 |
- |
For remaining partitions |
Next, we started partitioning with Fdisk (because Sfdisk is not compatible with some TF, so don't use it unless you really know how to use Sfdisk):
To plug the TF card into the computer and confirm the device name, we use SDX instead, you need to modify it according to your own situation, such as SDB:
card=/Dev/sdx if=/devof=count=# re-read ${card}#使用fdisk进行分区
The specific partitioning steps are as follows:
Create the first partition
[Email protected]:~/src/u-boot-sunxi# fdisk ${card}device contains neither a valid DOS partition table, nor Sun, SGI or OS F disklabelbuilding A new DOS disklabel with disk identifier 0x911332e8. Changes'll remain in memory only, until the decide to write them. After that, of course, the previous content won ' t is recoverable. Warning:invalid flag 0x0000 of partition Table 4 would be a corrected by W (rite) Command (M-help): N #键入n然后回车Partitio N type: P Primary (0 primary, 0 extended, 4 free) e extendedselect (default p): #直接回车Using default RE Sponse ppartition Number (1-4, default 1): #直接回车Using Default value 1First sector (2048-15278079, default 2048): # Direct carriage return using default value 2048Last sector, +sectors or +size{k,m,g} (2048-15278079, default 15278079): +64m #键入 +64m after carriage return, That is, the partition size is 64M
Create a second partition
Command (M for help): N #键入n然后回车Partition type: P Primary (1 primary, 0 extended, 3 free) e extendeds Elect (default P): #直接回车Using Default Response ppartition number (1-4, default 2): #直接回车 Using Default value 2Firs T sector (133120-15278079, default 133120): #直接回车Using Default value 133120Last sector, +sectors or +size{k,m,g} (1331 20-15278079, default 15278079): #直接回车, that is, the second partition uses all of the remaining space using the default value 15278079
Next specify the partition type:
Command (M for help): T #键入t然后回车Partition number (1-4): 1 #键入1然后回车, which specifies the first partition hex code (type L to list codes): C #键入c然后回车, which specifies that the first partition is vfatchanged system type of partition 1 to C (W95 FAT32 (LBA)) Command (M-help): W #键入w然后回车, save partition Table T He partition table has been altered! Calling IOCTL () to re-read partition table. Syncing disks.
To format a partition:
${card}${card}2 #需要稍等片刻
Then write bootloader:
$WORK _dir/u-boot-sunxiof=bs=seek=8
Finally install the kernel uimage, set the startup parameters:
Mount${card}1 /mntmkdir / Mnt/bootCP $WORK _dir/linux-sunxi/arch/arm/boot/uimage /mnt< Span class= "sy0" >/bootCP $WORK _dir/sunxi-boards /sys_config/a20/script.bin /mnt /bootCP $WORK _dir/BOOT.SCR /mnt/sync && Umount /mnt
At this point, the boot to the Linux kernel has been completed, then we can watch the Linux kernel boot process, kernel debugging.
Print Serial Debugging information
By looking at the output of the serial port, we can determine the problem, and then find a way to solve the problem.
There are a variety of serial debugging tools available under Linux and Windows, with only two reference articles:
- Http://linux-sunxi.org/Cubieboard/TTL
- http://cn.cubiebook.org/index.php?title=Cubieboard/Serial Debugging
Here is attached the author's serial output information: Http://mer.jolladev.net/data/media/cutecom.txt
End of message because the root file system could not be mounted, start init and wait 10 seconds to restart.
Summarize
This article refers to a number of Web content, in the following list the main article address, in this together thanks.
The reason to write this content, is because from my beginning cubieboard2, through the bitter search for information, in various pain and wrong attempts to constantly embark on the "right path", know for a no Embedded development foundation or development experience of ordinary players, want to make all kinds of links to clear is a difficult thing, Therefore, through a large number of references, reference network content and their own groping, summed up the article, in anticipation of the new players can help; in the case of embedded Linux, the entire power-up-start bootloader--boot kernel-loading ROOTFS process will be very vague for beginners, And I don't know how to do it. This article describes as much as possible the whole process of using cubieboard from power-up to booting the Linux kernel, laying the groundwork for further learning how to build a running Linux system. Later on, we will continue to describe how to mount the file system, boot to the shell and even GUI, and build a complete and usable Linux system.
Reference
- Http://linux-sunxi.org/Bootable_SD_card
- Http://linux-sunxi.org/Boot
- Https://github.com/linux-sunxi/u-boot-sunxi/wiki
- Http://cn.cubieboard.org/forum.php?mod=viewthread&tid=1108&extra=page%3D1
- http://blog.csdn.net/yichunjie/article/details/8661176
- http://blog.csdn.net/abc47bca/article/details/6306005
Turn: A10/A20 bootloader loading Process Analysis