平台:RK3399
板型:NanoPC-T4
Host:Ubuntu 16.04
Kernel:https://github.com/friendlyarm/kernel-rockchip
u-boot:https://github.com/friendlyarm/uboot-rockchip
本文档基于友善NanoPC-T4制作,主要是为了记录做Linux板级驱动全过程,以备忘。
1、在drivers/soc
建立自己的板目录,在这里我创建venkeeboard
cd drivers/soc
mkdir venkeeboard
2、在drivers/soc/venkeeboard
目录建立自己的一个Kconfig
文件
cd venkeeboard
vi Kconfig
内容如下
#
# Machine drivers
#
if ARCH_ROCKCHIP
config MACH_VENKEEBOARD # 这个在编译dts时用到
bool "Venkee board Machine"
default y
endif
3、复制原厂的board.c
文件到drivers/soc/venkeeboard
目录
cp ../friendlyelec/board.c .
vi board.c
修改代码片段
static const struct of_device_id board_sys_of_match[] = {
{ .compatible = "venkee,board" }, // 设置自己的compatible,跟一会修改的dts的compatible保持一致
{}
};
MODULE_DEVICE_TABLE(of, board_sys_of_match);
static struct platform_driver board_sys_driver = {
.probe = board_sys_probe,
.driver = {
.name = "venkee-board",
.of_match_table = board_sys_of_match,
},
};
static int __init board_sys_init(void)
{
return platform_driver_register(&board_sys_driver);
}
device_initcall(board_sys_init);
4、复制原厂的Makefile
文件到drivers/soc/venkeeboard
目录
cp ../friendlyelec/Makefile .
vi Makefile
内容修改为
obj-$(CONFIG_MACH_VENKEEBOARD) += board.o
5、修改drivers/soc
目录下的Kconfig
cd ..
vi Kconfig
增加内容
source "drivers/soc/venkeeboard/Kconfig" # 使用自己建立的Kconfig
6、修改drivers/soc
目录下的Makefile
vi Makefile
增加内容
obj-$(CONFIG_MACH_VENKEEBOARD) += venkeeboard/
1、进入arch/arm64/boot/dts/rockchip
目录,执行复制操作
cd ../../arch/arm64/boot/dts/rockchip/
cp rk3399-nanopi4-cifisp.dtsi rk3399-venkee-cifisp.dtsi
cp rk3399-nanopi4-common.dtsi rk3399-venkee-common.dtsi
cp rk3399-nanopi4-rev00.dts rk3399-venkee-rev00.dts
2、修改rk3399-venkee-common.dtsi
文件
vi rk3399-venkee-common.dtsi
原来的内容:
#define NANOPI4_RK_CIF_ISP10
#include "rk3399-nanopi4-cifisp.dtsi"
/ {
model = "FriendlyElec boards based on Rockchip RK3399";
compatible = "friendlyelec,nanopi4",
"rockchip,rk3399";
......
mach: board {
compatible = "friendlyelec,board";
machine = "NANOPI4";
hwrev = <255>;
model = "NanoPi 4 Series";
};
......
};
修改后的内容:
#define VENKEE_RK_CIF_ISP10
#include "rk3399-venkee-cifisp.dtsi"
/ {
model = "Venkee pads based on Rockchip RK3399"; // model需要在rev00具体dts重新定义
compatible = "venkee,pads",
"rockchip,rk3399"; // compatible需要在rev00具体dts重新定义
......
mach: board {
compatible = "venkee,pad"; // 这个需要跟board.c文件里面的compatible保持一致
machine = "Pad Machine"; // machine需要在rev00具体dts重新定义
hwrev = <255>; // hwrev需要在rev00具体dts重新定义
model = "Pad Model"; // model需要在rev00具体dts重新定义
};
......
};
3、修改rk3399-venkee-cifisp.dtsi
文件
原来的内容:
#if defined(NANOPI4_RK_CIF_ISP10)
修改后的内容
#if defined(VENKEE_RK_CIF_ISP10)
4、修改rk3399-venkee-rev00.dtsi
文件
原来的内容
#include "rk3399-nanopi4-common.dtsi"
/ {
model = "FriendlyElec NanoPC-T4";
compatible = "friendlyelec,nanopc-t4", "rockchip,rk3399";
};
&mach {
hwrev = <0>;
model = "NanoPC-T4";
};
修改后的内容
#include "rk3399-venkee-common.dtsi"
/ {
model = "Venkee Pad1S"; // 重新定义model
compatible = "venkee,pad1s", "rockchip,rk3399"; // 重新定义compatible
};
&mach {
hwrev = <0>; // 重新定义hwrev
machine = "Pad1S"; // 重新定义machine
model = "Pad 1 Series"; // 重新定义model
};
5、修改Makefile
vi Makefile
原来的内容
ifeq ($(CONFIG_MACH_NANOPI4),y)
dtb-$(CONFIG_ARCH_ROCKCHIP) += \
rk3399-nanopi4-rev00.dtb \
rk3399-nanopi4-rev01.dtb \
rk3399-nanopi4-rev04.dtb \
rk3399-nanopi4-rev06.dtb
else
......
endif
always := $(dtb-y)
subdir-y := $(dts-dirs)
clean-files := *.dtb
修改后的内容
ifeq ($(CONFIG_MACH_VENKEEBOARD),y) // 这里使用了Kconfig配置的变量
dtb-$(CONFIG_ARCH_ROCKCHIP) += \
rk3399-venkee-rev00.dtb
else
......
endif
always := $(dtb-y)
subdir-y := $(dts-dirs)
clean-files := *.dtb
1、进入arch/arm64/configs
目录
cd ../../../configs/
2、复制nanopi4_linux_defconfig
文件为venkee_linux_defconfig
cp nanopi4_linux_defconfig venkee_linux_defconfig
3、修改顶层架构Makefile
cd ../
vi Makefile
增加生成image的目标(参照nanopi4)
ifeq ($(CONFIG_MACH_VENKEEBOARD),y)
DTBS := rockchip/rk3399-venkee-rev*.dtb
PHONY += venkee-images venkee-bootimg
venkee-images: dtbs kernel.img rklogo
$(Q)scripts/resource_tool --dtbname $(objtree)/arch/arm64/boot/dts/$(DTBS) $(LOGO) $(LOGO_KERNEL)
@echo ' Image: resource.img (with $(DTBS) $(LOGO) $(LOGO_KERNEL)) is ready'
venkee-bootimg: venkee-images
$(Q) if [ -x $(srctree)/scripts/mkbootimg ]; then \
$(srctree)/scripts/mkbootimg \
--kernel $(objtree)/arch/arm64/boot/Image \
--second resource.img \
-o boot.img && \
echo ' Image: boot.img (with Image resource.img) is ready'; \
$(srctree)/scripts/mkbootimg \
--kernel $(objtree)/arch/arm64/boot/Image.lz4 \
--second resource.img \
-o zboot.img && \
echo ' Image: zboot.img (with Image.lz4 resource.img) is ready'; \
fi
endif
1、进入源代码顶层目录并生成构建文件
cd ../../
make ARCH=arm64 venkee_linux_defconfig
2、执行构建
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j6 venkee-bootimg
FriendlyElec做u-boot的时候,把dtb名称硬编码到了环境变量,如果不修改会导致启动不了,或者需要手动修改环境变量才能启动
1、进入uboot-rockchip/board/rockchip/rk33xx
,修改rk33xx.c
原来的代码
static void set_dtb_name(void)
{
char info[64] = {0, };
snprintf(info, ARRAY_SIZE(info),
"rk3399-nanopi4-rev%02x.dtb", get_board_rev());
setenv("dtb_name", info);
}
修改后的代码
static void set_dtb_name(void)
{
char info[64] = {0, };
snprintf(info, ARRAY_SIZE(info),
"rk3399-venkee-rev%02x.dtb", get_board_rev());
setenv("dtb_name", info);
}