rk3399 ported linux kernel


Reference articles:
1. RK3399 transplants u-boot
2. I.MX6Q-SDB development board transplants ubuntu
3. Rockchip RK3399 - transplants ubuntu 20.04.4 root file system
4. Rockchip RK3399 - transplants uboot 2023.04 & linux 6.3

0.Preface

  In the previous section, the u-boot of rk3399 was transplanted. In this section, we will continue to transplant the Linux kernel. However, before rk3399 transplants kenel, it needs to create a root file system first, so that the relevant information of the root file system can be filled in when generating the kernel image file Image.

1. Transplant the ubuntu root file system

  I won’t go into details about the transplantation steps here, just refer to the previous steps of i.mx6Q transplantation. However, there are some steps that are slightly different, such as not configuring the output of the serial port for the time being, and then booting the board to the u-boot interface and then configuring it. In addition, the prepared root file system needs to be packaged into .img format. Here is a brief description of the packaging steps as a record:
The produced ubuntu root file system is in the ubuntu_base directory, and a new directory ubuntu_ext4_mount is created in the same directory to mount the virtual disk and format it into ext4 format:

mkdir ubuntu_ext4_mount
#挂载虚拟磁盘
sudo dd if=/dev/zero of=ubuntu_ext4.img bs=1M count=1300
#格式化
sudo mkfs.ext4 ubuntu_ext4.img
#挂载img镜像
sudo mount ubuntu_ext4.img ubuntu_ext4_mount/
#拷贝根文件系统
sudo cp ubuntu_base/* ubuntu_ext4_mount/ -af

The count is 2 times the size of the root file system. You can use du -h --max-depth=1the command to view the directory size.
After that, you can uninstall and delete the ubuntu_ext4_mount directory, and then check the created img:

umount ubuntu_ext4_mount
rm -rf ubuntu_rootfs
#用e2fsck修复及检测镜像文件系统
e2fsck -p -f ubuntu_ext4.img
#resize2fs减小镜像文件的大小
resize2fs -M ubuntu_ext4_rootfs.img

2. Transplant Linux

Official website download address: https://www.kernel.org/
Mirror download station: http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/.
Download the latest linux-6.4.7 here and unzip it:

tar -xvf linux-6.4.7.tar.gz

Modify the target platform and cross-compilation chain in the top-level makefile:
Insert image description here
Since the official kernel has only one default configuration, some tailoring is required.

#配置文件存放位置
ll arch/arm64/configs/defconfig
#加载默认配置
make defconfig
#手动裁剪
make menuconfig

1. Support NFS (optional)

NFS is a network file system. If you need to develop the kernel or file system later, it will be more convenient to use NFS. Check it here first.
Insert image description here

2. Configure uevent helper

The purpose of this option is to enable support for the uevent helper program. uevent is a way of communication between the kernel and user space. When the kernel detects a new device, it will generate a uevent to notify the user space, so that the user space can respond to device plug-in and unplug events in a timely manner and handle it accordingly. Among them, the uevent helper program is a user space program that is executed after receiving uevent to complete the hot-plug processing of the device.
Insert image description here

3.Support etx4 file system (supported by default)

Insert image description here

4. Configure DRM driver

DRM, the full name is Direct Rending Manger. It is the current mainstream graphics display framework in Linux. This is configured to support the Ubuntu root file system with desktop in the future.
Insert image description here

5. Cable network card driver

There is an RTL8111 wired network card on the board, which is configured as follows:
Insert image description here
Note: In version 6.4, the STMicroelectronics 10/100/1000/EQOS Ethernet driver was changed to the STMicroelectronics Multi-Gigabit Ethernet driver.

6. Wireless network card driver

Onboard AP6236 wireless network card, configure as follows:

Device Drivers  ---> 
	<*> Broadcom specific AMBA  ---> 
		[*]   Support for BCMA on PCI-host bus (NEW)                                       
		[*]   Support for BCMA in a SoC                                             
		[*]   ChipCommon-attached serial flash support (NEW)                               
		[*]   BCMA Broadcom GBIT MAC COMMON core driver                                    
		[*]   BCMA GPIO driver

Just save the configuration.

3. Device tree

The device tree used by the author here is a decompiled dts file found on the Internet. It can be used directly, so I will skip it first. Just add the dts into the dtb compilation directory.

4. Kernel image file production

After compilation is completed, the kernel image file Image.gz will be generated in the arch/arm64/boot/ folder. Because mkimage packs the image to generate itb file (FIT uImage) according to the description in its file, so you first need to make an its file. Describe the image that needs to be packaged in its file, mainly kernel image, dtb file, etc.
kernel.its:

/*
 * Simple U-Boot uImage source file containing a single kernel and FDT blob
 */
