Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Realtek RTL8720CF #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 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,9 @@

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

IMAGE_SIGNATURE_OFFSET = 0
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, IMAGE_SIGNATURE_OFFSET


def patch_firmware_for_ota(data: bytes) -> bytes:
copy = bytearray(data)
copy[IMAGE_SIGNATURE_OFFSET] ^= 0xFF # negate first signature byte
copy[IMAGE_PUBLIC_KEY_OFFSET] ^= 0xFF # negate first pubkey byte
return bytes(copy)
7 changes: 7 additions & 0 deletions uf2tool/models/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def get_offset(self, part: str, offs: int) -> Optional[int]:
return None
return start + offs

def rewind(self) -> None:
self.seq = 0

def read_next(self, scheme: OTAScheme) -> Optional[Tuple[str, int, bytes]]:
"""
Read next available data block for the specified OTA scheme.
Expand Down Expand Up @@ -152,6 +155,10 @@ def collect_data(self, scheme: OTAScheme) -> Optional[Dict[int, BytesIO]]:
if not self.board_name:
raise ValueError("This UF2 is not readable, since no board name is present")

# rewind to the beginning of the UF2 so collect_data can be called
# multiple times
self.rewind()

out: Dict[int, BytesIO] = {}
while True:
ret = self.read_next(scheme)
Expand Down
Loading