1. Basic Structure of Device Tree Nodes
Device Tree node = a set of properties enclosed in braces, containing these common fields:
compatible: same as the matching string in the driverreg: physical number/base address (can also write<0>if none)status: enable status,"okay"means valid- Other custom properties, such as
myparam,buffer-len, etc.
2. Adding a New Device Tree Node
1. Locate the Board .dts File
The Device Tree file for LCSC-TaishanPi-3M-RK3576 development board in the SDK:
TaishanPi-3-Linux/kernel-6.1/arch/arm64/boot/dts/rockchip/tspi-3m-rk3576.dts
2. Add Custom Node
Can be placed directly inside the root node **/ { ... }**, or depending on the project, placed under soc {} or a suitable peripherals {}.
/*-----------------------------------------------------------
* Board Basic Information Configuration
*----------------------------------------------------------*/
/ {
model = "LCKFB TaishanPi 3M RK3576 Board";
compatible = "lckfb,tspi-3m-rk3576", "rockchip,rk3576";
/*
* User LED
* Used to indicate system status
*/
leds: leds {
status = "okay";
compatible = "gpio-leds";
work_led: work {
linux,default-trigger = "heartbeat";
gpios = <&gpio0 RK_PA0 GPIO_ACTIVE_LOW>;
};
};
/*
* Custom mychardev device node
*/
mychardev: mychardev@0 {
compatible = "lckfb,mychardev"; // Driver matching field
reg = <0x0>; // Register address, set as needed
buffer-len = <64>; // buffer length
dev-id = <0xFFA8>; // preset device ID
status = "okay";
};
};2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
mychardev node field explanation:
mychardev:label. Used for referencing elsewhere or by phandle (can be omitted).mychardev@0node name,@0can be a number, base address, etc.compatibleis the most critical - your driver will automatically associate with this node through it.regonly represents a unique identifier; if no actual register exists, fill<0x0>.buffer-len,dev-id, etc. can all be customized as needed.status = "okay"must be present, otherwise the device is disabled by default.
3. Compile and Verify
According to the tutorial Debian12 Kernel Compilation, recompile the kernel to generate boot.img, and replace the Device Tree by separately flashing the kernel image.
After flashing is complete, boot the board and verify the Device Tree node:
View the unpacked Device Tree node
ls /sys/firmware/devicetree/base/mychardev@0Seeing buffer-len/dev-id/compatible fields means they are active!
Check if buffer-len is the 64 size we set:
# Method 1: using hexdump tool
hexdump -C /sys/firmware/devicetree/base/mychardev@0/buffer-len
# Method 2: using python tool
python3 -c "print(int.from_bytes(open('/sys/firmware/devicetree/base/mychardev@0/buffer-len','rb').read(), 'big'))"2
3
4
5
Note:
After buffer-len = <64>; is stored in dtb, it becomes "4-byte big-endian binary", not text number.
Using python can interpret it as an integer.