Esp32.Image (esp32 v0.2.0)

Copy Markdown View Source

Parser for ESP32-family application images.

An image is an 8-byte header, a 16-byte extended header, the segments, padding and a checksum byte closing a 16-byte boundary, then an optional SHA256 digest. ESP8266 images have no extended header and are not supported.

Summary

Functions

Rewrites the flash mode, size and frequency bytes of a bootloader image.

Types

t()

@type t() :: %Esp32.Image{
  checksum: byte(),
  checksum_ok?: boolean(),
  chip: Esp32.Chip.name() | {:unknown, non_neg_integer()},
  data_length: pos_integer(),
  entry_point: non_neg_integer(),
  flash_freq: 0..15,
  flash_mode: 0..3,
  flash_size: 0..15,
  hash_appended?: boolean(),
  segments: [%{offset: non_neg_integer(), data: binary()}]
}

Functions

parse(binary)

@spec parse(binary()) ::
  {:ok, t()} | {:error, :invalid_magic | :invalid_segments | :truncated}

patch_header(binary, chip, opts)

@spec patch_header(binary(), Esp32.Chip.name(), keyword()) ::
  {:ok, binary()} | {:error, term()}

Rewrites the flash mode, size and frequency bytes of a bootloader image.

Options :flash_mode (:qio | :qout | :dio | :dout), :flash_freq ("40m" …) and :flash_size ("4MB" …) default to :keep. Binaries that are not images are returned unchanged; an appended SHA256 digest is recomputed.