xref: /freebsd/contrib/file/magic/Magdir/firmware (revision ae316d1d1cffd71ab7751f94e10118777a88e027)
1898496eeSXin LI#------------------------------------------------------------------------------
2*ae316d1dSXin LI# $File: firmware,v 1.13 2024/09/04 19:04:03 christos Exp $
3898496eeSXin LI# firmware:  file(1) magic for firmware files
4898496eeSXin LI#
5898496eeSXin LI
6898496eeSXin LI# https://github.com/MatrixEditor/frontier-smart-api/blob/main/docs/firmware-2.0.md#11-header-structure
7898496eeSXin LI# examples: https://github.com/cweiske/frontier-silicon-firmwares
8898496eeSXin LI0	lelong		0x00001176
9898496eeSXin LI>4	lelong		0x7c		Frontier Silicon firmware download
10898496eeSXin LI>>8	lelong		x		\b, MeOS version %x
11898496eeSXin LI>>12	string/32/T	x		\b, version %s
12898496eeSXin LI>>40	string/64/T	x		\b, customization %s
13898496eeSXin LI
14898496eeSXin LI# HPE iLO firmware update image
15898496eeSXin LI# From: Alexandre Iooss <erdnaxe@crans.org>
16898496eeSXin LI# URL: https://www.sstic.org/2018/presentation/backdooring_your_server_through_its_bmc_the_hpe_ilo4_case/
17898496eeSXin LI# iLO1 (ilo1*.bin) or iLO2 (ilo2_*.bin) images
18898496eeSXin LI0               string                  \x20\x36\xc1\xce\x60\x37\x62\xf0\x3f\x06\xde\x00\x00\x03\x7f\x00
19898496eeSXin LI>16             ubeshort                =0xCFDD         HPE iLO2 firmware update image
20898496eeSXin LI>16             ubeshort                =0x6444         HPE iLO1 firmware update image
21898496eeSXin LI# iLO3 images (ilo3_*.bin) start directly with image name
22898496eeSXin LI0               string                  iLO3\x20v\x20   HPE iLO3 firmware update image,
23898496eeSXin LI>7              string                  x               version %s
24898496eeSXin LI# iLO4 images (ilo4_*.bin) start with a signature and a certificate
25898496eeSXin LI0               string                  --=</Begin\x20HP\x20Signed
26898496eeSXin LI>75             string                  label_HPBBatch
27898496eeSXin LI>>5828          string                  iLO\x204
28898496eeSXin LI>>>5732         string                  HPIMAGE\x00     HPE iLO4 firmware update image,
29898496eeSXin LI>>>6947         string                  x               version %s
30898496eeSXin LI# iLO5 images (ilo5_*.bin) start with a signature
31898496eeSXin LI>75             string                  label_HPE-HPB-BMC-ILO5-4096
32898496eeSXin LI>>880           string                  HPIMAGE\x00     HPE iLO5 firmware update image,
33898496eeSXin LI>>944           string                  x               version %s
34898496eeSXin LI
35898496eeSXin LI# IBM POWER Secure Boot Container
36898496eeSXin LI# from https://github.com/open-power/skiboot/blob/master/libstb/container.h
37898496eeSXin LI0	belong	0x17082011	POWER Secure Boot Container,
38898496eeSXin LI>4	beshort	x		version %u
39898496eeSXin LI>6	bequad	x		container size %llu
40898496eeSXin LI# These are always zero
41898496eeSXin LI# >14	bequad	x		target HRMOR %llx
42898496eeSXin LI# >22	bequad  x		stack pointer %llx
43898496eeSXin LI>4096	ustring \xFD7zXZ\x00    XZ compressed
44898496eeSXin LI0	belong	0x1bad1bad	POWER boot firmware
45898496eeSXin LI>256	belong	0x48002030	(PHYP entry point)
46898496eeSXin LI
47898496eeSXin LI# ARM Cortex-M vector table
48898496eeSXin LI# From: Alexandre Iooss <erdnaxe@crans.org>
49898496eeSXin LI# URL: https://developer.arm.com/documentation/100701/0200/Exception-properties
50898496eeSXin LI# Match stack MSB
51898496eeSXin LI3		byte			0x20
52898496eeSXin LI# Function pointers must be in Thumb-mode and before 0x20000000 (4*5 bits match)
53898496eeSXin LI>4		ulelong&0xE0000001	1
54898496eeSXin LI>>8		ulelong&0xE0000001	1
55898496eeSXin LI>>>12		ulelong&0xE0000001	1
56898496eeSXin LI>>>>44		ulelong&0xE0000001	1
57898496eeSXin LI>>>>>56		ulelong&0xE0000001	1
58898496eeSXin LI# Match Cortex-M reserved sections (0x00000000 or 0xFFFFFFFF)
59898496eeSXin LI>>>>>>28	ulelong+1		<2
60898496eeSXin LI>>>>>>>32	ulelong+1		<2
61898496eeSXin LI>>>>>>>>36	ulelong+1		<2
62898496eeSXin LI>>>>>>>>>40	ulelong+1		<2
63898496eeSXin LI>>>>>>>>>>52	ulelong+1		<2	ARM Cortex-M firmware
64898496eeSXin LI>>>>>>>>>>>0	ulelong			>0	\b, initial SP at 0x%08x
65898496eeSXin LI>>>>>>>>>>>4	ulelong^1		x	\b, reset at 0x%08x
66898496eeSXin LI>>>>>>>>>>>8	ulelong^1		x	\b, NMI at 0x%08x
67898496eeSXin LI>>>>>>>>>>>12	ulelong^1		x	\b, HardFault at 0x%08x
68898496eeSXin LI>>>>>>>>>>>44	ulelong^1		x	\b, SVCall at 0x%08x
69898496eeSXin LI>>>>>>>>>>>56	ulelong^1		x	\b, PendSV at 0x%08x
70898496eeSXin LI
71898496eeSXin LI# ESP-IDF partition table entry
72898496eeSXin LI# From: Alexandre Iooss <erdnaxe@crans.org>
73898496eeSXin LI# URL: https://github.com/espressif/esp-idf/blob/v5.0/components/esp_partition/include/esp_partition.h
74898496eeSXin LI0	string		\xAA\x50
75898496eeSXin LI>2	ubyte		<2		ESP-IDF partition table entry
76898496eeSXin LI>>12	string/16	x		\b, label: "%s"
77898496eeSXin LI>>2	ubyte		0
78898496eeSXin LI>>>3	ubyte		0x00		\b, factory app
79898496eeSXin LI>>>3	ubyte		0x10		\b, OTA_0 app
80898496eeSXin LI>>>3	ubyte		0x11		\b, OTA_1 app
81898496eeSXin LI>>>3	ubyte		0x12		\b, OTA_2 app
82898496eeSXin LI>>>3	ubyte		0x13		\b, OTA_3 app
83898496eeSXin LI>>>3	ubyte		0x14		\b, OTA_4 app
84898496eeSXin LI>>>3	ubyte		0x15		\b, OTA_5 app
85898496eeSXin LI>>>3	ubyte		0x16		\b, OTA_6 app
86898496eeSXin LI>>>3	ubyte		0x17		\b, OTA_7 app
87898496eeSXin LI>>>3	ubyte		0x18		\b, OTA_8 app
88898496eeSXin LI>>>3	ubyte		0x19		\b, OTA_9 app
89898496eeSXin LI>>>3	ubyte		0x1A		\b, OTA_10 app
90898496eeSXin LI>>>3	ubyte		0x1B		\b, OTA_11 app
91898496eeSXin LI>>>3	ubyte		0x1C		\b, OTA_12 app
92898496eeSXin LI>>>3	ubyte		0x1D		\b, OTA_13 app
93898496eeSXin LI>>>3	ubyte		0x1E		\b, OTA_14 app
94898496eeSXin LI>>>3	ubyte		0x1F		\b, OTA_15 app
95898496eeSXin LI>>>3	ubyte		0x20		\b, test app
96898496eeSXin LI>>2	ubyte		1
97898496eeSXin LI>>>3	ubyte		0x00		\b, OTA selection data
98898496eeSXin LI>>>3	ubyte		0x01		\b, PHY init data
99898496eeSXin LI>>>3	ubyte		0x02		\b, NVS data
100898496eeSXin LI>>>3	ubyte		0x03		\b, coredump data
101898496eeSXin LI>>>3	ubyte		0x04		\b, NVS keys
102898496eeSXin LI>>>3	ubyte		0x05		\b, emulated eFuse data
103898496eeSXin LI>>>3	ubyte		0x06		\b, undefined data
104898496eeSXin LI>>>3	ubyte		0x80		\b, ESPHTTPD partition
105898496eeSXin LI>>>3	ubyte		0x81		\b, FAT partition
106898496eeSXin LI>>>3	ubyte		0x82		\b, SPIFFS partition
107898496eeSXin LI>>>3	ubyte		0xFF		\b, any data
108898496eeSXin LI>>4	ulelong		x		\b, offset: 0x%X
109898496eeSXin LI>>8	ulelong		x		\b, size: 0x%X
110898496eeSXin LI>>28	ulelong&0x1	1		\b, encrypted
111898496eeSXin LI
112898496eeSXin LI# ESP-IDF application image
113898496eeSXin LI# From: Alexandre Iooss <erdnaxe@crans.org>
114*ae316d1dSXin LI# Update:	Joerg Jenderek
115898496eeSXin LI# URL: https://github.com/espressif/esp-idf/blob/v5.0/components/bootloader_support/include/esp_app_format.h
116*ae316d1dSXin LI# Reference:	https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/app_image_format.html
117898496eeSXin LI# Note: Concatenation of esp_image_header_t, esp_image_segment_header_t and esp_app_desc_t
118898496eeSXin LI# 	First segment contains esp_app_desc_t
119*ae316d1dSXin LI# ESP_IMAGE_HEADER_MAGIC at the beginning of esp_image_header_t structure
120898496eeSXin LI0	ubyte		0xE9
121*ae316d1dSXin LI# display ESP-IDF application image (strength=40=40+0) before DOS executable with 16bit JuMP (strength=40) handled by ./msdos
122*ae316d1dSXin LI#!:strength	+0
123*ae316d1dSXin LI# ESP_APP_DESC_MAGIC_WORD; magic for the esp_app_desc_t structure
124898496eeSXin LI>32	ulelong		0xABCD5432	ESP-IDF application image
125*ae316d1dSXin LI#!:mime	application/octet-stream
126*ae316d1dSXin LI!:mime	application/x-espressif-bin
127*ae316d1dSXin LI!:ext	bin
128898496eeSXin LI>>12	uleshort	0x0000		for ESP32
129898496eeSXin LI>>12	uleshort	0x0002		for ESP32-S2
130898496eeSXin LI>>12	uleshort	0x0005		for ESP32-C3
131898496eeSXin LI>>12	uleshort	0x0009		for ESP32-S3
132898496eeSXin LI>>12	uleshort	0x000A		for ESP32-H2 Beta1
133898496eeSXin LI>>12	uleshort	0x000C		for ESP32-C2
134898496eeSXin LI>>12	uleshort	0x000D		for ESP32-C6
135898496eeSXin LI>>12	uleshort	0x000E		for ESP32-H2 Beta2
136898496eeSXin LI>>12	uleshort	0x0010		for ESP32-H2
137898496eeSXin LI>>80	string/32	x		\b, project name: "%s"
138898496eeSXin LI>>48	string/32	x		\b, version %s
139898496eeSXin LI>>128	string/16	x		\b, compiled on %s
140898496eeSXin LI>>>112	string/16	x		%s
141898496eeSXin LI>>144	string/32	x		\b, IDF version: %s
142898496eeSXin LI>>4	ulelong		x		\b, entry address: 0x%08X
143*ae316d1dSXin LI
144*ae316d1dSXin LI# AVR firmware
145*ae316d1dSXin LI# From: Alexandre Iooss <erdnaxe@crans.org>
146*ae316d1dSXin LI# URL: https://microchipdeveloper.com/8avr:int
147*ae316d1dSXin LI# Match 4-byte JMP for Reset, Int0-2, PcInt0-3 and WDT
148*ae316d1dSXin LI0		uleshort&0xFE0E	0x940C
149*ae316d1dSXin LI>4		uleshort&0xFE0E	0x940C
150*ae316d1dSXin LI>>8		uleshort&0XFE0E	0x940C
151*ae316d1dSXin LI>>>12		uleshort&0XFE0E	0x940C
152*ae316d1dSXin LI>>>>16		uleshort&0XFE0E	0x940C
153*ae316d1dSXin LI>>>>>20		uleshort&0XFE0E	0x940C
154*ae316d1dSXin LI>>>>>>24	uleshort&0XFE0E	0x940C
155*ae316d1dSXin LI>>>>>>>28	uleshort&0XFE0E	0x940C
156*ae316d1dSXin LI>>>>>>>>32	uleshort&0XFE0E	0x940C	AVR firmware
157*ae316d1dSXin LI# Handle only 16-bit addressing
158*ae316d1dSXin LI>>>>>>>>>0	uleshort	0x940C
159*ae316d1dSXin LI>>>>>>>>>>2	uleshort	x	\b, reset at 0x%04x
160*ae316d1dSXin LI# Match 2-byte RJMP for Reset, Int0-2, PcInt0-3 and WDT for smaller AVR
161*ae316d1dSXin LI1		byte&0xF0	0xC0
162*ae316d1dSXin LI>3		byte&0xF0	0xC0
163*ae316d1dSXin LI>>5		byte&0xF0	0xC0
164*ae316d1dSXin LI>>>7		byte&0xF0	0xC0
165*ae316d1dSXin LI>>>>9		byte&0xF0	0xC0
166*ae316d1dSXin LI>>>>>11		byte&0xF0	0xC0
167*ae316d1dSXin LI>>>>>>13	byte&0xF0	0xC0
168*ae316d1dSXin LI>>>>>>>15	byte&0xF0	0xC0
169*ae316d1dSXin LI>>>>>>>>17	byte&0xF0	0xC0	AVR firmware
170*ae316d1dSXin LI>>>>>>>>>0	uleshort&0x0FFF	x	\b, reset at 0x%04x
171*ae316d1dSXin LI
172*ae316d1dSXin LI# Summary:	Intel HEXadecimal file format
173*ae316d1dSXin LI# URL:		https://en.wikipedia.org/wiki/Intel_HEX
174*ae316d1dSXin LI# Reference:	http://www.piclist.com/techref/fileext/hex/intel.htm
175*ae316d1dSXin LI#		http://mark0.net/download/triddefs_xml.7z/defs/h/hex-intel.trid.xml
176*ae316d1dSXin LI# From:		Joerg Jenderek
177*ae316d1dSXin LI# Note:		called "Intel Hexadecimal object format" by TrID, "Intel� hexadecimal object file" on Linux
178*ae316d1dSXin LI#		and "Intel HEX binary data" by Notepad++
179*ae316d1dSXin LI# look for start code; 1 character, an ASCII colon ':'; all characters preceding this symbol should be ignored
180*ae316d1dSXin LI0	ubyte		0x3A
181*ae316d1dSXin LI# check for valid record type string with range 00 - 05 (3030h - 3035h)
182*ae316d1dSXin LI>&6	ubeshort&0xFFf8	=0x3030
183*ae316d1dSXin LI# check for valid record length string like: 02 04 08 10h 20h 03 (usbdload.hex usbdldv2.hex from Windows Vista)
184*ae316d1dSXin LI#>>1	string		x		LENGTH_STRING=%0.2s
185*ae316d1dSXin LI#>>1	ubeshort	x		LENGTH=%#4.4x
186*ae316d1dSXin LI>>&-8	ubeshort&0xFCf0	=0x3030
187*ae316d1dSXin LI>>>0	use		intel-hex
188*ae316d1dSXin LI#	display information (offset, record length and type) of Intel HEX
189*ae316d1dSXin LI0	name		intel-hex
190*ae316d1dSXin LI# RECORD MARK
191*ae316d1dSXin LI>0	ubyte		x		Intel hexadecimal object
192*ae316d1dSXin LI#!:mime	text/plain
193*ae316d1dSXin LI!:mime	text/x-hex
194*ae316d1dSXin LI!:ext	hex
195*ae316d1dSXin LI# no samples with other suffix found
196*ae316d1dSXin LI# .hex .mcs .int .ihex .ihe .ihx .h80 .h86 .a43 .a90 .obj .obl .obh .rom .eep
197*ae316d1dSXin LI# .hxl-.hxh .h00-.h15 .p00-.pff
198*ae316d1dSXin LI# RECLEN; 2 hex digits for number of bytes in 1st data field; like 0x02 0x03 0x04 0x08 0x10 0x20; maximum 255
199*ae316d1dSXin LI>1	string		x		\b, 0x%2.2s record length
200*ae316d1dSXin LI# OFFSET; 4 hex digits for 1st 16-bit memory offset of data like: 0000 (often) 1C00h 1E00h 3800h 3E00h 76EDh 7800h 7E00h ...
201*ae316d1dSXin LI>3	string		x		\b, 0x%4.4s offset
202*ae316d1dSXin LI# RECTYP; 2 hex digits (00 - 05); meaning of 1st data field; 00~DataRecord (often) 0l~EndOfFileRecord 02~ExtendedSegmentAddressRecord 03~StartSegmentAddressRecord 04~ExtendedLinearAddressRecord 05~StartLinearAddressRecord
203*ae316d1dSXin LI>7	string		x		\b, '%2.2s' type
204*ae316d1dSXin LI# DATA; n bytes of 1st data represented by 2n hex digits followed by 1 byte checksum
205*ae316d1dSXin LI>9	string		x		\b, data+checksum %s
206*ae316d1dSXin LI# last record :00000001FF with RECLEN 0, OFFSET 0, record type 01 for EndOfFile and 1 checksum byte FF
207*ae316d1dSXin LI# samples with CarriageReturnLineFeed terminator
208*ae316d1dSXin LI>-2	ubeshort	=0x0d0a
209*ae316d1dSXin LI# This should not happen!
210*ae316d1dSXin LI>>-13	string		!:00000001FF	\b, last line %s
211*ae316d1dSXin LI>-2	ubeshort	!0x0d0a
212*ae316d1dSXin LI# samples with LineFeed terminator
213*ae316d1dSXin LI>>-1	ubyte		=0x0a
214*ae316d1dSXin LI# This should not happen!
215*ae316d1dSXin LI>>>-12	string		!:00000001FF	\b, last line %s
216*ae316d1dSXin LI
217*ae316d1dSXin LI# Raspberry Pi RP2040 firmware
218*ae316d1dSXin LI# From: Alexandre Iooss <erdnaxe@crans.org>
219*ae316d1dSXin LI# Note: RP2040 flash image starts with stage2 bootloader, then a vector table.
220*ae316d1dSXin LI# URL: https://github.com/raspberrypi/pico-sdk/tree/1.5.1/src/rp2_common/boot_stage2
221*ae316d1dSXin LI# boot2_*.S code (_stage2_boot)
222*ae316d1dSXin LI0		ulelong			0x4B32B500
223*ae316d1dSXin LI>4		ulelong			0x60582021
224*ae316d1dSXin LI>>8		ulelong			0x21026898
225*ae316d1dSXin LI# exit_from_boot2.S code (check_return) `pop {r0}; cmp r0, #0`
226*ae316d1dSXin LI>>>148		ulelong			0x2800bc01
227*ae316d1dSXin LI# Cortex-M vector table with reserved section filled with a default interrupt address
228*ae316d1dSXin LI>>>>259		byte			0x20
229*ae316d1dSXin LI# make sure required vector table entries are ARM Thumb and in flash
230*ae316d1dSXin LI>>>>>260	ulelong&0xE0000001	1
231*ae316d1dSXin LI>>>>>>264	ulelong&0xE0000001	1
232*ae316d1dSXin LI>>>>>>>268	ulelong&0xE0000001	1
233*ae316d1dSXin LI>>>>>>>>300	ulelong&0xE0000001	1
234*ae316d1dSXin LI>>>>>>>>>312	ulelong&0xE0000001	1		Raspberry Pi RP2040 firmware
235*ae316d1dSXin LI>>>>>>>>>>256	ulelong			>0		\b, initial SP at 0x%08x
236*ae316d1dSXin LI>>>>>>>>>>260	ulelong^1		x		\b, reset at 0x%08x
237*ae316d1dSXin LI>>>>>>>>>>264	ulelong^1		x		\b, NMI at 0x%08x
238*ae316d1dSXin LI>>>>>>>>>>268	ulelong^1		x		\b, HardFault at 0x%08x
239*ae316d1dSXin LI>>>>>>>>>>300	ulelong^1		x		\b, SVCall at 0x%08x
240*ae316d1dSXin LI>>>>>>>>>>312	ulelong^1		x		\b, PendSV at 0x%08x
241*ae316d1dSXin LI# optional binary_info in the first 256 bytes, used by picotool
242*ae316d1dSXin LI# https://github.com/raspberrypi/pico-sdk/blob/master/src/common/pico_binary_info/include/pico/binary_info/defs.h
243*ae316d1dSXin LI>>>>>>>>>>256	search/256		\xf2\xeb\x88\x71	\b, with binary_info
244*ae316d1dSXin LI
245*ae316d1dSXin LI# Silicon Labs Gecko Bootloader update image
246*ae316d1dSXin LI# From: Alexandre Iooss <erdnaxe@crans.org>
247*ae316d1dSXin LI# Reference: https://github.com/raboof/gbl
248*ae316d1dSXin LI#            https://github.com/dsyx/emberznet-doc
249*ae316d1dSXin LI# Note: TLV always starting with tag 0x03A617EB of length 8
250*ae316d1dSXin LI0	ulelong		0x03A617EB
251*ae316d1dSXin LI>4	ulelong		8		Silicon Labs Gecko bootloader update image
252*ae316d1dSXin LI!:ext	gbl
253*ae316d1dSXin LI>>12	byte		1		\b, encrypted (AES-CTR-128)
254*ae316d1dSXin LI>>13	byte		1		\b, signed (ECDSA-P256)
255*ae316d1dSXin LI# If not encrypted, indicate first image type
256*ae316d1dSXin LI>>16	ulelong		0xF40A0AF4	\b, application image
257*ae316d1dSXin LI>>16	ulelong		0xF50909F5	\b, bootloader image
258*ae316d1dSXin LI
259*ae316d1dSXin LI# Silicon Labs Gecko Bootloader OTA update with Zigbee EmberZNet SDK
260*ae316d1dSXin LI# URL: https://github.com/SiliconLabs/gecko_sdk
261*ae316d1dSXin LI0	ulelong		0x0BEEF11E
262*ae316d1dSXin LI>6	ulelong		0x38		Silicon Labs Gecko EmberZNet OTA image
263*ae316d1dSXin LI!:ext	ota/zigbee
264*ae316d1dSXin LI>>4	ubeshort	x		v%d
265*ae316d1dSXin LI
266*ae316d1dSXin LI# Device Firmware Upgrade with ST STMicroelectronics extensions
267*ae316d1dSXin LI# From: Alexandre Iooss <erdnaxe@crans.org>
268*ae316d1dSXin LI# Reference: STMicroelectronics note UM0391
269*ae316d1dSXin LI# Reference: https://dfu-util.sourceforge.net/dfuse.html
270*ae316d1dSXin LI# DFU prefix
271*ae316d1dSXin LI0	string		DfuSe\x01	DFU image (STM variant)
272*ae316d1dSXin LI!:ext	dfu
273*ae316d1dSXin LI>6	ulelong		x		\b, size: %d bytes
274*ae316d1dSXin LI# DFU suffix, specification 0x011A
275*ae316d1dSXin LI>-10	string		\x1A\x01UFD
276*ae316d1dSXin LI>>-12	uleshort	x		\b, for device %04X:
277*ae316d1dSXin LI>>-14	uleshort	x		\b%04X
278