test(core): add bootloader firmware install tests [no changelog]
What changed, and why it matters
This commit only adds and reorganizes automated test code for the Trezor bootloader. It does not change any firmware, bootloader, or production code. The new tests verify normal, expected behavior: installing firmware on an empty device, upgrading existing firmware with user confirmation, and booting preloaded firmware. There is no security-relevant code change here.
No action required. This is a test-only change and does not affect shipped firmware or bootloader behavior.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces tests/bootloader_tests/test_firmware_install.py with three pytest cases covering trusted firmware install on an empty device (no confirmation, storage erased), boot of installed firmware (jump, command cleared, storage retained), and firmware upgrade (confirmation required, storage retained). It also refactors tests/bootloader_tests/common.py to share confirm/cancel helpers between the wipe and firmware-install tests, and updates test_wipe_device.py to use the shared helper. All changes are in the test suite; no bootloader or firmware logic is modified.
Changed components
tests/bootloader_tests/common.pytests/bootloader_tests/test_firmware_install.pytests/bootloader_tests/test_wipe_device.pyInspect captured patch +157 / −14
### tests/bootloader_tests/common.py
@@ -0,0 +1,58 @@
+# This file is part of the Trezor project.
+#
+# Copyright (C) 2012-2026 SatoshiLabs and contributors
+#
+# This library is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the License along with this library.
+# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
+
+"""Screen interaction shared by the bootloader tests.
+
+The bootloader's confirmation screens (wipe, install, unlock) put the
+confirming button bottom-right on touch layouts; on Caesar both physical
+buttons together confirm. Until DebugLinkState carries layout tokens, the
+positions are fixed per layout from recordings.
+"""
+
+from __future__ import annotations
+
+import typing as t
+
+from trezorlib.debuglink import LayoutType
+
+if t.TYPE_CHECKING:
+ from trezorlib._internal.bootloader_emulator import BootloaderTestContext
+
+
+def confirm(ctx: "BootloaderTestContext") -> None:
+ """Press the confirming button of a bootloader confirmation screen."""
+ layout = ctx.layout_type
+ if layout in (LayoutType.Bolt, LayoutType.Delizia):
+ ctx.debug.click((180, 212))
+ elif layout is LayoutType.Eckhart:
+ ctx.debug.click((285, 475))
+ elif layout is LayoutType.Caesar:
+ ctx.debug.press_middle()
+ else:
+ raise NotImplementedError(layout)
+
+
+def cancel(ctx: "BootloaderTestContext") -> None:
+ """Press the cancelling button of a bootloader confirmation screen."""
+ layout = ctx.layout_type
+ if layout in (LayoutType.Bolt, LayoutType.Delizia):
+ ctx.debug.click((60, 212))
+ elif layout is LayoutType.Eckhart:
+ ctx.debug.click((95, 475))
+ elif layout is LayoutType.Caesar:
+ ctx.debug.press_left()
+ else:
+ raise NotImplementedError(layout)
### tests/bootloader_tests/test_firmware_install.py
@@ -0,0 +1,96 @@
+# This file is part of the Trezor project.
+#
+# Copyright (C) 2012-2026 SatoshiLabs and contributors
+#
+# This library is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the License along with this library.
+# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
+
+from __future__ import annotations
+
+import typing as t
+
+from trezorlib._internal.bootargs import BootArgs, BootCommand
+from trezorlib._internal.bootloader_emulator import BootloaderStartup, ExitKind
+
+from .common import confirm
+
+if t.TYPE_CHECKING:
+ from .conftest import BootloaderRunner
+
+VERSION = (2, 9, 0, 0)
+NEWER_VERSION = (2, 9, 1, 0)
+
+
+def test_install_on_empty_device(bootloader: "BootloaderRunner") -> None:
+ """A trusted image installs on an empty device without a confirmation."""
+ emu = bootloader.start(BootloaderStartup())
+ ctx = emu.ctx
+ assert not ctx.features.firmware_present
+
+ # the vendor is fully trusted and there is nothing to replace, so the
+ # bootloader asks nothing and the call returns after the upload
+ ctx.firmware_update(bootloader.make_firmware(version=VERSION))
+
+ record = bootloader.wait_exit()
+ assert record.kind is ExitKind.REBOOT
+ assert record.bootargs is not None
+ assert record.bootargs.command == BootCommand.REBOOT
+ # a fresh install starts with empty storage
+ assert record.storage_erased is True
+
+
+def test_boot_installed_firmware(bootloader: "BootloaderRunner") -> None:
+ """With trusted firmware present the bootloader boots it straight away."""
+ image = bootloader.profile_dir / "firmware.bin"
+ image.write_bytes(bootloader.make_firmware(version=VERSION))
+
+ emu = bootloader.start(BootloaderStartup(firmware=image))
+ # no screen to interact with: the run is over before the debug link
+ # answers, the storage marker written at startup must survive
+ assert not emu.running
+
+ record = bootloader.wait_exit()
+ assert record.kind is ExitKind.JUMP
+ assert record.bootargs is not None
+ assert record.bootargs.command == BootCommand.NONE
+ assert record.storage_erased is False
+
+
+def test_install_on_device_with_firmware(bootloader: "BootloaderRunner") -> None:
+ """Upgrading installed firmware asks for a confirmation and keeps the seed."""
+ installed = bootloader.profile_dir / "firmware-installed.bin"
+ installed.write_bytes(bootloader.make_firmware(version=VERSION))
+ # stay in the bootloader on the screen that talks to the host
+ connect = BootArgs.stop_and_connect().write(
+ bootloader.profile_dir / "connect.bootargs"
+ )
+
+ emu = bootloader.start(BootloaderStartup(firmware=installed, bootargs=connect))
+ ctx = emu.ctx
+ features = ctx.features
+ assert features.firmware_present
+ assert (features.fw_major, features.fw_minor, features.fw_patch) == VERSION[:3]
+
+ # firmware is present, so the bootloader asks before replacing it
+ with ctx.debug.wait_for_layout_change():
+ upload = ctx.firmware_update_in_background(
+ bootloader.make_firmware(version=NEWER_VERSION)
+ )
+ confirm(ctx)
+ upload.result(timeout=60)
+
+ record = bootloader.wait_exit()
+ assert record.kind is ExitKind.REBOOT
+ assert record.bootargs is not None
+ assert record.bootargs.command == BootCommand.REBOOT
+ # same vendor: the seed survives the upgrade
+ assert record.storage_erased is False
### tests/bootloader_tests/test_wipe_device.py
@@ -25,23 +25,12 @@
from trezorlib.debuglink import LayoutType
from trezorlib.messages import DebugWaitType
+from .common import confirm
+
if t.TYPE_CHECKING:
from .conftest import BootloaderRunner
-def confirm_wipe(ctx) -> None:
- """Press the confirming button of the wipe-confirmation screen."""
- layout = ctx.layout_type
- if layout in (LayoutType.Bolt, LayoutType.Delizia):
- ctx.debug.click((180, 212))
- elif layout is LayoutType.Eckhart:
- ctx.debug.click((285, 475))
- elif layout is LayoutType.Caesar:
- ctx.debug.press_right()
- else:
- raise NotImplementedError(layout)
-
-
def test_host_wipe_empty_device(bootloader: "BootloaderRunner") -> None:
"""An empty device wipes its storage on the host's request."""
emu = bootloader.start(BootloaderStartup())
@@ -53,7 +42,7 @@ def test_host_wipe_empty_device(bootloader: "BootloaderRunner") -> None:
# confirmation on screen
with ctx.debug.wait_for_layout_change():
reply = ctx.wire.call_in_background(messages.WipeDevice(), timeout=60)
- confirm_wipe(ctx)
+ confirm(ctx)
assert isinstance(reply.result(timeout=60), messages.Success)
# Success is sent 100 ms before the success screen is drawn; withoutWhy this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.