Skip to content

Commit be7fe7b

Browse files
committed
patch pico sdk using cmake
1 parent 3e55638 commit be7fe7b

File tree

4 files changed

+67
-48
lines changed

4 files changed

+67
-48
lines changed

.github/workflows/build-common.yml

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,11 @@ jobs:
5656
Expand-Archive -Path $output -DestinationPath "C:\arm-toolchain"
5757
echo "C:\arm-toolchain\xpack-arm-none-eabi-gcc-13.2.1-1.1\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
5858
59-
- name: Install Pico SDK 2.1.1 manually
60-
run: |
61-
git clone -b 2.1.1 --depth 1 https://github.com/raspberrypi/pico-sdk.git pico-sdk
62-
cd pico-sdk
63-
git submodule update --init
64-
git apply --ignore-whitespace --ignore-space-change --3way ../picosdk-2.0.0-visrealm-fastboot.patch || echo "Patch failed or already applied"
65-
cd ..
66-
67-
- name: Configure CMake
59+
- name: Configure CMake (with automatic SDK fetch and patch)
6860
run: |
6961
mkdir build
7062
cd build
71-
cmake -S .. -B . -G Ninja -DPICO_SDK_PATH="$PWD/../pico-sdk" -DPICO_BOARD_HEADER_DIRS="../src/boards" -DPICO_BOARD=pico9918 -DBUILD_TOOLS_FROM_SOURCE=ON
63+
cmake -S .. -B . -G Ninja -DPICO_SDK_FETCH_FROM_GIT=ON -DPICO_SDK_FETCH_FROM_GIT_TAG=2.1.1 -DPICO_BOARD_HEADER_DIRS="../src/boards" -DPICO_BOARD=pico9918 -DBUILD_TOOLS_FROM_SOURCE=ON
7264
7365
- name: Build Firmware
7466
if: ${{ inputs.build-firmware }}
@@ -115,19 +107,11 @@ jobs:
115107
sudo apt-get install -y build-essential cmake python3 python3-pip git gcc-arm-none-eabi
116108
pip3 install pillow
117109
118-
- name: Install Pico SDK 2.1.1 manually
119-
run: |
120-
git clone -b 2.1.1 --depth 1 https://github.com/raspberrypi/pico-sdk.git pico-sdk
121-
cd pico-sdk
122-
git submodule update --init
123-
git apply --ignore-whitespace --ignore-space-change --3way ../picosdk-2.0.0-visrealm-fastboot.patch || echo "Patch failed or already applied"
124-
cd ..
125-
126-
- name: Configure CMake
110+
- name: Configure CMake (with automatic SDK fetch and patch)
127111
run: |
128112
mkdir build
129113
cd build
130-
cmake -S .. -B . -G Ninja -DPICO_SDK_PATH="$PWD/../pico-sdk" -DPICO_BOARD_HEADER_DIRS="../src/boards" -DPICO_BOARD=pico9918 -DBUILD_TOOLS_FROM_SOURCE=ON
114+
cmake -S .. -B . -G Ninja -DPICO_SDK_FETCH_FROM_GIT=ON -DPICO_SDK_FETCH_FROM_GIT_TAG=2.1.1 -DPICO_BOARD_HEADER_DIRS="../src/boards" -DPICO_BOARD=pico9918 -DBUILD_TOOLS_FROM_SOURCE=ON
131115
132116
- name: Build Firmware
133117
if: ${{ inputs.build-firmware }}
@@ -180,19 +164,11 @@ jobs:
180164
sudo tar -xzf arm-toolchain.tar.gz -C /opt
181165
echo "/opt/xpack-arm-none-eabi-gcc-13.2.1-1.1/bin" >> $GITHUB_PATH
182166
183-
- name: Install Pico SDK 2.1.1 manually
184-
run: |
185-
git clone -b 2.1.1 --depth 1 https://github.com/raspberrypi/pico-sdk.git pico-sdk
186-
cd pico-sdk
187-
git submodule update --init
188-
git apply --ignore-whitespace --ignore-space-change --3way ../picosdk-2.0.0-visrealm-fastboot.patch || echo "Patch failed or already applied"
189-
cd ..
190-
191-
- name: Configure CMake
167+
- name: Configure CMake (with automatic SDK fetch and patch)
192168
run: |
193169
mkdir build
194170
cd build
195-
cmake -S .. -B . -G Ninja -DPICO_SDK_PATH="$PWD/../pico-sdk" -DPICO_BOARD_HEADER_DIRS="../src/boards" -DPICO_BOARD=pico9918 -DBUILD_TOOLS_FROM_SOURCE=ON
171+
cmake -S .. -B . -G Ninja -DPICO_SDK_FETCH_FROM_GIT=ON -DPICO_SDK_FETCH_FROM_GIT_TAG=2.1.1 -DPICO_BOARD_HEADER_DIRS="../src/boards" -DPICO_BOARD=pico9918 -DBUILD_TOOLS_FROM_SOURCE=ON
196172
197173
- name: Build Firmware
198174
if: ${{ inputs.build-firmware }}

