Skip to content

Commit 9104038

Browse files
KonstantinKondrashovradimkarnis
authored andcommitted
feat(espefuse): Adds efuse calculation fields for ESP32-C5
1 parent c102510 commit 9104038

File tree

2 files changed

+62
-7
lines changed

2 files changed

+62
-7
lines changed

espefuse/efuse/esp32c5/fields.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,55 @@ def convert(parent, efuse):
301301
"keypurpose": EfuseKeyPurposeField,
302302
"t_sensor": EfuseTempSensor,
303303
"adc_tp": EfuseAdcPointCalibration,
304-
"wafer": EfuseWafer,
304+
"recovery_bootloader": EfuseBtldrRecoveryField,
305+
"bootloader_anti_rollback": EfuseBtldrAntiRollbackField,
305306
}.get(efuse.class_type, EfuseField)(parent, efuse)
306307

307308

308-
class EfuseWafer(EfuseField):
309+
class EfuseBtldrRecoveryField(EfuseField):
309310
def get(self, from_read=True):
310-
hi_bits = self.parent["WAFER_VERSION_MINOR_HI"].get(from_read)
311-
assert self.parent["WAFER_VERSION_MINOR_HI"].bit_len == 1
312-
lo_bits = self.parent["WAFER_VERSION_MINOR_LO"].get(from_read)
313-
assert self.parent["WAFER_VERSION_MINOR_LO"].bit_len == 3
311+
hi_bits = self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_HI"].get(from_read)
312+
assert self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_HI"].bit_len == 3
313+
lo_bits = self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_LO"].get(from_read)
314+
assert self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_LO"].bit_len == 9
315+
return (hi_bits << 9) + lo_bits
316+
317+
def save(self, new_value):
318+
efuse = self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_HI"]
319+
efuse.save((new_value >> 9) & 3)
320+
print(
321+
f"\t - '{efuse.name}' {efuse.get_bitstring()} -> {efuse.get_bitstring(from_read=False)}"
322+
)
323+
efuse = self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_LO"]
324+
efuse.save(new_value & 0x1FF)
325+
print(
326+
f"\t - '{efuse.name}' {efuse.get_bitstring()} -> {efuse.get_bitstring(from_read=False)}"
327+
)
328+
329+
330+
class EfuseBtldrAntiRollbackField(EfuseField):
331+
def get(self, from_read=True):
332+
hi_bits = self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_HI"].get(
333+
from_read
334+
)
335+
assert self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_HI"].bit_len == 1
336+
lo_bits = self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_LO"].get(
337+
from_read
338+
)
339+
assert self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_LO"].bit_len == 3
314340
return (hi_bits << 3) + lo_bits
315341

316342
def save(self, new_value):
317-
raise esptool.FatalError("Burning %s is not supported" % self.name)
343+
efuse = self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_HI"]
344+
efuse.save((new_value >> 3) & 1)
345+
print(
346+
f"\t - '{efuse.name}' {efuse.get_bitstring()} -> {efuse.get_bitstring(from_read=False)}"
347+
)
348+
efuse = self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_LO"]
349+
efuse.save(new_value & 0x7)
350+
print(
351+
f"\t - '{efuse.name}' {efuse.get_bitstring()} -> {efuse.get_bitstring(from_read=False)}"
352+
)
318353

319354

320355
class EfuseTempSensor(EfuseField):

espefuse/efuse/esp32c5/mem_definition.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,26 @@ def __init__(self, extend_efuse_table) -> None:
158158
f.description = "calc MAC_EUI64 = MAC[0]:MAC[1]:MAC[2]:MAC_EXT[0]:MAC_EXT[1]:MAC[3]:MAC[4]:MAC[5]"
159159
self.CALC.append(f)
160160

161+
f = Field()
162+
f.name = "RECOVERY_BOOTLOADER_FLASH_SECTOR"
163+
f.block = 0
164+
f.bit_len = 12
165+
f.type = f"uint:{f.bit_len}"
166+
f.category = "config"
167+
f.class_type = "recovery_bootloader"
168+
f.description = "calc recovery_bootloader = recovery_bootloader_hi << 9 + recovery_bootloader_lo"
169+
self.CALC.append(f)
170+
171+
f = Field()
172+
f.name = "BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION"
173+
f.block = 0
174+
f.bit_len = 4
175+
f.type = f"uint:{f.bit_len}"
176+
f.category = "config"
177+
f.class_type = "bootloader_anti_rollback"
178+
f.description = "calc ANTI_ROLLBACK_SECURE_VERSION = ANTI_ROLLBACK_SECURE_VERSION_HI << 3 + ANTI_ROLLBACK_SECURE_VERSION_LO"
179+
self.CALC.append(f)
180+
161181
for efuse in self.ALL_EFUSES:
162182
if efuse is not None:
163183
self.EFUSES.append(efuse)

0 commit comments

Comments
 (0)