1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-26 15:20:58 +00:00

fixup! wip

This commit is contained in:
Martin Milata 2025-01-08 22:56:10 +01:00
parent 3041bcd628
commit 526ad10810
21 changed files with 41 additions and 80 deletions

View File

@ -133,13 +133,13 @@ jobs:
strategy:
fail-fast: false
matrix:
model: ["1", T2T1, T2B1, T3B1, T3T1]
model: [T1B1, T2T1, T2B1, T3B1, T3T1]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git checkout ${{ github.head_ref || github.ref_name }}
- run: ./build-docker.sh ${{ matrix.model == '1' && '--skip-core' || '--skip-legacy' }} --models ${{ matrix.model }} --targets bootloader,firmware,prodtest ${{ github.head_ref || github.ref_name }}
- run: ./build-docker.sh ${{ matrix.model == 'T1B1' && '--skip-core' || '--skip-legacy' }} --models ${{ matrix.model }} --targets bootloader,firmware,prodtest ${{ github.head_ref || github.ref_name }}
- name: Show fingerprints
run: |
echo "model **${{ matrix.model }}** commit \`${{ github.sha }}\` (fingerprint, sha256)" >> $GITHUB_STEP_SUMMARY

View File

@ -65,7 +65,7 @@ jobs:
- model: T3W1
type: production
env:
TREZOR_MODEL: ${{ matrix.model == 'D001' && 'DISC1' || matrix.model }}
TREZOR_MODEL: ${{ matrix.model }}
BITCOIN_ONLY: ${{ matrix.coins == 'universal' && '0' || '1' }}
PYOPT: ${{ matrix.type == 'debuglink' && '0' || '1' }}
PRODUCTION: ${{ matrix.type == 'production' && '1' || '0' }}

View File

@ -324,6 +324,7 @@ for BITCOIN_ONLY in ${VARIANTS_legacy[@]}; do
DIRSUFFIX=${BITCOIN_ONLY/1/-bitcoinonly}
DIRSUFFIX=${DIRSUFFIX/0/}
DIRSUFFIX="-T1B1${DIRSUFFIX}"
SCRIPT_NAME=".build_legacy_$BITCOIN_ONLY.sh"
cat <<EOF > "build/$SCRIPT_NAME"

View File

@ -70,10 +70,10 @@ else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),T3W1))
MCU = STM32U5
OPENOCD_TARGET = target/stm32u5x.cfg
MODEL_FEATURE = model_ford
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),DISC1))
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),D001))
MCU = STM32F4
OPENOCD_TARGET = target/stm32f4x.cfg
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),DISC2))
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),D002))
MCU = STM32U5
OPENOCD_TARGET = target/stm32u5x.cfg
else

View File

@ -6,7 +6,6 @@ import tools, models
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T2T1')
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
FEATURES_WANTED = ["sd_card"]
@ -163,7 +162,7 @@ obj_program += env.Object(source=SOURCE_HAL)
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='boardloader')],
source=[f'embed/models/{TREZOR_MODEL}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='boardloader')],
action='$CAT $SOURCES > $TARGET',
)

View File

@ -9,7 +9,6 @@ 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)
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
FEATURES_WANTED = ["input", "rgb_led", "consumption_mask", "usb", "optiga", "dma2d"]
@ -246,7 +245,7 @@ obj_program += env.Object(source=SOURCE_HAL)
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='bootloader')],
source=[f'embed/models/{TREZOR_MODEL}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='bootloader')],
action='$CAT $SOURCES > $TARGET',
)

View File

@ -6,7 +6,6 @@ import tools, models, ui
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T2T1')
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
FEATURES_WANTED = ["input", "rgb_led", "consumption_mask", "usb", "optiga"]
@ -190,7 +189,7 @@ obj_program += env.Object(source=SOURCE_HAL)
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='bootloader')],
source=[f'embed/models/{TREZOR_MODEL}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='bootloader')],
action='$CAT $SOURCES > $TARGET',
)

View File

