Skip to content

Commit bc27c70

Browse files
authored
Merge pull request #2 from pimoroni/dir2uf2-and-refactor
Dir2uf2 and refactor
2 parents c3f946b + 72946c1 commit bc27c70

File tree

11 files changed

+62
-18
lines changed

11 files changed

+62
-18
lines changed

.github/workflows/micropython.yml

+39-6
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ jobs:
3434
# MicroPython version will be contained in github.event.release.tag_name for releases
3535
RELEASE_FILE: ${{ matrix.name }}-${{ github.event.release.tag_name || github.sha }}-micropython
3636
PIMORONI_PICO_DIR: "${{ github.workspace }}/pimoroni-pico"
37-
MICROPY_BOARD_DIR: "${{ github.workspace }}/src-${{ github.sha }}/${{ matrix.BOARD }}"
3837
USER_C_MODULES: "${{ github.workspace }}/src-${{ github.sha }}/modules/${{ matrix.modules }}.cmake"
38+
USER_FS_MANIFEST: "${{ github.workspace }}/src-${{ github.sha }}/modules/${{ matrix.modules }}.txt"
39+
USER_FS_SOURCE: "${{ github.workspace }}/src-${{ github.sha }}/modules/littlefs"
3940
TAG_OR_SHA: ${{ github.event.release.tag_name || github.sha }}
4041
MICROPY_BOARD: ${{ matrix.board }}
4142
MICROPY_BOARD_VARIANT: ${{ matrix.variant }}
43+
MICROPY_BOARD_DIR: "${{ github.workspace }}/src-${{ github.sha }}/${{ matrix.BOARD }}"
44+
MICROPY_FROZEN_MANIFEST: "${{ github.workspace }}/src-${{ github.sha }}/modules/${{ matrix.modules }}.py"
4245
BOARD_NAME: ${{ matrix.name }}
4346
BUILD_TOOLS: src-${{ github.sha }}/ci/micropython.sh
4447

@@ -81,12 +84,19 @@ jobs:
8184
source $BUILD_TOOLS
8285
micropython_clone
8386
84-
- name: "Py_Decl: Checkout py_decl"
87+
- name: "Py_Decl: Checkout"
8588
uses: actions/checkout@v4
8689
with:
8790
repository: gadgetoid/py_decl
8891
ref: v0.0.2
8992
path: py_decl
93+
94+
- name: "dir2uf2: Checkout"
95+
uses: actions/checkout@v4
96+
with:
97+
repository: gadgetoid/dir2uf2
98+
ref: v0.0.7
99+
path: dir2uf2
90100

91101
- name: "MicroPython: Build MPY Cross"
92102
run: |
@@ -106,24 +116,47 @@ jobs:
106116
source $BUILD_TOOLS
107117
cmake_build
108118
109-
- name: "Py_Decl: Verify UF2"
119+
- name: "Py_Decl: Verify .uf2"
110120
shell: bash
111121
run: |
112122
python3 py_decl/py_decl.py --to-json --verify build-${{ matrix.name }}/${{ env.RELEASE_FILE }}.uf2
113123
114-
- name: Store .uf2 as artifact
124+
- name: "dir2uf2: Append filesystem to .uf2"
125+
shell: bash
126+
run: |
127+
python3 -m pip install littlefs-python==0.12.0
128+
./dir2uf2/dir2uf2 --fs-compact --append-to build-${{ matrix.name }}/${{ env.RELEASE_FILE }}.uf2 --manifest ${{env.USER_FS_MANIFEST}} --filename with-filesystem.uf2 ${{env.USER_FS_SOURCE}}/
129+
130+
- name: "Artifacts: Upload .uf2"
115131
uses: actions/upload-artifact@v4
116132
with:
117133
name: ${{ env.RELEASE_FILE }}.uf2
118134
path: build-${{ matrix.name }}/${{ env.RELEASE_FILE }}.uf2
119135

