diff --git a/core/SConscript.bootloader_emu b/core/SConscript.bootloader_emu index 435364542b..a9dc34b537 100644 --- a/core/SConscript.bootloader_emu +++ b/core/SConscript.bootloader_emu @@ -185,6 +185,7 @@ env.Replace( 'HW_REVISION=' + ('6' if TREZOR_MODEL in ('R',) else '0'), 'TREZOR_MODEL_'+TREZOR_MODEL, 'TREZOR_BOARD=\\"boards/board-unix.h\\"', + 'MCU_TYPE='+CPU_MODEL, 'PB_FIELD_16BIT', 'PB_ENCODE_ARRAYS_UNPACKED', 'PB_VALIDATE_UTF8', diff --git a/core/SConscript.unix b/core/SConscript.unix index 104920776c..430167a763 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -481,6 +481,7 @@ env.Replace( 'TREZOR_EMULATOR', 'TREZOR_MODEL_'+TREZOR_MODEL, 'TREZOR_BOARD=\\"boards/board-unix.h\\"', + 'MCU_TYPE='+CPU_MODEL, ('MP_CONFIGFILE', '\\"embed/unix/mpconfigport.h\\"'), ] + CPPDEFINES_MOD, ASPPFLAGS='$CFLAGS $CCFLAGS', ) diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs index ca55fa579b..4bb44c74f9 100644 --- a/core/embed/rust/build.rs +++ b/core/embed/rust/build.rs @@ -12,6 +12,13 @@ fn main() { link_core_objects(); } +fn mcu_type() -> String { + match env::var("MCU_TYPE") { + Ok(mcu) => mcu, + Err(_) => String::from("STM32F427xx"), + } +} + fn model() -> String { match env::var("TREZOR_MODEL") { Ok(model) => model, @@ -77,24 +84,28 @@ fn prepare_bindings() -> bindgen::Builder { "-I../../vendor/micropython/lib/uzlib", "-I../lib", "-I../trezorhal", - "-DSTM32F427xx", + format!("-D{}", mcu_type()).as_str(), format!("-DTREZOR_MODEL_{}", model()).as_str(), format!("-DTREZOR_BOARD=\"{}\"", board()).as_str(), ]); // Pass in correct include paths and defines. if is_firmware() { - bindings = bindings.clang_args(&[ - "-nostdinc", - "-I../firmware", - "-I../trezorhal/stm32f4", - "-I../../build/firmware", - "-I../../vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Inc", - "-I../../vendor/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include", - "-I../../vendor/micropython/lib/cmsis/inc", - "-DUSE_HAL_DRIVER", - "-DSTM32_HAL_H=", - ]); + let mut clang_args: Vec<&str> = Vec::new(); + + let includes = env::var("RUST_INCLUDES").unwrap(); + let args = includes.split(";"); + + for arg in args { + clang_args.push(arg); + } + clang_args.push("-nostdinc"); + clang_args.push("-I../firmware"); + clang_args.push("-I../../build/firmware"); + clang_args.push("-I../../vendor/micropython/lib/cmsis/inc"); + clang_args.push("-DUSE_HAL_DRIVER"); + bindings = bindings.clang_args(&clang_args); + // Append gcc-arm-none-eabi's include paths. let cc_output = Command::new("arm-none-eabi-gcc") .arg("-E") diff --git a/core/site_scons/boards/discovery.py b/core/site_scons/boards/discovery.py index 17267b8c22..84d3b81150 100644 --- a/core/site_scons/boards/discovery.py +++ b/core/site_scons/boards/discovery.py @@ -16,13 +16,15 @@ def configure( hw_model = get_hw_model_as_number("D001") hw_revision = 0 - stm32f4_common_files(defines, sources, paths) + mcu = "STM32F429xx" + + stm32f4_common_files(env, defines, sources, paths) env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' - defines += ["STM32F429xx"] + defines += [mcu] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] @@ -53,5 +55,6 @@ def configure( features_available.append("usb") env.get("ENV")["TREZOR_BOARD"] = board + env.get("ENV")["MCU_TYPE"] = mcu return features_available diff --git a/core/site_scons/boards/stm32f4_common.py b/core/site_scons/boards/stm32f4_common.py index f59176bb1a..c22c62e8f5 100644 --- a/core/site_scons/boards/stm32f4_common.py +++ b/core/site_scons/boards/stm32f4_common.py @@ -1,7 +1,7 @@ from __future__ import annotations -def stm32f4_common_files(defines, sources, paths): +def stm32f4_common_files(env, defines, sources, paths): defines += [ ('STM32_HAL_H', '""'), ] @@ -50,3 +50,11 @@ def stm32f4_common_files(defines, sources, paths): 'embed/trezorhal/stm32f4/vectortable.s', ] + env.get("ENV")["RUST_INCLUDES"] = \ + "-I../trezorhal/stm32f4;" \ + "-I../../vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Inc;"\ + "-I../../vendor/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include;"\ + "-DSTM32_HAL_H=" + + + diff --git a/core/site_scons/boards/trezor_1.py b/core/site_scons/boards/trezor_1.py index 28752106ca..a97aedf8cb 100644 --- a/core/site_scons/boards/trezor_1.py +++ b/core/site_scons/boards/trezor_1.py @@ -17,13 +17,15 @@ def configure( hw_model = get_hw_model_as_number("T1B1") hw_revision = 0 - stm32f4_common_files(defines, sources, paths) + mcu = "STM32F405xx" + + stm32f4_common_files(env, defines, sources, paths) env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m3 -mfloat-abi=soft' env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mtune=cortex-m3 -mcpu=cortex-m3 -mfloat-abi=soft ' env.get("ENV")['RUST_TARGET'] = 'thumbv7m-none-eabi' - defines += ["STM32F405xx"] + defines += [mcu] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] @@ -45,5 +47,6 @@ def configure( features_available.append("usb") env.get("ENV")["TREZOR_BOARD"] = board + env.get("ENV")["MCU_TYPE"] = mcu return features_available diff --git a/core/site_scons/boards/trezor_r_v10.py b/core/site_scons/boards/trezor_r_v10.py index 9d56ee868d..2ba363436d 100644 --- a/core/site_scons/boards/trezor_r_v10.py +++ b/core/site_scons/boards/trezor_r_v10.py @@ -17,13 +17,15 @@ def configure( board = "trezor_r_v10.h" display = "vg-2864ksweg01.c" - stm32f4_common_files(defines, sources, paths) + mcu = "STM32F427xx" + + stm32f4_common_files(env, defines, sources, paths) env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' - defines += ["STM32F427xx"] + defines += [mcu] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] @@ -56,5 +58,6 @@ def configure( features_available.append("usb") env.get("ENV")["TREZOR_BOARD"] = board + env.get("ENV")["MCU_TYPE"] = mcu return features_available diff --git a/core/site_scons/boards/trezor_r_v3.py b/core/site_scons/boards/trezor_r_v3.py index 10c86a420e..c41ff8a9f5 100644 --- a/core/site_scons/boards/trezor_r_v3.py +++ b/core/site_scons/boards/trezor_r_v3.py @@ -17,13 +17,15 @@ def configure( board = "trezor_r_v3.h" display = "ug-2828tswig01.c" - stm32f4_common_files(defines, sources, paths) + mcu = "STM32F427xx" + + stm32f4_common_files(env, defines, sources, paths) env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' - defines += ["STM32F427xx"] + defines += [mcu] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] @@ -53,5 +55,6 @@ def configure( features_available.append("usb") env.get("ENV")["TREZOR_BOARD"] = board + env.get("ENV")["MCU_TYPE"] = mcu return features_available diff --git a/core/site_scons/boards/trezor_r_v4.py b/core/site_scons/boards/trezor_r_v4.py index b8c5c5674f..112173236a 100644 --- a/core/site_scons/boards/trezor_r_v4.py +++ b/core/site_scons/boards/trezor_r_v4.py @@ -17,13 +17,15 @@ def configure( board = "trezor_r_v4.h" display = "vg-2864ksweg01.c" - stm32f4_common_files(defines, sources, paths) + mcu = "STM32F427xx" + + stm32f4_common_files(env, defines, sources, paths) env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' - defines += ["STM32F427xx"] + defines += [mcu] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] @@ -49,5 +51,6 @@ def configure( features_available.append("usb") env.get("ENV")["TREZOR_BOARD"] = board + env.get("ENV")["MCU_TYPE"] = mcu return features_available diff --git a/core/site_scons/boards/trezor_r_v6.py b/core/site_scons/boards/trezor_r_v6.py index 58b403e5cc..8e105dd31e 100644 --- a/core/site_scons/boards/trezor_r_v6.py +++ b/core/site_scons/boards/trezor_r_v6.py @@ -17,13 +17,15 @@ def configure( board = "trezor_r_v6.h" display = "vg-2864ksweg01.c" - stm32f4_common_files(defines, sources, paths) + mcu = "STM32F427xx" + + stm32f4_common_files(env, defines, sources, paths) env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' - defines += ["STM32F427xx"] + defines += [mcu] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] @@ -49,5 +51,6 @@ def configure( features_available.append("usb") env.get("ENV")["TREZOR_BOARD"] = board + env.get("ENV")["MCU_TYPE"] = mcu return features_available diff --git a/core/site_scons/boards/trezor_t.py b/core/site_scons/boards/trezor_t.py index 256d72786f..17b1c1d066 100644 --- a/core/site_scons/boards/trezor_t.py +++ b/core/site_scons/boards/trezor_t.py @@ -18,13 +18,15 @@ def configure( hw_revision = 0 features_available.append("disp_i8080_8bit_dw") - stm32f4_common_files(defines, sources, paths) + mcu = "STM32F427xx" + + stm32f4_common_files(env, defines, sources, paths) env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' - defines += ["STM32F427xx"] + defines += [mcu] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] @@ -75,5 +77,6 @@ def configure( features_available.append("dma2d") env.get("ENV")["TREZOR_BOARD"] = board + env.get("ENV")["MCU_TYPE"] = mcu return features_available