Embedded Linux Development - Introduction to common commands of uboot (Part I)

Posted by jamesloi on Mon, 28 Feb 2022 17:35:33 +0100

1. Preface

U-boot is an open source bootloader, which is used to guide operations and provide developers with testing and debugging tools. It is a simplified Linux system, which is mainly responsible for the initialization and boot of hardware. It has some tools as the boot program, often as the boot of embedded devices. When the real system starts running, u-boot hands over the management authority.

Reasons for choosing U-Boot:
① Open source;
② Support a variety of embedded operating system cores, such as Linux, NetBSD, VxWorks, QNX, RTEMS, ARTOS, LynxOS, android;
③ Support multiple processor series, such as PowerPC, ARM, x86 and MIPS;
④ High reliability and stability;
⑤ Highly flexible function settings, suitable for U-Boot debugging, different boot requirements of operating system, product release, etc;
⑥ Rich device driver source code, such as serial port, Ethernet, SDRAM, FLASH, LCD, NVRAM, EEPROM, RTC, keyboard, etc;
⑦ Rich development and debugging documents and strong network technical support;

U-BOOT working mode

The working modes of U-Boot include startup loading mode and download mode. Boot loading mode is the normal working mode of bootloader. When the embedded product is released, bootloader must work in this mode. Bootloader loads the embedded operating system from FLASH to SDRAM for operation, and the whole process is automatic. The download mode is that the bootloader downloads the kernel image or root file system image from the PC to the FLASH of the target board through some communication means. Users can use some command interfaces provided by bootloader to complete their desired operations.

At present, the development board for testing uboot command is friendly arm tin441, which uses Samsung's EXYNOS4412. This article focuses on the command function and usage of uboot command line. The uboot version used is 2010.12, which is officially provided by friendly arm.

2. Introduction to uboot command

2.1 help command – help

See which commands are currently supported by UBOOT.

TINY4412 # help
?       - alias for 'help'
base    - Print a set of address offsets
bdinfo  - Information structure of development board
boot    - boot default, i.e., run 'bootcmd'
bootd   - boot default, i.e., run 'bootcmd'
bootelf - Boot from an ELF image in memory
bootm   - Launching an application from memory
bootp   - through the use of BOOTP / TFTP Network boot image of protocol
bootvx  - Boot vxWorks from an ELF image
chpart  - Change active partition 
cmp     - memory compare
coninfo - print console devices and information
cp      - Memory Copy 
crc32   - Calculation of inspection and 
dcache  - Enable or disable data caching
dnw     - dnw     - USB The device is initialized and ready to accept Windows server(Specific)

echo    - echo args to console
editenv - Modify environment variables
emmc    - open/close eMMC Boot partition
env     - Environment processing command
exit    - Exit script
ext2format- ext2 ext2format-Disk format

ext2load- from Ext2 File system loading binaries
ext2ls  - List files in a directory(default/)
ext3format- ext3 ext3format-Disk format

false   - Do nothing,But it didn't succeed
fastboot- fastboot-use USB fastboot agreement

fatformat- FAT32 fatformat-Disk format

fatinfo - fatinfo-Print file system information
fatload - fatload-from dos File system for loading binary files

fatls   - A directory list file(default/)
fdisk   - fdisk for sd/mmc.

go      - In“ addr"application was launched
help    - Print command description/Use help
icache  - enable or disable instruction cache
iminfo  - print header information for application image
imxtract- extract a part of a multi-image
itest   - return true/false on integer compare
loadb   - load binary file over serial line (kermit mode)
loads   - load S-Record file over serial line
loady   - load binary file over serial line (ymodem mode)
loop    - infinite loop on address range
md      - memory display
mm      - memory modify (auto-incrementing address)
mmc     - MMC Subsystem
mmcinfo - mmcinfo <dev num>-- display MMC info
movi    - movi  - sd/mmc r/w sub system for SMDK board
mtdparts- define flash/nand partitions
mtest   - simple RAM read/write test
mw      - memory write (fill)
nfs     - boot image via network using NFS protocol
nm      - memory modify (constant address)
ping    - send ICMP ECHO_REQUEST to network host
printenv- print environment variables
reginfo - print register information
reset   - Perform RESET of the CPU
run     - run commands in an environment variable
saveenv - save environment variables to persistent storage
setenv  - set environment variables
showvar - print local hushshell variables
sleep   - delay execution for some time
source  - run script from memory
test    - minimal test like /bin/sh
tftpboot- boot image via network using TFTP protocol
true    - do nothing, successfully
usb     - USB sub-system
version - print monitor version

