在rk3399(rockpi 4b)上运行linux-5.3的mainline内核
由于瑞芯微提供的bsp中的内核版本为4.4,所以各个开发板的厂家提供的长期维护的内核版本也是4.4,
此外gpu的驱动一般分为两部分:一小部分在 Linux 内核中,另外一大部分在 userspace,在 usercapce 的部分向下操作内核中的驱动,向上对应用层提供标准的 OpenGL 接口,
这样各种图形显示相关的应用才能通过标准的 OpenGL API 进行图形渲染加速。但是 mali GPU IP 提供商 Arm 公司只开放了内核部分驱动,而且这部分驱动还没有按照 linux kernel
的规范以 Drm 的框架去实现,所以它无法被 linux mainline 接受,还有一个更重要的部分,usersapce 部分,Arm 没有开源,只是以库的形式提供给购买了 mali GPU 授权的 SOC 厂
商,比如 Rockchip,Amlogic。而且这套代码主要是为 Android 系统设计的,对 Debian、Ubuntu 这种系统的兼容性也不好。
基于以上如果我们想在4.4的内核下去使用mali的驱动,难度比较大,尤其是日后如果想要移植到自己的板子上在没有原厂支持的情况下可以说是非常难的,可控性太差。
不过有一个好消息
有一部分黑客们不满于这种封锁,他们勇于探索,积极尝试,逆向了 Arm 发布的二进制库,然后重写了针对 Arm mali gpu 的开源驱动,最终在 Linux 5.2 发布的时候合并到了 mainline 中:
针对 Mali-400/Mali-450 的驱动叫做 lima,针对 Mali-T6xx / Mali-T7xx / Mali-T8xx GPU 和 GXX 系列的叫做 panfrost。Usersacpe 部分的开源库叫做 mesa,对 mali gpu 的支持从 mesa 19.2
开始。
而且据说是个妹子做到的。。。。。。。。。
这里的测试我是基于linux的mainline 5.3.y的kernel进行的,
首先拉内核的代码
git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
#如果拉取的速度慢的话,可以用小飞机加速git。。
#也可以先从国内的比如说清华源等拉,然后再remote add主线的url
#考虑到vpn的流量我用了后者
zw@zw-pc:~/share/rockchip/rockchip-bsp/linux$ git remote -v
origin https://mirrors.tuna.tsinghua.edu.cn/git/linux.git (fetch)
origin https://mirrors.tuna.tsinghua.edu.cn/git/linux.git (push)
upstream https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git (fetch)
upstream https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git (push)
zw@zw-pc:~/share/rockchip/rockchip-bsp/linux$
#同步完成后
#git branch -a 可以看到很多分支
#切换到remotes/upstream/linux-5.3.y
然后进行内核的配置
#将附件中的配置文件放到内核的arch/arm64/configs目录
#执行
zw@zw-pc:~/share/rockchip/rockchip-bsp/linux$ make ARCH=arm64 rockpi_defconfig
#然后添加gpu的驱动
zw@zw-pc:~/share/rockchip/rockchip-bsp/linux$ make ARCH=arm64 menuconfig CROSS_COMPILE=aarch64-linux-gnu-
#执行编译
zw@zw-pc:~/share/rockchip/rockchip-bsp/linux$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j8
#编译完成后将Image和rk3399-rock-pi-4.dtb放到rockpi的bsp的out/kernel目录并生成新的boot.img
zw@zw-pc:~/share/rockchip/rockchip-bsp$ ./build/mk-image.sh -c rk3399 -t boot -b rockpi4b
#打包system.img,文件系统可以暂时用原来的
zw@zw-pc:~/share/rockchip/rockchip-bsp$ ./build/mk-image.sh -c rk3399 -t system -r /home/zw/swap/work/zq7020_rk3399/softcode/rootfs/ubuntu16.04-rk3399.img
上板启动
U-Boot 2017.09-00013-g6d910b7-dirty (Jan 08 2020 - 15:14:12 +0800)
Model: ROCK PI 4 Board
DRAM: 2 GiB
Relocation Offset is: 7dc09000
PMIC: RK808
pwm-regulator(vdd-center): init 950000 uV
vdd_center 950000 uV
regulator(vdd-center) init 950000 uV
MMC: dwmmc@fe320000: 1, sdhci@fe330000: 0
Using default environment
Warn: can't find connect driver
Failed to found available display route
Warn: can't find connect driver
Failed to found available display route
In: serial
Out: serial
Err: serial
Model: ROCK PI 4 Board
Enable PCIE Power for ROCKPI4 board
rk3399_force_pcie_power_on: trying to force pcie power on
switch to partitions #0, OK
mmc1 is current device
do_rkimg_test found IDB in SDcard
Boot from SDcard
get part misc fail -1
Net: eth0: ethernet@fe300000
Hit any key to stop autoboot: 0
switch to partitions #0, OK
mmc1 is current device
Scanning mmc 1:4...
Found /extlinux/extlinux.conf
pxefile_addr_str = 0x00500000
bootfile = /extlinux/extlinux.conf
Retrieving file: /extlinux/extlinux.conf
reading /extlinux/extlinux.conf
245 bytes read in 5 ms (47.9 KiB/s)
Retrieving file: /hw_intfc.conf
** Unable to read file /hw_intfc.conf **
hw_conf.valid = 0
hw_conf.pwm0 = 2
hw_conf.pwm1 = 2
hw_conf.uart2 = 2
hw_conf.uart4 = 2
hw_conf.spi1 = 2
hw_conf.spi2 = 2
hw_conf.i2c2 = 2
hw_conf.i2c6 = 2
hw_conf.i2c7 = 2
hw_conf.dts_overlay_count = 0
1: kernel-5.3
Retrieving file: /Image
reading /Image
21456904 bytes read in 903 ms (22.7 MiB/s)
append: earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 coherent_pool=1m earlyprintk console=ttyS2,1500000n8 rw root=PARTUUID=b921b045-1d rootfstype=ext4 init=/sbin/init rootwait
Retrieving file: /rk3399-rock-pi-4.dtb
reading /rk3399-rock-pi-4.dtb
54180 bytes read in 6 ms (8.6 MiB/s)
fdt addr 0000000001f00000
fdt magic number edfe0dd0
fdt size 1048576
## Flattened Device Tree blob at 01f00000
Booting using the fdt blob at 0x1f00000
Loading Device Tree to 000000007bcec000, end 000000007bdeefff ... OK
Adding bank: start=0x00200000, size=0x7fe00000
Starting kernel ...
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[ 0.000000] Linux version 5.3.18-dirty (zw@zw-pc) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11-rc1)) #2 SMP Tue Jan 14 15:03:21 CST 2020
[ 0.000000] Machine model: Radxa ROCK Pi 4
[ 0.000000] earlycon: uart8250 at MMIO32 0x00000000ff1a0000 (options '')
[ 0.000000] printk: bootconsole [uart8250] enabled
[ 0.000000] psci: probing for conduit method from DT.
[ 0.000000] psci: PSCIv1.0 detected in firmware.
[ 0.000000] psci: Using standard PSCI v0.2 function IDs
[ 0.000000] psci: MIGRATE_INFO_TYPE not supported.
[ 0.000000] psci: SMC Calling Convention v1.0
[ 0.000000] percpu: Embedded 30 pages/cpu s82728 r8192 d31960 u122880
[ 0.000000] Detected VIPT I-cache on CPU0
[ 0.000000] CPU features: detected: ARM erratum 845719
[ 0.000000] CPU features: detected: GIC system register CPU interface
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 515592
[ 0.000000] Kernel command line: earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 coherent_pool=1m earlyprintk console=ttyS2,1500000n8 rw root=PARTUUID=b921b045-1d rootfstype=ext4 init=/sbin/init rootwait
[ 0.000000] Dentry cache hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[ 0.000000] Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Memory: 2032280K/2095104K available (13566K kernel code, 1690K rwdata, 4132K rodata, 1472K init, 546K bss, 62824K reserved, 0K cma-reserved)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=6, Nodes=1
[ 0.000000] ftrace: allocating 48070 entries in 188 pages
[ 0.000000] rcu: Hierarchical RCU implementation.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=6.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=6
[ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[ 0.000000] GICv3: GIC: Using split EOI/Deactivate mode
[ 0.000000] GICv3: Distributor has no Range Selector support
[ 0.000000] GICv3: no VLPI support, no direct LPI support
[ 0.000000] GICv3: CPU0: found redistributor 0 region 0:0x00000000fef00000
[ 0.000000] ITS [mem 0xfee20000-0xfee3ffff]
[ 0.000000] ITS@0x00000000fee20000: allocated 65536 Devices @7d180000 (flat, esz 8, psz 64K, shr 0)
[ 0.000000] ITS: using cache flushing for cmd queue
[ 0.000000] GICv3: using LPI property table @0x000000007d170000
[ 0.000000] GIC: using cache flushing for LPI property table
[ 0.000000] GICv3: CPU0: using allocated LPI pending table @0x000000007d200000
[ 0.000000] GICv3: GIC: PPI partition interrupt-partition-0[0] { /cpus/cpu@0[0] /cpus/cpu@1[1] /cpus/cpu@2[2] /cpus/cpu@3[3] }
[ 0.000000] GICv3: GIC: PPI partition interrupt-partition-1[1] { /cpus/cpu@100[4] /cpus/cpu@101[5] }
........
[ 18.846079] rockchip-vop ff8f0000.vop: Adding to iommu group 1
[ 18.873883] rockchip-vop ff900000.vop: Adding to iommu group 2
[ 19.112933] rockchip-drm display-subsystem: bound ff8f0000.vop (ops 0xffffff8010e806f8)
[ 19.152875] rockchip-drm display-subsystem: bound ff900000.vop (ops 0xffffff8010e806f8)
[ 19.160250] rockchip-drm display-subsystem: failed to bind ff940000.hdmi (ops 0xffffff8010e83e58): -517
[ 19.171779] rockchip-drm display-subsystem: master bind failed: -517
[ 19.219575] panfrost ff9a0000.gpu: clock rate = 500000000
[ 19.223660] panfrost ff9a0000.gpu: failed to get regulator: -517
[ 19.225353] panfrost ff9a0000.gpu: regulator init failed -517
[ 19.247715] cacheinfo: Unable to detect cache hierarchy for CPU 0
[ 19.289717] brd: module loaded
[ 19.796148] loop: module loaded
[ 19.821759] lkdtm: No crash points registered, enable through debugfs
[ 19.941151] libphy: Fixed MDIO Bus: probed
[ 19.944337] CAN device driver interface
[ 19.980242] rk_gmac-dwmac fe300000.ethernet: PTP uses main clock
[ 19.987491] rk_gmac-dwmac fe300000.ethernet: clock input or output? (input).
[ 19.989511] rk_gmac-dwmac fe300000.ethernet: TX delay(0x28).
[ 19.992179] rk_gmac-dwmac fe300000.ethernet: RX delay(0x11).
[ 19.993926] rk_gmac-dwmac fe300000.ethernet: integrated PHY? (no).
[ 19.999109] rk_gmac-dwmac fe300000.ethernet: cannot get clock clk_mac_speed
[ 20.000923] rk_gmac-dwmac fe300000.ethernet: clock input from PHY
[ 20.008603] rk_gmac-dwmac fe300000.ethernet: init for RGMII
[ 20.021569] rk_gmac-dwmac fe300000.ethernet: User ID: 0x10, Synopsys ID: 0x35
[ 20.024628] rk_gmac-dwmac fe300000.ethernet: DWMAC1000
[ 20.026230] rk_gmac-dwmac fe300000.ethernet: DMA HW capability register supported
[ 20.028765] rk_gmac-dwmac fe300000.ethernet: RX Checksum Offload Engine supported
[ 20.031195] rk_gmac-dwmac fe300000.ethernet: COE Type 2
[ 20.032703] rk_gmac-dwmac fe300000.ethernet: TX Checksum insertion supported
[ 20.035036] rk_gmac-dwmac fe300000.ethernet: Wake-Up On Lan supported
[ 20.037948] rk_gmac-dwmac fe300000.ethernet: Normal descriptors
[ 20.040154] rk_gmac-dwmac fe300000.ethernet: Ring mode enabled
[ 20.041786] rk_gmac-dwmac fe300000.ethernet: Enable RX Mitigation via HW Watchdog Timer
....