Skip to content

Commit d389e59

Browse files
committed
Deduplicate firmware_image_type and migrate renumbered devices over OTA (romasku#474)
1 parent 243a55a commit d389e59

4 files changed

Lines changed: 98 additions & 34 deletions

File tree

board.mk

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ CONFIG_STR := $(shell yq -r .$(BOARD).config_str $(DEVICE_DB_FILE))
6565
FROM_STOCK_MANUFACTURER_ID := $(shell yq -r .$(BOARD).stock_manufacturer_id $(DEVICE_DB_FILE))
6666
FROM_STOCK_IMAGE_TYPE := $(shell yq -r .$(BOARD).stock_image_type $(DEVICE_DB_FILE))
6767
FIRMWARE_IMAGE_TYPE := $(shell yq -r .$(BOARD).firmware_image_type $(DEVICE_DB_FILE))
68+
# Superseded image types this device was previously published under (renumbered
69+
# to fix a duplicate). One migration OTA is emitted per id so units still
70+
# reporting an old id get updated once and then report the new id.
71+
MIGRATION_FROM_IMAGE_TYPES := $(shell yq -r '.$(BOARD).migration_from_image_type // [] | .[]' $(DEVICE_DB_FILE))
6872

6973
# ==============================================================================
7074
# Platform Configuration
@@ -128,7 +132,7 @@ drop-old-files:
128132
rm -f $(BIN_PATH)/*.zigbee
129133

130134
# Generate all three types of OTA files
131-
generate-ota-files: generate-normal-ota generate-tuya-ota generate-force-ota
135+
generate-ota-files: generate-normal-ota generate-tuya-ota generate-force-ota generate-migration-ota
132136

133137
generate-normal-ota:
134138
$(MAKE) $(PLATFORM_PREFIX)/ota \
@@ -154,6 +158,18 @@ generate-force-ota:
154158
OTA_IMAGE_TYPE=$(FIRMWARE_IMAGE_TYPE) \
155159
OTA_FILE=../../$(FORCE_OTA_FILE)
156160

161+
# Migration OTA per superseded image type: current firmware wrapped in a header
162+
# carrying the old id, so units still reporting it update once (then they report
163+
# the new firmware_image_type). Version stays FILE_VERSION -> no re-verify loop.
164+
generate-migration-ota:
165+
@for old_id in $(MIGRATION_FROM_IMAGE_TYPES); do \
166+
$(MAKE) $(PLATFORM_PREFIX)/ota \
167+
DEVICE_TYPE=$(DEVICE_TYPE) \
168+
FILE_VERSION=$(FILE_VERSION) \
169+
OTA_IMAGE_TYPE=$$old_id \
170+
OTA_FILE=../../$(BIN_PATH)/$(PROJECT_NAME)-$(VERSION_STR)-migration-$$old_id.zigbee; \
171+
done
172+
157173
# Update Zigbee2MQTT index files
158174
update-indexes:
159175
@python3 $(HELPERS_PATH)/make_z2m_ota_index.py --db_file $(DEVICE_DB_FILE) $(OTA_FILE) $(Z2M_INDEX_FILE) --board $(BOARD)
@@ -165,11 +181,16 @@ endif
165181
endif
166182
endif
167183
@python3 $(HELPERS_PATH)/make_z2m_ota_index.py --db_file $(DEVICE_DB_FILE) $(FORCE_OTA_FILE) $(Z2M_FORCE_INDEX_FILE) --board $(BOARD)
184+
@for old_id in $(MIGRATION_FROM_IMAGE_TYPES); do \
185+
python3 $(HELPERS_PATH)/make_z2m_ota_index.py --db_file $(DEVICE_DB_FILE) \
186+
$(BIN_PATH)/$(PROJECT_NAME)-$(VERSION_STR)-migration-$$old_id.zigbee \
187+
$(Z2M_INDEX_FILE) --board $(BOARD); \
188+
done
168189

169190

170191
flash_telink: build-firmware
171192
@echo "Flashing $(BIN_FILE) to device via $(TLSRPGM_TTY)"
172193
$(MAKE) telink/flasher ARGS="-t25 -a 20 --mrst we 0 ../../$(BIN_FILE)"
173194

174-
.PHONY: help build build-firmware drop-old-files generate-ota-files generate-normal-ota generate-tuya-ota generate-force-ota update-indexes clean_z2m_index update_converters update_zha_quirk update_homed_extension update_supported_devices freeze_ota_links
195+
.PHONY: help build build-firmware drop-old-files generate-ota-files generate-normal-ota generate-tuya-ota generate-force-ota generate-migration-ota update-indexes clean_z2m_index update_converters update_zha_quirk update_homed_extension update_supported_devices freeze_ota_links
175196

device_db.yaml

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ BOARD__MHCOZY_TS0004_3:
115115
old_zb_models: null
116116
stock_manufacturer_id: 4417
117117
stock_image_type: 513
118-
firmware_image_type: 45631
118+
firmware_image_type: 47133
119+
migration_from_image_type: [45631]
119120
build: yes
120121
status: mostly_supported
121122
info: Needs pinout confirmation
@@ -142,7 +143,8 @@ BOARD__SCIMAGIC_TS0001:
142143
old_zb_models: null
143144
stock_manufacturer_id: 4417
144145
stock_image_type: 54179
145-
firmware_image_type: 43623
146+
firmware_image_type: 47124
147+
migration_from_image_type: [43623]
146148
build: yes
147149
status: fully_supported
148150
info: Supported
@@ -250,7 +252,8 @@ DIN_RELAY_TUYA_TS011F_PM:
250252
old_zb_models: null
251253
stock_manufacturer_id: 4417
252254
stock_image_type: 54179
253-
firmware_image_type: 45599
255+
firmware_image_type: 47132
256+
migration_from_image_type: [45599]
254257
build: yes
255258
status: in_progress
256259
info: Power monitoring not implemented
@@ -395,7 +398,8 @@ MODULE_AVATTO_A_TS0001:
395398
- TS0001-AV-CUS
396399
stock_manufacturer_id: 4417
397400
stock_image_type: 54179
398-
firmware_image_type: 43527
401+
firmware_image_type: 47117
402+
migration_from_image_type: [43527]
399403
build: yes
400404
status: fully_supported
401405
info: Supported
@@ -722,7 +726,8 @@ MODULE_EKAZA_TS0002:
722726
old_zb_models: null
723727
stock_manufacturer_id: 4417
724728
stock_image_type: 54179
725-
firmware_image_type: 43547
729+
firmware_image_type: 47119
730+
migration_from_image_type: [43547]
726731
build: yes
727732
status: fully_supported
728733
info: Supported
@@ -1324,7 +1329,8 @@ MODULE_GIRIER_ZTU_TS0001:
13241329
old_zb_models: null
13251330
stock_manufacturer_id: 4417
13261331
stock_image_type: 54179
1327-
firmware_image_type: 45585
1332+
firmware_image_type: 47130
1333+
migration_from_image_type: [45585]
13281334
build: yes
13291335
status: fully_supported
13301336
info: Supported
@@ -1908,7 +1914,8 @@ MODULE_NOUS_B1Z_TS0001:
19081914
old_zb_models: null
19091915
stock_manufacturer_id: 4417
19101916
stock_image_type: 54179
1911-
firmware_image_type: 43633
1917+
firmware_image_type: 47125
1918+
migration_from_image_type: [43633]
19121919
build: yes
19131920
status: fully_supported
19141921
info: Supported
@@ -2152,7 +2159,8 @@ MODULE_TUYA_COMMON_TS0004:
21522159
old_zb_models: null
21532160
stock_manufacturer_id: 4417
21542161
stock_image_type: 54179
2155-
firmware_image_type: 47004
2162+
firmware_image_type: 47143
2163+
migration_from_image_type: [47004]
21562164
build: yes
21572165
status: fully_supported
21582166
info: Supported
@@ -2179,7 +2187,8 @@ MODULE_TUYA_COMMON2_TS0003:
21792187
old_zb_models: null
21802188
stock_manufacturer_id: 4417
21812189
stock_image_type: 54179
2182-
firmware_image_type: 47005
2190+
firmware_image_type: 47144
2191+
migration_from_image_type: [47005]
21832192
build: yes
21842193
status: fully_supported
21852194
info: Supported
@@ -2467,7 +2476,8 @@ MODULE_TUYA_NOVATO_QS_S05_TS0001:
24672476
old_zb_models: null
24682477
stock_manufacturer_id: 4417
24692478
stock_image_type: 54179
2470-
firmware_image_type: 45577
2479+
firmware_image_type: 47127
2480+
migration_from_image_type: [45577]
24712481
build: yes
24722482
status: fully_supported
24732483
info: Supported
@@ -2494,7 +2504,8 @@ MODULE_TUYA_NOVATO_QS_S05_TS0011:
24942504
old_zb_models: null
24952505
stock_manufacturer_id: 4417
24962506
stock_image_type: 54179
2497-
firmware_image_type: 45578
2507+
firmware_image_type: 47128
2508+
migration_from_image_type: [45578]
24982509
build: yes
24992510
status: fully_supported
25002511
info: Supported
@@ -3132,7 +3143,8 @@ OUTLET_MAKEGOOD_PM_TS011F_2GANG:
31323143
old_zb_models: null
31333144
stock_manufacturer_id: 4417
31343145
stock_image_type: 54179
3135-
firmware_image_type: 47009
3146+
firmware_image_type: 47147
3147+
migration_from_image_type: [47009]
31363148
build: yes
31373149
status: in_progress
31383150
info: Power monitoring not implemented
@@ -3186,7 +3198,8 @@ OUTLET_TUYA_PM_TS011F:
31863198
old_zb_models: null
31873199
stock_manufacturer_id: 4417
31883200
stock_image_type: 54179
3189-
firmware_image_type: 45681
3201+
firmware_image_type: 47139
3202+
migration_from_image_type: [45681]
31903203
build: yes
31913204
status: in_progress
31923205
info: Power monitoring not implemented
@@ -3213,7 +3226,8 @@ PLUG___AUBESS_PM_TS011F:
32133226
old_zb_models: null
32143227
stock_manufacturer_id: 4417
32153228
stock_image_type: 54179
3216-
firmware_image_type: 43556
3229+
firmware_image_type: 47120
3230+
migration_from_image_type: [43556]
32173231
build: yes
32183232
status: in_progress
32193233
info: Power monitoring not implemented
@@ -3240,7 +3254,8 @@ PLUG___LELLKI_TS0001:
32403254
old_zb_models: null
32413255
stock_manufacturer_id: 4417
32423256
stock_image_type: 54179
3243-
firmware_image_type: 47003
3257+
firmware_image_type: 47142
3258+
migration_from_image_type: [47003]
32443259
build: yes
32453260
status: fully_supported
32463261
info: Supported
@@ -3348,7 +3363,8 @@ REMOTE_HOBEIAN_BUTTON_TS0001:
33483363
old_zb_models: null
33493364
stock_manufacturer_id: 4417
33503365
stock_image_type: 54179
3351-
firmware_image_type: 47002
3366+
firmware_image_type: 47140
3367+
migration_from_image_type: [47002]
33523368
build: yes
33533369
status: in_progress
33543370
info: 1MB variant working, 512KB not
@@ -3375,7 +3391,8 @@ REMOTE_IHSENO_BUTTON_TS0041:
33753391
old_zb_models: null
33763392
stock_manufacturer_id: 4417
33773393
stock_image_type: 54179
3378-
firmware_image_type: 47002
3394+
firmware_image_type: 47141
3395+
migration_from_image_type: [47002]
33793396
build: yes
33803397
status: fully_supported
33813398
info: Supported
@@ -3433,7 +3450,8 @@ REMOTE_IHSENO_TS0046:
34333450
old_zb_models: null
34343451
stock_manufacturer_id: 4417
34353452
stock_image_type: 54179
3436-
firmware_image_type: 43563
3453+
firmware_image_type: 47121
3454+
migration_from_image_type: [43563]
34373455
build: yes
34383456
status: in_progress
34393457
info: Max 4 buttons supported
@@ -3460,7 +3478,8 @@ REMOTE_LIDL_BUTTON_TS004F:
34603478
old_zb_models: null
34613479
stock_manufacturer_id: 4417
34623480
stock_image_type: 54179
3463-
firmware_image_type: 45635
3481+
firmware_image_type: 47134
3482+
migration_from_image_type: [45635]
34643483
build: yes
34653484
status: mostly_supported
34663485
info: Lower battery life
@@ -3630,7 +3649,8 @@ REMOTE_TUYA_BUTTON_TS0041:
36303649
old_zb_models: null
36313650
stock_manufacturer_id: 4417
36323651
stock_image_type: 54179
3633-
firmware_image_type: 45636
3652+
firmware_image_type: 47135
3653+
migration_from_image_type: [45636]
36343654
build: yes
36353655
status: fully_supported
36363656
info: Supported
@@ -3657,7 +3677,8 @@ REMOTE_TUYA_BUTTON_TS0041_2:
36573677
old_zb_models: null
36583678
stock_manufacturer_id: 4417
36593679
stock_image_type: 54179
3660-
firmware_image_type: 45636
3680+
firmware_image_type: 47136
3681+
migration_from_image_type: [45636]
36613682
build: yes
36623683
status: in_progress
36633684
info: Not working
@@ -3738,7 +3759,8 @@ REMOTE_TUYA_SWITCH_TS0043:
37383759
old_zb_models: null
37393760
stock_manufacturer_id: 4417
37403761
stock_image_type: 54179
3741-
firmware_image_type: 45637
3762+
firmware_image_type: 47137
3763+
migration_from_image_type: [45637]
37423764
build: yes
37433765
status: mostly_supported
37443766
info: Needs testing
@@ -3765,7 +3787,8 @@ REMOTE_TUYA_SWITCH_TS0043_1:
37653787
old_zb_models: null
37663788
stock_manufacturer_id: 4417
37673789
stock_image_type: 54179
3768-
firmware_image_type: 45637
3790+
firmware_image_type: 47138
3791+
migration_from_image_type: [45637]
37693792
build: yes
37703793
status: fully_supported
37713794
info: Supported
@@ -4354,7 +4377,8 @@ SWITCH_BSEED_TOUCH_TS0001_2:
43544377
old_zb_models: null
43554378
stock_manufacturer_id: 4417
43564379
stock_image_type: 54179
4357-
firmware_image_type: 45575
4380+
firmware_image_type: 47126
4381+
migration_from_image_type: [45575]
43584382
build: yes
43594383
status: fully_supported
43604384
info: Supported
@@ -4408,7 +4432,8 @@ SWITCH_BSEED_TOUCH_TS0002_2:
44084432
old_zb_models: null
44094433
stock_manufacturer_id: 4417
44104434
stock_image_type: 54179
4411-
firmware_image_type: 45578
4435+
firmware_image_type: 47129
4436+
migration_from_image_type: [45578]
44124437
build: yes
44134438
status: in_progress
44144439
info: Missing state indicators (specifc dimming implementation)?
@@ -4760,7 +4785,8 @@ SWITCH_BSEED_TS0726_L_3GANG_2:
47604785
old_zb_models: null
47614786
stock_manufacturer_id: 4417
47624787
stock_image_type: 54179
4763-
firmware_image_type: 47007
4788+
firmware_image_type: 47146
4789+
migration_from_image_type: [47007]
47644790
build: yes
47654791
status: fully_supported
47664792
info: Supported
@@ -5102,7 +5128,8 @@ SWITCH_LERLINK_TS0012:
51025128
old_zb_models: null
51035129
stock_manufacturer_id: 4417
51045130
stock_image_type: 54179
5105-
firmware_image_type: 43510
5131+
firmware_image_type: 47116
5132+
migration_from_image_type: [43510]
51065133
build: yes
51075134
status: fully_supported
51085135
info: Supported
@@ -5129,7 +5156,8 @@ SWITCH_LERLINK_TS0013:
51295156
old_zb_models: null
51305157
stock_manufacturer_id: 4417
51315158
stock_image_type: 54179
5132-
firmware_image_type: 43533
5159+
firmware_image_type: 47118
5160+
migration_from_image_type: [43533]
51335161
build: yes
51345162
status: fully_supported
51355163
info: Supported
@@ -5183,7 +5211,8 @@ SWITCH_LORATAP_TS130F:
51835211
old_zb_models: null
51845212
stock_manufacturer_id: 4417
51855213
stock_image_type: 54179
5186-
firmware_image_type: 43616
5214+
firmware_image_type: 47123
5215+
migration_from_image_type: [43616]
51875216
build: yes
51885217
status: in_progress
51895218
info: Stop button (D2) not implemented
@@ -5670,7 +5699,8 @@ SWITCH_NOVADIGITAL_TS0003:
56705699
old_zb_models: null
56715700
stock_manufacturer_id: 4417
56725701
stock_image_type: 54179
5673-
firmware_image_type: 43614
5702+
firmware_image_type: 47122
5703+
migration_from_image_type: [43614]
56745704
build: yes
56755705
status: fully_supported
56765706
info: Supported
@@ -5834,7 +5864,8 @@ SWITCH_TUYA_A_TS0001:
58345864
old_zb_models: null
58355865
stock_manufacturer_id: 4417
58365866
stock_image_type: 54179
5837-
firmware_image_type: 47005
5867+
firmware_image_type: 47145
5868+
migration_from_image_type: [47005]
58385869
build: yes
58395870
status: in_progress
58405871
info: Can't control relay from Z2M??
@@ -6187,7 +6218,8 @@ SWITCH_ZEMISMART_2_TS0011:
61876218
old_zb_models: null
61886219
stock_manufacturer_id: 4417
61896220
stock_image_type: 54179
6190-
firmware_image_type: 45589
6221+
firmware_image_type: 47131
6222+
migration_from_image_type: [45589]
61916223
build: yes
61926224
status: fully_supported
61936225
info: Supported

docs/changelog_fw.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ Please describe what you are working on, under ## Upcoming
4949
working unchanged; while a switch endpoint is in either deprecated long mode,
5050
its paired long-press endpoint is muted to prevent double-toggles and
5151
conflicting emissions.
52+
- **Made `firmware_image_type` unique per device** — 27 ids were each shared by
53+
two or more devices, violating the intended one-id-per-device invariant. OTA
54+
matchers (zigpy / Home Assistant ZHA and Zigbee2MQTT) normally tell such
55+
devices apart by `manufacturerName`, so most collisions are masked — but where
56+
two colliding devices also share a manufacturer name the match breaks, and any
57+
entry left without a `manufacturerName` matches the wrong device. The
58+
later-registered device in each collision was renumbered to a free id (a CI
59+
check now keeps them unique). Each renumbered device ships a migration OTA so
60+
already-deployed units update over the air once and then report the new id —
61+
no manual re-flash.
5262
- Add `D<N>` config option to customize button debounce delay in milliseconds
5363
- **Bi-stable (latching) relays** have been reworked
5464
- They now use proper pulses instead of continuously driving the coil

0 commit comments

Comments
 (0)