2.2 view the usage of specific commands – help

Format:
Help < instructions you want to check >
Or< The command you want to check >,
Even h < the instruction abbreviation you want to check >.

TINY4412 # help sleep
sleep - Delay execution for a period of time

Usage:
sleep N
    - Delayed execution N second(N yes_decimal_ ! ! !)

2.3 print environment variable – printenv

TINY4412 # printenv
baudrate=115200
bootargs=root=/dev/nfs nfsroot=192.168.18.3:/work/rootfs ip=192.168.18.123:192.168.18.3:192.168.18.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC0,115200
bootcmd=movi read kernel 0 40008000;movi read rootfs 0 41000000 400000;bootm 40008000 41000000
bootdelay=3
ethaddr=00:40:5c:26:0a:5b
gatewayip=192.168.0.1
ipaddr=192.168.0.20
netmask=255.255.255.0
serverip=192.168.0.10

Environment size: 416/16380 bytes

baudrate: current baud rate. Generally not modified.
bootcmd: start command.
bootdelay: the time to delay the execution of the boot CMD command.
ethaddr: MAC address of network card.
Gateway IP: gateway IP address.
ipaddr: the IP address of the development board.
netmask: subnet mask.
serverip: server IP (generally the IP of the PC, the IP of the host that provides various network services to the development board)
Bootargs: the startup parameters passed by u-boot to the operating system kernel. (very important)

Use example
Prints the specified environment variables

Format: printenv name of environment variable for printing

TINY4412 # printenv bootargs
bootargs=root=/dev/nfs nfsroot=192.168.18.3:/work/rootfs ip=192.168.18.123:192.168.18.3:192.168.18.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC0,115200

2.4 setting environment variables – setenv

View help:
TINY4412 # help setenv
setenv - set environment variables -->The function is to set environment variables

Usage:  //Command usage
setenv name value ...  //Use format
    - set environment variable 'name' to 'value ...'
    //Format environment variable name value
setenv name
    - delete environment variable 'name'
//Delete environment variable

Use example

Set the power on delay time:
TINY4412 # setenv bootdelay 10 / / set the power on delay time to 10 seconds
TINY4412 # saveenv / / save settings
Saving Environment to SMDK bootable device...
done

Example of setting baud rate:
TINY4412 # setenv baudrate 115200 / / set the baud rate to 115200
## Switch baudrate to 115200 bps and press ENTER ...  // After setting, you need to restart the development board and it will take effect automatically

Example of deleting an environment variable:
setenv baudrate   //Delete baudrate environment variable

Examples of reference environment variables:

TINY4412 # setenv timer 10 / / set any environment variable
TINY4412 # setenv bootdelay ${timer} / / reference environment variable
TINY4412 # Save / / save environment variables
Saving Environment to SMDK bootable device...
done
TINY4412 # print
baudrate=115200
bootargs=root=/dev/nfs nfsroot=192.168.18.3:/work/rootfs ip=192.168.18.123:192.168.18.3:192.168.18.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC0,115200
bootcmd=movi read kernel 0 40007fc0;bootm 40007fc0
bootdelay=10    //Set successfully
ethaddr=00:40:5c:26:0a:5b
gatewayip=192.168.18.1
ipaddr=192.168.18.123
netmask=255.255.255.0
serverip=192.168.18.124
timer=10   //Set new environment variables

Environment size: 389/16380 bytes
TINY4412 # 

2.5 setting the bootargs parameter

Bootargs is the top priority of environment variables. It can even be said that the whole environment variables are set around bootargs.

coherent_pool parameters:

set up DMA Size of
 Example: coherent_pool=2M

Local mount example

set bootargs root=/dev/mmcblk0p2 rootfstype=ext3 init=/linuxrc console=ttySAC0,115200

set bootargs root=/dev/mmcblk0p2 rw rootfstype=ext3 init=/linuxrc console=ttySAC0,115200

NFS network mount example:

set bootargs root=/dev/nfs nfsroot=192.168.18.3:/work/nfs_root ip=192.168.18.123:192.168.18.3:192.168.18.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC0,115200

The root parameter is used to specify where the root file system is mounted.

