folder2uf2 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mikey Sklar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,215 @@
1
+ Metadata-Version: 2.4
2
+ Name: folder2uf2
3
+ Version: 0.1.0
4
+ Summary: Ship a CircuitPython project as one file: a self-extracting code.py, a UF2 for RP2, or an image for ESP32
5
+ Author-email: Mikey Sklar <mikeysklar@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/mikeysklar/folder2uf2
8
+ Project-URL: Issues, https://github.com/mikeysklar/folder2uf2/issues
9
+ Keywords: circuitpython,uf2,rp2040,rp2350,esp32,adafruit,fat
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Software Development :: Embedded Systems
16
+ Classifier: Topic :: System :: Hardware
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Provides-Extra: test
21
+ Requires-Dist: pytest; extra == "test"
22
+ Dynamic: license-file
23
+
24
+ # folder2uf2
25
+
26
+ ## What it does
27
+
28
+ Ships a CircuitPython project as one file, so customers copy once.
29
+
30
+ ## Install
31
+
32
+ ```sh
33
+ pip install folder2uf2
34
+ ```
35
+
36
+ Python 3.8 or newer, standard library only. No dependencies.
37
+
38
+ ## Three ways to ship
39
+
40
+ | Output | Goes onto | Board must be |
41
+ |---|---|---|
42
+ | `code.py` | `CIRCUITPY` | running CircuitPython |
43
+ | `.uf2` | `RPI-RP2`, `RP2350` | in the UF2 bootloader |
44
+ | `.bin` | flashed by esptool | ESP32, any state |
45
+
46
+ ## Self-extract: one file, no bootloader
47
+
48
+ Pack the project. Output must be `code.py`, the name CircuitPython runs.
49
+
50
+ ```sh
51
+ folder2uf2 --self-extract -o code.py myproject/
52
+ ```
53
+
54
+ ### What your customer does
55
+
56
+ ```
57
+ 1. drag code.py onto CIRCUITPY
58
+ 2. CIRCUITPY disappears for about 4 seconds
59
+ 3. board reboots with code.py, lib/ and assets in place
60
+ ```
61
+
62
+ Works on every port, RP2 and ESP32 alike.
63
+
64
+ ### If it fails
65
+
66
+ The drive is handed back with an error. Nobody gets locked out.
67
+
68
+ ### How it works
69
+
70
+ `storage.unsafe_disable_usb_drive()` makes CIRCUITPY writable from `code.py`.
71
+
72
+ ```python
73
+ # payload rides in trailing comments, inflated one file at a time
74
+ # peak RAM is the largest single file, not the whole tree
75
+ # remount() cannot: MSC holds the block device lock while mounted
76
+ ```
77
+
78
+ ### Limits
79
+
80
+ Needs CircuitPython installed already. CIRCUITPY vanishes while it runs.
81
+
82
+ ```
83
+ zlib required: default wherever CIRCUITPY_FULL_BUILD is set
84
+ 60KB incompressible single file verified on a 264KB RP2040
85
+ ```
86
+
87
+ ## UF2, for RP2 boards
88
+
89
+ ```sh
90
+ # filesystem only
91
+ folder2uf2 --board adafruit_metro_rp2350 -o fs.uf2 myproject/
92
+
93
+ # firmware and filesystem together
94
+ folder2uf2 --board adafruit_metro_rp2350 \
95
+ --combine firmware.uf2 -o product.uf2 myproject/
96
+
97
+ # wipe residual data rather than writing only used sectors
98
+ folder2uf2 --board adafruit_metro_rp2350 --full -o fs.uf2 myproject/
99
+
100
+ # a board with no built-in profile
101
+ folder2uf2 --flash-offset 0x100000 --flash-size 0x1000000 \
102
+ --family-id 0xe48bff59 -o fs.uf2 myproject/
103
+
104
+ folder2uf2 --list-boards
105
+ ```
106
+
107
+ ## ESP32
108
+
109
+ tinyuf2 writes only `ota_0`, so ESP32 gets a raw image for esptool.
110
+
111
+ ```sh
112
+ folder2uf2 --board esp32_16mb -o fs.bin myproject/
113
+ esptool --before no-reset --after no-reset write-flash 0x450000 fs.bin
114
+ ```
115
+
116
+ ### Storage extend
117
+
118
+ Layouts differ, so read the table off your chip.
119
+
120
+ ```sh
121
+ esptool --before no-reset --after no-reset read-flash 0x8000 0xc00 pt.bin
122
+ folder2uf2 --board esp32_16mb --partition-table pt.bin --storage-extend -o fs.bin src/
123
+ ```
124
+
125
+ ```c
126
+ storage_extended = (_partition[0]->size < fatfs_bytes());
127
+ /* S3 16MB has that slot: 28032 sectors. S2 4MB does not: 1920. */
128
+ ```
129
+
130
+ ### Download mode
131
+
132
+ One-shot: one esptool run per entry, then power cycle.
133
+
134
+ ### Bootloader
135
+
136
+ Install the tinyuf2 bootloader first, per your board's learn guide.
137
+
138
+ ### Browser instead of esptool
139
+
140
+ Takes a file and an offset, so customers need no Python.
141
+
142
+ <https://adafruit.github.io/Adafruit_WebSerial_ESPTool/>
143
+
144
+ ## How it was tested
145
+
146
+ ### Self-extract, three boards
147
+
148
+ RP2040 is the tight one.
149
+
150
+ ```
151
+ Adafruit CircuitPython 10.3.0 on 2026-08-31; Adafruit Metro RP2040 with rp2040
152
+ Adafruit CircuitPython 10.3.0 on 2026-08-31; Adafruit Metro RP2350 with rp2350b
153
+ Adafruit CircuitPython 10.3.0 on 2026-08-31; Adafruit Metro ESP32S3 with ESP32S3
154
+
155
+ 60144 bytes of source packed into 84356 bytes
156
+ assets.bin 60000 bytes incompressible, md5 matched
157
+ lib/mypkg/__init__.py created, nested dir
158
+ code.py replaced by the product, printed its marker
159
+ ```
160
+
161
+ Drive returned unaided. All boards restored, identical.
162
+
163
+ ### What the RP2040 taught
164
+
165
+ Two MemoryErrors before it fit, both invisible on roomier chips.
166
+
167
+ ```
168
+ "".join(chunks) -> allocating 80037 bytes, failed
169
+ growing a bytearray -> allocating 49680 bytes, failed
170
+ preallocate + memoryview -> fits
171
+ ```
172
+
173
+ ### Combine, Metro RP2350
174
+
175
+ Before, then after one UF2 carrying the 10.3.0 release.
176
+
177
+ ```
178
+ Adafruit CircuitPython 10.3.0-alpha.4 on 2026-07-23; Adafruit Metro RP2350 with rp2350b
179
+
180
+ Adafruit CircuitPython 10.3.0 on 2026-08-31; Adafruit Metro RP2350 with rp2350b
181
+ code.py output:
182
+ FOLDER2UF2-COMBINE-OK marker 8f3a21
183
+ lib import works
184
+
185
+ restored by a second combined UF2, 108 files identical
186
+ ```
187
+
188
+ ### ESP32 image, Metro ESP32-S3
189
+
190
+ Partition table read from the chip, not assumed.
191
+
192
+ ```
193
+ ffat data fat 0x450000 0xBB0000 11968K
194
+ wrote 43520 bytes, hash verified
195
+ volume 28032 sectors, files intact
196
+ ```
197
+
198
+ ## Safety
199
+
200
+ Firmware is untouched unless you pass `--combine`.
201
+
202
+ ```
203
+ --self-extract writes only your files, leaving others alone
204
+ an ESP32 image sized wrong overflows, so read the table
205
+ ```
206
+
207
+ ## Credit
208
+
209
+ Idea from jepler's archived mkfatimg. Thanks @todbot for the requests.
210
+
211
+ https://github.com/adafruit/circuitpython/issues/10074
212
+
213
+ ## License
214
+
215
+ MIT
@@ -0,0 +1,192 @@
1
+ # folder2uf2
2
+
3
+ ## What it does
4
+
5
+ Ships a CircuitPython project as one file, so customers copy once.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ pip install folder2uf2
11
+ ```
12
+
13
+ Python 3.8 or newer, standard library only. No dependencies.
14
+
15
+ ## Three ways to ship
16
+
17
+ | Output | Goes onto | Board must be |
18
+ |---|---|---|
19
+ | `code.py` | `CIRCUITPY` | running CircuitPython |
20
+ | `.uf2` | `RPI-RP2`, `RP2350` | in the UF2 bootloader |
21
+ | `.bin` | flashed by esptool | ESP32, any state |
22
+
23
+ ## Self-extract: one file, no bootloader
24
+
25
+ Pack the project. Output must be `code.py`, the name CircuitPython runs.
26
+
27
+ ```sh
28
+ folder2uf2 --self-extract -o code.py myproject/
29
+ ```
30
+
31
+ ### What your customer does
32
+
33
+ ```
34
+ 1. drag code.py onto CIRCUITPY
35
+ 2. CIRCUITPY disappears for about 4 seconds
36
+ 3. board reboots with code.py, lib/ and assets in place
37
+ ```
38
+
39
+ Works on every port, RP2 and ESP32 alike.
40
+
41
+ ### If it fails
42
+
43
+ The drive is handed back with an error. Nobody gets locked out.
44
+
45
+ ### How it works
46
+
47
+ `storage.unsafe_disable_usb_drive()` makes CIRCUITPY writable from `code.py`.
48
+
49
+ ```python
50
+ # payload rides in trailing comments, inflated one file at a time
51
+ # peak RAM is the largest single file, not the whole tree
52
+ # remount() cannot: MSC holds the block device lock while mounted
53
+ ```
54
+
55
+ ### Limits
56
+
57
+ Needs CircuitPython installed already. CIRCUITPY vanishes while it runs.
58
+
59
+ ```
60
+ zlib required: default wherever CIRCUITPY_FULL_BUILD is set
61
+ 60KB incompressible single file verified on a 264KB RP2040
62
+ ```
63
+
64
+ ## UF2, for RP2 boards
65
+
66
+ ```sh
67
+ # filesystem only
68
+ folder2uf2 --board adafruit_metro_rp2350 -o fs.uf2 myproject/
69
+
70
+ # firmware and filesystem together
71
+ folder2uf2 --board adafruit_metro_rp2350 \
72
+ --combine firmware.uf2 -o product.uf2 myproject/
73
+
74
+ # wipe residual data rather than writing only used sectors
75
+ folder2uf2 --board adafruit_metro_rp2350 --full -o fs.uf2 myproject/
76
+
77
+ # a board with no built-in profile
78
+ folder2uf2 --flash-offset 0x100000 --flash-size 0x1000000 \
79
+ --family-id 0xe48bff59 -o fs.uf2 myproject/
80
+
81
+ folder2uf2 --list-boards
82
+ ```
83
+
84
+ ## ESP32
85
+
86
+ tinyuf2 writes only `ota_0`, so ESP32 gets a raw image for esptool.
87
+
88
+ ```sh
89
+ folder2uf2 --board esp32_16mb -o fs.bin myproject/
90
+ esptool --before no-reset --after no-reset write-flash 0x450000 fs.bin
91
+ ```
92
+
93
+ ### Storage extend
94
+
95
+ Layouts differ, so read the table off your chip.
96
+
97
+ ```sh
98
+ esptool --before no-reset --after no-reset read-flash 0x8000 0xc00 pt.bin
99
+ folder2uf2 --board esp32_16mb --partition-table pt.bin --storage-extend -o fs.bin src/
100
+ ```
101
+
102
+ ```c
103
+ storage_extended = (_partition[0]->size < fatfs_bytes());
104
+ /* S3 16MB has that slot: 28032 sectors. S2 4MB does not: 1920. */
105
+ ```
106
+
107
+ ### Download mode
108
+
109
+ One-shot: one esptool run per entry, then power cycle.
110
+
111
+ ### Bootloader
112
+
113
+ Install the tinyuf2 bootloader first, per your board's learn guide.
114
+
115
+ ### Browser instead of esptool
116
+
117
+ Takes a file and an offset, so customers need no Python.
118
+
119
+ <https://adafruit.github.io/Adafruit_WebSerial_ESPTool/>
120
+
121
+ ## How it was tested
122
+
123
+ ### Self-extract, three boards
124
+
125
+ RP2040 is the tight one.
126
+
127
+ ```
128
+ Adafruit CircuitPython 10.3.0 on 2026-08-31; Adafruit Metro RP2040 with rp2040
129
+ Adafruit CircuitPython 10.3.0 on 2026-08-31; Adafruit Metro RP2350 with rp2350b
130
+ Adafruit CircuitPython 10.3.0 on 2026-08-31; Adafruit Metro ESP32S3 with ESP32S3
131
+
132
+ 60144 bytes of source packed into 84356 bytes
133
+ assets.bin 60000 bytes incompressible, md5 matched
134
+ lib/mypkg/__init__.py created, nested dir
135
+ code.py replaced by the product, printed its marker
136
+ ```
137
+
138
+ Drive returned unaided. All boards restored, identical.
139
+
140
+ ### What the RP2040 taught
141
+
142
+ Two MemoryErrors before it fit, both invisible on roomier chips.
143
+
144
+ ```
145
+ "".join(chunks) -> allocating 80037 bytes, failed
146
+ growing a bytearray -> allocating 49680 bytes, failed
147
+ preallocate + memoryview -> fits
148
+ ```
149
+
150
+ ### Combine, Metro RP2350
151
+
152
+ Before, then after one UF2 carrying the 10.3.0 release.
153
+
154
+ ```
155
+ Adafruit CircuitPython 10.3.0-alpha.4 on 2026-07-23; Adafruit Metro RP2350 with rp2350b
156
+
157
+ Adafruit CircuitPython 10.3.0 on 2026-08-31; Adafruit Metro RP2350 with rp2350b
158
+ code.py output:
159
+ FOLDER2UF2-COMBINE-OK marker 8f3a21
160
+ lib import works
161
+
162
+ restored by a second combined UF2, 108 files identical
163
+ ```
164
+
165
+ ### ESP32 image, Metro ESP32-S3
166
+
167
+ Partition table read from the chip, not assumed.
168
+
169
+ ```
170
+ ffat data fat 0x450000 0xBB0000 11968K
171
+ wrote 43520 bytes, hash verified
172
+ volume 28032 sectors, files intact
173
+ ```
174
+
175
+ ## Safety
176
+
177
+ Firmware is untouched unless you pass `--combine`.
178
+
179
+ ```
180
+ --self-extract writes only your files, leaving others alone
181
+ an ESP32 image sized wrong overflows, so read the table
182
+ ```
183
+
184
+ ## Credit
185
+
186
+ Idea from jepler's archived mkfatimg. Thanks @todbot for the requests.
187
+
188
+ https://github.com/adafruit/circuitpython/issues/10074
189
+
190
+ ## License
191
+
192
+ MIT
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "folder2uf2"
7
+ version = "0.1.0"
8
+ description = "Ship a CircuitPython project as one file: a self-extracting code.py, a UF2 for RP2, or an image for ESP32"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Mikey Sklar", email = "mikeysklar@gmail.com" }]
14
+ keywords = ["circuitpython", "uf2", "rp2040", "rp2350", "esp32", "adafruit", "fat"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Environment :: Console",
18
+ "Intended Audience :: Developers",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Topic :: Software Development :: Embedded Systems",
22
+ "Topic :: System :: Hardware",
23
+ ]
24
+ dependencies = []
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/mikeysklar/folder2uf2"
28
+ Issues = "https://github.com/mikeysklar/folder2uf2/issues"
29
+
30
+ [project.scripts]
31
+ folder2uf2 = "folder2uf2:main"
32
+
33
+ [project.optional-dependencies]
34
+ test = ["pytest"]
35
+
36
+ [tool.setuptools.packages.find]
37
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+