From 614a30fd4e683f3765b9d92a4c75badd8775dc0d Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 1 May 2025 00:55:33 +0200 Subject: [PATCH] avr: generate new uid if the current one consists of 4 equal bytes. --- avr/common/utils.asm | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/avr/common/utils.asm b/avr/common/utils.asm index 81ef3ea..e297b9b 100644 --- a/avr/common/utils.asm +++ b/avr/common/utils.asm @@ -397,35 +397,27 @@ Utils_SetupUid: in r15, SREG cli rcall Utils_ReadUid ; (R16, X) - mov r16, r18 ; all 0x00? - or r16, r19 - or r16, r20 - or r16, r21 - breq Utils_SetupUid_generate ; yep, go generate one - mov r16, r18 ; all 0xff? - and r16, r19 - and r16, r20 - and r16, r21 - inc r16 - breq Utils_SetupUid_generate ; yep, go generate one - out SREG, r15 - clc - ret -Utils_SetupUid_generate: - ldi xl, LOW(EEPROM_OFFS_UUID) + cp r18, r19 ; all the same? + brne Utils_SetupUid_uidOkay ; different, jmp + cp r18, r20 + brne Utils_SetupUid_uidOkay ; different, jmp + cp r18, r21 + brne Utils_SetupUid_uidOkay ; different, jmp + ldi xl, LOW(EEPROM_OFFS_UUID) ; all the same, generate new uid ldi xh, HIGH(EEPROM_OFFS_UUID) rcall Utils_PseudoRandom ; byte 0 (R16, R17, R18, R19) inc r16 - rcall Utils_WriteEepromIncr ; (R17) + rcall Utils_WriteEepromIncr ; (R17) rcall Utils_PseudoRandom ; byte 1 - rcall Utils_WriteEepromIncr + rcall Utils_WriteEepromIncr ; (R17) rcall Utils_PseudoRandom ; byte 2 - rcall Utils_WriteEepromIncr + rcall Utils_WriteEepromIncr ; (R17) rcall Utils_PseudoRandom ; byte 3 - rcall Utils_WriteEepromIncr + rcall Utils_WriteEepromIncr ; (R17) rcall Utils_UpdateSeedInEeprom ; (R16, R17, R18, R19, X) +Utils_SetupUid_uidOkay: out SREG, r15 sec ret