The nfsroot parameter needs to be set only when the NFS network file system is mounted, followed by the NFS address and mounting directory of the server

The IP parameter is to set the IP address of the network card of the development board. It must be set when NFS network is mounted.

init is a script that is run after the file system is mounted. It is used for system initialization.

2.6 view the configuration information of the development board – bdinfo

TINY4412 # bdinfo
arch_number = 0x00001200 ->The machine code of the development board is used to boot the kernel of the operating system
boot_params = 0x40000100 ->Memory location of startup parameter storage
DRAM bank = 0x00000000 -> DRAM Number, which means the 0 th DDR
-> start = 0x40000000    -->DRAM Start address of
-> size = 0x10000000     -->DRAM Size of ( 0x10000000 /1024 /1024 = 256M)
DRAM bank = 0x00000001 -> DRAM Number, which means the first one here DDR
-> start = 0x50000000    -->DRAM Start address of
-> size = 0x10000000     -->DRAM Size of( 0x10000000 /1024 /1024 = 256M)
DRAM bank = 0x00000002-> DRAM Number, which means the second one DDR
-> start = 0x60000000    -->DRAM Start address of
-> size = 0x10000000     ->DRAM Size of( 0x10000000 /1024 /1024 = 256M)
DRAM bank = 0x00000003-> DRAM Number, which means the third DDR
-> start = 0x70000000    ->DRAM Start address of
-> size = 0x0FF00000     ->DRAM Size of( 0x10000000 /1024 /1024 = 256M)
ethaddr = 00:40:5c:26:0a:5b  ->network card MAC address(DM9600)
ip_addr = 192.168.0.20      ->Development board IP
baudrate = 0           bps ->Baud rate. Here is the code. There is a problem. It should be 115200
TLB addr = 0x3FFF0000      ->MMU(CPU) Mapping table storage location
relocaddr = 0xC3E00000     ->Address of code relocation
reloc off = 0x00000000      ->Relocation address
irq_sp = 0xC3CFBF58       ->irq Stack pointer
sp start = 0xC3CFBF50     ->Start address stack pointer 
FB base = 0x00000000      ->framebuffer Base address

2.7 memory data display - > MD

View help:

TINY4412 # ? md
md - memory display Memory data display---Only data in memory can be displayed, that is, only in DDR Operation in address

