編譯kernel配置
make ARCH=arm64 nanopi4_linux_defconfig
/kernel-rockchip/arch/arm64/configs/nanopi4_linux_defconfig
CONFIG_ARCH_ROCKCHIP=y
----------------------------------------------------------------
kernel-rockchip/drivers/soc/Kconfig
menu "SOC (System On Chip) specific Drivers"
source "drivers/soc/brcmstb/Kconfig"
source "drivers/soc/mediatek/Kconfig"
source "drivers/soc/qcom/Kconfig"
source "drivers/soc/rockchip/Kconfig"
source "drivers/soc/sunxi/Kconfig"
source "drivers/soc/ti/Kconfig"
source "drivers/soc/versatile/Kconfig"
source "drivers/soc/friendlyelec/Kconfig"
endmenu
------------------------------------------------------------------------
/kernel-rockchip/drivers/soc/friendlyelec/Kconfig
#
# Machine drivers
#
if ARCH_ROCKCHIP
config MACH_NANOPI4
bool "FriendlyElec NanoPi 4 Series Machine"
default y
endif
manuconfig設 FriendlyElec NanoPi 4 Series Machine 為 Y
, 則 config MACH_NANOPI4 =Y
------------------------------------------------------------------
/kernel-rockchip/drivers/soc/Makefile
# Makefile for the Linux Kernel SOC specific device drivers.
#
obj-$(CONFIG_SOC_BRCMSTB) += brcmstb/
obj-$(CONFIG_MACH_DOVE) += dove/
obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
obj-$(CONFIG_ARCH_QCOM) += qcom/
obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/
obj-$(CONFIG_ARCH_SUNXI) += sunxi/
obj-$(CONFIG_ARCH_TEGRA) += tegra/
obj-$(CONFIG_SOC_TI) += ti/
obj-$(CONFIG_PLAT_VERSATILE) += versatile/
obj-$(CONFIG_MACH_NANOPI4) += friendlyelec/
---------------------------------------------------------------------------
/kernel-rockchip/drivers/soc/friendlyelec/Makefile
obj-$(CONFIG_MACH_NANOPI4) += board.o
--------------------------------------------------------------------
/kernel-rockchip/drivers/soc/friendlyelec/board.c
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/types.h>
24 #include <linux/io.h>
25 #include <linux/of.h>
26 #include <linux/of_platform.h>
27 #include <linux/platform_device.h>
28 #include <linux/slab.h>
29 #include <asm/system_info.h>
30
31 #define BOARD_MANF "FriendlyELEC Computer Tech. Co., Ltd."
32
33 static const char *board_mach;
34 static const char *board_name;
35 static u32 board_rev;
36 static u32 board_serial_high, board_serial_low;
37
38 static ssize_t board_sys_info_show(struct device *dev,
39 struct device_attribute *attr,
40 char *buf)
41 {
42 char *s = buf;
43
44 s += sprintf(s, "Hardware\t: %s\n", board_mach);
45 s += sprintf(s, "Revision\t: %04x\n", board_rev);
46 s += sprintf(s, "Serial\t\t: %08x%08x\n",
47 board_serial_high, board_serial_low);
48 s += sprintf(s, "\nModel\t\t: %s\n", board_name);
49 s += sprintf(s, "Manufacturer\t: %s\n", BOARD_MANF);
50
51 return (s - buf);
52 }
53
54 static struct device_attribute board_attr_info =
55 __ATTR(info, S_IRUGO, board_sys_info_show, NULL);
56
57 static int board_sys_probe(struct platform_device *pdev)
58 {
59 struct device_node *np = pdev->dev.of_node;
60 struct device_node *root;
61
62 root = of_find_node_by_path("/");
63
64 of_property_read_u32(np, "hwrev", &board_rev);
65
66 if (of_property_read_string(np, "machine", &board_mach))
67 of_property_read_string(root, "compatible", &board_mach);
68
69 if (of_property_read_string(np, "model", &board_name))
70 of_property_read_string(root, "model", &board_name);
71
72 of_node_put(root);
73
74 if (system_serial_low || system_serial_high) {
75 board_serial_low = system_serial_low;
76 board_serial_high = system_serial_high;
77 } else {
78 board_serial_high = 0xFA3399DB;
79 board_serial_low = 0xA7110821;
80 }
81
82 device_create_file(&pdev->dev, &board_attr_info);
83
84 return 0;
85 }
86
87 static const struct of_device_id board_sys_of_match[] = {
88 { .compatible = "friendlyelec,board" }, // dts的compatible一致
89 {}
90 };
91 MODULE_DEVICE_TABLE(of, board_sys_of_match);
92
93 static struct platform_driver board_sys_driver = {
94 .probe = board_sys_probe,
95 .driver = {
96 .name = "friendlyelec-board",
97 .of_match_table = board_sys_of_match,
98 },
99 };
100
101 static int __init board_sys_init(void)
102 {
103 return platform_driver_register(&board_sys_driver);
104 }
105 device_initcall(board_sys_init);
106
107 MODULE_AUTHOR("support@friendlyarm.com");
108 MODULE_DESCRIPTION("FriendlyElec NanoPi Series Machine Driver");
109 MODULE_LICENSE("GPL v2");
-----------------------------------------------------------------------------------------------------
/kernel-rockchip/arch/arm64/boot/dts/rockchip/rk3399-nanopi4-common.dtsi
/ {
mach: board {
compatible = "friendlyelec,board";
machine = "NANOPI4";
hwrev = <255>;
model = "NanoPi 4 Series";
};
基于RK3399的Linux驱动开发 -- 往内核添加自己板型_VeryCoolVenkee的博客-CSDN博客
manuconfig
│ Symbol: MACH_NANOPI4 [=y] │
│ Type : boolean │
│ Prompt: FriendlyElec NanoPi 4 Series Machine │
│ Location: │
│ -> Device Drivers │
│ (1) -> SOC (System On Chip) specific Drivers │
│ Defined at drivers/soc/friendlyelec/Kconfig:7 │
│ Depends on: ARCH_ROCKCHIP [=y]
│ Symbol: ARCH_ROCKCHIP [=y] │
│ Type : boolean │
│ Prompt: Rockchip Platforms │
│ Location: │
│ (1) -> Platform selection │
│ Defined at arch/arm64/Kconfig.platforms:55 │
│ Selects: ARCH_HAS_RESET_CONTROLLER [=y] && ARCH_REQUIRE_GPIOLIB [=y] && PINCTRL [=y] && PINCTRL_ROCKCHIP [=y] && ROCKCHIP_TIMER [=y]
Device Drivers > SOC (System On Chip) specific Drivers
[*] FriendlyElec NanoPi 4 Series Machine