Transplant the target

1. Get the source code of the Linux kernel; 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 the experience.

Setting environment variables

Before configuring or compiling the kernel, determine the target CPU architecture and what toolchain will be used at compile time.

Method 1: by modifying the ARCH and CROSS_COMPILE values in the Makefile under the root directory.

Method 2: Modify the environment variables. Modify the /etc/profile file to take effect for all users. Source /etc/profile takes effect immediately. Or modify ~/.bashrc for the current user (this method is recommended) and execute source ~/.bashrc immediately.

For example: vim ~/.bashrc, at the end of the file,

export ARCH=arm

export CROSS_COMPILE=/usr/local/arm-linux-gcc/bin/arm-linux-

Execute the command: source ~/.bashrc

Check the environment variable: echo $ARCH

Download and extract the kernel

The Linux official website is, and chipmakers typically download a version of the Linux kernel from the official website and port it to their own CPUs. So also can from the manufacturer to provide the Linux kernel transplanted into their own products, such as Atmel AT91 series kernel can be downloaded at address. A File name too long error may pop up at compile time. A File name too long error may appear at compile time. “Sudo apt-get install p7zip-full” and “7za x” can be unzipped.

Configure and compile the kernel

1. Kernel configuration, configuration to support the file system format. Copy the sama5_defconfig config file in the kernel file /arch/arm/configs directory to the first level of the kernel file. Open the command line terminal and type “make sama5_defconfig” to compile it.

2. Execute the make menuconfig command to enter the configuration interface. The file system we use is in the format of ramdisk, so we need to modify the kernel to support this file system. Enter the directory “General Setup” and select the option “Initial RAM filesystem and RAM disk (initramfs/initrd) support” (press spacebar to select), as shown below:

3. Modify the version information of kernel. Enter the directory “General Setup”, select “Local Version – APPEND TP Kernel Release”, and enter the version information.

4. Set the RAMdisks format to Bzip2: select “General Setup” -> “Support initial RAMdisks Compressed with Bzip2”.

Set the number of ramdisks to 1 and the size to 128M.

/ / make uImage: / / make uImage: / / make uImage: / / make uImage: / / make uImage: / / make uImage: / / make uImage: / / make uImage: / / Uimage file is generated in the arch/arm/boot directory, which is the kernel image file.

After compiling and downloading, you can see that the uboot has started the kernel correctly

If you want to know more technical knowledge, scan the code and follow me.