According to Unix conventions, any object (including devices) in a Linux system is usually considered a file. The root file system is the starting point of all files and device nodes, and it is the key to whether the system can start normally. This article will introduce in detail how to use the Busybox tool set to create a simple root file system, namely the Cramfs root file system.
2 Development Platform Introduction
The development system adopts the host + target board development mode, and the target board and the host communicate through serial lines and Ethernet cables. The host uses: PC + Red Hat 9 under VMware6.0 virtual machine Target board: FS2410 experimental development board developed by Shenzhen Youlong Company: Its main parameters: CPU: Samsung S3C2410, main frequency 203MHz; memory: 64M bytes; NOR Flash: 2M bytes (SST39VF1601); NAND Flash: 64M bytes (K9F1208); embedded Linux version: Linux2.4.18
After the root file system is generated, use the Boot Loader to burn it into partition 2 of the NAND Flash of the development board and run it (its address is: offset 0x200000, size 0x1e00000).
3 Basic structure of the root file system
The top-level directories of the embedded Linux root file system have their own special usage and purpose. Generally speaking, the root file system of an embedded Linux system should contain the following:
(1) The minimum directories that can ensure that most applications in the embedded Linux system can run normally include /bin /dev /etc /lib /proc /sbin /usr /tmp /var. If the user needs to provide an expandable environment for multiple users, the following directories must also be created: /home /mnt /opt /root.
(2) Basic link libraries required for the root file system: Glibc and uClibc.
(3) Basic system configuration files: rcS, inittab, fstab, linuxrc and other script files
(4) Basic device files: /dev/tty0 /dev/ttyS0 /dev/console
(5) Basic applications: such as cd, ls, mv, cp, etc.
4 Use Busybox to create a Cramfs root file system
4.1 Introduction to Cramfs
Cramfs (Compressed Rom File System) is a file system with only the most basic features that Linux Torvalds participated in developing when he was working at Transmeta. It is a new read-only file system designed for Linux kernel versions after 2.4. It uses zlib compression, and the compression ratio can generally reach 1:2, but it can still achieve efficient random reading. In Linux systems, directories that do not need to be modified frequently are usually compressed and stored, and the compressed files are decompressed when the system boots. Because Cramfs does not affect the system's file reading speed and is a highly compressed file system. Therefore, it is widely used in embedded systems.
In an embedded environment, both memory and external storage resources need to be used sparingly. If you use the RAMDISK method to use the file system, then after the system is running, you must first decompress the image file on the Flash into the memory and build the RAMDISK environment before you can start running the program. But it also has a fatal weakness. Under normal circumstances, the same code not only occupies space in the Flash (in a compressed form), but also occupies a larger space in the memory (in a decompressed form), which violates the requirement of saving resources as much as possible in an embedded environment.
The use of Cramfs file system can solve this problem well. Cramfs is a compressed file system. It does not need to decompress all the contents of the file system into the memory at once. Instead, when the system needs to access data at a certain location, it immediately calculates the location of the data in Cramfs, decompresses it into the memory in real time, and then obtains the data that needs to be read in the file system by accessing the memory. The decompression in Cramfs and the storage location of the data in the memory after decompression are maintained by the Cramfs file system itself. Users do not need to understand the specific implementation process. Therefore, this method enhances transparency, which is convenient for developers and saves storage space. Therefore, we chose to use this simple Cramfs file system to transplant the root file system during development.
4.2 Introduction to Busybox
Busybox is a single executable implementation of standard Linux tools. Busybox includes some simple tools, such as cat and echo, as well as some larger and more complex tools, such as grep, find, mount, and telnet. Some people call Busybox the Swiss Army Knife of Linux tools. Simply put, Busybox is like a large toolbox that integrates and compresses many Linux tools and commands. Although these tools in Busybox are simplified compared to GNU tools, they are very practical. Busybox is designed with full consideration of special working environments with limited hardware resources. It adopts a modular design, and it uses a configuration menu similar to the Linux kernel configuration menu, making configuration and tailoring quite simple. This feature of Busybox makes it very suitable for embedded system applications. Almost all embedded Linux uses Busybox as a tool. At the same time, the installation script of Busybox makes it easy to build a Linux root file system based on Busybox. This article uses the powerful tool set Busybox to create a Cramfs root file system.
4.3 Configure Busybox
The source code of Busybox can be downloaded from the official website http://www.busybox.net/. We use the source code package busybox-1.00-pre10.tar.bz2 provided by Shenzhen Youlong Company. Note that the newer the version, the better. If the new version cannot be started normally in the target board after compilation, you can try to return to the older version. We used busybox-1.1.3 at the beginning of the development process, and the resulting root file system could not be started normally on fs2410. Switching back to busybox-1.00-pre10 can easily solve this problem.
First, copy busybox-1.00-pre10.tar.bz2 to the user's home directory: home/jixiang (you can set the directory where busybox is copied to).
[root@mynet jixiang]# cd /home/jixiang
[root@mynet jixiang]# tar vxjf busybox-1.00-pre10.tar.bz2
[root@mynet jixiang]# cd busybox-1.00-pre10
[root@mynet busybox-1.00-pre10]# make menuconfig
Enter the configuration menu interface, and make the following configuration:
(1) In General Configuration, be sure to select the "Support for devfs" option. The new version of Busybox has removed this option, but it should be possible to add it by modifying the configuration file.
Figure 1 Configuration support device file system interface
(2) In the Build Options option, select "Static Library" and set the PREFIX of the cross-compilation tool. The path of the cross-compilation tool I use is: /usr/local/arm/3.3.2/bin. (The specific situation depends on the different cross-compilation environment paths of the host machine.
Figure 2 Configuration static library interface
(3) In the Init Utilities option, "Support reading an inittab file" should be selected so that you can initialize according to your own inittab file; "Support running init from within an initrd" should be selected, otherwise you will be prompted with a very confusing prompt "/bin/sh: can't access tty; job control turned off", although you can enter the console command line.
Figure 3 Script file configuration interface
(4) Another Bourne-like Shell →Choose your default shell (ash) →, here you should select the default shell: ash, otherwise sh will not be generated and the script file cannot be interpreted.
Figure 4 Shell configuration
(5) Other configurations can be configured according to your own development needs.
4.3 Compile and install Busybox
After the configuration is complete, exit and save (it is best to back up the .config file for later use), then start generating and execute make TARGET_ARCH=arm; TARGET_ARCH here is required.
[root@mynet busybox-1.00-pre10]# make TARGET_ARCH=arm
[root@mynet busybox-1.00-pre10]# make install
Busybox will create three subdirectories, bin, sbin, and usr, and a link file, linuxrc, under the default PREFIX directory - install.
4.4 Prepare to generate cramfs file system
(1) Create a folder rootfs, copy the bin, sbin, and usr directories generated in the _install directory to rootfs, and create other subdirectories in the rootfs directory. Execute the command mkdir dev etc home lib mnt proc sys tmp var to create the corresponding folders, and then create the init.d folder under etc.
(2) Prepare the startup files inittab, fstab, linuxrc, and rcS. Inittab and fstab are placed in the etc directory, rcS is placed in the etc/init.d/ directory, and linuxrc is placed in the rootfs directory.
(3) Writing a simple configuration file
linuxrc file:
#!/bin/sh
echo "mount /etc as ramfs"
/bin/mount -f -t cramfs -o remount,ro /dev/bon/2 /
/bin/mount -t ramfs ramfs /var
/bin/mkdir -p /var/tmp
/bin/mkdir -p /var/run
/bin/mkdir -p /var/log
/bin/mkdir -p /var/lock
/bin/mkdir -p /var/emptymk
#/bin/mount -t usbdevfs none /proc/bus/usb
exec /sbin/init
rcS file:
#!/bin/sh
/bin/mount –a
fstab file:
none /proc proc defaults 0 0
none /dev/pts devpts mode=0622 0 0
tmpfs /dev/shm tmpfs defaults 0 0
Note that the above files should have execution permissions. You can use chmod 755 to modify their permissions.
4.5 Generate Cramfs root file system image
We use the cramfs-1.1.tar.gz source package provided by Youlong to generate the root file system image.
After decompression, put mkcramfs in the /bin directory of the host Red Hat9.
Go to the parent directory of the rootfs directory and execute: mkcramfs rootfs test.cramfs
5 Download and run test.cramfs
Download test.cramfs to the file partition in the nand flash of the Youlong FS2410 development board through dnw (its address is: offset 0x200000, size 0x1e00000), and the file system starts normally. The startup interface is as follows:
NET: Registered protocol family 1
NET: Registered protocol family 17
VFS: Mounted root (cramfs filesystem) readonly.
Mounted devfs on /dev
Freeing init memory: 124K
mount /etc as ramfs
mount: /etc/mtab: No such file or directory
mount: /etc/mtab: Read-on
mount: /etc/mtab: No such file or directory
mount: /etc/mtab: Read-on
mount: /etc/mtab: Read-on
mount: /etc/mtab: Read-on
mount: /etc/mtab: Read-on
Please press Enter to activate this console.
BusyBox v1.00-pre10 (2009.09.01-12:23+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.
/ # ls
bin etc lib mint bin temp var
dev home linuxrc proc sys usr
/ #
Previous article:ARM assembly and C mixed programming marquee program
Next article:Marquee experiment implemented by arm assembly
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Ultrasound patch can continuously and noninvasively monitor blood pressure
- Ultrasound patch can continuously and noninvasively monitor blood pressure
- Europe's three largest chip giants re-examine their supply chains
- Europe's three largest chip giants re-examine their supply chains
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- Design of automotive LIN communication simulator based on Renesas MCU
- When will solid-state batteries become popular?
- Adding solid-state batteries, CATL wants to continue to be the "King of Ning"
- The agency predicts that my country's public electric vehicle charging piles will reach 3.6 million this year, accounting for nearly 70% of the world
- Using C language for PIC microcontroller (I)
- Photoelectric switch position coding measurement and control technology and its application
- EEWORLD University ---- Robotics
- EEWORLD University Hall - Wildfire uCOS-III Kernel Implementation and Application Development Practical Guide
- mDNS http server redundant array
- Circuit design, simulation and PCB design - from analog circuits, digital circuits, RF circuits, control circuits to signal integrity...
- [Atria AT32WB415 Series Bluetooth BLE 5.0 MCU] Bluetooth initial test
- High-density packaging progress
- [Qinheng RISC-V core CH582] Constant temperature control heater
- The Raspberry Pi you want is here. Apply now!