diff --git a/core/SConscript.boardloader b/core/SConscript.boardloader index e5d898cd63..8739c28b14 100644 --- a/core/SConscript.boardloader +++ b/core/SConscript.boardloader @@ -1,10 +1,11 @@ # pylint: disable=E0602 import os -import tools +import tools, models TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T') CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0)) +HW_REVISION = ARGUMENTS.get('HW_REVISION', None) NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1' if TREZOR_MODEL in ('1', ): @@ -95,7 +96,7 @@ env = Environment(ENV=os.environ, CPPDEFINES_IMPLICIT=[] ) -FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) +FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) FILE_SUFFIX= env.get('ENV')['SUFFIX'] LINKER_SCRIPT_SUFFIX= env.get('ENV')['LINKER_SCRIPT'] @@ -177,7 +178,7 @@ program_elf = env.Command( '$LINK -o $TARGET $CCFLAGS $CFLAGS $LINKFLAGS $SOURCES -lc_nano -lgcc', ) -BINARY_NAME = f"build/boardloader/boardloader-{tools.get_model_identifier(TREZOR_MODEL)}" +BINARY_NAME = f"build/boardloader/boardloader-{models.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 "" diff --git a/core/SConscript.bootloader b/core/SConscript.bootloader index 709743fe5e..6c3452fabd 100644 --- a/core/SConscript.bootloader +++ b/core/SConscript.bootloader @@ -1,12 +1,13 @@ # pylint: disable=E0602 import os -import tools +import tools, models TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T') CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0)) BOOTLOADER_QA = ARGUMENTS.get('BOOTLOADER_QA', '0') == '1' PRODUCTION = 0 if BOOTLOADER_QA else ARGUMENTS.get('PRODUCTION', '0') == '1' +HW_REVISION = ARGUMENTS.get('HW_REVISION', None) NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1' if TREZOR_MODEL in ('1', ): @@ -150,7 +151,7 @@ env = Environment( CPPDEFINES_IMPLICIT=[] ) -FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) +FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) FILE_SUFFIX= env.get('ENV')['SUFFIX'] LINKER_SCRIPT_SUFFIX= env.get('ENV')['LINKER_SCRIPT'] @@ -306,7 +307,7 @@ env.Depends(program_elf, rust) SUFFIX = '_qa' if BOOTLOADER_QA else '' -BINARY_NAME = f"build/bootloader/bootloader-{tools.get_model_identifier(TREZOR_MODEL)}{SUFFIX}" +BINARY_NAME = f"build/bootloader/bootloader-{models.get_model_identifier(TREZOR_MODEL)}{SUFFIX}" BINARY_NAME += "-" + tools.get_version('embed/bootloader/version.h') BINARY_NAME += "-" + tools.get_git_revision_short_hash() BINARY_NAME += "-dirty" if tools.get_git_modified() else "" diff --git a/core/SConscript.bootloader_ci b/core/SConscript.bootloader_ci index 63417a1172..0dca24c0fb 100644 --- a/core/SConscript.bootloader_ci +++ b/core/SConscript.bootloader_ci @@ -1,10 +1,11 @@ # pylint: disable=E0602 import os -import tools +import tools, models TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T') CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0)) +HW_REVISION = ARGUMENTS.get('HW_REVISION', None) NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1' if TREZOR_MODEL in ('1', 'DISC1', 'DISC2'): @@ -124,7 +125,7 @@ env = Environment( CPPDEFINES_IMPLICIT=[] ) -FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) +FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) FILE_SUFFIX= env.get('ENV')['SUFFIX'] LINKER_SCRIPT_SUFFIX= env.get('ENV')['LINKER_SCRIPT'] @@ -220,7 +221,7 @@ program_elf = env.Command( '$LINK -o $TARGET $CCFLAGS $CFLAGS $LINKFLAGS $SOURCES -lc_nano -lgcc', ) -BINARY_NAME = f"build/bootloader_ci/bootloader_ci-{tools.get_model_identifier(TREZOR_MODEL)}" +BINARY_NAME = f"build/bootloader_ci/bootloader_ci-{models.get_model_identifier(TREZOR_MODEL)}" BINARY_NAME += "-" + tools.get_version('embed/bootloader_ci/version.h') BINARY_NAME += "-" + tools.get_git_revision_short_hash() BINARY_NAME += "-dirty" if tools.get_git_modified() else "" diff --git a/core/SConscript.bootloader_emu b/core/SConscript.bootloader_emu index a87339c728..c290f72347 100644 --- a/core/SConscript.bootloader_emu +++ b/core/SConscript.bootloader_emu @@ -1,11 +1,11 @@ # pylint: disable=E0602 import os -import tools -import boards +import tools, models TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T') CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0)) +HW_REVISION = 'emulator' NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1' DMA2D = False @@ -237,8 +237,8 @@ elif TREZOR_MODEL in ('1',): else: raise ValueError('Unknown Trezor model') -MODEL_IDENTIFIER = tools.get_model_identifier(TREZOR_MODEL) -MODEL_AS_NUMBER = str(boards.get_hw_model_as_number(MODEL_IDENTIFIER)) +MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL) +MODEL_AS_NUMBER = str(models.get_hw_model_as_number(MODEL_IDENTIFIER)) ALLPATHS = ['embed/rust', 'embed/bootloader', diff --git a/core/SConscript.firmware b/core/SConscript.firmware index e47842a999..6a6afbc457 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -2,7 +2,7 @@ # fmt: off import os -import tools +import tools, models BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0') PRODUCTION = ARGUMENTS.get('PRODUCTION', '0') == '1' @@ -13,6 +13,7 @@ TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T') CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0)) PYOPT = ARGUMENTS.get('PYOPT', '1') DISABLE_OPTIGA = ARGUMENTS.get('DISABLE_OPTIGA', '0') == '1' +HW_REVISION = ARGUMENTS.get('HW_REVISION', None) THP = ARGUMENTS.get('THP', '0') == '1' # Trezor-Host Protocol NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1' @@ -432,7 +433,7 @@ env = Environment( CPPDEFINES_IMPLICIT=[] ) -FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) +FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) FILE_SUFFIX= env.get('ENV')['SUFFIX'] @@ -848,7 +849,7 @@ env.Append(LINKFLAGS=f' -L{RUST_LIBDIR}') env.Append(LINKFLAGS=f' -l{RUST_LIB}') -MODEL_IDENTIFIER = tools.get_model_identifier(TREZOR_MODEL) +MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL) BOOTLOADER_SUFFIX = MODEL_IDENTIFIER if BOOTLOADER_QA: BOOTLOADER_SUFFIX += '_qa' @@ -901,7 +902,7 @@ if CMAKELISTS != 0: env.Depends(program_elf, cmake_gen) env.Depends(program_elf, rust) -BINARY_NAME = f"build/firmware/firmware-{tools.get_model_identifier(TREZOR_MODEL)}" +BINARY_NAME = f"build/firmware/firmware-{models.get_model_identifier(TREZOR_MODEL)}" if not EVERYTHING: BINARY_NAME += "-btconly" BINARY_NAME += "-" + tools.get_version('embed/firmware/version.h') diff --git a/core/SConscript.prodtest b/core/SConscript.prodtest index a12714e873..087de05319 100644 --- a/core/SConscript.prodtest +++ b/core/SConscript.prodtest @@ -1,12 +1,13 @@ # pylint: disable=E0602 import os -import tools +import tools, models TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T') CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0)) PRODUCTION = ARGUMENTS.get('PRODUCTION', '0') == '1' BOOTLOADER_DEVEL = ARGUMENTS.get('BOOTLOADER_DEVEL', '0') == '1' +HW_REVISION = ARGUMENTS.get('HW_REVISION', None) if TREZOR_MODEL in ('DISC1', 'DISC2'): # skip prodtest build @@ -115,7 +116,7 @@ env = Environment( 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) +FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) FILE_SUFFIX= env.get('ENV')['SUFFIX'] LINKER_SCRIPT_SUFFIX= env.get('ENV')['LINKER_SCRIPT'] @@ -203,7 +204,7 @@ obj_program.extend(env.Object(source=SOURCE_MOD_CRYPTO, CCFLAGS='$CCFLAGS -ftriv obj_program.extend(env.Object(source=SOURCE_PRODTEST)) obj_program.extend(env.Object(source=SOURCE_HAL)) -MODEL_IDENTIFIER = tools.get_model_identifier(TREZOR_MODEL) +MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL) if (vh := ARGUMENTS.get("VENDOR_HEADER", None)): @@ -238,7 +239,7 @@ program_elf = env.Command( '$LINK -o $TARGET $CCFLAGS $CFLAGS $LINKFLAGS $SOURCES -lc_nano -lgcc', ) -BINARY_NAME = f"build/prodtest/prodtest-{tools.get_model_identifier(TREZOR_MODEL)}" +BINARY_NAME = f"build/prodtest/prodtest-{models.get_model_identifier(TREZOR_MODEL)}" BINARY_NAME += "-" + tools.get_version('embed/prodtest/version.h') BINARY_NAME += "-" + tools.get_git_revision_short_hash() BINARY_NAME += "-dirty" if tools.get_git_modified() else "" diff --git a/core/SConscript.reflash b/core/SConscript.reflash index 5312e6d1fc..8e739c14d1 100644 --- a/core/SConscript.reflash +++ b/core/SConscript.reflash @@ -1,10 +1,11 @@ # pylint: disable=E0602 import os -import tools +import tools, models TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T') CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0)) +HW_REVISION = ARGUMENTS.get('HW_REVISION', None) if TREZOR_MODEL in ('DISC1', 'DISC2'): # skip reflash build @@ -89,7 +90,7 @@ env = Environment( CPPDEFINES_IMPLICIT=[] ) -FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) +FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) FILE_SUFFIX= env.get('ENV')['SUFFIX'] LINKER_SCRIPT_SUFFIX= env.get('ENV')['LINKER_SCRIPT'] @@ -166,7 +167,7 @@ obj_program += env.Object(source=SOURCE_MOD_CRYPTO, CCFLAGS='$CCFLAGS -ftrivial- obj_program += env.Object(source=SOURCE_REFLASH) obj_program += env.Object(source=SOURCE_HAL) -MODEL_IDENTIFIER = tools.get_model_identifier(TREZOR_MODEL) +MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL) VENDORHEADER = f'embed/vendorheader/{MODEL_IDENTIFIER}/vendorheader_' + ('unsafe_signed_dev.bin' if ARGUMENTS.get('PRODUCTION', '0') == '0' else 'satoshilabs_signed_prod.bin') @@ -185,7 +186,7 @@ program_elf = env.Command( '$LINK -o $TARGET $CCFLAGS $CFLAGS $LINKFLAGS $SOURCES -lc_nano -lgcc', ) -BINARY_NAME = f"build/reflash/reflash-{tools.get_model_identifier(TREZOR_MODEL)}" +BINARY_NAME = f"build/reflash/reflash-{models.get_model_identifier(TREZOR_MODEL)}" BINARY_NAME += "-" + tools.get_version('embed/reflash/version.h') BINARY_NAME += "-" + tools.get_git_revision_short_hash() BINARY_NAME += "-dirty" if tools.get_git_modified() else "" diff --git a/core/SConscript.unix b/core/SConscript.unix index c2dfe80497..8924593e3c 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -2,7 +2,7 @@ # fmt: off import os -import tools +import tools, models BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0') EVERYTHING = BITCOIN_ONLY != '1' @@ -10,6 +10,7 @@ TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T') DMA2D = TREZOR_MODEL in ('T', 'T3T1') OPTIGA = TREZOR_MODEL in ('R', 'T3T1') CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0)) +HW_REVISION ='emulator' THP = ARGUMENTS.get('THP', '0') == '1' # Trezor-Host Protocol NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1' diff --git a/core/site_scons/boards/__init__.py b/core/site_scons/boards/__init__.py deleted file mode 100644 index a4b4c81dd1..0000000000 --- a/core/site_scons/boards/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -def get_hw_model_as_number(hw_model: str) -> int: - return int.from_bytes(hw_model.encode(), "little") diff --git a/core/site_scons/models/D001/__init__.py b/core/site_scons/models/D001/__init__.py new file mode 100644 index 0000000000..8110fbd075 --- /dev/null +++ b/core/site_scons/models/D001/__init__.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from typing import Optional + +from .discovery import configure + + +def configure_board( + revision: Optional[int | str], + features_wanted: list[str], + env: dict, # type: ignore + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], +): + return configure(env, features_wanted, defines, sources, paths) diff --git a/core/site_scons/boards/discovery.py b/core/site_scons/models/D001/discovery.py similarity index 97% rename from core/site_scons/boards/discovery.py rename to core/site_scons/models/D001/discovery.py index f06b4126ed..d9e3a9331d 100644 --- a/core/site_scons/boards/discovery.py +++ b/core/site_scons/models/D001/discovery.py @@ -1,7 +1,7 @@ from __future__ import annotations -from . import get_hw_model_as_number -from .stm32f4_common import stm32f4_common_files +from .. import get_hw_model_as_number +from ..stm32f4_common import stm32f4_common_files def configure( diff --git a/core/site_scons/models/D002/__init__.py b/core/site_scons/models/D002/__init__.py new file mode 100644 index 0000000000..87d5cc5c50 --- /dev/null +++ b/core/site_scons/models/D002/__init__.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from typing import Optional + +from .discovery2 import configure + + +def configure_board( + revision: Optional[int | str], + features_wanted: list[str], + env: dict, # type: ignore + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], +): + return configure(env, features_wanted, defines, sources, paths) diff --git a/core/site_scons/boards/discovery2.py b/core/site_scons/models/D002/discovery2.py similarity index 97% rename from core/site_scons/boards/discovery2.py rename to core/site_scons/models/D002/discovery2.py index fa9edeb4b5..c50cc834e8 100644 --- a/core/site_scons/boards/discovery2.py +++ b/core/site_scons/models/D002/discovery2.py @@ -1,7 +1,7 @@ from __future__ import annotations -from . import get_hw_model_as_number -from .stm32u5_common import stm32u5_common_files +from .. import get_hw_model_as_number +from ..stm32u5_common import stm32u5_common_files def configure( diff --git a/core/site_scons/models/T1B1/__init__.py b/core/site_scons/models/T1B1/__init__.py new file mode 100644 index 0000000000..9bc4544bfb --- /dev/null +++ b/core/site_scons/models/T1B1/__init__.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from typing import Optional + +from .trezor_1 import configure + + +def configure_board( + revision: Optional[int | str], + features_wanted: list[str], + env: dict, # type: ignore + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], +): + return configure(env, features_wanted, defines, sources, paths) diff --git a/core/site_scons/boards/trezor_1.py b/core/site_scons/models/T1B1/trezor_1.py similarity index 94% rename from core/site_scons/boards/trezor_1.py rename to core/site_scons/models/T1B1/trezor_1.py index 8c565383f0..2fcdf6e284 100644 --- a/core/site_scons/boards/trezor_1.py +++ b/core/site_scons/models/T1B1/trezor_1.py @@ -1,7 +1,7 @@ from __future__ import annotations -from . import get_hw_model_as_number -from .stm32f4_common import stm32f4_common_files +from .. import get_hw_model_as_number +from ..stm32f4_common import stm32f4_common_files def configure( diff --git a/core/site_scons/models/T2B1/__init__.py b/core/site_scons/models/T2B1/__init__.py new file mode 100644 index 0000000000..675c9dbffa --- /dev/null +++ b/core/site_scons/models/T2B1/__init__.py @@ -0,0 +1,29 @@ +from __future__ import annotations + +from typing import Optional + +from .trezor_r_v3 import configure as configure_r3 +from .trezor_r_v4 import configure as configure_r4 +from .trezor_r_v6 import configure as configure_r6 +from .trezor_r_v10 import configure as configure_r10 + + +def configure_board( + revision: Optional[int | str], + features_wanted: list[str], + env: dict, # type: ignore + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], +): + if revision is None: + revision = 10 + if revision == 3: + return configure_r3(env, features_wanted, defines, sources, paths) + elif revision == 4: + return configure_r4(env, features_wanted, defines, sources, paths) + elif revision == 6: + return configure_r6(env, features_wanted, defines, sources, paths) + elif revision == 10: + return configure_r10(env, features_wanted, defines, sources, paths) + raise Exception("Unknown model_r_version") diff --git a/core/site_scons/boards/trezor_r_v10.py b/core/site_scons/models/T2B1/trezor_r_v10.py similarity index 97% rename from core/site_scons/boards/trezor_r_v10.py rename to core/site_scons/models/T2B1/trezor_r_v10.py index 96be803d47..3327af4a26 100644 --- a/core/site_scons/boards/trezor_r_v10.py +++ b/core/site_scons/models/T2B1/trezor_r_v10.py @@ -1,7 +1,7 @@ from __future__ import annotations -from . import get_hw_model_as_number -from .stm32f4_common import stm32f4_common_files +from .. import get_hw_model_as_number +from ..stm32f4_common import stm32f4_common_files def configure( diff --git a/core/site_scons/boards/trezor_r_v3.py b/core/site_scons/models/T2B1/trezor_r_v3.py similarity index 96% rename from core/site_scons/boards/trezor_r_v3.py rename to core/site_scons/models/T2B1/trezor_r_v3.py index 15546db251..4cd7a6adfd 100644 --- a/core/site_scons/boards/trezor_r_v3.py +++ b/core/site_scons/models/T2B1/trezor_r_v3.py @@ -1,7 +1,7 @@ from __future__ import annotations -from . import get_hw_model_as_number -from .stm32f4_common import stm32f4_common_files +from .. import get_hw_model_as_number +from ..stm32f4_common import stm32f4_common_files def configure( diff --git a/core/site_scons/boards/trezor_r_v4.py b/core/site_scons/models/T2B1/trezor_r_v4.py similarity index 96% rename from core/site_scons/boards/trezor_r_v4.py rename to core/site_scons/models/T2B1/trezor_r_v4.py index 0df0131c63..90bf5d12dc 100644 --- a/core/site_scons/boards/trezor_r_v4.py +++ b/core/site_scons/models/T2B1/trezor_r_v4.py @@ -1,7 +1,7 @@ from __future__ import annotations -from . import get_hw_model_as_number -from .stm32f4_common import stm32f4_common_files +from .. import get_hw_model_as_number +from ..stm32f4_common import stm32f4_common_files def configure( diff --git a/core/site_scons/boards/trezor_r_v6.py b/core/site_scons/models/T2B1/trezor_r_v6.py similarity index 96% rename from core/site_scons/boards/trezor_r_v6.py rename to core/site_scons/models/T2B1/trezor_r_v6.py index 29a8f2af68..db2f8ff484 100644 --- a/core/site_scons/boards/trezor_r_v6.py +++ b/core/site_scons/models/T2B1/trezor_r_v6.py @@ -1,7 +1,7 @@ from __future__ import annotations -from . import get_hw_model_as_number -from .stm32f4_common import stm32f4_common_files +from .. import get_hw_model_as_number +from ..stm32f4_common import stm32f4_common_files def configure( diff --git a/core/site_scons/models/T2T1/__init__.py b/core/site_scons/models/T2T1/__init__.py new file mode 100644 index 0000000000..623b0651a7 --- /dev/null +++ b/core/site_scons/models/T2T1/__init__.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from typing import Optional + +from .trezor_t import configure + + +def configure_board( + revision: Optional[int | str], + features_wanted: list[str], + env: dict, # type: ignore + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], +): + return configure(env, features_wanted, defines, sources, paths) diff --git a/core/site_scons/boards/trezor_t.py b/core/site_scons/models/T2T1/trezor_t.py similarity index 97% rename from core/site_scons/boards/trezor_t.py rename to core/site_scons/models/T2T1/trezor_t.py index b038cc356d..ef675f7e40 100644 --- a/core/site_scons/boards/trezor_t.py +++ b/core/site_scons/models/T2T1/trezor_t.py @@ -1,7 +1,7 @@ from __future__ import annotations -from . import get_hw_model_as_number -from .stm32f4_common import stm32f4_common_files +from .. import get_hw_model_as_number +from ..stm32f4_common import stm32f4_common_files def configure( diff --git a/core/site_scons/models/T3T1/__init__.py b/core/site_scons/models/T3T1/__init__.py new file mode 100644 index 0000000000..2b968aca04 --- /dev/null +++ b/core/site_scons/models/T3T1/__init__.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from typing import Optional + +from .trezor_t3t1_revE import configure as configure_revE +from .trezor_t3t1_v4 import configure as configure_v4 + + +def configure_board( + revision: Optional[int | str], + features_wanted: list[str], + env: dict, # type: ignore + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], +): + if revision is None: + revision = "E" + if revision == 4: + return configure_v4(env, features_wanted, defines, sources, paths) + elif revision == "E": + return configure_revE(env, features_wanted, defines, sources, paths) + raise Exception("Unknown model_t3t1_version") diff --git a/core/site_scons/boards/trezor_t3t1_revE.py b/core/site_scons/models/T3T1/trezor_t3t1_revE.py similarity index 98% rename from core/site_scons/boards/trezor_t3t1_revE.py rename to core/site_scons/models/T3T1/trezor_t3t1_revE.py index e422eac2df..f1a4beabcb 100644 --- a/core/site_scons/boards/trezor_t3t1_revE.py +++ b/core/site_scons/models/T3T1/trezor_t3t1_revE.py @@ -1,7 +1,7 @@ from __future__ import annotations -from . import get_hw_model_as_number -from .stm32u5_common import stm32u5_common_files +from .. import get_hw_model_as_number +from ..stm32u5_common import stm32u5_common_files def configure( diff --git a/core/site_scons/boards/trezor_t3t1_v4.py b/core/site_scons/models/T3T1/trezor_t3t1_v4.py similarity index 98% rename from core/site_scons/boards/trezor_t3t1_v4.py rename to core/site_scons/models/T3T1/trezor_t3t1_v4.py index e9e169cfa1..c40435b595 100644 --- a/core/site_scons/boards/trezor_t3t1_v4.py +++ b/core/site_scons/models/T3T1/trezor_t3t1_v4.py @@ -1,7 +1,7 @@ from __future__ import annotations -from . import get_hw_model_as_number -from .stm32u5_common import stm32u5_common_files +from .. import get_hw_model_as_number +from ..stm32u5_common import stm32u5_common_files def configure( diff --git a/core/site_scons/models/__init__.py b/core/site_scons/models/__init__.py new file mode 100644 index 0000000000..1703168f67 --- /dev/null +++ b/core/site_scons/models/__init__.py @@ -0,0 +1,40 @@ +from __future__ import annotations + +import importlib +from typing import Optional + + +def get_hw_model_as_number(hw_model: str) -> int: + return int.from_bytes(hw_model.encode(), "little") + + +def configure_board( + model: str, + revision: Optional[str | int], + features_wanted: list[str], + env: dict, # type: ignore + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], +) -> list[str]: + imported_module = importlib.import_module("models." + get_model_identifier(model)) + return imported_module.configure_board( + revision, features_wanted, env, defines, sources, paths + ) + + +def get_model_identifier(model: str) -> str: + if model == "1": + return "T1B1" + elif model == "T": + return "T2T1" + elif model == "R": + return "T2B1" + elif model == "T3T1": + return "T3T1" + elif model == "DISC1": + return "D001" + elif model == "DISC2": + return "D002" + else: + raise Exception("Unknown model") diff --git a/core/site_scons/boards/stm32f4_common.py b/core/site_scons/models/stm32f4_common.py similarity index 100% rename from core/site_scons/boards/stm32f4_common.py rename to core/site_scons/models/stm32f4_common.py diff --git a/core/site_scons/boards/stm32u5_common.py b/core/site_scons/models/stm32u5_common.py similarity index 100% rename from core/site_scons/boards/stm32u5_common.py rename to core/site_scons/models/stm32u5_common.py diff --git a/core/site_scons/tools.py b/core/site_scons/tools.py index e069c20e5b..315ca5cef7 100644 --- a/core/site_scons/tools.py +++ b/core/site_scons/tools.py @@ -4,19 +4,6 @@ import subprocess import zlib from pathlib import Path -from boards import ( - discovery, - discovery2, - trezor_1, - trezor_r_v3, - trezor_r_v4, - trezor_r_v6, - trezor_r_v10, - trezor_t, - trezor_t3t1_revE, - trezor_t3t1_v4, -) - HERE = Path(__file__).parent.resolve() # go up from site_scons to core/ @@ -37,65 +24,6 @@ def add_font( sources.append(sourcefile) -def configure_board( - model: str, - features_wanted: list[str], - env: dict, # type: ignore - defines: list[str | tuple[str, str]], - sources: list[str], - paths: list[str], -) -> list[str]: - model_r_version = 10 - model_t3t1_version = "E" - - if model in ("1",): - return trezor_1.configure(env, features_wanted, defines, sources, paths) - elif model in ("T",): - return trezor_t.configure(env, features_wanted, defines, sources, paths) - elif model in ("R",): - if model_r_version == 3: - return trezor_r_v3.configure(env, features_wanted, defines, sources, paths) - elif model_r_version == 4: - return trezor_r_v4.configure(env, features_wanted, defines, sources, paths) - elif model_r_version == 6: - return trezor_r_v6.configure(env, features_wanted, defines, sources, paths) - elif model_r_version == 10: - return trezor_r_v10.configure(env, features_wanted, defines, sources, paths) - raise Exception("Unknown model_r_version") - elif model in ("T3T1",): - if model_t3t1_version == 4: - return trezor_t3t1_v4.configure( - env, features_wanted, defines, sources, paths - ) - elif model_t3t1_version == "E": - return trezor_t3t1_revE.configure( - env, features_wanted, defines, sources, paths - ) - raise Exception("Unknown model_t3t1_version") - elif model in ("DISC1",): - return discovery.configure(env, features_wanted, defines, sources, paths) - elif model in ("DISC2",): - return discovery2.configure(env, features_wanted, defines, sources, paths) - raise Exception("Unknown model") - - -def get_model_identifier(model: str) -> str: - if model == "1": - return "T1B1" - elif model == "T": - return "T2T1" - elif model == "R": - return "T2B1" - elif model == "T3T1": - return "T3T1" - elif model == "DISC1": - return "D001" - elif model == "DISC2": - return "D002" - else: - raise Exception("Unknown model") - - def get_version(file: str) -> str: major = 0 minor = 0