"[Beijing Xunwei] itop-3568 Development Board File System Construction Manual v1.0.pdf" study notes
Article directory
Download Busybox
BusyBox is a software that integrates more than 300 most commonly used Linux commands and tools. BusyBox includes simple tools like ls, cat, echo, etc., and larger, more complex tools like grep, find, mount, and telnet. Some people refer to BusyBox as the Swiss Army Knife of Linux tools. Simply put, BusyBox is like a big toolbox, which integrates and compresses many tools and commands of Linux, and also includes the shell that comes with the Linux system.
--Baidu Encyclopedia
The official download address of Busybox is: https://busybox.net/downloads/ . This tool is an open source program, and the version used in the Xunwei tutorial is busybox-1.33.1, so I also choose to download this version.
Settings support Chinese
The newer version of busybox cannot display Chinese when using the ls command, because the version after busybox1.17.0 has limited Chinese support, if you want busybox to support Chinese, you need to make the following modifications:
- Modify libbb/printable_string.c
- Modify libb/unicode.c
- Modify the configuration file
Open the terminal, enter the root directory of the busybox source code, enter make menuconfig
to open configuration interface, and open the two configuration items in the figure below (Settings --> Library Tuning --> Support Unicode, in the latter part of Settings)
configure busybox
Open the terminal, enter the root directory of the busybox source code, and enter make menuconfig
to open the configuration interface. First set up the cross compiler (Settings–>Build Options–>Cross Compiler prefix):
The name of the cross compiler should be filled in according to your own development environment. The following is the cross compiler in my environment variable:
busybox is installed to the ./_install directory by default. If you need to change it, you can modify the relevant options under Setting–>Installation Options in the configuration menu:
Compile and install busybox
After configuring busybox, execute make
and make install
to compile and install busybox.
After the installation is complete, enter the installation directory, you can see four directories (bin, linuxrc, sbin and usr)
Improve the root file system
- Create the necessary folders
Add some necessary directories (dev, lib, mnt, lib, mnt, proc, sys, tmp, var, etc/init.d):
- copy dynamic library
Since busybox does not use static libraries by default when compiling, and the lib/ directory of the minimal system after installation is empty, you must copy the dynamic library files of the cross compiler to run the binary (command) files in bin/ and sbin/ into the lib/ directory of the minimal system.
When copying, the link relationship between library files needs to be preserved.
- Create etc/fstab file
fstab contains information about storage devices and file systems, and fstab can automatically mount hard disks, partitions, and removable devices of various file systems.
Here I directly copy Ubuntu's /etc/fstab to the minimal system (and then modify it manually):
Set permissions (I don't know if it is a necessary step)
- Create etc/passwd file
The passwd file is used to store user information. Similarly, I copied the Ubuntu passwd file to the minimal root file system (and then modified it manually):
The format of each line of this file is:<name>:<password><uid>:<gid>:<comment>:<home>:<shell>
- Create etc/inittab file
Copy the inittab file in the example folder in the root directory of the busybox source code to the minimal root file system:
Keep the following five lines:
sysinit: Provide init with a path to initialize the command line
askfirst: It will restart whenever the corresponding process terminates (it will make init prompt the user to press Enter to continue on the console)
restart: When init restarts, execute the corresponding corresponding process (execute init here itself)
shutdown: Execute the corresponding process when the system shuts down
- Create etc/init.d/rcS file
The above inttable file ::sysinit:/etc/init.d/rcS
indicates that when the system starts, the /etc/init.d/rcS script will be executed, and the rcS file will be created in the etc/init.d directory of the smallest root file system:
The content of rcS is as follows:
- Create /etc/profile file
The profile file is used to set our environment variables, create a profile file in the etc/ directory of the smallest root file system:
The content of the profile file is as follows:
Create a filesystem image
Through the above steps, the root file system is completed. Now it is necessary to package the root file system into an image and burn it into the development board.
Create an empty folder rootfs
, use the du command to check my minimum root file system size (about 64M), and then use the dd command to generate a .ext4 file with a size of 80M (in principle, 70M is enough, but I actually reported an error , so take 80M directly), and finally use mkfs.ext4 to format rootfs.ext4. (The -L parameter is followed by the filesystem's header name):
Mount rootfs.ext4 to the empty directory rootfs, and then copy all the files of the previously modified minimal root file system to rootfs (note that the link relationship between files is preserved).
After copying, unmount rootfs.ext4 and rename it to rootfs.img. At this point, the root file system image is created.
Finally, use the Rockchip development tool to copy the rootfs.img file to the development board.
Test the root file system
The following is the busybox root file system I made. You can see that the file system can either input Chinese or display Chinese:
Next, test the library file. The following is a simple C program. Now test whether it can run in the minimal file system I just made.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
// argc:命令行中参数的个数
// argv:命令行的参数
int i = 0;
printf("参数个数为 %d\n", argc);
for(i = 0; i < argc; i++)
{
printf("第%d个参数为 %s.\n", i + 1, argv[i]);
}
return 0;
}
The running results are as follows, and the C program runs successfully: