Commit 5dfd201
[lightning-ln882h] Restore Tuya factory MAC on first boot; fall back to TRNG
Every LN882H ships with the same factory-default MAC address (00:50:C2:5E:10:88)
written to KV flash by sysparam_integrity_check_all(). Without a fix every device
on the same network shares one MAC, causing ARP conflicts and connection failures.
Fix: lt_init_unique_mac() is called immediately after sysparam_integrity_check_all()
in lt_init_family(). It resolves the MAC in priority order:
1. sysparam KV (0x1E0000) already holds a non-sentinel MAC: return immediately.
This is the fast path on every boot after the first, and also covers the
LibreTiny-to-LibreTiny OTA update case since 0x1E0000 is outside the OTA
partition and is never erased by OTA.
2. Tuya BLK_V1.0 KV store at 0x1C5000: scan for the last valid 6_sta_mac entry
and restore it. Tuya assigns every LN882H a unique MAC at the factory and
stores it here. This region lies within the OTA partition (0x133000-0x1DD000),
but OTA writes are block-addressed and the current firmware (~530 KB) ends at
~0x1B4700 — well short of 0x1C5000 — so the Tuya KV is preserved under both
UART flash (covers 0x000000-0x088000) and OTA (block-addressed, stops at image
end). No partition layout changes are needed.
3. Tuya KV absent or erased (e.g. UART flash with full-chip erase option): generate
a unique address via ln_generate_random_mac() (hardware TRNG). This mirrors the
approach used in OpenBK7231T_App.
In all cases the result is persisted to sysparam KV so step 1 handles every
subsequent boot. The SoftAP MAC is derived by setting the locally-administered bit
on the first octet of the STA MAC.
Analysis based on binary examination of 5 unique Tuya LN882H flash dumps (4x
DS-101JL wall switches + 1x GU10 bulb). All devices, including those never
provisioned via the Tuya app, carry a unique 6_sta_mac entry at a predictable
offset within the BLK_V1.0 KV region, confirming that the MAC is factory-assigned
at manufacturing time.1 parent af7e7e8 commit 5dfd201
1 file changed
Lines changed: 114 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
6 | 11 | | |
7 | 12 | | |
8 | 13 | | |
| |||
13 | 18 | | |
14 | 19 | | |
15 | 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 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
16 | 126 | | |
17 | 127 | | |
18 | 128 | | |
| |||
42 | 152 | | |
43 | 153 | | |
44 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
45 | 158 | | |
46 | 159 | | |
47 | 160 | | |
48 | 161 | | |
49 | | - | |
| 162 | + | |
50 | 163 | | |
51 | 164 | | |
52 | 165 | | |
| |||
0 commit comments