Create a root file system based on the following five items:
/dev/console,/dev/null;
init ⇒ busybox;
/etc/inittab;
The program specified in the configuration file;
C library.
/dev/console,/dev/null
First, create two devices: /dev/console and /dev/null. Let's take a look at the descriptions of these two devices in the PC. (All devices exist in the form of files in the /dev directory, called device files)
The C in crw indicates a character device, 5 is the major device number, and 1 is the minor device number. (In an embedded system, a character device or block device has a major device number and a minor device number, which are collectively referred to as the device number. The major device number is used to represent a specific driver, and the minor device number is used to represent each device of the driver. For example, an embedded system has two LED lights that need to be turned on or off independently, so you can write a character device driver for the LED lights, register its major device number as 10, and the minor device numbers are 1 and 2, representing two LED lights)
So, we first create a dev directory, and then create console and null in the dev directory.
Use the mknod command to create a device file. c means that a character device is created (b means a block device), then the major device number is 5, the minor device number is 1, and null is similar.
After creation, use ll to view it.
init ⇒ busybox
The second item is the link from init to busybox. Our init = /linuxrc, so it is the link from linuxrc to busybox. This item has been done.
/etc/inittab
The third item is to construct an inittab. If we do not construct our own inittab file, the default configuration will be used. The following figure is the default configuration summarized earlier.
We don't need so many, just one ::askfirst:-/bin/sh is enough.
Create an etc directory and create an inittab file in this directory. Note that the terminal needs to be set to console, and the standard input, standard output, and standard error should all be located in the console.
The final result is as follows. Use the cat command to view the file contents.
In this way, the inittab file is configured. This is the simplest inittab file. It only executes one program with the execution timing of ASKFIRST - /bin/sh. The standard input, standard output, and standard error of this program are all controlled by /dev/console.
Programs specified in the configuration file
Fourth, the program specified in the configuration file. Since we only want to make a minimal root file system and not execute any application programs, we will not configure it here and will improve it later.
C Library
Fifth, C library.
Check the application manual, which tells how to install the C library.
Just copy all the .so files. -d means that if the file is a link file, then it will also be a link file when copied, and the dynamically linked files will not be copied, so it will not be very large. (.a means static library, we don't need static library)
Create a lib directory under 046, and then copy all the .so files to it. Remember not to forget -d.
In this way, we have made a minimal root file system. It should be noted that this root file system has no applications.
Burn the root file system
So, how do we burn this root file system to our development board?
Answer: You need to make an image file. Check the Embedded Linux Application Development Manual. 17.4.4 and 17.4.5 respectively describe how to make the yaffs and yaffs2 root file systems. Yaffs is used for small page (512 bytes per page) Flash. Our NAND flash has 2048 bytes per page, so we need to use the yaffs2 root file system that supports large pages.
The tool used to compile the image file is called mkyaffs2image, and the format is: mkyaffs2image directory name image file name.
Execute the following compilation instructions to compile an image file 046_first_fs.yaffs2, send this file to Windows, and then burn the development board.
Select y on the menu page in uboot and use the DNW burning tool to burn the image file.
After the flashing is complete, an error occurs when loading the root file system. The error message is as follows.
I checked the init_main function and found that the error occurred when matching the name. Action was lowercase, but it was uppercase in inittab, which caused the match to fail.
Change ASKFIRST to lowercase, recompile the image file and burn it, and it will start normally.
In this way, my first root file system was successfully burned and run.
Complete the root file system
The compiled root file system does not have any functions. For example, if we want to use the ps command, we will find that this command is not supported.
We need to improve it further, how do we improve it?
First, use mkdir proc to create a proc folder. Although a proc folder is created, the ps command is still invalid at this time, and a virtual root file system must be mounted.
So, what to do?
Answer: In the kernel, the information about which applications are currently running is stored in a virtual root file system called proc in the kernel. You can implement the ps command by mounting the proc directory you just created to this virtual root file system.
Use mount -t proc none /proc to mount, and then the ps command can be used normally.
At this time, enter the proc directory and you can see that there are many files in it. This is because proc has been mounted to the virtual root file system provided by the kernel.
If you do not want to mount manually, you can set it to mount automatically in the /etc/inittab configuration file.
Add a line to the inittab file, ::sysinit:etc/init.d/rcS, then create an init.d directory under the etc path and create an rcS file in this directory, which is a script file.
Enter the mount command in the rcS file and add an executable attribute to it. Then each time you run it, the proc will be automatically mounted during initialization.
In addition to the above method, another method is to use the mount -a command, which will mount all file systems defined in /etc/fstab.
To use this method, first modify the rcS script, comment out mount -t proc none /proc, and add mount -a.
Then, you need to add an fstab file in the etc directory, and add proc /proc and so on in this file in sequence, with each item separated by a space.
#Lines are format instructions:
device, the device to be mounted;
mount-point, mount point;
type, file system type;
options, hook parameters, separated by commas;
Both methods can achieve automatic mounting.
After loading the new root file system, you can directly use the ps command to view which files are mounted by viewing the /proc/mounts file.
Continue to improve.
There are only two things in the dev directory now. The files in the dev directory correspond to devices and drivers. If we have hundreds of drivers, it will be troublesome to create a dev file for each driver separately. There is a udev mechanism that can automatically create device nodes (/dev/device-node) in the dev directory.
In embedded Linux systems, there is a simplified version of udev called mdev. So how to use this mdev?
There is a mdev.txt in the docs directory, which explains how to use it.
It can be seen that the first and fourth steps are to mount /sys and /dev to sysfs and tmpfs respectively, which are also virtual root file systems.
Mount sys and dev in fstab.
Use rcS to automatically perform the remaining operations. The modified rcS file is as follows.
/proc/sys/kernel/hotplug, hot plug, when the dynamic loading device is inserted into a hot plug device such as a USB flash drive, the kernel calls this hotplug, hotplug points to mdev, so that the kernel will automatically create the corresponding device node.
mdev -s creates the device nodes that the kernel already has.
For detailed instructions, please refer to this article (https://blog.csdn.net/qq_33160790/article/details/79266306)
Recompile the yaffs2 root file system, burn and restart, you can see that there are many more devices in the dev directory.
Many file systems are mounted.
In this way, our minimal root file system is more complete.
If we want to use another root file system format, such as jffs2, this format is generally used on NOR Flash, of course it can also be used on Nand Flash. (I didn't find the zlib compression package, and this file system is not the focus at present. I will talk about the study of jffs2 later)
Mounting the root file system using NFS
Now we have to re-burn the root file system every time we change it, so is there any way to avoid burning it?
Answer: Use NFS to mount the root file system, place the root file system on the server, and when the kernel starts, directly use the root file system on the server as the root file system of the device.
If you want to mount the root file system using NFS, the development board cannot be directly connected to the computer. It needs to be connected to a router or switch, and then the computer is also connected to this router or switch.
Connect the development board to the router, and the computer to the router wirelessly. The development board still does not respond when the network cable is plugged in. After setting the IP address, it is displayed as follows. At this time, pinging the computer can be successful.
Mounting NFS requires two conditions:
The server allows that directory to be mounted by others;
The development board goes to mount that directory.
Set the server to allow mounting
Well, how does the server allow that directory to be mounted by others?
Answer: Through the NFS service, modify the /etc/exports file and add the directory to be mounted to the file.
Then restart the NFS service. The instructions and results are shown in the figure below.
Generally speaking, after doing this, the directory can be mounted by others, but we need to experiment on the server first, and try mounting it to the /mnt directory of the server.
Use the mount command to mount the server. If the mount is successful, it means the server can be mounted.
Set up the development board to mount the server
Previous article:1_5.4.3_Root file system_Building the root file system busybox_P
Next article:1_5.5.1_Character Device Driver Concept Introduction_P
- Popular Resources
- Popular amplifiers
- Python Application Recommender System: Building Recommender Systems Using Deep Learning, NLP, and Graph-Based Technologies
- Deep Learning and Computer Vision in Autonomous Driving
- Build a Home Automation System for 100 (Rui Santos)
- Practical Development of Hongmeng HarmonyOS Mobile Applications (Liu Weiwei)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Qorvo based small PA introduction series
- Watch for free: How to solve the 32.0 GT/s PCIe5 test? Two experts reveal the secrets for you
- GD32L233C-START evaluates the implementation of serial port USART0 printf redirection
- Is there any delay when directly connecting FPGA I/O pins?
- Eat mushrooms and see villains! It's the time of the year again when Yunnan people poison themselves
- Getting Started with Modelsim
- Crosstalk Elimination Technology in Altium Designer
- Evaluation Weekly Report 20220207: How many days are left to apply for Qinheng ch582 and Pingtouge Linux RISC-V kit
- ESD resistance of capacitors
- Date in spring + small flowers blooming in the spring bushes