1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

build(core): improve CPPDEFINES quoting

Here we change all FOO=VALUE defines to be tuples ("FOO", "VALUE").
Also, VALUE is always the raw string you want to end up in the C file,
instead of attempting to shell-escape it while specifying.

By all rights scons _should_ be using shlex.quote() on the CPPDEFINES,
but it doesn't, so we hack it by specifying the define prefix as `-D'`
and suffix as `'`. That way the arguments in shell are '-escaped, and
we're (currently) not using ' in any argument value so this should work
fine.

At the same time, when passing the flags to cargo, we can shlex.quote
the whole thing and get the right strings passed all the way into
build.rs -- as long as no argument contains a comma, which is the split
character...
This commit is contained in:
matejcik 2024-11-21 11:55:05 +01:00 committed by cepetr
parent cd65ba52fe
commit b35854471b
25 changed files with 258 additions and 196 deletions

View File

@ -72,8 +72,10 @@ SOURCE_MOD += [
env = Environment(ENV=os.environ, env = Environment(ENV=os.environ,
CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')), CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')),
CONSTRAINTS=["limited_util_s"], CONSTRAINTS=["limited_util_s"],
CPPDEFINES_IMPLICIT=[] CPPDEFINES_IMPLICIT=[],
) CPPDEFPREFIX="-D'",
CPPDEFSUFFIX="'",
)
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, 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)

View File

@ -1,6 +1,7 @@
# pylint: disable=E0602 # pylint: disable=E0602
import os import os
import shlex
import tools, models, ui import tools, models, ui
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T') TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
@ -93,7 +94,9 @@ ui.init_ui(TREZOR_MODEL, "bootloader", CPPDEFINES_MOD, SOURCE_MOD, RUST_UI_FEATU
env = Environment( env = Environment(
ENV=os.environ, ENV=os.environ,
CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DBOOTLOADER_QA={int(BOOTLOADER_QA)}", CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DBOOTLOADER_QA={int(BOOTLOADER_QA)}",
CPPDEFINES_IMPLICIT=[] CPPDEFINES_IMPLICIT=[],
CPPDEFPREFIX="-D'",
CPPDEFSUFFIX="'",
) )
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, 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)
@ -217,7 +220,7 @@ def cargo_build():
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS) bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
build_dir = str(Dir('.').abspath) build_dir = str(Dir('.').abspath)
return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts) return f'export BINDGEN_MACROS={shlex.quote(bindgen_macros)}; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts)
rust = env.Command( rust = env.Command(
target=RUST_LIBPATH, target=RUST_LIBPATH,

View File

@ -86,9 +86,12 @@ SOURCE_NANOPB = [
ui.init_ui(TREZOR_MODEL, "bootloader", CPPDEFINES_MOD, SOURCE_MOD, RUST_UI_FEATURES) ui.init_ui(TREZOR_MODEL, "bootloader", CPPDEFINES_MOD, SOURCE_MOD, RUST_UI_FEATURES)
env = Environment( env = Environment(
ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')), ENV=os.environ,
CPPDEFINES_IMPLICIT=[] CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')),
) CPPDEFINES_IMPLICIT=[],
CPPDEFPREFIX="-D'",
CPPDEFSUFFIX="'",
)
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, 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)

View File

@ -1,6 +1,7 @@
# pylint: disable=E0602 # pylint: disable=E0602
import os import os
import shlex
import tools, models, ui import tools, models, ui
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T') TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
@ -127,7 +128,12 @@ SOURCE_UNIX = [
ui.init_ui(TREZOR_MODEL, "bootloader", CPPDEFINES_MOD, SOURCE_MOD, RUST_UI_FEATURES) ui.init_ui(TREZOR_MODEL, "bootloader", CPPDEFINES_MOD, SOURCE_MOD, RUST_UI_FEATURES)
env = Environment(ENV=os.environ, CFLAGS='%s -DCONFIDENTIAL= -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) env = Environment(
ENV=os.environ,
CFLAGS=ARGUMENTS.get('CFLAGS', '') + f" -DCONFIDENTIAL= -DPRODUCTION={ARGUMENTS.get('PRODUCTION', '0')}",
CPPDEFPREFIX="-D'",
CPPDEFSUFFIX="'",
)
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_UNIX, PATH_HAL) FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_UNIX, PATH_HAL)
@ -252,7 +258,7 @@ def cargo_build():
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS) bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
build_dir = str(Dir('.').abspath) build_dir = str(Dir('.').abspath)
return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build --profile {RUST_PROFILE} ' + ' '.join(cargo_opts) return f'export BINDGEN_MACROS={shlex.quote(bindgen_macros)}; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build --profile {RUST_PROFILE} ' + ' '.join(cargo_opts)
rust = env.Command( rust = env.Command(
target=RUST_LIBPATH, target=RUST_LIBPATH,

View File

@ -2,6 +2,7 @@
# fmt: off # fmt: off
import os import os
import shlex
import tools, models, ui import tools, models, ui
BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0') BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0')
@ -373,7 +374,9 @@ SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED
env = Environment( env = Environment(
ENV=os.environ, ENV=os.environ,
CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DPYOPT={PYOPT} -DBOOTLOADER_QA={int(BOOTLOADER_QA)} -DBITCOIN_ONLY={BITCOIN_ONLY}", CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DPYOPT={PYOPT} -DBOOTLOADER_QA={int(BOOTLOADER_QA)} -DBITCOIN_ONLY={BITCOIN_ONLY}",
CPPDEFINES_IMPLICIT=[] CPPDEFINES_IMPLICIT=[],
CPPDEFPREFIX="-D'",
CPPDEFSUFFIX="'",
) )
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, 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)
@ -770,7 +773,7 @@ def cargo_build():
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS) bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
build_dir = str(Dir('.').abspath) build_dir = str(Dir('.').abspath)
return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts) return f'export BINDGEN_MACROS={shlex.quote(bindgen_macros)}; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts)
rust = env.Command( rust = env.Command(
target=RUST_LIBPATH, target=RUST_LIBPATH,

View File

@ -239,8 +239,10 @@ if THP:
env = Environment( env = Environment(
ENV=os.environ, ENV=os.environ,
CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DPYOPT={PYOPT} -DBOOTLOADER_QA={int(BOOTLOADER_QA)} -DBITCOIN_ONLY={BITCOIN_ONLY}", CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DPYOPT={PYOPT} -DBOOTLOADER_QA={int(BOOTLOADER_QA)} -DBITCOIN_ONLY={BITCOIN_ONLY}",
CPPDEFINES_IMPLICIT=[] CPPDEFINES_IMPLICIT=[],
) CPPDEFPREFIX="-D'",
CPPDEFSUFFIX="'",
)
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, 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)

View File

@ -87,7 +87,10 @@ ui.init_ui(TREZOR_MODEL, "prodtest", CPPDEFINES_MOD, SOURCE_MOD, RUST_UI_FEATURE
env = Environment( env = Environment(
ENV=os.environ, ENV=os.environ,
CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')), CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')),
CPPDEFINES_IMPLICIT=[]) CPPDEFINES_IMPLICIT=[],
CPPDEFPREFIX="-D'",
CPPDEFSUFFIX="'",
)
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, 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)

