1. 程式人生 > 實用技巧 >在rk3399(rockpi 4b)上執行linux-5.3的mainline核心

在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
....