1. Obtain the Linux kernel source code;
2. Modify the kernel so that the root file system rootfs can be mounted correctly (i.e. select the file system format supported by the kernel);
3. Modify the driver and cut the kernel;
4 compile and generate uimage and download experience.
Setting environment variables
Before configuring or compiling the kernel, first determine the target CPU architecture and what tool chain to use during compilation.
Method 1: modify arch and cross in makefile under the root directory_ Compile value.
Method 2: modify the environment variable. Modify the / etc / profile file to take effect for all users. It takes effect immediately after executing source / etc / profile; Or modify ~ /. Bashrc to be effective for the current user (this method is recommended). After modification, execute source ~ /. Bashrc to take effect immediately.
For example: VIM ~ /. Bashrc, add at the end of the file,
Execute instruction: source ~ /. Bashrc
View environment variable: echo $arch
Download and unzip the kernel
The official Linux website ishttps://www.kernel.orgGenerally, chip manufacturers will download a certain version of Linux kernel from the official website and transplant it to their own CPU. Therefore, it can also be transplanted from the Linux kernel provided by the manufacturer to its own products. For example, ATMEL’s at91 series kernel can be used inhttps://github.com/linux4samAddress download.
Download and unzip. There is a problem with the zip software under Ubuntu. A file name too long error may pop up during compilation. You can execute “sudo apt get install p7zip full” and “7za x XXXX. Zip” to unzip.
Configure and compile the kernel
1. Kernel configuration, which supports the file system format. Change the kernel file to sama5 in the / arch / arm / configurations directory_ Copy the defconfig configuration file to the first level directory of the kernel file. Open the command line terminal and enter the “make sama5_defconfig” command to compile it.
2. Execute the make menuconfig command to enter the configuration interface. The file system we use is in ramdisk format. We need to modify the kernel to support the file system. Enter the “general setup” directory and select the “initial ram file system and RAM disk (initramfs / initrd) support” option (press the spacebar to select), as shown below:
3. Modify the version information of the kernel. Enter the “general setup” directory, select the “local version – append TP kernel release” option, and enter the version information.
4. Set the ramdisks compilation format to bzip2: select “general setup” – > “support initial ramdisks compressed using bzip2”.
5 set the number of ramdisks to 1 and the size to 128M.
6. Execute make uimage under the root directory (generate a special image file for uboot. Now the new uboot supports zimage); Generate the uimage file in the arch / arm / boot directory, which is the kernel image file.
After compiling and downloading, you can see that uboot has started the kernel correctly
If you want to know more technical knowledge, scan the code and pay attention to me.