View File

@ -73,8 +73,10 @@ ui.init_ui(TREZOR_MODEL, "prodtest", CPPDEFINES_MOD, SOURCE_MOD, RUST_UI_FEATURE
env = Environment( env = Environment(
ENV=os.environ, ENV=os.environ,
CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')), CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')),
CPPDEFINES_IMPLICIT=[] CPPDEFINES_IMPLICIT=[],
) CPPDEFPREFIX="-D'",
CPPDEFSUFFIX="'",
)
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, 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)

View File

@ -2,6 +2,7 @@
# fmt: off # fmt: off
import os import os
import shlex
import tools, models, ui import tools, models, ui
BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0') BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0')
@ -416,7 +417,12 @@ if PYOPT == '0' or not FROZEN:
else: else:
STATIC="" STATIC=""
env = Environment(ENV=os.environ, CFLAGS='%s -DCONFIDENTIAL= -DPYOPT=%s -DBITCOIN_ONLY=%s %s' % (ARGUMENTS.get('CFLAGS', ''), PYOPT, BITCOIN_ONLY, STATIC)) env = Environment(
ENV=os.environ,
CFLAGS=ARGUMENTS.get("CFLAGS", "") + f" -DCONFIDENTIAL= -DPYOPT={PYOPT} -DBITCOIN_ONLY={BITCOIN_ONLY} {STATIC}",
CPPDEFPREFIX="-D'",
CPPDEFSUFFIX="'",
)
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_UNIX, PATH_HAL) FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_UNIX, PATH_HAL)
@ -508,7 +514,7 @@ env.Replace(
CPPDEFINES=[ CPPDEFINES=[
'TREZOR_EMULATOR', 'TREZOR_EMULATOR',
'TREZOR_MODEL_'+TREZOR_MODEL, 'TREZOR_MODEL_'+TREZOR_MODEL,
('MP_CONFIGFILE', '\\"embed/projects/unix/mpconfigport.h\\"'), ('MP_CONFIGFILE', '"embed/projects/unix/mpconfigport.h"'),
ui.get_ui_layout(TREZOR_MODEL), ui.get_ui_layout(TREZOR_MODEL),
] + CPPDEFINES_MOD + CPPDEFINES_HAL, ] + CPPDEFINES_MOD + CPPDEFINES_HAL,
ASPPFLAGS='$CFLAGS $CCFLAGS', ) ASPPFLAGS='$CFLAGS $CCFLAGS', )
@ -830,7 +836,7 @@ def cargo_build():
bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS) bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
build_dir = str(Dir('.').abspath) build_dir = str(Dir('.').abspath)
return f'export BINDGEN_MACROS=\'{bindgen_macros}\'; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build --profile {RUST_PROFILE} --target-dir=../../build/unix/rust --no-default-features --features "{" ".join(features)}" --target {TARGET}' return f'export BINDGEN_MACROS={shlex.quote(bindgen_macros)}; export BUILD_DIR=\'{build_dir}\'; cd embed/rust; cargo build --profile {RUST_PROFILE} --target-dir=../../build/unix/rust --no-default-features --features "{" ".join(features)}" --target {TARGET}'
rust = env.Command( rust = env.Command(
target=RUST_LIBPATH, target=RUST_LIBPATH,

View File

@ -28,11 +28,14 @@ def configure(
] = "-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 " ] = "-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 "
env.get("ENV")["RUST_TARGET"] = "thumbv7em-none-eabihf" env.get("ENV")["RUST_TARGET"] = "thumbv7em-none-eabihf"
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={hw_revision}"] ("HW_MODEL", str(hw_model)),
defines += ["HSE_VALUE=8000000", "USE_HSE=1"] ("HW_REVISION", str(hw_revision)),
("HSE_VALUE", "8000000"),
("USE_HSE", "1"),
]
sources += [ sources += [
"embed/io/display/stm32f429i-disc1/display_driver.c", "embed/io/display/stm32f429i-disc1/display_driver.c",
@ -50,7 +53,7 @@ def configure(
"vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c" "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c"
] ]
defines += ["USE_DMA2D"] defines += ["USE_DMA2D"]
defines += ["USE_RGB_COLORS=1"] defines += [("USE_RGB_COLORS", "1")]
features_available.append("dma2d") features_available.append("dma2d")
defines += ["FRAMEBUFFER"] defines += ["FRAMEBUFFER"]
@ -60,7 +63,7 @@ def configure(
sources += ["embed/sys/sdram/stm32f429i-disc1/sdram_bsp.c"] sources += ["embed/sys/sdram/stm32f429i-disc1/sdram_bsp.c"]
paths += ["embed/sys/sdram/inc"] paths += ["embed/sys/sdram/inc"]
defines += ["USE_SDRAM=1"] defines += [("USE_SDRAM", "1")]
if "input" in features_wanted: if "input" in features_wanted:
sources += ["embed/io/i2c_bus/stm32f4/i2c_bus.c"] sources += ["embed/io/i2c_bus/stm32f4/i2c_bus.c"]
@ -68,8 +71,10 @@ def configure(
paths += ["embed/io/i2c_bus/inc"] paths += ["embed/io/i2c_bus/inc"]
paths += ["embed/io/touch/inc"] paths += ["embed/io/touch/inc"]
features_available.append("touch") features_available.append("touch")
defines += ["USE_TOUCH=1"] defines += [
defines += ["USE_I2C=1"] ("USE_TOUCH", "1"),
("USE_I2C", "1"),
]
if "usb" in features_wanted: if "usb" in features_wanted:
sources += [ sources += [
@ -86,6 +91,6 @@ def configure(
features_available.append("usb") features_available.append("usb")
paths += ["embed/io/usb/inc"] paths += ["embed/io/usb/inc"]
defines += ["USE_PVD=1"] defines += [("USE_PVD", "1")]
return features_available return features_available

View File

@ -29,11 +29,14 @@ def configure(
] = "-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mtune=cortex-m33 -mcmse " ] = "-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mtune=cortex-m33 -mcmse "
env.get("ENV")["RUST_TARGET"] = "thumbv8m.main-none-eabihf" env.get("ENV")["RUST_TARGET"] = "thumbv8m.main-none-eabihf"
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={hw_revision}"] ("HW_MODEL", str(hw_model)),
defines += ["HSE_VALUE=16000000", "USE_HSE=1"] ("HW_REVISION", str(hw_revision)),
("HSE_VALUE", "16000000"),
("USE_HSE", "1"),
]
sources += [ sources += [
"embed/io/display/stm32u5a9j-dk/display_driver.c", "embed/io/display/stm32u5a9j-dk/display_driver.c",
@ -48,8 +51,10 @@ def configure(
paths += ["embed/io/i2c_bus/inc"] paths += ["embed/io/i2c_bus/inc"]
paths += ["embed/io/touch/inc"] paths += ["embed/io/touch/inc"]
features_available.append("touch") features_available.append("touch")
defines += ["USE_TOUCH=1"] defines += [
defines += ["USE_I2C=1"] ("USE_TOUCH", "1"),
("USE_I2C", "1"),
]
if "usb" in features_wanted: if "usb" in features_wanted:
sources += [ sources += [
@ -68,8 +73,8 @@ def configure(
defines += [ defines += [
"USE_DMA2D", "USE_DMA2D",
"UI_COLOR_32BIT", ("UI_COLOR_32BIT", "1"),
"USE_RGB_COLORS", ("USE_RGB_COLORS", "1"),
] ]
sources += ["embed/gfx/bitblt/stm32/dma2d_bitblt.c"] sources += ["embed/gfx/bitblt/stm32/dma2d_bitblt.c"]

View File

@ -21,31 +21,33 @@ def configure(
features_available.append("framebuffer") features_available.append("framebuffer")
features_available.append("display_mono") features_available.append("display_mono")
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={hw_revision}"] ("HW_MODEL", str(hw_model)),
defines += [f"MCU_TYPE={mcu}"] ("HW_REVISION", str(hw_revision)),
defines += ["FLASH_BIT_ACCESS=1"] ("MCU_TYPE", mcu),
defines += ["FLASH_BLOCK_WORDS=1"] ("FLASH_BIT_ACCESS", "1"),
("FLASH_BLOCK_WORDS", "1"),
]
if "sbu" in features_wanted: if "sbu" in features_wanted:
sources += ["embed/io/sbu/unix/sbu.c"] sources += ["embed/io/sbu/unix/sbu.c"]
paths += ["embed/io/sbu/inc"] paths += ["embed/io/sbu/inc"]
defines += ["USE_SBU=1"] defines += [("USE_SBU", "1")]
if "optiga" in features_wanted: if "optiga" in features_wanted:
sources += ["embed/sec/optiga/unix/optiga_hal.c"] sources += ["embed/sec/optiga/unix/optiga_hal.c"]
sources += ["embed/sec/optiga/unix/optiga.c"] sources += ["embed/sec/optiga/unix/optiga.c"]
paths += ["embed/sec/optiga/inc"] paths += ["embed/sec/optiga/inc"]
features_available.append("optiga") features_available.append("optiga")
defines += ["USE_OPTIGA=1"] defines += [("USE_OPTIGA", "1")]
if "input" in features_wanted: if "input" in features_wanted:
sources += ["embed/io/button/unix/button.c"] sources += ["embed/io/button/unix/button.c"]
paths += ["embed/io/button/inc"] paths += ["embed/io/button/inc"]
features_available.append("button") features_available.append("button")
defines += ["USE_BUTTON=1"] defines += [("USE_BUTTON", "1")]
sources += ["embed/util/flash/stm32f4/flash_layout.c"] sources += ["embed/util/flash/stm32f4/flash_layout.c"]

View File

@ -32,11 +32,14 @@ def configure(
] = "-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 " ] = "-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 "
env.get("ENV")["RUST_TARGET"] = "thumbv7em-none-eabihf" env.get("ENV")["RUST_TARGET"] = "thumbv7em-none-eabihf"
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={hw_revision}"] ("HW_MODEL", str(hw_model)),
defines += ["HSE_VALUE=8000000", "USE_HSE=1"] ("HW_REVISION", str(hw_revision)),
("HSE_VALUE", "8000000"),
("USE_HSE", "1"),
]
sources += ["embed/io/display/vg-2864/display_driver.c"] sources += ["embed/io/display/vg-2864/display_driver.c"]
paths += ["embed/io/display/inc"] paths += ["embed/io/display/inc"]
@ -45,13 +48,13 @@ def configure(
sources += ["embed/io/button/stm32/button.c"] sources += ["embed/io/button/stm32/button.c"]
paths += ["embed/io/button/inc"] paths += ["embed/io/button/inc"]
features_available.append("button") features_available.append("button")
defines += ["USE_BUTTON=1"] defines += [("USE_BUTTON", "1")]
if "sbu" in features_wanted: if "sbu" in features_wanted:
sources += ["embed/io/sbu/stm32/sbu.c"] sources += ["embed/io/sbu/stm32/sbu.c"]
paths += ["embed/io/sbu/inc"] paths += ["embed/io/sbu/inc"]
features_available.append("sbu") features_available.append("sbu")
defines += ["USE_SBU=1"] defines += [("USE_SBU", "1")]
if "consumption_mask" in features_wanted: if "consumption_mask" in features_wanted:
sources += ["embed/sec/consumption_mask/stm32f4/consumption_mask.c"] sources += ["embed/sec/consumption_mask/stm32f4/consumption_mask.c"]
@ -59,7 +62,7 @@ def configure(
"vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c" "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c"
] ]
paths += ["embed/sec/consumption_mask/inc"] paths += ["embed/sec/consumption_mask/inc"]
defines += ["USE_CONSUMPTION_MASK=1"] defines += [("USE_CONSUMPTION_MASK", "1")]
if "usb" in features_wanted: if "usb" in features_wanted:
sources += [ sources += [
@ -86,9 +89,9 @@ def configure(
paths += ["embed/io/i2c_bus/inc"] paths += ["embed/io/i2c_bus/inc"]
paths += ["embed/sec/optiga/inc"] paths += ["embed/sec/optiga/inc"]
features_available.append("optiga") features_available.append("optiga")
defines += ["USE_OPTIGA=1"] defines += [("USE_OPTIGA", "1")]
defines += ["USE_I2C=1"] defines += [("USE_I2C", "1")]
defines += ["USE_PVD=1"] defines += [("USE_PVD", "1")]
return features_available return features_available

View File

@ -19,15 +19,17 @@ def configure(
defines += ["DISPLAY_RGB565"] defines += ["DISPLAY_RGB565"]
features_available.append("display_rgb565") features_available.append("display_rgb565")
defines += ["USE_RGB_COLORS"] defines += [("USE_RGB_COLORS", "1")]
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={hw_revision}"] ("HW_MODEL", str(hw_model)),
defines += [f"MCU_TYPE={mcu}"] ("HW_REVISION", str(hw_revision)),
defines += ["FLASH_BIT_ACCESS=1"] ("MCU_TYPE", mcu),
defines += ["FLASH_BLOCK_WORDS=1"] ("FLASH_BIT_ACCESS", "1"),
("FLASH_BLOCK_WORDS", "1"),
]
if "sd_card" in features_wanted: if "sd_card" in features_wanted:
features_available.append("sd_card") features_available.append("sd_card")
@ -37,21 +39,21 @@ def configure(
"embed/upymod/modtrezorio/ffunicode.c", "embed/upymod/modtrezorio/ffunicode.c",
] ]
paths += ["embed/io/sdcard/inc"] paths += ["embed/io/sdcard/inc"]
defines += ["USE_SD_CARD=1"] defines += [("USE_SD_CARD", "1")]
if "sbu" in features_wanted: if "sbu" in features_wanted:
sources += ["embed/io/sbu/unix/sbu.c"] sources += ["embed/io/sbu/unix/sbu.c"]
paths += ["embed/io/sbu/inc"] paths += ["embed/io/sbu/inc"]
defines += ["USE_SBU=1"] defines += [("USE_SBU", "1")]
if "input" in features_wanted: if "input" in features_wanted:
sources += ["embed/io/touch/unix/touch.c"] sources += ["embed/io/touch/unix/touch.c"]
paths += ["embed/io/touch/inc"] paths += ["embed/io/touch/inc"]
features_available.append("touch") features_available.append("touch")
defines += ["USE_TOUCH=1"] defines += [("USE_TOUCH", "1")]
features_available.append("backlight") features_available.append("backlight")
defines += ["USE_BACKLIGHT=1"] defines += [("USE_BACKLIGHT", "1")]
sources += ["embed/util/flash/stm32f4/flash_layout.c"] sources += ["embed/util/flash/stm32f4/flash_layout.c"]

View File

@ -18,7 +18,7 @@ def configure(
defines += ["DISPLAY_RGB565"] defines += ["DISPLAY_RGB565"]
features_available.append("display_rgb565") features_available.append("display_rgb565")
defines += ["USE_RGB_COLORS=1"] defines += [("USE_RGB_COLORS", "1")]
mcu = "STM32F427xx" mcu = "STM32F427xx"
@ -32,11 +32,14 @@ def configure(
] = "-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 " ] = "-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 "
env.get("ENV")["RUST_TARGET"] = "thumbv7em-none-eabihf" env.get("ENV")["RUST_TARGET"] = "thumbv7em-none-eabihf"
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={hw_revision}"] ("HW_MODEL", str(hw_model)),
defines += ["HSE_VALUE=8000000", "USE_HSE=1"] ("HW_REVISION", str(hw_revision)),
("HSE_VALUE", "8000000"),
("USE_HSE", "1"),
]
sources += ["embed/io/display/st-7789/display_nofb.c"] sources += ["embed/io/display/st-7789/display_nofb.c"]
sources += ["embed/io/display/st-7789/display_driver.c"] sources += ["embed/io/display/st-7789/display_driver.c"]
@ -51,7 +54,7 @@ def configure(
sources += ["embed/io/display/backlight/stm32/backlight_pwm.c"] sources += ["embed/io/display/backlight/stm32/backlight_pwm.c"]
features_available.append("backlight") features_available.append("backlight")
defines += ["USE_BACKLIGHT=1"] defines += [("USE_BACKLIGHT", "1")]
if "input" in features_wanted: if "input" in features_wanted:
sources += ["embed/io/i2c_bus/stm32f4/i2c_bus.c"] sources += ["embed/io/i2c_bus/stm32f4/i2c_bus.c"]
@ -59,8 +62,8 @@ def configure(
paths += ["embed/io/i2c_bus/inc"] paths += ["embed/io/i2c_bus/inc"]
paths += ["embed/io/touch/inc"] paths += ["embed/io/touch/inc"]
features_available.append("touch") features_available.append("touch")
defines += ["USE_TOUCH=1"] defines += [("USE_TOUCH", "1")]
defines += ["USE_I2C=1"] defines += [("USE_I2C", "1")]
if "sd_card" in features_wanted: if "sd_card" in features_wanted:
sources += ["embed/io/sdcard/stm32f4/sdcard.c"] sources += ["embed/io/sdcard/stm32f4/sdcard.c"]
@ -71,13 +74,13 @@ def configure(
] ]
paths += ["embed/io/sdcard/inc"] paths += ["embed/io/sdcard/inc"]
features_available.append("sd_card") features_available.append("sd_card")
defines += ["USE_SD_CARD=1"] defines += [("USE_SD_CARD", "1")]
if "sbu" in features_wanted: if "sbu" in features_wanted:
sources += ["embed/io/sbu/stm32/sbu.c"] sources += ["embed/io/sbu/stm32/sbu.c"]
paths += ["embed/io/sbu/inc"] paths += ["embed/io/sbu/inc"]
features_available.append("sbu") features_available.append("sbu")
defines += ["USE_SBU=1"] defines += [("USE_SBU", "1")]
if "usb" in features_wanted: if "usb" in features_wanted:
sources += [ sources += [
@ -102,6 +105,6 @@ def configure(
] ]
features_available.append("dma2d") features_available.append("dma2d")
defines += ["USE_PVD=1"] defines += [("USE_PVD", "1")]
return features_available return features_available

View File

@ -21,31 +21,33 @@ def configure(
features_available.append("framebuffer") features_available.append("framebuffer")
features_available.append("display_mono") features_available.append("display_mono")
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={hw_revision}"] ("HW_MODEL", str(hw_model)),
defines += [f"MCU_TYPE={mcu}"] ("HW_REVISION", str(hw_revision)),
defines += ["FLASH_BIT_ACCESS=1"] ("MCU_TYPE", mcu),
defines += ["FLASH_BLOCK_WORDS=1"] ("FLASH_BIT_ACCESS", "1"),
("FLASH_BLOCK_WORDS", "1"),
]
if "sbu" in features_wanted: if "sbu" in features_wanted:
sources += ["embed/io/sbu/unix/sbu.c"] sources += ["embed/io/sbu/unix/sbu.c"]
paths += ["embed/io/sbu/inc"] paths += ["embed/io/sbu/inc"]
defines += ["USE_SBU=1"] defines += [("USE_SBU", "1")]
if "optiga" in features_wanted: if "optiga" in features_wanted:
sources += ["embed/sec/optiga/unix/optiga_hal.c"] sources += ["embed/sec/optiga/unix/optiga_hal.c"]
sources += ["embed/sec/optiga/unix/optiga.c"] sources += ["embed/sec/optiga/unix/optiga.c"]
paths += ["embed/sec/optiga/inc"] paths += ["embed/sec/optiga/inc"]
features_available.append("optiga") features_available.append("optiga")
defines += ["USE_OPTIGA=1"] defines += [("USE_OPTIGA", "1")]
if "input" in features_wanted: if "input" in features_wanted:
sources += ["embed/io/button/unix/button.c"] sources += ["embed/io/button/unix/button.c"]
paths += ["embed/io/button/inc"] paths += ["embed/io/button/inc"]
features_available.append("button") features_available.append("button")
defines += ["USE_BUTTON=1"] defines += [("USE_BUTTON", "1")]
sources += ["embed/util/flash/stm32u5/flash_layout.c"] sources += ["embed/util/flash/stm32u5/flash_layout.c"]

View File

@ -14,7 +14,7 @@ def configure(
features_available: list[str] = [] features_available: list[str] = []
board = "T3B1/boards/trezor_t3b1_revB.h" board = "T3B1/boards/trezor_t3b1_revB.h"
hw_model = get_hw_model_as_number("T3B1") hw_model = get_hw_model_as_number("T3B1")
hw_revision = "B" hw_revision = ord("B")
defines += ["FRAMEBUFFER"] defines += ["FRAMEBUFFER"]
features_available.append("framebuffer") features_available.append("framebuffer")
@ -33,10 +33,12 @@ def configure(
] = "-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mtune=cortex-m33 -mcmse " ] = "-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mtune=cortex-m33 -mcmse "
env.get("ENV")["RUST_TARGET"] = "thumbv8m.main-none-eabihf" env.get("ENV")["RUST_TARGET"] = "thumbv8m.main-none-eabihf"
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={ord(hw_revision)}"] ("HW_MODEL", str(hw_model)),
("HW_REVISION", str(hw_revision)),
]
sources += ["embed/io/display/vg-2864/display_driver.c"] sources += ["embed/io/display/vg-2864/display_driver.c"]
paths += ["embed/io/display/inc"] paths += ["embed/io/display/inc"]
@ -45,13 +47,13 @@ def configure(
sources += ["embed/io/button/stm32/button.c"] sources += ["embed/io/button/stm32/button.c"]
paths += ["embed/io/button/inc"] paths += ["embed/io/button/inc"]
features_available.append("button") features_available.append("button")
defines += ["USE_BUTTON=1"] defines += [("USE_BUTTON", "1")]
if "sbu" in features_wanted: if "sbu" in features_wanted:
sources += ["embed/io/sbu/stm32/sbu.c"] sources += ["embed/io/sbu/stm32/sbu.c"]
paths += ["embed/io/sbu/inc"] paths += ["embed/io/sbu/inc"]
features_available.append("sbu") features_available.append("sbu")
defines += ["USE_SBU=1"] defines += [("USE_SBU", "1")]
if "usb" in features_wanted: if "usb" in features_wanted:
sources += [ sources += [
@ -78,22 +80,24 @@ def configure(
paths += ["embed/io/i2c_bus/inc"] paths += ["embed/io/i2c_bus/inc"]
paths += ["embed/sec/optiga/inc"] paths += ["embed/sec/optiga/inc"]
features_available.append("optiga") features_available.append("optiga")
defines += ["USE_OPTIGA=1"] defines += [
defines += ["USE_I2C=1"] ("USE_OPTIGA", "1"),
("USE_I2C", "1"),
]
if "consumption_mask" in features_wanted: if "consumption_mask" in features_wanted:
sources += ["embed/sec/consumption_mask/stm32u5/consumption_mask.c"] sources += ["embed/sec/consumption_mask/stm32u5/consumption_mask.c"]
paths += ["embed/sec/consumption_mask/inc"] paths += ["embed/sec/consumption_mask/inc"]
defines += ["USE_CONSUMPTION_MASK=1"] defines += [("USE_CONSUMPTION_MASK", "1")]
defines += [ defines += [
"USE_HASH_PROCESSOR=1", ("USE_HASH_PROCESSOR", "1"),
"USE_STORAGE_HWKEY=1", ("USE_STORAGE_HWKEY", "1"),
"USE_TAMPER=1", ("USE_TAMPER", "1"),
"USE_FLASH_BURST=1", ("USE_FLASH_BURST", "1"),
"USE_RESET_TO_BOOT=1", ("USE_RESET_TO_BOOT", "1"),
"USE_OEM_KEYS_CHECK=1", ("USE_OEM_KEYS_CHECK", "1"),
"USE_PVD=1", ("USE_PVD", "1"),
] ]
env.get("ENV")["TREZOR_BOARD"] = board env.get("ENV")["TREZOR_BOARD"] = board

View File

@ -20,16 +20,18 @@ def configure(
defines += ["FRAMEBUFFER", "DISPLAY_RGB565"] defines += ["FRAMEBUFFER", "DISPLAY_RGB565"]
features_available.append("framebuffer") features_available.append("framebuffer")
features_available.append("display_rgb565") features_available.append("display_rgb565")
defines += ["USE_RGB_COLORS=1"] defines += [("USE_RGB_COLORS", "1")]
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={hw_revision}"] ("HW_MODEL", str(hw_model)),
defines += [f"MCU_TYPE={mcu}"] ("HW_REVISION", str(hw_revision)),
("MCU_TYPE", mcu),
# todo change to blockwise flash when implemented in unix # todo change to blockwise flash when implemented in unix
defines += ["FLASH_BIT_ACCESS=1"] ("FLASH_BIT_ACCESS", "1"),
defines += ["FLASH_BLOCK_WORDS=1"] ("FLASH_BLOCK_WORDS", "1"),
]
if "sd_card" in features_wanted: if "sd_card" in features_wanted:
features_available.append("sd_card") features_available.append("sd_card")
@ -39,28 +41,28 @@ def configure(
"embed/upymod/modtrezorio/ffunicode.c", "embed/upymod/modtrezorio/ffunicode.c",
] ]
paths += ["embed/io/sdcard/inc"] paths += ["embed/io/sdcard/inc"]
defines += ["USE_SD_CARD=1"] defines += [("USE_SD_CARD", "1")]
if "sbu" in features_wanted: if "sbu" in features_wanted:
sources += ["embed/io/sbu/unix/sbu.c"] sources += ["embed/io/sbu/unix/sbu.c"]
paths += ["embed/io/sbu/inc"] paths += ["embed/io/sbu/inc"]
defines += ["USE_SBU=1"] defines += [("USE_SBU", "1")]
if "optiga" in features_wanted: if "optiga" in features_wanted:
sources += ["embed/sec/optiga/unix/optiga_hal.c"] sources += ["embed/sec/optiga/unix/optiga_hal.c"]
sources += ["embed/sec/optiga/unix/optiga.c"] sources += ["embed/sec/optiga/unix/optiga.c"]
paths += ["embed/sec/optiga/inc"] paths += ["embed/sec/optiga/inc"]
features_available.append("optiga") features_available.append("optiga")
defines += ["USE_OPTIGA=1"] defines += [("USE_OPTIGA", "1")]
if "input" in features_wanted: if "input" in features_wanted:
sources += ["embed/io/touch/unix/touch.c"] sources += ["embed/io/touch/unix/touch.c"]
paths += ["embed/io/touch/inc"] paths += ["embed/io/touch/inc"]
features_available.append("touch") features_available.append("touch")
defines += ["USE_TOUCH=1"] defines += [("USE_TOUCH", "1")]
features_available.append("backlight") features_available.append("backlight")
defines += ["USE_BACKLIGHT=1"] defines += [("USE_BACKLIGHT", "1")]
sources += ["embed/util/flash/stm32u5/flash_layout.c"] sources += ["embed/util/flash/stm32u5/flash_layout.c"]

View File

@ -18,9 +18,9 @@ def configure(
features_available.append("framebuffer") features_available.append("framebuffer")
features_available.append("display_rgb565") features_available.append("display_rgb565")
defines += ["DISPLAY_RGB565"] defines += [("DISPLAY_RGB565", "1")]
defines += ["FRAMEBUFFER"] defines += [("FRAMEBUFFER", "1")]
defines += ["USE_RGB_COLORS=1"] defines += [("USE_RGB_COLORS", "1")]
mcu = "STM32U585xx" mcu = "STM32U585xx"
linker_script = """embed/sys/linker/stm32u58/{target}.ld""" linker_script = """embed/sys/linker/stm32u58/{target}.ld"""
@ -35,10 +35,12 @@ def configure(
] = "-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mtune=cortex-m33 -mcmse " ] = "-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mtune=cortex-m33 -mcmse "
env.get("ENV")["RUST_TARGET"] = "thumbv8m.main-none-eabihf" env.get("ENV")["RUST_TARGET"] = "thumbv8m.main-none-eabihf"
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={hw_revision}"] ("HW_MODEL", str(hw_model)),
("HW_REVISION", str(hw_revision)),
]
sources += ["embed/io/display/st-7789/display_fb.c"] sources += ["embed/io/display/st-7789/display_fb.c"]
sources += ["embed/io/display/st-7789/display_driver.c"] sources += ["embed/io/display/st-7789/display_driver.c"]
@ -49,7 +51,7 @@ def configure(
sources += ["embed/io/display/backlight/stm32/backlight_pwm.c"] sources += ["embed/io/display/backlight/stm32/backlight_pwm.c"]
features_available.append("backlight") features_available.append("backlight")
defines += ["USE_BACKLIGHT=1"] defines += [("USE_BACKLIGHT", "1")]
env_constraints = env.get("CONSTRAINTS") env_constraints = env.get("CONSTRAINTS")
if not (env_constraints and "limited_util_s" in env_constraints): if not (env_constraints and "limited_util_s" in env_constraints):
@ -62,8 +64,8 @@ def configure(
paths += ["embed/io/i2c_bus/inc"] paths += ["embed/io/i2c_bus/inc"]
paths += ["embed/io/touch/inc"] paths += ["embed/io/touch/inc"]
features_available.append("touch") features_available.append("touch")
defines += ["USE_TOUCH=1"] defines += [("USE_TOUCH", "1")]
defines += ["USE_I2C=1"] defines += [("USE_I2C", "1")]
if "haptic" in features_wanted: if "haptic" in features_wanted:
sources += [ sources += [
@ -71,7 +73,7 @@ def configure(
] ]
paths += ["embed/io/haptic/inc"] paths += ["embed/io/haptic/inc"]
features_available.append("haptic") features_available.append("haptic")
defines += ["USE_HAPTIC=1"] defines += [("USE_HAPTIC", "1")]
if "sd_card" in features_wanted: if "sd_card" in features_wanted:
sources += ["embed/io/sdcard/stm32u5/sdcard.c"] sources += ["embed/io/sdcard/stm32u5/sdcard.c"]
@ -81,13 +83,13 @@ def configure(
sources += ["vendor/stm32u5xx_hal_driver/Src/stm32u5xx_ll_sdmmc.c"] sources += ["vendor/stm32u5xx_hal_driver/Src/stm32u5xx_ll_sdmmc.c"]
paths += ["embed/io/sdcard/inc"] paths += ["embed/io/sdcard/inc"]
features_available.append("sd_card") features_available.append("sd_card")
defines += ["USE_SD_CARD=1"] defines += [("USE_SD_CARD", "1")]
if "sbu" in features_wanted: if "sbu" in features_wanted:
sources += ["embed/io/sbu/stm32/sbu.c"] sources += ["embed/io/sbu/stm32/sbu.c"]
paths += ["embed/io/sbu/inc"] paths += ["embed/io/sbu/inc"]
features_available.append("sbu") features_available.append("sbu")
defines += ["USE_SBU=1"] defines += [("USE_SBU", "1")]
if "usb" in features_wanted: if "usb" in features_wanted:
sources += [ sources += [
@ -105,7 +107,7 @@ def configure(
paths += ["embed/io/usb/inc"] paths += ["embed/io/usb/inc"]
if "dma2d" in features_wanted: if "dma2d" in features_wanted:
defines += ["USE_DMA2D"] defines += [("USE_DMA2D", "1")]
sources += ["embed/gfx/bitblt/stm32/dma2d_bitblt.c"] sources += ["embed/gfx/bitblt/stm32/dma2d_bitblt.c"]
features_available.append("dma2d") features_available.append("dma2d")
@ -117,16 +119,16 @@ def configure(
sources += ["vendor/trezor-crypto/hash_to_curve.c"] sources += ["vendor/trezor-crypto/hash_to_curve.c"]
paths += ["embed/sec/optiga/inc"] paths += ["embed/sec/optiga/inc"]
features_available.append("optiga") features_available.append("optiga")
defines += ["USE_OPTIGA=1"] defines += [("USE_OPTIGA", "1")]
defines += [ defines += [
"USE_HASH_PROCESSOR=1", ("USE_HASH_PROCESSOR", "1"),
"USE_STORAGE_HWKEY=1", ("USE_STORAGE_HWKEY", "1"),
"USE_TAMPER=1", ("USE_TAMPER", "1"),
"USE_FLASH_BURST=1", ("USE_FLASH_BURST", "1"),
"USE_RESET_TO_BOOT=1", ("USE_RESET_TO_BOOT", "1"),
"USE_OEM_KEYS_CHECK=1", ("USE_OEM_KEYS_CHECK", "1"),
"USE_PVD=1", ("USE_PVD", "1"),
] ]
env.get("ENV")["TREZOR_BOARD"] = board env.get("ENV")["TREZOR_BOARD"] = board

View File

@ -21,37 +21,39 @@ def configure(
features_available.append("framebuffer") features_available.append("framebuffer")
features_available.append("display_rgba8888") features_available.append("display_rgba8888")
features_available.append("ui_color_32bit") features_available.append("ui_color_32bit")
defines += ["USE_RGB_COLORS=1"] defines += [("USE_RGB_COLORS", "1")]
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={hw_revision}"] ("HW_MODEL", str(hw_model)),
defines += [f"MCU_TYPE={mcu}"] ("HW_REVISION", str(hw_revision)),
("MCU_TYPE", mcu),
# todo change to blockwise flash when implemented in unix # todo change to blockwise flash when implemented in unix
defines += ["FLASH_BIT_ACCESS=1"] ("FLASH_BIT_ACCESS", "1"),
defines += ["FLASH_BLOCK_WORDS=1"] ("FLASH_BLOCK_WORDS", "1"),
]
if "sbu" in features_wanted: if "sbu" in features_wanted:
sources += ["embed/io/sbu/unix/sbu.c"] sources += ["embed/io/sbu/unix/sbu.c"]
paths += ["embed/io/sbu/inc"] paths += ["embed/io/sbu/inc"]
defines += ["USE_SBU=1"] defines += [("USE_SBU", "1")]
if "optiga" in features_wanted: if "optiga" in features_wanted:
sources += ["embed/sec/optiga/unix/optiga_hal.c"] sources += ["embed/sec/optiga/unix/optiga_hal.c"]
sources += ["embed/sec/optiga/unix/optiga.c"] sources += ["embed/sec/optiga/unix/optiga.c"]
paths += ["embed/sec/optiga/inc"] paths += ["embed/sec/optiga/inc"]
features_available.append("optiga") features_available.append("optiga")
defines += ["USE_OPTIGA=1"] defines += [("USE_OPTIGA", "1")]
if "input" in features_wanted: if "input" in features_wanted:
sources += ["embed/io/touch/unix/touch.c"] sources += ["embed/io/touch/unix/touch.c"]
paths += ["embed/io/touch/inc"] paths += ["embed/io/touch/inc"]
features_available.append("touch") features_available.append("touch")
defines += ["USE_TOUCH=1"] defines += [("USE_TOUCH", "1")]
features_available.append("backlight") features_available.append("backlight")
defines += ["USE_BACKLIGHT=1"] defines += [("USE_BACKLIGHT", "1")]
sources += ["embed/util/flash/stm32u5/flash_layout.c"] sources += ["embed/util/flash/stm32u5/flash_layout.c"]

View File

@ -29,11 +29,14 @@ def configure(
] = "-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mtune=cortex-m33 -mcmse " ] = "-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mtune=cortex-m33 -mcmse "
env.get("ENV")["RUST_TARGET"] = "thumbv8m.main-none-eabihf" env.get("ENV")["RUST_TARGET"] = "thumbv8m.main-none-eabihf"
defines += [mcu] defines += [
defines += [f'TREZOR_BOARD=\\"{board}\\"'] mcu,
defines += [f"HW_MODEL={hw_model}"] ("TREZOR_BOARD", f'"{board}"'),
defines += [f"HW_REVISION={hw_revision}"] ("HW_MODEL", str(hw_model)),
defines += ["HSE_VALUE=32000000", "USE_HSE=1"] ("HW_REVISION", str(hw_revision)),
("HSE_VALUE", "32000000"),
("USE_HSE", "1"),
]
sources += [ sources += [
"embed/io/display/st7785ma/display_driver.c", "embed/io/display/st7785ma/display_driver.c",
@ -42,7 +45,7 @@ def configure(
paths += ["embed/io/display/inc"] paths += ["embed/io/display/inc"]
features_available.append("backlight") features_available.append("backlight")
defines += ["USE_BACKLIGHT=1"] defines += [("USE_BACKLIGHT", "1")]
if "input" in features_wanted: if "input" in features_wanted:
sources += ["embed/io/i2c_bus/stm32u5/i2c_bus.c"] sources += ["embed/io/i2c_bus/stm32u5/i2c_bus.c"]
@ -54,9 +57,11 @@ def configure(
sources += ["embed/io/button/stm32/button.c"] sources += ["embed/io/button/stm32/button.c"]
paths += ["embed/io/button/inc"] paths += ["embed/io/button/inc"]
features_available.append("button") features_available.append("button")
defines += ["USE_TOUCH=1"] defines += [
defines += ["USE_I2C=1"] ("USE_TOUCH", "1"),
defines += ["USE_BUTTON=1"] ("USE_I2C", "1"),
("USE_BUTTON", "1"),
]
if "haptic" in features_wanted: if "haptic" in features_wanted:
sources += [ sources += [
@ -76,7 +81,7 @@ def configure(
# "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c" # "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c"
# ] # ]
# features_available.append("ble") # features_available.append("ble")
# defines += ["USE_BLE=1"] # defines += [("USE_BLE", "1")]
if "ble" in features_wanted: if "ble" in features_wanted:
sources += [ sources += [
@ -91,19 +96,19 @@ def configure(
sources += ["vendor/trezor-crypto/hash_to_curve.c"] sources += ["vendor/trezor-crypto/hash_to_curve.c"]
paths += ["embed/sec/optiga/inc"] paths += ["embed/sec/optiga/inc"]
features_available.append("optiga") features_available.append("optiga")
defines += ["USE_OPTIGA=1"] defines += [("USE_OPTIGA", "1")]
if "sbu" in features_wanted: if "sbu" in features_wanted:
sources += ["embed/io/sbu/stm32/sbu.c"] sources += ["embed/io/sbu/stm32/sbu.c"]
paths += ["embed/io/sbu/inc"] paths += ["embed/io/sbu/inc"]
features_available.append("sbu") features_available.append("sbu")
defines += ["USE_SBU=1"] defines += [("USE_SBU", "1")]
if "rgb_led" in features_wanted: if "rgb_led" in features_wanted:
sources += ["embed/io/rgb_led/stm32/rgb_led.c"] sources += ["embed/io/rgb_led/stm32/rgb_led.c"]
paths += ["embed/io/rgb_led/inc"] paths += ["embed/io/rgb_led/inc"]
features_available.append("rgb_led") features_available.append("rgb_led")
defines += ["USE_RGB_LED=1"] defines += [("USE_RGB_LED", "1")]
if "usb" in features_wanted: if "usb" in features_wanted:
sources += [ sources += [
@ -122,7 +127,7 @@ def configure(
defines += [ defines += [
"USE_DMA2D", "USE_DMA2D",
"USE_RGB_COLORS", ("USE_RGB_COLORS", "1"),
] ]
sources += ["embed/gfx/bitblt/stm32/dma2d_bitblt.c"] sources += ["embed/gfx/bitblt/stm32/dma2d_bitblt.c"]
@ -134,12 +139,12 @@ def configure(
features_available.append("display_rgb565") features_available.append("display_rgb565")
defines += [ defines += [
"USE_HASH_PROCESSOR=1", ("USE_HASH_PROCESSOR", "1"),
"USE_STORAGE_HWKEY=1", ("USE_STORAGE_HWKEY", "1"),
"USE_TAMPER=1", ("USE_TAMPER", "1"),
"USE_FLASH_BURST=1", ("USE_FLASH_BURST", "1"),
"USE_OEM_KEYS_CHECK=1", ("USE_OEM_KEYS_CHECK", "1"),
"USE_RESET_TO_BOOT=1", ("USE_RESET_TO_BOOT", "1"),
] ]
env.get("ENV")["LINKER_SCRIPT"] = linker_script env.get("ENV")["LINKER_SCRIPT"] = linker_script

View File

@ -3,7 +3,7 @@ from __future__ import annotations
def stm32f4_common_files(env, defines, sources, paths): def stm32f4_common_files(env, defines, sources, paths):
defines += [ defines += [
("STM32_HAL_H", '"<stm32f4xx.h>"'), ("STM32_HAL_H", "<stm32f4xx.h>"),
("FLASH_BLOCK_WORDS", "1"), ("FLASH_BLOCK_WORDS", "1"),
("FLASH_BIT_ACCESS", "1"), ("FLASH_BIT_ACCESS", "1"),
("CONFIDENTIAL", ""), ("CONFIDENTIAL", ""),

View File

@ -3,10 +3,10 @@ from __future__ import annotations
def stm32u5_common_files(env, defines, sources, paths): def stm32u5_common_files(env, defines, sources, paths):
defines += [ defines += [
("STM32_HAL_H", '"<stm32u5xx.h>"'), ("STM32_HAL_H", "<stm32u5xx.h>"),
("FLASH_BLOCK_WORDS", "4"), ("FLASH_BLOCK_WORDS", "4"),
("USE_TRUSTZONE", "1"), ("USE_TRUSTZONE", "1"),
("CONFIDENTIAL", "'__attribute__((section(\".confidential\")))'"), ("CONFIDENTIAL", '__attribute__((section(".confidential")))'),
] ]
paths += [ paths += [

View File

@ -63,21 +63,13 @@ def _compress(data: bytes) -> bytes:
return z.compress(data) + z.flush() return z.compress(data) + z.flush()
def get_bindgen_defines( def get_bindgen_defines(defines: list[str | tuple[str, str]], paths: list[str]) -> str:
defines: list[str | tuple[str, str]], paths: list[str]
) -> tuple(str, str):
rest_defs = [] rest_defs = []
for d in defines: for d in defines:
if type(d) is tuple: if type(d) is tuple:
d = f"-D{d[0]}={d[1]}" d = f"-D{d[0]}={d[1]}"
else: else:
d = f"-D{d}" d = f"-D{d}"
d = (
d.replace('\\"', '"')
.replace("'", "'\"'\"'")
.replace('"<', "<")
.replace('>"', ">")
)
rest_defs.append(d) rest_defs.append(d)
for d in paths: for d in paths:
rest_defs.append(f"-I../../{d}") rest_defs.append(f"-I../../{d}")

View File

@ -2,13 +2,16 @@ from __future__ import annotations
def add_font( def add_font(
font_name: str, font: str | None, defines: list[str], sources: list[str] font_name: str,
font: str | None,
defines: list[str | tuple[str, str]],
sources: list[str],
) -> None: ) -> None:
if font is not None: if font is not None:
font_filename = font.replace("_upper", "").lower() font_filename = font.replace("_upper", "").lower()
defines += [ defines += [
"TREZOR_FONT_" + font_name + "_ENABLE=" + font, (f"TREZOR_FONT_{font_name}_ENABLE", font),
"TREZOR_FONT_" + font_name + '_INCLUDE=\\"' + font_filename + '.h\\"', (f"TREZOR_FONT_{font_name}_INCLUDE", f'"{font_filename}.h"'),
] ]
sourcefile = "embed/gfx/fonts/" + font_filename + ".c" sourcefile = "embed/gfx/fonts/" + font_filename + ".c"
if sourcefile not in sources: if sourcefile not in sources: