OpenWrt 中寻找 LED 灯不能被关闭的原因

开篇废话

这几天闲的没事干(其实是太焦虑了),把家里 Netgear WAX202 从 22.03 升级到了 24.10 ,虽然现在还是 rc6 。

升级完后发现 LED 的 lan1 lan2 lan3 的灯不受控制了,于是我们来调查下。

正文

看看设置页面

首先就是进入 /cgi-bin/luci/admin/system/leds 看看之前 LED 的配置,看上去配置没被改, 然后点了下编辑,发现 green:lan1 green:lan2 green:lan3 都消失了:
led-confguration-2410

正常情况应该是这样的:
led-confguration-2203

于是大概知道是哪里出锅了。

Device Tree

再补下这部分知识…

众所周知,大部分嵌入式设备都是用 Device Tree 来描述硬件信息的,而不是 x86 里面的 ACPI 。

各种硬件参数基本是由 Device Tree 描述后 Linux 才能识别到的,当然 LED 灯的控制电路是什么位置其实就是在 Device Tree 里面描述的。

之前也有类似文章,可以先看看:

当然不看也不要紧,本文基本上不涉及修改,只是把代码恢复回来了。

查找 dts

最简单的办法是在 Github/openwrt/openwrt 直接搜索型号,比如我的路由器型号是 WAX202 ,然后就找到了相关的 dts : github-find-dts

然后我们简单 b1ame 一下,发现了确实有人把我的 gpio 的绿色 LED 删了:

https://github.com/openwrt/openwrt/commit/fc33c41c21362b7186aa051a2140623943fa3143

然后 commit 说了这些:

ramips: do not use GPIO function on switch pins on certain devices
The pins of the MT7530 switch that translate to GPIO 0, 3, 6, 9 and 12 has
got a function, by default, which does the same thing as the netdev
trigger. Because of bridge offloading on DSA, the netdev trigger won't see
the frames between the switch ports whilst the default function will.

Do not use the GPIO function on switch pins on devices that fall under this
category.

Keep it for:

mt7621_belkin_rt1800.dts: There's only one LED which is for the wan
interface and there's no bridge offloading between the "wan" interface and
other interfaces.

mt7621_yuncore_ax820.dts: There's no bridge offloading between the "wan"
and "lan" interfaces.

简单来说就是绿灯闪实际上是靠交换机芯片出来的,不需要再靠 soc 来处理,所以贴心地帮你删了。

行8,这个理由,也许只有我喜欢把路由器的 LED 都关了?

回滚修改

好像也没什么好说的,怎么删的怎么恢复了:
https://github.com/openwrt/openwrt/commit/fc33c41c21362b7186aa051a2140623943fa3143#diff-30afa22b0158eec71cf22b1569cf24e6f8cd94a1e188cd653eca92ee32d78f21L32

led_lan1_green: lan1_green {
			label = "green:lan1";
			gpios = <&switch0 3 GPIO_ACTIVE_LOW>;
		};
		led_lan1_orange: lan1_orange {
			label = "orange:lan1";
			gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
		};

		led_lan2_green: lan2_green {
			label = "green:lan2";
			gpios = <&switch0 6 GPIO_ACTIVE_LOW>;
		};
		led_lan2_orange: lan2_orange {
			label = "orange:lan2";
			gpios = <&gpio 13 GPIO_ACTIVE_LOW>;
		};

		led_lan3_green: lan3_green {
			label = "green:lan3";
			gpios = <&switch0 12 GPIO_ACTIVE_LOW>;
		};
		led_lan3_orange: lan3_orange {
			label = "orange:lan3";
			gpios = <&gpio 14 GPIO_ACTIVE_LOW>;

然后除了 LED 以外,记得下面的

&switch0 {

加上 gpio-controller;

&switch0 {
	gpio-controller;

然后我们替换下本地的 dts:

target/linux/ramips/dts/mt7621_netgear_wax202.dts

这里涉及到内核更改,需要重刷固件才行,所以我们需要编译系统。
当然本文涉及编译部分内容,如果不理解的话请自行搜索教程。
当然我前面文章好像顺手写了一点,也可以看看:

总结

没想到 OpenWrt 系列的开发教程都出到第⑨篇了,感觉挺感慨的(

总之 OpenWrt 是个开源破车,想用的舒服或多或少要自己改点东西….