BUILDING.md

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,18 @@ The latest PICO9918 source can be configured and built using the official [Raspb
8484
The PICO9918 firmware is the primary component - a TMS9918A VDP emulator for Raspberry Pi Pico.
8585

8686
### Quick Start - Firmware Only
87+
88+
**Option 1: Automatic SDK Download (Recommended)**
8789
```bash
8890
mkdir build && cd build
91+
cmake .. -DPICO_SDK_FETCH_FROM_GIT=ON -DPICO_SDK_FETCH_FROM_GIT_TAG=2.1.1
92+
cmake --build . --target firmware
93+
```
94+
95+
**Option 2: Manual SDK Setup**
96+
```bash
97+
# First: Follow platform-specific setup above to install SDK
98+
mkdir build && cd build
8999
cmake ..
90100
cmake --build . --target firmware
91101
```
@@ -152,20 +162,34 @@ Set build options in `.vscode/settings.json`:
152162
- **DMA**: Memory transfers and sprite processing
153163
- **Flash**: Configuration storage in upper 1MB
154164

155-
### Automatic SDK Patches
156-
The build system automatically applies performance patches to the Pico SDK:
157-
- **Fast Boot**: Optimizes ROSC (Ring Oscillator) for faster boot times
158-
- Patches are applied automatically when using `PICO_SDK_FETCH_FROM_GIT=ON`
165+
### SDK Performance Patch
166+
167+
> **✅ Automatic Patch Application**
168+
>
169+
> A performance patch is automatically applied for optimal boot times:
170+
> - **Fast Boot**: Optimizes ROSC (Ring Oscillator) for faster startup
171+
> - **Automatic**: Applied by CMake when using `PICO_SDK_FETCH_FROM_GIT=ON`
172+
> - **Manual Setup**: Still required when manually installing SDK (see platform instructions above)
173+
174+
#### How It Works
175+
- **FetchContent builds**: CMake automatically applies `picosdk-2.0.0-visrealm-fastboot.patch` after downloading the SDK
176+
- **Manual SDK installs**: You must run the `git apply` command shown in platform setup above
177+
- **Safe Operation**: Patch command includes fallback - build continues even if patch fails
159178

160179
## Building Configurator
161180

162181
The configurator creates ROM files for retro computers that can upload firmware to PICO9918.
163182

164183
### Prerequisites - Configurator
165-
In addition to firmware requirements:
166-
- **CVBasic**: Retro BASIC compiler (auto-built if missing)
167-
- **GASM80**: Z80 assembler (auto-built if missing)
168-
- **XDT99**: TI-99/4A tools (auto-built if missing)
184+
185+
> **✅ No Manual Tool Installation Required!**
186+
>
187+
> The build system **automatically downloads and builds** all required tools:
188+
> - **CVBasic** (Retro BASIC compiler)
189+
> - **GASM80** (Z80 assembler)
190+
> - **XDT99** (TI-99/4A development tools)
191+
>
192+
> Simply run the build commands below - all tools will be built from source automatically.
169193
170194
### Quick Start - Configurator
171195
```bash
@@ -206,15 +230,21 @@ cmake --build . --target creativision # CreatiVision
206230
All configurator tasks automatically depend on firmware build.
207231

208232
### Tool Auto-Building
209-
By default, the build system automatically builds CVBasic, GASM80, and XDT99 from source. This ensures builds work on any platform without pre-installed tools.
210233

211-
The system will:
212-
1. Clone tool repositories from GitHub
213-
2. Build tools from source using CMake
214-
3. Cache built tools for subsequent builds
215-
4. Use locally-built tools for ROM generation
234+
> **🚀 Zero-Configuration Tool Management**
235+
>
236+
> **By default**, the build system automatically handles all configurator tools:
216237
217-
To use existing tools instead (if available):
238+
The system will automatically:
239+
1. **Clone** tool repositories from GitHub
240+
2. **Build** tools from source using CMake
241+
3. **Cache** built tools for subsequent builds
242+
4. **Use** locally-built tools for ROM generation
243+
244+
**No manual tool installation needed!** Works on all platforms out-of-the-box.
245+
246+
#### Advanced: Use Pre-installed Tools (Optional)
247+
If you have CVBasic, GASM80, and XDT99 already installed in PATH:
218248
```bash
219249
cmake .. -DBUILD_TOOLS_FROM_SOURCE=OFF
220250
```
@@ -328,6 +358,18 @@ cmake ..
328358
# Note: PICO_SDK_FETCH_FROM_GIT_TAG has known issues with tag resolution
329359
```
330360

361+
**SDK patch issues**
362+
```bash
363+
# If patch fails to apply:
364+
git apply --ignore-whitespace --ignore-space-change --3way ../picosdk-2.0.0-visrealm-fastboot.patch
365+
366+
# If patch was already applied or conflicts:
367+
echo "Patch failed or already applied" # This is normal, firmware will still build
368+
369+
# Patch is optional but improves boot performance
370+
# Firmware works without it, just boots slower
371+
```
372+
331373
**Missing splash/font assets**
332374
```bash
333375
# Install pillow for image conversion

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ To install, just hold the 'BOOTSEL' (or 'BOOT') button while plugging the Pico i
123123
Quick start - build both firmware and configurator ROMs:
124124

125125
```bash
126+
# Automatic SDK download (recommended)
126127
mkdir build && cd build
127-
cmake ..
128+
cmake .. -DPICO_SDK_FETCH_FROM_GIT=ON -DPICO_SDK_FETCH_FROM_GIT_TAG=2.1.1
128129
cmake --build .
129130
```
130131

pico_sdk_import.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ if (NOT PICO_SDK_PATH)
4747
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
4848
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
4949
GIT_SUBMODULES_RECURSE FALSE
50-
PATCH_COMMAND ""
50+
PATCH_COMMAND ${CMAKE_COMMAND} -E chdir <SOURCE_DIR> git apply --ignore-whitespace --ignore-space-change --3way ${CMAKE_SOURCE_DIR}/picosdk-2.0.0-visrealm-fastboot.patch || ${CMAKE_COMMAND} -E echo "PICO9918: SDK patch failed or already applied (this is normal)"
5151
)
5252
else ()
5353
FetchContent_Declare(
5454
pico_sdk
5555
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
5656
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
57-
PATCH_COMMAND ""
57+
PATCH_COMMAND ${CMAKE_COMMAND} -E chdir <SOURCE_DIR> git apply --ignore-whitespace --ignore-space-change --3way ${CMAKE_SOURCE_DIR}/picosdk-2.0.0-visrealm-fastboot.patch || ${CMAKE_COMMAND} -E echo "PICO9918: SDK patch failed or already applied (this is normal)"
5858
)
5959
endif ()
6060

0 commit comments

Comments
 (0)