Skip to content

Commit 48ce1b5

Browse files
authored
Install pre-compiled files into source tree (#242)
* Copy newly compiled files over when using USE_PRECOMPILED=FALSE * Add action to check precompiled binaries * Fix build with precompiled * Update precompiled binaries * Remove `if: runner.os == 'Linux'` where not needed Keep the step name "Install dependencies (Linux)" in case dependencies change later, to make changing all of them simpler * Change workflow to just check for file updates, rather than identical files * Run checks in separate script * Anchor start/end of greps * Review fixups Simplify CMakeLists.txt and BUILD.bazel skips Install all ELFs as files, so they aren't marked as executable * Tidy up file checks * Add add_embedded_data_project function This fixes the BUILD_ALWAYS issues as it's now only set when `USE_PRECOMPILED=false`, and also removes the need for `${CMAKE_COMMAND} --install .` * Add back BUILD_ALWAYS It's needed so if you update the binaries (eg `git pull`) they get re-copied and re-installed
1 parent 1631e27 commit 48ce1b5

File tree

11 files changed

+136
-13
lines changed

11 files changed

+136
-13
lines changed

.github/workflows/check_help_text.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
uses: actions/checkout@v4
1414

1515
- name: Install dependencies (Linux)
16-
if: runner.os == 'Linux'
1716
run: sudo apt install cmake ninja-build python3 build-essential libusb-1.0-0-dev
1817

1918
- name: Checkout Pico SDK
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# Pass updated files in $updated_files environment variable
4+
5+
# enc_bootloader
6+
if ! echo "$updated_files" | grep -q "^enc_bootloader/.*\.elf$"; then
7+
echo "Checking enc_bootloader files for modifications as ELFs have not been updated"
8+
for file in enc_bootloader/*; do
9+
if [[ "$file" == "enc_bootloader/CMakeLists.txt" || "$file" == "enc_bootloader/BUILD.bazel" ]]; then
10+
continue
11+
fi
12+
if [[ "$updated_files" == *"$file"* ]]; then
13+
echo "File $file is in the PR but enc_bootloader ELFs have not been updated"
14+
exit 1
15+
fi
16+
done
17+
fi
18+
19+
# picoboot_flash_id
20+
if ! echo "$updated_files" | grep -q "^picoboot_flash_id/.*\.bin$"; then
21+
echo "Checking picoboot_flash_id files for modifications as BINs have not been updated"
22+
for file in picoboot_flash_id/*; do
23+
if [[ "$file" == "picoboot_flash_id/CMakeLists.txt" || "$file" == "picoboot_flash_id/BUILD.bazel" ]]; then
24+
continue
25+
fi
26+
if [[ "$updated_files" == *"$file"* ]]; then
27+
echo "File $file is in the PR but flash_id BINs have not been updated"
28+
exit 1
29+
fi
30+
done
31+
fi
32+
33+
# xip_ram_perms
34+
if ! echo "$updated_files" | grep -q "^xip_ram_perms/.*\.elf$"; then
35+
echo "Checking xip_ram_perms files for modifications as ELFs have not been updated"
36+
for file in xip_ram_perms/*; do
37+
if [[ "$file" == "xip_ram_perms/CMakeLists.txt" || "$file" == "xip_ram_perms/BUILD.bazel" ]]; then
38+
continue
39+
fi
40+
if [[ "$updated_files" == *"$file"* ]]; then
41+
echo "File $file is in the PR but xip_ram_perms ELFs have not been updated"
42+
exit 1
43+
fi
44+
done
45+
fi
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Check Precompiled Binaries
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'enc_bootloader/**'
7+
- 'picoboot_flash_id/**'
8+
- 'xip_ram_perms/**'
9+
10+
jobs:
11+
check-precompiled:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Install dependencies (Linux)
18+
run: sudo apt install cmake ninja-build python3 build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib libusb-1.0-0-dev
19+
20+
- name: Checkout Pico SDK
21+
uses: actions/checkout@v4
22+
with:
23+
repository: raspberrypi/pico-sdk
24+
ref: develop
25+
path: pico-sdk
26+
submodules: 'true'
27+
28+
- name: Build and Install
29+
run: |
30+
cmake -S . -B build -G "Ninja" -D PICO_SDK_PATH="${{ github.workspace }}/pico-sdk" -D USE_PRECOMPILED=FALSE
31+
cmake --build build
32+
sudo cmake --install build
33+
34+
- name: Check precompiled binaries have been updated
35+
run: |
36+
updated_files=$(curl -s -u "${{ github.repository_owner }}":"${{ github.token }}" -H "Accept: application/vnd.github.v3+json" "${{ github.event.pull_request._links.self.href }}/files")
37+
updated_files=$(jq -r '.[] | .filename' <<<"$updated_files")
38+
39+
export updated_files
40+
echo "Updated files: $updated_files"
41+
./.github/workflows/check_precompiled.sh
42+
43+
- name: Upload new precompiled binaries
44+
if: always()
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: precompiled-binaries
48+
path: |
49+
enc_bootloader/enc_bootloader.elf
50+
enc_bootloader/enc_bootloader_mbedtls.elf
51+
picoboot_flash_id/flash_id.bin
52+
xip_ram_perms/xip_ram_perms.elf

CMakeLists.txt

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,33 @@ if (NOT DEFINED USE_PRECOMPILED)
6262
set(USE_PRECOMPILED true)
6363
endif()
6464

65+
66+
function(add_embedded_data_project TARGET)
67+
cmake_parse_arguments(PARSE_ARGV 1 OPTS "" "PREFIX;SOURCE_DIR;BINARY_DIR" "CMAKE_ARGS")
68+
69+
if (USE_PRECOMPILED)
70+
ExternalProject_Add(${TARGET}
71+
PREFIX ${OPTS_PREFIX}
72+
SOURCE_DIR ${OPTS_SOURCE_DIR}
73+
BINARY_DIR ${OPTS_BINARY_DIR}
74+
CMAKE_ARGS ${OPTS_CMAKE_ARGS}
75+
INSTALL_COMMAND ""
76+
BUILD_ALWAYS 1
77+
)
78+
else()
79+
ExternalProject_Add(${TARGET}
80+
PREFIX ${OPTS_PREFIX}
81+
SOURCE_DIR ${OPTS_SOURCE_DIR}
82+
BINARY_DIR ${OPTS_BINARY_DIR}
83+
CMAKE_ARGS ${OPTS_CMAKE_ARGS}
84+
BUILD_ALWAYS 1
85+
)
86+
endif()
87+
endfunction()
88+
89+
6590
# compile enc_bootloader.elf
66-
ExternalProject_Add(enc_bootloader
91+
add_embedded_data_project(enc_bootloader
6792
PREFIX enc_bootloader
6893
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/enc_bootloader
6994
BINARY_DIR ${CMAKE_BINARY_DIR}/enc_bootloader
@@ -73,14 +98,12 @@ ExternalProject_Add(enc_bootloader
7398
"-DUSE_PRECOMPILED:BOOL=${USE_PRECOMPILED}"
7499
"-DUSE_MBEDTLS=0"
75100
"-DPICO_DEBUG_INFO_IN_RELEASE=OFF"
76-
BUILD_ALWAYS 1 # todo remove this
77-
INSTALL_COMMAND ""
78101
)
79102

80103
set(ENC_BOOTLOADER_ELF ${CMAKE_BINARY_DIR}/enc_bootloader/enc_bootloader.elf)
81104

82105
if (TARGET mbedtls)
83-
ExternalProject_Add(enc_bootloader_mbedtls
106+
add_embedded_data_project(enc_bootloader_mbedtls
84107
PREFIX enc_bootloader_mbedtls
85108
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/enc_bootloader
86109
BINARY_DIR ${CMAKE_BINARY_DIR}/enc_bootloader_mbedtls
@@ -90,16 +113,14 @@ if (TARGET mbedtls)
90113
"-DUSE_PRECOMPILED:BOOL=${USE_PRECOMPILED}"
91114
"-DUSE_MBEDTLS=1"
92115
"-DPICO_DEBUG_INFO_IN_RELEASE=OFF"
93-
BUILD_ALWAYS 1 # todo remove this
94-
INSTALL_COMMAND ""
95116
)
96117

97118
set(ENC_BOOTLOADER_MBEDTLS_ELF ${CMAKE_BINARY_DIR}/enc_bootloader_mbedtls/enc_bootloader.elf)
98119
endif()
99120

100121
if (NOT PICOTOOL_NO_LIBUSB)
101122
# compile xip_ram_perms.elf
102-
ExternalProject_Add(xip_ram_perms
123+
add_embedded_data_project(xip_ram_perms
103124
PREFIX xip_ram_perms
104125
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/xip_ram_perms
105126
BINARY_DIR ${CMAKE_BINARY_DIR}/xip_ram_perms
@@ -108,14 +129,12 @@ if (NOT PICOTOOL_NO_LIBUSB)
108129
"-DPICO_SDK_PATH:FILEPATH=${PICO_SDK_PATH}"
109130
"-DUSE_PRECOMPILED:BOOL=${USE_PRECOMPILED}"
110131
"-DPICO_DEBUG_INFO_IN_RELEASE=OFF"
111-
BUILD_ALWAYS 1 # todo remove this
112-
INSTALL_COMMAND ""
113132
)
114133

115134
set(XIP_RAM_PERMS_ELF ${CMAKE_BINARY_DIR}/xip_ram_perms/xip_ram_perms.elf)
116135

117136
# compile flash_id
118-
ExternalProject_Add(flash_id
137+
add_embedded_data_project(flash_id
119138
PREFIX picoboot_flash_id
120139
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/picoboot_flash_id
121140
BINARY_DIR ${CMAKE_BINARY_DIR}/picoboot_flash_id
@@ -124,8 +143,6 @@ if (NOT PICOTOOL_NO_LIBUSB)
124143
"-DPICO_SDK_PATH:FILEPATH=${PICO_SDK_PATH}"
125144
"-DUSE_PRECOMPILED:BOOL=${USE_PRECOMPILED}"
126145
"-DPICO_DEBUG_INFO_IN_RELEASE=OFF"
127-
BUILD_ALWAYS 1 # todo remove this
128-
INSTALL_COMMAND ""
129146
)
130147

131148
set(FLASH_ID_BIN ${CMAKE_BINARY_DIR}/picoboot_flash_id/flash_id.bin)

enc_bootloader/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ if (NOT USE_PRECOMPILED)
112112

113113
pico_set_binary_type(enc_bootloader no_flash)
114114
pico_add_dis_output(enc_bootloader)
115+
116+
if (USE_MBEDTLS)
117+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/enc_bootloader.elf DESTINATION ${CMAKE_CURRENT_LIST_DIR} RENAME enc_bootloader_mbedtls.elf)
118+
else()
119+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/enc_bootloader.elf DESTINATION ${CMAKE_CURRENT_LIST_DIR})
120+
endif()
115121
else()
116122
project(enc_bootloader C CXX ASM)
117123
message("Using precompiled enc_bootloader.elf")

enc_bootloader/enc_bootloader.elf

100755100644
File mode changed.
0 Bytes
Binary file not shown.

picoboot_flash_id/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ if (NOT USE_PRECOMPILED)
2525
target_link_options(flash_id PRIVATE -nostartfiles -nodefaultlibs -Ttext=0)
2626
pico_add_bin_output(flash_id)
2727
pico_add_dis_output(flash_id)
28+
29+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/flash_id.bin DESTINATION ${CMAKE_CURRENT_LIST_DIR})
2830
else()
2931
project(flash_id C CXX ASM)
3032
message("Using precompiled flash_id.bin")

picoboot_flash_id/flash_id.bin

100755100644
File mode changed.

xip_ram_perms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ if (NOT USE_PRECOMPILED)
4242
string(REPLACE "RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512k" "RAM(rwx) : ORIGIN = 0x13ffc000, LENGTH = 16k" LINKER_SCRIPT "${LINKER_SCRIPT}")
4343
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/memmap_xip_ram.ld "${LINKER_SCRIPT}")
4444
pico_set_linker_script(xip_ram_perms ${CMAKE_CURRENT_BINARY_DIR}/memmap_xip_ram.ld)
45+
46+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xip_ram_perms.elf DESTINATION ${CMAKE_CURRENT_LIST_DIR})
4547
else()
4648
project(xip_ram_perms C CXX ASM)
4749
message("Using precompiled xip_ram_perms.elf")

0 commit comments

Comments
 (0)