diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 162be3b915..e1d23deac5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -68,7 +68,6 @@ set(DBB-FIRMWARE-UI-SOURCES ${CMAKE_SOURCE_DIR}/src/ui/components/show_logo.c ${CMAKE_SOURCE_DIR}/src/ui/components/waiting.c ${CMAKE_SOURCE_DIR}/src/ui/screen_process.c - ${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c ${CMAKE_SOURCE_DIR}/src/touch/gestures.c ) set(DBB-FIRMWARE-UI-SOURCES ${DBB-FIRMWARE-UI-SOURCES} PARENT_SCOPE) @@ -133,7 +132,6 @@ set(DBB-BOOTLOADER-SOURCES ${CMAKE_SOURCE_DIR}/src/bootloader/mpu_regions.c ${CMAKE_SOURCE_DIR}/src/queue.c ${CMAKE_SOURCE_DIR}/src/usb/usb_processing.c - ${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c ${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_9X9.c ${CMAKE_SOURCE_DIR}/src/hardfault.c ${CMAKE_SOURCE_DIR}/src/ui/components/ui_images.c @@ -149,6 +147,7 @@ set(DRIVER-SOURCES ${CMAKE_SOURCE_DIR}/src/platform/platform_init.c ${CMAKE_SOURCE_DIR}/src/qtouch/qtouch.c ${CMAKE_SOURCE_DIR}/src/ui/oled/oled.c + ${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c ) set(DRIVER-SOURCES ${DRIVER-SOURCES} PARENT_SCOPE) @@ -520,25 +519,25 @@ if(CMAKE_CROSSCOMPILING) target_sources(${bootloader}.elf PRIVATE ${BITBOXBASE-ONLY-SOURCES}) endforeach(bootloader) - target_compile_definitions(bootloader.elf PRIVATE PRODUCT_BITBOX_MULTI) - target_compile_definitions(bootloader-development.elf PRIVATE PRODUCT_BITBOX_MULTI BOOTLOADER_DEVDEVICE) - target_compile_definitions(bootloader-semihosting.elf PRIVATE PRODUCT_BITBOX_MULTI BOOTLOADER_DEVDEVICE SEMIHOSTING) - target_compile_definitions(bootloader-development-locked.elf PRIVATE PRODUCT_BITBOX_MULTI BOOTLOADER_DEVDEVICE BOOTLOADER_PRODUCTION) + target_compile_definitions(bootloader.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1") + target_compile_definitions(bootloader-development.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" BOOTLOADER_DEVDEVICE) + target_compile_definitions(bootloader-semihosting.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" BOOTLOADER_DEVDEVICE SEMIHOSTING) + target_compile_definitions(bootloader-development-locked.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" BOOTLOADER_DEVDEVICE BOOTLOADER_PRODUCTION) set_property(TARGET bootloader-development-locked.elf PROPERTY EXCLUDE_FROM_ALL ON) - target_compile_definitions(bootloader-production.elf PRIVATE PRODUCT_BITBOX_MULTI BOOTLOADER_PRODUCTION) + target_compile_definitions(bootloader-production.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" BOOTLOADER_PRODUCTION) set_property(TARGET bootloader-production.elf PROPERTY EXCLUDE_FROM_ALL ON) - target_compile_definitions(bootloader-btc.elf PRIVATE PRODUCT_BITBOX_BTCONLY) - target_compile_definitions(bootloader-btc-development.elf PRIVATE PRODUCT_BITBOX_BTCONLY BOOTLOADER_DEVDEVICE) - target_compile_definitions(bootloader-btc-production.elf PRIVATE PRODUCT_BITBOX_BTCONLY BOOTLOADER_PRODUCTION) + target_compile_definitions(bootloader-btc.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_BTCONLY=1") + target_compile_definitions(bootloader-btc-development.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_BTCONLY=1" BOOTLOADER_DEVDEVICE) + target_compile_definitions(bootloader-btc-production.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_BTCONLY=1" BOOTLOADER_PRODUCTION) set_property(TARGET bootloader-btc-production.elf PROPERTY EXCLUDE_FROM_ALL ON) - target_compile_definitions(bootloader-bitboxbase.elf PRIVATE PRODUCT_BITBOX_BASE) - target_compile_definitions(bootloader-bitboxbase-development.elf PRIVATE BOOTLOADER_DEVDEVICE PRODUCT_BITBOX_BASE) - target_compile_definitions(bootloader-bitboxbase-semihosting.elf PRIVATE BOOTLOADER_DEVDEVICE PRODUCT_BITBOX_BASE SEMIHOSTING) - target_compile_definitions(bootloader-bitboxbase-production.elf PRIVATE BOOTLOADER_PRODUCTION PRODUCT_BITBOX_BASE) + target_compile_definitions(bootloader-bitboxbase.elf PRIVATE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1") + target_compile_definitions(bootloader-bitboxbase-development.elf PRIVATE BOOTLOADER_DEVDEVICE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1") + target_compile_definitions(bootloader-bitboxbase-semihosting.elf PRIVATE BOOTLOADER_DEVDEVICE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1" SEMIHOSTING) + target_compile_definitions(bootloader-bitboxbase-production.elf PRIVATE BOOTLOADER_PRODUCTION "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1") set_property(TARGET bootloader-bitboxbase-production.elf PROPERTY EXCLUDE_FROM_ALL ON) set(FIRMWARES @@ -609,7 +608,7 @@ if(CMAKE_CROSSCOMPILING) endforeach(firmware) target_sources(firmware.elf PRIVATE firmware.c) - target_compile_definitions(firmware.elf PRIVATE PRODUCT_BITBOX_MULTI "APP_ETH=1" "APP_U2F=1") + target_compile_definitions(firmware.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" "APP_ETH=1" "APP_U2F=1") target_sources(firmware.elf PRIVATE ${FIRMWARE-U2F-SOURCES}) target_link_libraries(firmware.elf PRIVATE bitbox02-platform) target_link_libraries(firmware.elf PRIVATE app_btc-multi) @@ -620,21 +619,21 @@ if(CMAKE_CROSSCOMPILING) target_link_libraries(firmware-semihosting.elf PRIVATE app_btc-multi) # Select an implementation of the system calls that can communicate with the debugger - target_compile_definitions(firmware-semihosting.elf PRIVATE PRODUCT_BITBOX_MULTI "APP_ETH=1" "APP_U2F=1") + target_compile_definitions(firmware-semihosting.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" "APP_ETH=1" "APP_U2F=1") target_compile_definitions(firmware-semihosting.elf PRIVATE SEMIHOSTING) target_sources(firmware-btc.elf PRIVATE firmware.c) - target_compile_definitions(firmware-btc.elf PRIVATE PRODUCT_BITBOX_BTCONLY "APP_ETH=0" "APP_U2F=0") + target_compile_definitions(firmware-btc.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_BTCONLY=1" "APP_ETH=0" "APP_U2F=0") target_link_libraries(firmware-btc.elf PRIVATE bitbox02-platform) target_link_libraries(firmware-btc.elf PRIVATE app_btc-btc) target_sources(firmware-bitboxbase.elf PRIVATE bitboxbase/bitboxbase.c) - target_compile_definitions(firmware-bitboxbase.elf PRIVATE PRODUCT_BITBOX_BASE "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") + target_compile_definitions(firmware-bitboxbase.elf PRIVATE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1" "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") target_sources(firmware-bitboxbase.elf PRIVATE ${BITBOXBASE-FIRMWARE-SOURCES}) target_link_libraries(firmware-bitboxbase.elf PRIVATE bitboxbase-platform) target_sources(firmware-bitboxbase-semihosting.elf PRIVATE bitboxbase/bitboxbase.c) - target_compile_definitions(firmware-bitboxbase-semihosting.elf PRIVATE PRODUCT_BITBOX_BASE SEMIHOSTING "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") + target_compile_definitions(firmware-bitboxbase-semihosting.elf PRIVATE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1" SEMIHOSTING "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") target_sources(firmware-bitboxbase-semihosting.elf PRIVATE ${BITBOXBASE-FIRMWARE-SOURCES}) target_link_libraries(firmware-bitboxbase-semihosting.elf PRIVATE bitboxbase-platform) @@ -646,7 +645,7 @@ if(CMAKE_CROSSCOMPILING) target_link_libraries(factory-setup.elf PRIVATE bitbox02-platform) target_sources(factory-setup-bitboxbase.elf PRIVATE factorysetup.c) - target_compile_definitions(factory-setup-bitboxbase.elf PRIVATE PRODUCT_BITBOXBASE_FACTORYSETUP "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") + target_compile_definitions(factory-setup-bitboxbase.elf PRIVATE "PLATFORM_BITBOXBASE=1" "EDITION_FACTORYSETUP=1" "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") target_link_libraries(factory-setup-bitboxbase.elf PRIVATE bitboxbase-platform) foreach(name ${BOOTLOADERS} ${FIRMWARES}) diff --git a/src/platform/platform_config.h b/src/platform/platform_config.h index ba97cbbe26..8d6160cd64 100644 --- a/src/platform/platform_config.h +++ b/src/platform/platform_config.h @@ -15,67 +15,109 @@ #ifndef _PLATFORM_CONFIG_H #define _PLATFORM_CONFIG_H -// Force the PRODUCT_ defines to be 0 or 1, so they can be used safely without risk of typos. +#if !defined(PLATFORM_BITBOX02) +#define PLATFORM_BITBOX02 0 +#elif PLATFORM_BITBOX02 != 0 && PLATFORM_BITBOX02 != 1 +#error "Invalid value for PLATFORM_BITBOX02." +#endif + +#if !defined(PLATFORM_BITBOXBASE) +#define PLATFORM_BITBOXBASE 0 +#elif PLATFORM_BITBOXBASE != 0 && PLATFORM_BITBOXBASE != 1 +#error "Invalid value for PLATFORM_BITBOXBASE." +#endif + +#if !defined(EDITION_STANDARD) +#define EDITION_STANDARD 0 +#elif EDITION_STANDARD != 0 && EDITION_STANDARD != 1 +#error "Invalid value for EDITION_STANDARD." +#endif +#if !defined(EDITION_BTCONLY) +#define EDITION_BTCONLY 0 +#elif EDITION_BTCONLY != 0 && EDITION_BTCONLY != 1 +#error "Invalid value for EDITION_BTCONLY." +#endif +#if !defined(EDITION_FACTORYSETUP) +#define EDITION_FACTORYSETUP 0 +#elif EDITION_FACTORYSETUP != 0 && EDITION_FACTORYSETUP != 1 +#error "Invalid value for EDITION_FACTORYSETUP." +#endif + +#if PLATFORM_BITBOX02 == 1 + +#if EDITION_STANDARD == 1 +#define PRODUCT_BITBOX_MULTI 1 +#elif EDITION_BTCONLY == 1 +#define PRODUCT_BITBOX_BTCONLY 1 +#elif EDITION_FACTORYSETUP == 1 +#define PRODUCT_BITBOX02_FACTORYSETUP 1 +#else +#error "Invalid EDITION value." +#endif + +#elif PLATFORM_BITBOXBASE == 1 + +#if EDITION_STANDARD == 1 +#define PRODUCT_BITBOX_BASE 1 +#elif EDITION_FACTORYSETUP == 1 +#define PRODUCT_BITBOXBASE_FACTORYSETUP 1 +#else +#error "Invalid EDITION value." +#endif + +#else +#error "Invalid PRODUCT value." +#endif #if !defined(PRODUCT_BITBOX_MULTI) #define PRODUCT_BITBOX_MULTI 0 #elif PRODUCT_BITBOX_MULTI != 1 -#error "invalid product value" +#error "invalid PRODUCT_BITBOX_MULTI value" #endif #if !defined(PRODUCT_BITBOX_BTCONLY) #define PRODUCT_BITBOX_BTCONLY 0 #elif PRODUCT_BITBOX_BTCONLY != 1 -#error "invalid product value" +#error "invalid PRODUCT_BITBOX_BTCONLY value" #endif #if !defined(PRODUCT_BITBOX_BASE) #define PRODUCT_BITBOX_BASE 0 #elif PRODUCT_BITBOX_BASE != 1 -#error "invalid product value" +#error "invalid PRODUCT_BITBOX_BASE value" #endif #if !defined(PRODUCT_BITBOX02_FACTORYSETUP) #define PRODUCT_BITBOX02_FACTORYSETUP 0 #elif PRODUCT_BITBOX02_FACTORYSETUP != 1 -#error "invald product value" +#error "invald PRODUCT_BITBOX02_FACTORYSETUP value" #endif - #if !defined(PRODUCT_BITBOXBASE_FACTORYSETUP) #define PRODUCT_BITBOXBASE_FACTORYSETUP 0 #elif PRODUCT_BITBOXBASE_FACTORYSETUP != 1 -#error "invald product value" +#error "invald PRODUCT_BITBOXBASE_FACTORYSETUP value" #endif + // Derive other useful definitions from the product. #if PRODUCT_BITBOX_MULTI == 1 -#define PLATFORM_BITBOX02 1 -#define PLATFORM_BITBOXBASE 0 #define FACTORYSETUP 0 #endif #if PRODUCT_BITBOX_BTCONLY == 1 -#define PLATFORM_BITBOX02 1 -#define PLATFORM_BITBOXBASE 0 #define FACTORYSETUP 0 #endif #if PRODUCT_BITBOX_BASE == 1 -#define PLATFORM_BITBOX02 0 -#define PLATFORM_BITBOXBASE 1 #define FACTORYSETUP 0 #endif #if PRODUCT_BITBOX02_FACTORYSETUP == 1 -#define PLATFORM_BITBOX02 1 -#define PLATFORM_BITBOXBASE 0 #define FACTORYSETUP 1 #endif #if PRODUCT_BITBOXBASE_FACTORYSETUP == 1 -#define PLATFORM_BITBOX02 0 -#define PLATFORM_BITBOXBASE 1 #define FACTORYSETUP 1 #endif diff --git a/test/device-test/CMakeLists.txt b/test/device-test/CMakeLists.txt index f76d08a988..d75b3db6ef 100644 --- a/test/device-test/CMakeLists.txt +++ b/test/device-test/CMakeLists.txt @@ -86,7 +86,7 @@ target_link_libraries(bitbox02-test-platform ) # Always enable semihosting for the test firmwares -target_compile_definitions(bitbox02-test-platform PUBLIC PRODUCT_BITBOX_MULTI SEMIHOSTING) +target_compile_definitions(bitbox02-test-platform PUBLIC "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" SEMIHOSTING) target_link_libraries(bitbox02-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) target_compile_options(bitbox02-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) @@ -193,7 +193,7 @@ target_link_libraries(bitboxbase-test-platform add_dependencies(bitboxbase-test-platform rust-cbindgen) # Always enable semihosting for the test firmwares -target_compile_definitions(bitboxbase-test-platform PUBLIC PRODUCT_BITBOX_BASE SEMIHOSTING) +target_compile_definitions(bitboxbase-test-platform PUBLIC "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1" SEMIHOSTING) target_link_libraries(bitboxbase-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) target_compile_options(bitboxbase-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index caf81ef999..47e51de424 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -18,42 +18,23 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter -Wno-missing-prototypes -Wno-missing-declarations -Wno-implicit-function-declaration -Wno-bad-function-cast") - -set(DBB-FILTERED-SOURCES - ${DBB-FIRMWARE-COMMON-SOURCES} - ${DBB-FIRMWARE-UI-COMMON-SOURCES} - ${DBB-FIRMWARE-UI-SOURCES} - ${DBB-FIRMWARE-PROTOBUF-SOURCES} - ${FIRMWARE-U2F-SOURCES} - ${DBB-FIRMWARE-USB-SOURCES} - ${DBB-FIRMWARE-USART-SOURCES} - ) - -set(IGNORE_SOURCES - "src/screen.c" - "src/ui/ugui/ugui.c" - "src/memory/nvmctrl.c" - "src/memory/smarteeprom.c" - ) - -# Exclude some files which depends on the hardware. -foreach(SOURCEFILE ${IGNORE_SOURCES}) - list(FILTER DBB-FILTERED-SOURCES EXCLUDE REGEX ".*/${SOURCEFILE}$") -endforeach() - -message("FILTERED SOURCES: ${DBB-FILTERED-SOURCES}") - set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/tools/nanopb/extra) find_package(Nanopb REQUIRED) add_library(bitbox STATIC + ${DBB-FIRMWARE-COMMON-SOURCES} ${DBB-FIRMWARE-COMPONENT-SOURCES} ${DBB-FIRMWARE-WORKFLOW-SOURCES} ${APP-BTC-SOURCES} - ${DBB-FILTERED-SOURCES} + ${DBB-FIRMWARE-UI-COMMON-SOURCES} + ${DBB-FIRMWARE-UI-SOURCES} + ${DBB-FIRMWARE-PROTOBUF-SOURCES} + ${DBB-FIRMWARE-USB-SOURCES} + ${DBB-FIRMWARE-USART-SOURCES} ${CTAES-SOURCES} ${ETHEREUM-SOURCES} + ${FIRMWARE-U2F-SOURCES} # The usb.c file mixes together hardware and testing code... This should be split. ${CMAKE_SOURCE_DIR}/src/usb/usb.c ${CMAKE_SOURCE_DIR}/src/usb/usb_frame.c @@ -94,7 +75,7 @@ set_source_files_properties( target_include_directories(bitbox SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) target_include_directories(bitbox PRIVATE ${CMAKE_SOURCE_DIR}/external/FatFs/source) target_compile_definitions(bitbox PUBLIC "PB_NO_PACKED_STRUCTS=1" "PB_FIELD_16BIT=1") -target_compile_definitions(bitbox PUBLIC "PRODUCT_BITBOX_MULTI=1" "APP_BTC=1" "APP_LTC=1" "APP_U2F=1" "APP_ETH=1") +target_compile_definitions(bitbox PUBLIC "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" "APP_BTC=1" "APP_LTC=1" "APP_U2F=1" "APP_ETH=1") add_dependencies(bitbox generate-protobufs) # Since noiseprotocol and wallycore are external projects we need to specify the dependency @@ -146,7 +127,7 @@ target_include_directories( ${INCLUDES} ${CMAKE_BINARY_DIR}/src ) -target_compile_definitions(u2f-util PUBLIC "TESTING" PRODUCT_BITBOX_MULTI "APP_U2F=1" "APP_BTC=1" "APP_LTC=1" "APP_ETH=1") +target_compile_definitions(u2f-util PUBLIC "TESTING" "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" "APP_U2F=1" "APP_BTC=1" "APP_LTC=1" "APP_ETH=1") target_compile_definitions(u2f-util PUBLIC "USE_KECCAK")