xref: /freebsd/contrib/file/magic/Magdir/tplink (revision cc426dd31990b8b50b210efc450e404596548ca1)
1
2#------------------------------------------------------------------------------
3# $File: tplink,v 1.2 2017/12/14 05:52:56 christos Exp $
4# tplink: File magic for openwrt firmware files
5
6# URL: https://wiki.openwrt.org/doc/techref/header
7# Reference: http://git.openwrt.org/?p=openwrt.git;a=blob;f=tools/firmware-utils/src/mktplinkfw.c
8# From: Joerg Jenderek
9# check for valid header version 1 or 2
100		ulelong		<3
11>0		ulelong		!0
12# test for header padding with nulls
13>>0x100		long		0
14>>>0		use		firmware-tplink
15
160		name		firmware-tplink
17>0		ubyte		x		firmware
18!:mime application/x-tplink-bin
19!:ext	bin
20# hardware id like 10430001 07410001 09410004 09410006
21>0x40		ubeshort	x		%x
22>0x42		ubeshort	x		v%x
23# hardware revision like 1
24>0x44		ubelong		!1		(revision %u)
25# vendor_name[24] like OpenWrt or TP-LINK Technologies
26>4		string		x		%.24s
27# fw_version[36] like r49389 or ver. 1.0
28>0x1c		string		x		%.36s
29# header version 1 or 2
30>0		ubyte		!1		V%X
31# ver_hi.ver_mid.ver_lo
32>0x98		long		!0		\b, version
33>>0x98		ubeshort	x		%u
34>>0x9A		ubeshort	x		\b.%u
35>>0x9C		ubeshort	x		\b.%u
36# region code 0~universal 1~US
37>0x48		ubelong		x
38#>>0x48		ubelong		0		(universal)
39>>0x48		ubelong		1		(US)
40>>0x48		ubelong		>1		(region %u)
41# total length of the firmware. not always true
42>0x7C		ubelong		x		\b, %u bytes or less
43# unknown 1
44>0x48		ubelong		!0		\b, UNKNOWN1 0x%x
45# md5sum1[16]
46#>0x4c		ubequad		x		\b, MD5 %llx
47#>>0x54		ubequad		x		\b%llx
48# unknown 2
49>0x5c		ubelong		!0		\b, UNKNOWN2 0x%x
50# md5sum2[16]
51#>0x60		ubequad		!0		\b, 2nd MD5 %llx
52#>>0x68		ubequad		x		\b%llx
53# unknown 3
54>0x70		ubelong		!0		\b, UNKNOWN3 0x%x
55# kernel load address
56#>0x74		ubelong		x		\b, 0x%x load
57# kernel entry point
58#>0x78		ubelong		x		\b, 0x%x entry
59# kernel data offset. 200h means direct after header
60>0x80		ubelong		x		\b, at 0x%x
61# kernel data length and 1 space
62>0x84		ubelong		x		%u bytes
63# look for kernel type (gzip compressed vmlinux.bin by ./compress)
64>(0x80.L)	indirect	x
65# root file system data offset
66>0x88		ubelong		x		\b, at 0x%x
67# rootfs data length and 1 space
68>0x8C		ubelong		x		%u bytes
69# in 5.32 only true for offset ~< FILE_BYTES_MAX=9 MB defined in ../../src/file.h
70>(0x88.L)	indirect	x
71#>(0x88.L)	string		x		\b, file system '%.4s'
72#>(0x88.L)	ubequad		x		\b, file system 0x%llx
73# bootloader data offset
74>0x90		ubelong		!0		\b, at 0x%x
75# bootloader data length only resonable if bootloader offset not null
76>>0x94		ubelong		!0		%u bytes
77# pad[354] should be 354 null bytes.
78#>0x9E		ubequad		!0		\b, padding 0x%llx
79# But at 0x120 18 non null bytes in examples like
80# wr940nv4_eu_3_16_9_up_boot(160620).bin
81# wr940nv6_us_3_18_1_up_boot(171030).bin
82#>0x120		ubequad		!0		\b, other padding 0x%llx
83