Wei Dongshan uboot_kernel_root file system study notes 4.4-Lesson 004_root file system-section 004_Building the root file system

A minimal item required by the root file system (Note 4.1 4.2 Summary)

(Required for init process)

  1. Open the terminal: /dev/console, /dev/NULL
    If the id (standard input, output and standard error) in the inittab format is not set, it will be located in /dev/NULL.
  2. /sbin/init (init program): It is busybox itself.
  3. /etc/inittab: configuration file is required.
    If the configuration file specifies certain applications or execution scripts-these must exist, there will be defaults if they do not exist.
  4. Libraries required by the application (printf, fopen, fwrite and other functions require library functions).

Build a "minimal root file system" based on the requirements summarized above

1 Create device file: /dev/console, /dev/NULL

  1. Look at these two device files on ubuntu
    Insert picture description here
  2. Created on the embedded file system
[email protected]:~/nfs_root/fs_mini$ mkdir dev						//创建dev目录
[email protected]:~/nfs_root/fs_mini$ ls
bin  dev  linuxrc  sbin  usr
[email protected]:~/nfs_root/fs_mini$ cd dev/
[email protected]:~/nfs_root/fs_mini/dev$ sudo mknod console c 5 1  		//创建设备节点 //节点名称:console//字符型设备:c//主设备号:5//次设备号:1
[email protected]:~/nfs_root/fs_mini/dev$ sudo mknod null c 1 3

2 /sbin/init (init program)

Already have the program:
Insert picture description here

3. /etc/inittab configuration file

[email protected]:~/nfs_root/fs_mini$ mkdir etc								//创建etc文件夹
[email protected]:~/nfs_root/fs_mini/etc$ vim inittab							//创建inittab文件

Enter the contents of the inittab file: as shown below. The simplest configuration file only executes the -/bin/shprogram. This means that only one askfirst /bin/sh program is executed in it, and the standard input, output and standard error of the /bin/sh program are located in "/dev/console".
Insert picture description here

4. C library required by the application

The glibc library has been generated when the cross tool chain was made before, and it can be used directly to build the root file system. The following figure
Insert picture description here
shows the glibc library files: some of these library files are links-pointing to another file, such as the figure below ld-linux.so.2.
Insert picture description here

.so files: dynamic library files, such as dynamic math library libm.so/dynamic C++ library libstdc++.so, etc. These files will be used when compiling the dynamic library, but they will not be linked and will be linked at runtime.

When copying, you need to copy all the .so files in the directory. -d is originally a link file, but also remains a link file. Otherwise, it will be copied into a real file, which will be very large.
Insert picture description here

The minimum root file system is completed above.

2. How to burn the root file system to the development board

  1. Use this tool to make/use yaffs file system image files yaffs_source_util_larger_small_page_nand.tar.bz2(support nand512page or nand2048page).
    After decompressing the tool, enter the directory: /Development_util_ok/yaffs2/utilsexecute the makecommand to compile the following tools. Mainly used later mkyaffs2image.
    Insert picture description here

  2. The mkyaffs2imagecopied to the system directory and add ubuntu executable properties:
    Insert picture description here

  3. Create file system image
    Back to the created embedded file system directory: ~/nfs_root/
    input command: mkyaff2imageview the usage of the command;
    Insert picture description here
    input command: mkyaffs2image fs_mini fs_mini.yaffs2generate fs_mini.yaffs2an image file named as .
    Insert picture description here

  4. Burn the image fs_mini.yaffs2
    (1) Power on the development board and enter the uboot directory and enter y
    Insert picture description here
    (2) Open the dnw software for burning

  5. Check the startup process of the development board.
    Problem: The file system created according to the above steps prompts the error in the figure below. It is invalid after several attempts. The error will be solved later...
    Insert picture description here

After normal startup, it should look like the following figure.
Insert picture description here
Check the etc/inittab file in the file system:

# cat /etc/inittab
# /etc/inittab
ttySAC0::askfirst:-/bin/sh
  1. bootargs set default value
bootargs=noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200

Three perfect root file system 1-support PS command

  1. Support PS command

PS command: To monitor and control the process, you must first understand the current process, that is, you need to view the current process. The ps command is the most basic process view command. Use this command to determine which processes are running and running status, whether the process is over, whether the process has zombies, which processes are occupying too many resources, etc. In short, most of the information can be obtained by executing this command. ps displays the status of the instantaneous process, not dynamic and continuous; if you want to monitor the process in real time, you should use the top command.

The command requires the kernel 虚拟文件系统that is PROC, first of all you need to load up the core file system.

mkdir proc
mount -t proc none /proc
ps