@ -151,8 +151,7 @@ env.Replace(
PYTHON='python',
MAKECMAKELISTS='$PYTHON tools/make_cmakelists.py', )
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
MODEL_AS_NUMBER = str(models.get_hw_model_as_number(MODEL_IDENTIFIER))
MODEL_AS_NUMBER = str(models.get_hw_model_as_number(TREZOR_MODEL))
ALLPATHS = ['embed/rust',
'embed/projects/bootloader',

View File

@ -18,7 +18,6 @@ DISABLE_OPTIGA = ARGUMENTS.get('DISABLE_OPTIGA', '0') == '1'
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
SCM_REVISION = ARGUMENTS.get('SCM_REVISION', None)
THP = ARGUMENTS.get('THP', '0') == '1' # Trezor-Host Protocol
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL) # TODO normalize always
BENCHMARK = ARGUMENTS.get('BENCHMARK', '0') == '1'
DISABLE_ANIMATION = ARGUMENTS.get('TREZOR_DISABLE_ANIMATION', '0') == '1'
@ -807,8 +806,7 @@ env.Append(LINKFLAGS=f' -L{RUST_LIBDIR}')
env.Append(LINKFLAGS=f' -l{RUST_LIB}')
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
BOOTLOADER_SUFFIX = MODEL_IDENTIFIER
BOOTLOADER_SUFFIX = TREZOR_MODEL
if BOOTLOADER_QA or BOOTLOADER_DEVEL:
BOOTLOADER_SUFFIX += '_qa'
@ -825,7 +823,7 @@ else:
else:
vendor = "trezor_signed_prod"
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/vendorheader_{vendor}.bin'
VENDORHEADER = f'embed/models/{TREZOR_MODEL}/vendorheader/vendorheader_{vendor}.bin'
tools.embed_raw_binary(
obj_program,
@ -849,7 +847,7 @@ env.Depends(obj_program, qstr_generated)
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='firmware')],
source=[f'embed/models/{TREZOR_MODEL}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='firmware')],
action='$CAT $SOURCES > $TARGET',
)
@ -866,7 +864,7 @@ if CMAKELISTS != 0:
env.Depends(program_elf, cmake_gen)
env.Depends(program_elf, rust)
BINARY_NAME = f"build/firmware/firmware-{MODEL_IDENTIFIER}"
BINARY_NAME = f"build/firmware/firmware-{TREZOR_MODEL}"
if not EVERYTHING:
BINARY_NAME += "-btconly"
BINARY_NAME += "-" + tools.get_version('embed/projects/firmware/version.h')

View File

@ -354,8 +354,7 @@ cmake_gen = env.Command(
action='$MAKECMAKELISTS --sources $ALLSOURCES --dirs $CPPPATH --defs $ALLDEFS',
)
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
BOOTLOADER_SUFFIX = MODEL_IDENTIFIER
BOOTLOADER_SUFFIX = TREZOR_MODEL
if BOOTLOADER_QA:
BOOTLOADER_SUFFIX += '_qa'
@ -372,7 +371,7 @@ else:
else:
vendor = "trezor_signed_prod"
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/vendorheader_{vendor}.bin'
VENDORHEADER = f'embed/models/{TREZOR_MODEL}/vendorheader/vendorheader_{vendor}.bin'
obj_program.extend(
@ -388,14 +387,14 @@ tools.embed_compressed_binary(
env,
'bootloader',
'embed/projects/bootloaders/bootloader.o',
f'embed/models/{MODEL_IDENTIFIER}/bootloaders/bootloader_{BOOTLOADER_SUFFIX}.bin',
f'embed/models/{TREZOR_MODEL}/bootloaders/bootloader_{BOOTLOADER_SUFFIX}.bin',
'kernel',
'bootloader',
)
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='kernel')],
source=[f'embed/models/{TREZOR_MODEL}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='kernel')],
action='$CAT $SOURCES > $TARGET',
)

View File

@ -185,8 +185,6 @@ 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 = models.get_model_identifier(TREZOR_MODEL)
if (vh := ARGUMENTS.get("VENDOR_HEADER", None)):
VENDORHEADER = vh
@ -195,13 +193,13 @@ elif (vh := os.environ.get("VENDOR_HEADER", None)):
# of vendor header which does not affect reproducibility of the build. Nonetheless,
# we should figure out a cleaner way to pass in this argument, without having to teach
# the Makefile about it.
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/{vh}'
VENDORHEADER = f'embed/models/{TREZOR_MODEL}/vendorheader/{vh}'
elif PRODUCTION:
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/vendorheader_prodtest_signed_prod.bin'
VENDORHEADER = f'embed/models/{TREZOR_MODEL}/vendorheader/vendorheader_prodtest_signed_prod.bin'
elif BOOTLOADER_DEVEL:
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/vendorheader_dev_DO_NOT_SIGN_signed_dev.bin'
VENDORHEADER = f'embed/models/{TREZOR_MODEL}/vendorheader/vendorheader_dev_DO_NOT_SIGN_signed_dev.bin'
else:
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/vendorheader_unsafe_signed_prod.bin'
VENDORHEADER = f'embed/models/{TREZOR_MODEL}/vendorheader/vendorheader_unsafe_signed_prod.bin'
tools.embed_raw_binary(
@ -214,7 +212,7 @@ tools.embed_raw_binary(
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='prodtest')],
source=[f'embed/models/{TREZOR_MODEL}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='prodtest')],
action='$CAT $SOURCES > $TARGET',
)

View File

@ -7,7 +7,7 @@ TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T2T1')
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
if TREZOR_MODEL in ('DISC1', 'DISC2'):
if TREZOR_MODEL in ('D001', 'D002'):
# skip reflash build
env = Environment()
def build_reflash(target,source,env):
@ -160,9 +160,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 = models.get_model_identifier(TREZOR_MODEL)
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/vendorheader_' + ('unsafe_signed_dev.bin' if ARGUMENTS.get('PRODUCTION', '0') == '0' else 'satoshilabs_signed_prod.bin')
VENDORHEADER = f'embed/models/{TREZOR_MODEL}/vendorheader/vendorheader_' + ('unsafe_signed_dev.bin' if ARGUMENTS.get('PRODUCTION', '0') == '0' else 'satoshilabs_signed_prod.bin')
tools.embed_raw_binary(
obj_program,
@ -174,7 +172,7 @@ tools.embed_raw_binary(
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='prodtest')],
source=[f'embed/models/{TREZOR_MODEL}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='prodtest')],
action='$CAT $SOURCES > $TARGET',
)

