Skip to content

Commit

Permalink
[ambz2] Generate patched image for OTA
Browse files Browse the repository at this point in the history
  • Loading branch information
prokoma committed Dec 2, 2024
1 parent edaa767 commit ae07966
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ltchiptool/soc/ambz2/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Section,
)
from .util.models.utils import FF_32
from .util.ota import patch_firmware_for_ota


class AmebaZ2Binary(SocInterface, ABC):
Expand Down Expand Up @@ -110,6 +111,12 @@ def elf2bin(self, input: str, ota_idx: int) -> List[FirmwareBinary]:
description="Firmware partition image for direct flashing",
public=True,
)
out_ota1_ota = FirmwareBinary(
location=input,
name="firmware_is_ota",
offset=ota1_offset,
title="Application Image for OTA",
)
out_ptab = FirmwareBinary(
location=input,
name="part_table",
Expand Down Expand Up @@ -215,6 +222,10 @@ def elf2bin(self, input: str, ota_idx: int) -> List[FirmwareBinary]:
with out_ota1.write() as f:
ota1 = data[ota1_offset:ota1_end]
f.write(ota1)
with out_ota1_ota.write() as f:
ota1 = data[ota1_offset:ota1_end]
ota1_ota = patch_firmware_for_ota(ota1)
f.write(ota1_ota)
return output.group()

def detect_file_type(
Expand Down
2 changes: 2 additions & 0 deletions ltchiptool/soc/ambz2/util/models/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

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

IMAGE_PUBLIC_KEY_OFFSET = 32


@dataclass
class Image(DataStruct):
Expand Down
10 changes: 10 additions & 0 deletions ltchiptool/soc/ambz2/util/ota.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Martin Prokopič 2024-12-02

from .models.images import IMAGE_PUBLIC_KEY_OFFSET


def patch_firmware_for_ota(data: bytes) -> bytes:
copy = bytearray(data)
copy[0] ^= 0xff # negate first signature byte
copy[IMAGE_PUBLIC_KEY_OFFSET] ^= 0xff # negate first pubkey byte
return bytes(copy)

0 comments on commit ae07966

Please sign in to comment.