Fix build for 2040

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>

# Conflicts:
#	picokeys_sdk_import.cmake
This commit is contained in:
Pol Henarejos
2026-06-11 16:45:05 +02:00
parent 3a142cb575
commit f94c74a74c
4 changed files with 48 additions and 20 deletions

View File

@@ -1,5 +1,13 @@
include_guard(GLOBAL) include_guard(GLOBAL)
function(picokeys_trusted_region_enabled out_var)
if(PICO_RP2350 OR ENABLE_EMULATION OR ESP_PLATFORM)
set(${out_var} TRUE PARENT_SCOPE)
else()
set(${out_var} FALSE PARENT_SCOPE)
endif()
endfunction()
macro(picokeys_init_trusted_config) macro(picokeys_init_trusted_config)
set(PICOKEYS_TRUSTED_REGION_FLASH_BASE "0x100B0000" CACHE STRING "Fixed flash base for the trusted measurement region on Pico firmware builds") set(PICOKEYS_TRUSTED_REGION_FLASH_BASE "0x100B0000" CACHE STRING "Fixed flash base for the trusted measurement region on Pico firmware builds")
set(PICOKEYS_TRUSTED_STATE_RAM_BASE "0x20070000" CACHE STRING "Fixed RAM base for trusted writable state on Pico firmware builds") set(PICOKEYS_TRUSTED_STATE_RAM_BASE "0x20070000" CACHE STRING "Fixed RAM base for trusted writable state on Pico firmware builds")
@@ -27,6 +35,8 @@ macro(picokeys_init_trusted_config)
endmacro() endmacro()
function(configure_picokeys_mbedtls_target target_name) function(configure_picokeys_mbedtls_target target_name)
picokeys_trusted_region_enabled(enable_trusted_region)
if(enable_trusted_region)
target_sources(${target_name} PRIVATE ${TRUSTED_MBEDTLS_HELPER_SOURCES}) target_sources(${target_name} PRIVATE ${TRUSTED_MBEDTLS_HELPER_SOURCES})
target_compile_definitions(${target_name} PRIVATE target_compile_definitions(${target_name} PRIVATE
MBEDTLS_PLATFORM_ZEROIZE_ALT MBEDTLS_PLATFORM_ZEROIZE_ALT
@@ -36,6 +46,7 @@ function(configure_picokeys_mbedtls_target target_name)
memcmp=picokeys_trusted_memcmp memcmp=picokeys_trusted_memcmp
) )
target_compile_options(${target_name} PRIVATE -fno-builtin) target_compile_options(${target_name} PRIVATE -fno-builtin)
endif()
endfunction() endfunction()
function(configure_picokeys_trusted_mbedtls_target target_name) function(configure_picokeys_trusted_mbedtls_target target_name)
@@ -77,7 +88,7 @@ endfunction()
macro(picokeys_setup_trusted_mbedtls) macro(picokeys_setup_trusted_mbedtls)
if(NOT SKIP_MBEDTLS_FOR_OPENSSL_EMULATION) if(NOT SKIP_MBEDTLS_FOR_OPENSSL_EMULATION)
if(NOT ESP_PLATFORM) if(NOT ESP_PLATFORM)
if(PICO_PLATFORM AND NOT ENABLE_EMULATION) if(PICO_PLATFORM AND PICO_RP2350 AND NOT ENABLE_EMULATION)
add_library(trusted_mbedtls_build STATIC ${MBEDTLS_SOURCES}) add_library(trusted_mbedtls_build STATIC ${MBEDTLS_SOURCES})
target_include_directories(trusted_mbedtls_build SYSTEM PUBLIC target_include_directories(trusted_mbedtls_build SYSTEM PUBLIC
${CMAKE_CURRENT_LIST_DIR}/third-party/mbedtls/include ${CMAKE_CURRENT_LIST_DIR}/third-party/mbedtls/include
@@ -190,6 +201,8 @@ macro(picokeys_setup_trusted_mbedtls)
endmacro() endmacro()
macro(picokeys_configure_trusted_support_sources) macro(picokeys_configure_trusted_support_sources)
picokeys_trusted_region_enabled(enable_trusted_region)
if(enable_trusted_region)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU") if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/trusted_mem.c PROPERTIES set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/trusted_mem.c PROPERTIES
COMPILE_OPTIONS "-fno-builtin;-fno-tree-loop-distribute-patterns" COMPILE_OPTIONS "-fno-builtin;-fno-tree-loop-distribute-patterns"
@@ -199,6 +212,7 @@ macro(picokeys_configure_trusted_support_sources)
COMPILE_OPTIONS "-fno-builtin" COMPILE_OPTIONS "-fno-builtin"
) )
endif() endif()
endif()
if(DEFINED TRUSTED_REGION_EMBED_SOURCE) if(DEFINED TRUSTED_REGION_EMBED_SOURCE)
set_source_files_properties(${TRUSTED_REGION_EMBED_SOURCE} PROPERTIES set_source_files_properties(${TRUSTED_REGION_EMBED_SOURCE} PROPERTIES
OBJECT_DEPENDS "${TRUSTED_REGION_EMBED_INPUT}" OBJECT_DEPENDS "${TRUSTED_REGION_EMBED_INPUT}"

View File

@@ -333,8 +333,14 @@ list(APPEND PICOKEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/button.c ${CMAKE_CURRENT_LIST_DIR}/src/button.c
${CMAKE_CURRENT_LIST_DIR}/src/led/led.c ${CMAKE_CURRENT_LIST_DIR}/src/led/led.c
${CMAKE_CURRENT_LIST_DIR}/src/signal.c ${CMAKE_CURRENT_LIST_DIR}/src/signal.c
)
if(PICO_RP2350 OR ENABLE_EMULATION OR ESP_PLATFORM)
add_compile_definitions(PICOKEYS_HAS_TRUSTED_REGION=1)
list(APPEND PICOKEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/trusted.c ${CMAKE_CURRENT_LIST_DIR}/src/trusted.c
) )
endif()
if(ESP_PLATFORM) if(ESP_PLATFORM)
list(APPEND PICOKEYS_SOURCES list(APPEND PICOKEYS_SOURCES
@@ -436,7 +442,7 @@ set(LIBCVC_SOURCES
set(LIBRARIES) set(LIBRARIES)
if(NOT SKIP_MBEDTLS_FOR_OPENSSL_EMULATION) if(NOT SKIP_MBEDTLS_FOR_OPENSSL_EMULATION)
if(ESP_PLATFORM OR ENABLE_EMULATION OR NOT PICO_PLATFORM) if(ESP_PLATFORM OR ENABLE_EMULATION OR NOT PICO_PLATFORM OR PICO_RP2040)
list(APPEND LIBRARIES mbedtls) list(APPEND LIBRARIES mbedtls)
endif() endif()
endif() endif()

View File

@@ -42,7 +42,9 @@
#include "pico_time.h" #include "pico_time.h"
#include "serial.h" #include "serial.h"
#include "mbedtls/sha256.h" #include "mbedtls/sha256.h"
#if defined(PICOKEYS_HAS_TRUSTED_REGION)
#include "trusted.h" #include "trusted.h"
#endif
app_t apps[16]; app_t apps[16];
uint8_t num_apps = 0; uint8_t num_apps = 0;
@@ -153,7 +155,9 @@ int app_main(void) {
#else #else
int main(void) { int main(void) {
#endif #endif
#if defined(PICOKEYS_HAS_TRUSTED_REGION)
trusted_region_init(); trusted_region_init();
#endif
serial_init(); serial_init();
#ifndef ENABLE_EMULATION #ifndef ENABLE_EMULATION

View File

@@ -31,7 +31,9 @@
#include "random.h" #include "random.h"
#include "crypto_utils.h" #include "crypto_utils.h"
#include "usb.h" #include "usb.h"
#if defined(PICOKEYS_HAS_TRUSTED_REGION)
#include "trusted.h" #include "trusted.h"
#endif
#ifdef PICO_PLATFORM #ifdef PICO_PLATFORM
extern char __flash_binary_start; extern char __flash_binary_start;
@@ -352,6 +354,7 @@ static int cmd_read(void) {
res_APDU_size += put_uint32_be((uint32_t)tv_sec, res_APDU); res_APDU_size += put_uint32_be((uint32_t)tv_sec, res_APDU);
} }
} }
#if defined(PICOKEYS_HAS_TRUSTED_REGION)
else if (p1 == 0x5) { // GET TRUST DIGEST else if (p1 == 0x5) { // GET TRUST DIGEST
uint8_t digest[32]; uint8_t digest[32];
int ret = trusted_region_sha256(digest); int ret = trusted_region_sha256(digest);
@@ -361,6 +364,7 @@ static int cmd_read(void) {
memcpy(res_APDU, digest, 32); memcpy(res_APDU, digest, 32);
res_APDU_size = 32; res_APDU_size = 32;
} }
#endif
else { else {
return SW_INCORRECT_P1P2(); return SW_INCORRECT_P1P2();
} }