diff --git a/core/SConscript.bootloader b/core/SConscript.bootloader index 1dd9dccb8..ec8b33e53 100644 --- a/core/SConscript.bootloader +++ b/core/SConscript.bootloader @@ -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() diff --git a/core/embed/rust/Cargo.toml b/core/embed/rust/Cargo.toml index aab0a8c01..c3ea2e855 100644 --- a/core/embed/rust/Cargo.toml +++ b/core/embed/rust/Cargo.toml @@ -15,6 +15,7 @@ protobuf = ["micropython"] ui = [] dma2d = [] ui_debug = [] +bootloader = [] buttons = [] touch = [] clippy = []