Open source address: github.com/Mculover666… .

1. Compile and install BusyBox

System environment:

  • Ubuntu 18.04 64 – bit
  • Arm – Linux – GCC 4.4.3

Download 1.1.

Busybox.net/ is a quick download.

Version 1.20.2 is used here, at the bottom of the download page.

After downloading, unzip it:

The tar - JXF busybox - 1.20.2. Tar..bz2Copy the code

Compiled tests:

  • Version 1.20.2 was compiled successfully
  • 1.27.2 failed to compile
  • Version 1.30.1 failed to compile

1.2. Configure and compile

Before compiling busyBox, you need to set up the compilation tool chain:

cdBusybox 1.20.2 / make menuconfigCopy the code

Busybox Settings:



Go to Build Options:



Find the Cross Compiler prefix and change it toarm-linux-:



Exit and save the configuration.

Compile 1.3.

make
Copy the code



Once compiled, busyBox is used to build the root file system.

2. Create a root file system

To make a root file system image file is to store all the contents of the directory we made in the previous section into a file in a certain format. This file can be directly written to the memory. When the system is started and the device is attached, the same contents as the original directory can be read.

2.1. Install the busybox

First create a new installation directory fs_mini_mdev_test to install busyBox, then specify this directory to install busybox using the CONFIG_PREFIX environment variable:

make install CONFIG_PREFIX=/home/ubuntu/busybox/fs_mini_mdev_test
Copy the code



Once the installation is complete, there is a directory for basic commands in the installation directory, as shown in the following figure:

2.2. Install the library

2.2.1. Find compiler libraries

First find the location of the cross editor:

echo $PATH
Copy the code



Then go to the directory:

cdThe/usr/arm - Linux - toolchains4.4.3 / bincd.Copy the code



Find the library file used by the cross-compiler:

find -name lib
Copy the code



Sys-root: sys-root: sys-root: sys-root: sys-root

  • ./arm-none-linux-gnueabi/sys-root/usr/lib

  • ./arm-none-linux-gnueabi/sys-root/lib

2.2.2. Copy library files

Copy sys-root/lib:

cd~ mkdir /home/ubuntu/busybox/fs_mini_mdev_test/lib cp -d The/usr/arm - Linux - toolchains4.4.3 / arm - none - Linux - gnueabi/sys - root/lib / * so * / home/ubuntu/busybox/fs_mini_mdev_test/lib /Copy the code

/usr/lib/sys-root/usr/lib

cd~ mkdir /home/ubuntu/busybox/fs_mini_mdev_test/usr/lib cp -d The/usr/arm - Linux - toolchains4.4.3 / arm - none - Linux - gnueabi/sys - root/usr/lib / * so * /home/ubuntu/busybox/fs_mini_mdev_test/usr/lib/Copy the code

2.3. Build the etc directory

The contents of the etc directory depend on the program you want to run, so only three files are created in this tutorial:

  • etc/inittab
  • etc/init.d/rcS
  • etc/fsttab

The init process creates other child processes from the inittab file, such as calling script files to configure IP addresses, attaching other file systems, and finally starting the shell.

  • ① Create the etc/inittab file

Create an etc directory in the fs_mini_mdev_test/ directory, and then create an inittab file, as shown in the inittab file example in Busybox.

# /etc/inittab
::sysinit:/etc/init.d/rcS
console::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
Copy the code
  • ② Create the /etc/init. d/rcS file

Create this file in the etc directory, which is a script file to which you can add commands that need to be executed automatically to edit the following:

#! /bin/sh
mount -a
mkdir /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
Copy the code

Add executable permission, otherwise the startup will prompt no permission:

sudo chmod +x init.d/rcS
Copy the code

Network adapters are not supported and IP addresses are not configured.

  • ③ Create the etc/fstab file

The content of the file indicates the file system to be mounted after the mount -a command is executed. The content is as follows:

#device mount-point type options dump fsck order
proc    /proc   proc    defaults        0       0
tmpfs   /tmp    tmpfs   defaults        0       0
sysfs   /sys    sysfs   defaults        0       0
tmpfs   /dev    tmpfs   defaults        0       0
Copy the code

2.4. Build the dev directory

Init process uses two device files to create:

cd fs_mini_mdev_test/
mkdir dev
cd dev
sudo mknod console c 5 1
sudo mknod null c 1 3
Copy the code

2.5. Create other directories

Other directories can be empty. Run the following command to create them:

cd fs_mini_mdev_test/
mkdir proc mnt tmp sys root
Copy the code

3. Create a JFFS2 image file

The next step is to make the root file system directory fs_mini_mdev_test into a file system image. Since the Linux kernel is not configured to support Yaffs2, use JFFs2 to test it.

3.1. Install the mtD-utils tool

sudo apt-get install mtd-utils
Copy the code

3.2. Make a JFFS2 file system

First make sure that at one level above the file directory:



Execute production commands:

mkfs.jffs2 -n -s 2048 -e 128KiB -d fs_mini_mdev_test -o fs_mini_mdev_test.jffs2
Copy the code

These parameters mean:

  • -n: Do not put a clear mark on every erase block;
  • -s 2048: Specifies a page size of 2048 bytes;
  • -e 128KiB: specifies an erasing sector with a size of 128KB;
  • -d fs_mini_mdev_test: Specifies the root file system directory to package.
  • -o fs_mini_mdev_test.jffs2: specifies the name of the output image file.

Finished:

3.3. Burn test

Reference tutorial: uboot study notes | uboot 2012.04 to 10 – transplantation JZ2440 (burning the Linux kernel, burning yaffs2 filesystem).

Download the file system image to the Windows host, save it to the TFTP server directory, and then use uboot to burn nand Flash in the development board:

tftp 30000000 fs_mini_mdev_test.jffs2
nand erase.part filesystem
nand write.jffs2 30000000 260000 678c24
Copy the code



Then set the environment variable:

Set bootargs console=ttySAC0,115200 root=/dev/ mtdBlock3 RootFstype =jffs2 saveenvCopy the code



Restart the development board and test whether it can be mounted successfully:

reset
Copy the code

3.4. Problem solving

The problem is that the Embedded Application Binary Interface (EABI) is used by the compiler when it is compiled, but configuration is not enabled in the kernel, so the kernel indicates that this is an invalid instruction.

The solution is to configure the kernel to support this interface.

Go to the kernel directory:

make menuconfig
Copy the code

Access Kernel Features:



Select this item in the picture:

Then exit, save the Settings, and recompile the kernel:

make uImage
Copy the code

After compiling successfully, the kernel size is 2361KB, which exceeds the partition of 2MB, so it cannot be burned to Nand Flash, instead, it can be directly downloaded to memory using TFTP and run. In the following article, the kernel size can be burned to NAND Flash only after it is cut <2MB!

Rewrite the kernel and start it for testing:

tftp 30000000 uImage
bootm 30000000
Copy the code

After the startup, you can see that the Linux kernel is successfully started, the root file system is successfully mounted, and the Linux command line is successfully entered:

Welcome to subscribe to my wechat official account: “McUlover666”.