Rockchip | Rockchip Kernel的获取与构建

1 下载Kernel

可以 github 克隆 rockchip 内核存储库,它是从基于 kernel 4.4:

git clone https://github.com/rockchip-linux/kernel.git

2 支持的SoCs和Devices

Rockchip kernel 4.4 支持:

RK3036, RK3066, RK312X, RK3188, RK322X,RK3288RK3328, RK3368, RK3399, PX30


3 内核配置与构建

在 Linux OS 平台上使用 rockchip_linux_defconfig。

对于ARM v7:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- rockchip_linux_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4

对于ARM V8:

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- rockchip_linux_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j4

执行以上命令构建成功后,会输出 Image/zImage 与 dtb 文件,以提供启动 Linux 发行版。

Rockchip RKIMG格式镜像

RKIMG是Rockchip根据Android引导镜像定制的格式,通常只供内核开发人员使用。它由Rockchip U-Boot提供支持。

例如使用一下命令构建 rk3399-evb:

make rk3399-evb.img

输出如下所示,boot.img 是带有 rockchip header 的 ramdisk,kernel.img 是带有 rockchip header的 zImage/Image,resource.img 是 dtb 和 带有 rockchip header的启动 logo。

kernel/
├── boot.img
├── kernel.img
└── resource.img

4 安装Boot/kernel到Linux发行版

如果在发行版中使用 U-Boot 启动,需要为 U-boot 创建一个引导分区,其中包含 kernel 镜像和 dtb。

mkdir boot
cp arch/arm64/boot/dts/rockchip/rk3399-evb.dtb boot/rk3399.dtb
cp arch/arm64/boot/Image boot/

增加 extlinux/extlinux.conf 文件到发行版 boot 目录。

mkdir boot/extlinux
vi boot/extlinux/extlinux.conf
label rockchip-kernel-4.4
    kernel /Image
    fdt /rk3399.dtb
    append earlycon=uart8250,mmio32,0xff1a0000 root=PARTUUID=B921B045-1D rootwait rootfstype=ext4 init=/sbin/init

对于armv7:

label rockchip-kernel-4.4
    kernel /zImage
    fdt /rk3288.dtb
    append earlyprintk console=ttyS2,1500000n8 rw root=PARTUUID=69dad710-2c rootwait rootfstype=ext4 init=/sbin/init

需要更改debug UART的基址,即主板的 root 分区。

对于根文件系统分区和引导 flash 的地方,请参考 rockchip Linux parttion definition

在所有这些文件完全准备好之后,将文件写入引导分区。

对于armv8(rk3399、rk3328),文件夹树如下:

boot
├── extlinux
│   └── extlinux.conf
├── Image
└── rk3399-evb.dtb

对于armv7(rk3288),rootfs是可选的,而kernel 通常使用压缩的 zImage:

boot_rk3288/
├── extlinux
│   └── extlinux.conf
├── rk3288-evb-rk808.dtb
├── rootfs.cpio.gz
└── zImage

4.1 生成ext2fs引导分区

genext2fs:

genext2fs -b 32768 -B $((32*1024*1024/32768)) -d boot/ -i 8192 -U boot_rk3399.img

根据 Rockchip 的分区定义,还需要 flash 这个镜像到偏移地址是 0x8000 的引导分区。

4.2 生成fatfs引导分区

4.2.1 在fatfs中生成boot.img

使用以下命令生成 fatfs 格式的 boot.img:

dd if=/dev/zero of=boot.img bs=1M count=32
sudo mkfs.fat boot.img
mkdir tmp
sudo mount boot.img tmp/
cp -r boot/* tmp/
umount tmp

然后 flash 这个镜像到偏移地址是 0x8000 的引导分区。

4.2.2 通过U-Boot升级boot.img

在 flash 和引导 U-Boot 之后,从默认分区表中写入 gpt 表:

gpt write mmc 0 $partitions
gpt verify mmc 0 $partitions

连接目标板到 PC ,接着启动通过 ums 命令:

ums 0 mmc 1:6

之后应该能够看到设备连接到 PC,然后格式化数据并将数据复制到分区(例如dev/sdb6)。

sudo mkfs.fat /dev/sdb6
cp -r boot/* /media/machine/9F35-9565/

4.3 从U-Boot引导

如果使用 genext2fs 来生成boot.img,需要在 U-Boot 命令行中写入 gpt 表:

gpt write mmc 0 $partitions

然后从 eMMC 引导或者重启:

boot

如果正常执行,会看到类似以下 U-Boot 日志:

switch to partitions #0, OK
mmc0(part 0) is current device
Scanning mmc 0:6...
Found /extlinux/extlinux.conf
Retrieving file: /extlinux/extlinux.conf
205 bytes read in 82 ms (2 KiB/s)
1:      upstream-4.10
Retrieving file: /Image
13484040 bytes read in 1833 ms (7 MiB/s)
append: earlycon=uart8250,mmio32,0xff1a0000 console=ttyS2,1500000n8 rw root=PARTUUID=B921B045-1D rootwait rootfstype=ext4 init=/sbin/init
Retrieving file: /rk3399.dtb
61714 bytes read in 54 ms (1.1 MiB/s)
## Flattened Device Tree blob at 01f00000
   Booting using the fdt blob at 0x1f00000
   Loading Device Tree to 000000007df14000, end 000000007df26111 ... OK

Starting kernel ...

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值