-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
240 lines (219 loc) · 9.02 KB
/
Copy pathCMakeLists.txt
File metadata and controls
240 lines (219 loc) · 9.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
cmake_minimum_required(VERSION 3.13)
# Do not vendor pico_sdk_import.cmake. The Makefile passes PICO_SDK_PATH.
if(NOT DEFINED PICO_SDK_PATH)
if(DEFINED ENV{PICO_SDK_PATH})
set(PICO_SDK_PATH "$ENV{PICO_SDK_PATH}" CACHE PATH "Path to Raspberry Pi Pico SDK")
endif()
endif()
if(NOT PICO_SDK_PATH)
message(FATAL_ERROR "PICO_SDK_PATH is not set. Use the top-level Makefile or pass -DPICO_SDK_PATH=/path/to/pico-sdk")
endif()
include("${PICO_SDK_PATH}/external/pico_sdk_import.cmake")
project(pico_m65jtag C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
execute_process(
COMMAND bash -c "printf '%s-%d' \"$(date +%Y-%m-%d)\" $((10#$(date +%H)*60 + 10#$(date +%M)))"
OUTPUT_VARIABLE M65_BUILD_TIME
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git rev-parse --short=8 HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
OUTPUT_VARIABLE M65_GIT_COMMITISH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT M65_GIT_COMMITISH)
set(M65_GIT_COMMITISH "nogit")
endif()
set(M65_BUILD_MARKER "${M65_BUILD_TIME}-${M65_GIT_COMMITISH}")
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/include/generated_version.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/generated/generated_version.h"
@ONLY
)
option(M65_USE_FATFS "Build with FatFs storage backend" ON)
option(M65_HAVE_SD_INIT_DRIVER "Call sd_init_driver() before f_mount(); usually not needed for recent carlk3 library" OFF)
option(M65_ENABLE_WIFI_REMOTE "Build Pico W WiFi remote-delivery support" OFF)
option(M65_BOOTLOADER_APP "Link firmware to run from resident bootloader slot 0" OFF)
option(M65_BUILD_FACTORY_BOOTLOADER "Build the resident factory bootloader target" OFF)
option(M65_BOOT_DIAG "Enable early boot diagnostic breadcrumbs on UART0 and optional LED GPIO" OFF)
set(M65_BOOTLOADER_SLOT0_OFFSET "0x10000" CACHE STRING "Resident bootloader slot 0 flash offset")
set(M65_BOOTLOADER_SLOT_SIZE "0xF0000" CACHE STRING "Resident bootloader application slot size")
set(M65_BOOT_DIAG_UART_BAUD "115200" CACHE STRING "UART baud for early boot diagnostics")
set(M65_BOOT_DIAG_PIN "" CACHE STRING "Optional early boot diagnostic GPIO LED pin; empty uses board default when available")
set(M65_SD_MODE "" CACHE STRING "Optional compile-time SD mode override: M65_SD_MODE_AUTO, M65_SD_MODE_HW_SPI, or M65_SD_MODE_SCHEMATIC_BITBANG")
set(FATFS_SD_SPI_PATH "${CMAKE_CURRENT_LIST_DIR}/third_party/no-OS-FatFS-SD-SPI-RPi-Pico" CACHE PATH "Path to no-OS-FatFS-SD-SPI-RPi-Pico repository")
add_executable(pico_m65jtag
src/bootsel_button.c
src/main.c
src/uart_cmd.c
src/jtag_gpio.c
src/core_file.c
src/core_filter.c
src/machine_identity.c
src/remote_auth.c
src/remote_http.c
src/signed_file.c
src/usb_descriptors.c
src/write_gate.c
)
target_include_directories(pico_m65jtag PRIVATE include)
target_include_directories(pico_m65jtag PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/generated")
target_include_directories(pico_m65jtag PRIVATE
"${PICO_SDK_PATH}/lib/mbedtls/include"
"${PICO_SDK_PATH}/lib/mbedtls/include/mbedtls"
"${PICO_SDK_PATH}/lib/mbedtls/library"
)
target_compile_definitions(pico_m65jtag PRIVATE
MBEDTLS_CONFIG_FILE="m65_mbedtls_config.h"
M65_PICO_BOARD_NAME="${PICO_BOARD}"
USBD_MANUFACTURER="MEGA65"
USBD_PRODUCT="MEGA65 Expansion Board Integrated JTAG"
USBD_DESC_STR_MAX=64
PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS=0
PICO_STDIO_USB_STDOUT_TIMEOUT_US=10000
PICO_STDIO_DEADLOCK_TIMEOUT_MS=10
)
if(M65_BOOT_DIAG)
target_compile_definitions(pico_m65jtag PRIVATE
M65_BOOT_DIAG=1
M65_BOOT_DIAG_UART_BAUD=${M65_BOOT_DIAG_UART_BAUD}
)
endif()
if(M65_BOOT_DIAG_PIN)
target_compile_definitions(pico_m65jtag PRIVATE M65_BOOT_DIAG_PIN=${M65_BOOT_DIAG_PIN})
endif()
if(M65_SD_MODE)
target_compile_definitions(pico_m65jtag PRIVATE M65_SD_MODE=${M65_SD_MODE})
endif()
if(M65_BOOTLOADER_APP)
target_sources(pico_m65jtag PRIVATE src/ota_apply.c)
target_link_libraries(pico_m65jtag hardware_flash)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated/factory_linker")
file(WRITE
"${CMAKE_CURRENT_BINARY_DIR}/generated/factory_linker/pico_flash_region.ld"
"FLASH(rx) : ORIGIN = 0x10000000 + ${M65_BOOTLOADER_SLOT0_OFFSET}, LENGTH = ${M65_BOOTLOADER_SLOT_SIZE}\n"
)
pico_add_linker_script_override_path(
pico_m65jtag
"${CMAKE_CURRENT_BINARY_DIR}/generated/factory_linker"
FILES pico_flash_region.ld
)
target_compile_definitions(pico_m65jtag PRIVATE
M65_BOOTLOADER_APP=1
M65_RESIDENT_BOOTLOADER=1
M65_BOOTLOADER_SLOT0_OFFSET=${M65_BOOTLOADER_SLOT0_OFFSET}
M65_BOOTLOADER_SLOT_SIZE=${M65_BOOTLOADER_SLOT_SIZE}
)
endif()
target_link_libraries(pico_m65jtag
pico_stdlib
hardware_uart
hardware_gpio
hardware_timer
hardware_spi
hardware_watchdog
hardware_sync
pico_mbedtls_crypto
)
if(M65_ENABLE_WIFI_REMOTE)
if(NOT PICO_CYW43_SUPPORTED)
message(FATAL_ERROR "M65_ENABLE_WIFI_REMOTE requires a Pico W-class board, e.g. -DPICO_BOARD=pico_w")
endif()
target_compile_definitions(pico_m65jtag PRIVATE M65_WIFI_SUPPORTED=1)
target_link_libraries(pico_m65jtag pico_cyw43_arch_lwip_poll)
else()
target_compile_definitions(pico_m65jtag PRIVATE M65_WIFI_SUPPORTED=0)
endif()
if(M65_USE_FATFS)
target_sources(pico_m65jtag PRIVATE
src/storage_fatfs.c
src/hw_config.c
)
target_compile_definitions(pico_m65jtag PRIVATE M65_USE_FATFS=1)
if(M65_HAVE_SD_INIT_DRIVER)
target_compile_definitions(pico_m65jtag PRIVATE HAVE_SD_INIT_DRIVER=1)
endif()
# carlk3/no-OS-FatFS-SD-SPI-RPi-Pico has no root CMakeLists.txt; the
# library CMake project is under FatFs_SPI/. Accept either that repo root
# or a direct path to FatFs_SPI for less painful local hacking.
if(EXISTS "${FATFS_SD_SPI_PATH}/FatFs_SPI/CMakeLists.txt")
set(FATFS_SPI_CMAKE_DIR "${FATFS_SD_SPI_PATH}/FatFs_SPI")
elseif(EXISTS "${FATFS_SD_SPI_PATH}/CMakeLists.txt")
set(FATFS_SPI_CMAKE_DIR "${FATFS_SD_SPI_PATH}")
else()
message(FATAL_ERROR "FatFs SPI backend not found at ${FATFS_SD_SPI_PATH}. Expected CMakeLists.txt at <repo>/FatFs_SPI/CMakeLists.txt. Run: make fatfs")
endif()
add_subdirectory("${FATFS_SPI_CMAKE_DIR}" fatfs_spi EXCLUDE_FROM_ALL)
# The FatFs_SPI target normally publishes its include paths, but older
# copies of the helper repo are inconsistent. Add the likely include roots.
target_include_directories(pico_m65jtag PRIVATE
"${FATFS_SPI_CMAKE_DIR}"
"${FATFS_SPI_CMAKE_DIR}/sd_driver"
"${FATFS_SPI_CMAKE_DIR}/ff14a/source"
"${FATFS_SPI_CMAKE_DIR}/ff15/source"
"${FATFS_SPI_CMAKE_DIR}/ff16/source"
"${FATFS_SPI_CMAKE_DIR}/source"
)
target_sources(pico_m65jtag PRIVATE src/sd_transport.c)
set(FATFS_SPI_TARGET "")
if(TARGET FatFs_SPI)
set(FATFS_SPI_TARGET FatFs_SPI)
elseif(TARGET fatfs_spi)
set(FATFS_SPI_TARGET fatfs_spi)
elseif(TARGET fatfs_sd_spi)
set(FATFS_SPI_TARGET fatfs_sd_spi)
else()
message(FATAL_ERROR "FatFs backend was added, but no known CMake target was exported. Expected FatFs_SPI.")
endif()
get_target_property(FATFS_SPI_SOURCES ${FATFS_SPI_TARGET} INTERFACE_SOURCES)
if(FATFS_SPI_SOURCES)
list(REMOVE_ITEM FATFS_SPI_SOURCES
"${FATFS_SPI_CMAKE_DIR}/sd_driver/sd_spi.c"
"${FATFS_SPI_CMAKE_DIR}/sd_driver/spi.c"
)
set_target_properties(${FATFS_SPI_TARGET} PROPERTIES INTERFACE_SOURCES "${FATFS_SPI_SOURCES}")
endif()
target_link_libraries(pico_m65jtag ${FATFS_SPI_TARGET})
else()
target_sources(pico_m65jtag PRIVATE src/storage_stub.c)
target_compile_definitions(pico_m65jtag PRIVATE M65_USE_FATFS=0)
endif()
# USB CDC is enabled so the same command protocol can be used over the Pico
# USB connector as well as over the hardware UART pins. Hardware UART is
# managed explicitly by src/uart_cmd.c rather than by stdio.
pico_enable_stdio_usb(pico_m65jtag 1)
pico_enable_stdio_uart(pico_m65jtag 0)
pico_add_extra_outputs(pico_m65jtag)
if(M65_BUILD_FACTORY_BOOTLOADER)
add_executable(m65_factory_bootloader
bootloader/main.c
)
target_compile_definitions(m65_factory_bootloader PRIVATE
M65_BOOTLOADER_SLOT0_OFFSET=${M65_BOOTLOADER_SLOT0_OFFSET}
M65_BOOTLOADER_SLOT_SIZE=${M65_BOOTLOADER_SLOT_SIZE}
)
if(M65_BOOT_DIAG)
target_compile_definitions(m65_factory_bootloader PRIVATE
M65_BOOT_DIAG=1
M65_BOOT_DIAG_UART_BAUD=${M65_BOOT_DIAG_UART_BAUD}
)
endif()
if(M65_BOOT_DIAG_PIN)
target_compile_definitions(m65_factory_bootloader PRIVATE M65_BOOT_DIAG_PIN=${M65_BOOT_DIAG_PIN})
endif()
target_link_libraries(m65_factory_bootloader
pico_stdlib
hardware_gpio
hardware_uart
hardware_watchdog
hardware_flash
hardware_sync
)
pico_enable_stdio_usb(m65_factory_bootloader 0)
pico_enable_stdio_uart(m65_factory_bootloader 0)
pico_add_extra_outputs(m65_factory_bootloader)
endif()