You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/esptool/scripting.rst
+34
Original file line number
Diff line number
Diff line change
@@ -95,6 +95,40 @@ The following example demonstrates running a series of flash memory operations i
95
95
- This example doesn't use ``detect_chip()``, but instantiates a ``ESP32ROM`` class directly. This is useful when you know the target chip in advance. In this scenario ``esp.connect()`` is required to establish a connection with the device.
96
96
- Multiple operations can be chained together in a single context manager block.
97
97
98
+
------------
99
+
100
+
The Public API implements a custom ``ImageSource`` input type, which expands to ``str | bytes | IO[bytes]`` - a path to the firmware image file, an opened file-like object, or the image data as bytes.
101
+
102
+
As output, the API returns a ``bytes`` object representing the binary image or writes the image to a file if the ``output`` parameter is provided.
103
+
104
+
The following example converts an ELF file to a flashable binary, prints the image information, and flashes the image. The example demonstrates three different ways to achieve the same result, showcasing the flexibility of the API:
105
+
106
+
.. code-block:: python
107
+
108
+
ELF="firmware.elf"
109
+
110
+
# var 1 - Loading ELF from a file, not writing binary to a file
111
+
bin_file = elf2image(ELF, "esp32c3")
112
+
image_info(bin_file)
113
+
with detect_chip(PORT) as esp:
114
+
attach_flash(esp)
115
+
write_flash(esp, [(0, bin_file)])
116
+
117
+
# var 2 - Loading ELF from an opened file object, not writing binary to a file
118
+
withopen(ELF, "rb") as elf_file, detect_chip(PORT) as esp:
119
+
bin_file = elf2image(elf_file, "esp32c3")
120
+
image_info(bin_file)
121
+
attach_flash(esp)
122
+
write_flash(esp, [(0, bin_file)])
123
+
124
+
# var 3 - Loading ELF from a file, writing binary to a file
125
+
elf2image(ELF, "esp32c3", "image.bin")
126
+
image_info("image.bin")
127
+
with detect_chip(PORT) as esp:
128
+
attach_flash(esp)
129
+
write_flash(esp, [(0, "image.bin")])
130
+
131
+
98
132
------------
99
133
100
134
**The following section provides a detailed reference for the public API functions.**
0 commit comments