Usage:
md [.b, .w, .l] address [# of objects]  

Md.b: display data in bytes
Word in MW. D
Md.l: double word (4 bytes)
The above representation is displayed in bytes, words (2 bytes) and double words (4 bytes)

**Format: * * md.b < address to be displayed > [number of data displayed]

TINY4412 # Md.b 10 / / display 10 data at the starting address 1000000 to the terminal
01000000: 06 00 00 ea fe ff ff ea fe ff ff ea fe ff ff ea    ................

Example:

TINY4412 # md.b 1000000 10 one byte display:
01000000: 06 00 00 ea fe ff ff ea fe ff ff ea fe ff ff ea    ................
TINY4412 # md.w 1000000 10 two byte display
01000000: 0006 ea00 fffe eaff fffe eaff fffe eaff    ................
01000010: fffe eaff fffe eaff 301a ea00 301b ea00    .........0...0..
TINY4412 # md.l 1000000 10 four byte display
01000000: ea000006 eafffffe eafffffe eafffffe    ................
01000010: eafffffe eafffffe ea00301a ea00301b    .........0...0..
01000020: e59f01a4 e3a01000 e5801000 e59f019c    ................
01000030: e5900000 e200003e e330003e 1a00000d    ....>...>.0.....

2.8 copy memory command cp

View help:

TINY4412 # help cp
cp - memory copy  Memory Copy  --It can only be copied in memory, that is, it can only be copied in memory DDR Operation in address

Usage:
cp [.b, .w, .l] source target count Number of source and destination addresses

Example 1:

TINY4412 # cp 100000 4000000 10
 Copy 10 data from the starting address of 100000 to the address of 4000000

Example 2:

TINY4412 # md.b 46000000
46000000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
TINY4412 # md.b 10000000          
10000000: 11 20 41 e4 08 00 05 08 05 00 00 00 10 00 00 00    . A.............
TINY4412 # cp 10000000 46000000 10 copies 10 data from the starting address 10000000 to the address of 46000000
TINY4412 # md.b 46000000          
46000000: 11 20 41 e4 08 00 05 08 05 00 00 00 10 00 00 00    . A.............

2.9 view EMMC information - > mmcinfo

View help:

TINY4412 # help mmcinfo
mmcinfo - mmcinfo <dev num>-- display MMC info  >Output assigned number mmc Information, <dev num>Is the number to assign

Usage:
mmcinfo 

Number Description:
The number of MMC will change. There are EMMC and SD card on Tiny4412 board. Both are classified as MMC. The number is 0, 1. But who is 0 and who is 1 is uncertain, which is related to the startup mode. In which memory is started, the number is 0.

View SD card information:

TINY4412 # mmcinfo 0
Device: S3C_HSMMC2          Equipment name
Manufacturer ID: 2             Manufacturer identification ID
OEM: 544d                   Equipment manufacturer
Name: SE08G                  name
Tran Speed: 0     
Rd Block Len: 512              The size of each block, in bytes
SD version 2.0                 SD Card version
High Capacity: Yes              Is it a mass capacity card
Size: 7460MB (block: 15278080)   Capacity size,(How many blocks are there altogether)
Bus Width: 4-bit                Bus width, SD The card interface is 4 lines
Boot Partition Size: 0 KB          Boot partition size

View EMMC information:

TINY4412 # mmcinfo 1
Device: S5P_MSHC4           equipment
Manufacturer ID: 15         manufacturer ID
OEM: 100                    Original equipment manufacturer
Name: 4YMD3                 name
Tran Speed: 0               Tran speed
Rd Block Len: 512           The size of each block, in bytes
MMC version 4.0             MMC edition
High Capacity: Yes          Is it a mass capacity card
Size: 3728MB (block: 7634944) Card capacity and total block size
Bus Width: 8-bit             Bus width 
Boot Partition Size: 4096 KB Boot partition size

2.10 mmc command subsystem

mmc is not a single command. It is a subsystem that supports multiple commands.

View help information for mmc subsystem

TINY4412 # help mmc
mmc - MMC sub system          MMC Subsystem

Usage:
mmc read <device num> addr blk# cnt -- read data from the sector specified by mmc into ddr
mmc write <device num> addr blk# cnt -- write the data in ddr to the specified mmc sector
mmc rescan <device num>                     --Rescanning the specified device is equivalent to reinitializing
mmc erase <boot | user> <device num> <start block> <block count> --Erase the specified sector
mmc list - lists available devices          --List valid mmc equipment

Parameter Description:

<device num>:  mmc The numbering principle is the same as that mentioned above, that is, which equipment to operate.
addr:  DDR3 Memory address;
blk#: start address of mmc sector to be read / written;
cnt:   To read/Written mmc Number of sectors;
boot:  Reference partition is generally an operation bl1,bl2,u-boot of mmc Sector range.
user:  User partitions are generally used to operate the kernel and file system mmc Sector range.
<start block>: To erase mmc Sector start address;
<block count>: To erase mmc Number of sectors;

The parameters in the mmc command are expressed in hexadecimal, not in hexadecimal

(1) Read data from MMC sector to DDR memory - > MMC read

Format: mmc read <device num> addr blk# cnt
blk#: the starting address (in hexadecimal) of the mmc sector to be read / written
Cnt : To read/Written mmc Number of sectors(Hexadecimal representation)
addr:  DDR3 Memory address;
TINY4412 # mmc read 0 45000000 1 1

MMC read: dev # 0, block # 1, count 1 ... 1 blocks read: OK

This is from SD Starting from the first sector of the card, read the data of one sector to DDR 45 million address!

Example:
TINY4412 # md.b 48000000 10
48000000: ff ff ff ff ff ff ff ff ff ff ff ff bf ff ff ff    ................

//Starting from the first sector of the SD card, read the data of one sector to the address of 48 million DDR
TINY4412 # mmc read 0 48000000 1 1

MMC read: dev # 0, block # 1, count 1 ... 1 blocks read: OK
TINY4412 # md.b 48000000 10       
48000000: a3 69 d3 18 e9 7d b9 66 d1 6b d5 6e d4 79 a6 79    .i...}.f.k.n.y.y

(2) mmc write -- write the data in ddr to the specified mmc sector

Format: mmc write <device num> addr blk# cnt -- write the data in ddr to the specified mmc sector
blk#: the starting address (in hexadecimal) of the mmc sector to be read / written
Cnt : To read/Written mmc Number of sectors(Hexadecimal representation)
addr: DDR3 Memory address;
Example:
TINY4412 # mmc write 0 48000000 1 1 1 write data of one sector to the first sector of SD from DDR 48000000 address

