【项目】-Orange Pi Zero 3 编译内核测试LED
一次完整的嵌入式 Linux 驱动学习之旅
1,设置环境变量(写入 ~/.bashrc)
echo ‘export ARCH=arm64’ >> ~/.bashrc
echo ‘export CROSS_COMPILE=aarch64-linux-gnu-’ >> ~/.bashrc
source ~/.bashrc
2,、修改设备树:添加 LED 节点
arch/arm64/boot/dts/allwinner/sun50i-h618-orangepi-zero3.dts
`
`// 定义 LED 使用的引脚组(放在 &pio 内部或外部均可)
&pio {led_pins: led_pins {pins = "PC12", "PC13";function = "gpio_out";};
};// 添加 LED 设备节点(关键:不要用 / { } 包裹!)
leds {compatible = "gpio-leds";led_red {label = "red-led";gpios = <&pio 2 12 GPIO_ACTIVE_HIGH>;pinctrl-names = "default";pinctrl-0 = <&led_pins>;};led_green {label = "green-led";gpios = <&pio 2 13 GPIO_ACTIVE_HIGH>;pinctrl-names = "default";pinctrl-0 = <&led_pins>;};
};
彻底清理(避免缓存干扰)
make mrproper
生成配置
make defconfig
make olddefconfig # 补全所有新选项
3. 生成头文件链接(关键!解决 dt-bindings 找不到)
make include/config/auto.conf
4. 编译
make -j$(nproc) Image
make allwinner/sun50i-h618-orangepi-zero3.dtb
替换 SD 卡中的文件
/boot/dtb/allwinner/sun50i-h618-orangepi-zero3.dtb
测试 LED
进入系统后执行:
ls /sys/class/leds
echo 1 > /sys/class/leds/red-led/brightness # 点亮红灯
echo 0 > /sys/class/leds/red-led/brightness # 熄灭
现在编译出来了。内核启动不起来,我再研究下