View File

@ -11,9 +11,9 @@
#include "T3B1/versions.h"
#elif defined TREZOR_MODEL_T3W1
#include "T3W1/versions.h"
#elif defined TREZOR_MODEL_DISC1
#elif defined TREZOR_MODEL_D001
#include "D001/versions.h"
#elif defined TREZOR_MODEL_DISC2
#elif defined TREZOR_MODEL_D002
#include "D002/versions.h"
#else
#error Unknown Trezor model

View File

@ -14,9 +14,9 @@
#include "T3B1/model_T3B1.h"
#elif defined TREZOR_MODEL_T3W1
#include "T3W1/model_T3W1.h"
#elif defined TREZOR_MODEL_DISC1
#elif defined TREZOR_MODEL_D001
#include "D001/model_D001.h"
#elif defined TREZOR_MODEL_DISC2
#elif defined TREZOR_MODEL_D002
#include "D002/model_D002.h"
#else
#error Unknown Trezor model

View File

@ -340,7 +340,7 @@ mpu_mode_t mpu_reconfig(mpu_mode_t mode) {
// clang-format off
switch (mode) {
#ifdef TREZOR_MODEL_DISC1
#ifdef TREZOR_MODEL_D001
default:
// All Peripherals (Unprivileged, Read-Write, Non-Executable)
// SDRAM

View File

@ -17,39 +17,22 @@ def configure_board(
sources: list[str],
paths: list[str],
) -> list[str]:
imported_module = importlib.import_module("models." + get_model_identifier(model))
imported_module = importlib.import_module(f"models.{model}")
return imported_module.configure_board(
revision, features_wanted, env, defines, sources, paths
)
def get_model_identifier(model: str) -> str:
if model == "T" or model == "T2T1":
return "T2T1"
elif model == "R" or model == "T2B1":
return "T2B1"
elif model == "T3T1":
return "T3T1"
elif model == "T3B1":
return "T3B1"
elif model == "DISC1":
return "D001"
elif model == "DISC2":
return "D002"
else:
return model
def has_emulator(model: str) -> bool:
imported_module = importlib.import_module("models." + get_model_identifier(model))
imported_module = importlib.import_module(f"models.{model}")
return hasattr(imported_module, "emulator")
def get_model_ui(model: str) -> str:
imported_module = importlib.import_module("models." + get_model_identifier(model))
imported_module = importlib.import_module(f"models.{model}")
return imported_module.get_model_ui()
def get_model_ui_conf(model: str) -> str:
imported_module = importlib.import_module("models." + get_model_identifier(model))
imported_module = importlib.import_module(f"models.{model}")
return imported_module.get_model_ui_conf()

View File

@ -67,14 +67,10 @@ def generate(env):
r"-e 's/from typing import/# \0/'",
]
MODEL_SYMS = {
"T": "T2T1",
"R": "T2B1",
"T3T1": "T3T1",
}
MODELS = ["T2T1", "T2B1", "T3T1", "T3B1", "T3W1"]
for model_sym, internal_model in MODEL_SYMS.items():
model_matches = env["TREZOR_MODEL"] == model_sym
for internal_model in MODELS:
model_matches = env["TREZOR_MODEL"] == internal_model
sed_scripts.extend(
(
rf"-e 's/utils\.INTERNAL_MODEL == \"{internal_model}\"/{model_matches}/g'",

View File

@ -7040,4 +7040,5 @@ def by_name(name: str) -> CoinInfo:
None, # confidential_assets
)
raise ValueError # Unknown coin name
print(f"unknown model {utils.INTERNAL_MODEL}")
raise ValueError # Unknown model

View File

@ -163,4 +163,5 @@ def by_name(name: str) -> CoinInfo:
% endfor
raise ValueError # Unknown coin name
% endfor
print(f"unknown model {utils.INTERNAL_MODEL}")
raise ValueError # Unknown model

View File

@ -55,7 +55,7 @@ class TestUtils(unittest.TestCase):
def test_firmware_hash(self):
if utils.INTERNAL_MODEL in ( # pylint: disable=internal-model-tuple-comparison
"DISC2",
"D002",
"T3W1",
):
self.assertEqual(

View File

@ -7,19 +7,9 @@ CORE = HERE.parent.parent
MODELS_DIR = CORE / "embed" / "models"
MODELS_DICT = {
"1": "T1B1",
"T": "T2T1",
"R": "T2B1",
"DISC1": "D001",
"DISC2": "D002",
}
def get_layout_for_model(model: str) -> Path:
model = MODELS_DICT.get(model, model)
return MODELS_DIR / model / f"model_{model}.h"
def get_linkerscript_for_model(model: str) -> Path:
model = MODELS_DICT.get(model, model)
return MODELS_DIR / model / f"memory.ld"