1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 12:28:09 +00:00

refactor(core): reorganize model specific files in site-scons

[no changelog]
This commit is contained in:
tychovrahe 2024-04-14 12:28:57 +02:00 committed by TychoVrahe
parent c9027b1a1a
commit e6f2fa711e
29 changed files with 209 additions and 120 deletions

View File

@ -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 ""

View File

@ -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 ""

View File

@ -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 ""

View File

@ -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',

View File

@ -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')

View File

@ -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 ""

View File

@ -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 ""

View File

@ -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'

View File

@ -1,2 +0,0 @@
def get_hw_model_as_number(hw_model: str) -> int:
return int.from_bytes(hw_model.encode(), "little")

View File

@ -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)

View File

@ -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(

View File

@ -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)

View File

@ -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(

View File

@ -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)

View File

@ -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(

View File

@ -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")

View File

@ -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(

View File

@ -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(

View File

@ -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(

View File

@ -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(

View File

@ -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)

View File

@ -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(

View File

@ -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")

View File

@ -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(

View File

@ -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(

View File

@ -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")

View File

@ -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