Skip to content

Instantly share code, notes, and snippets.

@gtors
Forked from igrr/esp.ksy
Last active February 23, 2024 13:42
Show Gist options
  • Save gtors/aa44a22fb1be2021469144fa601baca0 to your computer and use it in GitHub Desktop.
Save gtors/aa44a22fb1be2021469144fa601baca0 to your computer and use it in GitHub Desktop.
esp8266 with OTA
# Try it out by opening https://ide.kaitai.io/ and copying this file there
# Based on an article by @angelcarve about ESP8266 binary image parsing with Kaitai Struct:
# https://carvesystems.com/news/parsing-binaries-with-kaitai-struct/
meta:
id: esp8266
file-extension: bin
endian: le
seq:
- id: header
type: image_header
- id: segments
type: segment
repeat: expr
repeat-expr: header.num_segments
instances:
user_slot_1:
pos: 0x1000
type: user_slot_1
doc: User application, slot 1
types:
image_header:
seq:
- id: magic
contents: [0xE9]
- id: num_segments
type: u1
- id: flash_mode
type: u1
enum: e_flash_mode
- id: flash_size
type: b4
enum: e_flash_size
- id: flash_freq
type: b4
enum: e_flash_freq
- id: entrypoint
type: u4
image_extended_header:
seq:
- id: wp_pin
type: u1
- id: spi_pin_drv
size: 3
- id: chip_id
type: u2
- id: min_chip_rev
type: u1
- id: reserved
size: 8
- id: hash_appended
type: u1
segment:
seq:
- id: load_addr
type: u4
- id: segment_size
type: u4
- id: segment_data
size: segment_size
user_slot_1:
seq:
- id: header
type: image_header
- id: segments
type: segment
repeat: expr
repeat-expr: header.num_segments
enums:
e_flash_mode:
0: qio
1: qout
2: dio
3: dout
e_flash_size:
0: size_1m
1: size_2m
2: size_4m
3: size_8m
4: size_16m
e_flash_freq:
0: freq_40mhz
1: freq_26mhz
2: freq_20mhz
0xf: freq_80mhz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment