diff --git a/src/rp2_common/boot_stage2/CMakeLists.txt b/src/rp2_common/boot_stage2/CMakeLists.txt index 99adf40..73c3e3e 100644 --- a/src/rp2_common/boot_stage2/CMakeLists.txt +++ b/src/rp2_common/boot_stage2/CMakeLists.txt @@ -1,10 +1,13 @@ -# 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 -# 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 +# 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 +# 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 + if (DEFINED ENV{PICO_DEFAULT_BOOT_STAGE2_FILE}) set(PICO_DEFAULT_BOOT_STAGE2_FILE $ENV{PICO_DEFAULT_BOOT_STAGE2_FILE}) message("Using PICO_DEFAULT_BOOT_STAGE2_FILE from environment ('${PICO_DEFAULT_BOOT_STAGE2_FILE}')") +elif (PICO_DEFAULT_BOOT_STAGE2_FILE) + # explicitly set, so cache it + set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_DEFAULT_BOOT_STAGE2_FILE}" CACHE STRING "boot stage 2 source file" FORCE) endif() -set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_DEFAULT_BOOT_STAGE2_FILE}" CACHE STRING "boot_stage2 source file" FORCE) set(PICO_BOOT_STAGE2_COMPILE_TIME_CHOICE_NAME compile_time_choice) # local var if (NOT PICO_DEFAULT_BOOT_STAGE2_FILE) @@ -15,12 +18,12 @@ if (NOT PICO_DEFAULT_BOOT_STAGE2_FILE) if (NOT DEFINED PICO_DEFAULT_BOOT_STAGE2) set(PICO_DEFAULT_BOOT_STAGE2 ${PICO_BOOT_STAGE2_COMPILE_TIME_CHOICE_NAME}) endif() - set(PICO_DEFAULT_BOOT_STAGE2 "${PICO_DEFAULT_BOOT_STAGE2}" CACHE STRING "boot_stage2 short name" FORCE) + set(PICO_DEFAULT_BOOT_STAGE2 "${PICO_DEFAULT_BOOT_STAGE2}" CACHE STRING "boot stage 2 short name" FORCE) set(PICO_DEFAULT_BOOT_STAGE2_FILE "${CMAKE_CURRENT_LIST_DIR}/${PICO_DEFAULT_BOOT_STAGE2}.S") endif() if (NOT EXISTS ${PICO_DEFAULT_BOOT_STAGE2_FILE}) - message(FATAL_ERROR "Specified boot_stage2 source '${PICO_DEFAULT_BOOT_STAGE2_FILE}' does not exist.") + message(FATAL_ERROR "Specified boot stage 2 source '${PICO_DEFAULT_BOOT_STAGE2_FILE}' does not exist.") endif() # needed by function below @@ -52,7 +55,7 @@ function(pico_define_boot_stage2 NAME SOURCES) pico_add_dis_output(${NAME}) pico_add_map_output(${NAME}) - + set(ORIGINAL_BIN ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.bin) set(PADDED_CHECKSUMMED_ASM ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_padded_checksummed.S) @@ -60,7 +63,7 @@ function(pico_define_boot_stage2 NAME SOURCES) add_custom_target(${NAME}_bin DEPENDS ${ORIGINAL_BIN}) add_custom_command(OUTPUT ${ORIGINAL_BIN} DEPENDS ${NAME} COMMAND ${CMAKE_OBJCOPY} -Obinary $ ${ORIGINAL_BIN}) - + add_custom_target(${NAME}_padded_checksummed_asm DEPENDS ${PADDED_CHECKSUMMED_ASM}) add_custom_command(OUTPUT ${PADDED_CHECKSUMMED_ASM} DEPENDS ${ORIGINAL_BIN} 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) if ("EXECUTABLE" STREQUAL "${target_type}") set_target_properties(${TARGET} PROPERTIES PICO_TARGET_BOOT_STAGE2 "${NAME}") else() - message(FATAL_ERROR "boot stage2 implementation must be set on executable not library") + message(FATAL_ERROR "boot stage 2 implementation must be set on executable not library") endif() endmacro() diff --git a/src/rp2_common/boot_stage2/compile_time_choice.S b/src/rp2_common/boot_stage2/compile_time_choice.S index cacb9aa..5aa2b96 100644 --- a/src/rp2_common/boot_stage2/compile_time_choice.S +++ b/src/rp2_common/boot_stage2/compile_time_choice.S @@ -11,19 +11,9 @@ #include "boot_stage2/config.h" #ifdef PICO_BUILD_BOOT_STAGE2_NAME - // boot stage2 is configured by cmake, so use the name specified there + // boot stage 2 is configured by cmake, so use the name specified there #error PICO_BUILD_BOOT_STAGE2_NAME should not be defined for compile_time_choice builds #else - // boot stage2 is selected by board configu header, so we have to do some work - #if PICO_BOOT_STAGE2_CHOOSE_IS25LP080 - #include "boot2_is25lp080.S" - #elif PICO_BOOT_STAGE2_CHOOSE_W25Q080 - #include "boot2_w28q080.S" - #elif PICO_BOOT_STAGE2_CHOOSE_W25X10CL - #include "boot2_w25x10cl.S" - #elif PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H - #include "boot2_generic_03h.S" - #else - #error unknown boot stage2 choice - #endif + // boot stage 2 is selected by board config header, and PICO_BOOT_STAGE2_ASM is set in boot_stage2/config.h + #include PICO_BOOT_STAGE2_ASM #endif diff --git a/src/rp2_common/boot_stage2/include/boot_stage2/config.h b/src/rp2_common/boot_stage2/include/boot_stage2/config.h index f6fdb9f..a8179b9 100644 --- a/src/rp2_common/boot_stage2/include/boot_stage2/config.h +++ b/src/rp2_common/boot_stage2/include/boot_stage2/config.h @@ -9,30 +9,74 @@ // NOTE THIS HEADER IS INCLUDED FROM ASSEMBLY +#include "pico/config.h" + // PICO_CONFIG: PICO_BUILD_BOOT_STAGE2_NAME, The name of the boot stage 2 if selected by the build, group=boot_stage2 -// 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 -// 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 -// 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 -// 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 +#ifdef PICO_BUILD_BOOT_STAGE2_NAME + #define _BOOT_STAGE2_SELECTED +#else + // check that multiple boot stage 2 options haven't been set... + +// 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 +#ifndef PICO_BOOT_STAGE2_CHOOSE_IS25LP080 + #define PICO_BOOT_STAGE2_CHOOSE_IS25LP080 0 +#elif PICO_BOOT_STAGE2_CHOOSE_IS25LP080 + #ifdef _BOOT_STAGE2_SELECTED + #error multiple boot stage 2 options chosen + #endif + #define _BOOT_STAGE2_SELECTED +#endif +// 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 +#ifndef PICO_BOOT_STAGE2_CHOOSE_W25Q080 + #define PICO_BOOT_STAGE2_CHOOSE_W25Q080 0 +#elif PICO_BOOT_STAGE2_CHOOSE_W25Q080 + #ifdef _BOOT_STAGE2_SELECTED + #error multiple boot stage 2 options chosen + #endif + #define _BOOT_STAGE2_SELECTED +#endif +// 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 +#ifndef PICO_BOOT_STAGE2_CHOOSE_W25X10CL + #define PICO_BOOT_STAGE2_CHOOSE_W25X10CL 0 +#elif PICO_BOOT_STAGE2_CHOOSE_W25X10CL + #ifdef _BOOT_STAGE2_SELECTED + #error multiple boot stage 2 options chosen + #endif + #define _BOOT_STAGE2_SELECTED +#endif +// 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 +#if defined(PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H) && PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H + #ifdef _BOOT_STAGE2_SELECTED + #error multiple boot stage 2 options chosen + #endif + #define _BOOT_STAGE2_SELECTED +#endif + +#endif // PICO_BUILD_BOOT_STAGE2_NAME #ifdef PICO_BUILD_BOOT_STAGE2_NAME - // boot stage2 is configured by cmake, so use the name specified there + // boot stage 2 is configured by cmake, so use the name specified there #define PICO_BOOT_STAGE2_NAME PICO_BUILD_BOOT_STAGE2_NAME #else - // boot stage2 is selected by board configu header, so we have to do some work - // NOTE: this switch is mirrored in compile_time_choice.S + // boot stage 2 is selected by board config header, so we have to do some work #if PICO_BOOT_STAGE2_CHOOSE_IS25LP080 - #define PICO_BOOT_STAGE2_NAME "boot2_is25lp080" + #define _BOOT_STAGE2 boot2_is25lp080 #elif PICO_BOOT_STAGE2_CHOOSE_W25Q080 - #define PICO_BOOT_STAGE2_NAME "boot2_w28q080" + #define _BOOT_STAGE2 boot2_w25q080 #elif PICO_BOOT_STAGE2_CHOOSE_W25X10CL - #define PICO_BOOT_STAGE2_NAME "boot2_w25x10cl" - #elif PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H || !defined(PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H) + #define _BOOT_STAGE2 boot2_w25x10cl + #elif !defined(PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H) || PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H #undef PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H #define PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H 1 - #define PICO_BOOT_STAGE2_NAME "boot2_generic_03h" + #define _BOOT_STAGE2 boot2_generic_03h #else - #error no bootstage2 is defined by PICO_BOOT_STAGE2_CHOOSE_ macro + #error no boot stage 2 is defined by PICO_BOOT_STAGE2_CHOOSE_ macro #endif + // we can't include cdefs in assembly, so define our own, but avoid conflict with real ones for c inclusion + #define _PICO__STRING(x) #x + #define _PICO__XSTRING(x) _PICO__STRING(x) + #define _PICO__CONCAT1(x, y) x ## y + #define PICO_BOOT_STAGE2_NAME _PICO__XSTRING(_BOOT_STAGE2) + #define PICO_BOOT_STAGE2_ASM _PICO__XSTRING(_PICO__CONCAT1(_BOOT_STAGE2,.S)) +#endif #endif -#endif \ No newline at end of file diff --git a/src/rp2_common/pico_standard_link/binary_info.c b/src/rp2_common/pico_standard_link/binary_info.c index bde2027..aa67ac4 100644 --- a/src/rp2_common/pico_standard_link/binary_info.c +++ b/src/rp2_common/pico_standard_link/binary_info.c @@ -6,7 +6,10 @@ #if !PICO_NO_BINARY_INFO && !PICO_NO_PROGRAM_INFO #include "pico/binary_info.h" + +#if !PICO_NO_FLASH #include "boot_stage2/config.h" +#endif // Note we put at most 4 pieces of binary info in the reset section because that's how much spare space we had // (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")) #endif #endif -#endif \ No newline at end of file +#endif