tplink 2.6 KB

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