mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-17 10:51:00 +00:00
chore(core): type and format the site_scons python helpers
[no changelog]
This commit is contained in:
parent
d888b21551
commit
d031be83e6
@ -1,3 +1,2 @@
|
||||
def get_hw_model_as_number(hw_model):
|
||||
return int.from_bytes(hw_model.encode(), 'little')
|
||||
|
||||
def get_hw_model_as_number(hw_model: str) -> int:
|
||||
return int.from_bytes(hw_model.encode(), "little")
|
||||
|
@ -1,22 +1,27 @@
|
||||
from . import get_hw_model_as_number
|
||||
|
||||
|
||||
def configure(env, features_wanted, defines, sources):
|
||||
features_available = []
|
||||
board = 'trezor_1.h'
|
||||
display = 'vg-2864ksweg01.c'
|
||||
hw_model = get_hw_model_as_number('T1B1')
|
||||
def configure(
|
||||
env: dict,
|
||||
features_wanted: list[str],
|
||||
defines: list[str | tuple[str, str]],
|
||||
sources: list[str],
|
||||
) -> list[str]:
|
||||
features_available: list[str] = []
|
||||
board = "trezor_1.h"
|
||||
display = "vg-2864ksweg01.c"
|
||||
hw_model = get_hw_model_as_number("T1B1")
|
||||
hw_revision = 0
|
||||
|
||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ]
|
||||
defines += [f'HW_MODEL={hw_model}', ]
|
||||
defines += [f'HW_REVISION={hw_revision}', ]
|
||||
sources += [f'embed/trezorhal/displays/{display}', ]
|
||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
|
||||
defines += [f"HW_MODEL={hw_model}"]
|
||||
defines += [f"HW_REVISION={hw_revision}"]
|
||||
sources += [f"embed/trezorhal/displays/{display}"]
|
||||
|
||||
if "input" in features_wanted:
|
||||
sources += ['embed/trezorhal/button.c']
|
||||
sources += ["embed/trezorhal/button.c"]
|
||||
features_available.append("button")
|
||||
|
||||
env.get('ENV')['TREZOR_BOARD'] = board
|
||||
env.get("ENV")["TREZOR_BOARD"] = board
|
||||
|
||||
return features_available
|
||||
|
@ -1,30 +1,35 @@
|
||||
from . import get_hw_model_as_number
|
||||
|
||||
|
||||
def configure(env, features_wanted, defines, sources):
|
||||
features_available = []
|
||||
hw_model = get_hw_model_as_number('T2B1')
|
||||
def configure(
|
||||
env: dict,
|
||||
features_wanted: list[str],
|
||||
defines: list[str | tuple[str, str]],
|
||||
sources: list[str],
|
||||
) -> list[str]:
|
||||
features_available: list[str] = []
|
||||
hw_model = get_hw_model_as_number("T2B1")
|
||||
hw_revision = 3
|
||||
board = 'trezor_r_v3.h'
|
||||
board = "trezor_r_v3.h"
|
||||
display = "ug-2828tswig01.c"
|
||||
|
||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ]
|
||||
defines += [f'HW_MODEL={hw_model}', ]
|
||||
defines += [f'HW_REVISION={hw_revision}', ]
|
||||
sources += [f'embed/trezorhal/displays/{display}', ]
|
||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
|
||||
defines += [f"HW_MODEL={hw_model}"]
|
||||
defines += [f"HW_REVISION={hw_revision}"]
|
||||
sources += [f"embed/trezorhal/displays/{display}"]
|
||||
|
||||
if "input" in features_wanted:
|
||||
sources += ['embed/trezorhal/button.c']
|
||||
sources += ["embed/trezorhal/button.c"]
|
||||
features_available.append("button")
|
||||
|
||||
if "rgb_led" in features_wanted:
|
||||
sources += ['embed/trezorhal/rgb_led.c']
|
||||
sources += ["embed/trezorhal/rgb_led.c"]
|
||||
features_available.append("rgb_led")
|
||||
|
||||
if "sbu" in features_wanted:
|
||||
sources += ['embed/trezorhal/sbu.c', ]
|
||||
sources += ["embed/trezorhal/sbu.c"]
|
||||
features_available.append("sbu")
|
||||
|
||||
env.get('ENV')['TREZOR_BOARD'] = board
|
||||
env.get("ENV")["TREZOR_BOARD"] = board
|
||||
|
||||
return features_available
|
||||
|
@ -1,26 +1,31 @@
|
||||
from . import get_hw_model_as_number
|
||||
|
||||
|
||||
def configure(env, features_wanted, defines, sources):
|
||||
features_available = []
|
||||
hw_model = get_hw_model_as_number('T2B1')
|
||||
def configure(
|
||||
env: dict,
|
||||
features_wanted: list[str],
|
||||
defines: list[str | tuple[str, str]],
|
||||
sources: list[str],
|
||||
) -> list[str]:
|
||||
features_available: list[str] = []
|
||||
hw_model = get_hw_model_as_number("T2B1")
|
||||
hw_revision = 4
|
||||
board = 'trezor_r_v4.h'
|
||||
display = 'vg-2864ksweg01.c'
|
||||
board = "trezor_r_v4.h"
|
||||
display = "vg-2864ksweg01.c"
|
||||
|
||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ]
|
||||
defines += [f'HW_MODEL={hw_model}', ]
|
||||
defines += [f'HW_REVISION={hw_revision}', ]
|
||||
sources += [f'embed/trezorhal/displays/{display}', ]
|
||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
|
||||
defines += [f"HW_MODEL={hw_model}"]
|
||||
defines += [f"HW_REVISION={hw_revision}"]
|
||||
sources += [f"embed/trezorhal/displays/{display}"]
|
||||
|
||||
if "input" in features_wanted:
|
||||
sources += ['embed/trezorhal/button.c']
|
||||
sources += ["embed/trezorhal/button.c"]
|
||||
features_available.append("button")
|
||||
|
||||
if "sbu" in features_wanted:
|
||||
sources += ['embed/trezorhal/sbu.c', ]
|
||||
sources += ["embed/trezorhal/sbu.c"]
|
||||
features_available.append("sbu")
|
||||
|
||||
env.get('ENV')['TREZOR_BOARD'] = board
|
||||
env.get("ENV")["TREZOR_BOARD"] = board
|
||||
|
||||
return features_available
|
||||
|
@ -1,26 +1,31 @@
|
||||
from . import get_hw_model_as_number
|
||||
|
||||
|
||||
def configure(env, features_wanted, defines, sources):
|
||||
features_available = []
|
||||
hw_model = get_hw_model_as_number('T2B1')
|
||||
def configure(
|
||||
env: dict,
|
||||
features_wanted: list[str],
|
||||
defines: list[str | tuple[str, str]],
|
||||
sources: list[str],
|
||||
) -> list[str]:
|
||||
features_available: list[str] = []
|
||||
hw_model = get_hw_model_as_number("T2B1")
|
||||
hw_revision = 6
|
||||
board = 'trezor_r_v6.h'
|
||||
display = 'vg-2864ksweg01.c'
|
||||
board = "trezor_r_v6.h"
|
||||
display = "vg-2864ksweg01.c"
|
||||
|
||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ]
|
||||
defines += [f'HW_MODEL={hw_model}', ]
|
||||
defines += [f'HW_REVISION={hw_revision}', ]
|
||||
sources += [f'embed/trezorhal/displays/{display}', ]
|
||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
|
||||
defines += [f"HW_MODEL={hw_model}"]
|
||||
defines += [f"HW_REVISION={hw_revision}"]
|
||||
sources += [f"embed/trezorhal/displays/{display}"]
|
||||
|
||||
if "input" in features_wanted:
|
||||
sources += ['embed/trezorhal/button.c']
|
||||
sources += ["embed/trezorhal/button.c"]
|
||||
features_available.append("button")
|
||||
|
||||
if "sbu" in features_wanted:
|
||||
sources += ['embed/trezorhal/sbu.c', ]
|
||||
sources += ["embed/trezorhal/sbu.c"]
|
||||
features_available.append("sbu")
|
||||
|
||||
env.get('ENV')['TREZOR_BOARD'] = board
|
||||
env.get("ENV")["TREZOR_BOARD"] = board
|
||||
|
||||
return features_available
|
||||
|
@ -1,35 +1,40 @@
|
||||
from . import get_hw_model_as_number
|
||||
|
||||
|
||||
def configure(env, features_wanted, defines, sources):
|
||||
features_available = []
|
||||
board = 'trezor_t.h'
|
||||
display = 'st7789v.c'
|
||||
hw_model = get_hw_model_as_number('T2T1')
|
||||
def configure(
|
||||
env: dict,
|
||||
features_wanted: list[str],
|
||||
defines: list[str | tuple[str, str]],
|
||||
sources: list[str],
|
||||
) -> list[str]:
|
||||
features_available: list[str] = []
|
||||
board = "trezor_t.h"
|
||||
display = "st7789v.c"
|
||||
hw_model = get_hw_model_as_number("T2T1")
|
||||
hw_revision = 0
|
||||
features_available.append("disp_i8080_8bit_dw")
|
||||
|
||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ]
|
||||
defines += [f'HW_MODEL={hw_model}', ]
|
||||
defines += [f'HW_REVISION={hw_revision}', ]
|
||||
sources += [f'embed/trezorhal/displays/{display}', ]
|
||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
|
||||
defines += [f"HW_MODEL={hw_model}"]
|
||||
defines += [f"HW_REVISION={hw_revision}"]
|
||||
sources += [f"embed/trezorhal/displays/{display}"]
|
||||
|
||||
if "input" in features_wanted:
|
||||
sources += ['embed/trezorhal/i2c.c', ]
|
||||
sources += ['embed/trezorhal/touch/touch.c', ]
|
||||
sources += ['embed/trezorhal/touch/ft6x36.c', ]
|
||||
sources += ["embed/trezorhal/i2c.c"]
|
||||
sources += ["embed/trezorhal/touch/touch.c"]
|
||||
sources += ["embed/trezorhal/touch/ft6x36.c"]
|
||||
features_available.append("touch")
|
||||
|
||||
if "sd_card" in features_wanted:
|
||||
sources += ['embed/trezorhal/sdcard.c', ]
|
||||
sources += ['embed/extmod/modtrezorio/ff.c', ]
|
||||
sources += ['embed/extmod/modtrezorio/ffunicode.c', ]
|
||||
sources += ["embed/trezorhal/sdcard.c"]
|
||||
sources += ["embed/extmod/modtrezorio/ff.c"]
|
||||
sources += ["embed/extmod/modtrezorio/ffunicode.c"]
|
||||
features_available.append("sd_card")
|
||||
|
||||
if "sbu" in features_wanted:
|
||||
sources += ['embed/trezorhal/sbu.c', ]
|
||||
sources += ["embed/trezorhal/sbu.c"]
|
||||
features_available.append("sbu")
|
||||
|
||||
env.get('ENV')['TREZOR_BOARD'] = board
|
||||
env.get("ENV")["TREZOR_BOARD"] = board
|
||||
|
||||
return features_available
|
||||
|
@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import subprocess
|
||||
@ -9,25 +11,33 @@ HERE = Path(__file__).parent.resolve()
|
||||
PROJECT_ROOT = HERE.parent.resolve()
|
||||
|
||||
|
||||
def add_font(font_name, font, defines, sources):
|
||||
def add_font(
|
||||
font_name: str, font: str | None, defines: list[str], sources: list[str]
|
||||
) -> None:
|
||||
if font is not None:
|
||||
defines += [
|
||||
'TREZOR_FONT_' + font_name + '_ENABLE=' + font,
|
||||
'TREZOR_FONT_' + font_name + '_INCLUDE=\\"' + font.lower() + '.h\\"',
|
||||
"TREZOR_FONT_" + font_name + "_ENABLE=" + font,
|
||||
"TREZOR_FONT_" + font_name + '_INCLUDE=\\"' + font.lower() + '.h\\"',
|
||||
]
|
||||
sourcefile = 'embed/lib/fonts/' + font.lower() + '.c'
|
||||
sourcefile = "embed/lib/fonts/" + font.lower() + ".c"
|
||||
if sourcefile not in sources:
|
||||
sources.append(sourcefile)
|
||||
|
||||
|
||||
def configure_board(model, features_wanted, env, defines, sources):
|
||||
def configure_board(
|
||||
model: str,
|
||||
features_wanted: list[str],
|
||||
env: dict, # type: ignore
|
||||
defines: list[str | tuple[str, str]],
|
||||
sources: list[str],
|
||||
):
|
||||
model_r_version = 6
|
||||
|
||||
if model in ('1',):
|
||||
if model in ("1",):
|
||||
return trezor_1.configure(env, features_wanted, defines, sources)
|
||||
elif model in ('T',):
|
||||
elif model in ("T",):
|
||||
return trezor_t.configure(env, features_wanted, defines, sources)
|
||||
elif model in ('R',):
|
||||
elif model in ("R",):
|
||||
if model_r_version == 3:
|
||||
return trezor_r_v3.configure(env, features_wanted, defines, sources)
|
||||
elif model_r_version == 4:
|
||||
@ -38,48 +48,57 @@ def configure_board(model, features_wanted, env, defines, sources):
|
||||
raise Exception("Unknown model")
|
||||
|
||||
|
||||
def get_model_identifier(model):
|
||||
if model == '1':
|
||||
def get_model_identifier(model: str) -> str:
|
||||
if model == "1":
|
||||
return "T1B1"
|
||||
elif model == 'T':
|
||||
elif model == "T":
|
||||
return "T2T1"
|
||||
elif model == 'R':
|
||||
elif model == "R":
|
||||
return "T2B1"
|
||||
else:
|
||||
raise Exception("Unknown model")
|
||||
|
||||
|
||||
def get_version(file):
|
||||
def get_version(file: str) -> str:
|
||||
major = 0
|
||||
minor = 0
|
||||
patch = 0
|
||||
|
||||
file = PROJECT_ROOT / file
|
||||
with open(file, 'r') as f:
|
||||
file_path = PROJECT_ROOT / file
|
||||
with open(file_path, "r") as f:
|
||||
for line in f:
|
||||
if line.startswith('#define VERSION_MAJOR '):
|
||||
major = line.split('VERSION_MAJOR')[1].strip()
|
||||
if line.startswith('#define VERSION_MINOR '):
|
||||
minor = line.split('VERSION_MINOR')[1].strip()
|
||||
if line.startswith('#define VERSION_PATCH '):
|
||||
patch = line.split('VERSION_PATCH')[1].strip()
|
||||
return f'{major}.{minor}.{patch}'
|
||||
if line.startswith("#define VERSION_MAJOR "):
|
||||
major = line.split("VERSION_MAJOR")[1].strip()
|
||||
if line.startswith("#define VERSION_MINOR "):
|
||||
minor = line.split("VERSION_MINOR")[1].strip()
|
||||
if line.startswith("#define VERSION_PATCH "):
|
||||
patch = line.split("VERSION_PATCH")[1].strip()
|
||||
return f"{major}.{minor}.{patch}"
|
||||
|
||||
|
||||
def get_git_revision_hash() -> str:
|
||||
return subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()
|
||||
return subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip()
|
||||
|
||||
|
||||
def get_git_revision_short_hash() -> str:
|
||||
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip()
|
||||
return (
|
||||
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
|
||||
.decode("ascii")
|
||||
.strip()
|
||||
)
|
||||
|
||||
|
||||
def get_git_modified() -> bool:
|
||||
return subprocess.check_output(['git', 'diff', '--name-status']).decode('ascii').strip() != ''
|
||||
return (
|
||||
subprocess.check_output(["git", "diff", "--name-status"])
|
||||
.decode("ascii")
|
||||
.strip()
|
||||
!= ""
|
||||
)
|
||||
|
||||
|
||||
def get_defs_for_cmake(defs):
|
||||
result = []
|
||||
def get_defs_for_cmake(defs: list[str | tuple[str, str]]) -> list[str]:
|
||||
result: list[str] = []
|
||||
for d in defs:
|
||||
if type(d) is tuple:
|
||||
result.append(d[0] + "=" + d[1])
|
||||
|
Loading…
Reference in New Issue
Block a user