mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-21 07:28:46 +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):
|
def get_hw_model_as_number(hw_model: str) -> int:
|
||||||
return int.from_bytes(hw_model.encode(), 'little')
|
return int.from_bytes(hw_model.encode(), "little")
|
||||||
|
|
||||||
|
@ -1,22 +1,27 @@
|
|||||||
from . import get_hw_model_as_number
|
from . import get_hw_model_as_number
|
||||||
|
|
||||||
|
|
||||||
def configure(env, features_wanted, defines, sources):
|
def configure(
|
||||||
features_available = []
|
env: dict,
|
||||||
board = 'trezor_1.h'
|
features_wanted: list[str],
|
||||||
display = 'vg-2864ksweg01.c'
|
defines: list[str | tuple[str, str]],
|
||||||
hw_model = get_hw_model_as_number('T1B1')
|
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
|
hw_revision = 0
|
||||||
|
|
||||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ]
|
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
|
||||||
defines += [f'HW_MODEL={hw_model}', ]
|
defines += [f"HW_MODEL={hw_model}"]
|
||||||
defines += [f'HW_REVISION={hw_revision}', ]
|
defines += [f"HW_REVISION={hw_revision}"]
|
||||||
sources += [f'embed/trezorhal/displays/{display}', ]
|
sources += [f"embed/trezorhal/displays/{display}"]
|
||||||
|
|
||||||
if "input" in features_wanted:
|
if "input" in features_wanted:
|
||||||
sources += ['embed/trezorhal/button.c']
|
sources += ["embed/trezorhal/button.c"]
|
||||||
features_available.append("button")
|
features_available.append("button")
|
||||||
|
|
||||||
env.get('ENV')['TREZOR_BOARD'] = board
|
env.get("ENV")["TREZOR_BOARD"] = board
|
||||||
|
|
||||||
return features_available
|
return features_available
|
||||||
|
@ -1,30 +1,35 @@
|
|||||||
from . import get_hw_model_as_number
|
from . import get_hw_model_as_number
|
||||||
|
|
||||||
|
|
||||||
def configure(env, features_wanted, defines, sources):
|
def configure(
|
||||||
features_available = []
|
env: dict,
|
||||||
hw_model = get_hw_model_as_number('T2B1')
|
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
|
hw_revision = 3
|
||||||
board = 'trezor_r_v3.h'
|
board = "trezor_r_v3.h"
|
||||||
display = "ug-2828tswig01.c"
|
display = "ug-2828tswig01.c"
|
||||||
|
|
||||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ]
|
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
|
||||||
defines += [f'HW_MODEL={hw_model}', ]
|
defines += [f"HW_MODEL={hw_model}"]
|
||||||
defines += [f'HW_REVISION={hw_revision}', ]
|
defines += [f"HW_REVISION={hw_revision}"]
|
||||||
sources += [f'embed/trezorhal/displays/{display}', ]
|
sources += [f"embed/trezorhal/displays/{display}"]
|
||||||
|
|
||||||
if "input" in features_wanted:
|
if "input" in features_wanted:
|
||||||
sources += ['embed/trezorhal/button.c']
|
sources += ["embed/trezorhal/button.c"]
|
||||||
features_available.append("button")
|
features_available.append("button")
|
||||||
|
|
||||||
if "rgb_led" in features_wanted:
|
if "rgb_led" in features_wanted:
|
||||||
sources += ['embed/trezorhal/rgb_led.c']
|
sources += ["embed/trezorhal/rgb_led.c"]
|
||||||
features_available.append("rgb_led")
|
features_available.append("rgb_led")
|
||||||
|
|
||||||
if "sbu" in features_wanted:
|
if "sbu" in features_wanted:
|
||||||
sources += ['embed/trezorhal/sbu.c', ]
|
sources += ["embed/trezorhal/sbu.c"]
|
||||||
features_available.append("sbu")
|
features_available.append("sbu")
|
||||||
|
|
||||||
env.get('ENV')['TREZOR_BOARD'] = board
|
env.get("ENV")["TREZOR_BOARD"] = board
|
||||||
|
|
||||||
return features_available
|
return features_available
|
||||||
|
@ -1,26 +1,31 @@
|
|||||||
from . import get_hw_model_as_number
|
from . import get_hw_model_as_number
|
||||||
|
|
||||||
|
|
||||||
def configure(env, features_wanted, defines, sources):
|
def configure(
|
||||||
features_available = []
|
env: dict,
|
||||||
hw_model = get_hw_model_as_number('T2B1')
|
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
|
hw_revision = 4
|
||||||
board = 'trezor_r_v4.h'
|
board = "trezor_r_v4.h"
|
||||||
display = 'vg-2864ksweg01.c'
|
display = "vg-2864ksweg01.c"
|
||||||
|
|
||||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ]
|
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
|
||||||
defines += [f'HW_MODEL={hw_model}', ]
|
defines += [f"HW_MODEL={hw_model}"]
|
||||||
defines += [f'HW_REVISION={hw_revision}', ]
|
defines += [f"HW_REVISION={hw_revision}"]
|
||||||
sources += [f'embed/trezorhal/displays/{display}', ]
|
sources += [f"embed/trezorhal/displays/{display}"]
|
||||||
|
|
||||||
if "input" in features_wanted:
|
if "input" in features_wanted:
|
||||||
sources += ['embed/trezorhal/button.c']
|
sources += ["embed/trezorhal/button.c"]
|
||||||
features_available.append("button")
|
features_available.append("button")
|
||||||
|
|
||||||
if "sbu" in features_wanted:
|
if "sbu" in features_wanted:
|
||||||
sources += ['embed/trezorhal/sbu.c', ]
|
sources += ["embed/trezorhal/sbu.c"]
|
||||||
features_available.append("sbu")
|
features_available.append("sbu")
|
||||||
|
|
||||||
env.get('ENV')['TREZOR_BOARD'] = board
|
env.get("ENV")["TREZOR_BOARD"] = board
|
||||||
|
|
||||||
return features_available
|
return features_available
|
||||||
|
@ -1,26 +1,31 @@
|
|||||||
from . import get_hw_model_as_number
|
from . import get_hw_model_as_number
|
||||||
|
|
||||||
|
|
||||||
def configure(env, features_wanted, defines, sources):
|
def configure(
|
||||||
features_available = []
|
env: dict,
|
||||||
hw_model = get_hw_model_as_number('T2B1')
|
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
|
hw_revision = 6
|
||||||
board = 'trezor_r_v6.h'
|
board = "trezor_r_v6.h"
|
||||||
display = 'vg-2864ksweg01.c'
|
display = "vg-2864ksweg01.c"
|
||||||
|
|
||||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ]
|
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
|
||||||
defines += [f'HW_MODEL={hw_model}', ]
|
defines += [f"HW_MODEL={hw_model}"]
|
||||||
defines += [f'HW_REVISION={hw_revision}', ]
|
defines += [f"HW_REVISION={hw_revision}"]
|
||||||
sources += [f'embed/trezorhal/displays/{display}', ]
|
sources += [f"embed/trezorhal/displays/{display}"]
|
||||||
|
|
||||||
if "input" in features_wanted:
|
if "input" in features_wanted:
|
||||||
sources += ['embed/trezorhal/button.c']
|
sources += ["embed/trezorhal/button.c"]
|
||||||
features_available.append("button")
|
features_available.append("button")
|
||||||
|
|
||||||
if "sbu" in features_wanted:
|
if "sbu" in features_wanted:
|
||||||
sources += ['embed/trezorhal/sbu.c', ]
|
sources += ["embed/trezorhal/sbu.c"]
|
||||||
features_available.append("sbu")
|
features_available.append("sbu")
|
||||||
|
|
||||||
env.get('ENV')['TREZOR_BOARD'] = board
|
env.get("ENV")["TREZOR_BOARD"] = board
|
||||||
|
|
||||||
return features_available
|
return features_available
|
||||||
|
@ -1,35 +1,40 @@
|
|||||||
from . import get_hw_model_as_number
|
from . import get_hw_model_as_number
|
||||||
|
|
||||||
|
|
||||||
def configure(env, features_wanted, defines, sources):
|
def configure(
|
||||||
features_available = []
|
env: dict,
|
||||||
board = 'trezor_t.h'
|
features_wanted: list[str],
|
||||||
display = 'st7789v.c'
|
defines: list[str | tuple[str, str]],
|
||||||
hw_model = get_hw_model_as_number('T2T1')
|
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
|
hw_revision = 0
|
||||||
features_available.append("disp_i8080_8bit_dw")
|
features_available.append("disp_i8080_8bit_dw")
|
||||||
|
|
||||||
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ]
|
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
|
||||||
defines += [f'HW_MODEL={hw_model}', ]
|
defines += [f"HW_MODEL={hw_model}"]
|
||||||
defines += [f'HW_REVISION={hw_revision}', ]
|
defines += [f"HW_REVISION={hw_revision}"]
|
||||||
sources += [f'embed/trezorhal/displays/{display}', ]
|
sources += [f"embed/trezorhal/displays/{display}"]
|
||||||
|
|
||||||
if "input" in features_wanted:
|
if "input" in features_wanted:
|
||||||
sources += ['embed/trezorhal/i2c.c', ]
|
sources += ["embed/trezorhal/i2c.c"]
|
||||||
sources += ['embed/trezorhal/touch/touch.c', ]
|
sources += ["embed/trezorhal/touch/touch.c"]
|
||||||
sources += ['embed/trezorhal/touch/ft6x36.c', ]
|
sources += ["embed/trezorhal/touch/ft6x36.c"]
|
||||||
features_available.append("touch")
|
features_available.append("touch")
|
||||||
|
|
||||||
if "sd_card" in features_wanted:
|
if "sd_card" in features_wanted:
|
||||||
sources += ['embed/trezorhal/sdcard.c', ]
|
sources += ["embed/trezorhal/sdcard.c"]
|
||||||
sources += ['embed/extmod/modtrezorio/ff.c', ]
|
sources += ["embed/extmod/modtrezorio/ff.c"]
|
||||||
sources += ['embed/extmod/modtrezorio/ffunicode.c', ]
|
sources += ["embed/extmod/modtrezorio/ffunicode.c"]
|
||||||
features_available.append("sd_card")
|
features_available.append("sd_card")
|
||||||
|
|
||||||
if "sbu" in features_wanted:
|
if "sbu" in features_wanted:
|
||||||
sources += ['embed/trezorhal/sbu.c', ]
|
sources += ["embed/trezorhal/sbu.c"]
|
||||||
features_available.append("sbu")
|
features_available.append("sbu")
|
||||||
|
|
||||||
env.get('ENV')['TREZOR_BOARD'] = board
|
env.get("ENV")["TREZOR_BOARD"] = board
|
||||||
|
|
||||||
return features_available
|
return features_available
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -9,25 +11,33 @@ HERE = Path(__file__).parent.resolve()
|
|||||||
PROJECT_ROOT = HERE.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:
|
if font is not None:
|
||||||
defines += [
|
defines += [
|
||||||
'TREZOR_FONT_' + font_name + '_ENABLE=' + font,
|
"TREZOR_FONT_" + font_name + "_ENABLE=" + font,
|
||||||
'TREZOR_FONT_' + font_name + '_INCLUDE=\\"' + font.lower() + '.h\\"',
|
"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:
|
if sourcefile not in sources:
|
||||||
sources.append(sourcefile)
|
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
|
model_r_version = 6
|
||||||
|
|
||||||
if model in ('1',):
|
if model in ("1",):
|
||||||
return trezor_1.configure(env, features_wanted, defines, sources)
|
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)
|
return trezor_t.configure(env, features_wanted, defines, sources)
|
||||||
elif model in ('R',):
|
elif model in ("R",):
|
||||||
if model_r_version == 3:
|
if model_r_version == 3:
|
||||||
return trezor_r_v3.configure(env, features_wanted, defines, sources)
|
return trezor_r_v3.configure(env, features_wanted, defines, sources)
|
||||||
elif model_r_version == 4:
|
elif model_r_version == 4:
|
||||||
@ -38,48 +48,57 @@ def configure_board(model, features_wanted, env, defines, sources):
|
|||||||
raise Exception("Unknown model")
|
raise Exception("Unknown model")
|
||||||
|
|
||||||
|
|
||||||
def get_model_identifier(model):
|
def get_model_identifier(model: str) -> str:
|
||||||
if model == '1':
|
if model == "1":
|
||||||
return "T1B1"
|
return "T1B1"
|
||||||
elif model == 'T':
|
elif model == "T":
|
||||||
return "T2T1"
|
return "T2T1"
|
||||||
elif model == 'R':
|
elif model == "R":
|
||||||
return "T2B1"
|
return "T2B1"
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown model")
|
raise Exception("Unknown model")
|
||||||
|
|
||||||
|
|
||||||
def get_version(file):
|
def get_version(file: str) -> str:
|
||||||
major = 0
|
major = 0
|
||||||
minor = 0
|
minor = 0
|
||||||
patch = 0
|
patch = 0
|
||||||
|
|
||||||
file = PROJECT_ROOT / file
|
file_path = PROJECT_ROOT / file
|
||||||
with open(file, 'r') as f:
|
with open(file_path, "r") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if line.startswith('#define VERSION_MAJOR '):
|
if line.startswith("#define VERSION_MAJOR "):
|
||||||
major = line.split('VERSION_MAJOR')[1].strip()
|
major = line.split("VERSION_MAJOR")[1].strip()
|
||||||
if line.startswith('#define VERSION_MINOR '):
|
if line.startswith("#define VERSION_MINOR "):
|
||||||
minor = line.split('VERSION_MINOR')[1].strip()
|
minor = line.split("VERSION_MINOR")[1].strip()
|
||||||
if line.startswith('#define VERSION_PATCH '):
|
if line.startswith("#define VERSION_PATCH "):
|
||||||
patch = line.split('VERSION_PATCH')[1].strip()
|
patch = line.split("VERSION_PATCH")[1].strip()
|
||||||
return f'{major}.{minor}.{patch}'
|
return f"{major}.{minor}.{patch}"
|
||||||
|
|
||||||
|
|
||||||
def get_git_revision_hash() -> str:
|
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:
|
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:
|
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):
|
def get_defs_for_cmake(defs: list[str | tuple[str, str]]) -> list[str]:
|
||||||
result = []
|
result: list[str] = []
|
||||||
for d in defs:
|
for d in defs:
|
||||||
if type(d) is tuple:
|
if type(d) is tuple:
|
||||||
result.append(d[0] + "=" + d[1])
|
result.append(d[0] + "=" + d[1])
|
||||||
|
Loading…
Reference in New Issue
Block a user