小米路由器 4A 千兆版烧录了 OpenWRT 后,需要做一些软件上的开发。由于每次烧录 Flash 时间较长,开发效率低,因此希望可以通过 booter 下载 initframfs 到内存中进行调试以提高效率。
我焊接上了串口,在 OpenWRT 启动后,串口可以正常输入和输出,但是在单板启动的那一刻,无法通过按数字键进入 uboot 菜单。

串口
通过下面的命令:(如果没有 fw_printenv 命令,需要通过 opkg 命令安装 uboot-envtools)
root@OpenWrt:/# fw_printenv
...
boot_wait=off
...
root@OpenWrt:~# fw_setenv boot_wait on
Can't open /dev/mtd1: Permission denied
Error: can't write fw_env to flash
由于 OpenWRT 对 uboot 的环境变量是只读的,因此无法修改。
需要修改 target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-common.dtsi,将 uboot 的环境变量区设置为可读写(直接删除 read-only)
git diff target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-common.dtsi
diff --git a/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-common.dtsi b/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-common.dtsi
index efc32733e9..5c35a9ec5e 100644
--- a/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-common.dtsi
+++ b/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-common.dtsi
@@ -51,7 +51,6 @@
partition@30000 {
label = "u-boot-env";
reg = <0x30000 0x10000>;
- read-only;
};
partition@40000 {
重新编译 OpenWRT 并烧录,再次执行命令 fw_setenv boot_wait on 重启单板后,可通过输入数字进入 uboot 命令菜单。
Please choose the operation:
1: Load system code to SDRAM via TFTP.
2: Load system code then write to Flash via TFTP.
3: Boot system code via Flash (default).
4: Entr boot command line interface.
7: Load Boot Loader code then write to Flash via Serial.
9: Load Boot Loader code then write to Flash via TFTP.
You choosed 4
0
4: System Enter Boot Command Line Interface.
U-Boot 1.1.3 (Feb 22 2019 - 06:43:39)
MT7621 #