2017-08-03 22:45:32 +00:00
|
|
|
# pylint: disable=E0602
|
|
|
|
|
2017-09-04 12:15:16 +00:00
|
|
|
import os
|
2022-10-14 10:43:37 +00:00
|
|
|
import tools
|
2017-09-04 12:15:16 +00:00
|
|
|
|
2020-08-28 12:50:38 +00:00
|
|
|
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
|
2023-01-30 14:36:22 +00:00
|
|
|
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
|
2020-08-28 12:50:38 +00:00
|
|
|
|
2022-05-07 07:19:29 +00:00
|
|
|
if TREZOR_MODEL in ('1', ):
|
|
|
|
# skip boardloader build
|
|
|
|
env = Environment()
|
|
|
|
def build_boardloader(target,source,env):
|
|
|
|
print(f'Boardloader: nothing to build for Model {TREZOR_MODEL}')
|
|
|
|
program_bin = env.Command(
|
|
|
|
target='boardloader.bin',
|
|
|
|
source=None,
|
|
|
|
action=build_boardloader
|
|
|
|
)
|
|
|
|
Return()
|
|
|
|
|
2023-03-27 14:44:01 +00:00
|
|
|
FEATURES_WANTED = ["sd_card"]
|
2023-02-15 12:57:54 +00:00
|
|
|
|
2017-08-03 22:45:32 +00:00
|
|
|
CCFLAGS_MOD = ''
|
|
|
|
CPPPATH_MOD = []
|
2023-08-09 12:53:13 +00:00
|
|
|
CPPDEFINES_MOD = ["BOARDLOADER"]
|
2017-08-03 22:45:32 +00:00
|
|
|
SOURCE_MOD = []
|
2024-04-10 13:11:12 +00:00
|
|
|
SOURCE_MOD_CRYPTO = []
|
2023-06-23 14:50:13 +00:00
|
|
|
CPPDEFINES_HAL = []
|
|
|
|
SOURCE_HAL = []
|
|
|
|
PATH_HAL = []
|
2017-08-03 22:45:32 +00:00
|
|
|
|
|
|
|
# modtrezorcrypto
|
|
|
|
CCFLAGS_MOD += '-Wno-sequence-point '
|
|
|
|
CPPPATH_MOD += [
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto',
|
2023-06-30 10:12:55 +00:00
|
|
|
'vendor/trezor-storage',
|
2017-08-03 22:45:32 +00:00
|
|
|
]
|
|
|
|
CPPDEFINES_MOD += [
|
|
|
|
'AES_128',
|
|
|
|
'AES_192',
|
|
|
|
'USE_KECCAK',
|
|
|
|
'ED25519_NO_PRECOMP',
|
|
|
|
]
|
|
|
|
SOURCE_MOD += [
|
2024-04-10 13:11:12 +00:00
|
|
|
'vendor/trezor-storage/flash_area.c',
|
|
|
|
]
|
|
|
|
SOURCE_MOD_CRYPTO += [
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto/blake2s.c',
|
2017-12-12 21:00:15 +00:00
|
|
|
'vendor/trezor-crypto/ed25519-donna/curve25519-donna-32bit.c',
|
|
|
|
'vendor/trezor-crypto/ed25519-donna/curve25519-donna-helpers.c',
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto/ed25519-donna/ed25519.c',
|
2017-12-12 21:00:15 +00:00
|
|
|
'vendor/trezor-crypto/ed25519-donna/ed25519-donna-32bit-tables.c',
|
|
|
|
'vendor/trezor-crypto/ed25519-donna/ed25519-donna-impl-base.c',
|
|
|
|
'vendor/trezor-crypto/ed25519-donna/modm-donna-32bit.c',
|
2018-01-18 14:26:22 +00:00
|
|
|
'vendor/trezor-crypto/memzero.c',
|
2017-12-12 19:31:03 +00:00
|
|
|
'vendor/trezor-crypto/sha2.c',
|
2017-08-03 22:45:32 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# modtrezorui
|
2020-01-16 10:56:50 +00:00
|
|
|
CPPPATH_MOD += [
|
2021-09-09 18:26:10 +00:00
|
|
|
'vendor/micropython/lib/uzlib',
|
2020-01-16 10:56:50 +00:00
|
|
|
]
|
2017-08-03 22:45:32 +00:00
|
|
|
SOURCE_MOD += [
|
2023-03-27 13:03:54 +00:00
|
|
|
'embed/lib/colors.c',
|
2024-01-17 14:29:49 +00:00
|
|
|
'embed/lib/display_utils.c',
|
|
|
|
'embed/lib/display.c',
|
2023-03-27 13:03:54 +00:00
|
|
|
'embed/lib/fonts/font_bitmap.c',
|
2024-01-17 14:29:49 +00:00
|
|
|
'embed/lib/fonts/fonts.c',
|
2023-06-30 10:12:55 +00:00
|
|
|
'embed/lib/image.c',
|
2023-06-23 14:50:13 +00:00
|
|
|
'embed/lib/mini_printf.c',
|
2024-01-17 14:29:49 +00:00
|
|
|
'embed/lib/terminal.c',
|
2017-08-03 22:45:32 +00:00
|
|
|
]
|
|
|
|
|
2023-11-23 21:24:55 +00:00
|
|
|
env = Environment(ENV=os.environ,
|
|
|
|
CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')),
|
|
|
|
CONSTRAINTS=["limited_util_s"],
|
|
|
|
CPPDEFINES_IMPLICIT=[]
|
|
|
|
)
|
2023-06-28 08:51:30 +00:00
|
|
|
|
|
|
|
FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)
|
|
|
|
|
|
|
|
FILE_SUFFIX= env.get('ENV')['SUFFIX']
|
|
|
|
LINKER_SCRIPT_SUFFIX= env.get('ENV')['LINKER_SCRIPT']
|
|
|
|
|
2017-08-03 22:45:32 +00:00
|
|
|
SOURCE_BOARDLOADER = [
|
2023-06-28 08:51:30 +00:00
|
|
|
f"embed/boardloader/startup_{FILE_SUFFIX}.s",
|
2017-08-03 22:45:32 +00:00
|
|
|
'embed/boardloader/main.c',
|
|
|
|
]
|
|
|
|
|
2022-10-14 10:43:37 +00:00
|
|
|
|
2017-08-03 22:45:32 +00:00
|
|
|
env.Replace(
|
2023-01-10 21:28:57 +00:00
|
|
|
CP='cp',
|
2017-08-03 22:45:32 +00:00
|
|
|
AS='arm-none-eabi-as',
|
|
|
|
AR='arm-none-eabi-ar',
|
|
|
|
CC='arm-none-eabi-gcc',
|
2018-02-17 15:19:16 +00:00
|
|
|
LINK='arm-none-eabi-gcc',
|
2017-08-03 22:45:32 +00:00
|
|
|
SIZE='arm-none-eabi-size',
|
|
|
|
STRIP='arm-none-eabi-strip',
|
2023-01-30 14:36:22 +00:00
|
|
|
OBJCOPY='arm-none-eabi-objcopy',
|
|
|
|
PYTHON='python',
|
|
|
|
MAKECMAKELISTS='$PYTHON tools/make_cmakelists.py',)
|
2017-08-03 22:45:32 +00:00
|
|
|
|
|
|
|
env.Replace(
|
2020-08-28 12:50:38 +00:00
|
|
|
TREZOR_MODEL=TREZOR_MODEL, )
|
2018-09-30 14:39:40 +00:00
|
|
|
|
|
|
|
env.Replace(
|
2018-07-09 19:03:25 +00:00
|
|
|
COPT=env.get('ENV').get('OPTIMIZE', '-Os'),
|
|
|
|
CCFLAGS='$COPT '
|
2017-08-03 22:45:32 +00:00
|
|
|
'-g3 '
|
|
|
|
'-nostdlib '
|
2023-08-07 13:50:53 +00:00
|
|
|
'-std=gnu11 -Wall -Werror -Wdouble-promotion -Wpointer-arith -Wno-missing-braces -fno-common '
|
2017-10-13 21:21:09 +00:00
|
|
|
'-fsingle-precision-constant -fdata-sections -ffunction-sections '
|
2017-12-08 18:30:46 +00:00
|
|
|
'-ffreestanding '
|
2024-04-05 11:25:54 +00:00
|
|
|
'-fstack-protector-strong '
|
2023-06-23 14:50:13 +00:00
|
|
|
+ env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD,
|
2017-08-03 22:45:32 +00:00
|
|
|
CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB',
|
2023-06-28 08:51:30 +00:00
|
|
|
LINKFLAGS=f"-T embed/boardloader/memory_{LINKER_SCRIPT_SUFFIX}.ld -Wl,--gc-sections -Wl,-Map=build/boardloader/boardloader.map -Wl,--warn-common -Wl,--print-memory-usage",
|
2017-08-03 22:45:32 +00:00
|
|
|
CPPPATH=[
|
|
|
|
'embed/boardloader',
|
2023-03-27 13:03:54 +00:00
|
|
|
'embed/lib',
|
2023-06-01 12:21:51 +00:00
|
|
|
'embed/models',
|
2017-08-03 22:45:32 +00:00
|
|
|
'embed/trezorhal',
|
|
|
|
'embed/extmod/modtrezorui',
|
|
|
|
'vendor/micropython/lib/cmsis/inc',
|
2023-06-23 14:50:13 +00:00
|
|
|
] + CPPPATH_MOD + PATH_HAL,
|
2017-08-03 22:45:32 +00:00
|
|
|
CPPDEFINES=[
|
2022-05-31 07:31:32 +00:00
|
|
|
'BOARDLOADER',
|
2022-04-26 11:47:40 +00:00
|
|
|
'TREZOR_MODEL_'+TREZOR_MODEL,
|
2017-11-05 15:57:31 +00:00
|
|
|
'USE_HAL_DRIVER',
|
2023-06-23 14:50:13 +00:00
|
|
|
] + CPPDEFINES_MOD + CPPDEFINES_HAL,
|
|
|
|
ASFLAGS=env.get('ENV')['CPU_ASFLAGS'],
|
|
|
|
ASPPFLAGS='$CFLAGS $CCFLAGS',
|
|
|
|
)
|
2017-08-03 22:45:32 +00:00
|
|
|
|
2023-01-30 14:36:22 +00:00
|
|
|
env.Replace(
|
2024-04-10 13:11:12 +00:00
|
|
|
ALLSOURCES=SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_BOARDLOADER + SOURCE_HAL,
|
2023-11-23 21:24:55 +00:00
|
|
|
ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT']))
|
2023-01-30 14:36:22 +00:00
|
|
|
|
|
|
|
cmake_gen = env.Command(
|
|
|
|
target='CMakeLists.txt',
|
|
|
|
source='',
|
|
|
|
action='$MAKECMAKELISTS --sources $ALLSOURCES --dirs $CPPPATH --defs $ALLDEFS',
|
|
|
|
)
|
|
|
|
|
2017-08-03 22:45:32 +00:00
|
|
|
#
|
|
|
|
# Program objects
|
|
|
|
#
|
|
|
|
|
|
|
|
obj_program = []
|
|
|
|
obj_program += env.Object(source=SOURCE_MOD)
|
2024-04-15 15:55:24 +00:00
|
|
|
obj_program += env.Object(source=SOURCE_MOD_CRYPTO, CCFLAGS='$CCFLAGS -ftrivial-auto-var-init=zero')
|
2017-08-03 22:45:32 +00:00
|
|
|
obj_program += env.Object(source=SOURCE_BOARDLOADER)
|
2023-06-23 14:50:13 +00:00
|
|
|
obj_program += env.Object(source=SOURCE_HAL)
|
2017-08-03 22:45:32 +00:00
|
|
|
|
|
|
|
program_elf = env.Command(
|
|
|
|
target='boardloader.elf',
|
|
|
|
source=obj_program,
|
|
|
|
action=
|
2018-02-17 15:19:16 +00:00
|
|
|
'$LINK -o $TARGET $CCFLAGS $CFLAGS $LINKFLAGS $SOURCES -lc_nano -lgcc',
|
2017-08-03 22:45:32 +00:00
|
|
|
)
|
|
|
|
|
2023-01-10 21:28:57 +00:00
|
|
|
BINARY_NAME = f"build/boardloader/boardloader-{tools.get_model_identifier(TREZOR_MODEL)}"
|
|
|
|
BINARY_NAME += "-" + tools.get_version('embed/boardloader/version.h')
|
|
|
|
BINARY_NAME += "-" + tools.get_git_revision_short_hash()
|
|
|
|
BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
|
|
|
|
BINARY_NAME += ".bin"
|
|
|
|
|
2023-01-30 14:36:22 +00:00
|
|
|
if CMAKELISTS != 0:
|
|
|
|
env.Depends(program_elf, cmake_gen)
|
|
|
|
|
2017-08-03 22:45:32 +00:00
|
|
|
program_bin = env.Command(
|
|
|
|
target='boardloader.bin',
|
|
|
|
source=program_elf,
|
2023-01-10 21:28:57 +00:00
|
|
|
action=[
|
2024-03-03 21:19:12 +00:00
|
|
|
'$OBJCOPY -O binary -j .vector_table -j .text -j .data -j .rodata -j .capabilities -j .confidential $SOURCE $TARGET',
|
2023-01-10 21:28:57 +00:00
|
|
|
'$CP $TARGET ' + BINARY_NAME,
|
|
|
|
],
|
2017-08-03 22:45:32 +00:00
|
|
|
)
|