Skip to content

Commit

Permalink
[ambz2] Implement reading eFuse
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Nov 7, 2023
1 parent c893a8f commit a63b3e6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ltchiptool/soc/ambz2/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
from ltchiptool.util.streams import ProgressCallback
from uf2tool import OTAScheme, UploadContext

from .util.ambz2tool import AmbZ2Tool
from .util.ambz2code import AMBZ2_CODE_EFUSE_READ
from .util.ambz2tool import (
AMBZ2_CODE_ADDR,
AMBZ2_DATA_ADDR,
AMBZ2_EFUSE_PHYSICAL_SIZE,
AmbZ2Tool,
)


class AmebaZ2Flash(SocInterface, ABC):
amb: Optional[AmbZ2Tool] = None

def flash_get_features(self) -> FlashFeatures:
return FlashFeatures(
can_read_efuse=False,
can_read_info=False,
)

Expand Down Expand Up @@ -82,6 +87,8 @@ def flash_get_size(self, memory: FlashMemoryType = FlashMemoryType.FLASH) -> int
return 0x200000
if memory == FlashMemoryType.ROM:
return 384 * 1024
if memory == FlashMemoryType.EFUSE:
return AMBZ2_EFUSE_PHYSICAL_SIZE
raise NotImplementedError("Memory type not readable via UART")

def flash_read_raw(
Expand All @@ -94,6 +101,10 @@ def flash_read_raw(
) -> Generator[bytes, None, None]:
self.flash_connect()
assert self.amb
if memory == FlashMemoryType.EFUSE:
self.amb.register_write_bytes(AMBZ2_CODE_ADDR, AMBZ2_CODE_EFUSE_READ)
self.amb.memory_boot(AMBZ2_CODE_ADDR, force_find=True)
offset |= AMBZ2_DATA_ADDR
gen = self.amb.memory_read(
offset=offset,
length=length,
Expand Down
40 changes: 40 additions & 0 deletions ltchiptool/soc/ambz2/util/ambz2code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) Kuba Szczodrzyński 2023-11-7.

AMBZ2_CODE_EFUSE_READ = (
# push {r3-r5,lr}
# movs r5, #0
# loop:
# ldr r0, EFUSE_CTRL_SETTING
# movs r1, r5
# ldr r2, read_data
# add r2, r5
# movs r3, #0xAA
# strb r3, [r2]
# movs r3, #0
# ldr r4, hal_efuse_stubs
# adds r4, r4, #8
# ldr r4, [r4]
# blx r4
# ldr r3, read_size
# adds r5, r5, #1
# cmp r5, r3
# bne loop
# pop {r3-r5,pc}
# EFUSE_CTRL_SETTING: .word 0x33300000
# hal_efuse_stubs: .word 0x500
# read_size: .word 512
# read_data: .word 0x10038000
b"\x38\xb5\x00\x25"
b"\x07\x48\x29\x00"
b"\x09\x4a\x2a\x44"
b"\xaa\x23\x13\x70"
b"\x00\x23\x05\x4c"
b"\x08\x34\x24\x68"
b"\xa0\x47\x04\x4b"
b"\x6d\x1c\x9d\x42"
b"\xf0\xd1\x38\xbd"
b"\x00\x00\x30\x33" # EFUSE_CTRL_SETTING
b"\x00\x05\x00\x00" # hal_efuse_stubs
b"\x00\x02\x00\x00" # read_size
b"\x00\x80\x03\x10" # read_data
)

0 comments on commit a63b3e6

Please sign in to comment.