MMC write: dev # 0, block # 1, count 1 ... 1 blocks written: OK

(3) Erase the specified sector

Format:
mmc erase <boot | user> <device num> <start block> <block count> --Erase the specified sector
 Parameter Description:
<start block>: To erase mmc Sector start address
<block count>: To erase mmc Number of sectors
boot:  Reference partition
User:  User partition
 For the convenience of comparison, first SD Read the contents of the first sector of the card DDR Yes.

Read out the data of the 10th sector
TINY4412 # mmc read 0 48000000 1 1

MMC read: dev # 0, block # 1, count 1 ... 1 blocks read: OK

Display the data of the first sector
TINY4412 # md.b 48000000 30       
48000000: a3 69 d3 18 e9 7d b9 66 d1 6b d5 6e d4 79 a6 79    .i...}.f.k.n.y.y
48000010: 07 00 00 ea fe ff ff ea fe ff ff ea fe ff ff ea    ................
48000020: fe ff ff ea fe ff ff ea fe ff ff ea fe ff ff ea    ................
 

Erase SD First sector of the card
TINY4412 # mmc erase user 0 1 1   
START: 1 BLOCK: 1        Start sector 1, erase sector 1
high_capacity: 1         High capacity
Capacity: 15278080       capacity

Erase                    Erase

 512 B erase Done        512 byte
MMC erase Success.!! MMC Erase succeeded.! !
 

Reread and display
TINY4412 # mmc read 0 40000000 1 1

MMC read: dev # 0, block # 1, count 1 ... 1 blocks read: OK
TINY4412 # md.b 40000000 30       
40000000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
40000010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
40000020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
 

Recover the data, read it again and then display it
TINY4412 # mmc write 0 48000000 1 1 1 write data from DDR to SD card

MMC write: dev # 0, block # 1, count 1 ... 1 blocks written: OK
TINY4412 # mmc read 0 40000000 1 1 1 read data again

MMC read: dev # 0, block # 1, count 1 ... 1 blocks read: OK
TINY4412 # md.b 40000000 30 display --- data recovered
40000000: a3 69 d3 18 e9 7d b9 66 d1 6b d5 6e d4 79 a6 79    .i...}.f.k.n.y.y
40000010: 07 00 00 ea fe ff ff ea fe ff ff ea fe ff ff ea    ................
40000020: fe ff ff ea fe ff ff ea fe ff ff ea fe ff ff ea    ................

(4) List MMC devices – mmc list

TINY4412 # mmc list
S3C_HSMMC2: 0 --- 0 Numbered mmc Equipment, connect here SD card
S5P_MSHC4: 1  --- 1 Numbered mmc Equipment, which is connected to the development board EMMC

2.11 viewing MMC partition information - fatinfo

TINY4412 # help fatinfo
fatinfo - fatinfo - print information about filesystem 
                    Print file system information

Usage:
fatinfo <interface> <dev[:part]>   Format description
    - print information about filesystem from 'dev' on 'interface'

Parameter Description:
<interface>:  mmc or usb;
dev:  Equipment number;
part:  Equipment partition number


View the information of the 0th device---Here is SD Card:
TINY4412 # fatinfo mmc 0   
-----Partition 1-----
Partition1: Start Address(0x2e2e2e2e), Size(0x2e2e2e2e)
Zone 1	        Starting address                 size
------------------------
-----Partition 2-----
Partition1: Start Address(0x2e2e2e2e), Size(0x2e2e2e2e)
------------------------
-----Partition 3-----
Partition1: Start Address(0x2e2e2e2e), Size(0x2e2e2e2e)
------------------------
-----Partition 4-----
Partition1: Start Address(0x2e2e2e2e), Size(0x2e2e2e2e)
------------------------
Interface:  SD/MMC
 Interface
        
  Device 0: Vendor: Man 02544d Snr c9226e33 Rev: 2.1 Prod: SE08G
            Type: Removable Hard Disk  
            Type: removable hard disk
            
            Capacity: 14.5 MB = 0.0 GB (29840 x 512)
Partition 1: Filesystem: FAT32 "NO NAME    "

The space is limited. The next article will continue to introduce.

Topics: Linux Operation & Maintenance server