1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 15:08:12 +00:00

refactor(core): rust bindgen mcu-type related arguments are taken from board definition

[no changelog]
This commit is contained in:
tychovrahe 2023-06-28 00:10:46 +02:00 committed by TychoVrahe
parent 6dbeba9730
commit eca1fc381b
11 changed files with 69 additions and 27 deletions

View File

@ -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',

View File

@ -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', )

View File

@ -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=<stm32f4xx.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")

View File

@ -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

View File

@ -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', '"<stm32f4xx.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=<stm32f4xx.h>"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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