openwrt


LS1043A 开发板 OpenWrt 极简复盘笔记

编译与固件提取

  • menuconfig:Target: NXP Layerscape -> Subtarget: ARMv8… -> Profile: SD Card Boot
  • 镜像选择:仅勾选 [*] ext4,其余全取消。
  • LuCI/中文:勾选 luci 与 luci-i18n-base-zh-cn。
  • 提取产物:缓存目录捞出 Image、fsl-nh03-sdk.dtb、root.ext4。

TinyLinux 刷写 eMMC

刷写根系统

  • dd if=/media/openwrt/root.ext4 of=/dev/mmcblk0p2 bs=4M status=progress && sync# 拷贝内核与设备树
  • mkdir -p /mnt/mmc1 && mount /dev/mmcblk0p1 /mnt/mmc1/
  • cp /media/openwrt/Image /media/openwrt/fsl-nh03-sdk.dtb /mnt/mmc1/
  • sync && umount /mnt/mmc1/

U-Boot 固化启动参数

拦截启动进入 U-Boot 执行:

  • setenv bootcmd "mmc dev 0; ext4load mmc 0:1 0xa0000000 Image; ext4load mmc 0:1 0xb0000000 fsl-nh03-sdk.dtb; booti 0xa0000000 - 0xb0000000"
  • setenv bootargs "console=ttyS0,115200 earlycon=uart8250,mmio,0x21c0500 root=/dev/mmcblk0p2 rw rootwait"
  • saveenv && boot

基础网络与 ttyd 配置(主路由模式)

配置 LAN 口静态 IP

  • uci set network.lan.proto='static'
  • uci set network.lan.ipaddr='192.168.2.1'
  • uci set network.lan.netmask='255.255.255.0'
  • uci delete dhcp.lan.ignore # 开启 DHCP
  • uci commit network && uci commit dhcp# ttyd 允许 WAN 口访问
  • uci set ttyd.@ttyd[0].interface=''
  • uci set ttyd.@ttyd[0].listen='0.0.0.0'
  • uci commit ttyd# 重启服务
  • /etc/init.d/network restart && /etc/init.d/ttyd restart

面板口配置

1
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
root@OpenWrt:~# cat /etc/board.json
{
"model": {
"id": "fsl,ls1043a-sdboot",
"name": "NH03"
},
"network": {
"lan": {
"device": "br-lan",
"protocol": "static"
},
"wan": {
"device": "eth2",
"protocol": "dhcp"
}
}
}
root@OpenWrt:~# cat /etc/config/network

config interface 'loopback'
option device 'lo'
option proto 'static'
list ipaddr '127.0.0.1/8'

config globals 'globals'
option dhcp_default_duid '00049e7cb3c0895642958376c30f479dcb24'
option ula_prefix 'fdc2:858b:bbd::/48'

config device
option name 'br-lan'
option type 'bridge'
list ports 'eth3'
list ports 'eth0'
list ports 'eth1'
list ports 'eth4'
list ports 'eth5'

config interface 'lan'
option device 'br-lan'
option proto 'static'
option ip6assign '60'
option ipaddr '192.168.2.1'
option netmask '255.255.255.0'

config interface 'wan'
option device 'eth2'
option proto 'dhcp'

config interface 'wan6'
option device 'eth2'
option proto 'dhcpv6'

config interface 'singbox_tun'
option device 'tun0'
option proto 'unmanaged'
  • /etc/init.d/rpcd restart

Sing-Box 代理与 TUN 转发

基础运行配置

  • uci set sing-box.main.enabled='1'
  • uci set sing-box.main.user='root'
  • uci commit sing-box# 创建并放行 TUN 接口
  • uci set network.singbox_tun=interface
  • uci set network.singbox_tun.device='tun0'
  • uci set network.singbox_tun.proto='unmanaged'
  • uci add_list firewall.@zone[0].network='singbox_tun'
  • uci set firewall.@zone[0].forward='ACCEPT'# 关闭 DNS 重绑定保护 (对接 5353 转发)
  • uci set dhcp.@dnsmasq[0].rebind_protection='0'# 提交并重启
  • uci commit network && uci commit firewall && uci commit dhcp
  • sysctl -w net.ipv4.conf.all.rp_filter=0
  • iptables -I FORWARD -j ACCEPT
  • /etc/init.d/network restart && /etc/init.d/firewall restart && /etc/init.d/dnsmasq restart && /etc/init.d/sing-box restart

设备树 (DTS/DTB) 互转命令

反编译 DTB -> DTS

  • dtc -I dtb -O dts -o /tmp/myboard.dts /mnt/fsl-nh03-sdk.dtb# 编译 DTS -> DTB
  • dtc -I dts -O dtb -o /mnt/fsl-nh03-sdk.dtb /tmp/myboard.dts