1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-17 21:22:10 +00:00

feat(core/rust): bootloader compilation with rust

This commit is contained in:
tychovrahe 2022-05-05 10:12:27 +02:00 committed by Martin Milata
parent 3b23621bea
commit cacae36c73
2 changed files with 49 additions and 1 deletions

View File

@ -233,6 +233,50 @@ cmake_gen = env.Command(
)
#
# Rust library
#
RUST_PROFILE = 'release'
RUST_LIB = 'trezor_lib'
RUST_LIBDIR = f'build/bootloader/rust/{RUST_TARGET}/{RUST_PROFILE}'
RUST_LIBPATH = f'{RUST_LIBDIR}/lib{RUST_LIB}.a'
def cargo_build():
# Determine the profile build flags.
if RUST_PROFILE == 'release':
profile = '--release'
else:
profile = ''
if TREZOR_MODEL in ("1",):
features = ["model_t1"]
elif TREZOR_MODEL in ("R",):
features = ["model_tr"]
else:
features = ["model_tt"]
features.append("bitcoin_only")
features.append("ui")
features.append("bootloader")
cargo_opts = [
f'--target={RUST_TARGET}',
f'--target-dir=../../build/bootloader/rust',
'--no-default-features',
'--features ' + ','.join(features),
'-Z build-std=core',
'-Z build-std-features=panic_immediate_abort',
]
return f'cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts)
rust = env.Command(
target=RUST_LIBPATH,
source='',
action=cargo_build(), )
env.Append(LINKFLAGS=f' -L{RUST_LIBDIR}')
env.Append(LINKFLAGS=f' -l{RUST_LIB}')
#
# Program objects
#
@ -244,13 +288,16 @@ obj_program += env.Object(source=SOURCE_NANOPB)
obj_program += env.Object(source=SOURCE_STMHAL)
obj_program += env.Object(source=SOURCE_TREZORHAL)
program_elf = env.Command(
target='bootloader.elf',
source=obj_program,
action=
'$LINK -o $TARGET $CCFLAGS $CFLAGS $LINKFLAGS $SOURCES -lc_nano -lgcc',
'$LINK -o $TARGET $CCFLAGS $CFLAGS $SOURCES $LINKFLAGS -lc_nano -lm -lgcc',
)
env.Depends(program_elf, rust)
BINARY_NAME = f"build/bootloader/bootloader-{tools.get_model_identifier(TREZOR_MODEL)}"
BINARY_NAME += "-" + tools.get_version('embed/bootloader/version.h')
BINARY_NAME += "-" + tools.get_git_revision_short_hash()

View File

@ -15,6 +15,7 @@ protobuf = ["micropython"]
ui = []
dma2d = []
ui_debug = []
bootloader = []
buttons = []
touch = []
clippy = []