Skip to content

Commit d974a3b

Browse files
committed
boot_stage2: cleanup and correctness fixes
1 parent c6f87c7 commit d974a3b

File tree

4 files changed

+76
-36
lines changed

4 files changed

+76
-36
lines changed

src/rp2_common/boot_stage2/CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# PICO_CMAKE_CONFIG: PICO_DEFAULT_BOOT_STAGE2_FILE, Default stage2 file to use unless overridden by pico_set_boot_stage2 on the TARGET; this setting is useful when explicitly setting the default build from a per board CMake file, group=build
2-
# PICO_CMAKE_CONFIG: PICO_DEFAULT_BOOT_STAGE2, Simpler alternative to specifying PICO_DEFAULT_BOOT_STAGE2_FILE where the file is src/boards/{PICO_DEFAULT_BOOT_STAGE2_FILE}.S, default=compile_time_choice, group=build
1+
# PICO_CMAKE_CONFIG: PICO_DEFAULT_BOOT_STAGE2_FILE, Default boot stage 2 file to use unless overridden by pico_set_boot_stage2 on the TARGET; this setting is useful when explicitly setting the default build from a per board CMake file, group=build
2+
# PICO_CMAKE_CONFIG: PICO_DEFAULT_BOOT_STAGE2, Simpler alternative to specifying PICO_DEFAULT_BOOT_STAGE2_FILE where the file is src/rp2_common/boot_stage2/{PICO_DEFAULT_BOOT_STAGE2}.S, default=compile_time_choice, group=build
3+
34
if (DEFINED ENV{PICO_DEFAULT_BOOT_STAGE2_FILE})
45
set(PICO_DEFAULT_BOOT_STAGE2_FILE $ENV{PICO_DEFAULT_BOOT_STAGE2_FILE})
56
message("Using PICO_DEFAULT_BOOT_STAGE2_FILE from environment ('${PICO_DEFAULT_BOOT_STAGE2_FILE}')")
7+
elif (PICO_DEFAULT_BOOT_STAGE2_FILE)
8+
# explicitly set, so cache it
9+
set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_DEFAULT_BOOT_STAGE2_FILE}" CACHE STRING "boot stage 2 source file" FORCE)
610
endif()
7-
set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_DEFAULT_BOOT_STAGE2_FILE}" CACHE STRING "boot_stage2 source file" FORCE)
811

912
set(PICO_BOOT_STAGE2_COMPILE_TIME_CHOICE_NAME compile_time_choice) # local var
1013
if (NOT PICO_DEFAULT_BOOT_STAGE2_FILE)
@@ -15,12 +18,12 @@ if (NOT PICO_DEFAULT_BOOT_STAGE2_FILE)
1518
if (NOT DEFINED PICO_DEFAULT_BOOT_STAGE2)
1619
set(PICO_DEFAULT_BOOT_STAGE2 ${PICO_BOOT_STAGE2_COMPILE_TIME_CHOICE_NAME})
1720
endif()
18-
set(PICO_DEFAULT_BOOT_STAGE2 "${PICO_DEFAULT_BOOT_STAGE2}" CACHE STRING "boot_stage2 short name" FORCE)
21+
set(PICO_DEFAULT_BOOT_STAGE2 "${PICO_DEFAULT_BOOT_STAGE2}" CACHE STRING "boot stage 2 short name" FORCE)
1922
set(PICO_DEFAULT_BOOT_STAGE2_FILE "${CMAKE_CURRENT_LIST_DIR}/${PICO_DEFAULT_BOOT_STAGE2}.S")
2023
endif()
2124

2225
if (NOT EXISTS ${PICO_DEFAULT_BOOT_STAGE2_FILE})
23-
message(FATAL_ERROR "Specified boot_stage2 source '${PICO_DEFAULT_BOOT_STAGE2_FILE}' does not exist.")
26+
message(FATAL_ERROR "Specified boot stage 2 source '${PICO_DEFAULT_BOOT_STAGE2_FILE}' does not exist.")
2427
endif()
2528

2629
# needed by function below
@@ -52,15 +55,15 @@ function(pico_define_boot_stage2 NAME SOURCES)
5255

5356
pico_add_dis_output(${NAME})
5457
pico_add_map_output(${NAME})
55-
58+
5659
set(ORIGINAL_BIN ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.bin)
5760
set(PADDED_CHECKSUMMED_ASM ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_padded_checksummed.S)
5861

5962
find_package (Python3 REQUIRED COMPONENTS Interpreter)
6063

