Skip to content

Commit cffaf0e

Browse files
committed
Return board info
1 parent ec42aa2 commit cffaf0e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ U-Boot compiler: mipsel-24kec-linux-uclibc-gcc.br_real (Buildroot 2015.11.1
8787
U-Boot linker: GNU ld (GNU Binutils) 2.24
8888
File system: squashfs
8989
File system sections: fs
90+
Board vendor: Novatek
91+
Board: Novatek NA51023 evaluation board
9092
```
9193

9294
Or with JSON output:
@@ -110,6 +112,8 @@ $ reolinkfw info RLC-410-5MP_20_20052300.zip -j 2
110112
"uboot_compiler": "mipsel-24kec-linux-uclibc-gcc.br_real (Buildroot 2015.11.1-00003-gfd1edb1) 4.9.3",
111113
"uboot_linker": "GNU ld (GNU Binutils) 2.24",
112114
"linux_banner": "Linux version 4.1.0 (lwy@ubuntu) (gcc version 4.9.3 (Buildroot 2015.11.1-00003-gfd1edb1) ) #1 PREEMPT Tue Feb 26 18:19:48 CST 2019",
115+
"board": "Novatek NA51023 evaluation board",
116+
"board_vendor": "Novatek",
113117
"filesystems": [
114118
{
115119
"name": "fs",

reolinkfw/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ def fdt_json(self) -> Optional[dict[str, Any]]:
160160
return literal_eval(self.fdt.to_json().replace("null", "None"))
161161
return None
162162

163+
@property
164+
def board(self) -> Optional[str]:
165+
if self.fdt_json is not None:
166+
return self.fdt_json["model"][1]
167+
return None
168+
163169
def _fdclose(self, fd: BinaryIO) -> None:
164170
self._open_files -= 1
165171
if self._closefd and not self._open_files:
@@ -294,6 +300,22 @@ def get_kernel_config(self) -> Optional[bytes]:
294300
return gzip.decompress(match.group(1))
295301
return None
296302

303+
def get_vendor(self) -> Optional[str]:
304+
map_ = {
305+
"novatek": "Novatek",
306+
"sstar": "MStar/SigmaStar",
307+
"hisilicon": "HiSilicon",
308+
}
309+
if self.fdt_json is not None:
310+
key = self.fdt_json["compatible"][1].split(',')[0]
311+
return map_.get(key.lower(), key)
312+
with self.open(self["uboot"]) as f:
313+
if re.match(b"GM[0-9]{4}", f.read(6)):
314+
return "Grain Media"
315+
if re.search(b"HISILICON LOGO MAGIC", self.uboot_section) is not None:
316+
return "HiSilicon"
317+
return None
318+
297319
def get_fs_info(self) -> list[dict[str, str]]:
298320
result = []
299321
for section in self._fs_sections:
@@ -332,6 +354,8 @@ async def get_info(self) -> dict[str, Any]:
332354
"uboot_compiler": compiler,
333355
"uboot_linker": linker,
334356
"linux_banner": self.get_linux_banner(),
357+
"board": self.board or "Unknown",
358+
"board_vendor": self.get_vendor() or "Unknown",
335359
"filesystems": self.get_fs_info(),
336360
"sha256": ha
337361
}

reolinkfw/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ async def info(args: Namespace) -> None:
3838
print(f"{'U-Boot linker:':{width}}", info.uboot_linker or "Unknown")
3939
print(f"{'File system:':{width}}", ', '.join(sorted(fs_types)))
4040
print(f"{'File system sections:':{width}}", ', '.join(fs_names))
41+
print(f"{'Board vendor:':{width}}", info.board_vendor or "Unknown")
42+
print(f"{'Board:':{width}}", info.board or "Unknown")
4143
if idx != len(pak_infos) - 1:
4244
print()
4345
else:

0 commit comments

Comments
 (0)