Master the Complete Process of Reading and Writing Files on Storage Devices at the U-Boot Stage of the RK3588 Development Board in 10 Minutes
by yir65681 in Circuits > Linux
2 Views, 0 Favorites, 0 Comments
Master the Complete Process of Reading and Writing Files on Storage Devices at the U-Boot Stage of the RK3588 Development Board in 10 Minutes
The Forlinx OK3588-C development board is built based on a flagship processor that utilizes an advanced 8nm manufacturing process and adopts a big.LITTLE architecture, featuring four Cortex-A76 cores and four Cortex-A55 cores. It not only features a triple-core NPU with 6 TOPS computing power and 8K ultra-high-definition processing capabilities, but also provides a stable and reliable hardware foundation for storage device debugging through rich hardware designs such as dual independent MMC controllers and multi-specification USB interfaces.
This article outlines standardized methods for accessing the contents of various storage devices (eMMC, TF cards, USB flash drives) during the U-Boot console stage of the RK3588 development board. While the initialization subsystems of various storage devices differ, unified read and write operations can be performed through the U-Boot console, making it ideal for development, debugging, and system verification scenarios.
Enter the U-Boot Console
The U-Boot for the Forlinx RK3588 development board has been extensively customized and optimized. By default, there is a reasonable boot delay configured. During the U-Boot startup process, you can interrupt this countdown and enter the interactive console by pressing the Spacebar or Ctrl + C before the automatic startup completes.
The operation interface and an example are as follows:
Prompt: If you fail to press the key in time, U - Boot will continuethe automatic startup (loading the kernel). You need to restart thedevelopment board and try again.
Reading and Writing Files on MMCDevices (EMMC/TF Cards)
The RK3588 development board features dual MMC controllers in its hardware, which correspond to the EMMC and TF card interfaces. It is fully compatible with the EMMC 5.1 specification and the SD 3.0 protocol. The board supports the HS400 high-speed transmission mode and allows for both 8-bit and 4-bit data bus widths. This design provides hardware support for the parallel operation of storage devices. Reading and writing files on MMC devices requires following a four-step process of ''identification → switching → querying → operating''.
The specific steps are as follows:
1. View MMC Controllers
Use the ''mmc list'' command to view the initialized MMC controllers (pre - defined by the device tree, usually 0 corresponds to EMMC and 1 corresponds to the TF card) and confirm whether the devices are recognized:
2. Switch MMC Devices
Use the''mmc dev <device number>''command to switch to the target device. The device number corresponds to the controller serial number queried in the previous step:
3. View MMC Device Information
After switching the device, use the mmc info command to view the detailed device parameters (capacity, bus width, interface version, etc.).
Examples of EMMC and TF card information are as follows:
Example of EMMC device information:
Examples of TF card device information:
4. View MMC Device Information
Use the MMC part command to view the device partition table (take EMMC as an example, the partition type is EFI), and obtain key information such as the partition name and the start/end address:
5. View the file system content
Use theext4ls <device type> <device number:partition number>command to view the directory structure of the specified partition (Example: the rootfs partition, which is the 6th partition of the EMMC):
6. Read the file content (Take Hello.txt as an example)
To read the/home/forlinx/Hello.txtfile in the rootfs partition, you need to follow four steps: ''Confirm existence → Select memory address → Load the file → View the content''.
Confirm the file existence:Verify the validity of the target file path usingext4ls:
Warning: Do not use the system -reserved memory (such as DRAM bank 0), otherwise, it may cause the U -Boot to crash or data corruption.
Load the file into memory: Useext4loadto load the file to the specified memory address.
View the file content in memory: Use md.b <address> <length>to read the memory data.
7. Modify the file content (You need to enable ext4write)
Important: The ext4write command is disabled by default in U-Boot (to prevent accidental operations). You need to enable it in the U-Boot source code configuration first.
After enabling the function, two modification methods aresupported:
(1)Replacement-style modification (Load an external file tooverwrite):
(2)Directly modify the memory data and then write:
Reading Files From USB Devices(such As USB Flash Drives)
USB devices are external storage. Please initialize the USB subsystem first to recognize them. The steps are as follows:
1. Initialize the USB subsystem:
Use the usb start command to start the USB controller and scan for devices. After successful recognition, the number of storage devices will be displayed.
Tip: If the device is not recognized, check the USB flash drive connection (it is recommended to plug it into a USB 2.0 port) or re-execute the usb start command.
2. View the files on the USB device:
USB flash drives are usually in the FATT32 format. Use fatls usb <device number> to view the directory content (The device number starts from 0 by default).
3. Read the file content from the USB device:
Use fatload to load the file into memory and then use md.b to view the content:
Key Precautions
All operations need to be performed on the U - Boot console. Make sure the development board has entered the console mode normally (not in the automatic startup process).
For MMC devices (EMMC/TF cards), the commonly used commands are ext4ls/ext4load/ext4write(for the ext4 file system). For USB devices, the commonly used commands are fatls/fat load(for the FAT file system). Please select the commands according to the file system.
Write operations (such asext4write) pose data risks. It is recommended to use them in a debugging environment and avoid enabling them in a production environment.
If you need to integrate file operations into the U-Boot source code, you can call the API provided by U-Boot (such asext4_read_file(), usb_storage_probe()). Make sure the corresponding drivers are compiled.