11# Build-time Patches
22
3- MicroPythonOS builds from pinned upstream sources (MicroPython, LVGL, the
4- ` lvgl_micropython ` binding) and applies a small set of patches at build time
5- instead of forking those projects. This page is the single reference for
3+ MicroPythonOS builds from pinned upstream sources (MicroPython, LVGL, ESP-IDF,
4+ the ` lvgl_micropython ` binding) and applies a small set of patches at build
5+ time instead of forking those projects. This page is the single reference for
66where those patches live, how they are applied, and how to add or update one.
77
8- ## Two families
8+ ## Three families
99
1010| Family | Where the ` .patch ` files live | What they patch | Applied by |
1111| ---| ---| ---| ---|
1212| ** lvgl_micropython patches** | root of the [ ` lvgl_micropython ` ] ( https://github.com/MicroPythonOS/lvgl_micropython ) repo (` integration ` branch) | files under its ` lib/micropython ` , ` lib/lvgl ` , or the repo itself (e.g. ` builder/ ` ) | ` scripts/build_mpos.sh ` (` apply_patch ` ) |
13+ | ** MicroPythonOS patches** | ` patches/ ` in the [ ` MicroPythonOS ` ] ( https://github.com/MicroPythonOS/MicroPythonOS ) repo | files under ` lvgl_micropython ` 's ` lib/esp-idf ` and ` lib/micropython ` , and in the ` espressif__tinyusb ` component that ESP32-S3 and ESP32-P4 builds download | ` scripts/build_mpos.sh ` (` apply_patch ` ) |
1314| ** Web-port patches** | ` scripts/web_port/ ` in the [ ` MicroPythonOS ` ] ( https://github.com/MicroPythonOS/MicroPythonOS ) repo | ` lvgl_micropython ` files needed only by the Emscripten target | ` scripts/build_mpos.sh web ` , see [ Web Port Developer Info] ( ../web-port/developer.md#submodule-patches-applied-automatically ) |
1415
15- Everything else about the two families is the same: a unified diff created
16- with ` git diff ` , applied with ` patch -p1 --forward ` , idempotent on rebuilds .
16+ All three are unified diffs, applied with ` patch -p1 --forward ` by the same
17+ helper, and idempotent on rebuilds. The sections below say where they differ .
1718
1819## How ` apply_patch ` behaves
1920
@@ -32,7 +33,8 @@ apply_patch <directory to patch in> <patch file>
3233
3334Patches that were added after some pinned ` lvgl_micropython ` commits are
3435** existence-guarded** (` if [ -f "$patch" ] ` ) so MicroPythonOS can still build
35- against older submodule pins; copy that pattern for new patches.
36+ against older submodule pins; copy that pattern for new ` lvgl_micropython `
37+ patches.
3638
3739## Current lvgl_micropython patches
3840
@@ -46,11 +48,48 @@ each; at the time of writing:
4648 (guarded).
4749- ** ESP32** builds only: ` esp32_inisetup_warn_and_format.patch ` ,
4850 ` esp32_inisetup_readsize_progsize.patch ` ,
49- ` network_wlan_country_japan.patch ` , ` network_wlan_config_country.patch ` .
50- - ** Desktop (unix/macOS)** builds only: ` unix_autoimport_main.patch ` ,
51- ` unix_native_decorator_fallback.patch ` (guarded), and
52- ` unix_sdl_release_2_32_8.patch ` (guarded; patches ` builder/unix.py ` in the
53- ` lvgl_micropython ` repo itself, applied in that directory).
51+ ` network_wlan_country_japan.patch ` , ` network_wlan_config_country.patch ` ,
52+ ` esp32_user_c_modules_abspath.patch ` (guarded; patches ` builder/esp32.py `
53+ in the ` lvgl_micropython ` repo itself, applied in that directory), and
54+ ` esp32_riscv_frozen_native_align.patch ` (guarded).
55+ - ** Desktop (unix/macOS) and web** builds: ` unix_autoimport_main.patch ` and
56+ ` unix_native_decorator_fallback.patch ` (guarded).
57+ - ** Desktop (unix/macOS)** builds only: ` unix_sdl_release_2_32_8.patch `
58+ (guarded; patches ` builder/unix.py ` in the ` lvgl_micropython ` repo itself,
59+ applied in that directory).
60+ - ** macOS** builds only: ` macos_brew_prefix.patch ` (guarded; patches
61+ ` builder/macOS.py ` in the ` lvgl_micropython ` repo itself, applied in that
62+ directory after the ` sdl2-compat ` edit described under
63+ [ Adding a patch] ( #adding-a-patch ) ).
64+
65+ ## Current MicroPythonOS patches
66+
67+ These are in ` patches/ ` and are applied for every target. Only ESP32 builds
68+ compile the files they change, but desktop and web builds apply them too, so
69+ they also need the ` lib/esp-idf ` submodule checked out.
70+
71+ - In ` lvgl_micropython/lib/esp-idf ` : ` usb_ext_port_settle.patch ` ,
72+ ` usb_ext_port_retries.patch ` , ` usb_enum_no_abort.patch ` .
73+ - In ` lvgl_micropython/lib/micropython ` : ` usb_phy_deinit.patch ` .
74+ - In the ` espressif__tinyusb ` component under
75+ ` lvgl_micropython/lib/micropython/ports/esp32/managed_components/ ` :
76+ ` tinyusb_isr_double_free.patch ` . The ESP-IDF component manager downloads
77+ this component during ESP32-S3 and ESP32-P4 builds, so it isn't there on a
78+ fresh checkout. Until it is there, ` build_mpos.sh ` skips the patch with a
79+ warning. So the first ESP32-S3 or ESP32-P4 build after a fresh checkout
80+ is built without it; build again to apply it. Other targets don't use the
81+ component, so for them the warning is harmless.
82+
83+ ## Current web-port patches
84+
85+ These are in ` scripts/web_port/ ` and are applied only for the ` web ` target.
86+ Every other build undoes them by checking out the four files they change.
87+
88+ - In ` lvgl_micropython ` : ` make.py.patch ` , ` lcd_bus_micropython.mk.patch `
89+ (patches ` ext_mod/lcd_bus/micropython.mk ` ) and ` sdl_bus.h.patch ` (patches
90+ ` ext_mod/lcd_bus/sdl_bus/sdl_bus.h ` ).
91+ - In ` lvgl_micropython/lib/micropython ` : ` gccollect.c.patch ` (patches
92+ ` ports/unix/gccollect.c ` ).
5493
5594## Adding a patch
5695
@@ -59,30 +98,66 @@ each; at the time of writing:
59982 . Generate the diff ** from the directory the patch will be applied in** , so
6099 the paths are right for ` patch -p1 ` :
61100
62- ``` bash
63- # a MicroPython change:
64- cd lvgl_micropython/lib/micropython
65- git diff -- ports/unix/main.c > ../../my_change.patch
101+ # a MicroPython change:
102+ cd lvgl_micropython/lib/micropython
103+ git diff -- ports/unix/main.c > ../../my_change.patch
66104
67- # a change to lvgl_micropython itself (e.g. builder/):
68- cd lvgl_micropython
69- git diff -- builder/unix.py > my_change.patch
70- ```
105+ # a change to lvgl_micropython itself (e.g. builder/):
106+ cd lvgl_micropython
107+ git diff -- builder/unix.py > my_change.patch
108+
109+ # a MicroPythonOS patch to ESP-IDF:
110+ cd lvgl_micropython/lib/esp-idf
111+ git diff -- components/usb/hub.c > ../../../patches/my_change.patch
112+
113+ After a build, the file also holds the changes made by the other
114+ patches and the in-place edits described below, and ` git diff ` shows
115+ those too. Keep only your own change in the patch.
71116
721173 . Commit the ` .patch ` file to ` lvgl_micropython ` (branch off ` integration ` ,
73118 see its [ CONTRIBUTING.md] ( https://github.com/MicroPythonOS/lvgl_micropython/blob/integration/CONTRIBUTING.md ) )
74119 and open a ** companion PR** in MicroPythonOS adding an ` apply_patch ` call
75120 to ` scripts/build_mpos.sh ` in the right target section, existence-guarded.
76- 4. Revert your direct edit in the submodule and rebuild: the build must
77- re-apply the patch cleanly (no ` .rej` files).
78-
79- Web-port patches follow the same steps but live in ` scripts/web_port/` and
80- need no companion PR; the update commands are in the
121+ Put the call after every other ` apply_patch ` call that changes the same
122+ file. The guard skips the patch until MicroPythonOS's ` lvgl_micropython `
123+ submodule is bumped to a commit that has the file.
124+ 4 . Revert your direct edit in the submodule and rebuild. The build log must
125+ show your patch being applied (` patching file ... ` ). Build once more: it
126+ must now say ` Patch ... already applied, skipping. `
127+
128+ MicroPythonOS patches and web-port patches live in the MicroPythonOS repo
129+ (` patches/ ` and ` scripts/web_port/ ` ), so the patch file and its ` apply_patch `
130+ call go in one PR, with no existence guard on the patch file. A new
131+ web-port patch to another file also needs that file added to
132+ ` reset_web_port_changes ` in ` build_mpos.sh ` , or other builds keep the change.
133+ Git doesn't track the downloaded tinyusb component, so make a patch for it
134+ with ` diff -u ` against an unpatched copy, with ` a/ ` and ` b/ ` in front of the
135+ paths. Put its ` apply_patch ` call inside the same check for the component's
136+ files that the current tinyusb call uses. Without it, every build that hasn't
137+ downloaded the component stops with ` FATAL ` . The web-port update commands are
138+ in the
81139[ Web Port Developer Info] ( ../web-port/developer.md#updating-a-submodule-patch ) .
82140
141+ ` build_mpos.sh ` and lvgl_micropython's ` make.py ` also edit some files in
142+ place, without a ` .patch ` file, and most of these edits stay after the build.
143+ For example, for the macOS target ` build_mpos.sh ` changes ` 'sdl2' ` to
144+ ` 'sdl2-compat' ` in the ` brew info ` call in ` builder/macOS.py ` . On desktop
145+ builds ` make.py ` edits ` ports/unix/main.c ` after the patches are applied, so
146+ a fresh checkout doesn't have those edits when the patches go in. If your
147+ patch changes such a file, keep the edited lines out of the patch and out of
148+ its context (for example with ` git diff -U1 ` ), so it applies whether or not
149+ the edit has been made.
150+
83151## Updating a patch
84152
85153Regenerate it the same way (edit the file in the submodule, ` git diff ` from
86154the apply directory, overwrite the ` .patch ` ), then rebuild from a clean
87155submodule to prove it applies. If a submodule bump makes a patch stop
88156applying, the build's ` FATAL ` message tells you which one.
157+
158+ ` tinyusb_isr_double_free.patch ` is applied to the downloaded component
159+ instead. After you change it, delete
160+ ` lvgl_micropython/lib/micropython/ports/esp32/managed_components/espressif__tinyusb `
161+ and build an ESP32-S3 or ESP32-P4 target twice. A tree that still has the
162+ old version applied needs the same delete, or the build can stop with
163+ ` FATAL ` .
0 commit comments