6164
add_custom_target(${NAME}_bin DEPENDS ${ORIGINAL_BIN})
6265
add_custom_command(OUTPUT ${ORIGINAL_BIN} DEPENDS ${NAME} COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${NAME}> ${ORIGINAL_BIN})
63-
66+
6467
add_custom_target(${NAME}_padded_checksummed_asm DEPENDS ${PADDED_CHECKSUMMED_ASM})
6568
add_custom_command(OUTPUT ${PADDED_CHECKSUMMED_ASM} DEPENDS ${ORIGINAL_BIN}
6669
COMMAND ${Python3_EXECUTABLE} ${PICO_BOOT_STAGE2_DIR}/pad_checksum -s 0xffffffff ${ORIGINAL_BIN} ${PADDED_CHECKSUMMED_ASM}
@@ -89,7 +92,7 @@ macro(pico_set_boot_stage2 TARGET NAME)
8992
if ("EXECUTABLE" STREQUAL "${target_type}")
9093
set_target_properties(${TARGET} PROPERTIES PICO_TARGET_BOOT_STAGE2 "${NAME}")
9194
else()
92-
message(FATAL_ERROR "boot stage2 implementation must be set on executable not library")
95+
message(FATAL_ERROR "boot stage 2 implementation must be set on executable not library")
9396
endif()
9497
endmacro()
9598

src/rp2_common/boot_stage2/compile_time_choice.S

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,9 @@
1111
#include "boot_stage2/config.h"
1212

1313
#ifdef PICO_BUILD_BOOT_STAGE2_NAME
14-
// boot stage2 is configured by cmake, so use the name specified there
14+
// boot stage 2 is configured by cmake, so use the name specified there
1515
#error PICO_BUILD_BOOT_STAGE2_NAME should not be defined for compile_time_choice builds
1616
#else
17-
// boot stage2 is selected by board configu header, so we have to do some work
18-
#if PICO_BOOT_STAGE2_CHOOSE_IS25LP080
19-
#include "boot2_is25lp080.S"
20-
#elif PICO_BOOT_STAGE2_CHOOSE_W25Q080
21-
#include "boot2_w28q080.S"
22-
#elif PICO_BOOT_STAGE2_CHOOSE_W25X10CL
23-
#include "boot2_w25x10cl.S"
24-
#elif PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H
25-
#include "boot2_generic_03h.S"
26-
#else
27-
#error unknown boot stage2 choice
28-
#endif
17+
// boot stage 2 is selected by board config header, and PICO_BOOT_STAGE2_ASM is set in boot_stage2/config.h
18+
#include PICO_BOOT_STAGE2_ASM
2919
#endif

src/rp2_common/boot_stage2/include/boot_stage2/config.h

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,74 @@
99

1010
// NOTE THIS HEADER IS INCLUDED FROM ASSEMBLY
1111

12+
#include "pico/config.h"
13+
1214
// PICO_CONFIG: PICO_BUILD_BOOT_STAGE2_NAME, The name of the boot stage 2 if selected by the build, group=boot_stage2
13-
// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_IS25LP080, Select boot2_is25lp080 as the boot stage 2 when no boot stage2 selection is made by the CMake build, type=bool, default=false, group=boot_stage2
14-
// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25Q080, Select boot2_w28q080 as the boot stage 2 when no boot stage2 selection is made by the CMake build, type=bool, default=false, group=boot_stage2
15-
// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25X10CL, Select boot2_is25lp080 as the boot stage 2 when no boot stage2 selection is made by the CMake build, type=bool, default=false, group=boot_stage2
16-
// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H, Select boot2_generic_03h as the boot stage 2 when no boot stage2 selection is made by the CMake build, type=bool, default=true, group=boot_stage2
15+
#ifdef PICO_BUILD_BOOT_STAGE2_NAME
16+
#define _BOOT_STAGE2_SELECTED
17+
#else
18+
// check that multiple boot stage 2 options haven't been set...
19+
20+
// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_IS25LP080, Select boot2_is25lp080 as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=0, group=boot_stage2
21+
#ifndef PICO_BOOT_STAGE2_CHOOSE_IS25LP080
22+
#define PICO_BOOT_STAGE2_CHOOSE_IS25LP080 0
23+
#elif PICO_BOOT_STAGE2_CHOOSE_IS25LP080
24+
#ifdef _BOOT_STAGE2_SELECTED
25+
#error multiple boot stage 2 options chosen
26+
#endif
27+
#define _BOOT_STAGE2_SELECTED
28+
#endif
29+
// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25Q080, Select boot2_w25q080 as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=0, group=boot_stage2
30+
#ifndef PICO_BOOT_STAGE2_CHOOSE_W25Q080
31+
#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 0
32+
#elif PICO_BOOT_STAGE2_CHOOSE_W25Q080
33+
#ifdef _BOOT_STAGE2_SELECTED
34+
#error multiple boot stage 2 options chosen
35+
#endif
36+
#define _BOOT_STAGE2_SELECTED
37+
#endif
38+
// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25X10CL, Select boot2_w25x10cl as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=0, group=boot_stage2
39+
#ifndef PICO_BOOT_STAGE2_CHOOSE_W25X10CL
40+
#define PICO_BOOT_STAGE2_CHOOSE_W25X10CL 0
41+
#elif PICO_BOOT_STAGE2_CHOOSE_W25X10CL
42+
#ifdef _BOOT_STAGE2_SELECTED
43+
#error multiple boot stage 2 options chosen
44+
#endif
45+
#define _BOOT_STAGE2_SELECTED
46+
#endif
47+
// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H, Select boot2_generic_03h as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=1, group=boot_stage2
48+
#if defined(PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H) && PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H
49+
#ifdef _BOOT_STAGE2_SELECTED
50+
#error multiple boot stage 2 options chosen
51+
#endif
52+
#define _BOOT_STAGE2_SELECTED
53+
#endif
54+
55+
#endif // PICO_BUILD_BOOT_STAGE2_NAME
1756

1857
#ifdef PICO_BUILD_BOOT_STAGE2_NAME
19-
// boot stage2 is configured by cmake, so use the name specified there
58+
// boot stage 2 is configured by cmake, so use the name specified there
2059
#define PICO_BOOT_STAGE2_NAME PICO_BUILD_BOOT_STAGE2_NAME
2160
#else
22-
// boot stage2 is selected by board configu header, so we have to do some work
23-
// NOTE: this switch is mirrored in compile_time_choice.S
61+
// boot stage 2 is selected by board config header, so we have to do some work
2462
#if PICO_BOOT_STAGE2_CHOOSE_IS25LP080
25-
#define PICO_BOOT_STAGE2_NAME "boot2_is25lp080"
63+
#define _BOOT_STAGE2 boot2_is25lp080
2664
#elif PICO_BOOT_STAGE2_CHOOSE_W25Q080
27-
#define PICO_BOOT_STAGE2_NAME "boot2_w28q080"
65+
#define _BOOT_STAGE2 boot2_w25q080
2866
#elif PICO_BOOT_STAGE2_CHOOSE_W25X10CL
29-
#define PICO_BOOT_STAGE2_NAME "boot2_w25x10cl"
30-
#elif PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H || !defined(PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H)
67+
#define _BOOT_STAGE2 boot2_w25x10cl
68+
#elif !defined(PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H) || PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H
3169
#undef PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H
3270
#define PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H 1
33-
#define PICO_BOOT_STAGE2_NAME "boot2_generic_03h"
71+
#define _BOOT_STAGE2 boot2_generic_03h
3472
#else
35-
#error no bootstage2 is defined by PICO_BOOT_STAGE2_CHOOSE_ macro
73+
#error no boot stage 2 is defined by PICO_BOOT_STAGE2_CHOOSE_ macro
3674
#endif
75+
// we can't include cdefs in assembly, so define our own, but avoid conflict with real ones for c inclusion
76+
#define _PICO__STRING(x) #x
77+
#define _PICO__XSTRING(x) _PICO__STRING(x)
78+
#define _PICO__CONCAT1(x, y) x ## y
79+
#define PICO_BOOT_STAGE2_NAME _PICO__XSTRING(_BOOT_STAGE2)
80+
#define PICO_BOOT_STAGE2_ASM _PICO__XSTRING(_PICO__CONCAT1(_BOOT_STAGE2,.S))
81+
#endif
3782
#endif
38-
#endif

src/rp2_common/pico_standard_link/binary_info.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
#if !PICO_NO_BINARY_INFO && !PICO_NO_PROGRAM_INFO
88
#include "pico/binary_info.h"
9+
10+
#if !PICO_NO_FLASH
911
#include "boot_stage2/config.h"
12+
#endif
1013

1114
// Note we put at most 4 pieces of binary info in the reset section because that's how much spare space we had
1215
// (picked the most common ones)... if there is a link failure because of .reset section overflow then move
@@ -89,4 +92,4 @@ bi_decl(bi_program_build_attribute("All optimization disabled"))
8992
#endif
9093
#endif
9194

92-
#endif
95+
#endif

0 commit comments

Comments
 (0)