“This is my 38th day of participating in the First Challenge 2022. For details: First Challenge 2022”
1. Introduction
U-boot is an open source bootloader used to boot operations and provide testing and debugging tools for developers. Linux itself is a compact Linux system, mainly responsible for hardware initialization and boot, with some tools, as a boot program, often as the boot of embedded devices. When the real system starts running, the U-boot hands over administrative rights.
Reasons for choosing U-boot: ① Open source; ② Support a variety of embedded operating system kernel, such as Linux, NetBSD, VxWorks, QNX, RTEMS, ARTOS, LynxOS, Android; ③ Support multiple processor series, such as PowerPC, ARM, x86, MIPS; ④ Higher reliability and stability; ⑤ Highly flexible function Settings, suitable for U-boot debugging, operating system different Boot requirements, product release, etc. ⑥ Rich device driver source, 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 U-boot can work in Boot loading mode and download mode. Bootloader 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 and runs the whole process automatically. In the download mode, the Bootloader downloads the kernel image or root file system image from the PC to the FLASH of the target board by some means of communication. Users can use some command interfaces provided by Bootloader to complete their desired operations.
Currently, the development board for testing uboot commands is Friendly Arm TIN441, which uses Samsung EXYNOS4412. This article focuses on the function and usage of uboot command line. The uboot version used is 2010.12, which is the official Uboot provided by Friendly Arm.
2. Introduction to UBOOT commands
2.1 Help command –help
View the commands supported by the current UBOOT.
TINY4412 # help ? Boot-boot default, i.e., run 'bootcmd' bootd-boot default, i.e., run 'bootcmd' bootd-boot default, i.e. i.e., Run 'bootcmd' bootelf -boot from an ELF Image in memory BOOTM - Start the application booTP from memory - Bootvx - network Boot image using booTP/TFTP protocol Boot vxWorks from an ELF image chpart - Change active partition cmp-memory compare coninfo - print console devices and information cp - Memory copy CRC32 - Check and calculation dCache - Enable or disable data cache DNW - DNW - USB device is initialized and ready to accept Windows Server (specific) echo - Echo args to Console Editenv - Modify environment variable emMC - Open/close EMMC boot partition env - Environment processing command exit - exit script ext2format- ext2 ext2format -- disk format ext2load- Ext3format - ext3 ext3format -- Disk format False - Do nothing but fail fastboot- fastboot -- Use USB Fastboot protocol fatformat-fat32 Fatformat -- Disk format fatinfo-fatinfo -- Prints information about the file system fatload-fatLOAD -- the file system fatls - that loads binary files from DOS A directory list file (default /) fdisk - fdisk for SD /mmc. go - Start application at 'addr' 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-increaddress) 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 versionCopy the code
2.2 Viewing the usage of the command help
Format: help < instruction you want to look up > or? < command you want to check >, even h < command you want to check abbreviation >.
TINY4412 # help sleep sleep - delay execution time Usage: sleep N - delay execution N seconds (N is _decimal_! ! !).Copy the code
2.3 Print the 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 bytesCopy the code
Baudrate: indicates the current baudrate. Generally not modified. Bootcmd: start command. Bootdelay: indicates the delay of executing the bootcmd command. Ethaddr: indicates the MAC address of a nic. Gatewayip: indicates the gatewayip address. Ipaddr: indicates the IP address of the development board. Netmask: indicates the subnet mask. Serverip: indicates the serverip address (usually the IP address of a PC and the IP address of a host that provides various network services for the development board) bootargs: indicates the boot parameter transmitted to the operating system kernel by the u-boot. (Very important)
Print the specified environment variables using an example
Format: printenv Prints the name of the environment variable
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, 115200Copy the code
2.4 Setting the environment variable –setenv
TINY4412 # help setenv setenv -set environment variables --> Setenv setenv Usage: // Setenv name value -set environment variable 'name' to 'value... '// Set the environment variable' name ' 'value... Setenv name-delete environment variable 'name' // Delete environment variableCopy the code
Use the sample
Set the power-on delay: TINY4412 # setenv bootdelay 10 TINY4412 # saveenv Saving Environment to SMDK Bootable device... Done set baudrate example: TINY4412 # setenv baudrate 115200 ## Switch baudrate to 115200 BPS and press ENTER... // You need to restart the development board for the Settings to take effect automatically. Example: Setenv baudrate // Delete the baudrate environment variableCopy the code
Examples of reference environment variables:
TINY4412 # setenv timer 10 // set an environment variable TINY4412 # setenv bootdelay ${timer} // reference environment variable TINY4412 # save // save environment variable Saving Environment to SMDK bootable device... The 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 // The setting is successful 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 the new Environment variable Environment size: 389/16380 bytes TINY4412 #Copy the code
2.5 Setting Bootargs Parameters
Bootargs is the most important environment variable, or even the entire environment variable is set around Bootargs.
Coherent_pool parameters:
Example of setting the size of DMA: coherent_pool=2MCopy the code
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, 115200Copy the code
Example for mounting an NFS network:
The 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, 115200Copy the code
The root parameter is used to specify the location where the root file system is mounted.
Parameter nfsroot needs to be set only when the NFS network file system is mounted, followed by the NFS address of the server, and the mount directory
The IP parameter is the IP address of the network interface card (NIC) on the development board.
Init is a script that is run after the file system is specified to be mounted to do some system initialization.
2.6 Viewing the configuration information of the development board -bdinfo
TINY4412 # bdinfo arch_number = 0x00001200 Used to boot the operating system kernel boot_params = 0x40000100 -> Boot parameter storage memory location DRAM bank = 0x00000000 -> DRAM number, DDR -> start = 0x40000000 --> START ADDRESS of DRAM --> size = 0x10000000 --> SIZE of DRAM (0x10000000/1024/1024 = 256M) DRAM bank = 0x00000001 -> DRAM number, This indicates that it is the first DDR -> start = 0x50000000 -> START ADDRESS of DRAM -> size = 0x10000000 -> SIZE of DRAM (0x10000000/1024/1024 = 256M) Bank = 0x00000002-> DRAM id, This indicates that it is the second DDR -> start = 0x60000000 -> START ADDRESS of DRAM -> size = 0x10000000 -> SIZE of DRAM (0x10000000/1024/1024 = 256M) Bank = 0x00000003-> DRAM id, DDR -> start = 0x70000000 -> START address of DRAM -> size = 0x0FF00000 -> Size of DRAM (0x10000000/1024/1024 = 256M) Ethaddr = 00:40:5c:26:0a:5b -> MAC address of nic (DM9600) ip_addr = 192.168.0.20 -> IP baudrate = 0 BPS -> baudrate 115200 TLB addr = 0x3FFF0000 -> Storage location of the MMU(CPU) mapping table RelocADDR = 0xC3E00000 -> Reloc OFF = 0x00000000 -> Relocation address Irq_sp = 0xC3CFBF58 -> IRQ stack pointer sp start = 0xC3CFBF50 -> Start address Stack pointer FB Base = 0x00000000 -> FrameBuffer base addressCopy the code
2.7 Memory Data Display -> MD
View help:
TINY4412 # ? Md [.b,.w,.l] address [# of objects] Usage: md [.b,.w,.l] address [# of objects]Copy the code
Md.b: displays data in bytes MD. w: displays data in words (2 bytes) MD. l: displays data in bytes, words (2 bytes), and words (4 bytes)
Format: MD.b < Address to display > [Number of data to display]
TINY4412 # md.b 1000000 10 // Display 10 data at the starting address 1000000 to terminal 01000000: 06 00 00 ea fe ff ff ea fe ff ff ea fe ff ff ea ................Copy the code
Example:
TINY4412 # md.b 1000000 10 One byte display: 01000000:06 0000 EA fe ff FF EA fe ff FF EA................ TINY4412 # md.w 1000000 10 Two bytes 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 bytes display 01000000: ea000006 eafffffe eafffffe eafffffe................ 01000010: eafffffe eafffffe ea00301a ea00301b ......... 0... 0.. 01000020: e59f01a4 e3a01000 e5801000 e59f019c ................ 01000030: e5900000 e200003e e330003e 1a00000d .... >... >. Zero...Copy the code
2.8 Copying memory Command cp
View help:
TINY4412 # help cp cp -memory copy -- copy in memory, only in DDR address Cp [.b,.w,.l] Source Target Count Number of source target addressesCopy the code
Example 1:
TINY4412 # cp 100000 4000000 10 copy 10 data from 100000 to 4000000Copy the code
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 copy 10 from address 10000000 to address 46000000 TINY4412 # md.b 46000000 46000000: 11 20 41 e4 08 00 05 08 05 00 00 00 10 00 00 00 . A.............Copy the code
2.9 Viewing EMMC Information -> mmcInfo
View help:
TINY4412 # help mmcinfo mmcinfo -mmcinfo <dev num>-- display MMC info > Displays information about the specified MMC. <dev num> is the specified number. Usage: mmcinfoCopy the code
Number description: THE number of MMC will change, Tiny4412 board has EMMC, SD card. Both of these are classified as MMCS. The number is 0,1. But who’s a zero and who’s a one is not certain, depending on how you start. Whichever memory is started, the number is 0.
View SD card information:
TINY4412 # mmcInfo 0 Device: S3C_HSMMC2 Device Name Manufacturer ID: 2 Manufacturer ID OEM: 544D Device Manufacturer Name: SE08G Name Tran Speed: 0 Rd Block Len: 512 Size of each Block, in bytes SD version 2.0 SD card version High Capacity: Yes whether the SD card has a large Capacity Size: 7460MB (Block: 15278080) The Size of the SD card is 0 KB. The Size of the SD card is 0 KBCopy the code
To view EMMC information:
TINY4412 # mmcInfo 1 Device: S5P_MSHC4 Device Manufacturer ID: 15 Manufacturer ID OEM: 100 OEM: 4YMD3 Name Tran Speed: 0 Tran speed Rd Block Len: 512 Size of each Block, in bytes MMC version 4.0 MMC version High Capacity: Yes whether the card has large Capacity Size: 3728MB (Block: 7634944) card Size and total block Size Bus Width: 8-bitCopy the code
2.10 MMC Command subsystem
MMC is not a single command, it is a subsystem that supports multiple commands.
View help information for the MMC subsystem
TINY4412 # help MMC MMC-MMC sub System MMC read <device num> addr blk# CNT -- reads data from the specified sector of the MMC to the DDR. MMC write <device num> addr blk# CNT -- writes data from the DDR to the specified sector of the MMC MMC rescan <device num> -- rescan specified devices, Equivalent to initialize the MMC erase < boot | user > < device num > < start block > < block count > MMC - erasing specified sectors list - lists the available devices List valid MMC devicesCopy the code
Parameter Description:
<device num> : indicates the NUMBER of the MMC. Addr: INDICATES the DDR3 memory address. Blk# : start address of the MMC sector address to read/write; CNT: number of MMC sectors to read/write; Boot: Refers to the MMC sector range used to operate BL1, BL2, and U-boot. User: the user partition, usually the MMC sector range of the operating kernel and file system. <start block> : the start address of the MMC sector to be erased; <block count> : number of MMC sectors to be erased;Copy the code
Parameters in the MMC command are expressed in hexadecimal notation, not in decimal notation
(1) Read data from MMC sector into DDR memory -> MMC read
Format: MMC read <device num> addr blk# CNT blk# : start address of the MMC sector to be read/written (in hexadecimal) CNT: number of MMC sectors to be read/written (in hexadecimal) addr: DDR3 memory address; TINY4412 # mmc read 0 45000000 1 1 MMC read: dev # 0, block # 1, count 1 ... 1 blocks read: OK This reads the data from the first sector of the SD card to the DDR 45000000 address! Example: TINY4412 # md.b 48000000 10 48000000: FF FF FF FF ff ff ff ff ff ff ff ff bf ff ff ff ff................ 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.yCopy the code
(2) MMC write — Write DDR data to the specified MMC sector
Format: MMC write <device num> addr blk# CNT -- write DDR data to the specified MMC sector blk# : start address of the MMC sector to read/write (in hexadecimal) CNT: Number of MMC sectors to read/write (hexadecimal) addr: DDR3 memory address; Example: TINY4412 # MMC write 0 48000000 1 1 Write 1 sector data to the first sector of the SD from the DDR 48000000 address MMC write: dev # 0, block # 1, count 1... 1 blocks written: OKCopy the code
(3) Erase the specified sector
Format: MMC erase < boot | user > < device num > < start block > < block count > - erasing specified sector parameters description: < start block > : Start ADDRESS of MMC sectors to be erased <block count> : number of MMC sectors to be erased Boot: reference partition User: User partition For comparison, read the first sector of the SD card to the DDR. TINY4412 # MMC read 0 48000000 1 1 MMC read: dev # 0 block # 1 count 1... 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 ................ TINY4412 # MMC erase user 0 1 1 START: 1 BLOCK: 1 START sector 1, erase sector 1 high_capacity: 1 15278080 capacity Erase Erase 512 B Erase Done 512 bytes MMC Erase Success. MMC erasure succeeded. ! ! 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 ................ MMC write: dev # 0, block # 1, count 1... 1 block written: OK TINY4412 # MMC read 0 40000000 1 1 MMC read: dev # 0, block # 1, count 1... 1 blocks read: OK TINY4412 # md.b 40000000 30 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 ................Copy the code
(4) List MMC devices — MMC List
TINY4412 # MMC list S3C_HSMMC2:0 -- 0 MMC device, here connected to SD card S5P_MSHC4:1 -- 1 MMC device, here connected to development board onboard EMMC deviceCopy the code
2.11 Viewing MMC Partition Information (fatinfo
TINY4412 # help fatinfo fatinfo - fatinfo - print information about filesystem Fatinfo <interface> <dev[:part]> -print information about filesystem from 'dev' on 'interface' parameter description: <interface> : MMC or usb; Dev: indicates the device id. TINY4412 # Fatinfo MMC 0 -----Partition 1----- Partition1: The Start Address (0 x2e2e2e2e), Size (0 x2e2e2e2e) Partition 1 starting Address Size -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Partition 2 -- -- -- -- - Partition1: Start Address(0x2e2e2e2e), Size(0x2e2e2e2e) ------------------------ -----Partition 3----- Partition1: Start Address(0x2e2e2e2e), Size(0x2e2e2e2e) ------------------------ -----Partition 4----- Partition1: The Start Address (0 x2e2e2e2e), Size (0 x2e2e2e2e) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Interface: SD/MMC Interface Device 0: Vendor: Man 02544d Snr C9226E33 Rev: 2.1 Prod: SE08G Type: Removable Hard Disk 14.5MB = 0.0GB (29840 x 512) Partition 1: Filesystem: FAT32Copy the code
Continue in the next article.