Skip to content

Commit fe6885a

Browse files
committed
[ambz2] Generate patched image for OTA
1 parent d8ad636 commit fe6885a

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

ltchiptool/soc/ambz2/binary.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Section,
2929
)
3030
from .util.models.utils import FF_32
31+
from .util.ota import patch_firmware_for_ota
3132

3233

3334
class AmebaZ2Binary(SocInterface, ABC):
@@ -110,6 +111,12 @@ def elf2bin(self, input: str, ota_idx: int) -> List[FirmwareBinary]:
110111
description="Firmware partition image for direct flashing",
111112
public=True,
112113
)
114+
out_ota1_ota = FirmwareBinary(
115+
location=input,
116+
name="firmware_is_ota",
117+
offset=ota1_offset,
118+
title="Application Image for OTA",
119+
)
113120
out_ptab = FirmwareBinary(
114121
location=input,
115122
name="part_table",
@@ -215,6 +222,10 @@ def elf2bin(self, input: str, ota_idx: int) -> List[FirmwareBinary]:
215222
with out_ota1.write() as f:
216223
ota1 = data[ota1_offset:ota1_end]
217224
f.write(ota1)
225+
with out_ota1_ota.write() as f:
226+
ota1 = data[ota1_offset:ota1_end]
227+
ota1_ota = patch_firmware_for_ota(ota1)
228+
f.write(ota1_ota)
218229
return output.group()
219230

220231
def detect_file_type(

ltchiptool/soc/ambz2/util/models/images.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
FLASH_CALIBRATION = b"\x99\x99\x96\x96\x3F\xCC\x66\xFC\xC0\x33\xCC\x03\xE5\xDC\x31\x62"
3131

32+
IMAGE_PUBLIC_KEY_OFFSET = 32
33+
3234

3335
@dataclass
3436
class Image(DataStruct):

ltchiptool/soc/ambz2/util/ota.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) Martin Prokopič 2024-12-02
2+
3+
from .models.images import IMAGE_PUBLIC_KEY_OFFSET
4+
5+
6+
def patch_firmware_for_ota(data: bytes) -> bytes:
7+
copy = bytearray(data)
8+
copy[0] ^= 0xff # negate first signature byte
9+
copy[IMAGE_PUBLIC_KEY_OFFSET] ^= 0xff # negate first pubkey byte
10+
return bytes(copy)

0 commit comments

Comments
 (0)