Skip to content

Commit c85d5e0

Browse files
lamaunykuba2k2
andauthored
[ln882h] Add Lightning LN882H support (#52)
* ln882h support: first version * removed ln882x sdk python scirpts from cli & cleanup * ln882x : added generation of partcfg json file & ota file * removed test files, oops * ln882x: cleanup flash tools because not implemented * ln882x: fix check ota size * [ln882x] update firmware binaries generation with sparate partition images * [ln882h] changed ln882x->ln882h; first flash tools release * [ln882h] reformat * [ln882h] reformat * [ln822h] add ramcode binary * Reformat Python files --------- Co-authored-by: Kuba Szczodrzyński <[email protected]>
1 parent 6415eb3 commit c85d5e0

31 files changed

+1950
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ltchiptool
22

3-
Universal, easy-to-use GUI flashing/dumping tool for BK7231, RTL8710B and RTL8720C. Also contains some CLI utilities for binary firmware manipulation.
3+
Universal, easy-to-use GUI flashing/dumping tool for BK7231, LN882H, RTL8710B and RTL8720C. Also contains some CLI utilities for binary firmware manipulation.
44

55
<div align="center">
66

ltchiptool/commands/soc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"rtltool": "ltchiptool/soc/ambz/util/rtltool.py",
1010
"ambztool": "ltchiptool/soc/ambz/util/ambztool.py",
1111
"ambz2tool": "ltchiptool/soc/ambz2/util/ambz2tool.py",
12+
"ln882htool": "ltchiptool/soc/ln882h/util/ln882htool.py",
1213
}
1314

1415

ltchiptool/soc/amb/system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from datastruct import DataStruct
77
from datastruct.fields import adapter, alignto, bitfield, field
88

9-
FF_16 = b"\xFF" * 16
9+
FF_16 = b"\xff" * 16
1010

1111

1212
class FlashSpeed(IntEnum):

ltchiptool/soc/ambz/binary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ def check_xip_binary(
2424
) -> Optional[Tuple[int, int, bytes]]:
2525
if data[0:8] != header:
2626
return None
27-
if data[16:32] != b"\xFF" * 16:
27+
if data[16:32] != b"\xff" * 16:
2828
return None
2929
length, start = unpack("<II", data[8:16])
3030
return start, length, data[32:]
3131

3232

3333
def check_bootloader_binary(data: bytes) -> Optional[Tuple[int, int, bytes]]:
34-
return check_xip_binary(data, header=b"\x99\x99\x96\x96\x3F\xCC\x66\xFC")
34+
return check_xip_binary(data, header=b"\x99\x99\x96\x96\x3f\xcc\x66\xfc")
3535

3636

3737
class AmebaZBinary(SocInterface, ABC):

ltchiptool/soc/ambz/flash.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def flash_sw_reset(self) -> None:
105105
port.baudrate = 115200
106106
sleep(0.1)
107107
# try software reset by writing the family ID, preceded by 55AA
108-
magic_word = b"\x55\xAA" + self.family.id.to_bytes(length=4, byteorder="big")
108+
magic_word = b"\x55\xaa" + self.family.id.to_bytes(length=4, byteorder="big")
109109
port.write(magic_word)
110110
sleep(0.5)
111111
port.baudrate = prev_baudrate
@@ -178,7 +178,7 @@ def flash_get_chip_info(self) -> List[Tuple[str, str]]:
178178
syscfg2 = letoint(data[256 + 512 + 16 + 8 : 256 + 512 + 16 + 8 + 4])
179179

180180
system_data = data[256 + 512 + 16 + 16 : 256 + 512 + 16 + 16 + 128].ljust(
181-
4096, b"\xFF"
181+
4096, b"\xff"
182182
)
183183
system = SystemData.unpack(system_data)
184184

ltchiptool/soc/ambz/util/ambzcode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def read_efuse_otp(offset: int = 0) -> bytes:
204204
return (
205205
b"\x02\x48\x01\x4b"
206206
b"\x98\x47\x03\xe0"
207-
b"\x21\x3C\x00\x00" # EFUSE_OTP_Read32B()
207+
b"\x21\x3c\x00\x00" # EFUSE_OTP_Read32B()
208208
) + inttole32(AMBZ_DATA_ADDRESS + offset)
209209

210210
@staticmethod

