itop-3568 development board file system construction study notes (2) Busybox makes the smallest file system

"[Beijing Xunwei] itop-3568 Development Board File System Construction Manual v1.0.pdf" study notes

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.

insert image description here

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:

  1. Modify libbb/printable_string.c

insert image description here

  1. Modify libb/unicode.c

insert image description here

  1. Modify the configuration file

Open the terminal, enter the root directory of the busybox source code, enter make menuconfigto open configuration interface, and open the two configuration items in the figure below (Settings --> Library Tuning --> Support Unicode, in the latter part of Settings)

insert image description here

configure busybox

Open the terminal, enter the root directory of the busybox source code, and enter make menuconfigto open the configuration interface. First set up the cross compiler (Settings–>Build Options–>Cross Compiler prefix):

insert image description here

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:

insert image description here
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:

insert image description here

Compile and install busybox

After configuring busybox, execute makeand make installto 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

  1. Create the necessary folders

Add some necessary directories (dev, lib, mnt, lib, mnt, proc, sys, tmp, var, etc/init.d):

insert image description here

  1. 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.

insert image description here

When copying, the link relationship between library files needs to be preserved.

insert image description here

  1. 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):

insert image description here

insert image description here
Set permissions (I don't know if it is a necessary step)

insert image description here

  1. 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):

insert image description here
insert image description here

The format of each line of this file is:<name>:<password><uid>:<gid>:<comment>:<home>:<shell>

  1. 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:

insert image description here
Keep the following five lines:

insert image description here

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

  1. Create etc/init.d/rcS file

The above inttable file ::sysinit:/etc/init.d/rcSindicates 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:

insert image description here

The content of rcS is as follows:

insert image description here

  1. 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:

insert image description here

The content of the profile file is as follows:

insert image description here

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):

insert image description here

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).

insert image description here

After copying, unmount rootfs.ext4 and rename it to rootfs.img. At this point, the root file system image is created.

insert image description here

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:

insert image description here

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:

insert image description here

Guess you like

Origin blog.csdn.net/weixin_43772810/article/details/129080320