Http://www.linuxidc.com/Linux/2012-09/70510.htm Source: Linux Community Zhao Chunjiang
The main function of uboot is to boot the kernel. This article describes how to implement this feature and make up the simplest system, not only porting uboot, but also porting the Linux kernel and creating a root filesystem.
First we partition the Nandflash and plan the location of each file in Nandflash. The following is the Nandflash partition:
No. 0 Partition: 0x000000000000-0x000000080000 for Uboot District
1th Partition: 0x000000080000-0x000000100000 as the parameter area
2nd partition: 0x000000200000-0x000000600000 for Linux kernel zone
3rd partition: 0x000000800000-0x000001000000 as root file system zone
After planning the partition, we can sequentially complete the uboot porting, the Linux kernel porting, and creating a root filesystem. We chose Cramfs as the root file system.
First, Uboot transplant
1. Modify the machine code to ensure that the uboot is consistent with the machine code of the Linux kernel in order to boot the kernel.
Modify the contents of line 116th in the board/samsung/zhaocj2440/zhaocj2440.c file to change the SMDK2410 to SMDK2440, i.e.:
Gd->bd->bi_arch_number = mach_type_smdk2440;
Because our uboot transplant is the template of the SMDK2440 Development Board with Uboot, so we still follow the SMDK2440 machine code to transplant, mach_type_smdk2440 the specific value in arch/arm/include/asm/ The 1013th line of the Mach-types.h file is already defined:
#define MACH_TYPE_SMDK2440 1008
2. Add the Bootcmd and Bootargs parameters. Where Bootcmd is to boot the kernel, and Bootargs is to pass the necessary parameters to the root file system when loading the root file system.
There are two ways to set these two parameters:
The first method is to set the two parameters of Bootcmd and Bootargs directly at the prompt of the uboot:
ZHAOCJ2440 # setenv Bootcmd ' NAND read 31000000 200000 400000; Bootm 31000000 '
ZHAOCJ2440 # setenv Bootargs ' root=/dev/mtdblock3 ro noinitrd init=/linuxrc console=ttysac, 115200 ROOTFSTYPE=CRAMF S mem=64m '
ZHAOCJ2440 # Saveenv
The meaning of bootcmd here is to read the kernel from the Nandflash and then start with the command Bootm. The implication of Bootargs is that the root filesystem is stored in the 3rd partition in the Nandflash, which is in the form of a Cramfs. Finally, the saveenv command is applied to save the two variables. At this point, if you typed the printenv command at the prompt, you will see that there are two more uboot environment parameters, such as:
Bootargs=root=/dev/mtdblock3 ro noinitrd init=/linuxrc console=ttysac,115200 Rootfstype=cramfs Mem=64M
Bootcmd=nand read 31000000 200000 400000; Bootm 31000000
The second approach is to define the two macro definitions of Config_bootargs and Config_bootcommand within Include/configs/zhaocj2440.h:
#define Config_bootargs "Root=/dev/mtdblock3 ro noinitrd init=/linuxrc console=ttysac, 115200 Rootfstype=cramfs Me M=64m "
#define CONFIG_BOOTCOMMAND "NAND read 31000000 200000 400000; Bootm 31000000 "
3. Burn the transplanted uboot into the nandflash of 0x00000000 to 0x000000080000.
Second, the Linux kernel porting
Here we are implementing the simplest porting, which is the ability to start.
1. Download the Linux kernel at the following URL, linux-3.4.6.tar.bz2
www.kernel.org/pub/linux/kernel/v3.x/
Unzip to current directory:
TAR-XVJF linux-3.4.6.tar.bz2
2. Modify the makefile file in the home directory, and Lines 195th and 196th are rewritten as:
ARCH =arm.
Cross_compile? = arm-linux-
3. Add machine code to align Uboot with Linux machine code and change kernel clock
Add the following code on line No. 207 of the Arch/arm/tools/mach-types file:
smdk2440 mach_smdk2440 SMDK2440 1008
Within the arch/arm/mach-s3c24xx/mach-smdk2440.c file
The 16934400 in line 165th is changed to 12000000, i.e.
S3c24xx_init_clocks (12000000);
The s3c2440 in line 178th is changed to SMDK2440, i.e.
Machine_start (SMDK2440, "SMDK2440")
4. Modify the partition in the kernel so that it is consistent with our pre-defined partition
Within the Arch/arm/mach-s3c24xx/common-smdk.c file
The Smdk_default_nand_part structure in line 111th is modified to:
static struct Mtd_partition smdk_default_nand_part[] = {
[0]= {
. Name = "UBoot",
. Size = sz_512k,
. Offset = 0,
},
[1]= {
. Name = "Para",
. offset= sz_512k,
. Size = sz_512k,
},
[2]= {
. Name = "Kernel",
. offset= sz_2m,
. Size = sz_4m,
},
[3]= {
. Name = "Rootfs",
. offset = sz_8m,
. Size = sz_8m,
}
};
5. Change the ECC type of the kernel
Within the drivers/mtd/nand/s3c2410.c file
The Nand_ecc_soft in line No. 846 is changed to Nand_ecc_none, i.e.:
Chip->ecc.mode = Nand_ecc_none;
If you do not change this, you can start the Linux kernel, but you cannot load the root file system.
6. Compiling the kernel
Go back to the root directory of linux-3.4.6 and copy the configuration file:
CP arch/arm/configs/s3c2410_defconfig. config
Use Menuconfig to configure the kernel:
Make Menuconfig
Choose two things under Kernelfeatures,
Kernel Features--->
[*] Use the ARM EABI to compile the kernel
[*] Allow-old ABI binaries-to-run with this kernel (experimental)
If you do not select these two items, the kernel panic:attempted to kill init error occurs when the kernel is booted and the root filesystem is mounted.
Other content of Menuconfig can be changed without change, choose Default.
Finally execute the following two commands:
Make clean
Make Zimage
After waiting for a period of time, the Zimage file is generated in the arch/arm/boot/directory.
7. Make kernel image
In the previous step although we have generated the Zimage file, but it can not be uboot properly booted, we also need to add 64 bytes of data header to the Zimage file, which includes CPU architecture (A), operating system (O), image Type (T), compression type (C), Image name (n), mirror load address (a), mirror entry (e), source file (d). Only add these content uboot to boot the kernel correctly.
The Mkimage tool is the tool that Uboot uses to make the above content. After compiling the uboot, the mkimage is generated in the tools directory. To make it easier to apply the tool, we need to do the following to access the tools directory and execute the following commands as the root user:
CP Mkimage/usr/bin
chmod 777/usr/bin/mkimage
Enter the arch/arm/boot/directory under the linux-3.4.6 directory and execute the following command:
Mkimage-n ' Linux '-A arm-o linux-t kernel-c none-a 0x31000000-e 0x31000040-d zimage uimage.img
Uimage.img for the end we need to burn the files into the Nandflash. Here, we are loading the image into the memory 0x31000000 address.
8. Finally, we burn the uimage.img file to the 0x200000 to 0x600000 in Nandflash.
u-boot-2011.06 boot kernel and loading root file system based on s3c2440 Development Board