ltchiptool/soc/ambz/util/ambztool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def read(self, io: IO[bytes], n: int) -> bytes:
108108
# increment saved address
109109
self.address += n
110110
# add padding to force sending N+4 packet size
111-
data = data.ljust(n + 4, b"\xFF")
111+
data = data.ljust(n + 4, b"\xff")
112112
return data
113113

114114

ltchiptool/soc/ambz/util/rtltool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
CMD_XMD = b"\x07" # Go xmodem mode (write RAM/Flash mode)
3030
CMD_EFS = b"\x17" # Erase Flash Sectors
3131
CMD_RBF = b"\x19" # Read Block Flash
32-
CMD_ABRT = b"\x1B" # End xmodem mode (write RAM/Flash mode)
32+
CMD_ABRT = b"\x1b" # End xmodem mode (write RAM/Flash mode)
3333
CMD_GFS = b"\x21" # FLASH Get Status
3434
CMD_SFS = b"\x26" # FLASH Set Status
3535

@@ -283,7 +283,7 @@ def send_xmodem(self, stream, offset, size, retry=3):
283283
if not data: # end of stream
284284
print("send: at EOF")
285285
return False
286-
data = data.ljust(packet_size, b"\xFF")
286+
data = data.ljust(packet_size, b"\xff")
287287
pkt = (
288288
struct.pack("<BBBI", ord(cmd), sequence, 0xFF - sequence, offset)
289289
+ data

ltchiptool/soc/ambz2/binary.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def elf2bin(self, input: str, ota_idx: int) -> List[FirmwareBinary]:
134134
nmap_ota1 = self.board.toolchain.nm(input)
135135

136136
# build the partition table
137-
ptable = PartitionTable(user_data=b"\xFF" * 256)
137+
ptable = PartitionTable(user_data=b"\xff" * 256)
138138
for region, type in config.ptable.items():
139139
offset, length, _ = self.board.region(region)
140140
hash_key = config.keys.hash_keys[region]
@@ -205,11 +205,11 @@ def elf2bin(self, input: str, ota_idx: int) -> List[FirmwareBinary]:
205205
with output.write() as f:
206206
f.write(data)
207207
with out_ptab.write() as f:
208-
ptab = data[ptab_offset:ptab_end].rstrip(b"\xFF")
208+
ptab = data[ptab_offset:ptab_end].rstrip(b"\xff")
209209
ptab = pad_data(ptab, 0x20, 0xFF)
210210
f.write(ptab)
211211
with out_boot.write() as f:
212-
boot = data[boot_offset:boot_end].rstrip(b"\xFF")
212+
boot = data[boot_offset:boot_end].rstrip(b"\xff")
213213
boot = pad_data(boot, 0x20, 0xFF)
214214
f.write(boot)
215215
with out_ota1.write() as f:
@@ -230,15 +230,15 @@ def detect_file_type(
230230
return Detection.make("Realtek AmebaZ2 Flash Image", offset=0)
231231

232232
if (
233-
data[0x40:0x44] != b"\xFF\xFF\xFF\xFF"
233+
data[0x40:0x44] != b"\xff\xff\xff\xff"
234234
and data[0x48] == ImageType.BOOT.value
235235
):
236236
return Detection.make("Realtek AmebaZ2 Bootloader", offset=0x4000)
237237

238238
if (
239-
data[0xE0:0xE8].strip(b"\xFF")
239+
data[0xE0:0xE8].strip(b"\xff")
240240
and data[0xE8] == ImageType.FWHS_S.value
241-
and data[0x1A0:0x1A8].strip(b"\xFF")
241+
and data[0x1A0:0x1A8].strip(b"\xff")
242242
and data[0x1A8] == SectionType.SRAM.value
243243
):
244244
return Detection.make("Realtek AmebaZ2 Firmware", offset=None)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from .partitions import Bootloader, Firmware, PartitionTable
2828
from .utils import FF_32
2929

30-
FLASH_CALIBRATION = b"\x99\x99\x96\x96\x3F\xCC\x66\xFC\xC0\x33\xCC\x03\xE5\xDC\x31\x62"
30+
FLASH_CALIBRATION = b"\x99\x99\x96\x96\x3f\xcc\x66\xfc\xc0\x33\xcc\x03\xe5\xdc\x31\x62"
3131

3232

3333
@dataclass

0 commit comments

Comments
 (0)