Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core firmware split #4188

Merged
merged 44 commits into from
Sep 24, 2024
Merged

Core firmware split #4188

merged 44 commits into from
Sep 24, 2024

Conversation

cepetr
Copy link
Contributor

@cepetr cepetr commented Sep 18, 2024

This PR introduces a significant conceptual change to our Trezor firmware. It divides the firmware into two parts: a privileged and an unprivileged section. We refer to these as the kernel and the coreapp.

The kernel includes all hardware drivers, storage management, and necessary cryptographic functions. It operates in privileged mode, providing interfaces to the less trusted coreapp via approximately 100 syscalls.

The coreapp contains the MicroPython core, MicroPython applications, and the Rust-based UI. It runs entirely in unprivileged mode, with no direct access to hardware, except for DMA2D in its current implementation.

Kernel and coreapp are built as two separate applications but eventually glued together by build scripts as a single binary. So you can make firmware as before with no change at the first glance.

Benefits:

  1. Enhanced security by separating the trusted kernel from the untrusted coreapp.
  2. Enhanced security by enabling access to specific memory regions (storage, OTP, secrets) only on demand, reducing the risk of random overwrites).
  3. Improved maintainability, with a clearer separation of concerns between hardware-level operations and application logic.

Known issues:

  1. Syscall arguments are currently not verified.
  2. TrustZone settings need to be updated to reflect the new architecture.

These issues need to be resolved soon, but they do not have a significant impact on security at the moment, as they have not been addressed in the firmware until now.

This PR brings also a lot of changes and improvements to drivers code:

  1. Improved display driver API (preparation for init/deinit sequence)
  2. Refactored interrupt handling routines API, reduced number of used priorities.
  3. New systick driver that offer more precise time measurement.
  4. New systimer for scheduling timer callbacks for background operations.
  5. New i2c_bus driver, enabling non-blocking i2c operations
  6. New mpu driver for region banking, that overcomes cortex-m cpu limitations.
  7. New systask module, which allows manuall switching between privileged and unprivileged tasks
  8. New system module with more reliable error handling (emergency mode)
  9. Completely refactored and simplified linker scripts and startup codes.

@cepetr cepetr self-assigned this Sep 18, 2024
@cepetr cepetr force-pushed the cepetr/core-split branch 4 times, most recently from 26d1025 to 3c561cf Compare September 18, 2024 12:34
Copy link
Contributor

@TychoVrahe TychoVrahe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First part of the review, focusing mainly on drivers up to introduction of non-blocking i2c driver, of which the review is not yet complete.

core/embed/bootloader/main.c Outdated Show resolved Hide resolved
core/site_scons/models/T3B1/trezor_t3b1_revB.py Outdated Show resolved Hide resolved
core/embed/trezorhal/xdisplay.h Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32f4/systick.c Show resolved Hide resolved
core/embed/trezorhal/stm32f4/i2c_bus.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32u5/i2c_bus.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32u5/i2c_bus.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32u5/i2c_bus.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32u5/i2c_bus.c Outdated Show resolved Hide resolved
Copy link
Contributor

@TychoVrahe TychoVrahe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some more stuff related to drivers part, up to and excluding the new mpu driver.

core/embed/trezorhal/stm32f4/i2c_bus.c Show resolved Hide resolved
core/embed/trezorhal/stm32f4/i2c_bus.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32f4/i2c_bus.c Show resolved Hide resolved
core/embed/trezorhal/stm32f4/systimer.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32u5/i2c_bus.c Show resolved Hide resolved
core/embed/trezorhal/stm32f4/bootutils.c Show resolved Hide resolved
core/embed/trezorhal/bootargs.h Outdated Show resolved Hide resolved
core/embed/trezorhal/bootutils.h Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32f4/fwutils.c Outdated Show resolved Hide resolved
core/embed/trezorhal/secure_aes.h Show resolved Hide resolved
core/embed/trezorhal/stm32u5/secure_aes.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32u5/secure_aes.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32u5/secure_aes.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32u5/secure_aes.c Show resolved Hide resolved
core/embed/trezorhal/stm32u5/secure_aes.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32u5/secure_aes.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32u5/secure_aes.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32f4/linker/boardloader.ld Outdated Show resolved Hide resolved
core/embed/kernel/main.c Show resolved Hide resolved
core/embed/kernel/main.c Outdated Show resolved Hide resolved
core/site_scons/tools.py Show resolved Hide resolved
core/embed/trezorhal/stm32f4/startup_stage_2.S Outdated Show resolved Hide resolved
core/embed/models/T2B1/model_T2B1.h Show resolved Hide resolved
Copy link
Contributor

@TychoVrahe TychoVrahe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some more issues/questions related to the last part - mpu, split and tasks+etc.

core/embed/lib/flash_utils.c Outdated Show resolved Hide resolved
core/embed/lib/flash_utils.c Show resolved Hide resolved
core/embed/lib/flash_utils.c Outdated Show resolved Hide resolved
core/embed/lib/flash_utils.h Outdated Show resolved Hide resolved
core/embed/lib/flash_utils.h Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32f4/applet.c Show resolved Hide resolved
core/embed/trezorhal/stm32f4/system.c Show resolved Hide resolved
core/embed/trezorhal/stm32f4/system.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32f4/system.c Show resolved Hide resolved
core/embed/trezorhal/stm32f4/systask.c Show resolved Hide resolved
@cepetr cepetr force-pushed the cepetr/core-split branch 2 times, most recently from 5a2da1e to 6075662 Compare September 24, 2024 08:32
@cepetr cepetr merged commit ab96ce7 into main Sep 24, 2024
85 checks passed
@cepetr cepetr deleted the cepetr/core-split branch September 24, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🤝 Needs QA
Development

Successfully merging this pull request may close these issues.

2 participants