/dts-v1/;
/ {
    
    
	  description = "Simple image with single Linux kernel and FDT blob";
	  #address-cells = <1>;
	  images {
    
    
	          kernel {
    
    
	                  description = "Vanilla Linux kernel";
	                  data = /incbin/("arch/arm64/boot/Image.gz");
	                  type = "kernel";
	                  arch = "arm64";
	                  os = "linux";
	                  compression = "gzip";
	                  load = <0x280000>;
	                  entry = <0x280000>;
	                  hash-1 {
    
    
	                          algo = "crc32";
	                  };
	                  hash-2 {
    
    
	                          algo = "sha1";
	                  };
	          };
	
	         fdt {
    
    
	                  description = "Flattened Device Tree blob";
	                  data = /incbin/("arch/arm64/boot/dts/rockchip/rk3399_sw799.dtb");
	                  type = "flat_dt";
	                  arch = "arm64";
	                  compression = "none";
	                  load = <0x8300000>;
	                  entry = <0x8300000>;
	                  hash-1 {
    
    
	                          algo = "crc32";
	                  };
	                  hash-2 {
    
    
	                          algo = "sha1";
	                  };
	          };
	
	  };
	
	  configurations {
    
    
	          default = "conf-1";
	          conf-1 {
    
    
	                  description = "Boot Linux kernel with FDT blob";
	                  kernel = "kernel";
	                  fdt = "fdt";
	          };
	  };
};

Then copy the mkimage tool under the u-boot-2023.07/tools/ path and compile it using the mkimage tool:

cp u-boot-2023.07/tools/mkimage linux-6.4.7/
./mkimage -f kernel.its kernel.itb

5. Burning

All relevant files have been produced. If you do not need to develop functions under u-boot, you can use the u-boot produced in the previous section. If necessary, since the newer version of u-boot is also divided into u-boot + device tree dtb, when compiling u-boot, just specify the relevant device tree as the device tree of your own board for compilation.
rk3399 burning address:

idbloader.img     --->     eMMC的0x40扇区
u-boot.itb        --->     0x4000扇区
kernel.itb        --->     0x8000扇区
ubuntu_ext4.img   --->     0x40000扇区

In addition to the above files, rk3399 also needs a rk3399_loader_v1.24.126.bin file. This file will be loaded into the internal sram when the chip starts to initialize basic peripherals such as onboard memory. This file can be downloaded from the official rockchip website.
There are two burning tools. One is to use rockchip's official RKDevTool, which needs to be run in a windows environment. The other is to use rkdeveloptool, which can be burned using the command line under Linux. For specific usage methods, please refer to this article . This is the method I use. Enter the chip into Loader mode or Maskrom mode, and then use the following command to program the corresponding file to the board:

rkdeveloptool db rkxx_loader_vx.xx.bin
rkdeveloptool wl 0x40 idbLoader.img
rkdeveloptool wl 0x4000 uboot.itb
rkdeveloptool wl 0x8000 boot.itb
rkdeveloptool wl 0x40000 ubuntu_ext4.img

6. Summary

The corresponding GPU driver is not enabled in the kernel made by the author, so subsequent use of the desktop display will cause lag, high CPU usage, and serious heat generation. So in the end, the author still used the armbian system transplanted by the boss (it feels so good to lie down). The corresponding image and tool download addresses are attached here . If it is the same SW799 board, you can use the corresponding image for burning. There are also some other boards and some simple tutorials here, you can also learn from them. I’ll stop playing with the hardware here first, and then I’ll find some small embedded demos to try out.

Guess you like

Origin blog.csdn.net/weixin_45682654/article/details/132009195