From ea0f3038a08bb5d0df66d20ae1fb95e7356d32b3 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Thu, 23 Nov 2023 22:24:55 +0100 Subject: [PATCH] fix(core): improve cmakelists generation for CMSE [no changelog] --- core/SConscript.boardloader | 8 ++++++-- core/SConscript.bootloader | 8 ++++++-- core/SConscript.bootloader_ci | 7 +++++-- core/SConscript.firmware | 8 ++++++-- core/SConscript.prodtest | 7 +++++-- core/SConscript.reflash | 9 +++++++-- core/site_scons/boards/discovery2.py | 3 +++ core/site_scons/boards/trezor_t3t1_v4.py | 3 +++ 8 files changed, 41 insertions(+), 12 deletions(-) diff --git a/core/SConscript.boardloader b/core/SConscript.boardloader index 6bc2cd6a1..786c9970a 100644 --- a/core/SConscript.boardloader +++ b/core/SConscript.boardloader @@ -68,7 +68,11 @@ SOURCE_MOD += [ 'embed/lib/terminal.c', ] -env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')), CONSTRAINTS=["limited_util_s"]) +env = Environment(ENV=os.environ, + CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')), + CONSTRAINTS=["limited_util_s"], + CPPDEFINES_IMPLICIT=[] + ) FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) @@ -127,7 +131,7 @@ env.Replace( env.Replace( ALLSOURCES=SOURCE_MOD + SOURCE_BOARDLOADER + SOURCE_HAL, - ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'])) + ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'])) cmake_gen = env.Command( target='CMakeLists.txt', diff --git a/core/SConscript.bootloader b/core/SConscript.bootloader index d55a22c1a..25a6d6c14 100644 --- a/core/SConscript.bootloader +++ b/core/SConscript.bootloader @@ -109,7 +109,11 @@ tools.add_font('DEMIBOLD', FONT_DEMIBOLD, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('MONO', FONT_MONO, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('BIG', FONT_BIG, CPPDEFINES_MOD, SOURCE_MOD) -env = Environment(ENV=os.environ, CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DBOOTLOADER_QA={int(BOOTLOADER_QA)}") +env = Environment( + ENV=os.environ, + CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DBOOTLOADER_QA={int(BOOTLOADER_QA)}", + CPPDEFINES_IMPLICIT=[] + ) FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) @@ -182,7 +186,7 @@ env.Replace( env.Replace( ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_HAL, - ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + [f"PRODUCTION={int(PRODUCTION)}", f"BOOTLOADER_QA={int(BOOTLOADER_QA)}"])) + ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'] + [f"PRODUCTION={int(PRODUCTION)}", f"BOOTLOADER_QA={int(BOOTLOADER_QA)}"])) cmake_gen = env.Command( target='CMakeLists.txt', diff --git a/core/SConscript.bootloader_ci b/core/SConscript.bootloader_ci index 277d9a09e..5ac0d8805 100644 --- a/core/SConscript.bootloader_ci +++ b/core/SConscript.bootloader_ci @@ -101,7 +101,10 @@ tools.add_font('DEMIBOLD', FONT_DEMIBOLD, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('MONO', FONT_MONO, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('BIG', FONT_BIG, CPPDEFINES_MOD, SOURCE_MOD) -env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) +env = Environment( + ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')), + CPPDEFINES_IMPLICIT=[] + ) FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) @@ -172,7 +175,7 @@ env.Replace( env.Replace( ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_HAL, - ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'])) + ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'])) cmake_gen = env.Command( target='CMakeLists.txt', diff --git a/core/SConscript.firmware b/core/SConscript.firmware index 8b3f34f0c..fa6d02157 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -375,7 +375,11 @@ tools.add_font('BIG', FONT_BIG, CPPDEFINES_MOD, SOURCE_MOD) SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED -env = Environment(ENV=os.environ, CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DPYOPT={PYOPT} -DBOOTLOADER_QA={int(BOOTLOADER_QA)} -DBITCOIN_ONLY={BITCOIN_ONLY}") +env = Environment( + ENV=os.environ, + CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DPYOPT={PYOPT} -DBOOTLOADER_QA={int(BOOTLOADER_QA)} -DBITCOIN_ONLY={BITCOIN_ONLY}", + CPPDEFINES_IMPLICIT=[] + ) FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) @@ -767,7 +771,7 @@ if FROZEN: env.Replace( ALLSOURCES=source_files, - ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + [f"PRODUCTION={int(PRODUCTION)}", f"BOOTLOADER_QA={int(BOOTLOADER_QA)}", f"PYOPT={PYOPT}", f"BITCOIN_ONLY={BITCOIN_ONLY}"])) + ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'] + [f"PRODUCTION={int(PRODUCTION)}", f"BOOTLOADER_QA={int(BOOTLOADER_QA)}", f"PYOPT={PYOPT}", f"BITCOIN_ONLY={BITCOIN_ONLY}"])) cmake_gen = env.Command( diff --git a/core/SConscript.prodtest b/core/SConscript.prodtest index 2401f7afe..bf8b4d188 100644 --- a/core/SConscript.prodtest +++ b/core/SConscript.prodtest @@ -101,7 +101,10 @@ tools.add_font('DEMIBOLD', FONT_DEMIBOLD, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('MONO', FONT_MONO, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('BIG', FONT_BIG, CPPDEFINES_MOD, SOURCE_MOD) -env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) +env = Environment( + ENV=os.environ, + CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')), + CPPDEFINES_IMPLICIT=[]) FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) @@ -172,7 +175,7 @@ env.Replace( env.Replace( ALLSOURCES=SOURCE_MOD + SOURCE_PRODTEST + SOURCE_HAL, - ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'])) + ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'])) cmake_gen = env.Command( target='CMakeLists.txt', diff --git a/core/SConscript.reflash b/core/SConscript.reflash index 43aedb734..8b63be817 100644 --- a/core/SConscript.reflash +++ b/core/SConscript.reflash @@ -75,7 +75,12 @@ tools.add_font('DEMIBOLD', FONT_DEMIBOLD, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('MONO', FONT_MONO, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('BIG', FONT_BIG, CPPDEFINES_MOD, SOURCE_MOD) -env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')), CONSTRAINTS=["limited_util_s"]) +env = Environment( + ENV=os.environ, + CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')), + CONSTRAINTS=["limited_util_s"], + CPPDEFINES_IMPLICIT=[] + ) FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) @@ -136,7 +141,7 @@ env.Replace( env.Replace( ALLSOURCES=SOURCE_MOD + SOURCE_REFLASH + SOURCE_HAL, - ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'])) + ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'])) cmake_gen = env.Command( target='CMakeLists.txt', diff --git a/core/site_scons/boards/discovery2.py b/core/site_scons/boards/discovery2.py index 7ee701a43..e3924449f 100644 --- a/core/site_scons/boards/discovery2.py +++ b/core/site_scons/boards/discovery2.py @@ -94,4 +94,7 @@ def configure( env.get("ENV")["MCU_TYPE"] = mcu env.get("ENV")["LINKER_SCRIPT"] = linker_script + defs = env.get("CPPDEFINES_IMPLICIT") + defs += ["__ARM_FEATURE_CMSE=3"] + return features_available diff --git a/core/site_scons/boards/trezor_t3t1_v4.py b/core/site_scons/boards/trezor_t3t1_v4.py index 1a3b314d4..391f47f7a 100644 --- a/core/site_scons/boards/trezor_t3t1_v4.py +++ b/core/site_scons/boards/trezor_t3t1_v4.py @@ -100,4 +100,7 @@ def configure( env.get("ENV")["MCU_TYPE"] = mcu env.get("ENV")["LINKER_SCRIPT"] = linker_script + defs = env.get("CPPDEFINES_IMPLICIT") + defs += ["__ARM_FEATURE_CMSE=3"] + return features_available