ZYSJ-RK3399移植armbian
前不久捡垃圾了一块众云世纪的RK3399开发板,感觉是从电梯里面的大屏上拆下来的,做工倒是蛮不错的,各个接口都引出来,非常的完善,开发板自带的是Android7.1系统,想着可以捣鼓来当临时测试的NAS用,这不得比啥树莓派好多了吗?
本文写于2021年,但直达后面才有时间发布,所以文中的部分内容没有勘误过,可能会有问题没有写清楚,可以留言联系我修改。依旧相信RK3399,即使是在RK3568,RK3588等新品出来后,依旧会有很高的市场保有量。
硬件配置的话如下,资料来自官网:ZYSJ-1739A2 (zysj-sz.com):
不过最可惜的大概是,自带的网口居然是百兆的。。。这用来当NAS显然不是很科学,不过好在有USB3.0能外接,也将就用吧,这个开发板我买的时候不到一百块钱,就不要求啥自行车了。因为是RK3399的瑞芯微方案,网上资料是相当多的,找一个合适的Linux系统没啥问题。我选择了armbian,因为资料比较多,在我买这个开发板之前,海鲜市场开了很多低价的TN3399的车,资料也是相当的完善,可惜我看晚了点,全都涨价了,所以才退而求其次买的现在这个。
lanseyujie/tn3399_v3: TN3399_V3 开发板折腾记录 (github.com)
在上面的项目中修改了Linux的设备树来适配TN3399,因为ZYSJ和TN的引脚还是不一样的,直接把系统搬过来用是有问题的,就是配置中的IO冲突了。系统的话就是以TN3399和rock960(Rock960 (Vamrs) - 96Boards)为原型的armbian来适配的。
以下是记录了原厂的Android系统中的引脚定义,可以参考一下:
rk3399_all:/sys/firmware/devicetree/base $ cat /sys/kernel/debug/gpio
GPIOs 0-31, platform/pinctrl, gpio0:
gpio-1 ( |vcc_sd ) out lo
gpio-4 ( |bt_default_wake_host) in lo
gpio-5 ( |power ) in hi
gpio-9 ( |bt_default_reset ) out lo
gpio-10 ( |reset ) out hi
gpio-11 ( |SOUNDS_SPK_EN ) out lo
GPIOs 32-63, platform/pinctrl, gpio1:
gpio-34 ( |int-n ) in hi
gpio-35 ( |camsys_gpio ) out hi
gpio-45 ( |enable ) out hi
gpio-46 ( |vsel ) out lo
gpio-49 ( |vsel ) out lo
gpio-50 ( |USB_HUB_RES ) out hi
gpio-52 ( |GTP_INT_IRQ ) in hi
gpio-54 ( |mpu6500 ) in lo
GPIOs 64-95, platform/pinctrl, gpio2:
gpio-70 ( |vcc5v0_host ) out hi开
gpio-73 ( |enable ) out hi
gpio-74 ( |UART_IC_EN ) out hi
gpio-83 ( |bt_default_rts ) in hi
gpio-90 ( |bt_default_wake ) in lo
gpio-91 ( |SYSTEM_LED ) out lo
GPIOs 96-127, platform/pinctrl, gpio3:
gpio-111 ( |mdio-reset ) out hi
gpio-124 ( |vcc_lcd ) out hi
gpio-125 ( |enable ) out hi
GPIOs 128-159, platform/pinctrl, gpio4:
gpio-135 ( |reset ) out hi
gpio-150 ( |GTP_RST_PORT ) in hi
gpio-153 ( |vbus-5v ) out lo开
gpio-156 ( |hp det ) in hi
gpio-157 ( |SYSTEM_5V_EN ) out hi开
比如 gpio-149对应管脚GPIO4_C5,
此处反着算引脚,要计算的是 gpio-157,那就是:
- 157-128=29
- x*8+y=29
- 3*8+5
- GPIO4_D5
也可以查手册,记得不要数错了。
因为RK3399的资料确实多,我就不多说了。
总之就是,gpio157
没有打开导致一串供电没有启动,在armbian中要让其处于高电平才行。你可以选择修改设备树,或者下面的命令直接手动控制:
echo 157 >/sys/class/gpio/export
echo out >/sys/class/gpio/gpio157/direction
echo 1 >/sys/class/gpio/gpio157/value
# pcfg_output_high
6. GPIO 使用 — Firefly Wiki (t-firefly.com)
如果还是觉得修改设备树来适配比较好的话,可以接着看下面的内容,不过我觉得看到上面的内容就知道下面是啥了:
修改调试串口
先检查一下使用的开发板的调试串口是否可用,不能用的得看情况是否需要修改:
rk3399修改调试串口 - tccxy - 博客园 (cnblogs.com)中记录了uboot与内核的修改方法。
rock960的如下:
/dts-v1/;
#include "rk3399-rock960.dtsi"
/ {
model = "RK3399 ZYSJ Dev Board";
compatible = "vamrs,rock960", "rockchip,rk3399";
chosen {
stdout-path = "serial2:1500000n8";
};
clkin_gmac: external-gmac-clock {
compatible = "fixed-clock";
clock-frequency = <125000000>;
clock-output-names = "clkin_gmac";
#clock-cells = <0>;
};
};
&gmac {
assigned-clocks = <&cru SCLK_RMII_SRC>;
assigned-clock-parents = <&clkin_gmac>;
clock_in_out = "input";
phy-supply = <&vcc3v3_sys>;
phy-mode = "rgmii";
pinctrl-names = "default";
pinctrl-0 = <&rgmii_pins>;
snps,reset-gpio = <&gpio3 RK_PB7 GPIO_ACTIVE_LOW>;
snps,reset-active-low;
snps,reset-delays-us = <0 10000 50000>;
tx_delay = <0x28>;
rx_delay = <0x11>;
status = "okay";
};
&pcie0 {
ep-gpios = <&gpio2 RK_PA2 GPIO_ACTIVE_HIGH>;
};
&pinctrl {
gmac {
rgmii_sleep_pins: rgmii-sleep-pins {
rockchip,pins =
<1 RK_PB2 RK_FUNC_GPIO &pcfg_output_low>;
};
};
pcie {
pcie_drv: pcie-drv {
rockchip,pins =
<2 RK_PA5 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
usb2 {
host_vbus_drv: host-vbus-drv {
rockchip,pins =
<4 RK_PD5 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
};
&usbdrd_dwc3_0 {
dr_mode = "otg";
};
&usbdrd_dwc3_1 {
dr_mode = "host";
};
&vcc3v3_pcie {
gpio = <&gpio2 5 GPIO_ACTIVE_HIGH>;
};
&vcc5v0_host {
gpio = <&gpio4 25 GPIO_ACTIVE_HIGH>;
};
按TN3399教程中的方法准备编译链工具aarch64-linux-gnu-gcc
:
cyqsd@cyqsd-virtual-machine:~$ cd Project/toolchain/
cyqsd@cyqsd-virtual-machine:~/Project/toolchain$ ls
aarch64-linux-gnu bin gcc-linaro-7.5.0-2019.12-linux-manifest.txt include lib libexec share
cyqsd@cyqsd-virtual-machine:~/Project/toolchain$ pwd
/home/cyqsd/Project/toolchain
cyqsd@cyqsd-virtual-machine:~/Project/toolchain$ export PATH=/home/cyqsd/Project/toolchain/bin:$PATH
cyqsd@cyqsd-virtual-machine:~/Project/toolchain$ aarch64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/home/cyqsd/Project/toolchain/bin/../libexec/gcc/aarch64-linux-gnu/7.5.0/lto-wrapper
Target: aarch64-linux-gnu
Configured with: '/home/tcwg-buildslave/workspace/tcwg-make-release_0/snapshots/gcc.git~linaro-7.5-2019.12/configure' SHELL=/bin/bash --with-mpc=/home/tcwg-buildslave/workspace/tcwg-make-release_0/_build/builds/destdir/x86_64-unknown-linux-gnu --with-mpfr=/home/tcwg-buildslave/workspace/tcwg-make-release_0/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gmp=/home/tcwg-buildslave/workspace/tcwg-make-release_0/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gnu-as --with-gnu-ld --disable-libmudflap --enable-lto --enable-shared --without-included-gettext --enable-nls --with-system-zlib --disable-sjlj-exceptions --enable-gnu-unique-object --enable-linker-build-id --disable-libstdcxx-pch --enable-c99 --enable-clocale=gnu --enable-libstdcxx-debug --enable-long-long --with-cloog=no --with-ppl=no --with-isl=no --disable-multilib --enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 --with-arch=armv8-a --enable-threads=posix --enable-multiarch --enable-libstdcxx-time=yes --enable-gnu-indirect-function --with-build-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release_0/_build/sysroots/aarch64-linux-gnu --with-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release_0/_build/builds/destdir/x86_64-unknown-linux-gnu/aarch64-linux-gnu/libc --enable-checking=release --disable-bootstrap --enable-languages=c,c++,fortran,lto --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=aarch64-linux-gnu --prefix=/home/tcwg-buildslave/workspace/tcwg-make-release_0/_build/builds/destdir/x86_64-unknown-linux-gnu
Thread model: posix
gcc version 7.5.0 (Linaro GCC 7.5-2019.12)
cyqsd@cyqsd-virtual-machine:~/Project/toolchain$ arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-none-eabi/10.3.1/lto-wrapper
Target: arm-none-eabi
Configured with: ../configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/lib/include' --mandir='/usr/lib/share/man' --infodir='/usr/lib/share/info' --sysconfdir=/etc --localstatedir=/var --disable-option-checking --disable-silent-rules --libdir='/usr/lib/lib/x86_64-linux-gnu' --libexecdir='/usr/lib/lib/x86_64-linux-gnu' --disable-maintainer-mode --disable-dependency-tracking --mandir=/usr/share/man --enable-languages=c,c++,lto --enable-multilib --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --enable-tls --build=x86_64-linux-gnu --target=arm-none-eabi --with-system-zlib --with-gnu-as --with-gnu-ld --with-pkgversion=15:10.3-2021.07-4 --without-included-gettext --prefix=/usr/lib --infodir=/usr/share/doc/gcc-arm-none-eabi/info --htmldir=/usr/share/doc/gcc-arm-none-eabi/html --pdfdir=/usr/share/doc/gcc-arm-none-eabi/pdf --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --disable-libstdc++-v3 --host=x86_64-linux-gnu --with-headers=no --without-newlib --with-multilib-list=rmprofile,aprofile CFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-arm-none-eabi-hYfgK4/gcc-arm-none-eabi-10.3-2021.07=. -flto=auto -ffat-lto-objects -fstack-protector-strong' CPPFLAGS='-Wdate-time -D_FORTIFY_SOURCE=2' CXXFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-arm-none-eabi-hYfgK4/gcc-arm-none-eabi-10.3-2021.07=. -flto=auto -ffat-lto-objects -fstack-protector-strong' DFLAGS=-frelease FCFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-arm-none-eabi-hYfgK4/gcc-arm-none-eabi-10.3-2021.07=. -flto=auto -ffat-lto-objects -fstack-protector-strong' FFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-arm-none-eabi-hYfgK4/gcc-arm-none-eabi-10.3-2021.07=. -flto=auto -ffat-lto-objects -fstack-protector-strong' GCJFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-arm-none-eabi-hYfgK4/gcc-arm-none-eabi-10.3-2021.07=. -fstack-protector-strong' LDFLAGS='-Wl,-Bsymbolic-functions -flto=auto -Wl,-z,relro' OBJCFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-arm-none-eabi-hYfgK4/gcc-arm-none-eabi-10.3-2021.07=. -flto=auto -ffat-lto-objects -fstack-protector-strong' OBJCXXFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-arm-none-eabi-hYfgK4/gcc-arm-none-eabi-10.3-2021.07=. -flto=auto -ffat-lto-objects -fstack-protector-strong' INHIBIT_LIBC_CFLAGS=-DUSE_TM_CLONE_REGISTRY=0 AR_FOR_TARGET=arm-none-eabi-ar AS_FOR_TARGET=arm-none-eabi-as LD_FOR_TARGET=arm-none-eabi-ld NM_FOR_TARGET=arm-none-eabi-nm OBJDUMP_FOR_TARGET=arm-none-eabi-objdump RANLIB_FOR_TARGET=arm-none-eabi-ranlib READELF_FOR_TARGET=arm-none-eabi-readelf STRIP_FOR_TARGET=arm-none-eabi-strip SED=/bin/sed SHELL=/bin/sh BASH=/bin/bash CONFIG_SHELL=/bin/bash
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 10.3.1 20210621 (release) (15:10.3-2021.07-4)
cyqsd@cyqsd-virtual-machine:~/Project/toolchain$
检查我们的设备树配置:
rk33xx-gpio {
compatible = "rockchip,rk33xx_gpio_init";
pinctrl-names = "default";
pinctrl-0 = <0xd9>;
system_5v_en = <0x3d 0x1d 0x00>;
system_led = <0x3e 0x1b 0x00>;
uart_ic_en = <0x3e 0x0a 0x00>;
usb_hub_res = <0x34 0x12 0x00>;
sounds_spk_en = <0x3c 0x0b 0x01>;
status = "okay";
};
reg = <address1 length1 address2 length2 address3 length3……>
soc {
#address-cells = <2>;
#size-cells = <1>;
serial {
compatible = "xxx";
reg = <0x4600 0x5000 0x100>; /*地址信息是:0x00004600 00005000,长度信息是:0x100*/
};
};
system_led = <0x3e 0x1b 0x00>;
重新编译
cyqsd@cyqsd-virtual-machine:~/Project$ cd arm-trusted-firmware
cyqsd@cyqsd-virtual-machine:~/Project/arm-trusted-firmware$ unset BL31
cyqsd@cyqsd-virtual-machine:~/Project/arm-trusted-firmware$ make CROSS_COMPILE=aarch64-linux-gnu- PLAT=rk3399
Building rk3399
make -C plat/rockchip/rk3399/drivers/m0 BUILD=/home/cyqsd/Project/arm-trusted-firmware/build/rk3399/release/m0
make[1]: Entering directory '/home/cyqsd/Project/arm-trusted-firmware/plat/rockchip/rk3399/drivers/m0'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/cyqsd/Project/arm-trusted-firmware/plat/rockchip/rk3399/drivers/m0'
cyqsd@cyqsd-virtual-machine:~/Project/arm-trusted-firmware$ export BL31=/home/cyqsd/Project/arm-trusted-firmware/build/rk3399/release/bl31/bl31.elf
1.设置ATF(arm-trusted-firmware)
export BL31=/home/cyqsd/Project/arm-trusted-firmware/build/rk3399/release/bl31/bl31.elf
2.u-boot
/home/cyqsd/Project/u-boot/arch/arm/dts
#rk3399_zysj.dts
进入u-boot目录进行编译
/home/cyqsd/Project/u-boot
可以使用make dtb
来提前检查前面的配置是否有语法为问题
gpiochip0: GPIOs 0-31, parent: platform/pinctrl, gpio0:
gpio-4 ( |host-wakeup ) in lo
gpio-7 ( |cd ) in lo ACTIVE LOW
gpio-9 ( |shutdown ) out hi
gpio-10 ( |reset ) out hi ACTIVE LOW
gpiochip1: GPIOs 32-63, parent: platform/pinctrl, gpio1:
gpio-45 ( |sysfs ) out lo
gpiochip2: GPIOs 64-95, parent: platform/pinctrl, gpio2:
gpio-69 ( |vcc3v3-pcie-regulato) out lo
gpio-70 ( |vcc5v0-host-regulato) out hi
gpio-91 ( |device-wakeup ) out hi
gpiochip3: GPIOs 96-127, parent: platform/pinctrl, gpio3:
gpio-111 ( |snps,reset ) out hi ACTIVE LOW
gpiochip4: GPIOs 128-159, parent: platform/pinctrl, gpio4:
gpio-157 ( |yellow:wlan ) out hi
上面的操作一切顺利后,重启的开机报文里面就有下面的信息了100Mbps/Full
:
[ 15.514698] rk_gmac-dwmac fe300000.ethernet eth0: PHY [stmmac-0:00] driver [RTL8211E Gigabit Ethernet] (irq=POLL)
[ 15.526964] rk_gmac-dwmac fe300000.ethernet eth0: No Safety Features support found
[ 15.526985] rk_gmac-dwmac fe300000.ethernet eth0: PTP not supported by HW
[ 15.527416] rk_gmac-dwmac fe300000.ethernet eth0: configuring for phy/rgmii link mode
[ 26.788030] rk_gmac-dwmac fe300000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
[ 26.788096] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
使用ethtool
就可以看到网卡了,不过咋们这个是百兆,感觉比别人的差了不是一点点:
root@TN3399V3:/# ethtool eth0
Settings for eth0:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
Supported pause frame use: Symmetric Receive-only
Supports auto-negotiation: Yes
Supported FEC modes: Not reported
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
Advertised pause frame use: Symmetric Receive-only
Advertised auto-negotiation: Yes
Advertised FEC modes: Not reported
Link partner advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Link partner advertised pause frame use: Symmetric Receive-only
Link partner advertised auto-negotiation: Yes
Link partner advertised FEC modes: Not reported
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
Supports Wake-on: ug
Wake-on: d
Current message level: 0x0000003f (63)
drv probe link timer ifdown ifup
Link detected: yes
如果你的开发板网口还是有问题,可以再参考一下:[ Linux ] 网口相关BUG调试思路_rxpackets一直为0-CSDN博客,还缺了什么。
本文到这里就结束了,RK3399上市多年,市场保有量是蛮大的,低廉的价格和非常不错的性能,让国产工控机作为首选。开发板的安卓固件版本在不断提升,从7.1到11,已经比非常多的手机适配的版本更全了。
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。