Source file: /~heha/hsn/esptool.zip/image.h

#pragma once
#include "esptool.h"	// byte, uint32
#include <stdio.h>	// FILE
#include "sha.h"	// Sha256, Md5

/* Anstatt auf ELF zu setzen benutzt ESP32 sein eigenes binäres Image-Format.
 Es enthält 1..16 „Lade-Blöcke“, hier Segmente genannt.
	8266	32	S2	S3	C3	C2	C6	H2
	fmode
0	QIO	"	"	"	"	"	"	"
1	QOUT	"	"	"	"	"	"	"
2	DIO	"	"	"	"	"	"	"
3	DOUT	"	"	"	"	"	"	"
	ffreq
0	40 MHz	"	"	"	"	30 MHz	80 MHz	24 MHz
1	26 MHz	"	"	"	"	20 MHz	40 MHz	16 MHz
2	20 MHz	"	"	"	"	15 MHz	20 MHz	12 MHz
F	80 MHz	"	"	"	"	60 MHz		48 MHz
	fsize
0	512 KB	1 MB	"	"	"	"	"	"
1	256 KB	2 MB	"	"	"	"	"	"
2	1 MB	4 MB	"	"	"	"	"	"
3	2 MB	8 MB	"	"	"	"	"	"
4	4 MB	16 MB	"	"	"	"	"	"
5	2 MB-c1		32 MB	"
6	4 MB-c1		64 MB	"
7			128 MB	"
8	8 MB
9	16 MB
*/
struct ESPFirmwareImage {
 enum{
  MAGIC = 0xE9,		// First byte of the application image
 };
 struct SEGHDR{
  uint32 offset,size;	// in der Datei folgen die Daten direkt darauf
  uint32 segsize() const {return (size+3)&~3;}
  const byte*data() const {return reinterpret_cast<const byte*>(this+1);}
  const SEGHDR*next() const {return reinterpret_cast<const SEGHDR*>(data()+segsize());}
 };
 struct IMGHDR{	// Erweiterter Header (+16 Bytes) für ESP32
  byte	magic,	// stets 0xE9
	nseg,	// Anzahl „Segmente“ (max. 16)
	fmode,	// DIO, QIO usw.
	ffreq:4,// Lo-Nibble = Frequenz
	fsize:4;// Hi-Nibble = Größe: log2(flashsize/1MB)
  uint32 entry;
// Nicht für RAM-Images:
  byte	wp_pin,			// 0xEE = disabled
	spi_pin_drv[3],		// 0
  	chipL,chipH,		// 0 für ESP32 (hier programmintern 32), sonst siehe Info
	min_chip_rev,		// 0 unused
  	min_chip_L,min_chip_H,	// 0
	max_chip_L,max_chip_H,	// 0xFFFF
	reserved[4],		// 0
	hash_append;		// = 1: Sha256::Digest hintenan
  const SEGHDR*next(bool kurz=false) const;
  char detectchip() const;	// zero for no-detect, otherwise 32 or 66 or image_id
 }hdr;
 struct SEG:public SEGHDR{
  byte*data;
 }*segments;
 char m_chip;
 byte check;	// Am Dateiende befindet sich eine dusselige XOR8-Prüfsumme,
		// so ausgerichtet dass die Dateilänge durch 16 teilbar ist
		// Die Füllbytes sind 0. Nicht für RAM-Images.
 bool check_avail;
 Sha256::Digest filehash,calchash;	// ab ESP32

 ESPFirmwareImage(char chip,const char*filename=0);	// constructor
 void load(const char*filename);	// loader
 void load(FILE*f);
 unsigned version() const {return 1;}
 const char*fmode_str() const;
 String<8>ffreq_str() const;
 String<16>fsize_str() const;
 void checkchip();
 static bool valid(const void*fdata,size_t flen=-1);
 static bool parse(const Dumpfile&,cb2_t cb,void*cbd,uint32*sadr);
 static uint32 detectSize(const void*fdata,uint32 fsize);
// <data> wird „wegkopiert“ und nicht weiter referenziert
 bool add_segment(const Dumpfile&);
 static bool add_segment_cb(void*cbd,const Dumpfile&df) {
  return ((ESPFirmwareImage*)cbd)->add_segment(df);
 }
 void save(const char*filename) const;
 ~ESPFirmwareImage();
};
Detected encoding: ANSI (CP1252)4
Wrong umlauts? - Assume file is ANSI (CP1252) encoded