firmware 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. #------------------------------------------------------------------------------
  2. # $File: firmware,v 1.17 2025/04/06 18:37:40 christos Exp $
  3. # firmware: file(1) magic for firmware files
  4. #
  5. # https://github.com/MatrixEditor/frontier-smart-api/blob/main/docs/firmware-2.0.md#11-header-structure
  6. # examples: https://github.com/cweiske/frontier-silicon-firmwares
  7. 0 lelong 0x00001176
  8. >4 lelong 0x7c Frontier Silicon firmware download
  9. >>8 lelong x \b, MeOS version %x
  10. >>12 string/32/T x \b, version %s
  11. >>40 string/64/T x \b, customization %s
  12. # HPE iLO firmware update image
  13. # From: Alexandre Iooss <erdnaxe@crans.org>
  14. # URL: https://www.sstic.org/2018/presentation/backdooring_your_server_through_its_bmc_the_hpe_ilo4_case/
  15. # iLO1 (ilo1*.bin) or iLO2 (ilo2_*.bin) images
  16. 0 string \x20\x36\xc1\xce\x60\x37\x62\xf0\x3f\x06\xde\x00\x00\x03\x7f\x00
  17. >16 ubeshort =0xCFDD HPE iLO2 firmware update image
  18. >16 ubeshort =0x6444 HPE iLO1 firmware update image
  19. # iLO3 images (ilo3_*.bin) start directly with image name
  20. 0 string iLO3\x20v\x20 HPE iLO3 firmware update image,
  21. >7 string x version %s
  22. # iLO4 images (ilo4_*.bin) start with a signature and a certificate
  23. 0 string --=</Begin\x20HP\x20Signed
  24. >75 string label_HPBBatch
  25. >>5828 string iLO\x204
  26. >>>5732 string HPIMAGE\x00 HPE iLO4 firmware update image,
  27. >>>6947 string x version %s
  28. # iLO5 images (ilo5_*.bin) start with a signature
  29. >75 string label_HPE-HPB-BMC-ILO5-4096
  30. >>880 string HPIMAGE\x00 HPE iLO5 firmware update image,
  31. >>944 string x version %s
  32. # IBM POWER Secure Boot Container
  33. # from https://github.com/open-power/skiboot/blob/master/libstb/container.h
  34. 0 belong 0x17082011 POWER Secure Boot Container,
  35. >4 beshort x version %u
  36. >6 bequad x container size %llu
  37. # These are always zero
  38. # >14 bequad x target HRMOR %llx
  39. # >22 bequad x stack pointer %llx
  40. >4096 ustring \xFD7zXZ\x00 XZ compressed
  41. 0 belong 0x1bad1bad POWER boot firmware
  42. >256 belong 0x48002030 (PHYP entry point)
  43. # ARM Cortex-M vector table
  44. # From: Alexandre Iooss <erdnaxe@crans.org>
  45. # URL: https://developer.arm.com/documentation/100701/0200/Exception-properties
  46. # Match stack MSB
  47. 3 byte 0x20
  48. # Function pointers must be in Thumb-mode and before 0x20000000 (4*5 bits match)
  49. >4 ulelong&0xE0000001 1
  50. >>8 ulelong&0xE0000001 1
  51. >>>12 ulelong&0xE0000001 1
  52. >>>>44 ulelong&0xE0000001 1
  53. >>>>>56 ulelong&0xE0000001 1
  54. # Match Cortex-M reserved sections (0x00000000 or 0xFFFFFFFF)
  55. >>>>>>28 ulelong+1 <2
  56. >>>>>>>32 ulelong+1 <2
  57. >>>>>>>>36 ulelong+1 <2
  58. >>>>>>>>>40 ulelong+1 <2
  59. >>>>>>>>>>52 ulelong+1 <2 ARM Cortex-M firmware
  60. >>>>>>>>>>>0 ulelong >0 \b, initial SP at 0x%08x
  61. >>>>>>>>>>>4 ulelong^1 x \b, reset at 0x%08x
  62. >>>>>>>>>>>8 ulelong^1 x \b, NMI at 0x%08x
  63. >>>>>>>>>>>12 ulelong^1 x \b, HardFault at 0x%08x
  64. >>>>>>>>>>>44 ulelong^1 x \b, SVCall at 0x%08x
  65. >>>>>>>>>>>56 ulelong^1 x \b, PendSV at 0x%08x
  66. # ESP-IDF partition table entry
  67. # From: Alexandre Iooss <erdnaxe@crans.org>
  68. # URL: https://github.com/espressif/esp-idf/blob/v5.0/components/esp_partition/include/esp_partition.h
  69. 0 string \xAA\x50
  70. >2 ubyte <2 ESP-IDF partition table entry
  71. >>12 string/16 x \b, label: "%s"
  72. >>2 ubyte 0
  73. >>>3 ubyte 0x00 \b, factory app
  74. >>>3 ubyte 0x10 \b, OTA_0 app
  75. >>>3 ubyte 0x11 \b, OTA_1 app
  76. >>>3 ubyte 0x12 \b, OTA_2 app
  77. >>>3 ubyte 0x13 \b, OTA_3 app
  78. >>>3 ubyte 0x14 \b, OTA_4 app
  79. >>>3 ubyte 0x15 \b, OTA_5 app
  80. >>>3 ubyte 0x16 \b, OTA_6 app
  81. >>>3 ubyte 0x17 \b, OTA_7 app
  82. >>>3 ubyte 0x18 \b, OTA_8 app
  83. >>>3 ubyte 0x19 \b, OTA_9 app
  84. >>>3 ubyte 0x1A \b, OTA_10 app
  85. >>>3 ubyte 0x1B \b, OTA_11 app
  86. >>>3 ubyte 0x1C \b, OTA_12 app
  87. >>>3 ubyte 0x1D \b, OTA_13 app
  88. >>>3 ubyte 0x1E \b, OTA_14 app
  89. >>>3 ubyte 0x1F \b, OTA_15 app
  90. >>>3 ubyte 0x20 \b, test app
  91. >>2 ubyte 1
  92. >>>3 ubyte 0x00 \b, OTA selection data
  93. >>>3 ubyte 0x01 \b, PHY init data
  94. >>>3 ubyte 0x02 \b, NVS data
  95. >>>3 ubyte 0x03 \b, coredump data
  96. >>>3 ubyte 0x04 \b, NVS keys
  97. >>>3 ubyte 0x05 \b, emulated eFuse data
  98. >>>3 ubyte 0x06 \b, undefined data
  99. >>>3 ubyte 0x80 \b, ESPHTTPD partition
  100. >>>3 ubyte 0x81 \b, FAT partition
  101. >>>3 ubyte 0x82 \b, SPIFFS partition
  102. >>>3 ubyte 0xFF \b, any data
  103. >>4 ulelong x \b, offset: 0x%X
  104. >>8 ulelong x \b, size: 0x%X
  105. >>28 ulelong&0x1 1 \b, encrypted
  106. # ESP-IDF application image
  107. # From: A. Iooss <aiooss@crans.org>
  108. # Update: Joerg Jenderek
  109. # URL: https://github.com/espressif/esp-idf/blob/v5.0/components/bootloader_support/include/esp_app_format.h
  110. # Reference: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/app_image_format.html
  111. # Note: Concatenation of esp_image_header_t, esp_image_segment_header_t and esp_app_desc_t
  112. # First segment contains esp_app_desc_t
  113. # ESP_IMAGE_HEADER_MAGIC at the beginning of esp_image_header_t structure
  114. 0 ubyte 0xE9
  115. # display ESP-IDF application image (strength=40=40+0) before DOS executable with 16bit JuMP (strength=40) handled by ./msdos
  116. #!:strength +0
  117. # ESP_APP_DESC_MAGIC_WORD; magic for the esp_app_desc_t structure
  118. >32 ulelong 0xABCD5432 ESP-IDF application image
  119. #!:mime application/octet-stream
  120. !:mime application/x-espressif-bin
  121. !:ext bin
  122. >>12 uleshort 0x0000 for ESP32
  123. >>12 uleshort 0x0002 for ESP32-S2
  124. >>12 uleshort 0x0005 for ESP32-C3
  125. >>12 uleshort 0x0009 for ESP32-S3
  126. >>12 uleshort 0x000A for ESP32-H2 Beta1
  127. >>12 uleshort 0x000C for ESP32-C2
  128. >>12 uleshort 0x000D for ESP32-C6
  129. >>12 uleshort 0x000E for ESP32-H2 Beta2
  130. >>12 uleshort 0x0010 for ESP32-H2
  131. >>80 byte !0
  132. >>>80 string/32 x \b, project name: "%s"
  133. >>48 byte !0
  134. >>>48 string/32 x \b, version %s
  135. >>128 string/16 x \b, compiled on %s
  136. >>>112 string/16 x %s
  137. >>144 string/32 x \b, IDF version: %s
  138. >>4 ulelong x \b, entry address: 0x%08X
  139. # ESP8266/ESP32 firmware image
  140. # Note: contain partition table entries and ESP-IDF application image
  141. # From: A. Iooss <aiooss@crans.org>
  142. # Reference: https://docs.espressif.com/projects/esptool/en/latest/esp32/advanced-topics/firmware-image-format.html
  143. 0 byte 0xE9
  144. >2 byte <4
  145. >>7 byte 0x40 ESP firmware image
  146. # ESP8266 does not have Extended File Header
  147. >>>12 uleshort 0x0000 for ESP32
  148. >>>12 uleshort 0x0002 for ESP32-S2
  149. >>>12 uleshort 0x0005 for ESP32-C3
  150. >>>12 uleshort 0x0009 for ESP32-S3
  151. >>>12 uleshort 0x000A for ESP32-H2 Beta1
  152. >>>12 uleshort 0x000C for ESP32-C2
  153. >>>12 uleshort 0x000D for ESP32-C6
  154. >>>12 uleshort 0x000E for ESP32-H2 Beta2
  155. >>>12 uleshort 0x0010 for ESP32-H2
  156. >>>4 ulelong x \b, entry point 0x%08X
  157. # AVR firmware
  158. # From: Alexandre Iooss <erdnaxe@crans.org>
  159. # URL: https://microchipdeveloper.com/8avr:int
  160. # Match 4-byte JMP for Reset, Int0-2, PcInt0-3 and WDT
  161. 0 uleshort&0xFE0E 0x940C
  162. >4 uleshort&0xFE0E 0x940C
  163. >>8 uleshort&0XFE0E 0x940C
  164. >>>12 uleshort&0XFE0E 0x940C
  165. >>>>16 uleshort&0XFE0E 0x940C
  166. >>>>>20 uleshort&0XFE0E 0x940C
  167. >>>>>>24 uleshort&0XFE0E 0x940C
  168. >>>>>>>28 uleshort&0XFE0E 0x940C
  169. >>>>>>>>32 uleshort&0XFE0E 0x940C AVR firmware
  170. # Handle only 16-bit addressing
  171. >>>>>>>>>0 uleshort 0x940C
  172. >>>>>>>>>>2 uleshort x \b, reset at 0x%04x
  173. # Match 2-byte RJMP for Reset, Int0-2, PcInt0-3 and WDT for smaller AVR
  174. 1 byte&0xF0 0xC0
  175. >3 byte&0xF0 0xC0
  176. >>5 byte&0xF0 0xC0
  177. >>>7 byte&0xF0 0xC0
  178. >>>>9 byte&0xF0 0xC0
  179. >>>>>11 byte&0xF0 0xC0
  180. >>>>>>13 byte&0xF0 0xC0
  181. >>>>>>>15 byte&0xF0 0xC0
  182. >>>>>>>>17 byte&0xF0 0xC0 AVR firmware
  183. >>>>>>>>>0 uleshort&0x0FFF x \b, reset at 0x%04x
  184. # Summary: Intel HEXadecimal file format
  185. # URL: https://en.wikipedia.org/wiki/Intel_HEX
  186. # Reference: http://www.piclist.com/techref/fileext/hex/intel.htm
  187. # http://mark0.net/download/triddefs_xml.7z/defs/h/hex-intel.trid.xml
  188. # From: Joerg Jenderek
  189. # Note: called "Intel Hexadecimal object format" by TrID, "Intel(R) hexadecimal object file" on Linux
  190. # and "Intel HEX binary data" by Notepad++
  191. # look for start code; 1 character, an ASCII colon ':'; all characters preceding this symbol should be ignored
  192. 0 ubyte 0x3A
  193. # check for valid record type string with range 00 - 05 (3030h - 3035h)
  194. >&6 ubeshort&0xFFf8 =0x3030
  195. # check for valid record length string like: 02 04 08 10h 20h 03 (usbdload.hex usbdldv2.hex from Windows Vista)
  196. #>>1 string x LENGTH_STRING=%0.2s
  197. #>>1 ubeshort x LENGTH=%#4.4x
  198. >>&-8 ubeshort&0xFCf0 =0x3030
  199. >>>0 use intel-hex
  200. # display information (offset, record length and type) of Intel HEX
  201. 0 name intel-hex
  202. # RECORD MARK
  203. >0 ubyte x Intel hexadecimal object
  204. #!:mime text/plain
  205. !:mime text/x-hex
  206. !:ext hex
  207. # no samples with other suffix found
  208. # .hex .mcs .int .ihex .ihe .ihx .h80 .h86 .a43 .a90 .obj .obl .obh .rom .eep
  209. # .hxl-.hxh .h00-.h15 .p00-.pff
  210. # RECLEN; 2 hex digits for number of bytes in 1st data field; like 0x02 0x03 0x04 0x08 0x10 0x20; maximum 255
  211. >1 string x \b, 0x%2.2s record length
  212. # OFFSET; 4 hex digits for 1st 16-bit memory offset of data like: 0000 (often) 1C00h 1E00h 3800h 3E00h 76EDh 7800h 7E00h ...
  213. >3 string x \b, 0x%4.4s offset
  214. # RECTYP; 2 hex digits (00 - 05); meaning of 1st data field; 00~DataRecord (often) 0l~EndOfFileRecord 02~ExtendedSegmentAddressRecord 03~StartSegmentAddressRecord 04~ExtendedLinearAddressRecord 05~StartLinearAddressRecord
  215. >7 string x \b, '%2.2s' type
  216. # DATA; n bytes of 1st data represented by 2n hex digits followed by 1 byte checksum
  217. >9 string x \b, data+checksum %s
  218. # last record :00000001FF with RECLEN 0, OFFSET 0, record type 01 for EndOfFile and 1 checksum byte FF
  219. # samples with CarriageReturnLineFeed terminator
  220. >-2 ubeshort =0x0d0a
  221. # This should not happen!
  222. >>-13 string !:00000001FF \b, last line %s
  223. >-2 ubeshort !0x0d0a
  224. # samples with LineFeed terminator
  225. >>-1 ubyte =0x0a
  226. # This should not happen!
  227. >>>-12 string !:00000001FF \b, last line %s
  228. # Raspberry Pi RP2040 firmware
  229. # From: Alexandre Iooss <erdnaxe@crans.org>
  230. # Note: RP2040 flash image starts with stage2 bootloader, then a vector table.
  231. # URL: https://github.com/raspberrypi/pico-sdk/tree/1.5.1/src/rp2_common/boot_stage2
  232. # boot2_*.S code (_stage2_boot)
  233. 0 ulelong 0x4B32B500
  234. >4 ulelong 0x60582021
  235. >>8 ulelong 0x21026898
  236. # exit_from_boot2.S code (check_return) `pop {r0}; cmp r0, #0`
  237. >>>148 ulelong 0x2800bc01
  238. # Cortex-M vector table with reserved section filled with a default interrupt address
  239. >>>>259 byte 0x20
  240. # make sure required vector table entries are ARM Thumb and in flash
  241. >>>>>260 ulelong&0xE0000001 1
  242. >>>>>>264 ulelong&0xE0000001 1
  243. >>>>>>>268 ulelong&0xE0000001 1
  244. >>>>>>>>300 ulelong&0xE0000001 1
  245. >>>>>>>>>312 ulelong&0xE0000001 1 Raspberry Pi RP2040 firmware
  246. >>>>>>>>>>256 ulelong >0 \b, initial SP at 0x%08x
  247. >>>>>>>>>>260 ulelong^1 x \b, reset at 0x%08x
  248. >>>>>>>>>>264 ulelong^1 x \b, NMI at 0x%08x
  249. >>>>>>>>>>268 ulelong^1 x \b, HardFault at 0x%08x
  250. >>>>>>>>>>300 ulelong^1 x \b, SVCall at 0x%08x
  251. >>>>>>>>>>312 ulelong^1 x \b, PendSV at 0x%08x
  252. # optional binary_info in the first 256 bytes, used by picotool
  253. # https://github.com/raspberrypi/pico-sdk/blob/master/src/common/pico_binary_info/include/pico/binary_info/defs.h
  254. >>>>>>>>>>256 search/256 \xf2\xeb\x88\x71 \b, with binary_info
  255. # Silicon Labs Gecko Bootloader update image
  256. # From: Alexandre Iooss <erdnaxe@crans.org>
  257. # Reference: https://github.com/raboof/gbl
  258. # https://github.com/dsyx/emberznet-doc
  259. # Note: TLV always starting with tag 0x03A617EB of length 8
  260. 0 ulelong 0x03A617EB
  261. >4 ulelong 8 Silicon Labs Gecko bootloader update image
  262. !:ext gbl
  263. >>12 byte 1 \b, encrypted (AES-CTR-128)
  264. >>13 byte 1 \b, signed (ECDSA-P256)
  265. # If not encrypted, indicate first image type
  266. >>16 ulelong 0xF40A0AF4 \b, application image
  267. >>16 ulelong 0xF50909F5 \b, bootloader image
  268. # Silicon Labs Gecko Bootloader OTA update with Zigbee EmberZNet SDK
  269. # URL: https://github.com/SiliconLabs/gecko_sdk
  270. 0 ulelong 0x0BEEF11E
  271. >6 ulelong 0x38 Silicon Labs Gecko EmberZNet OTA image
  272. !:ext ota/zigbee
  273. >>4 ubeshort x v%d
  274. # Device Firmware Upgrade with ST STMicroelectronics extensions
  275. # From: Alexandre Iooss <erdnaxe@crans.org>
  276. # Reference: STMicroelectronics note UM0391
  277. # Reference: https://dfu-util.sourceforge.net/dfuse.html
  278. # DFU prefix
  279. 0 string DfuSe\x01 DFU image (STM variant)
  280. !:ext dfu
  281. >6 ulelong x \b, size: %d bytes
  282. # DFU suffix, specification 0x011A
  283. >-10 string \x1A\x01UFD
  284. >>-12 uleshort x \b, for device %04X:
  285. >>-14 uleshort x \b%04X
  286. # Allwinner eGON Boot Image
  287. # Reference: https://linux-sunxi.org/EGON
  288. 0 name egon-details
  289. # ARM b instruction
  290. >0 ulelong&0xff000000 0xea000000 (ARM)
  291. # RISC-V jal instruction
  292. >0 ulelong&0x00000fff 0x0000006f (RISC-V)
  293. >16 ulelong x \b, size %u
  294. 4 string eGON.BT0 Allwinner eGON.BT0 Boot Image
  295. >0 use egon-details
  296. 4 string eGON.BT1 Allwinner eGON.BT1 Boot Image
  297. >0 use egon-details
  298. # Allwinner TOC0 Boot Image
  299. # Reference: https://linux-sunxi.org/TOC0
  300. 0 name toc0-item
  301. >0 ulelong 0x010101 certificate
  302. >0 ulelong 0x010202 firmware
  303. >0 ulelong 0x010303 key
  304. >4 ulelong x (offset 0x%x
  305. >8 ulelong x \b, size 0x%x)
  306. 8 ulelong 0x89119800 Allwinner TOC0 Boot Image
  307. >24 ulelong x with %u items
  308. # each item is 32 bytes
  309. # item 0
  310. >24 ulelong >0 \b:
  311. >>48 use toc0-item
  312. # item 1
  313. >24 ulelong >1 \b,
  314. >>80 use toc0-item
  315. # item 2
  316. >24 ulelong >2 \b,
  317. >>112 use toc0-item
  318. # item 3
  319. >24 ulelong >3 \b,
  320. >>144 use toc0-item
  321. # item 4
  322. >24 ulelong >4 \b,
  323. >>176 use toc0-item
  324. # item 5+
  325. >24 ulelong >5 \b, ...
  326. # Allwinner TOC1 Boot Image
  327. # Reference: https://lore.kernel.org/all/20211015040811.56856-2-samuel@sholland.org/T/
  328. 0 name toc1-item
  329. >0 string/64/T x %s
  330. >64 ulelong x (offset 0x%x
  331. >68 ulelong x \b, size 0x%x)
  332. 16 ulelong 0x89119800 Allwinner TOC1 Boot Image
  333. >0 string/16/T >\0 (name "%s")
  334. >32 ulelong x with %u items
  335. # each item is 368 bytes
  336. # item 0
  337. >32 ulelong >0 \b:
  338. >>64 use toc1-item
  339. # item 1
  340. >32 ulelong >1 \b,
  341. >>432 use toc1-item
  342. # item 2
  343. >32 ulelong >2 \b,
  344. >>800 use toc1-item
  345. # item 3
  346. >32 ulelong >3 \b,
  347. >>1168 use toc1-item
  348. # item 4
  349. >32 ulelong >4 \b,
  350. >>1536 use toc1-item
  351. # item 5+
  352. >32 ulelong >5 \b, ...
  353. # https://github.com/o-gs/dji-firmware-tools/blob/master/dji_imah_fwsig.py#L404
  354. 0 string IM*H DJI firmware update
  355. >40 string/4 >\0 (auth %s,
  356. >44 string/4 >\0 enc %s)
  357. >44 string/4 =\0 no enc)
  358. # NXP i.MX RT firmware image
  359. # From: A. Iooss <aiooss@crans.org>
  360. # Reference: Table 8-2 in MCU_Flashloader_Reference_Manual.pdf
  361. # URL: https://github.com/tock/tock/blob/master/boards/teensy40/layout.ld
  362. # Image starts with a NOR FlexSPI Configuration Block (FCB) of 3kB or 4kB
  363. 0 string FCFB
  364. >7 string V NXP i.MX RT bootable image
  365. !:ext bin
  366. >>6 byte x \b, version %d
  367. >>5 byte x \b.%d
  368. >>4 byte x \b.%d
  369. # then a Image Vector Table of 4kB
  370. >>3072 ulelong&0xFCFFFFFF 0x402000D1
  371. >>>7168 use flexspi-fw
  372. >>4096 ulelong&0xFDFFFFFF 0x402000D1
  373. >>>5120 use flexspi-fw
  374. >>4096 ulelong&0xFDFFFFFF 0x412000D1
  375. >>>8192 use flexspi-fw
  376. # then maybe a ARM Cortex-M program, but with vector table pointing to peripheral memory
  377. 0 name flexspi-fw
  378. >3 byte 0x20
  379. >>4 ulelong&1 1
  380. >>>8 ulelong&1 1
  381. >>>>12 ulelong&1 1
  382. >>>>>44 ulelong&1 1
  383. >>>>>>56 ulelong&1 1 \b, ARM Cortex-M
  384. >>>>>>>0 ulelong >0 \b, initial SP at 0x%08x
  385. >>>>>>>4 ulelong^1 x \b, reset at 0x%08x
  386. >>>>>>>8 ulelong^1 x \b, NMI at 0x%08x
  387. >>>>>>>12 ulelong^1 x \b, HardFault at 0x%08x
  388. >>>>>>>44 ulelong^1 x \b, SVCall at 0x%08x
  389. >>>>>>>56 ulelong^1 x \b, PendSV at 0x%08x