esp-idf-defs 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ name: Publish esp-idf-defs
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v5
13
+ with:
14
+ fetch-depth: 0
15
+
16
+ - uses: actions/setup-python@v6
17
+ with:
18
+ python-version: "3.13"
19
+
20
+ - name: Build package
21
+ run: |
22
+ pip install build
23
+ python -m build
24
+
25
+ - uses: actions/upload-artifact@v4
26
+ with:
27
+ name: dist
28
+ path: dist/
29
+
30
+ publish:
31
+ needs: build
32
+ runs-on: ubuntu-latest
33
+ environment: pypi
34
+ permissions:
35
+ id-token: write
36
+ steps:
37
+ - uses: actions/download-artifact@v4
38
+ with:
39
+ name: dist
40
+ path: dist/
41
+
42
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,65 @@
1
+ # Created by .ignore support plugin (hsz.mobi)
2
+ ### Python template
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+
8
+ # Distribution / packaging
9
+ .Python
10
+ env/
11
+ build/
12
+ build-*/
13
+ develop-eggs/
14
+ dist/
15
+ dist-*/
16
+ downloads/
17
+ eggs/
18
+ .eggs/
19
+ lib/
20
+ lib64/
21
+ parts/
22
+ sdist/
23
+ var/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+
28
+ # Installer logs
29
+ pip-log.txt
30
+ pip-delete-this-directory.txt
31
+
32
+ # Sphinx documentation
33
+ docs/_build/
34
+
35
+ # PyBuilder
36
+ target/
37
+
38
+ # pyenv
39
+ .python-version
40
+
41
+ # dotenv
42
+ .env
43
+
44
+ # virtualenv
45
+ venv/
46
+ ENV/
47
+
48
+ ### VirtualEnv template
49
+ # Virtualenv
50
+ # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
51
+ [Bb]in
52
+ [Ii]nclude
53
+ [Ll]ib
54
+ [Ll]ib64
55
+ [Ll]ocal
56
+ [Ss]cripts
57
+ pyvenv.cfg
58
+ .venv
59
+ pip-selfcheck.json
60
+
61
+ # File-based project format
62
+ *.iws
63
+
64
+ # idea folder
65
+ .idea
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may accept and charge a
167
+ fee for the acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend, and
172
+ hold each Contributor harmless for any liability incurred by, or
173
+ claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Nebojša Cvetković
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: esp-idf-defs
3
+ Version: 0.1.0
4
+ License-File: LICENSE.md
5
+ Dynamic: license-file
@@ -0,0 +1,53 @@
1
+ # esp-idf-defs
2
+
3
+ Python data structures for ESP-IDF internals — partition tables, firmware image headers, OTA data, and application descriptors.
4
+
5
+ Used by [`idftool`](https://github.com/nebkat/idftool).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install esp-idf-defs
11
+ ```
12
+
13
+ ## Classes
14
+
15
+ ### Partition table
16
+
17
+ ```python
18
+ from esp_idf_defs import PartitionTable, PartitionDefinition
19
+
20
+ table = PartitionTable.from_binary(data) # parse binary partition table
21
+ table = PartitionTable.from_csv(text) # parse CSV partition table
22
+
23
+ partition = table["ota_0"] # look up by name
24
+ print(partition.offset, partition.size)
25
+ ```
26
+
27
+ ### Firmware images
28
+
29
+ ```python
30
+ from esp_idf_defs import ImageMetadata
31
+
32
+ image = ImageMetadata.from_binary(data)
33
+ print(image.header.chip_id, image.app_description.version)
34
+ ```
35
+
36
+ ### OTA data
37
+
38
+ ```python
39
+ from esp_idf_defs import OtaDataSelectEntry
40
+ from esp_idf_defs.otadata import OtaDataParameters
41
+
42
+ entry = OtaDataSelectEntry.from_binary(data)
43
+ print(entry.ota_seq, entry.state)
44
+ ```
45
+
46
+ ### Application descriptor
47
+
48
+ ```python
49
+ from esp_idf_defs import AppDescription
50
+
51
+ desc = AppDescription.from_binary(data)
52
+ print(desc.project_name, desc.version)
53
+ ```
@@ -0,0 +1,22 @@
1
+ __all__ = [
2
+ "AppDescription",
3
+ "ImageMetadata",
4
+ "ImageHeader",
5
+ "ImageSegment",
6
+ "ImageSpiMode",
7
+ "ImageSpiFrequency",
8
+ "ChipId",
9
+ "ImageFlashSize",
10
+ "OtaDataSelectEntry",
11
+ "PartitionTable",
12
+ "PartitionDefinition"
13
+ ]
14
+
15
+ from esp_idf_defs.image_metadata import ImageMetadata, ImageHeader, ImageSegment, ImageSpiMode, ImageSpiFrequency, \
16
+ ChipId, ImageFlashSize
17
+
18
+ from esp_idf_defs.otadata import OtaDataSelectEntry
19
+
20
+ from esp_idf_defs.partitions import PartitionTable, PartitionDefinition
21
+
22
+ from esp_idf_defs.app_description import AppDescription
@@ -0,0 +1,90 @@
1
+ from __future__ import annotations
2
+ import struct
3
+ from dataclasses import dataclass
4
+ from typing import ClassVar
5
+
6
+
7
+ @dataclass
8
+ class AppDescription:
9
+ # `ESP_APP_DESC_MAGIC_WORD`
10
+ MAGIC: ClassVar[int] = 0xABCD5432
11
+
12
+ # sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)
13
+ FIRMWARE_BINARY_OFFSET: ClassVar[int] = 0x20
14
+
15
+ # `sizeof(esp_app_desc_t)`
16
+ SIZE: ClassVar[int] = 256
17
+
18
+ project_name: str
19
+ version: str
20
+ idf_version: str
21
+ secure_version: int
22
+ elf_sha256: bytes
23
+ time: str | None = None
24
+ date: str | None = None
25
+
26
+ @property
27
+ def title(self) -> str:
28
+ return f"{self.project_name} {self.version}"
29
+
30
+ @property
31
+ def compiled(self) -> str | None:
32
+ if self.date and self.time:
33
+ return f"{self.date} {self.time}"
34
+ return None
35
+
36
+ @classmethod
37
+ def from_bytes(cls, buffer: bytes) -> AppDescription:
38
+ if len(buffer) < cls.SIZE:
39
+ raise ValueError(f"Invalid app description, expected >= 256 bytes, got {len(buffer)}")
40
+
41
+ if struct.unpack_from('<I', buffer, 0)[0] != cls.MAGIC:
42
+ raise ValueError("Invalid firmware file, magic not found")
43
+
44
+ def decode_string(start, length):
45
+ return buffer[start:start + length].split(b'\x00', 1)[0].decode('utf-8')
46
+
47
+ project_name = decode_string(48, 32)
48
+ version = decode_string(16, 32)
49
+ idf_version = decode_string(112, 32)
50
+ secure_version = struct.unpack_from('<I', buffer, 4)[0]
51
+
52
+ time = decode_string(80, 16)
53
+ date = decode_string(96, 16)
54
+
55
+ elf_sha256 = buffer[144:176]
56
+
57
+ return cls(
58
+ project_name=project_name,
59
+ version=version,
60
+ idf_version=idf_version,
61
+ secure_version=secure_version,
62
+ time=time,
63
+ date=date,
64
+ elf_sha256=elf_sha256
65
+ )
66
+
67
+ @classmethod
68
+ def from_bytes_or_none(cls, buffer: bytes) -> AppDescription | None:
69
+ try:
70
+ return cls.from_bytes(buffer)
71
+ except ValueError:
72
+ return None
73
+
74
+ def to_bytes(self) -> bytes:
75
+ def encode_field(value: str | None, length: int) -> bytes:
76
+ """Helper function to encode a string or None into a fixed-length byte array."""
77
+ if value:
78
+ return value.encode('utf-8')[:length].ljust(length, b'\x00')
79
+ return b'\x00' * length
80
+
81
+ buffer = bytearray(self.SIZE)
82
+ struct.pack_into('<I', buffer, 0, self.MAGIC)
83
+ struct.pack_into('<I', buffer, 4, self.secure_version)
84
+ buffer[48:80] = encode_field(self.project_name, 32)
85
+ buffer[16:48] = encode_field(self.version, 32)
86
+ buffer[112:144] = encode_field(self.idf_version, 32)
87
+ buffer[80:96] = encode_field(self.time, 16)
88
+ buffer[96:112] = encode_field(self.date, 16)
89
+ buffer[144:176] = self.elf_sha256
90
+ return bytes(buffer)
@@ -0,0 +1,178 @@
1
+ from __future__ import annotations
2
+
3
+ import collections
4
+ import struct
5
+ from dataclasses import dataclass
6
+ from enum import IntEnum
7
+ from functools import reduce
8
+ from hashlib import sha256
9
+ from typing import ClassVar, NamedTuple, List
10
+
11
+ from esp_idf_defs.app_description import AppDescription
12
+
13
+
14
+ @dataclass
15
+ class ImageMetadata:
16
+ """ESP-IDF firmware image metadata (`esp_image_metadata_t`)"""
17
+
18
+ # `ESP_ROM_CHECKSUM_INITIAL` / `ESP_CHECKSUM_MAGIC`
19
+ CHECKSUM_MAGIC: ClassVar[int] = 0xEF
20
+
21
+ header: ImageHeader
22
+ segments: List[ImageSegment]
23
+ digest: bytes
24
+ app_description: AppDescription | None
25
+
26
+ @classmethod
27
+ def from_bytes(cls, buffer: bytes, app_required: bool = False) -> ImageMetadata:
28
+ header = ImageHeader.from_bytes(buffer[0:ImageHeader.SIZE])
29
+ offset = ImageHeader.SIZE
30
+ segments: List[ImageSegment] = []
31
+ checksum = ImageMetadata.CHECKSUM_MAGIC
32
+ app_description: AppDescription | None = None
33
+ for i in range(header.segment_count):
34
+ if offset + 8 >= len(buffer):
35
+ raise ValueError(f"Segment {i} out of range (not enough data)")
36
+ address, length = struct.unpack_from('<II', buffer, offset)
37
+ offset += 8
38
+ segment = ImageSegment(offset, length, address)
39
+
40
+ data = buffer[offset:offset+length]
41
+ checksum = reduce(lambda a, b: a ^ b & 0xFF, data, checksum)
42
+
43
+ if i == 0:
44
+ app_description = AppDescription.from_bytes(data) if app_required else AppDescription.from_bytes_or_none(data)
45
+
46
+ offset += length
47
+ segments.append(segment)
48
+
49
+ # Add a byte for the checksum
50
+ offset += 1
51
+
52
+ # Pad to the next full 16 byte block
53
+ offset = (offset + 15) & ~0xF
54
+
55
+ # Checksum (simple)
56
+ expected_checksum = struct.unpack_from('<B', buffer, offset - 1)[0]
57
+ if checksum != expected_checksum:
58
+ raise ValueError(f"Checksum mismatch: expected {expected_checksum:#02x}, got {checksum:#02x}")
59
+
60
+ # Hash (SHA-256)
61
+ digest = sha256(buffer[:offset]).digest()
62
+ if header.hash_appended:
63
+ expected_hash = buffer[offset:offset+32]
64
+ if digest != expected_hash:
65
+ raise ValueError(f"SHA-256 hash mismatch: expected {expected_hash.hex()}, got {digest.hex()}")
66
+
67
+ return cls(
68
+ header=header,
69
+ segments=segments,
70
+ digest=digest,
71
+ app_description=app_description
72
+ )
73
+
74
+
75
+
76
+ @dataclass
77
+ class ImageHeader:
78
+ # `ESP_IMAGE_HEADER_MAGIC`
79
+ MAGIC: ClassVar[int] = 0xE9
80
+
81
+ # `ESP_IMAGE_HEADER_MAGIC`
82
+ MAX_SEGMENTS: ClassVar[int] = 16
83
+
84
+ # `sizeof(esp_image_header_t)`
85
+ SIZE: ClassVar[int] = 24
86
+
87
+ # `WP_PIN_DISABLED`
88
+ WP_PIN_DISABLED: ClassVar[int] = 0xEE
89
+
90
+ @classmethod
91
+ def from_bytes(cls, buffer: bytes) -> ImageHeader:
92
+ if len(buffer) < cls.SIZE:
93
+ raise ValueError(f"Invalid image header, expected >= 24 bytes, got {len(buffer)}")
94
+
95
+ magic = struct.unpack_from('<B', buffer, 0)[0]
96
+ if magic != cls.MAGIC:
97
+ raise ValueError(f"Invalid image header, magic not found: expected {cls.MAGIC:#02x}, got {magic:#02x}")
98
+
99
+ segment_count = struct.unpack_from('<B', buffer, 1)[0]
100
+ if segment_count == 0 or segment_count > cls.MAX_SEGMENTS:
101
+ raise ValueError(
102
+ f"Invalid image header, bad segment count: {segment_count}: "
103
+ f"expected 1..{cls.MAX_SEGMENTS}")
104
+
105
+ wp_pin = struct.unpack_from('<B', buffer, 8)[0]
106
+
107
+ return cls(
108
+ segment_count=segment_count,
109
+ spi_mode = ImageSpiMode(struct.unpack_from('<B', buffer, 2)[0]),
110
+ spi_frequency = ImageSpiFrequency(struct.unpack_from('<B', buffer, 3)[0] & 0xF),
111
+ spi_size = ImageFlashSize(struct.unpack_from('<B', buffer, 3)[0] >> 4),
112
+ entry_address = struct.unpack_from('<I', buffer, 4)[0],
113
+ wp_pin = wp_pin if wp_pin != cls.WP_PIN_DISABLED else None,
114
+ spi_pin_drv = struct.unpack_from('<BBB', buffer, 9),
115
+ chip_id = ChipId(struct.unpack_from('<H', buffer, 12)[0]),
116
+ min_chip_rev = struct.unpack_from('<B', buffer, 14)[0],
117
+ min_chip_rev_full = struct.unpack_from('<H', buffer, 15)[0],
118
+ max_chip_rev_full = struct.unpack_from('<H', buffer, 11)[0],
119
+ hash_appended = bool(struct.unpack_from('<B', buffer, 23)[0] == 1)
120
+ )
121
+
122
+ segment_count: int
123
+ spi_mode: ImageSpiMode | None
124
+ spi_frequency: ImageSpiFrequency | None
125
+ spi_size: ImageFlashSize | None
126
+ entry_address: int
127
+ wp_pin: int | None
128
+ spi_pin_drv: (int, int, int)
129
+ chip_id: ChipId | None
130
+ min_chip_rev: int
131
+ min_chip_rev_full: int
132
+ max_chip_rev_full: int
133
+ hash_appended: bool
134
+
135
+ ImageSegment = NamedTuple("ImageSegment", [
136
+ ("offset", int),
137
+ ("length", int),
138
+ ("address", int)
139
+ ])
140
+
141
+ # `esp_image_spi_mode_t`
142
+ class ImageSpiMode(IntEnum):
143
+ QIO = 0x0
144
+ QOUT = 0x1
145
+ DIO = 0x2
146
+ DOUT = 0x3
147
+ FAST_READ = 0x4
148
+ SLOW_READ = 0x5
149
+
150
+ # `esp_image_spi_freq_t`
151
+ class ImageSpiFrequency(IntEnum):
152
+ DIV1 = 0xF
153
+ DIV2 = 0x0
154
+ DIV3 = 0x1
155
+ DIV4 = 0x2
156
+
157
+ # `esp_chip_id_t`
158
+ class ChipId(IntEnum):
159
+ ESP32 = 0x0000
160
+ ESP32S2 = 0x0002
161
+ ESP32C3 = 0x0005
162
+ ESP32S3 = 0x0009
163
+ ESP32C2 = 0x000C
164
+ ESP32C6 = 0x000D
165
+ ESP32H2 = 0x0010
166
+ ESP32P4 = 0x0012
167
+ ESP32C5 = 0x0017
168
+
169
+ # `esp_image_flash_size_t`
170
+ class ImageFlashSize(IntEnum):
171
+ MB1 = 0x0
172
+ MB2 = 0x1
173
+ MB4 = 0x2
174
+ MB8 = 0x3
175
+ MB16 = 0x4
176
+ MB32 = 0x5
177
+ MB64 = 0x6
178
+ MB128 = 0x7