From 8004cf42c1232077ed21aeec29dfa9cf0fdb0378 Mon Sep 17 00:00:00 2001 From: Utkarsh Maurya Date: Tue, 24 Jun 2025 01:51:41 +0530 Subject: [PATCH 01/14] fix: Resolve merge conflict and exchange app issue --- CMakeLists.txt | 31 +- apps/btc_family/btc_pub_key.c | 9 +- apps/btc_family/btc_txn.c | 11 +- common/coin_support/coin_specific_data.c | 146 ++++---- common/coin_support/coin_utils.c | 23 +- common/coin_support/coin_utils.h | 5 +- common/coin_support/eth.h | 6 +- common/core/core_flow_init.c | 28 +- .../crypto/mpz_operations/mpz_ecdsa.c | 2 +- .../crypto/mpz_operations/mpz_pedersen.c | 10 +- src/controller_main.c | 24 +- utilities/cmake/firmware/firmware.cmake | 349 +++++++++++++----- 12 files changed, 438 insertions(+), 206 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db642fd01..11ed8b589 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,13 +24,29 @@ execute_process(COMMAND sh utilities/proto/generate-protob.sh WORKING_DIRECTORY include(utilities/cmake/version.cmake) file(GLOB_RECURSE PROTO_SRCS "generated/proto/*.*") -list(APPEND PROTO_SRCS "vendor/nanopb/pb_common.c" "vendor/nanopb/pb_decode.c" "vendor/nanopb/pb_encode.c" "vendor/nanopb/pb_common.h" "vendor/nanopb/pb_decode.h" "vendor/nanopb/pb_encode.h" "vendor/nanopb/pb.h") +list(APPEND PROTO_SRCS + "vendor/nanopb/pb_common.c" + "vendor/nanopb/pb_decode.c" + "vendor/nanopb/pb_encode.c" + "vendor/nanopb/pb_common.h" + "vendor/nanopb/pb_decode.h" + "vendor/nanopb/pb_encode.h" + "vendor/nanopb/pb.h" +) -list (APPEND MINI_GMP_SRCS "vendor/mini-gmp/mini-gmp-helpers.c" "vendor/mini-gmp/mini-gmp.c") -list (APPEND POSEIDON_SRCS "vendor/poseidon/sources/f251.c" "vendor/poseidon/sources/poseidon.c" "vendor/poseidon/sources/poseidon_rc.c") +list (APPEND MINI_GMP_SRCS + "vendor/mini-gmp/mini-gmp-helpers.c" + "vendor/mini-gmp/mini-gmp.c" +) +list (APPEND POSEIDON_SRCS + "vendor/poseidon/sources/f251.c" + "vendor/poseidon/sources/poseidon.c" + "vendor/poseidon/sources/poseidon_rc.c" +) OPTION(DEV_SWITCH "Additional features/logs to aid developers" OFF) OPTION(UNIT_TESTS_SWITCH "Compile build for main firmware or unit tests" OFF) +OPTION(BTC_ONLY "Build firmware for Bitcoin only" OFF) # Make static functions testable via unit-tests IF(UNIT_TESTS_SWITCH) @@ -47,12 +63,17 @@ endif() if("${CMAKE_BUILD_PLATFORM}" STREQUAL "Device") include(utilities/cmake/firmware/firmware.cmake) -else() +else() # Simulator or default include(utilities/cmake/simulator/simulator.cmake) endif() # Include nanopb source headers -target_include_directories( ${EXECUTABLE} PRIVATE vendor/nanopb generated/proto vendor/mini-gmp vendor/poseidon/sources) +target_include_directories( ${EXECUTABLE} PRIVATE + vendor/nanopb + generated/proto + vendor/mini-gmp + vendor/poseidon/sources +) # Enable support for dynamically allocated fields in nanopb # Ref: vendor/nanopb/pb.h diff --git a/apps/btc_family/btc_pub_key.c b/apps/btc_family/btc_pub_key.c index f3ff53489..0566e95e0 100644 --- a/apps/btc_family/btc_pub_key.c +++ b/apps/btc_family/btc_pub_key.c @@ -70,7 +70,11 @@ #include "coin_utils.h" #include "composable_app_queue.h" #include "curves.h" + +#ifndef BTC_ONLY_BUILD #include "exchange_main.h" +#endif // BTC_ONLY_BUILD + #include "reconstruct_wallet_flow.h" #include "status_api.h" #include "ui_core_confirm.h" @@ -186,9 +190,10 @@ static bool validate_request_data(btc_get_public_key_request_t *request) { memcpy(data.params, request->initiate.wallet_id, sizeof(request->initiate.wallet_id)); +#ifndef BTC_ONLY_BUILD data.params[32] = EXCHANGE_FLOW_TAG_RECEIVE; - sign_address = exchange_app_validate_caq(data); +#endif // BTC_ONLY_BUILD return status; } @@ -302,7 +307,9 @@ void btc_get_pub_key(btc_query_t *query) { memzero(seed, sizeof(seed)); if (sign_address) { + #ifndef BTC_ONLY_BUILD exchange_sign_address(msg, sizeof(msg)); + #endif // BTC_ONLY_BUILD } if (0 < length && diff --git a/apps/btc_family/btc_txn.c b/apps/btc_family/btc_txn.c index b5422a84d..41c740d64 100644 --- a/apps/btc_family/btc_txn.c +++ b/apps/btc_family/btc_txn.c @@ -78,7 +78,11 @@ #include "composable_app_queue.h" #include "constant_texts.h" #include "curves.h" + +#ifndef BTC_ONLY_BUILD #include "exchange_main.h" +#endif // BTC_ONLY_BUILD + #include "reconstruct_wallet_flow.h" #include "status_api.h" #include "ui_core_confirm.h" @@ -308,16 +312,15 @@ static bool validate_request_data(const btc_sign_txn_request_t *request) { ERROR_DATA_FLOW_INVALID_DATA); status = false; } - +#ifndef BTC_ONLY_BUILD caq_node_data_t data = {.applet_id = get_btc_app_desc()->id}; - memzero(data.params, sizeof(data.params)); memcpy(data.params, request->initiate.wallet_id, sizeof(request->initiate.wallet_id)); data.params[32] = EXCHANGE_FLOW_TAG_SEND; - use_signature_verification = exchange_app_validate_caq(data); +#endif // BTC_ONLY_BUILD return status; } @@ -588,10 +591,12 @@ static bool get_user_verification() { } if (use_signature_verification) { + #ifndef BTC_ONLY_BUILD if (!exchange_validate_stored_signature(address, sizeof(address))) { btc_send_error(ERROR_COMMON_ERROR_UNKNOWN_ERROR_TAG, status); return false; } + #endif // BTC_ONLY_BUILD } if (!core_scroll_page(title, address, btc_send_error) || diff --git a/common/coin_support/coin_specific_data.c b/common/coin_support/coin_specific_data.c index b607ed39d..b84739fea 100644 --- a/common/coin_support/coin_specific_data.c +++ b/common/coin_support/coin_specific_data.c @@ -168,78 +168,78 @@ static uint16_t prepare_coin_specific_data_tlv( coin_specific_data, &coin_data_len, &coin_data_addr); } -static void purge_coin_specific_data() { - // Store all the unique data length and address in an array - Coin_Type coin_type_arr[MAX_UNIQUE_COIN_COUNT] = {COIN_TYPE_NEAR}; - struct meta_data_t { - Coin_Specific_Data_Struct data_struct; - uint16_t data_length; - uint32_t data_addr; - } meta_data_arr[MAX_UNIQUE_COIN_COUNT * MAX_WALLETS_ALLOWED] = {0}; - - for (size_t coin_type_index = 0; coin_type_index < MAX_UNIQUE_COIN_COUNT; - coin_type_index++) { - for (size_t wallet_id_index = 0; wallet_id_index < MAX_WALLETS_ALLOWED; - wallet_id_index++) { - size_t current_index = - coin_type_index * MAX_WALLETS_ALLOWED + wallet_id_index; - - meta_data_arr[current_index].data_length = 0; - meta_data_arr[current_index].data_addr = 0; - - meta_data_arr[current_index].data_struct.coin_type = - coin_type_arr[coin_type_index]; - memcpy(meta_data_arr[current_index].data_struct.wallet_id, - get_wallet_id(wallet_id_index), - WALLET_ID_SIZE); - find_latest_coin_data(&meta_data_arr[current_index].data_struct, - &meta_data_arr[current_index].data_length, - &meta_data_arr[current_index].data_addr); - - if (meta_data_arr[current_index].data_length > 0 && - FLASH_COIN_SPECIFIC_BASE_ADDRESS < - meta_data_arr[current_index].data_addr && - meta_data_arr[current_index].data_addr + - meta_data_arr[current_index].data_length < - FLASH_END) { - // Allocate a proper size array to store the data - meta_data_arr[current_index].data_struct.coin_data = - (uint8_t *)malloc(meta_data_arr[current_index].data_length); - ASSERT(meta_data_arr[current_index].data_struct.coin_data != NULL); - read_cmd(meta_data_arr[current_index].data_addr, - (uint32_t *)meta_data_arr[current_index].data_struct.coin_data, - meta_data_arr[current_index].data_length); - } - } - } - - // Erase everything from flash - erase_flash_coin_specific_data(); - - // Write the data back to flash - for (size_t i = 0; i < MAX_UNIQUE_COIN_COUNT * MAX_WALLETS_ALLOWED; i++) { - if (meta_data_arr[i].data_length > 0 && - FLASH_COIN_SPECIFIC_BASE_ADDRESS < meta_data_arr[i].data_addr && - meta_data_arr[i].data_addr + meta_data_arr[i].data_length < FLASH_END) { - uint16_t data_length = - (3 + WALLET_ID_SIZE) + (3 + meta_data_arr[i].data_length); - uint16_t tlv_size = 6 + data_length; - tlv_size = GET_NEXT_MULTIPLE_OF_8(tlv_size); - uint8_t tlv[tlv_size]; - memzero(tlv, sizeof(tlv)); - - uint16_t offset = - prepare_coin_specific_data_tlv(&meta_data_arr[i].data_struct, - meta_data_arr[i].data_length, - tlv, - data_length); - write_cmd( - FLASH_COIN_SPECIFIC_BASE_ADDRESS + offset, (uint32_t *)tlv, tlv_size); - - free(meta_data_arr[i].data_struct.coin_data); - } - } -} +// static void purge_coin_specific_data() { +// // Store all the unique data length and address in an array +// Coin_Type coin_type_arr[MAX_UNIQUE_COIN_COUNT] = {COIN_TYPE_NEAR}; +// struct meta_data_t { +// Coin_Specific_Data_Struct data_struct; +// uint16_t data_length; +// uint32_t data_addr; +// } meta_data_arr[MAX_UNIQUE_COIN_COUNT * MAX_WALLETS_ALLOWED] = {0}; + +// for (size_t coin_type_index = 0; coin_type_index < MAX_UNIQUE_COIN_COUNT; +// coin_type_index++) { +// for (size_t wallet_id_index = 0; wallet_id_index < MAX_WALLETS_ALLOWED; +// wallet_id_index++) { +// size_t current_index = +// coin_type_index * MAX_WALLETS_ALLOWED + wallet_id_index; + +// meta_data_arr[current_index].data_length = 0; +// meta_data_arr[current_index].data_addr = 0; + +// meta_data_arr[current_index].data_struct.coin_type = +// coin_type_arr[coin_type_index]; +// memcpy(meta_data_arr[current_index].data_struct.wallet_id, +// get_wallet_id(wallet_id_index), +// WALLET_ID_SIZE); +// find_latest_coin_data(&meta_data_arr[current_index].data_struct, +// &meta_data_arr[current_index].data_length, +// &meta_data_arr[current_index].data_addr); + +// if (meta_data_arr[current_index].data_length > 0 && +// FLASH_COIN_SPECIFIC_BASE_ADDRESS < +// meta_data_arr[current_index].data_addr && +// meta_data_arr[current_index].data_addr + +// meta_data_arr[current_index].data_length < +// FLASH_END) { +// // Allocate a proper size array to store the data +// meta_data_arr[current_index].data_struct.coin_data = +// (uint8_t *)malloc(meta_data_arr[current_index].data_length); +// ASSERT(meta_data_arr[current_index].data_struct.coin_data != NULL); +// read_cmd(meta_data_arr[current_index].data_addr, +// (uint32_t *)meta_data_arr[current_index].data_struct.coin_data, +// meta_data_arr[current_index].data_length); +// } +// } +// } + +// // Erase everything from flash +// erase_flash_coin_specific_data(); + +// // Write the data back to flash +// for (size_t i = 0; i < MAX_UNIQUE_COIN_COUNT * MAX_WALLETS_ALLOWED; i++) { +// if (meta_data_arr[i].data_length > 0 && +// FLASH_COIN_SPECIFIC_BASE_ADDRESS < meta_data_arr[i].data_addr && +// meta_data_arr[i].data_addr + meta_data_arr[i].data_length < FLASH_END) { +// uint16_t data_length = +// (3 + WALLET_ID_SIZE) + (3 + meta_data_arr[i].data_length); +// uint16_t tlv_size = 6 + data_length; +// tlv_size = GET_NEXT_MULTIPLE_OF_8(tlv_size); +// uint8_t tlv[tlv_size]; +// memzero(tlv, sizeof(tlv)); + +// uint16_t offset = +// prepare_coin_specific_data_tlv(&meta_data_arr[i].data_struct, +// meta_data_arr[i].data_length, +// tlv, +// data_length); +// write_cmd( +// FLASH_COIN_SPECIFIC_BASE_ADDRESS + offset, (uint32_t *)tlv, tlv_size); + +// free(meta_data_arr[i].data_struct.coin_data); +// } +// } +// } static int store_coin_data(const uint8_t *tlv_data, uint16_t tlv_data_size, @@ -250,7 +250,7 @@ static int store_coin_data(const uint8_t *tlv_data, (uint32_t *)tlv_data, tlv_data_size); } else { - purge_coin_specific_data(); + // purge_coin_specific_data(); uint16_t coin_data_len = 0; uint32_t coin_data_addr = 0; Coin_Specific_Data_Struct dummy = {0}; diff --git a/common/coin_support/coin_utils.c b/common/coin_support/coin_utils.c index 7e42fd171..60f925a97 100644 --- a/common/coin_support/coin_utils.c +++ b/common/coin_support/coin_utils.c @@ -58,17 +58,20 @@ */ #include "coin_utils.h" -#include "arbitrum.h" -#include "avalanche.h" -#include "bsc.h" -#include "etc.h" -#include "fantom.h" -#include "harmony.h" -#include "near.h" -#include "optimism.h" -#include "polygon.h" #include "segwit_addr.h" -#include "solana.h" + +#ifndef BTC_ONLY_BUILD + #include "arbitrum.h" + #include "avalanche.h" + #include "bsc.h" + #include "etc.h" + #include "fantom.h" + #include "harmony.h" + #include "near.h" + #include "optimism.h" + #include "polygon.h" + #include "solana.h" +#endif void s_memcpy(uint8_t *dst, const uint8_t *src, diff --git a/common/coin_support/coin_utils.h b/common/coin_support/coin_utils.h index 5a5832f07..94a785332 100644 --- a/common/coin_support/coin_utils.h +++ b/common/coin_support/coin_utils.h @@ -40,6 +40,7 @@ /// BTC TEST coin index #define BTC_TEST (BITCOIN + 0x01) +#ifndef BTC_ONLY_BUILD /// LITECOIN coin index #define LITCOIN (BITCOIN + 0x02) #define LTC_COIN_VERSION 0x00000000 @@ -61,7 +62,7 @@ /// SOLANA coin index #define SOLANA (BITCOIN + 0x1F5) - +#endif /// NATIVE SEGWIT purpose id #define NATIVE_SEGWIT 0x80000054 @@ -71,6 +72,7 @@ typedef enum Coin_Type { COIN_TYPE_BITCOIN = 0x01, COIN_TYPE_BTC_TEST = 0x02, + #ifndef BTC_ONLY_BUILD COIN_TYPE_LITECOIN = 0x03, COIN_TYPE_DOGE = 0x04, COIN_TYPE_DASH = 0x05, @@ -85,6 +87,7 @@ typedef enum Coin_Type { COIN_TYPE_HARMONY = 0x0E, COIN_TYPE_ETHEREUM_CLASSIC = 0x0f, COIN_TYPE_ARBITRUM = 0x10, + #endif } Coin_Type; #pragma pack(push, 1) diff --git a/common/coin_support/eth.h b/common/coin_support/eth.h index d8448b3b9..452e8a967 100644 --- a/common/coin_support/eth.h +++ b/common/coin_support/eth.h @@ -28,10 +28,10 @@ #include "../crypto/secp256k1.h" #include "../crypto/sha2.h" #include "../crypto/sha3.h" -#include "abi.h" +#include "../common/coin_support/eth_sign_data/abi.h" #include "coin_utils.h" -#include "eip712.pb.h" -#include "evm_txn_helpers.h" +#include "../common/coin_support/eth_sign_data/eip712.pb.h" +#include "../apps/evm_family/evm_txn_helpers.h" #define ETHEREUM_MAINNET_CHAIN 1 diff --git a/common/core/core_flow_init.c b/common/core/core_flow_init.c index ff6466188..41418fa72 100644 --- a/common/core/core_flow_init.c +++ b/common/core/core_flow_init.c @@ -63,6 +63,17 @@ #include "app_registry.h" #include "application_startup.h" +#include "../apps/inheritance_app/inheritance_main.h" +#include "main_menu.h" +#include "manager_app.h" +#include "onboarding.h" +#include "restricted_app.h" + + +#include "btc_app.h" +#include "btc_main.h" + +#ifndef BTC_ONLY_BUILD #include "arbitrum_app.h" #include "avalanche_app.h" #include "bsc_app.h" @@ -76,19 +87,15 @@ #include "exchange_main.h" #include "fantom_app.h" #include "icp_main.h" -#include "inheritance_main.h" #include "ltc_app.h" -#include "main_menu.h" -#include "manager_app.h" -#include "near_main.h" -#include "onboarding.h" #include "optimism_app.h" #include "polygon_app.h" -#include "restricted_app.h" #include "solana_main.h" #include "starknet_main.h" #include "tron_main.h" #include "xrp_main.h" +#include "near_main.h" +#endif // BTC_ONLY_BUILD /***************************************************************************** * EXTERN VARIABLES @@ -170,11 +177,18 @@ engine_ctx_t *get_core_flow_ctx(void) { } void core_init_app_registry() { + registry_add_app(get_manager_app_desc()); registry_add_app(get_btc_app_desc()); + registry_add_app(get_inheritance_app_desc()); + + +#ifndef BTC_ONLY_BUILD registry_add_app(get_ltc_app_desc()); registry_add_app(get_doge_app_desc()); registry_add_app(get_dash_app_desc()); + registry_add_app(get_inheritance_app_desc()); + registry_add_app(get_eth_app_desc()); registry_add_app(get_near_app_desc()); registry_add_app(get_polygon_app_desc()); @@ -185,10 +199,10 @@ void core_init_app_registry() { registry_add_app(get_optimism_app_desc()); registry_add_app(get_arbitrum_app_desc()); registry_add_app(get_tron_app_desc()); - registry_add_app(get_inheritance_app_desc()); registry_add_app(get_xrp_app_desc()); registry_add_app(get_starknet_app_desc()); registry_add_app(get_constellation_app_desc()); registry_add_app(get_icp_app_desc()); registry_add_app(get_exchange_app_desc()); +#endif } diff --git a/common/libraries/crypto/mpz_operations/mpz_ecdsa.c b/common/libraries/crypto/mpz_operations/mpz_ecdsa.c index 5b04a85c8..acf56d85c 100644 --- a/common/libraries/crypto/mpz_operations/mpz_ecdsa.c +++ b/common/libraries/crypto/mpz_operations/mpz_ecdsa.c @@ -61,7 +61,7 @@ #include "mpz_ecdsa.h" #include -#include +#include <../apps/starknet_app/starknet_context.h> #include "mini-gmp-helpers.h" #include diff --git a/common/libraries/crypto/mpz_operations/mpz_pedersen.c b/common/libraries/crypto/mpz_operations/mpz_pedersen.c index 5bc153089..06bb8018c 100644 --- a/common/libraries/crypto/mpz_operations/mpz_pedersen.c +++ b/common/libraries/crypto/mpz_operations/mpz_pedersen.c @@ -65,11 +65,11 @@ #include "coin_utils.h" #include "mini-gmp-helpers.h" -#include "starknet_api.h" -#include "starknet_context.h" -#include "starknet_crypto.h" -#include "starknet_helpers.h" -#include "starknet_pedersen.h" +#include "../apps/starknet_app/starknet_api.h" +#include "../apps/starknet_app/starknet_context.h" +#include "../apps/starknet_app/starknet_crypto.h" +#include "../apps/starknet_app/starknet_helpers.h" +#include "../apps/starknet_app/starknet_pedersen.h" /***************************************************************************** * EXTERN VARIABLES diff --git a/src/controller_main.c b/src/controller_main.c index 2334a6bbb..e6eaa3a99 100644 --- a/src/controller_main.c +++ b/src/controller_main.c @@ -86,25 +86,29 @@ #include #include "application_startup.h" -#include "arbitrum.h" -#include "avalanche.h" -#include "bsc.h" #include "chacha20poly1305.h" #include "communication.h" #include "constant_texts.h" #include "cryptoauthlib.h" +#include "rfc7539.h" +#include "ui_events.h" +#include "ui_instruction.h" +#include "pb_decode.h" +#include "options.h" +#include "coin_utils.h" + +#ifndef BTC_ONLY_BUILD +#include "arbitrum.h" +#include "avalanche.h" +#include "bsc.h" #include "etc.h" #include "eth.h" #include "fantom.h" #include "harmony.h" #include "near.h" #include "optimism.h" -#include "pb_decode.h" #include "polygon.h" -#include "rfc7539.h" -#include "ui_events.h" -#include "ui_instruction.h" - +#endif /** * @brief A task declared to execute a callback after a timeout. * @@ -163,7 +167,9 @@ Flash_Wallet wallet_for_flash; * @brief Message data for wallet connect EIP-712 using protobuf * */ +#ifndef BTC_ONLY_BUILD MessageData msg_data; +#endif ui_display_node *current_display_node = NULL; uint8_t provision_date[4]; @@ -214,7 +220,9 @@ void reset_flow_level() { memzero(wallet_credential_data.passphrase, sizeof(wallet_credential_data.passphrase)); cy_free(); +#ifndef BTC_ONLY_BUILD pb_release(MessageData_fields, &msg_data); +#endif current_display_node = NULL; } diff --git a/utilities/cmake/firmware/firmware.cmake b/utilities/cmake/firmware/firmware.cmake index c9a405509..f7875754b 100644 --- a/utilities/cmake/firmware/firmware.cmake +++ b/utilities/cmake/firmware/firmware.cmake @@ -1,4 +1,3 @@ - enable_language(C ASM) set(EXECUTABLE ${PROJECT_NAME}.elf) set(LINKER_SCRIPT STM32L486RGTX_FLASH.ld) @@ -7,8 +6,128 @@ set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) +# Define base source files (always built) +file(GLOB_RECURSE CORE_STM_HAL_SOURCES "stm32-hal/*.*") +file(GLOB_RECURSE CORE_SRC_SOURCES "src/*.*") + +# Common files from 'common/' subdirectories that are always needed +file(GLOB_RECURSE CORE_COMMON_INTERFACES_SOURCES "common/interfaces/*.*") +file(GLOB_RECURSE CORE_COMMON_LIBRARIES_SOURCES "common/libraries/*.*") +file(GLOB_RECURSE CORE_COMMON_STARTUP_SOURCES "common/startup/*.*") +file(GLOB_RECURSE CORE_COMMON_LOGGER_SOURCES "common/logger/*.*") +file(GLOB_RECURSE CORE_COMMON_FLASH_SOURCES "common/flash/*.*") +file(GLOB_RECURSE CORE_COMMON_FIREWALL_SOURCES "common/Firewall/*.*") +file(GLOB_RECURSE CORE_COMMON_TIMERS_SOURCES "common/timers/*.*") +# For LVGL, source files are primarily in its 'src' subdirectory. +# common/lvgl/lvgl.h is picked up by include path. common/lv_conf.h by 'common/' include path. +file(GLOB_RECURSE CORE_COMMON_LVGL_SOURCES "common/lvgl/src/**/*.c" "common/lvgl/src/**/*.h") + +# Source files from common/core/ (assumed common or internally guarded) +file(GLOB_RECURSE CORE_COMMON_CORE_SOURCES "common/core/*.c") + +set(CORE_COMMON_GENERAL_SOURCES_FROM_SUBDIRS + ${CORE_COMMON_INTERFACES_SOURCES} + ${CORE_COMMON_LIBRARIES_SOURCES} + ${CORE_COMMON_STARTUP_SOURCES} + ${CORE_COMMON_LOGGER_SOURCES} + ${CORE_COMMON_FLASH_SOURCES} + ${CORE_COMMON_FIREWALL_SOURCES} + ${CORE_COMMON_TIMERS_SOURCES} + ${CORE_COMMON_LVGL_SOURCES} + ${CORE_COMMON_CORE_SOURCES} +) + +# Specific common files that are always compiled. +# These are assumed to have internal guards for different build configurations +# or are genuinely generic. +set(CORE_COMMON_SPECIFIC_FILES + "${CMAKE_CURRENT_SOURCE_DIR}/common/assert_def.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/coin_specific_data.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/coin_utils.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/wallet.c" + # common/core/core_flow_init.c is now covered by CORE_COMMON_CORE_SOURCES glob. + # Ensure it and other common/core/*.c files have internal guards where needed. +) + +set(BASE_SOURCES + ${CORE_STM_HAL_SOURCES} + ${CORE_SRC_SOURCES} + ${CORE_COMMON_GENERAL_SOURCES_FROM_SUBDIRS} + ${CORE_COMMON_SPECIFIC_FILES} +) + +# Define app-specific sources +file(GLOB_RECURSE MANAGER_APP_SOURCES "apps/manager_app/*.*") +file(GLOB_RECURSE BTC_FAMILY_SOURCES "apps/btc_family/*.*") + +# Full build: include all apps' source files +file(GLOB_RECURSE EVM_FAMILY_SOURCES "apps/evm_family/*.*") +file(GLOB_RECURSE NEAR_APP_SOURCES "apps/near_app/*.*") +file(GLOB_RECURSE SOLANA_APP_SOURCES "apps/solana_app/*.*") +file(GLOB_RECURSE TRON_APP_SOURCES "apps/tron_app/*.*") +file(GLOB_RECURSE INHERITANCE_APP_SOURCES "apps/inheritance_app/*.*") +file(GLOB_RECURSE EXCHANGE_APP_SOURCE "apps/exchange_app/*.*") +file(GLOB_RECURSE CONSTELLATION_APP_SOURCE "apps/constellation_app/*.*") +file(GLOB_RECURSE STARKNET_APP_SOURCES "apps/starknet_app/*.*") +file(GLOB_RECURSE XRP_APP_SOURCES "apps/xrp_app/*.*") +file(GLOB_RECURSE ICP_APP_SOURCES "apps/icp_app/*.*") + +# Define sources from common/coin_support that are specific to non-BTC builds +set(COMMON_NON_BTC_SOURCES "") +IF(NOT BTC_ONLY) + # Source files from common/coin_support/eth_sign_data/ + set(ETH_SIGN_DATA_COMMON_SRCS "") + file(GLOB ETH_SIGN_DATA_COMMON_SRCS_TMP "common/coin_support/eth_sign_data/*.c") + foreach(file ${ETH_SIGN_DATA_COMMON_SRCS_TMP}) + list(APPEND ETH_SIGN_DATA_COMMON_SRCS "${file}") + endforeach() + + # Source files from common/coin_support/tron_parse_txn/ + set(TRON_PARSE_TXN_COMMON_SRCS "") + file(GLOB TRON_PARSE_TXN_COMMON_SRCS_TMP "common/coin_support/tron_parse_txn/*.c") + foreach(file ${TRON_PARSE_TXN_COMMON_SRCS_TMP}) + list(APPEND TRON_PARSE_TXN_COMMON_SRCS "${file}") + endforeach() + + list(APPEND COMMON_NON_BTC_SOURCES + ${ETH_SIGN_DATA_COMMON_SRCS} + ${TRON_PARSE_TXN_COMMON_SRCS} + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/eth.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/solana.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/near.c" + # Add other .c files from common/coin_support that are exclusively for non-BTC chains if any + ) +ENDIF() + + +IF(BTC_ONLY) + # BTC-only build: include only Bitcoin-related apps + set(APP_SOURCES + ${MANAGER_APP_SOURCES} + ${BTC_FAMILY_SOURCES} + ${INHERITANCE_APP_SOURCES} +) +ELSE() + set(APP_SOURCES + ${MANAGER_APP_SOURCES} + ${BTC_FAMILY_SOURCES} + ${EVM_FAMILY_SOURCES} + ${NEAR_APP_SOURCES} + ${SOLANA_APP_SOURCES} + ${EXCHANGE_APP_SOURCE} + ${TRON_APP_SOURCES} + ${INHERITANCE_APP_SOURCES} + ${STARKNET_APP_SOURCES} + ${XRP_APP_SOURCES} + ${ICP_APP_SOURCES} + ${CONSTELLATION_APP_SOURCE}) +ENDIF(BTC_ONLY) + IF(UNIT_TESTS_SWITCH) - file(GLOB_RECURSE SOURCES "stm32-hal/*.*" "common/*.*" "src/*.*" "apps/*.*" "tests/*.*") + # Add test sources + file(GLOB_RECURSE TEST_SOURCES "tests/*.*") + set(SOURCES ${BASE_SOURCES} ${APP_SOURCES} ${COMMON_NON_BTC_SOURCES} ${TEST_SOURCES}) + #exclude src/main.c from the compilation list as it needs to be overriden by unit_tests_main.c LIST(REMOVE_ITEM SOURCES "${PROJECT_SOURCE_DIR}/src/main.c") @@ -16,12 +135,37 @@ IF(UNIT_TESTS_SWITCH) add_compile_definitions(UNITY_INCLUDE_CONFIG_H) add_compile_definitions(UNITY_FIXTURE_NO_EXTRAS) ELSE() - file(GLOB_RECURSE SOURCES "stm32-hal/*.*" "common/*.*" "src/*.*" "apps/*.*") + set(SOURCES ${BASE_SOURCES} ${APP_SOURCES} ${COMMON_NON_BTC_SOURCES}) ENDIF(UNIT_TESTS_SWITCH) -add_executable(${EXECUTABLE} ${SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/version.c ${MINI_GMP_SRCS} ${POSEIDON_SRCS} ${PROTO_SRCS} ${PROTO_HDRS} ${INCLUDES} ${LINKER_SCRIPT} ${STARTUP_FILE}) -target_compile_definitions(${EXECUTABLE} PRIVATE -DUSE_HAL_DRIVER -DSTM32L486xx ) -add_compile_definitions(USE_SIMULATOR=0 USE_BIP32_CACHE=0 USE_BIP39_CACHE=0 STM32L4 USBD_SOF_DISABLED ENABLE_HID_WEBUSB_COMM=1) +add_executable(${EXECUTABLE} + ${SOURCES} + ${CMAKE_CURRENT_BINARY_DIR}/version.c + ${MINI_GMP_SRCS} + ${POSEIDON_SRCS} + ${PROTO_SRCS} + ${PROTO_HDRS} + ${INCLUDES} + ${LINKER_SCRIPT} + ${STARTUP_FILE}) + +target_compile_definitions(${EXECUTABLE} PRIVATE + -DUSE_HAL_DRIVER + -DSTM32L486xx ) + +add_compile_definitions( + USE_SIMULATOR=0 + USE_BIP32_CACHE=0 + USE_BIP39_CACHE=0 + STM32L4 + USBD_SOF_DISABLED + ENABLE_HID_WEBUSB_COMM=1) + +# Add BTC_ONLY compile definition when building BTC-only firmware +IF(BTC_ONLY) + add_compile_definitions(BTC_ONLY_BUILD) +ENDIF(BTC_ONLY) + IF (DEV_SWITCH) add_compile_definitions(DEV_BUILD) ENDIF(DEV_SWITCH) @@ -39,42 +183,19 @@ elseif("${FIRMWARE_TYPE}" STREQUAL "Initial") else() message(FATAL_ERROR "Firmware type not specified. Specify using -DFIRMWARE_TYPE= Type can be Main or Initial") endif() + +# Base include directories (always included) target_include_directories(${EXECUTABLE} PRIVATE - apps/manager_app + apps/manager_app # Manager app is always included - apps/btc_family - apps/btc_family/btc - apps/btc_family/dash - apps/btc_family/doge - apps/btc_family/ltc - apps/evm_family - apps/evm_family/eth - apps/evm_family/polygon - apps/evm_family/bsc - apps/evm_family/fantom - apps/evm_family/avalanche - apps/evm_family/optimism - apps/evm_family/arbitrum - apps/near_app - apps/solana_app - apps/tron_app - apps/inheritance_app - apps/starknet_app - apps/xrp_app - apps/constellation_app - apps/icp_app - apps/exchange_app - src/ src/menu src/wallet src/restricted_app src/onboarding src/settings - src/card_operations src/card_flows - src/level_one/controller src/level_one/tasks src/level_two/controller @@ -92,10 +213,11 @@ target_include_directories(${EXECUTABLE} PRIVATE src/level_four/tap_cards/controller src/level_four/tap_cards/tasks - common/interfaces/card_interface - common/interfaces/desktop_app_interface - common/interfaces/flash_interface - common/interfaces/user_interface + common + common/interfaces/card_interface + common/interfaces/desktop_app_interface + common/interfaces/flash_interface + common/interfaces/user_interface common/libraries/atecc common/libraries/atecc/atcacert common/libraries/atecc/basic @@ -104,30 +226,26 @@ target_include_directories(${EXECUTABLE} PRIVATE common/libraries/atecc/hal common/libraries/atecc/host common/libraries/atecc/jwt - common/libraries/crypto + common/libraries/crypto common/libraries/crypto/mpz_operations common/libraries/crypto/aes common/libraries/crypto/chacha20poly1305 common/libraries/crypto/ed25519-donna common/libraries/crypto/monero common/libraries/crypto/random_gen - common/libraries/proof_of_work - common/libraries/shamir - common/libraries/util - common/startup + common/libraries/proof_of_work + common/libraries/shamir + common/libraries/util + common/startup common/logger - common/coin_support - common/coin_support/eth_sign_data - common/coin_support/tron_parse_txn - common/flash - common/Firewall - common/core - common/timers - - common - common/lvgl + common/coin_support + common/flash + common/Firewall + common/core + common/timers + common/lvgl common/lvgl/porting - common/lvgl/src + common/lvgl/src common/lvgl/src/lv_core common/lvgl/src/lv_draw common/lvgl/src/lv_font @@ -136,22 +254,19 @@ target_include_directories(${EXECUTABLE} PRIVATE common/lvgl/src/lv_objx common/lvgl/src/lv_themes - # Device + # Device specific includes stm32-hal stm32-hal/BSP stm32-hal/Inc - stm32-hal/Drivers/CMSIS/Include stm32-hal/Drivers/CMSIS/Device/ST/STM32L4xx/Include stm32-hal/Drivers/STM32L4xx_HAL_Driver/Inc stm32-hal/Drivers/STM32L4xx_HAL_Driver/Inc/Legacy stm32-hal/Drivers/STM32L4xx_HAL_Driver/Src - stm32-hal/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc stm32-hal/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src stm32-hal/Middlewares/ST/STM32_USB_Device_Library/Core/Inc stm32-hal/Middlewares/ST/STM32_USB_Device_Library/Core/Src - stm32-hal/Peripherals stm32-hal/Peripherals/Buzzer stm32-hal/Peripherals/display @@ -159,22 +274,19 @@ target_include_directories(${EXECUTABLE} PRIVATE stm32-hal/Peripherals/flash/ stm32-hal/Peripherals/logger/ stm32-hal/Peripherals/nfc/ - stm32-hal/Src stm32-hal/Startup stm32-hal/porting - stm32-hal/Inc - stm32-hal/libusb/ stm32-hal/libusb/inc stm32-hal/libusb/src - #unit test framework + #unit test framework includes (conditional on UNIT_TESTS_SWITCH) $<$:${PROJECT_SOURCE_DIR}/tests/framework/unity> $<$:${PROJECT_SOURCE_DIR}/tests/framework/unity/src> $<$:${PROJECT_SOURCE_DIR}/tests/framework/unity/extras/fixture/src> - #unit test modules: this list needs to be updated whenever a test module is being added + #unit test modules includes (conditional on UNIT_TESTS_SWITCH) $<$:${PROJECT_SOURCE_DIR}/tests> $<$:${PROJECT_SOURCE_DIR}/tests/common/core> $<$:${PROJECT_SOURCE_DIR}/tests/common/util> @@ -185,6 +297,51 @@ target_include_directories(${EXECUTABLE} PRIVATE $<$:${PROJECT_SOURCE_DIR}/tests/nfc> $<$:${PROJECT_SOURCE_DIR}/tests/apps/manager_app> $<$:${PROJECT_SOURCE_DIR}/tests/apps/btc_app> +) + +# Conditional include directories based on BTC_ONLY flag +IF(BTC_ONLY) + # BTC-only build: include only Bitcoin family apps + target_include_directories(${EXECUTABLE} PRIVATE + apps/btc_family + apps/btc_family/btc + apps/inheritance_app + ) +ELSE() + # Full build: include all cryptocurrency apps and their specific common support includes + target_include_directories(${EXECUTABLE} PRIVATE + apps/btc_family # BTC family is also part of full build + apps/btc_family/btc + apps/btc_family/dash + apps/btc_family/doge + apps/btc_family/ltc + apps/evm_family + apps/evm_family/eth + apps/evm_family/polygon + apps/evm_family/bsc + apps/evm_family/fantom + apps/evm_family/avalanche + apps/evm_family/optimism + apps/evm_family/arbitrum + apps/near_app + apps/solana_app + apps/tron_app + apps/inheritance_app + apps/starknet_app + apps/xrp_app + apps/icp_app + apps/constellation_app + apps/exchange_app + + # Common coin support sub-module includes for non-BTC builds + common/coin_support/eth_sign_data # Headers for eth_sign_data module + common/coin_support/tron_parse_txn # Headers for tron_parse_txn module + # If other coin-specific helper headers (e.g., solana_txn_helpers.h, near_context.h) + # reside in specific subdirectories under common/coin_support/, add those paths here. + # If they are within the app-specific directories (e.g. apps/solana_app/), + # those are already covered by the app include paths. + + # All unit tests for full build (conditional on UNIT_TESTS_SWITCH) $<$:${PROJECT_SOURCE_DIR}/tests/apps/evm_app> $<$:${PROJECT_SOURCE_DIR}/tests/apps/near_app> $<$:${PROJECT_SOURCE_DIR}/tests/apps/solana_app> @@ -192,45 +349,59 @@ target_include_directories(${EXECUTABLE} PRIVATE $<$:${PROJECT_SOURCE_DIR}/tests/apps/xrp_app> $<$:${PROJECT_SOURCE_DIR}/tests/apps/constellation_app> $<$:${PROJECT_SOURCE_DIR}/tests/apps/icp_app> - ) + ) +ENDIF(BTC_ONLY) target_compile_options(${EXECUTABLE} PRIVATE - -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard - -fdata-sections -ffunction-sections - -Wall -Wno-format-truncation -Wno-unused-but-set-variable -Wno-return-type - -D_POSIX_C_SOURCE=200809L - $<$:-g3> - $<$:-Werror> - ) + -mcpu=cortex-m4 + -mthumb + -mfpu=fpv4-sp-d16 + -mfloat-abi=hard + -fdata-sections + -ffunction-sections + -Wall + -Wno-format-truncation + -Wno-unused-but-set-variable + -Wno-return-type + -D_POSIX_C_SOURCE=200809L + $<$:-g3> + $<$:-Werror> +) target_link_options(${EXECUTABLE} PRIVATE - -T${CMAKE_SOURCE_DIR}/STM32L486RGTX_FLASH.ld - -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 - -mfloat-abi=hard -u _printf_float -lc -lm -lnosys - -Wl,-Map=${PROJECT_NAME}.map,--cref -Wl,--gc-sections - ) + -T${CMAKE_SOURCE_DIR}/STM32L486RGTX_FLASH.ld + -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 + -mfloat-abi=hard -u _printf_float -lc -lm -lnosys + -Wl,-Map=${PROJECT_NAME}.map,--cref -Wl,--gc-sections +) # Used to suppress compile time warnings in libraries -file(GLOB_RECURSE LIBRARIES_SRC_DIR "common/libraries/atecc/*.c" - "common/libraries/atecc/*.h" "common/lvgl/*.c" "common/lvgl/*.h" - "common/libraries/crypto/*.c" "common/libraries/crypto/*.h" - "stm32-hal/Peripherals/*.c" "stm32-hal/Peripherals/*.h") +file(GLOB_RECURSE LIBRARIES_SRC_DIR + "common/libraries/atecc/*.c" + "common/libraries/atecc/*.h" + "common/lvgl/src/**/*.c" + "common/lvgl/src/**/*.h" + "common/libraries/crypto/*.c" + "common/libraries/crypto/*.h" + "stm32-hal/Peripherals/*.c" + "stm32-hal/Peripherals/*.h") set_source_files_properties(${LIBRARIES_SRC_DIR} PROPERTIES COMPILE_FLAGS "-w") # Print executable size add_custom_command(TARGET ${EXECUTABLE} - POST_BUILD - COMMAND arm-none-eabi-size ${EXECUTABLE}) + POST_BUILD + COMMAND arm-none-eabi-size ${EXECUTABLE}) # Create hex file add_custom_command(TARGET ${EXECUTABLE} - POST_BUILD - COMMAND arm-none-eabi-objcopy -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex - COMMAND arm-none-eabi-objcopy -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin) + POST_BUILD + COMMAND arm-none-eabi-objcopy -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex + COMMAND arm-none-eabi-objcopy -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin) + if (SIGN_BINARY) - add_custom_command(TARGET ${EXECUTABLE} - POST_BUILD - COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py add-header --input="${PROJECT_NAME}.bin" --output=${PROJECT_NAME}_Header.bin --version=${CMAKE_SOURCE_DIR}/version.txt --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key1.h - COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py sign-header --input=${PROJECT_NAME}_Header.bin --output=${PROJECT_NAME}-signed.bin --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key2.h - COMMAND rm ${PROJECT_NAME}_Header.bin) -endif() + add_custom_command(TARGET ${EXECUTABLE} + POST_BUILD + COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py add-header --input="${PROJECT_NAME}.bin" --output=${PROJECT_NAME}_Header.bin --version=${CMAKE_SOURCE_DIR}/version.txt --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key1.h + COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py sign-header --input=${PROJECT_NAME}_Header.bin --output=${PROJECT_NAME}-signed.bin --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key2.h + COMMAND rm ${PROJECT_NAME}_Header.bin) +endif() \ No newline at end of file From 6683767fc1f15c0d49de7c38fd9f8d7ae19a359c Mon Sep 17 00:00:00 2001 From: Utkarsh Maurya Date: Wed, 25 Jun 2025 12:00:41 +0530 Subject: [PATCH 02/14] fix: Minor updates as per pr review --- apps/btc_family/btc_pub_key.c | 12 +++++++----- apps/btc_family/btc_txn.c | 16 ++++++++++++---- common/core/core_flow_init.c | 1 - 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/btc_family/btc_pub_key.c b/apps/btc_family/btc_pub_key.c index 0566e95e0..83b4401a4 100644 --- a/apps/btc_family/btc_pub_key.c +++ b/apps/btc_family/btc_pub_key.c @@ -161,7 +161,9 @@ static void send_public_key(const uint8_t *public_key); /***************************************************************************** * STATIC VARIABLES *****************************************************************************/ -static bool sign_address = false; +#ifndef BTC_ONLY_BUILD + static bool sign_address = false; +#endif // BTC_ONLY_BUILD static bool check_which_request(const btc_query_t *query, pb_size_t which_request) { @@ -184,13 +186,13 @@ static bool validate_request_data(btc_get_public_key_request_t *request) { status = false; } + #ifndef BTC_ONLY_BUILD caq_node_data_t data = {.applet_id = get_btc_app_desc()->id}; memzero(data.params, sizeof(data.params)); memcpy(data.params, request->initiate.wallet_id, sizeof(request->initiate.wallet_id)); -#ifndef BTC_ONLY_BUILD data.params[32] = EXCHANGE_FLOW_TAG_RECEIVE; sign_address = exchange_app_validate_caq(data); #endif // BTC_ONLY_BUILD @@ -305,12 +307,12 @@ void btc_get_pub_key(btc_query_t *query) { delay_scr_init(ui_text_processing, DELAY_SHORT); size_t length = btc_get_address(seed, path, path_length, public_key, msg); memzero(seed, sizeof(seed)); - + + #ifndef BTC_ONLY_BUILD if (sign_address) { - #ifndef BTC_ONLY_BUILD exchange_sign_address(msg, sizeof(msg)); - #endif // BTC_ONLY_BUILD } + #endif // BTC_ONLY_BUILD if (0 < length && true == core_scroll_page(ui_text_receive_on, msg, btc_send_error)) { diff --git a/apps/btc_family/btc_txn.c b/apps/btc_family/btc_txn.c index 41c740d64..3c88beddd 100644 --- a/apps/btc_family/btc_txn.c +++ b/apps/btc_family/btc_txn.c @@ -281,7 +281,6 @@ static bool send_script_sig(btc_query_t *query, const scrip_sig_t *sigs); /***************************************************************************** * STATIC VARIABLES *****************************************************************************/ -static bool use_signature_verification = false; static btc_txn_context_t *btc_txn_context = NULL; /***************************************************************************** @@ -313,6 +312,7 @@ static bool validate_request_data(const btc_sign_txn_request_t *request) { status = false; } #ifndef BTC_ONLY_BUILD + bool use_signature_verification = false; // Declare and initialize here caq_node_data_t data = {.applet_id = get_btc_app_desc()->id}; memzero(data.params, sizeof(data.params)); memcpy(data.params, @@ -572,6 +572,14 @@ static bool get_user_verification() { char value[100] = ""; char address[100] = ""; +#ifndef BTC_ONLY_BUILD + bool use_signature_verification = false; + // This needs to be re-evaluated as validate_request_data will be called first and will set this variable. + // The query is not accessible directly in get_user_verification. + // For now, removing this re-evaluation part. + // Keeping the if condition as is for the exchange_validate_stored_signature function call. +#endif // BTC_ONLY_BUILD + for (int idx = 0; idx < btc_txn_context->metadata.output_count; idx++) { btc_sign_txn_output_t *output = &btc_txn_context->outputs[idx]; btc_sign_txn_output_script_pub_key_t *script = &output->script_pub_key; @@ -590,14 +598,14 @@ static bool get_user_verification() { return false; } +#ifndef BTC_ONLY_BUILD if (use_signature_verification) { - #ifndef BTC_ONLY_BUILD if (!exchange_validate_stored_signature(address, sizeof(address))) { btc_send_error(ERROR_COMMON_ERROR_UNKNOWN_ERROR_TAG, status); return false; } - #endif // BTC_ONLY_BUILD } +#endif // BTC_ONLY_BUILD if (!core_scroll_page(title, address, btc_send_error) || !core_scroll_page(title, value, btc_send_error)) { @@ -749,4 +757,4 @@ void btc_sign_transaction(btc_query_t *query) { free(btc_txn_context); btc_txn_context = NULL; } -} +} \ No newline at end of file diff --git a/common/core/core_flow_init.c b/common/core/core_flow_init.c index 41418fa72..10f12ff7d 100644 --- a/common/core/core_flow_init.c +++ b/common/core/core_flow_init.c @@ -187,7 +187,6 @@ void core_init_app_registry() { registry_add_app(get_ltc_app_desc()); registry_add_app(get_doge_app_desc()); registry_add_app(get_dash_app_desc()); - registry_add_app(get_inheritance_app_desc()); registry_add_app(get_eth_app_desc()); registry_add_app(get_near_app_desc()); From de5cef0484236f2cf605de1ce7bd4f536ebab943 Mon Sep 17 00:00:00 2001 From: Utkarsh Maurya Date: Wed, 25 Jun 2025 13:26:24 +0530 Subject: [PATCH 03/14] style: Apply code formatting to match ci guidelines --- apps/btc_family/btc_pub_key.c | 16 ++++++++-------- apps/btc_family/btc_txn.c | 19 ++++++++++--------- common/coin_support/coin_specific_data.c | 9 ++++++--- common/coin_support/coin_utils.c | 20 ++++++++++---------- common/coin_support/coin_utils.h | 4 ++-- common/coin_support/eth.h | 6 +++--- common/core/core_flow_init.c | 14 +++++--------- src/controller_main.c | 6 +++--- 8 files changed, 47 insertions(+), 47 deletions(-) diff --git a/apps/btc_family/btc_pub_key.c b/apps/btc_family/btc_pub_key.c index 83b4401a4..aca7b2891 100644 --- a/apps/btc_family/btc_pub_key.c +++ b/apps/btc_family/btc_pub_key.c @@ -73,7 +73,7 @@ #ifndef BTC_ONLY_BUILD #include "exchange_main.h" -#endif // BTC_ONLY_BUILD +#endif // BTC_ONLY_BUILD #include "reconstruct_wallet_flow.h" #include "status_api.h" @@ -162,8 +162,8 @@ static void send_public_key(const uint8_t *public_key); * STATIC VARIABLES *****************************************************************************/ #ifndef BTC_ONLY_BUILD - static bool sign_address = false; -#endif // BTC_ONLY_BUILD +static bool sign_address = false; +#endif // BTC_ONLY_BUILD static bool check_which_request(const btc_query_t *query, pb_size_t which_request) { @@ -186,7 +186,7 @@ static bool validate_request_data(btc_get_public_key_request_t *request) { status = false; } - #ifndef BTC_ONLY_BUILD +#ifndef BTC_ONLY_BUILD caq_node_data_t data = {.applet_id = get_btc_app_desc()->id}; memzero(data.params, sizeof(data.params)); @@ -195,7 +195,7 @@ static bool validate_request_data(btc_get_public_key_request_t *request) { sizeof(request->initiate.wallet_id)); data.params[32] = EXCHANGE_FLOW_TAG_RECEIVE; sign_address = exchange_app_validate_caq(data); -#endif // BTC_ONLY_BUILD +#endif // BTC_ONLY_BUILD return status; } @@ -307,12 +307,12 @@ void btc_get_pub_key(btc_query_t *query) { delay_scr_init(ui_text_processing, DELAY_SHORT); size_t length = btc_get_address(seed, path, path_length, public_key, msg); memzero(seed, sizeof(seed)); - - #ifndef BTC_ONLY_BUILD + +#ifndef BTC_ONLY_BUILD if (sign_address) { exchange_sign_address(msg, sizeof(msg)); } - #endif // BTC_ONLY_BUILD +#endif // BTC_ONLY_BUILD if (0 < length && true == core_scroll_page(ui_text_receive_on, msg, btc_send_error)) { diff --git a/apps/btc_family/btc_txn.c b/apps/btc_family/btc_txn.c index 3c88beddd..2d0a179c4 100644 --- a/apps/btc_family/btc_txn.c +++ b/apps/btc_family/btc_txn.c @@ -81,7 +81,7 @@ #ifndef BTC_ONLY_BUILD #include "exchange_main.h" -#endif // BTC_ONLY_BUILD +#endif // BTC_ONLY_BUILD #include "reconstruct_wallet_flow.h" #include "status_api.h" @@ -312,7 +312,7 @@ static bool validate_request_data(const btc_sign_txn_request_t *request) { status = false; } #ifndef BTC_ONLY_BUILD - bool use_signature_verification = false; // Declare and initialize here + bool use_signature_verification = false; // Declare and initialize here caq_node_data_t data = {.applet_id = get_btc_app_desc()->id}; memzero(data.params, sizeof(data.params)); memcpy(data.params, @@ -320,7 +320,7 @@ static bool validate_request_data(const btc_sign_txn_request_t *request) { sizeof(request->initiate.wallet_id)); data.params[32] = EXCHANGE_FLOW_TAG_SEND; use_signature_verification = exchange_app_validate_caq(data); -#endif // BTC_ONLY_BUILD +#endif // BTC_ONLY_BUILD return status; } @@ -574,11 +574,12 @@ static bool get_user_verification() { #ifndef BTC_ONLY_BUILD bool use_signature_verification = false; - // This needs to be re-evaluated as validate_request_data will be called first and will set this variable. - // The query is not accessible directly in get_user_verification. - // For now, removing this re-evaluation part. - // Keeping the if condition as is for the exchange_validate_stored_signature function call. -#endif // BTC_ONLY_BUILD + // This needs to be re-evaluated as validate_request_data will be called first + // and will set this variable. The query is not accessible directly in + // get_user_verification. For now, removing this re-evaluation part. Keeping + // the if condition as is for the exchange_validate_stored_signature function + // call. +#endif // BTC_ONLY_BUILD for (int idx = 0; idx < btc_txn_context->metadata.output_count; idx++) { btc_sign_txn_output_t *output = &btc_txn_context->outputs[idx]; @@ -605,7 +606,7 @@ static bool get_user_verification() { return false; } } -#endif // BTC_ONLY_BUILD +#endif // BTC_ONLY_BUILD if (!core_scroll_page(title, address, btc_send_error) || !core_scroll_page(title, value, btc_send_error)) { diff --git a/common/coin_support/coin_specific_data.c b/common/coin_support/coin_specific_data.c index b84739fea..cc8dc7f6b 100644 --- a/common/coin_support/coin_specific_data.c +++ b/common/coin_support/coin_specific_data.c @@ -207,7 +207,8 @@ static uint16_t prepare_coin_specific_data_tlv( // (uint8_t *)malloc(meta_data_arr[current_index].data_length); // ASSERT(meta_data_arr[current_index].data_struct.coin_data != NULL); // read_cmd(meta_data_arr[current_index].data_addr, -// (uint32_t *)meta_data_arr[current_index].data_struct.coin_data, +// (uint32_t +// *)meta_data_arr[current_index].data_struct.coin_data, // meta_data_arr[current_index].data_length); // } // } @@ -220,7 +221,8 @@ static uint16_t prepare_coin_specific_data_tlv( // for (size_t i = 0; i < MAX_UNIQUE_COIN_COUNT * MAX_WALLETS_ALLOWED; i++) { // if (meta_data_arr[i].data_length > 0 && // FLASH_COIN_SPECIFIC_BASE_ADDRESS < meta_data_arr[i].data_addr && -// meta_data_arr[i].data_addr + meta_data_arr[i].data_length < FLASH_END) { +// meta_data_arr[i].data_addr + meta_data_arr[i].data_length < +// FLASH_END) { // uint16_t data_length = // (3 + WALLET_ID_SIZE) + (3 + meta_data_arr[i].data_length); // uint16_t tlv_size = 6 + data_length; @@ -234,7 +236,8 @@ static uint16_t prepare_coin_specific_data_tlv( // tlv, // data_length); // write_cmd( -// FLASH_COIN_SPECIFIC_BASE_ADDRESS + offset, (uint32_t *)tlv, tlv_size); +// FLASH_COIN_SPECIFIC_BASE_ADDRESS + offset, (uint32_t *)tlv, +// tlv_size); // free(meta_data_arr[i].data_struct.coin_data); // } diff --git a/common/coin_support/coin_utils.c b/common/coin_support/coin_utils.c index 60f925a97..7e1e3f0d9 100644 --- a/common/coin_support/coin_utils.c +++ b/common/coin_support/coin_utils.c @@ -61,16 +61,16 @@ #include "segwit_addr.h" #ifndef BTC_ONLY_BUILD - #include "arbitrum.h" - #include "avalanche.h" - #include "bsc.h" - #include "etc.h" - #include "fantom.h" - #include "harmony.h" - #include "near.h" - #include "optimism.h" - #include "polygon.h" - #include "solana.h" +#include "arbitrum.h" +#include "avalanche.h" +#include "bsc.h" +#include "etc.h" +#include "fantom.h" +#include "harmony.h" +#include "near.h" +#include "optimism.h" +#include "polygon.h" +#include "solana.h" #endif void s_memcpy(uint8_t *dst, diff --git a/common/coin_support/coin_utils.h b/common/coin_support/coin_utils.h index 94a785332..f1a2cd541 100644 --- a/common/coin_support/coin_utils.h +++ b/common/coin_support/coin_utils.h @@ -72,7 +72,7 @@ typedef enum Coin_Type { COIN_TYPE_BITCOIN = 0x01, COIN_TYPE_BTC_TEST = 0x02, - #ifndef BTC_ONLY_BUILD +#ifndef BTC_ONLY_BUILD COIN_TYPE_LITECOIN = 0x03, COIN_TYPE_DOGE = 0x04, COIN_TYPE_DASH = 0x05, @@ -87,7 +87,7 @@ typedef enum Coin_Type { COIN_TYPE_HARMONY = 0x0E, COIN_TYPE_ETHEREUM_CLASSIC = 0x0f, COIN_TYPE_ARBITRUM = 0x10, - #endif +#endif } Coin_Type; #pragma pack(push, 1) diff --git a/common/coin_support/eth.h b/common/coin_support/eth.h index 452e8a967..aebdecad4 100644 --- a/common/coin_support/eth.h +++ b/common/coin_support/eth.h @@ -19,6 +19,9 @@ #include #include +#include "../apps/evm_family/evm_txn_helpers.h" +#include "../common/coin_support/eth_sign_data/abi.h" +#include "../common/coin_support/eth_sign_data/eip712.pb.h" #include "../crypto/base58.h" #include "../crypto/bip32.h" #include "../crypto/bip39.h" @@ -28,10 +31,7 @@ #include "../crypto/secp256k1.h" #include "../crypto/sha2.h" #include "../crypto/sha3.h" -#include "../common/coin_support/eth_sign_data/abi.h" #include "coin_utils.h" -#include "../common/coin_support/eth_sign_data/eip712.pb.h" -#include "../apps/evm_family/evm_txn_helpers.h" #define ETHEREUM_MAINNET_CHAIN 1 diff --git a/common/core/core_flow_init.c b/common/core/core_flow_init.c index 10f12ff7d..c1bf9adb9 100644 --- a/common/core/core_flow_init.c +++ b/common/core/core_flow_init.c @@ -61,18 +61,16 @@ *****************************************************************************/ #include "core_flow_init.h" +#include "../apps/inheritance_app/inheritance_main.h" #include "app_registry.h" #include "application_startup.h" -#include "../apps/inheritance_app/inheritance_main.h" +#include "btc_app.h" +#include "btc_main.h" #include "main_menu.h" #include "manager_app.h" #include "onboarding.h" #include "restricted_app.h" - -#include "btc_app.h" -#include "btc_main.h" - #ifndef BTC_ONLY_BUILD #include "arbitrum_app.h" #include "avalanche_app.h" @@ -88,14 +86,14 @@ #include "fantom_app.h" #include "icp_main.h" #include "ltc_app.h" +#include "near_main.h" #include "optimism_app.h" #include "polygon_app.h" #include "solana_main.h" #include "starknet_main.h" #include "tron_main.h" #include "xrp_main.h" -#include "near_main.h" -#endif // BTC_ONLY_BUILD +#endif // BTC_ONLY_BUILD /***************************************************************************** * EXTERN VARIABLES @@ -177,12 +175,10 @@ engine_ctx_t *get_core_flow_ctx(void) { } void core_init_app_registry() { - registry_add_app(get_manager_app_desc()); registry_add_app(get_btc_app_desc()); registry_add_app(get_inheritance_app_desc()); - #ifndef BTC_ONLY_BUILD registry_add_app(get_ltc_app_desc()); registry_add_app(get_doge_app_desc()); diff --git a/src/controller_main.c b/src/controller_main.c index e6eaa3a99..96ef57b6f 100644 --- a/src/controller_main.c +++ b/src/controller_main.c @@ -87,15 +87,15 @@ #include "application_startup.h" #include "chacha20poly1305.h" +#include "coin_utils.h" #include "communication.h" #include "constant_texts.h" #include "cryptoauthlib.h" +#include "options.h" +#include "pb_decode.h" #include "rfc7539.h" #include "ui_events.h" #include "ui_instruction.h" -#include "pb_decode.h" -#include "options.h" -#include "coin_utils.h" #ifndef BTC_ONLY_BUILD #include "arbitrum.h" From 5ec4208e11c133aace99520e2e605f4cf2e22e40 Mon Sep 17 00:00:00 2001 From: Utkarsh Maurya Date: Thu, 26 Jun 2025 10:53:21 +0530 Subject: [PATCH 04/14] fix: Minor updates as per pr review --- apps/btc_family/btc_txn.c | 28 ++-- common/coin_support/coin_specific_data.c | 163 ++++++++++++----------- 2 files changed, 98 insertions(+), 93 deletions(-) diff --git a/apps/btc_family/btc_txn.c b/apps/btc_family/btc_txn.c index 2d0a179c4..996a3bccf 100644 --- a/apps/btc_family/btc_txn.c +++ b/apps/btc_family/btc_txn.c @@ -78,11 +78,9 @@ #include "composable_app_queue.h" #include "constant_texts.h" #include "curves.h" - #ifndef BTC_ONLY_BUILD #include "exchange_main.h" -#endif // BTC_ONLY_BUILD - +#endif #include "reconstruct_wallet_flow.h" #include "status_api.h" #include "ui_core_confirm.h" @@ -281,6 +279,11 @@ static bool send_script_sig(btc_query_t *query, const scrip_sig_t *sigs); /***************************************************************************** * STATIC VARIABLES *****************************************************************************/ +#ifndef BTC_ONLY_BUILD +// This variable is needed for the exchange flow and needs to maintain its state +// across function calls. +static bool use_signature_verification = false; +#endif static btc_txn_context_t *btc_txn_context = NULL; /***************************************************************************** @@ -311,16 +314,18 @@ static bool validate_request_data(const btc_sign_txn_request_t *request) { ERROR_DATA_FLOW_INVALID_DATA); status = false; } + #ifndef BTC_ONLY_BUILD - bool use_signature_verification = false; // Declare and initialize here caq_node_data_t data = {.applet_id = get_btc_app_desc()->id}; + memzero(data.params, sizeof(data.params)); memcpy(data.params, request->initiate.wallet_id, sizeof(request->initiate.wallet_id)); data.params[32] = EXCHANGE_FLOW_TAG_SEND; + use_signature_verification = exchange_app_validate_caq(data); -#endif // BTC_ONLY_BUILD +#endif return status; } @@ -572,15 +577,6 @@ static bool get_user_verification() { char value[100] = ""; char address[100] = ""; -#ifndef BTC_ONLY_BUILD - bool use_signature_verification = false; - // This needs to be re-evaluated as validate_request_data will be called first - // and will set this variable. The query is not accessible directly in - // get_user_verification. For now, removing this re-evaluation part. Keeping - // the if condition as is for the exchange_validate_stored_signature function - // call. -#endif // BTC_ONLY_BUILD - for (int idx = 0; idx < btc_txn_context->metadata.output_count; idx++) { btc_sign_txn_output_t *output = &btc_txn_context->outputs[idx]; btc_sign_txn_output_script_pub_key_t *script = &output->script_pub_key; @@ -606,7 +602,7 @@ static bool get_user_verification() { return false; } } -#endif // BTC_ONLY_BUILD +#endif if (!core_scroll_page(title, address, btc_send_error) || !core_scroll_page(title, value, btc_send_error)) { @@ -758,4 +754,4 @@ void btc_sign_transaction(btc_query_t *query) { free(btc_txn_context); btc_txn_context = NULL; } -} \ No newline at end of file +} diff --git a/common/coin_support/coin_specific_data.c b/common/coin_support/coin_specific_data.c index cc8dc7f6b..38ebc098d 100644 --- a/common/coin_support/coin_specific_data.c +++ b/common/coin_support/coin_specific_data.c @@ -167,83 +167,86 @@ static uint16_t prepare_coin_specific_data_tlv( return find_latest_coin_data( coin_specific_data, &coin_data_len, &coin_data_addr); } +#ifndef BTC_ONLY_BUILD +// This function is commented out as it is not used in the current +// implementation. It is kept here for reference in case it is needed in the +// future. It was intended to purge coin specific data from flash by reading all +// the unique coin data and writing them back to flash after erasing the flash. +// It is a complex operation and may not be necessary in the current context. + +static void purge_coin_specific_data() { + // Store all the unique data length and address in an array + Coin_Type coin_type_arr[MAX_UNIQUE_COIN_COUNT] = {COIN_TYPE_NEAR}; + struct meta_data_t { + Coin_Specific_Data_Struct data_struct; + uint16_t data_length; + uint32_t data_addr; + } meta_data_arr[MAX_UNIQUE_COIN_COUNT * MAX_WALLETS_ALLOWED] = {0}; + + for (size_t coin_type_index = 0; coin_type_index < MAX_UNIQUE_COIN_COUNT; + coin_type_index++) { + for (size_t wallet_id_index = 0; wallet_id_index < MAX_WALLETS_ALLOWED; + wallet_id_index++) { + size_t current_index = + coin_type_index * MAX_WALLETS_ALLOWED + wallet_id_index; + + meta_data_arr[current_index].data_length = 0; + meta_data_arr[current_index].data_addr = 0; + + meta_data_arr[current_index].data_struct.coin_type = + coin_type_arr[coin_type_index]; + memcpy(meta_data_arr[current_index].data_struct.wallet_id, + get_wallet_id(wallet_id_index), + WALLET_ID_SIZE); + find_latest_coin_data(&meta_data_arr[current_index].data_struct, + &meta_data_arr[current_index].data_length, + &meta_data_arr[current_index].data_addr); + + if (meta_data_arr[current_index].data_length > 0 && + FLASH_COIN_SPECIFIC_BASE_ADDRESS < + meta_data_arr[current_index].data_addr && + meta_data_arr[current_index].data_addr + + meta_data_arr[current_index].data_length < + FLASH_END) { + // Allocate a proper size array to store the data + meta_data_arr[current_index].data_struct.coin_data = + (uint8_t *)malloc(meta_data_arr[current_index].data_length); + ASSERT(meta_data_arr[current_index].data_struct.coin_data != NULL); + read_cmd(meta_data_arr[current_index].data_addr, + (uint32_t *)meta_data_arr[current_index].data_struct.coin_data, + meta_data_arr[current_index].data_length); + } + } + } -// static void purge_coin_specific_data() { -// // Store all the unique data length and address in an array -// Coin_Type coin_type_arr[MAX_UNIQUE_COIN_COUNT] = {COIN_TYPE_NEAR}; -// struct meta_data_t { -// Coin_Specific_Data_Struct data_struct; -// uint16_t data_length; -// uint32_t data_addr; -// } meta_data_arr[MAX_UNIQUE_COIN_COUNT * MAX_WALLETS_ALLOWED] = {0}; - -// for (size_t coin_type_index = 0; coin_type_index < MAX_UNIQUE_COIN_COUNT; -// coin_type_index++) { -// for (size_t wallet_id_index = 0; wallet_id_index < MAX_WALLETS_ALLOWED; -// wallet_id_index++) { -// size_t current_index = -// coin_type_index * MAX_WALLETS_ALLOWED + wallet_id_index; - -// meta_data_arr[current_index].data_length = 0; -// meta_data_arr[current_index].data_addr = 0; - -// meta_data_arr[current_index].data_struct.coin_type = -// coin_type_arr[coin_type_index]; -// memcpy(meta_data_arr[current_index].data_struct.wallet_id, -// get_wallet_id(wallet_id_index), -// WALLET_ID_SIZE); -// find_latest_coin_data(&meta_data_arr[current_index].data_struct, -// &meta_data_arr[current_index].data_length, -// &meta_data_arr[current_index].data_addr); - -// if (meta_data_arr[current_index].data_length > 0 && -// FLASH_COIN_SPECIFIC_BASE_ADDRESS < -// meta_data_arr[current_index].data_addr && -// meta_data_arr[current_index].data_addr + -// meta_data_arr[current_index].data_length < -// FLASH_END) { -// // Allocate a proper size array to store the data -// meta_data_arr[current_index].data_struct.coin_data = -// (uint8_t *)malloc(meta_data_arr[current_index].data_length); -// ASSERT(meta_data_arr[current_index].data_struct.coin_data != NULL); -// read_cmd(meta_data_arr[current_index].data_addr, -// (uint32_t -// *)meta_data_arr[current_index].data_struct.coin_data, -// meta_data_arr[current_index].data_length); -// } -// } -// } - -// // Erase everything from flash -// erase_flash_coin_specific_data(); - -// // Write the data back to flash -// for (size_t i = 0; i < MAX_UNIQUE_COIN_COUNT * MAX_WALLETS_ALLOWED; i++) { -// if (meta_data_arr[i].data_length > 0 && -// FLASH_COIN_SPECIFIC_BASE_ADDRESS < meta_data_arr[i].data_addr && -// meta_data_arr[i].data_addr + meta_data_arr[i].data_length < -// FLASH_END) { -// uint16_t data_length = -// (3 + WALLET_ID_SIZE) + (3 + meta_data_arr[i].data_length); -// uint16_t tlv_size = 6 + data_length; -// tlv_size = GET_NEXT_MULTIPLE_OF_8(tlv_size); -// uint8_t tlv[tlv_size]; -// memzero(tlv, sizeof(tlv)); - -// uint16_t offset = -// prepare_coin_specific_data_tlv(&meta_data_arr[i].data_struct, -// meta_data_arr[i].data_length, -// tlv, -// data_length); -// write_cmd( -// FLASH_COIN_SPECIFIC_BASE_ADDRESS + offset, (uint32_t *)tlv, -// tlv_size); - -// free(meta_data_arr[i].data_struct.coin_data); -// } -// } -// } - + // Erase everything from flash + erase_flash_coin_specific_data(); + + // Write the data back to flash + for (size_t i = 0; i < MAX_UNIQUE_COIN_COUNT * MAX_WALLETS_ALLOWED; i++) { + if (meta_data_arr[i].data_length > 0 && + FLASH_COIN_SPECIFIC_BASE_ADDRESS < meta_data_arr[i].data_addr && + meta_data_arr[i].data_addr + meta_data_arr[i].data_length < FLASH_END) { + uint16_t data_length = + (3 + WALLET_ID_SIZE) + (3 + meta_data_arr[i].data_length); + uint16_t tlv_size = 6 + data_length; + tlv_size = GET_NEXT_MULTIPLE_OF_8(tlv_size); + uint8_t tlv[tlv_size]; + memzero(tlv, sizeof(tlv)); + + uint16_t offset = + prepare_coin_specific_data_tlv(&meta_data_arr[i].data_struct, + meta_data_arr[i].data_length, + tlv, + data_length); + write_cmd( + FLASH_COIN_SPECIFIC_BASE_ADDRESS + offset, (uint32_t *)tlv, tlv_size); + + free(meta_data_arr[i].data_struct.coin_data); + } + } +} +#endif // BTC_ONLY_BUILD static int store_coin_data(const uint8_t *tlv_data, uint16_t tlv_data_size, uint16_t offset) { @@ -253,7 +256,13 @@ static int store_coin_data(const uint8_t *tlv_data, (uint32_t *)tlv_data, tlv_data_size); } else { - // purge_coin_specific_data(); +#ifndef BTC_ONLY_BUILD + // If there is not enough space, purge the coin specific data and try again. + // This is a complex operation and may not be necessary in the current + // context. It is commented out for now, but can be uncommented if needed in + // the future + purge_coin_specific_data(); +#endif // BTC_ONLY_BUILD uint16_t coin_data_len = 0; uint32_t coin_data_addr = 0; Coin_Specific_Data_Struct dummy = {0}; From 54bf3b47e44eb4e0aca6f6db3b9a27e598abdb04 Mon Sep 17 00:00:00 2001 From: Utkarsh Maurya Date: Fri, 27 Jun 2025 11:21:41 +0530 Subject: [PATCH 05/14] chore: Update gh actions workflows --- .github/workflows/auto-tag-versions.yml | 1 + .github/workflows/build.yml | 4 +- .github/workflows/ci-tests.yml | 1 + .github/workflows/containerized-build.yml | 77 +++++++++++++++++++---- .github/workflows/publish-docs.yml | 2 +- .github/workflows/version-check.yml | 2 +- utilities/build.sh | 34 ++++++++-- 7 files changed, 100 insertions(+), 21 deletions(-) diff --git a/.github/workflows/auto-tag-versions.yml b/.github/workflows/auto-tag-versions.yml index 205b618fe..b394859ce 100644 --- a/.github/workflows/auto-tag-versions.yml +++ b/.github/workflows/auto-tag-versions.yml @@ -22,3 +22,4 @@ jobs: VERSION=$(cat version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }') echo $VERSION curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${AUTH_TOKEN}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${REPOSITORY}/git/refs -d '{"ref":"refs/tags/v'${VERSION}'","sha":"'${COMMIT}'"}' + echo "Tag v${VERSION} created successfully." \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8dac9fbe9..a9361f045 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,10 +15,12 @@ jobs: matrix: firmware: [Main] target: [Release] + coin_support: ["BTC_ONLY", "MULTI_COIN"] uses: ./.github/workflows/containerized-build.yml with: firmware: ${{ matrix.firmware }} target: ${{ matrix.target }} + coin_support_variant: ${{ matrix.coin_support }} secrets: inherit create-release: needs: build-firmwares @@ -49,4 +51,4 @@ jobs: run: | content_type=$(file -b --mime-type Main-Release-outputs/Cypherock-Main.bin) curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=Cypherock-Main.bin --data-binary @Main-Release-outputs/Cypherock-Main.bin - curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=version.txt --data-binary @version.txt + curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=version.txt --data-binary @version.txt \ No newline at end of file diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index a709e6d13..71a61ccb0 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -198,3 +198,4 @@ jobs: cat test_results.txt # Unity prints "OK" if all tests pass, "FAIL" if tests fail; return 1 to indicate failure if [ ! "$(tail -n 1 test_results.txt)" = "OK" ]; then exit 1; fi + \ No newline at end of file diff --git a/.github/workflows/containerized-build.yml b/.github/workflows/containerized-build.yml index d3e0e47a4..624cc96d6 100644 --- a/.github/workflows/containerized-build.yml +++ b/.github/workflows/containerized-build.yml @@ -9,30 +9,81 @@ on: target: required: true type: string + coin_support_variant: + required: true + type: string + workflow_dispatch: + inputs: + firmware: + required: true + type: string + default: 'Main' + target: + required: true + type: string + default: 'Release' + coin_support_variant: + required: true + type: string + default: 'MULTI_COIN' jobs: build: runs-on: ubuntu-latest container: image: cypherock/x1-firmware-builder:v0.0.0 + steps: - - name: Build Firmware (${{ inputs.firmware }} - ${{ inputs.target }}) + - name: Set VERSION_TAG + id: set_version_tag run: | if [[ "${{ github.ref_type }}" == "tag" ]]; then - export VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/') + echo "VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/')" >> $GITHUB_OUTPUT elif [[ "${{ github.ref_type }}" == "branch" ]]; then - export VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/') + echo "VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/')" >> $GITHUB_OUTPUT else - # reftype is repository; use default branch - export VERSION_TAG=main + echo "VERSION_TAG=main" >> $GITHUB_OUTPUT fi - git clone --branch ${VERSION_TAG} --depth 1 https://github.com/${{ github.repository }}.git --recurse-submodules - mkdir build && cd x1_wallet_firmware && mkdir build && cd build - cmake -DCMAKE_BUILD_TYPE="${{ inputs.target }}" -DFIRMWARE_TYPE="${{ inputs.firmware }}" -DCMAKE_BUILD_PLATFORM="Device" -G "Ninja" .. - ninja && cd ../.. - cp x1_wallet_firmware/build/Cypherock-*.* ./build/ - - name: Archive Build Artifacts + + - name: Checkout Repository + uses: actions/checkout@v4 + with: + ref: ${{ steps.set_version_tag.outputs.VERSION_TAG }} + submodules: recursive + + - name: Build Firmware (${{ inputs.firmware }} - ${{ inputs.target }} - ${{ inputs.coin_support_variant }}) + run: | + cd x1_wallet_firmware + + BTC_ONLY_FLAG="OFF" + if [[ "${{ inputs.coin_support_variant }}" == "BTC_ONLY" ]]; then + BTC_ONLY_FLAG="ON" + fi + + BUILD_DIR="build_${{ inputs.coin_support_variant }}" + mkdir -p "${BUILD_DIR}" + + cmake -B "${BUILD_DIR}" \ + -DDEV_SWITCH=OFF \ + -DUNIT_TESTS_SWITCH:BOOL=OFF \ + -DBTC_ONLY:BOOL="${BTC_ONLY_FLAG}" \ + -DSIGN_BINARY=OFF \ + -DCMAKE_BUILD_TYPE:STRING="${{ inputs.target }}" \ + -DFIRMWARE_TYPE="${{ inputs.firmware }}" \ + -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF \ + -DCMAKE_BUILD_PLATFORM:STRING="Device" \ + -G "Ninja" . + + ninja -C "${BUILD_DIR}" + + cd .. + + mkdir -p build + + cp x1_wallet_firmware/"${BUILD_DIR}"/Cypherock-*.* ./build/ + + - name: Archive Build Artifacts (${{ inputs.coin_support_variant }}) uses: actions/upload-artifact@v4 with: - name: ${{ inputs.firmware }}-${{ inputs.target }}-outputs - path: build + name: ${{ inputs.firmware }}-${{ inputs.target }}-${{ inputs.coin_support_variant }}-outputs + path: build \ No newline at end of file diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 8dc94afc8..aef9de9fe 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -26,4 +26,4 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - run: aws s3 cp ./doxygen/html s3://docs-x1.cypherock.com --recursive + run: aws s3 cp ./doxygen/html s3://docs-x1.cypherock.com --recursive \ No newline at end of file diff --git a/.github/workflows/version-check.yml b/.github/workflows/version-check.yml index 67b119253..bc44919f8 100644 --- a/.github/workflows/version-check.yml +++ b/.github/workflows/version-check.yml @@ -24,4 +24,4 @@ jobs: version0=$(git show ${SHA_BASE}:version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print $1*2**24 + $2*2**16 + $3*2**8 + $4 }') version1=$(git show ${SHA_HEAD}:version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print $1*2**24 + $2*2**16 + $3*2**8 + $4 }') echo $version0:$version1 - if [[ $version0 > $version1 ]]; then echo -e "Version downgrade detected\nfrom $version0 to $version1\n"; exit 1; fi + if [[ $version0 > $version1 ]]; then echo -e "Version downgrade detected\nfrom $version0 to $version1\n"; exit 1; fi \ No newline at end of file diff --git a/utilities/build.sh b/utilities/build.sh index 8390712e3..d997e7aee 100755 --- a/utilities/build.sh +++ b/utilities/build.sh @@ -1,10 +1,12 @@ #!/usr/bin/env bash +# Function to display usage information usage() { - echo -e "USAGE: $0 [-c] [-u] [-f ] [-p ] [-t ]" + echo -e "USAGE: $0 [-c] [-u] [-b] [-f ] [-p ] [-t ]" echo -e "Parameters are optional and assumes 'main debug device' if not provided" echo -e "\n\n -c \t Performs a forced clean before invoking build" echo -e "\n\n -u \t Generate unsigned binary" + echo -e "\n\n -b \t Build BTC-only firmware" echo -e "\n\n -f \t Sets the preferred firmware to build. Can be main or initial" echo -e "\n\n -p \t Provides the preferred platform to build for. Can be simulator or device" echo -e "\n\n -t \t Tells the build type that should be generate. Can be a valid build type." @@ -12,6 +14,7 @@ usage() { exit 1 } +# Function to validate the firmware name validate_name() { if ! [[ "$ACTIVE_TYPE" =~ ^(Main|Initial)$ ]]; then echo -e "Incorrect firmware ($ACTIVE_TYPE) selected for build\n" @@ -19,6 +22,7 @@ validate_name() { fi } +# Function to validate the build platform validate_platform() { if ! [[ "$BUILD_PLATFORM" =~ ^(Device|Simulator)$ ]]; then echo -e "Incorrect platform ($BUILD_PLATFORM) selected for build\n" @@ -26,6 +30,7 @@ validate_platform() { fi } +# Function to validate the build type validate_type() { if ! [[ "$BUILD_TYPE" =~ ^(Debug|Release|Dev|Unit_tests)$ ]]; then echo -e "Incorrect type ($BUILD_TYPE) selected for build\n" @@ -33,6 +38,7 @@ validate_type() { fi } +# --- Script Defaults --- ACTIVE_ROOT_DIR=$(pwd) ACTIVE_TYPE=Main BUILD_TYPE=Debug @@ -40,10 +46,13 @@ BUILD_PLATFORM=Device UNIT_TESTS=OFF DEV=OFF SIGN_BINARY=ON +BTC_ONLY=OFF # Default to multi-coin build -while getopts 'cf:p:t:u' flag; do +# --- Parse Command Line Arguments --- +while getopts 'cbuf:p:t:' flag; do case "${flag}" in c) clean_flag="true" ;; + b) BTC_ONLY=ON ;; f) ACTIVE_TYPE=$(echo "${OPTARG}" | awk '{print toupper(substr($0, 1, 1)) tolower(substr($0, 2))}') ;; p) BUILD_PLATFORM=$(echo "${OPTARG}" | awk '{print toupper(substr($0, 1, 1)) tolower(substr($0, 2))}') ;; t) BUILD_TYPE=$(echo "${OPTARG}" | awk '{print toupper(substr($0, 1, 1)) tolower(substr($0, 2))}') ;; @@ -52,6 +61,7 @@ while getopts 'cf:p:t:u' flag; do esac done +# --- Validate Inputs --- shift "$((OPTIND - 1))" validate_name validate_platform @@ -61,6 +71,7 @@ if [ $# -gt 0 ]; then usage fi +# --- Set Build-specific Variables --- case $BUILD_TYPE in Dev) DEV=ON @@ -74,17 +85,26 @@ Unit_tests) ;; esac +# --- Prepare Build Directory --- +BUILD_DIR_SUFFIX="" +if [ "${BTC_ONLY}" = "ON" ]; then + BUILD_DIR_SUFFIX="_BTC" +fi + +BUILD_DIR="build/${ACTIVE_TYPE}${BUILD_DIR_SUFFIX}" + cd "${ACTIVE_ROOT_DIR}" || exit -mkdir -p "build/${ACTIVE_TYPE}" -cd "build/${ACTIVE_TYPE}" || exit +mkdir -p "${BUILD_DIR}" +cd "${BUILD_DIR}" || exit -# remove previous cmake configuration to ensure we are building with +# Remove previous cmake configuration to ensure we are building with # currently requested build configuration; it is important to delete # the existing cmake configuration if [ -f "CMakeCache.txt" ]; then rm "CMakeCache.txt" fi +# --- Find Build Tools --- # Detect if any one (cmake or mingw32-cmake) exists CMAKE=$(which cmake) if [ "${CMAKE}" = "" ]; then @@ -115,12 +135,15 @@ if [ "${BUILD_TOOL}" = "" ]; then exit 1 fi +# --- Run Build --- if [[ "${clean_flag}" = "true" ]]; then rm -rf "${ACTIVE_ROOT_DIR}/generated/proto" fi +# Configure the project with CMake "${CMAKE}" -DDEV_SWITCH=${DEV} \ -DUNIT_TESTS_SWITCH:BOOL="${UNIT_TESTS}" \ + -DBTC_ONLY:BOOL="${BTC_ONLY}" \ -DSIGN_BINARY:BOOL="${SIGN_BINARY}" \ -DCMAKE_BUILD_TYPE:STRING="${BUILD_TYPE}" \ -DFIRMWARE_TYPE="${ACTIVE_TYPE}" \ @@ -131,6 +154,7 @@ fi # exit if configuration failed with errors if [ ! $? -eq 0 ]; then exit 1; fi +# Clean and build the project if [[ "${clean_flag}" = "true" ]]; then "${BUILD_TOOL}" clean fi From 7859ca4a0d3c9756b51104c232468f695dcfa690 Mon Sep 17 00:00:00 2001 From: Utkarsh Maurya Date: Fri, 27 Jun 2025 16:46:38 +0530 Subject: [PATCH 06/14] feat: Updated gh build worklow to build btc only app --- .github/workflows/build.yml | 76 ++++++++++++++++++++++++++++++++----- CMakeLists.txt | 63 ++++++++++++++++-------------- 2 files changed, 102 insertions(+), 37 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a9361f045..47bdbf84c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,40 +15,98 @@ jobs: matrix: firmware: [Main] target: [Release] - coin_support: ["BTC_ONLY", "MULTI_COIN"] + coin_support: ["BTC_ONLY", "MULTI_COIN"] # Builds both BTC_ONLY and MULTI_COIN variants uses: ./.github/workflows/containerized-build.yml with: firmware: ${{ matrix.firmware }} target: ${{ matrix.target }} coin_support_variant: ${{ matrix.coin_support }} secrets: inherit + create-release: - needs: build-firmwares + needs: build-firmwares # Depends on all firmwares being built runs-on: ubuntu-latest if: ${{ github.ref_type }} == 'tag' steps: - name: Checkout uses: actions/checkout@v3 + - name: Download artifacts uses: actions/download-artifact@v4 with: - path: ./ + path: ./ # Downloads all artifacts to the current directory + - name: Publish a release env: TAG_NAME: ${{ github.ref_name }} auth_token: ${{ secrets.GITHUB_TOKEN }} REPOSITORY: ${{ github.repository }} run: | - chkmain=$(sha256sum Main-Release-outputs/Cypherock-Main.bin | cut -f -1 -d ' ') + # Calculate SHA256 hash for the MULTI_COIN firmware + # The path assumes download-artifact placed it in Main-Release-MULTI_COIN-outputs/build/ + chkmain_multicoin=$(sha256sum Main-Release-MULTI_COIN-outputs/build/Cypherock-Main.bin | cut -f -1 -d ' ') + + # Calculate SHA256 hash for the BTC_ONLY firmware + # The path assumes download-artifact placed it in Main-Release-BTC_ONLY-outputs/build/ + # The filename is Cypherock-Main-btc.bin due to the CMakeLists.txt modification + chkmain_btc_only=$(sha256sum Main-Release-BTC_ONLY-outputs/build/Cypherock-Main-btc.bin | cut -f -1 -d ' ') + APP_VERSION=$(cat version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }') HW_VERSION=$(cat version.txt | grep hardware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }') - echo ${APP_VERSION}:${HW_VERSION} - curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${REPOSITORY}/releases -d '{"tag_name":"'${TAG_NAME}'","target_commitish":"main","name":"'${TAG_NAME}'","body":"Application version: '${APP_VERSION}'\r\nHardware version: '${HW_VERSION}'\r\n## SHA256 of binaries:\r\n**Cypherock-Main.bin** : '${chkmain}'","draft":true,"prerelease":false,"generate_release_notes":true}' > output.txt + + echo "Application version: ${APP_VERSION}" + echo "Hardware version: ${HW_VERSION}" + + # Create the release with both firmware hashes in the body + curl -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${auth_token}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/${REPOSITORY}/releases \ + -d '{ + "tag_name":"'${TAG_NAME}'", + "target_commitish":"main", + "name":"'${TAG_NAME}'", + "body":"Application version: '${APP_VERSION}'\r\nHardware version: '${HW_VERSION}'\r\n## SHA256 of binaries:\r\n**Cypherock-Main.bin** : '${chkmain_multicoin}' \r\n**Cypherock-Main-btc.bin** : '${chkmain_btc_only}'", + "draft":true, + "prerelease":false, + "generate_release_notes":true + }' > output.txt + + # Extract upload_url for subsequent asset uploads echo "upload_url=$(cat output.txt | grep "\"upload_url\":" | cut -f 4-4 -d '"' | cut -f 1-1 -d '{')" >> $GITHUB_ENV + - name: Upload assets env: auth_token: ${{ secrets.GITHUB_TOKEN }} + upload_url: ${{ env.upload_url }} # Use the extracted upload_url run: | - content_type=$(file -b --mime-type Main-Release-outputs/Cypherock-Main.bin) - curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=Cypherock-Main.bin --data-binary @Main-Release-outputs/Cypherock-Main.bin - curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=version.txt --data-binary @version.txt \ No newline at end of file + # Upload the MULTI_COIN firmware binary + content_type_multicoin=$(file -b --mime-type Main-Release-MULTI_COIN-outputs/build/Cypherock-Main.bin) + curl -X POST \ + -H "Content-Type: ${content_type_multicoin}" \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${auth_token}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${upload_url}?name=Cypherock-Main.bin" \ + --data-binary @Main-Release-MULTI_COIN-outputs/build/Cypherock-Main.bin + + # Upload the BTC_ONLY firmware binary + content_type_btc_only=$(file -b --mime-type Main-Release-BTC_ONLY-outputs/build/Cypherock-Main-btc.bin) + curl -X POST \ + -H "Content-Type: ${content_type_btc_only}" \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${auth_token}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${upload_url}?name=Cypherock-Main-btc.bin" \ + --data-binary @Main-Release-BTC_ONLY-outputs/build/Cypherock-Main-btc.bin + + # Upload version.txt + content_type_version=$(file -b --mime-type version.txt) + curl -X POST \ + -H "Content-Type: ${content_type_version}" \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${auth_token}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${upload_url}?name=version.txt" \ + --data-binary @version.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 11ed8b589..b5adf5b1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,24 @@ else() set(PROJECT Cypherock_Simulator) endif() +# Define all options upfront, including BTC_ONLY +OPTION(DEV_SWITCH "Additional features/logs to aid developers" OFF) +OPTION(UNIT_TESTS_SWITCH "Compile build for main firmware or unit tests" OFF) +OPTION(BTC_ONLY "Build firmware for Bitcoin only" OFF) + +# Logic to append -btc to project name if BTC_ONLY is enabled +if (BTC_ONLY) + set(PROJECT ${PROJECT}-btc) +endif() + +# Make static functions testable via unit-tests +IF(UNIT_TESTS_SWITCH) + add_compile_definitions( STATIC= ) +ELSE() + add_compile_definitions( STATIC=static ) +ENDIF(UNIT_TESTS_SWITCH) + +# Now define the project with its final name, after all modifications project(${PROJECT}) # python is needed for compiling proto files using nanopb @@ -24,37 +42,26 @@ execute_process(COMMAND sh utilities/proto/generate-protob.sh WORKING_DIRECTORY include(utilities/cmake/version.cmake) file(GLOB_RECURSE PROTO_SRCS "generated/proto/*.*") -list(APPEND PROTO_SRCS - "vendor/nanopb/pb_common.c" - "vendor/nanopb/pb_decode.c" - "vendor/nanopb/pb_encode.c" - "vendor/nanopb/pb_common.h" - "vendor/nanopb/pb_decode.h" - "vendor/nanopb/pb_encode.h" +list(APPEND PROTO_SRCS + "vendor/nanopb/pb_common.c" + "vendor/nanopb/pb_decode.c" + "vendor/nanopb/pb_encode.c" + "vendor/nanopb/pb_common.h" + "vendor/nanopb/pb_decode.h" + "vendor/nanopb/pb_encode.h" "vendor/nanopb/pb.h" ) -list (APPEND MINI_GMP_SRCS - "vendor/mini-gmp/mini-gmp-helpers.c" +list (APPEND MINI_GMP_SRCS + "vendor/mini-gmp/mini-gmp-helpers.c" "vendor/mini-gmp/mini-gmp.c" ) -list (APPEND POSEIDON_SRCS - "vendor/poseidon/sources/f251.c" - "vendor/poseidon/sources/poseidon.c" +list (APPEND POSEIDON_SRCS + "vendor/poseidon/sources/f251.c" + "vendor/poseidon/sources/poseidon.c" "vendor/poseidon/sources/poseidon_rc.c" ) -OPTION(DEV_SWITCH "Additional features/logs to aid developers" OFF) -OPTION(UNIT_TESTS_SWITCH "Compile build for main firmware or unit tests" OFF) -OPTION(BTC_ONLY "Build firmware for Bitcoin only" OFF) - -# Make static functions testable via unit-tests -IF(UNIT_TESTS_SWITCH) - add_compile_definitions( STATIC= ) -ELSE() - add_compile_definitions( STATIC=static ) -ENDIF(UNIT_TESTS_SWITCH) - if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") add_compile_definitions(FIRMWARE_HASH_CALC=1) else() @@ -68,13 +75,13 @@ else() # Simulator or default endif() # Include nanopb source headers -target_include_directories( ${EXECUTABLE} PRIVATE - vendor/nanopb - generated/proto - vendor/mini-gmp +target_include_directories( ${EXECUTABLE} PRIVATE + vendor/nanopb + generated/proto + vendor/mini-gmp vendor/poseidon/sources ) # Enable support for dynamically allocated fields in nanopb # Ref: vendor/nanopb/pb.h -add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1) \ No newline at end of file +add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1) From 07e4f49311e3a0a3f4e4f598af4c08a7ccc60f48 Mon Sep 17 00:00:00 2001 From: Utkarsh Maurya Date: Sat, 28 Jun 2025 15:50:26 +0530 Subject: [PATCH 07/14] fix: Correctly generate protos for btc_only builds --- CMakeLists.txt | 14 +++++- utilities/proto/generate-protob.sh | 74 ++++++++++++++++++++---------- 2 files changed, 63 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5adf5b1c..097bde6e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,19 @@ project(${PROJECT}) # python is needed for compiling proto files using nanopb # also for generating & appending firmware signature headers find_package( Python3 REQUIRED COMPONENTS Interpreter ) -execute_process(COMMAND sh utilities/proto/generate-protob.sh WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY ) + +# Conditionally generate protobuf files based on the BTC_ONLY option +IF(BTC_ONLY) + message(STATUS "Generating protobufs for BTC-only build") + execute_process(COMMAND bash utilities/proto/generate-protob.sh --btc-only + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND_ERROR_IS_FATAL ANY) +ELSE() + message(STATUS "Generating protobufs for full build") + execute_process(COMMAND bash utilities/proto/generate-protob.sh + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND_ERROR_IS_FATAL ANY) +ENDIF() # Populate version.c include(utilities/cmake/version.cmake) diff --git a/utilities/proto/generate-protob.sh b/utilities/proto/generate-protob.sh index 18b7bced7..0a1867284 100755 --- a/utilities/proto/generate-protob.sh +++ b/utilities/proto/generate-protob.sh @@ -2,31 +2,57 @@ set -e -NANOPB_GEN="$(pwd)/vendor/nanopb/generator/nanopb_generator.py" +# Default to a full build +BUILD_MODE="FULL" -# Generate protobuf sources using nanopb -PYTHON_VERSION="$(python3 --version)" || exit 1 -OUTPUT_DIR="$(pwd)/generated/proto" -PROTO_SRC="$(pwd)/common/cypherock-common/proto" -OPTIONS_DIR="$(pwd)/common/proto-options/" -# Path for tron-specific device protocol structures -PROTO_TRON="$(pwd)/common/coin_support/tron_parse_txn/" +# Check for the --btc-only flag +if [[ "$1" == "--btc-only" ]]; then + BUILD_MODE="BTC_ONLY" + echo "Build mode: BTC-only" +fi -test -d "${PROTO_SRC}" -test -d "${PROTO_TRON}" -test -f "${NANOPB_GEN}" +# --- Define paths and tools relative to the project root --- +PROTO_COMMON_SRC="common/cypherock-common/proto" +PROTO_TRON="common/coin_support/tron_parse_txn" +OUTPUT_DIR="generated/proto" +OPTIONS_DIR="common/proto-options" +NANOPB_GEN="vendor/nanopb/generator/nanopb_generator.py" -echo -e "Detected ${PYTHON_VERSION} (at $(which python3))" +# --- Validate paths and create output directory --- +test -d "${PROTO_COMMON_SRC}" || { echo "Error: Directory ${PROTO_COMMON_SRC} not found."; exit 1; } +echo -e "Detected $(python3 --version) (at $(which python3))" mkdir -p "${OUTPUT_DIR}" || exit 1 -cd "${PROTO_SRC}" - -# --generated-include-format specifies the include format. Two viable options -# are "#include <%s>" and "#include \"proto/%s\"". -# The default include format "#include \"%s\"" creates problems in cases of -# duplicate file names residing under different packages (eg. error.proto and -# btc.error.proto) as it would result into a collision. -# By using <> format instead of "proto/" helps because in future, relocation -# of generated files would not require updating this parameter. -python3 "${NANOPB_GEN}" -q --generated-include-format "#include <%s>" --proto-path="${PROTO_SRC}" --options-path="${OPTIONS_DIR}" $(find "${PROTO_SRC}" -name "*.proto") --output-dir="${OUTPUT_DIR}" --c-style -s anonymous_oneof:true -s long_names:false -# generate tron files -python3 "${NANOPB_GEN}" -q --generated-include-format "#include <%s>" --proto-path="${PROTO_TRON}" --options-path="${OPTIONS_DIR}" $(find "${PROTO_TRON}" -name "*.proto") --output-dir="${OUTPUT_DIR}" --c-style -s anonymous_oneof:true -s long_names:false \ No newline at end of file + +# --- Select and Generate Protobufs --- +PROTO_FILES_TO_GENERATE=() + +if [[ "${BUILD_MODE}" == "BTC_ONLY" ]]; then + echo "Finding protobufs for BTC-only build..." + # For a BTC-only build, find all .proto files within the essential directories. + # This is robust and does not depend on specific filenames. + BTC_ONLY_DIRS=( + "${PROTO_COMMON_SRC}/manager" + "${PROTO_COMMON_SRC}/btc" + "${PROTO_COMMON_SRC}/inheritance" + ) + PROTO_FILES_TO_GENERATE=($(find "${BTC_ONLY_DIRS[@]}" -name "*.proto")) +else + echo "Finding all protobufs for full build..." + # For a full build, find all .proto files in all subdirectories + ALL_COMMON_PROTOS=($(find "${PROTO_COMMON_SRC}" -name "*.proto")) + ALL_TRON_PROTOS=($(find "${PROTO_TRON}" -name "*.proto")) + PROTO_FILES_TO_GENERATE=("${ALL_COMMON_PROTOS[@]}" "${ALL_TRON_PROTOS[@]}") +fi + +echo "Generating selected protobuf files..." +python3 "${NANOPB_GEN}" \ + -q \ + --generated-include-format "#include <%s>" \ + --proto-path="${PROTO_COMMON_SRC}" \ + --proto-path="${PROTO_TRON}" \ + --options-path="${OPTIONS_DIR}" \ + --output-dir="${OUTPUT_DIR}" \ + --c-style -s anonymous_oneof:true -s long_names:false \ + "${PROTO_FILES_TO_GENERATE[@]}" + +echo "Protobuf generation complete." \ No newline at end of file From f7e1888234a2b54f0639a57cb87dd997209899d3 Mon Sep 17 00:00:00 2001 From: Utkarsh Maurya Date: Wed, 2 Jul 2025 18:12:33 +0530 Subject: [PATCH 08/14] fix: Include top-level protos in btc-only build --- utilities/proto/generate-protob.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/utilities/proto/generate-protob.sh b/utilities/proto/generate-protob.sh index 0a1867284..718c03ae8 100755 --- a/utilities/proto/generate-protob.sh +++ b/utilities/proto/generate-protob.sh @@ -28,22 +28,36 @@ PROTO_FILES_TO_GENERATE=() if [[ "${BUILD_MODE}" == "BTC_ONLY" ]]; then echo "Finding protobufs for BTC-only build..." - # For a BTC-only build, find all .proto files within the essential directories. - # This is robust and does not depend on specific filenames. + # Define the specific subdirectories for a BTC-only build. BTC_ONLY_DIRS=( "${PROTO_COMMON_SRC}/manager" "${PROTO_COMMON_SRC}/btc" "${PROTO_COMMON_SRC}/inheritance" ) - PROTO_FILES_TO_GENERATE=($(find "${BTC_ONLY_DIRS[@]}" -name "*.proto")) + # Find all .proto files within the specified subdirectories. + PROTO_FILES_IN_SUBDIRS=($(find "${BTC_ONLY_DIRS[@]}" -name "*.proto")) + + # Find all top-level .proto files in the common directory (e.g., core.proto, error.proto). + # The '-maxdepth 1' flag is crucial to prevent re-including files from subdirectories. + PROTO_FILES_AT_TOP_LEVEL=($(find "${PROTO_COMMON_SRC}" -maxdepth 1 -name "*.proto")) + + # Combine the top-level files and the subdirectory files for the final list. + PROTO_FILES_TO_GENERATE=("${PROTO_FILES_IN_SUBDIRS[@]}" "${PROTO_FILES_AT_TOP_LEVEL[@]}") else echo "Finding all protobufs for full build..." - # For a full build, find all .proto files in all subdirectories + # For a full build, find all .proto files in all relevant directories. ALL_COMMON_PROTOS=($(find "${PROTO_COMMON_SRC}" -name "*.proto")) ALL_TRON_PROTOS=($(find "${PROTO_TRON}" -name "*.proto")) PROTO_FILES_TO_GENERATE=("${ALL_COMMON_PROTOS[@]}" "${ALL_TRON_PROTOS[@]}") fi +# Check if any proto files were found before attempting to generate +if [ ${#PROTO_FILES_TO_GENERATE[@]} -eq 0 ]; then + echo "Warning: No protobuf files found to generate." + exit 0 +fi + + echo "Generating selected protobuf files..." python3 "${NANOPB_GEN}" \ -q \ From e121db43d5e54d5f6e35179095cb7c2d3acab2b6 Mon Sep 17 00:00:00 2001 From: Utkarsh Maurya Date: Wed, 2 Jul 2025 18:46:22 +0530 Subject: [PATCH 09/14] fix: Include top-level protos in btc-only build --- common/libraries/crypto/mpz_operations/mpz_pedersen.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/common/libraries/crypto/mpz_operations/mpz_pedersen.c b/common/libraries/crypto/mpz_operations/mpz_pedersen.c index 06bb8018c..fc46ef766 100644 --- a/common/libraries/crypto/mpz_operations/mpz_pedersen.c +++ b/common/libraries/crypto/mpz_operations/mpz_pedersen.c @@ -62,14 +62,18 @@ #include #include - +#include "mpz_ecdsa.h" #include "coin_utils.h" #include "mini-gmp-helpers.h" + +// Exclude StarkNet specific includes for BTC-only builds +#ifndef BTC_ONLY_BUILD #include "../apps/starknet_app/starknet_api.h" #include "../apps/starknet_app/starknet_context.h" #include "../apps/starknet_app/starknet_crypto.h" #include "../apps/starknet_app/starknet_helpers.h" #include "../apps/starknet_app/starknet_pedersen.h" +#endif // BTC_ONLY_BUILD /***************************************************************************** * EXTERN VARIABLES @@ -98,7 +102,7 @@ /***************************************************************************** * GLOBAL FUNCTIONS *****************************************************************************/ - +#ifndef BTC_ONLY_BUILD // Ensure these functions are only compiled when NOT BTC_ONLY_BUILD void process_single_element(mpz_t element, mpz_curve_point *p1, mpz_curve_point *p2, @@ -139,7 +143,6 @@ void process_single_element(mpz_t element, mpz_curve_point_clear(&res1); mpz_curve_point_clear(&res2); } - void pederson_hash(uint8_t *x, uint8_t *y, uint8_t size, uint8_t *hash) { ASSERT(NULL != x); ASSERT(NULL != y); @@ -199,3 +202,4 @@ void pederson_hash(uint8_t *x, uint8_t *y, uint8_t size, uint8_t *hash) { mpz_curve_point_clear(&P_3); mpz_curve_point_clear(&P_4); } +#endif // BTC_ONLY_BUILD From b92ed97bcdce139a19d88d3d49850d9f939471d2 Mon Sep 17 00:00:00 2001 From: Utkarsh Maurya Date: Fri, 8 Aug 2025 07:24:16 +0530 Subject: [PATCH 10/14] feat: Changing versioning --- CMakeLists.txt | 58 ++++++++++++++++++------------ apps/manager_app/get_device_info.c | 10 ++++++ utilities/build.sh | 2 +- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 097bde6e6..d5088f651 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,25 +4,29 @@ set(CMAKE_MESSAGE_LOG_LEVEL debug) if("${CMAKE_BUILD_PLATFORM}" STREQUAL "Device") message("Device platform selected") set(CMAKE_TOOLCHAIN_FILE utilities/cmake/arm-none-eabi-gcc.cmake) - set(PROJECT Cypherock-${FIRMWARE_TYPE}) + set(PROJECT_NAME_BASE Cypherock-${FIRMWARE_TYPE}) elseif("${CMAKE_BUILD_PLATFORM}" STREQUAL "Simulator") message("Simulator platform selected") - set(PROJECT Cypherock_Simulator) + set(PROJECT_NAME_BASE Cypherock_Simulator) else() - message(WARNING "No platform specified defaulting to Simulator. Specify using -DCMAKE_BUILD_PLATFORM= Type can be Device or Simulator") - set(PROJECT Cypherock_Simulator) + message(WARNING "No platform specified, defaulting to Simulator. Specify using -DCMAKE_BUILD_PLATFORM=") + set(PROJECT_NAME_BASE Cypherock_Simulator) endif() -# Define all options upfront, including BTC_ONLY +# Define all build options OPTION(DEV_SWITCH "Additional features/logs to aid developers" OFF) OPTION(UNIT_TESTS_SWITCH "Compile build for main firmware or unit tests" OFF) OPTION(BTC_ONLY "Build firmware for Bitcoin only" OFF) -# Logic to append -btc to project name if BTC_ONLY is enabled +# Append suffix to the project name if BTC_ONLY is enabled +set(PROJECT ${PROJECT_NAME_BASE}) if (BTC_ONLY) set(PROJECT ${PROJECT}-btc) endif() +# Define the project with its final calculated name +project(${PROJECT}) + # Make static functions testable via unit-tests IF(UNIT_TESTS_SWITCH) add_compile_definitions( STATIC= ) @@ -30,11 +34,28 @@ ELSE() add_compile_definitions( STATIC=static ) ENDIF(UNIT_TESTS_SWITCH) -# Now define the project with its final name, after all modifications -project(${PROJECT}) +# Set firmware type (Main or Initial) +if ("${FIRMWARE_TYPE}" STREQUAL "Main") + add_compile_definitions(X1WALLET_INITIAL=0 X1WALLET_MAIN=1) +elseif("${FIRMWARE_TYPE}" STREQUAL "Initial") + add_compile_definitions(X1WALLET_INITIAL=1 X1WALLET_MAIN=0) +endif() + +# Set variant-specific definition (BTC_ONLY_BUILD) +if(BTC_ONLY) + add_compile_definitions(BTC_ONLY_BUILD=1) +endif() + +# Set hash calculation definition based on build type +if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") + add_compile_definitions(FIRMWARE_HASH_CALC=1) +else() + add_compile_definitions(FIRMWARE_HASH_CALC=0) +endif() + +# Enable support for dynamically allocated fields in nanopb +add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1) -# python is needed for compiling proto files using nanopb -# also for generating & appending firmware signature headers find_package( Python3 REQUIRED COMPONENTS Interpreter ) # Conditionally generate protobuf files based on the BTC_ONLY option @@ -74,26 +95,17 @@ list (APPEND POSEIDON_SRCS "vendor/poseidon/sources/poseidon_rc.c" ) -if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") - add_compile_definitions(FIRMWARE_HASH_CALC=1) -else() - add_compile_definitions(FIRMWARE_HASH_CALC=0) -endif() - +# This is where add_executable(${PROJECT} ...) is called if("${CMAKE_BUILD_PLATFORM}" STREQUAL "Device") include(utilities/cmake/firmware/firmware.cmake) else() # Simulator or default include(utilities/cmake/simulator/simulator.cmake) endif() -# Include nanopb source headers -target_include_directories( ${EXECUTABLE} PRIVATE +# This must come AFTER the add_executable call in the included files +target_include_directories( ${PROJECT} PRIVATE vendor/nanopb generated/proto vendor/mini-gmp vendor/poseidon/sources -) - -# Enable support for dynamically allocated fields in nanopb -# Ref: vendor/nanopb/pb.h -add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1) +) \ No newline at end of file diff --git a/apps/manager_app/get_device_info.c b/apps/manager_app/get_device_info.c index 5194066f0..c6397a8b7 100644 --- a/apps/manager_app/get_device_info.c +++ b/apps/manager_app/get_device_info.c @@ -67,6 +67,7 @@ #include "manager_api.h" #include "manager_app.h" #include "onboarding.h" +#include /***************************************************************************** * EXTERN VARIABLES @@ -143,6 +144,15 @@ static manager_get_device_info_response_t get_device_info(void) { result->is_initial = (MANAGER_ONBOARDING_STEP_COMPLETE != onboarding_get_last_step()); result->onboarding_step = onboarding_get_last_step(); + + // Populate the firmware variant string based on the compile-time flag. + // This allows the client (CySync) to know which firmware variant is running. +#ifdef BTC_ONLY_BUILD + strcpy(result->variant, "BTC_ONLY"); +#else + strcpy(result->variant, "MULTICOIN"); +#endif + // TODO: populate applet list (result->applet_list) } diff --git a/utilities/build.sh b/utilities/build.sh index d997e7aee..e4e351cdf 100755 --- a/utilities/build.sh +++ b/utilities/build.sh @@ -158,4 +158,4 @@ if [ ! $? -eq 0 ]; then exit 1; fi if [[ "${clean_flag}" = "true" ]]; then "${BUILD_TOOL}" clean fi -"${BUILD_TOOL}" -j8 all +"${BUILD_TOOL}" -j8 all \ No newline at end of file From 4b242d2fdba11b73f6d4f554a31cd85b71c2a075 Mon Sep 17 00:00:00 2001 From: Utkarsh Maurya Date: Mon, 11 Aug 2025 05:26:18 +0530 Subject: [PATCH 11/14] feat: Changing versioning --- utilities/cmake/firmware/firmware.cmake | 183 ++++++++++++------------ 1 file changed, 88 insertions(+), 95 deletions(-) diff --git a/utilities/cmake/firmware/firmware.cmake b/utilities/cmake/firmware/firmware.cmake index f7875754b..1e3c16b6f 100644 --- a/utilities/cmake/firmware/firmware.cmake +++ b/utilities/cmake/firmware/firmware.cmake @@ -1,5 +1,6 @@ enable_language(C ASM) -set(EXECUTABLE ${PROJECT_NAME}.elf) +# The EXECUTABLE variable is removed. We will use ${PROJECT} directly, +# which is passed down from the parent CMakeLists.txt and holds the correct name (e.g., "Cypherock-Main-btc"). set(LINKER_SCRIPT STM32L486RGTX_FLASH.ld) set(STARTUP_FILE startup_stm32l486xx.s) set(CMAKE_C_STANDARD 11) @@ -42,9 +43,9 @@ set(CORE_COMMON_GENERAL_SOURCES_FROM_SUBDIRS # or are genuinely generic. set(CORE_COMMON_SPECIFIC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/common/assert_def.c" - "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/coin_specific_data.c" - "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/coin_utils.c" - "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/wallet.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/coin_specific_data.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/coin_utils.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/wallet.c" # common/core/core_flow_init.c is now covered by CORE_COMMON_CORE_SOURCES glob. # Ensure it and other common/core/*.c files have internal guards where needed. ) @@ -77,24 +78,24 @@ set(COMMON_NON_BTC_SOURCES "") IF(NOT BTC_ONLY) # Source files from common/coin_support/eth_sign_data/ set(ETH_SIGN_DATA_COMMON_SRCS "") - file(GLOB ETH_SIGN_DATA_COMMON_SRCS_TMP "common/coin_support/eth_sign_data/*.c") + file(GLOB ETH_SIGN_DATA_COMMON_SRCS_TMP "common/coin_support/eth_sign_data/*.c") foreach(file ${ETH_SIGN_DATA_COMMON_SRCS_TMP}) list(APPEND ETH_SIGN_DATA_COMMON_SRCS "${file}") endforeach() # Source files from common/coin_support/tron_parse_txn/ set(TRON_PARSE_TXN_COMMON_SRCS "") - file(GLOB TRON_PARSE_TXN_COMMON_SRCS_TMP "common/coin_support/tron_parse_txn/*.c") + file(GLOB TRON_PARSE_TXN_COMMON_SRCS_TMP "common/coin_support/tron_parse_txn/*.c") foreach(file ${TRON_PARSE_TXN_COMMON_SRCS_TMP}) list(APPEND TRON_PARSE_TXN_COMMON_SRCS "${file}") endforeach() - + list(APPEND COMMON_NON_BTC_SOURCES ${ETH_SIGN_DATA_COMMON_SRCS} ${TRON_PARSE_TXN_COMMON_SRCS} - "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/eth.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/eth.c" "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/solana.c" - "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/near.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/near.c" # Add other .c files from common/coin_support that are exclusively for non-BTC chains if any ) ENDIF() @@ -102,14 +103,14 @@ ENDIF() IF(BTC_ONLY) # BTC-only build: include only Bitcoin-related apps - set(APP_SOURCES - ${MANAGER_APP_SOURCES} + set(APP_SOURCES + ${MANAGER_APP_SOURCES} ${BTC_FAMILY_SOURCES} ${INHERITANCE_APP_SOURCES} ) -ELSE() - set(APP_SOURCES - ${MANAGER_APP_SOURCES} +ELSE() + set(APP_SOURCES + ${MANAGER_APP_SOURCES} ${BTC_FAMILY_SOURCES} ${EVM_FAMILY_SOURCES} ${NEAR_APP_SOURCES} @@ -127,7 +128,7 @@ IF(UNIT_TESTS_SWITCH) # Add test sources file(GLOB_RECURSE TEST_SOURCES "tests/*.*") set(SOURCES ${BASE_SOURCES} ${APP_SOURCES} ${COMMON_NON_BTC_SOURCES} ${TEST_SOURCES}) - + #exclude src/main.c from the compilation list as it needs to be overriden by unit_tests_main.c LIST(REMOVE_ITEM SOURCES "${PROJECT_SOURCE_DIR}/src/main.c") @@ -138,46 +139,38 @@ ELSE() set(SOURCES ${BASE_SOURCES} ${APP_SOURCES} ${COMMON_NON_BTC_SOURCES}) ENDIF(UNIT_TESTS_SWITCH) -add_executable(${EXECUTABLE} - ${SOURCES} - ${CMAKE_CURRENT_BINARY_DIR}/version.c - ${MINI_GMP_SRCS} - ${POSEIDON_SRCS} - ${PROTO_SRCS} - ${PROTO_HDRS} - ${INCLUDES} - ${LINKER_SCRIPT} +add_executable(${PROJECT} + ${SOURCES} + ${CMAKE_CURRENT_BINARY_DIR}/version.c + ${MINI_GMP_SRCS} + ${POSEIDON_SRCS} + ${PROTO_SRCS} + ${PROTO_HDRS} + ${INCLUDES} + ${LINKER_SCRIPT} ${STARTUP_FILE}) -target_compile_definitions(${EXECUTABLE} PRIVATE - -DUSE_HAL_DRIVER +target_compile_definitions(${PROJECT} PRIVATE + -DUSE_HAL_DRIVER -DSTM32L486xx ) +# NOTE: The compile definitions for DEV_SWITCH, BTC_ONLY_BUILD, and FIRMWARE_TYPE +# have been removed from this file as they are now centrally managed in the +# main CMakeLists.txt. This avoids redundancy and ensures a single source of truth. add_compile_definitions( - USE_SIMULATOR=0 - USE_BIP32_CACHE=0 - USE_BIP39_CACHE=0 - STM32L4 - USBD_SOF_DISABLED + USE_SIMULATOR=0 + USE_BIP32_CACHE=0 + USE_BIP39_CACHE=0 + STM32L4 + USBD_SOF_DISABLED ENABLE_HID_WEBUSB_COMM=1) -# Add BTC_ONLY compile definition when building BTC-only firmware -IF(BTC_ONLY) - add_compile_definitions(BTC_ONLY_BUILD) -ENDIF(BTC_ONLY) - -IF (DEV_SWITCH) - add_compile_definitions(DEV_BUILD) -ENDIF(DEV_SWITCH) - if ("${FIRMWARE_TYPE}" STREQUAL "Main") - add_compile_definitions(X1WALLET_INITIAL=0 X1WALLET_MAIN=1) - target_include_directories(${EXECUTABLE} PRIVATE + target_include_directories(${PROJECT} PRIVATE main/config/ ) elseif("${FIRMWARE_TYPE}" STREQUAL "Initial") - add_compile_definitions(X1WALLET_INITIAL=1 X1WALLET_MAIN=0) - target_include_directories(${EXECUTABLE} PRIVATE + target_include_directories(${PROJECT} PRIVATE initial/config/ ) else() @@ -185,7 +178,7 @@ else() endif() # Base include directories (always included) -target_include_directories(${EXECUTABLE} PRIVATE +target_include_directories(${PROJECT} PRIVATE apps/manager_app # Manager app is always included src/ @@ -213,11 +206,11 @@ target_include_directories(${EXECUTABLE} PRIVATE src/level_four/tap_cards/controller src/level_four/tap_cards/tasks - common - common/interfaces/card_interface - common/interfaces/desktop_app_interface - common/interfaces/flash_interface - common/interfaces/user_interface + common + common/interfaces/card_interface + common/interfaces/desktop_app_interface + common/interfaces/flash_interface + common/interfaces/user_interface common/libraries/atecc common/libraries/atecc/atcacert common/libraries/atecc/basic @@ -226,26 +219,26 @@ target_include_directories(${EXECUTABLE} PRIVATE common/libraries/atecc/hal common/libraries/atecc/host common/libraries/atecc/jwt - common/libraries/crypto + common/libraries/crypto common/libraries/crypto/mpz_operations common/libraries/crypto/aes common/libraries/crypto/chacha20poly1305 common/libraries/crypto/ed25519-donna common/libraries/crypto/monero common/libraries/crypto/random_gen - common/libraries/proof_of_work - common/libraries/shamir - common/libraries/util - common/startup + common/libraries/proof_of_work + common/libraries/shamir + common/libraries/util + common/startup common/logger - common/coin_support - common/flash - common/Firewall - common/core - common/timers - common/lvgl + common/coin_support + common/flash + common/Firewall + common/core + common/timers + common/lvgl common/lvgl/porting - common/lvgl/src + common/lvgl/src common/lvgl/src/lv_core common/lvgl/src/lv_draw common/lvgl/src/lv_font @@ -302,14 +295,14 @@ target_include_directories(${EXECUTABLE} PRIVATE # Conditional include directories based on BTC_ONLY flag IF(BTC_ONLY) # BTC-only build: include only Bitcoin family apps - target_include_directories(${EXECUTABLE} PRIVATE + target_include_directories(${PROJECT} PRIVATE apps/btc_family apps/btc_family/btc apps/inheritance_app ) ELSE() # Full build: include all cryptocurrency apps and their specific common support includes - target_include_directories(${EXECUTABLE} PRIVATE + target_include_directories(${PROJECT} PRIVATE apps/btc_family # BTC family is also part of full build apps/btc_family/btc apps/btc_family/dash @@ -334,8 +327,8 @@ ELSE() apps/exchange_app # Common coin support sub-module includes for non-BTC builds - common/coin_support/eth_sign_data # Headers for eth_sign_data module - common/coin_support/tron_parse_txn # Headers for tron_parse_txn module + common/coin_support/eth_sign_data # Headers for eth_sign_data module + common/coin_support/tron_parse_txn # Headers for tron_parse_txn module # If other coin-specific helper headers (e.g., solana_txn_helpers.h, near_context.h) # reside in specific subdirectories under common/coin_support/, add those paths here. # If they are within the app-specific directories (e.g. apps/solana_app/), @@ -352,56 +345,56 @@ ELSE() ) ENDIF(BTC_ONLY) -target_compile_options(${EXECUTABLE} PRIVATE - -mcpu=cortex-m4 - -mthumb - -mfpu=fpv4-sp-d16 +target_compile_options(${PROJECT} PRIVATE + -mcpu=cortex-m4 + -mthumb + -mfpu=fpv4-sp-d16 -mfloat-abi=hard - -fdata-sections + -fdata-sections -ffunction-sections - -Wall - -Wno-format-truncation - -Wno-unused-but-set-variable + -Wall + -Wno-format-truncation + -Wno-unused-but-set-variable -Wno-return-type -D_POSIX_C_SOURCE=200809L $<$:-g3> - $<$:-Werror> + $<$:-Werror> ) -target_link_options(${EXECUTABLE} PRIVATE +target_link_options(${PROJECT} PRIVATE -T${CMAKE_SOURCE_DIR}/STM32L486RGTX_FLASH.ld -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -u _printf_float -lc -lm -lnosys - -Wl,-Map=${PROJECT_NAME}.map,--cref -Wl,--gc-sections + -Wl,-Map=${PROJECT}.map,--cref -Wl,--gc-sections ) # Used to suppress compile time warnings in libraries -file(GLOB_RECURSE LIBRARIES_SRC_DIR - "common/libraries/atecc/*.c" - "common/libraries/atecc/*.h" - "common/lvgl/src/**/*.c" - "common/lvgl/src/**/*.h" - "common/libraries/crypto/*.c" - "common/libraries/crypto/*.h" +file(GLOB_RECURSE LIBRARIES_SRC_DIR + "common/libraries/atecc/*.c" + "common/libraries/atecc/*.h" + "common/lvgl/src/**/*.c" + "common/lvgl/src/**/*.h" + "common/libraries/crypto/*.c" + "common/libraries/crypto/*.h" "stm32-hal/Peripherals/*.c" "stm32-hal/Peripherals/*.h") set_source_files_properties(${LIBRARIES_SRC_DIR} PROPERTIES COMPILE_FLAGS "-w") # Print executable size -add_custom_command(TARGET ${EXECUTABLE} +add_custom_command(TARGET ${PROJECT} POST_BUILD - COMMAND arm-none-eabi-size ${EXECUTABLE}) + COMMAND arm-none-eabi-size $) -# Create hex file -add_custom_command(TARGET ${EXECUTABLE} +# Create hex and bin files +add_custom_command(TARGET ${PROJECT} POST_BUILD - COMMAND arm-none-eabi-objcopy -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex - COMMAND arm-none-eabi-objcopy -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin) + COMMAND arm-none-eabi-objcopy -O ihex $ ${PROJECT}.hex + COMMAND arm-none-eabi-objcopy -O binary $ ${PROJECT}.bin) if (SIGN_BINARY) - add_custom_command(TARGET ${EXECUTABLE} + add_custom_command(TARGET ${PROJECT} POST_BUILD - COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py add-header --input="${PROJECT_NAME}.bin" --output=${PROJECT_NAME}_Header.bin --version=${CMAKE_SOURCE_DIR}/version.txt --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key1.h - COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py sign-header --input=${PROJECT_NAME}_Header.bin --output=${PROJECT_NAME}-signed.bin --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key2.h - COMMAND rm ${PROJECT_NAME}_Header.bin) -endif() \ No newline at end of file + COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py add-header --input="${PROJECT}.bin" --output=${PROJECT}_Header.bin --version=${CMAKE_SOURCE_DIR}/version.txt --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key1.h + COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py sign-header --input=${PROJECT}_Header.bin --output=${PROJECT}-signed.bin --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key2.h + COMMAND rm ${PROJECT}_Header.bin) +endif() From d368904eecdba2099277888454a31c0acdb85d3e Mon Sep 17 00:00:00 2001 From: Muzaffar Ahmad Bhat Date: Thu, 4 Sep 2025 13:09:57 +0530 Subject: [PATCH 12/14] revert: Changing versioning This reverts commit 4b242d2fdba11b73f6d4f554a31cd85b71c2a075. --- utilities/cmake/firmware/firmware.cmake | 183 ++++++++++++------------ 1 file changed, 95 insertions(+), 88 deletions(-) diff --git a/utilities/cmake/firmware/firmware.cmake b/utilities/cmake/firmware/firmware.cmake index d02d5cdd9..7a626a971 100644 --- a/utilities/cmake/firmware/firmware.cmake +++ b/utilities/cmake/firmware/firmware.cmake @@ -1,6 +1,5 @@ enable_language(C ASM) -# The EXECUTABLE variable is removed. We will use ${PROJECT} directly, -# which is passed down from the parent CMakeLists.txt and holds the correct name (e.g., "Cypherock-Main-btc"). +set(EXECUTABLE ${PROJECT_NAME}.elf) set(LINKER_SCRIPT STM32L486RGTX_FLASH.ld) set(STARTUP_FILE startup_stm32l486xx.s) set(CMAKE_C_STANDARD 11) @@ -43,9 +42,9 @@ set(CORE_COMMON_GENERAL_SOURCES_FROM_SUBDIRS # or are genuinely generic. set(CORE_COMMON_SPECIFIC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/common/assert_def.c" - "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/coin_specific_data.c" - "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/coin_utils.c" - "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/wallet.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/coin_specific_data.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/coin_utils.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/wallet.c" # common/core/core_flow_init.c is now covered by CORE_COMMON_CORE_SOURCES glob. # Ensure it and other common/core/*.c files have internal guards where needed. ) @@ -78,24 +77,24 @@ set(COMMON_NON_BTC_SOURCES "") IF(NOT BTC_ONLY) # Source files from common/coin_support/eth_sign_data/ set(ETH_SIGN_DATA_COMMON_SRCS "") - file(GLOB ETH_SIGN_DATA_COMMON_SRCS_TMP "common/coin_support/eth_sign_data/*.c") + file(GLOB ETH_SIGN_DATA_COMMON_SRCS_TMP "common/coin_support/eth_sign_data/*.c") foreach(file ${ETH_SIGN_DATA_COMMON_SRCS_TMP}) list(APPEND ETH_SIGN_DATA_COMMON_SRCS "${file}") endforeach() # Source files from common/coin_support/tron_parse_txn/ set(TRON_PARSE_TXN_COMMON_SRCS "") - file(GLOB TRON_PARSE_TXN_COMMON_SRCS_TMP "common/coin_support/tron_parse_txn/*.c") + file(GLOB TRON_PARSE_TXN_COMMON_SRCS_TMP "common/coin_support/tron_parse_txn/*.c") foreach(file ${TRON_PARSE_TXN_COMMON_SRCS_TMP}) list(APPEND TRON_PARSE_TXN_COMMON_SRCS "${file}") endforeach() - + list(APPEND COMMON_NON_BTC_SOURCES ${ETH_SIGN_DATA_COMMON_SRCS} ${TRON_PARSE_TXN_COMMON_SRCS} - "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/eth.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/eth.c" "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/solana.c" - "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/near.c" + "${CMAKE_CURRENT_SOURCE_DIR}/common/coin_support/near.c" # Add other .c files from common/coin_support that are exclusively for non-BTC chains if any ) ENDIF() @@ -103,14 +102,14 @@ ENDIF() IF(BTC_ONLY) # BTC-only build: include only Bitcoin-related apps - set(APP_SOURCES - ${MANAGER_APP_SOURCES} + set(APP_SOURCES + ${MANAGER_APP_SOURCES} ${BTC_FAMILY_SOURCES} ${INHERITANCE_APP_SOURCES} ) -ELSE() - set(APP_SOURCES - ${MANAGER_APP_SOURCES} +ELSE() + set(APP_SOURCES + ${MANAGER_APP_SOURCES} ${BTC_FAMILY_SOURCES} ${EVM_FAMILY_SOURCES} ${NEAR_APP_SOURCES} @@ -128,7 +127,7 @@ IF(UNIT_TESTS_SWITCH) # Add test sources file(GLOB_RECURSE TEST_SOURCES "tests/*.*") set(SOURCES ${BASE_SOURCES} ${APP_SOURCES} ${COMMON_NON_BTC_SOURCES} ${TEST_SOURCES}) - + #exclude src/main.c from the compilation list as it needs to be overriden by unit_tests_main.c LIST(REMOVE_ITEM SOURCES "${PROJECT_SOURCE_DIR}/src/main.c") @@ -139,38 +138,46 @@ ELSE() set(SOURCES ${BASE_SOURCES} ${APP_SOURCES} ${COMMON_NON_BTC_SOURCES}) ENDIF(UNIT_TESTS_SWITCH) -add_executable(${PROJECT} - ${SOURCES} - ${CMAKE_CURRENT_BINARY_DIR}/version.c - ${MINI_GMP_SRCS} - ${POSEIDON_SRCS} - ${PROTO_SRCS} - ${PROTO_HDRS} - ${INCLUDES} - ${LINKER_SCRIPT} +add_executable(${EXECUTABLE} + ${SOURCES} + ${CMAKE_CURRENT_BINARY_DIR}/version.c + ${MINI_GMP_SRCS} + ${POSEIDON_SRCS} + ${PROTO_SRCS} + ${PROTO_HDRS} + ${INCLUDES} + ${LINKER_SCRIPT} ${STARTUP_FILE}) -target_compile_definitions(${PROJECT} PRIVATE - -DUSE_HAL_DRIVER +target_compile_definitions(${EXECUTABLE} PRIVATE + -DUSE_HAL_DRIVER -DSTM32L486xx ) -# NOTE: The compile definitions for DEV_SWITCH, BTC_ONLY_BUILD, and FIRMWARE_TYPE -# have been removed from this file as they are now centrally managed in the -# main CMakeLists.txt. This avoids redundancy and ensures a single source of truth. add_compile_definitions( - USE_SIMULATOR=0 - USE_BIP32_CACHE=0 - USE_BIP39_CACHE=0 - STM32L4 - USBD_SOF_DISABLED + USE_SIMULATOR=0 + USE_BIP32_CACHE=0 + USE_BIP39_CACHE=0 + STM32L4 + USBD_SOF_DISABLED ENABLE_HID_WEBUSB_COMM=1) +# Add BTC_ONLY compile definition when building BTC-only firmware +IF(BTC_ONLY) + add_compile_definitions(BTC_ONLY_BUILD) +ENDIF(BTC_ONLY) + +IF (DEV_SWITCH) + add_compile_definitions(DEV_BUILD) +ENDIF(DEV_SWITCH) + if ("${FIRMWARE_TYPE}" STREQUAL "Main") - target_include_directories(${PROJECT} PRIVATE + add_compile_definitions(X1WALLET_INITIAL=0 X1WALLET_MAIN=1) + target_include_directories(${EXECUTABLE} PRIVATE main/config/ ) elseif("${FIRMWARE_TYPE}" STREQUAL "Initial") - target_include_directories(${PROJECT} PRIVATE + add_compile_definitions(X1WALLET_INITIAL=1 X1WALLET_MAIN=0) + target_include_directories(${EXECUTABLE} PRIVATE initial/config/ ) else() @@ -178,7 +185,7 @@ else() endif() # Base include directories (always included) -target_include_directories(${PROJECT} PRIVATE +target_include_directories(${EXECUTABLE} PRIVATE apps/manager_app # Manager app is always included src/ @@ -206,11 +213,11 @@ target_include_directories(${PROJECT} PRIVATE src/level_four/tap_cards/controller src/level_four/tap_cards/tasks - common - common/interfaces/card_interface - common/interfaces/desktop_app_interface - common/interfaces/flash_interface - common/interfaces/user_interface + common + common/interfaces/card_interface + common/interfaces/desktop_app_interface + common/interfaces/flash_interface + common/interfaces/user_interface common/libraries/atecc common/libraries/atecc/atcacert common/libraries/atecc/basic @@ -219,26 +226,26 @@ target_include_directories(${PROJECT} PRIVATE common/libraries/atecc/hal common/libraries/atecc/host common/libraries/atecc/jwt - common/libraries/crypto + common/libraries/crypto common/libraries/crypto/mpz_operations common/libraries/crypto/aes common/libraries/crypto/chacha20poly1305 common/libraries/crypto/ed25519-donna common/libraries/crypto/monero common/libraries/crypto/random_gen - common/libraries/proof_of_work - common/libraries/shamir - common/libraries/util - common/startup + common/libraries/proof_of_work + common/libraries/shamir + common/libraries/util + common/startup common/logger - common/coin_support - common/flash - common/Firewall - common/core - common/timers - common/lvgl + common/coin_support + common/flash + common/Firewall + common/core + common/timers + common/lvgl common/lvgl/porting - common/lvgl/src + common/lvgl/src common/lvgl/src/lv_core common/lvgl/src/lv_draw common/lvgl/src/lv_font @@ -295,14 +302,14 @@ target_include_directories(${PROJECT} PRIVATE # Conditional include directories based on BTC_ONLY flag IF(BTC_ONLY) # BTC-only build: include only Bitcoin family apps - target_include_directories(${PROJECT} PRIVATE + target_include_directories(${EXECUTABLE} PRIVATE apps/btc_family apps/btc_family/btc apps/inheritance_app ) ELSE() # Full build: include all cryptocurrency apps and their specific common support includes - target_include_directories(${PROJECT} PRIVATE + target_include_directories(${EXECUTABLE} PRIVATE apps/btc_family # BTC family is also part of full build apps/btc_family/btc apps/btc_family/dash @@ -328,8 +335,8 @@ ELSE() apps/stellar_app # Common coin support sub-module includes for non-BTC builds - common/coin_support/eth_sign_data # Headers for eth_sign_data module - common/coin_support/tron_parse_txn # Headers for tron_parse_txn module + common/coin_support/eth_sign_data # Headers for eth_sign_data module + common/coin_support/tron_parse_txn # Headers for tron_parse_txn module # If other coin-specific helper headers (e.g., solana_txn_helpers.h, near_context.h) # reside in specific subdirectories under common/coin_support/, add those paths here. # If they are within the app-specific directories (e.g. apps/solana_app/), @@ -347,56 +354,56 @@ ELSE() ) ENDIF(BTC_ONLY) -target_compile_options(${PROJECT} PRIVATE - -mcpu=cortex-m4 - -mthumb - -mfpu=fpv4-sp-d16 +target_compile_options(${EXECUTABLE} PRIVATE + -mcpu=cortex-m4 + -mthumb + -mfpu=fpv4-sp-d16 -mfloat-abi=hard - -fdata-sections + -fdata-sections -ffunction-sections - -Wall - -Wno-format-truncation - -Wno-unused-but-set-variable + -Wall + -Wno-format-truncation + -Wno-unused-but-set-variable -Wno-return-type -D_POSIX_C_SOURCE=200809L $<$:-g3> - $<$:-Werror> + $<$:-Werror> ) -target_link_options(${PROJECT} PRIVATE +target_link_options(${EXECUTABLE} PRIVATE -T${CMAKE_SOURCE_DIR}/STM32L486RGTX_FLASH.ld -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -u _printf_float -lc -lm -lnosys - -Wl,-Map=${PROJECT}.map,--cref -Wl,--gc-sections + -Wl,-Map=${PROJECT_NAME}.map,--cref -Wl,--gc-sections ) # Used to suppress compile time warnings in libraries -file(GLOB_RECURSE LIBRARIES_SRC_DIR - "common/libraries/atecc/*.c" - "common/libraries/atecc/*.h" - "common/lvgl/src/**/*.c" - "common/lvgl/src/**/*.h" - "common/libraries/crypto/*.c" - "common/libraries/crypto/*.h" +file(GLOB_RECURSE LIBRARIES_SRC_DIR + "common/libraries/atecc/*.c" + "common/libraries/atecc/*.h" + "common/lvgl/src/**/*.c" + "common/lvgl/src/**/*.h" + "common/libraries/crypto/*.c" + "common/libraries/crypto/*.h" "stm32-hal/Peripherals/*.c" "stm32-hal/Peripherals/*.h") set_source_files_properties(${LIBRARIES_SRC_DIR} PROPERTIES COMPILE_FLAGS "-w") # Print executable size -add_custom_command(TARGET ${PROJECT} +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND arm-none-eabi-size $) + COMMAND arm-none-eabi-size ${EXECUTABLE}) -# Create hex and bin files -add_custom_command(TARGET ${PROJECT} +# Create hex file +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND arm-none-eabi-objcopy -O ihex $ ${PROJECT}.hex - COMMAND arm-none-eabi-objcopy -O binary $ ${PROJECT}.bin) + COMMAND arm-none-eabi-objcopy -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex + COMMAND arm-none-eabi-objcopy -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin) if (SIGN_BINARY) - add_custom_command(TARGET ${PROJECT} + add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py add-header --input="${PROJECT}.bin" --output=${PROJECT}_Header.bin --version=${CMAKE_SOURCE_DIR}/version.txt --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key1.h - COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py sign-header --input=${PROJECT}_Header.bin --output=${PROJECT}-signed.bin --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key2.h - COMMAND rm ${PROJECT}_Header.bin) -endif() + COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py add-header --input="${PROJECT_NAME}.bin" --output=${PROJECT_NAME}_Header.bin --version=${CMAKE_SOURCE_DIR}/version.txt --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key1.h + COMMAND python3 ${CMAKE_SOURCE_DIR}/utilities/script/index.py sign-header --input=${PROJECT_NAME}_Header.bin --output=${PROJECT_NAME}-signed.bin --private-key=${CMAKE_SOURCE_DIR}/utilities/script/private_key2.h + COMMAND rm ${PROJECT_NAME}_Header.bin) +endif() \ No newline at end of file From e171b0cfed817d066ed1015952ef56937bf732e9 Mon Sep 17 00:00:00 2001 From: Muzaffar Ahmad Bhat Date: Thu, 4 Sep 2025 13:11:05 +0530 Subject: [PATCH 13/14] revert: Changing versioning This reverts commit b92ed97bcdce139a19d88d3d49850d9f939471d2. --- CMakeLists.txt | 58 ++++++++++++------------------ apps/manager_app/get_device_info.c | 10 ------ utilities/build.sh | 2 +- 3 files changed, 24 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5088f651..097bde6e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,29 +4,25 @@ set(CMAKE_MESSAGE_LOG_LEVEL debug) if("${CMAKE_BUILD_PLATFORM}" STREQUAL "Device") message("Device platform selected") set(CMAKE_TOOLCHAIN_FILE utilities/cmake/arm-none-eabi-gcc.cmake) - set(PROJECT_NAME_BASE Cypherock-${FIRMWARE_TYPE}) + set(PROJECT Cypherock-${FIRMWARE_TYPE}) elseif("${CMAKE_BUILD_PLATFORM}" STREQUAL "Simulator") message("Simulator platform selected") - set(PROJECT_NAME_BASE Cypherock_Simulator) + set(PROJECT Cypherock_Simulator) else() - message(WARNING "No platform specified, defaulting to Simulator. Specify using -DCMAKE_BUILD_PLATFORM=") - set(PROJECT_NAME_BASE Cypherock_Simulator) + message(WARNING "No platform specified defaulting to Simulator. Specify using -DCMAKE_BUILD_PLATFORM= Type can be Device or Simulator") + set(PROJECT Cypherock_Simulator) endif() -# Define all build options +# Define all options upfront, including BTC_ONLY OPTION(DEV_SWITCH "Additional features/logs to aid developers" OFF) OPTION(UNIT_TESTS_SWITCH "Compile build for main firmware or unit tests" OFF) OPTION(BTC_ONLY "Build firmware for Bitcoin only" OFF) -# Append suffix to the project name if BTC_ONLY is enabled -set(PROJECT ${PROJECT_NAME_BASE}) +# Logic to append -btc to project name if BTC_ONLY is enabled if (BTC_ONLY) set(PROJECT ${PROJECT}-btc) endif() -# Define the project with its final calculated name -project(${PROJECT}) - # Make static functions testable via unit-tests IF(UNIT_TESTS_SWITCH) add_compile_definitions( STATIC= ) @@ -34,28 +30,11 @@ ELSE() add_compile_definitions( STATIC=static ) ENDIF(UNIT_TESTS_SWITCH) -# Set firmware type (Main or Initial) -if ("${FIRMWARE_TYPE}" STREQUAL "Main") - add_compile_definitions(X1WALLET_INITIAL=0 X1WALLET_MAIN=1) -elseif("${FIRMWARE_TYPE}" STREQUAL "Initial") - add_compile_definitions(X1WALLET_INITIAL=1 X1WALLET_MAIN=0) -endif() - -# Set variant-specific definition (BTC_ONLY_BUILD) -if(BTC_ONLY) - add_compile_definitions(BTC_ONLY_BUILD=1) -endif() - -# Set hash calculation definition based on build type -if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") - add_compile_definitions(FIRMWARE_HASH_CALC=1) -else() - add_compile_definitions(FIRMWARE_HASH_CALC=0) -endif() - -# Enable support for dynamically allocated fields in nanopb -add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1) +# Now define the project with its final name, after all modifications +project(${PROJECT}) +# python is needed for compiling proto files using nanopb +# also for generating & appending firmware signature headers find_package( Python3 REQUIRED COMPONENTS Interpreter ) # Conditionally generate protobuf files based on the BTC_ONLY option @@ -95,17 +74,26 @@ list (APPEND POSEIDON_SRCS "vendor/poseidon/sources/poseidon_rc.c" ) -# This is where add_executable(${PROJECT} ...) is called +if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") + add_compile_definitions(FIRMWARE_HASH_CALC=1) +else() + add_compile_definitions(FIRMWARE_HASH_CALC=0) +endif() + if("${CMAKE_BUILD_PLATFORM}" STREQUAL "Device") include(utilities/cmake/firmware/firmware.cmake) else() # Simulator or default include(utilities/cmake/simulator/simulator.cmake) endif() -# This must come AFTER the add_executable call in the included files -target_include_directories( ${PROJECT} PRIVATE +# Include nanopb source headers +target_include_directories( ${EXECUTABLE} PRIVATE vendor/nanopb generated/proto vendor/mini-gmp vendor/poseidon/sources -) \ No newline at end of file +) + +# Enable support for dynamically allocated fields in nanopb +# Ref: vendor/nanopb/pb.h +add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1) diff --git a/apps/manager_app/get_device_info.c b/apps/manager_app/get_device_info.c index c6397a8b7..5194066f0 100644 --- a/apps/manager_app/get_device_info.c +++ b/apps/manager_app/get_device_info.c @@ -67,7 +67,6 @@ #include "manager_api.h" #include "manager_app.h" #include "onboarding.h" -#include /***************************************************************************** * EXTERN VARIABLES @@ -144,15 +143,6 @@ static manager_get_device_info_response_t get_device_info(void) { result->is_initial = (MANAGER_ONBOARDING_STEP_COMPLETE != onboarding_get_last_step()); result->onboarding_step = onboarding_get_last_step(); - - // Populate the firmware variant string based on the compile-time flag. - // This allows the client (CySync) to know which firmware variant is running. -#ifdef BTC_ONLY_BUILD - strcpy(result->variant, "BTC_ONLY"); -#else - strcpy(result->variant, "MULTICOIN"); -#endif - // TODO: populate applet list (result->applet_list) } diff --git a/utilities/build.sh b/utilities/build.sh index e4e351cdf..d997e7aee 100755 --- a/utilities/build.sh +++ b/utilities/build.sh @@ -158,4 +158,4 @@ if [ ! $? -eq 0 ]; then exit 1; fi if [[ "${clean_flag}" = "true" ]]; then "${BUILD_TOOL}" clean fi -"${BUILD_TOOL}" -j8 all \ No newline at end of file +"${BUILD_TOOL}" -j8 all From 3fcfbfe393e6a6eb2077368affb5111f8f8bb500 Mon Sep 17 00:00:00 2001 From: Muzaffar Ahmad Bhat Date: Thu, 4 Sep 2025 14:18:41 +0530 Subject: [PATCH 14/14] fix: Build issue --- utilities/cmake/firmware/firmware.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utilities/cmake/firmware/firmware.cmake b/utilities/cmake/firmware/firmware.cmake index 7a626a971..2472e0d1a 100644 --- a/utilities/cmake/firmware/firmware.cmake +++ b/utilities/cmake/firmware/firmware.cmake @@ -71,6 +71,7 @@ file(GLOB_RECURSE CONSTELLATION_APP_SOURCE "apps/constellation_app/*.*") file(GLOB_RECURSE STARKNET_APP_SOURCES "apps/starknet_app/*.*") file(GLOB_RECURSE XRP_APP_SOURCES "apps/xrp_app/*.*") file(GLOB_RECURSE ICP_APP_SOURCES "apps/icp_app/*.*") +file(GLOB_RECURSE STELLAR_APP_SOURCES "apps/stellar_app/*.*") # Define sources from common/coin_support that are specific to non-BTC builds set(COMMON_NON_BTC_SOURCES "") @@ -120,7 +121,8 @@ ELSE() ${STARKNET_APP_SOURCES} ${XRP_APP_SOURCES} ${ICP_APP_SOURCES} - ${CONSTELLATION_APP_SOURCE}) + ${CONSTELLATION_APP_SOURCE} + ${STELLAR_APP_SOURCES}) ENDIF(BTC_ONLY) IF(UNIT_TESTS_SWITCH)