From 0ce00cbdb6500a9c3d037ee0153ad4f12865838a Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 31 Jul 2024 12:40:59 +0200 Subject: [PATCH] feat(core/tools): create a poetry-installable package from some cli tools so that we can have them available globally inside the poetry shell --- core/tools/.gitignore | 1 + core/tools/README.md | 129 ++++++++++++++++++ core/tools/pyproject.toml | 20 +++ .../combine_firmware.py} | 0 .../{ => trezor_core_tools}/headertool.py | 0 .../{ => trezor_core_tools}/layout_parser.py | 0 6 files changed, 150 insertions(+) create mode 100644 core/tools/.gitignore create mode 100644 core/tools/README.md create mode 100644 core/tools/pyproject.toml rename core/tools/{combine_firmware => trezor_core_tools/combine_firmware.py} (100%) rename core/tools/{ => trezor_core_tools}/headertool.py (100%) rename core/tools/{ => trezor_core_tools}/layout_parser.py (100%) diff --git a/core/tools/.gitignore b/core/tools/.gitignore new file mode 100644 index 000000000..c04bc49f7 --- /dev/null +++ b/core/tools/.gitignore @@ -0,0 +1 @@ +poetry.lock diff --git a/core/tools/README.md b/core/tools/README.md new file mode 100644 index 000000000..14fb0baf7 --- /dev/null +++ b/core/tools/README.md @@ -0,0 +1,129 @@ +# Scripts for managing the project + +This directory contains various scripts that are used either in some of the make +targets, or manually, to generate code, check its size, etc. + +## Most used tools + +### `headertool` + +Lives in `trezor_core_tools/headertool.py` and is exposed as a CLI tool by the same +name. + +Headertool can generate, analyze, and modify vendor and firmware headers. Use +`headertool --help` to get the full list of commands. + +The most common usage is `headertool somefile.bin` that will dump header information. + +Another useful feature is `headertool -V vendor_header.bin firmware.bin`, which will +replace the embedded vendor header in `firmware.bin` with the one in +`vendor_header.bin`. + +### `build_mocks` + +Generate `.pyi` stubs from C and Rust source files. + +### `build_templates` + +Regenerate sources from Mako templates. + +### `build_vendorheader` + +Generate a vendor header binary from a json description. + +### `combine_firmware` + +Combine a flashable image from a boardloader, bootloader, and firmware. + +## Everything else + +### `codegen` + +Code generation tool for fonts, the loader graphic (deprecated) and cryptographic keys +(also deprecated). + +### `dialog-designer` + +Deprecated tool to visually preview multi-line dialogs in the old Trezor T UI. + +### `gdb_scripts` + +Scripts for GDB debugger. + +### `hid-bridge` + +Tool that creates a virtual HID device bridged to a UDP. This allows using the emulator +as a FIDO/U2F authenticator in a browser. + +### `size` + +Scripts to examine size of firmware. + +### `snippets` + +Ad-hoc scripts for various one-off tasks that could become useful again. + +(the whole thing is prooobably deprecated by LLMs, which will regenerate any script on +demand). + +### `translations` + +Tools for checking validity of translation data and its usage. + +### `trezor_core_tools` + +A Python package that exposes certain functionalities as CLI commands. + +`headertool` and `combine_firmware` live here, more may be moved or added. + +One additional tool is `layout_parser`, which is used to extract memory layout +information from a model `.h` file. + +### `alloc.py` + +Generate a HTML report of allocation count per line of code, as captured when running +`emu.py -p`. + +### `analyze-memory-dump.py` + +Generate a HTML report of a state of the Micropython GC heap, as captured by +`trezor.utils.mem_dump` at some execution point. + +### `build_icons.py` + +Regenerate embedded TOIF icons for webauthn apps from png files. + +### `coverage-report` + +Combine coverage reports from multiple CI jobs and generate a report. + +### `frozen_mpy_translator.py` + +Translate bytecode instructions in frozen_mpy.c to human readable form. + +### `generate_vendorheader.sh` + +Uses `build_vendorheader` to rebuild all vendor headers for all models. + +### `jpg_to_h.py` + +Convert a JPG image to a C array that can be embedded into the firmware. + +(TODO could we replace it with xxd -i?) + +### `make_cmakelists.py` + +Generate a CMakeLists.txt file for the core. + +### `provision_device.py` + +Run the provisioning flow on a prodtest firmware, against a staging provisioning server. + +### `rust_api_checks.py` + +Check that the Rust UI API is consistent with the Python UI API. + +### `rust_api_models_unification.py` + +Checks the consistency of the Rust API between models. + diff --git a/core/tools/pyproject.toml b/core/tools/pyproject.toml new file mode 100644 index 000000000..125aaf6dd --- /dev/null +++ b/core/tools/pyproject.toml @@ -0,0 +1,20 @@ +[tool.poetry] +name = "trezor_core_tools" +version = "0.1.0" +description = "Collection of CLI tools for trezor-core development" +authors = ["matejcik "] +license = "GPLv3+" +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.8" +trezor = "^0.13.9" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +headertool = "trezor_core_tools.headertool:cli" +layout_parser = "trezor_core_tools.layout_parser:main" +combine_firmware = "trezor_core_tools.combine_firmware:main" diff --git a/core/tools/combine_firmware b/core/tools/trezor_core_tools/combine_firmware.py similarity index 100% rename from core/tools/combine_firmware rename to core/tools/trezor_core_tools/combine_firmware.py diff --git a/core/tools/headertool.py b/core/tools/trezor_core_tools/headertool.py similarity index 100% rename from core/tools/headertool.py rename to core/tools/trezor_core_tools/headertool.py diff --git a/core/tools/layout_parser.py b/core/tools/trezor_core_tools/layout_parser.py similarity index 100% rename from core/tools/layout_parser.py rename to core/tools/trezor_core_tools/layout_parser.py