120-
- name: Upload .uf2
136+
- name: "Artifacts: Upload .uf2 with filesystem"
137+
uses: actions/upload-artifact@v4
138+
with:
139+
name: ${{ env.RELEASE_FILE }}-with-filesystem.uf2
140+
path: ${{ env.RELEASE_FILE }}-with-filesystem.uf2
141+
142+
- name: "Release: Upload .uf2"
121143
if: github.event_name == 'release'
122144
uses: actions/upload-release-asset@v1
123145
env:
124146
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125147
with:
126-
asset_path: build-${{ matrix.name }}/firmware.uf2
148+
asset_path: build-${{ matrix.name }}/${{ env.RELEASE_FILE }}.uf2
127149
upload_url: ${{ github.event.release.upload_url }}
128150
asset_name: ${{ env.RELEASE_FILE }}.uf2
151+
asset_content_type: application/octet-stream
152+
153+
- name: "Release: Upload .uf2 with filesystem"
154+
if: github.event_name == 'release'
155+
uses: actions/upload-release-asset@v1
156+
env:
157+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158+
with:
159+
asset_path: ${{ env.RELEASE_FILE }}-with-filesystem.uf2
160+
upload_url: ${{ github.event.release.upload_url }}
161+
asset_name: ${{ env.RELEASE_FILE }}-with-filesystem.uf2
129162
asset_content_type: application/octet-stream

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ should automatically handle building MicroPython for you.
1313
* pga2350 - MicroPython and Pico SDK board definitions for PGA2350, with PSRAM variant
1414
* modules/c/example - An example MicroPython C++ module, demonstrating C class bindings
1515
* modules/py_frozen - Python files intended to be frozen into the firmware
16-
* modules/py_littlefs - Python files intended to be visible/editable in the LittleFS user filesystem
16+
* modules/py_littlefs - Python files intended to be visible/editable in the LittleFS user filesystem
17+
* modules/default.py - The MicroPython manifest file, for specifying frozen libs
18+
* modules/default.txt - The dir2uf2 LittleFS manifest file, for specifying included files
19+
* modules/default.cmake - The MicroPython USER_C_MODULES file, for specifying included C/C++ modules

ci/micropython.sh

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function cmake_configure {
5252
-DMICROPY_BOARD_DIR=$MICROPY_BOARD_DIR \
5353
-DMICROPY_BOARD=$MICROPY_BOARD \
5454
-DMICROPY_BOARD_VARIANT=$MICROPY_BOARD_VARIANT \
55+
-DMICROPY_FROZEN_MANIFEST=$MICROPY_FROZEN_MANIFEST \
5556
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
5657
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
5758
}

modules/default.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Include the manifest.py from micropython/ports/rp2/boards/manifest.py
2+
include("$(PORT_DIR)/boards/manifest.py")
3+
4+
# Include the manifest.py from micropython/<board>/manifest.py
5+
include("$(BOARD_DIR)/manifest.py")
6+
7+
# Include pga/modules/py_frozen
8+
freeze("py_frozen/")

modules/default.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
example.py

modules/frozen.py

Whitespace-only changes.

modules/littlefs.txt

-1
This file was deleted.

modules/py_frozen/frozen_example.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file should be frozen into the MicroPython build
2+
# try: `import frozen_example`
3+
4+
def example():
5+
print("Hello Frozen Example")

modules/py_littlefs/example.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file should be added to the user-facing MicroPython filesystem
2+
print("Hello World")

pga2040/manifest.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
# Include the manifest.py from micropython/ports/rp2/boards/manifest.py
2-
include("$(PORT_DIR)/boards/manifest.py")
3-
4-
# Include frozen.py from pga/modules/frozen.py
5-
include("../modules/frozen.py")
1+
# Board-specific frozen libs go here

pga2350/manifest.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
# Include the manifest.py from micropython/ports/rp2/boards/manifest.py
2-
include("$(PORT_DIR)/boards/manifest.py")
3-
4-
# Include frozen.py from pga/modules/frozen.py
5-
include("../modules/frozen.py")
1+
# Board-specific frozen libs go here

0 commit comments

Comments
 (0)