The PID in the figure below represents the process number;
Insert picture description here
enter the process with process number 1 to view:
Insert picture description here
view the attributes of fd in the folder with process number 1 as shown in the figure below: all point to /dev/console

 0 -> /dev/console	//表示标准输出
 1 -> /dev/console	//表示标准输入
 2 -> /dev/console	//表示标准错误

Insert picture description here

  1. How to support the PS command (Method 1)
    (1) We need to automatically mount the above PROC, so we need to compile the inittab file, so that the configuration file requires the kernel to automatically execute a script: vim /etc/inintab
    Insert picture description here
    (2) Create the /etc/init.d/rcS file, give Add executable attribute to
    rcS file. The content of the rcS file is as follows: the kernel is required to execute the command
    Insert picture description here
    Insert picture description here

  2. How to support PS command (Method 2)
    (. 1) rcS file content may be modified further: mount -a;
    Meaning: reading out /etc/fstabcontents of the file, the file system based on the contents of the mount
    (2) /etc/fstabfile format explain

#device	mount-point	type	options		dump	fsck	order
proc	/proc		proc	defaults    0		0

Insert picture description here
Insert picture description here

  1. Check the effect:
    check the currently mounted file system, as shown in the figure below: the yaffs file system, rootfs root file system, and proc virtual file system have been mounted
    Insert picture description here

Four perfect root file system 2-mdev use (see P355)

  1. udev: automatically create /dev/device node;
  2. mdev: A simplified version of udev, which creates device files by reading kernel information. For usage see: busybox-1.7.0/doc/mdev.txt file.
    Insert picture description here
  3. Specific steps
    Insert picture description here

Among them, it [2] echo /bin/mdev > /proc/sys/kernel/hotplugmeans hot swap. When a driver is dynamically loaded or a U disk is inserted, the kernel automatically calls the /proc/sys/kernel/hotplugprogram; it
[3]mdev -smeans that all existing driver nodes in the kernel are created;

  1. Check the effect
    (1) There are many device nodes in the dev directory, these are the nodes automatically created by mdev
    Insert picture description here
    (2) Check the mounted file system
    Insert picture description here

Five use other file systems-jffs2 (see P360)

jffs2: Generally used for nor flash, then we currently use it for nand flash.

Insert picture description here

./configure --shared --prefix=/usr configuration information
--shared means compiled into a dynamic library
--prefix=/usr means installed in the /usr directory
sudo make install means installed in the system directory

Insert picture description here

Note: Use different flash to modify the corresponding parameter
-s 512 to -s 2048
-e 16KiB to -e 128KiB

Insert picture description here

Check the effect:
Insert picture description here

Six use other file systems-network file system NFS

开发阶段经常使用网络文件系统进行程序调试

NFS (Network File System) is the network file system, which allows computers on the network to share resources through the network. Mount the directory shared by the NFS host to the local client. The local NFS client application can transparently read and write files located on the remote NFS server, which looks like accessing local files on the client.

  1. Set the network segment of the ubuntu server and the development board to the same network segment:
    ubuntu ip address: 192.168.8.201
    development board ip address: ifconfig eth0 192.168.8.210
    development board can ping ubuntu

  2. Prerequisites for using commands to mount NFS
    (1) Ubuntu server allows a certain directory to be mounted
    Edit the corresponding file of Ubuntu server: sudo vim /etc/exports
    Insert picture description here
    Restart Ubuntu's nfs service:
    Insert picture description here
    Try ubuntu to mount its own NFS directory: sudo mount -t nfs 192.168.8.201:/home/book/nfs_root/fs_mini1 /mnt
    Insert picture description here
    (2) Go to the board Mount
    single board mount command:mount -t nfs -o nolock 192.168.8.201:/home/book/nfs_root/fs_mini1 /mnt

  3. Start the development board directly from NFS
    (1) uboot modify environment variables

bootargs=noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200
修改为
bootargs=noinitrd root=/dev/nfs nfsroot=192.168.8.201:/home/book/nfs_root/fs_mini1 ip=192.168.8.210:192.168.8.1:255.255.255.1:eth0:off init=/linuxrc console=ttySAC0,115200

(2) NFS startup parameters: server IP/mount directory/IP of the development board.
Find the description document: linux-2.6.22.6\Documentation\nfsroot.txtthen the parameters found are

nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]
ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>

Note: The parameters indicated by square brackets [] can be omitted; the parameters indicated by angle brackets <> cannot be omitted
. There is an explanation of usage in the documentation, so there is no screenshot here.

Guess you like

Origin blog.csdn.net/xiaoaojianghu09/article/details/104211168