Summary of tftp and nand flash startup Linux configuration under uboot and use of nand command (example)

1. Introduction

This article mainly uses examples to describe the two methods of tftp and nand flash to start the Linux system, and at the same time explains the example operation of nand's read and write commands.

Two, tfpt method

//网络配置
setenv ethaddr e2:a9:8d:e5:33:33
setenv ipaddr 192.168.22.248
setenv netmask 255.255.255.0
setenv serverip 192.168.21.199
//传入内核和设备树
tftp 0x8801000000 Image.gz
tftp 0x8800070000 tegra194-p2972-0000.dtb
//设置启动参数
setenv bootargs earlycon console=ttyS0  root=UUID=a080add7-cd8e-4950-a58c-e1d388e88c88  rw  init=/init
//解压内核到指定内存地址
unzip 0x8801000000 0x8800080000
//启动内核
booti 0x8800080000 - 0x8800070000

Reference link for building the tftp server:
Detailed summary of common problems in Ubuntu system settings - point 12

Three, nand flash method

1. First, transfer Image.gz and dtb to the memory cache through ftfp

setenv ethaddr e2:a9:8d:e5:33:33
setenv ipaddr 192.168.22.248
setenv netmask 255.255.255.0
setenv serverip 192.168.21.199
tftp 0x8801000000 Image.gz
tftp 0x8800070000 tegra194-p2972-0000.dtb

2. Write to nand flash, if write error, you can use the following nand erase command to erase the corresponding nand interval

nand write 0x8801000000 kernel 0x3200000
nand write 0x8800070000 dts 0x1200000 
//注意:这里的读写nand中nand的起始地址直接用kernel和dts代替,因为在nand分区中已经指定,后面章节会详细讲解

3. Manually read nand

nand read 0x8801000000 kernel 0x3200000
nand read 0x8800070000 dts 0x1200000 
setenv bootargs earlycon console=ttyS0  root=UUID=a080add7-cd8e-4950-a58c-e1d388e88c88  rw  init=/init
unzip 0x8801000000 0x8800080000
booti 0x8800080000 - 0x8800070000 

4. Automatically execute the uboot command to start the Linux system.
It needs to be set in the file corresponding to the u-boot/include/configs/xxx_verify.h development board in the uboot source code:

#define CONFIG_BOOTCOMMAND             \
       "nand read 0x8808000000 kernel 0x3200000 ; " \
        "nand read 0x8800070000 dts 0x10000 ; " \
        "unzip 0x8808000000 0x8800080000 ;booti 0x8800080000 - 0x8800070000 ;"

At the same time, bootargs can be modified under the dts corresponding to the kernel:

arch/arm64/boot/dts/xxxx.dts
bootargs = "console=ttyNORU0  root=UUID=a080add7-cd8e-4950-a58c-e1d388e88c88  rw  init=/init";

3. Detailed explanation of nand command

1. nand erase command

The nand erase command is used to erase NAND Flash. The characteristics of NAND Flash determine that the area to be written must be erased before writing data to NAND Flash. The "nand erase" command has three forms:

nand erase[.spread] [clean] off size //从指定地址开始(off)开始,擦除指定大小(size)的区域。
nand erase.part [clean] partition  //擦除指定的分区
nand erase.chip [clean] //全篇擦除

The following is an example of writing the content of memory 0x30008000 and length 0x20000 to 0x100000 in Nand Flash.

CRANE2410 # nand erase 0x100000 20000
NAND erase: device 0 offset 1048576, size 131072 ... OK
CRANE2410 # nand write 0x30008000 0x100000 0x20000
NAND write: device 0 offset 1048576, size 131072 ... 131072 bytes written: OK

2. nand write command

This command is used to write the specified data to the specified address of NAND. Generally, it is configured with the "nand erase" command to update files such as uboot, linux kernel or device tree in NAND. The command format is as follows:

nand write addr off size 

But we can use "nand write" command in uboot to program kernel and dtb. Compile the kernel and dtb files of the NAND version first, and partition the NAND before programming, that is, plan the storage area of ​​uboot, linux kernel, device tree and root file system. The NAND partition of the I.MX6U-ALPHA development board is as follows:

0x000000000000-0x000004000000 : "boot"
0x000004000000-0x000006000000 : "kernel"
0x000006000000-0x000007000000 : "dtb"
0x000007000000-0x000020000000 : "rootfs"

There are four partitions in total, the first partition stores uboot, the address range is 0x0-0x4000000 (total 64MB); the second partition stores kernel (that is, linux kernel), the address range is 0x4000000-0x6000000 (total 32MB); The first partition stores dtb (device tree), and the address range is 0x6000000-0x7000000 (16MB in total); all the remaining storage space is used as the last partition to store rootfs (root file system).

It can be seen that the kernel is stored from the address 0x4000000, put the zImage file corresponding to the NAND version kernel into the tftpboot directory in Ubuntu, and then use the tftp command to download it to the address 0X87800000 of the development board, and finally use "nand write" To burn it into NAND, the command is as follows:

tftp 0x87800000 zImage //下载zImage到DRAM中
nand erase 0x4000000 0xA00000 //从地址 0x4000000 开始擦除 10MB 的空间
nand write 0x87800000 0x4000000 0xA00000  //将接收到的zImage写到 NAND 中
0x87800000:内存中地址
0x4000000:Flash内地址
0xA00000:写入长度

3. nand read command

This command is used to read data of a specified size from a specified address in NAND to DRAM, and the command format is as follows:

nand read addr off size

addr is the destination address, off is the source address of the data in the NAND to be read, and size is the size of the data to be read. For example, if we read the device tree (dtb) file to the address 0x83000000, the command is as follows:

nand read 0x83000000 0x6000000 0x19000

4. Other related links

The root file system scheme manually made by starting the hard disk in uboot mode

Guess you like

Origin blog.csdn.net/Luckiers/article/details/125822124
Recommended