mirror of
https://github.com/espressif/esptool.git
synced 2025-10-18 18:01:15 +08:00
feat(espefuse): Adds efuse calculation fields for ESP32-C5
This commit is contained in:

committed by
Radim Karniš

parent
c1025103a7
commit
9104038d00
@@ -301,20 +301,55 @@ class EfuseField(base_fields.EfuseFieldBase):
|
|||||||
"keypurpose": EfuseKeyPurposeField,
|
"keypurpose": EfuseKeyPurposeField,
|
||||||
"t_sensor": EfuseTempSensor,
|
"t_sensor": EfuseTempSensor,
|
||||||
"adc_tp": EfuseAdcPointCalibration,
|
"adc_tp": EfuseAdcPointCalibration,
|
||||||
"wafer": EfuseWafer,
|
"recovery_bootloader": EfuseBtldrRecoveryField,
|
||||||
|
"bootloader_anti_rollback": EfuseBtldrAntiRollbackField,
|
||||||
}.get(efuse.class_type, EfuseField)(parent, efuse)
|
}.get(efuse.class_type, EfuseField)(parent, efuse)
|
||||||
|
|
||||||
|
|
||||||
class EfuseWafer(EfuseField):
|
class EfuseBtldrRecoveryField(EfuseField):
|
||||||
def get(self, from_read=True):
|
def get(self, from_read=True):
|
||||||
hi_bits = self.parent["WAFER_VERSION_MINOR_HI"].get(from_read)
|
hi_bits = self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_HI"].get(from_read)
|
||||||
assert self.parent["WAFER_VERSION_MINOR_HI"].bit_len == 1
|
assert self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_HI"].bit_len == 3
|
||||||
lo_bits = self.parent["WAFER_VERSION_MINOR_LO"].get(from_read)
|
lo_bits = self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_LO"].get(from_read)
|
||||||
assert self.parent["WAFER_VERSION_MINOR_LO"].bit_len == 3
|
assert self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_LO"].bit_len == 9
|
||||||
|
return (hi_bits << 9) + lo_bits
|
||||||
|
|
||||||
|
def save(self, new_value):
|
||||||
|
efuse = self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_HI"]
|
||||||
|
efuse.save((new_value >> 9) & 3)
|
||||||
|
print(
|
||||||
|
f"\t - '{efuse.name}' {efuse.get_bitstring()} -> {efuse.get_bitstring(from_read=False)}"
|
||||||
|
)
|
||||||
|
efuse = self.parent["RECOVERY_BOOTLOADER_FLASH_SECTOR_LO"]
|
||||||
|
efuse.save(new_value & 0x1FF)
|
||||||
|
print(
|
||||||
|
f"\t - '{efuse.name}' {efuse.get_bitstring()} -> {efuse.get_bitstring(from_read=False)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EfuseBtldrAntiRollbackField(EfuseField):
|
||||||
|
def get(self, from_read=True):
|
||||||
|
hi_bits = self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_HI"].get(
|
||||||
|
from_read
|
||||||
|
)
|
||||||
|
assert self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_HI"].bit_len == 1
|
||||||
|
lo_bits = self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_LO"].get(
|
||||||
|
from_read
|
||||||
|
)
|
||||||
|
assert self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_LO"].bit_len == 3
|
||||||
return (hi_bits << 3) + lo_bits
|
return (hi_bits << 3) + lo_bits
|
||||||
|
|
||||||
def save(self, new_value):
|
def save(self, new_value):
|
||||||
raise esptool.FatalError("Burning %s is not supported" % self.name)
|
efuse = self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_HI"]
|
||||||
|
efuse.save((new_value >> 3) & 1)
|
||||||
|
print(
|
||||||
|
f"\t - '{efuse.name}' {efuse.get_bitstring()} -> {efuse.get_bitstring(from_read=False)}"
|
||||||
|
)
|
||||||
|
efuse = self.parent["BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION_LO"]
|
||||||
|
efuse.save(new_value & 0x7)
|
||||||
|
print(
|
||||||
|
f"\t - '{efuse.name}' {efuse.get_bitstring()} -> {efuse.get_bitstring(from_read=False)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EfuseTempSensor(EfuseField):
|
class EfuseTempSensor(EfuseField):
|
||||||
|
@@ -158,6 +158,26 @@ class EfuseDefineFields(EfuseFieldsBase):
|
|||||||
f.description = "calc MAC_EUI64 = MAC[0]:MAC[1]:MAC[2]:MAC_EXT[0]:MAC_EXT[1]:MAC[3]:MAC[4]:MAC[5]"
|
f.description = "calc MAC_EUI64 = MAC[0]:MAC[1]:MAC[2]:MAC_EXT[0]:MAC_EXT[1]:MAC[3]:MAC[4]:MAC[5]"
|
||||||
self.CALC.append(f)
|
self.CALC.append(f)
|
||||||
|
|
||||||
|
f = Field()
|
||||||
|
f.name = "RECOVERY_BOOTLOADER_FLASH_SECTOR"
|
||||||
|
f.block = 0
|
||||||
|
f.bit_len = 12
|
||||||
|
f.type = f"uint:{f.bit_len}"
|
||||||
|
f.category = "config"
|
||||||
|
f.class_type = "recovery_bootloader"
|
||||||
|
f.description = "calc recovery_bootloader = recovery_bootloader_hi << 9 + recovery_bootloader_lo"
|
||||||
|
self.CALC.append(f)
|
||||||
|
|
||||||
|
f = Field()
|
||||||
|
f.name = "BOOTLOADER_ANTI_ROLLBACK_SECURE_VERSION"
|
||||||
|
f.block = 0
|
||||||
|
f.bit_len = 4
|
||||||
|
f.type = f"uint:{f.bit_len}"
|
||||||
|
f.category = "config"
|
||||||
|
f.class_type = "bootloader_anti_rollback"
|
||||||
|
f.description = "calc ANTI_ROLLBACK_SECURE_VERSION = ANTI_ROLLBACK_SECURE_VERSION_HI << 3 + ANTI_ROLLBACK_SECURE_VERSION_LO"
|
||||||
|
self.CALC.append(f)
|
||||||
|
|
||||||
for efuse in self.ALL_EFUSES:
|
for efuse in self.ALL_EFUSES:
|
||||||
if efuse is not None:
|
if efuse is not None:
|
||||||
self.EFUSES.append(efuse)
|
self.EFUSES.append(efuse)
|
||||||
|
Reference in New Issue
Block a user