Merge branch 'nickez-agent/locked-devdevice'
What changed, and why it matters
This commit reworks how BitBox02/Nova bootloader images are built, adding two new build flags: LOCKED (which enables hardware debug protection and boot protection) and DEVELOPMENT (which controls whether unsigned firmware images are accepted). It also renames the old 'devdevice' terminology to 'development' across scripts and tests. The change is primarily a build-system and naming refactor that introduces a new 'locked development' variant. It is not a patch for an active security vulnerability, but it touches security-relevant bootloader behavior, so care is needed that the wrong combination of flags cannot be accidentally produced or flashed.
Treat this as a security-sensitive build-system change rather than an urgent vulnerability fix. Review that the new LOCKED/DEVELOPMENT matrix cannot produce an unintended 'unlocked + non-development' artifact, verify CI artifact naming clearly distinguishes locked-development from production, and ensure flashing tools still refuse to flash unsigned firmware to production-locked devices. No immediate user action is required.
Security signals we found
Bootloader security policy is now controlled by two independent flags (LOCKED and DEVELOPMENT) instead of a single production/development split.
Stage0 debug-port locking is moved under BOOTLOADER_LOCKED, which can be combined with BOOTLOADER_DEVELOPMENT.
Build config enforces DEVELOPMENT=no requires LOCKED=yes, preventing an insecure unlocked-production configuration.
Terminology change from 'devdevice' to 'development' in Python API; old method kept as deprecated wrapper.
CI now builds and labels locked vs. unlocked and development vs. production artifacts explicitly.
Evidence from the diff
The merge refactors bootloader build configuration. Previously, stage0/stage1 bootloaders were built as separate ‘production’ and ‘development’ targets. Now the build system accepts LOCKED and DEVELOPMENT flags, producing three variants: production (locked + not development), development (not locked + development), and development-locked (locked + development). The C code replaces BOOTLOADER_PRODUCTION with BOOTLOADER_LOCKED and BB02_STAGE0_DEVELOPMENT with BOOTLOADER_DEVELOPMENT. Stage0 now locks debug access when BOOTLOADER_LOCKED is defined, regardless of development mode, and stage1 boot protection is gated by BOOTLOADER_LOCKED. Build scripts validate that DEVELOPMENT=no requires LOCKED=yes. Python tooling renames is_devdevice() to is_development() and adds a deprecation warning. CI matrices are expanded to cover the new variants.
Changed components
BitBox02/Nova bootloader stage0BitBox02/Nova bootloader stage1scripts/build_config.pyscripts/build_product.pysrc/CMakeLists.txtpy/bitbox02/bitbox02/bitbox02/bootloader.pypy/load_firmware.pyCI workflow .github/workflows/ci-common.ymlInspect captured patch +362 / −241
### .github/workflows/ci-common.yml
@@ -63,6 +63,9 @@ jobs:
- name: Run Python unit tests
run: PYTHONPATH=py/bitbox02 python3 -m unittest discover -s py/bitbox02/tests
+ - name: Run build configuration tests
+ run: python3 -m unittest discover -s test/scripts -p test_build_config.py
+
lint-src:
runs-on: ubuntu-22.04
container:
@@ -198,8 +201,18 @@ jobs:
- {target: firmware, product: bitbox02, edition: btc-only}
- {target: firmware, product: bitbox02nova, edition: multi}
- {target: firmware, product: bitbox02nova, edition: btc-only}
- - {target: bootloader-stage0-production, product: bitbox02, edition: multi}
- - {target: bootloader-stage1-production, product: bitbox02, edition: multi}
+ - {target: bootloader-stage0, product: bitbox02, edition: multi, locked: 'yes', development: 'no'}
+ - {target: bootloader-stage0, product: bitbox02, edition: btc-only, locked: 'yes', development: 'no'}
+ - {target: bootloader-stage0, product: bitbox02nova, edition: multi, locked: 'yes', development: 'no'}
+ - {target: bootloader-stage0, product: bitbox02nova, edition: btc-only, locked: 'yes', development: 'no'}
+ - {target: bootloader-stage1, product: bitbox02, edition: multi, locked: 'yes', development: 'no'}
+ - {target: bootloader-stage1, product: bitbox02, edition: btc-only, locked: 'yes', development: 'no'}
+ - {target: bootloader-stage1, product: bitbox02nova, edition: multi, locked: 'yes', development: 'no'}
+ - {target: bootloader-stage1, product: bitbox02nova, edition: btc-only, locked: 'yes', development: 'no'}
+ - {target: bootloader-stage0, product: bitbox02, edition: multi, locked: 'yes', development: 'yes'}
+ - {target: bootloader-stage0, product: bitbox02nova, edition: multi, locked: 'yes', development: 'yes'}
+ - {target: bootloader-stage1, product: bitbox02, edition: multi, locked: 'yes', development: 'yes'}
+ - {target: bootloader-stage1, product: bitbox02nova, edition: multi, locked: 'yes', development: 'yes'}
- {target: firmware-blupgrade-bitbox02-btconly, product: bitbox02, edition: multi}
- {target: firmware-blupgrade-bitbox02-multi, product: bitbox02, edition: multi}
- {target: firmware-blupgrade-bitbox02nova-btconly, product: bitbox02nova, edition: multi}
@@ -235,7 +248,7 @@ jobs:
run: ./scripts/bootstrap-cargo-config
- name: Configure product
- run: make config CONFIG_ARGS="--product ${{ matrix.product }} --edition ${{ matrix.edition }} --debug ${{ matrix.debug || 'no' }}"
+ run: make config CONFIG_ARGS="--product ${{ matrix.product }} --edition ${{ matrix.edition }} --debug ${{ matrix.debug || 'no' }} --locked ${{ matrix.locked || 'no' }} --development ${{ matrix.development || 'yes' }}"
- name: Build ${{ matrix.target }}
run: make -j$(($(nproc)+1)) ${{ matrix.target }}
@@ -260,7 +273,7 @@ jobs:
if: github.event_name == 'push' && !cancelled()
uses: actions/upload-artifact@v4
with:
- name: ${{matrix.product}}-${{matrix.edition}}-${{matrix.target}}${{ matrix.debug == 'yes' && '-debug' || '' }}-${{github.sha}}.bin
+ name: ${{matrix.product}}-${{matrix.edition}}-${{matrix.target}}${{ matrix.debug == 'yes' && '-debug' || '' }}-locked-${{ matrix.locked || 'no' }}-development-${{ matrix.development || 'yes' }}-${{github.sha}}.bin
path: |
build*/bin/*.bin
build*/bin/*.elf
### BUILD.md
@@ -165,9 +165,9 @@ make bootloader-stage1
```
`make config` remembers selections in the git-ignored `config.mk`. It prompts for product, board,
-edition (`multi` or `btc-only`), debug builds (`no` or `yes`), probe software, and SWD speed in kHz,
-automatically selecting fields with one choice. `DEBUG` defaults to `no`; `SWD_SPEED` defaults to
-`4000` for all products and both probe backends.
+edition (`multi` or `btc-only`), debug builds, locked hardware, development mode, probe software, and
+SWD speed in kHz, automatically selecting fields with one choice. `DEBUG` defaults to `no`; `SWD_SPEED` defaults to
+`4000` for all products and both probe backends. `LOCKED` defaults to `no` and `DEVELOPMENT` to `yes`.
Probe hardware is fixed by the board:
| Product | Board | Probe | Software (default first) |
@@ -191,6 +191,7 @@ make config CONFIG_ARGS="--product bitbox03 --board dev-kit"
make config CONFIG_ARGS="--product bitbox03 --board testboard"
make config CONFIG_ARGS="--product bitbox03 --debug yes"
make config CONFIG_ARGS="--product bitbox03 --swd-speed 1000"
+make config CONFIG_ARGS="--product bitbox02 --locked yes --development yes"
make config CONFIG_ARGS="--defaults"
```
@@ -200,6 +201,13 @@ command, for example `make debug-server SWD_SPEED=1000`.
The debug setting is also saved in `config.mk` and can be overridden per command with `DEBUG=yes`
or `DEBUG=no`. Build, flash, and run commands use the same configured profile.
+For BitBox02/Nova bootloaders, `LOCKED=yes` enables hardware debug protection and stage1 boot
+protection. `DEVELOPMENT=yes` allows unsigned images and enables the development markers; `no`
+requires signatures and `LOCKED=yes`. These settings are independent of `DEBUG`. Both are saved
+in `config.mk` and can be overridden per command, for example
+`make bootloader-stage1 LOCKED=yes DEVELOPMENT=yes`. Use the same flags when flashing or running.
+BitBox03 does not yet implement these bootloader modes and only accepts their defaults.
+
Invalid input, EOF, or Ctrl-C preserves the previous file. Interactive product changes reset
incompatible saved choices. Run configuration separately from builds: `make config firmware` is
rejected because Make has already parsed the old settings. Configuration and compilation require
@@ -208,7 +216,8 @@ neither installed probe software nor attached hardware.
With `DEBUG=no`, BitBox02/Nova primary targets use `RelWithDebInfo` and BitBox03 uses Cargo release
builds. `DEBUG=yes` selects debug builds for all products, with their existing RTT features.
Firmware follows the selected edition; factorysetup is edition-independent; stage0/stage1 select
-development images for the configured product and edition. Build directories are flat:
+images for the configured product, edition, `LOCKED`, and `DEVELOPMENT` settings. Build directories
+are flat:
| Backend | Directory |
| --- | --- |
@@ -225,14 +234,16 @@ software or SWD speed does not affect compilation. Configuration never cleans. `
build trees but preserves `config.mk`. Host tests and simulators still use `build-build` and
`build-build-noasan`.
-`bootloader-stage{0,1}-{production,development}` builds all BitBox02/Nova editions, sequentially in
-each product's directory. Production/development upgrade-firmware and upgrade-assets aliases are
-retained. Named product commands always use that product's directory.
+Use `bootloader-stage0` and `bootloader-stage1` with `LOCKED=yes DEVELOPMENT=no` for production
+bootloaders, or `LOCKED=yes DEVELOPMENT=yes` for locked development devices. These targets build
+only the configured product and edition. Development artifact names use `-development`, with
+`-locked` appended for locked development devices. Production artifact names use `-production`
+and always enable locking. Upgrade-firmware and upgrade-assets aliases also use `-development`
+for development devices. Named product commands always use that product's directory.
The old `firmware-btc`, `factory-setup`, per-product stage build shortcuts, and
-`bitbox03-*` build shortcuts are replaced by configuration plus the primary targets above. Backend
-targets and artifact basenames remain unchanged. Additional BitBox03 board/edition implementations
-are deferred.
+`bitbox03-*` build shortcuts are replaced by configuration plus the primary targets above.
+Additional BitBox03 board/edition implementations are deferred.
Pass `-j<N>` to speed up a build, for example `make -j8 firmware`. Top-level aliases run sequentially.
### Makefile
@@ -16,9 +16,11 @@ PRODUCT ?= bitbox02
BOARD ?= $(if $(filter bitbox03,$(PRODUCT)),dev-kit,$(PRODUCT))
EDITION ?= multi
DEBUG ?= no
+LOCKED ?= no
+DEVELOPMENT ?= yes
PROBE_SOFTWARE ?= $(if $(filter bitbox03,$(PRODUCT)),openocd,jlink)
SWD_SPEED ?= 4000
-CONFIG_OPTIONS = --product "$(PRODUCT)" --board "$(BOARD)" --edition "$(EDITION)" --debug "$(DEBUG)" --probe-software "$(PROBE_SOFTWARE)" --swd-speed "$(SWD_SPEED)"
+CONFIG_OPTIONS = --product "$(PRODUCT)" --board "$(BOARD)" --edition "$(EDITION)" --debug "$(DEBUG)" --locked "$(LOCKED)" --development "$(DEVELOPMENT)" --probe-software "$(PROBE_SOFTWARE)" --swd-speed "$(SWD_SPEED)"
config:
python3 scripts/build_config.py $(CONFIG_ARGS)
@@ -33,8 +35,6 @@ ifeq ($(PRODUCT),bitbox03)
FLASH_IMAGES := $(filter-out factorysetup,$(FLASH_IMAGES))
endif
BUILD_TARGETS := $(IMAGES) \
- bootloader-stage0-production bootloader-stage0-development \
- bootloader-stage1-production bootloader-stage1-development \
bootloader-upgrade-assets bootloader-upgrade-assets-development docs rust-docs
BUILD_TARGETS += $(foreach product,bitbox02 bitbox02nova,$(foreach edition,multi btconly,\
firmware-blupgrade-$(product)-$(edition) firmware-blupgrade-$(product)-$(edition)-development))
### py/bitbox02/bitbox02/bitbox02/bootloader.py
@@ -8,6 +8,7 @@
import math
import hashlib
import enum
+import warnings
from typing import TypedDict
import semver
@@ -126,16 +127,25 @@ def __init__(self, transport: TransportLayer, device_info: DeviceInfo):
if metadata is not None
for identifier in metadata.split(".")
]
- self._is_devdevice = "dev" in version_identifiers
+ self._is_development = "dev" in version_identifiers
# Delete the prelease part, as it messes with the comparison (e.g. 3.0.0-pre < 3.0.0 is
# True, but the 3.0.0-pre has already the same API breaking changes like 3.0.0...).
self.version = version.replace(prerelease=None)
assert self.expected_magic
assert self.product_id
+ def is_development(self) -> bool:
+ """Returns whether this is a development bootloader."""
+ return self._is_development
+
def is_devdevice(self) -> bool:
- """Returns whether this is a development-device bootloader."""
- return self._is_devdevice
+ """Deprecated: use is_development()."""
+ warnings.warn(
+ "Bootloader.is_devdevice() is deprecated; use is_development() instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.is_development()
def _query(self, msg: bytes) -> bytes:
cid = self._transport.generate_cid()
### py/load_firmware.py
@@ -40,11 +40,11 @@
FLASHING_HELP = """\
Flashing behavior:
- signed firmware + production device flash firmware and signatures
- signed firmware + development device flash firmware, attempt signatures, and treat a
- signature error as a warning
- unsigned firmware + production device flash firmware, but it will not boot
- unsigned firmware + development device flash firmware without signatures
+ signed firmware + production device flash firmware and signatures
+ signed firmware + development device flash firmware, attempt signatures, and treat a
+ signature error as a warning
+ unsigned firmware + production device flash firmware, but it will not boot
+ unsigned firmware + development device flash firmware without signatures
The input type is detected from the signed-firmware header. Recognized but malformed signed
firmware is rejected. Every flash asks for confirmation; -y/--yes skips the prompt. Edition
@@ -219,14 +219,13 @@ def _find_and_open_usb_bitbox02(use_cache: bool) -> Tuple[devices.DeviceInfo, Tr
return bootloader_device, u2fhid.U2FHid(hid_device)
-def _confirm_flash(signed: bool, devdevice: bool, product_string: str) -> bool:
+def _confirm_flash(signed: bool, development: bool, product_string: str) -> bool:
"""Ask the user to confirm the detected firmware and device combination."""
firmware_kind = "signed" if signed else "unsigned"
- device_kind = "development" if devdevice else "production"
+ device_kind = "development device" if development else "production device"
try:
response = input(
- f"Flash {firmware_kind} firmware to this {device_kind} device "
- f"({product_string})? [Y/n] "
+ f"Flash {firmware_kind} firmware to this {device_kind} " f"({product_string})? [Y/n] "
)
except EOFError:
return False
@@ -241,10 +240,10 @@ def _flash_firmware(
progress: Callable[[float], None],
) -> bool:
"""Flash a validated firmware input. Returns false if the user declines."""
- devdevice = bootloader.is_devdevice()
+ development = bootloader.is_development()
signed = firmware.sigdata is not None
- if not signed and not devdevice:
+ if not signed and not development:
eprint(
"WARNING: Unsigned firmware cannot boot on a production device; rebooting is "
"expected to show a firmware verification error."
@@ -254,13 +253,13 @@ def _flash_firmware(
"WARNING: The signed firmware edition does not match the connected device; "
"installing its signature data is expected to fail."
)
- if signed and devdevice:
+ if signed and development:
eprint(
"WARNING: Development device detected. Signature data will be attempted, but a "
"rejection will not prevent the firmware from booting."
)
- if not yes and not _confirm_flash(signed, devdevice, bootloader_device["product_string"]):
+ if not yes and not _confirm_flash(signed, development, bootloader_device["product_string"]):
return False
bootloader.flash_unsigned_firmware(firmware.payload, progress)
@@ -271,7 +270,7 @@ def _flash_firmware(
try:
bootloader.flash_sigdata(firmware.sigdata)
except Exception as error: # pylint: disable=broad-exception-caught
- if not devdevice:
+ if not development:
raise
if isinstance(error, BootloaderError):
message = _bootloader_error_message(error)
### scripts/build_config.py
@@ -43,6 +43,8 @@ class Config:
probe_software: str = "jlink"
swd_speed: int = DEFAULT_SWD_SPEED
debug: str = "no"
+ locked: str = "no"
+ development: str = "yes"
@property
def profile(self) -> str:
@@ -73,6 +75,14 @@ def validate(self) -> Config:
raise ValueError(f"Invalid edition: {self.edition}")
if self.debug not in ("no", "yes"):
raise ValueError(f"Invalid debug setting: {self.debug}")
+ if self.locked not in ("no", "yes"):
+ raise ValueError(f"Invalid locked setting: {self.locked}")
+ if self.development not in ("no", "yes"):
+ raise ValueError(f"Invalid development setting: {self.development}")
+ if self.product == "bitbox03" and (self.locked != "no" or self.development != "yes"):
+ raise ValueError("Locked and non-development builds are not implemented for BitBox03")
+ if self.development == "no" and self.locked == "no":
+ raise ValueError("DEVELOPMENT=no requires LOCKED=yes")
if self.probe_software not in self.software_choices:
raise ValueError(
f"{self.board} requires probe software: {', '.join(self.software_choices)}"
@@ -84,6 +94,7 @@ def validate(self) -> Config:
def describe(self) -> None:
print(f"Product: {self.product}; board: {self.board}; edition: {self.edition}")
print(f"Debug: {self.debug}; profile: {self.profile}")
+ print(f"Locked: {self.locked}; development: {self.development}")
print(f"Probe hardware: {self.probe_hardware}; software: {self.probe_software}")
print(f"SWD speed: {self.swd_speed} kHz")
if self.product == "bitbox03":
@@ -108,6 +119,8 @@ def add_config_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument("--board")
parser.add_argument("--edition", choices=EDITIONS)
parser.add_argument("--debug", choices=("no", "yes"), help="Debug build (default: no)")
+ parser.add_argument("--locked", choices=("no", "yes"), help="Lock hardware (default: no)")
+ parser.add_argument("--development", choices=("no", "yes"), help="Development (default: yes)")
parser.add_argument("--probe-software", choices=("jlink", "openocd"))
parser.add_argument("--swd-speed", type=int, help="SWD speed in kHz (default: 4000)")
@@ -121,6 +134,8 @@ def from_args(args: argparse.Namespace) -> Config:
args.probe_software or base.probe_software,
args.swd_speed if args.swd_speed is not None else base.swd_speed,
args.debug or base.debug,
+ args.locked or base.locked,
+ args.development or base.development,
).validate()
@@ -135,6 +150,8 @@ def read_config(path: Path) -> dict[str, str]:
"BOARD",
"EDITION",
"DEBUG",
+ "LOCKED",
+ "DEVELOPMENT",
"PROBE_SOFTWARE",
"SWD_SPEED",
):
@@ -165,14 +182,26 @@ def interactive(saved: dict[str, str]) -> Config:
)
edition = choose("Edition", EDITIONS, saved.get("EDITION", base.edition))
debug = choose("Debug", ("no", "yes"), saved.get("DEBUG", base.debug))
+ locked = choose(
+ "Locked",
+ ("no",) if product == "bitbox03" else ("no", "yes"),
+ saved.get("LOCKED", base.locked),
+ )
+ development = choose(
+ "Development",
+ ("yes",) if locked == "no" else ("yes", "no"),
+ saved.get("DEVELOPMENT", base.development),
+ )
config = Config(product, board, edition, base.probe_software)
print(f"Probe hardware: {config.probe_hardware} (derived from board)")
software = choose(
"Probe software", config.software_choices, saved.get("PROBE_SOFTWARE", base.probe_software)
)
saved_speed = saved.get("SWD_SPEED", str(base.swd_speed))
speed = input(f"SWD speed in kHz [{saved_speed}]: ").strip() or saved_speed
- return Config(product, board, edition, software, int(speed), debug).validate()
+ return Config(
+ product, board, edition, software, int(speed), debug, locked, development
+ ).validate()
def save_config(path: Path, config: Config) -> None:
@@ -185,7 +214,16 @@ def save_config(path: Path, config: Config) -> None:
) as outfile:
name = outfile.name
outfile.write("# Generated by make config. Local configuration; do not commit.\n")
- for key in ("product", "board", "edition", "debug", "probe_software", "swd_speed"):
+ for key in (
+ "product",
+ "board",
+ "edition",
+ "debug",
+ "locked",
+ "development",
+ "probe_software",
+ "swd_speed",
+ ):
outfile.write(f"{key.upper()} = {getattr(config, key)}\n")
os.replace(name, path)
finally:
@@ -211,7 +249,6 @@ def image_info(
config: Config,
image: str,
root: Path = ROOT,
- variant: str = "development",
) -> Image:
config.validate()
profile = config.profile
@@ -234,6 +271,9 @@ def image_info(
elf = build_dir(config, root=root) / CARGO_TARGET / profile / name
return Image(name, elf, vectors, image == "factorysetup")
if image.startswith("bootloader-"):
+ variant = "development" if config.development == "yes" else "production"
+ if config.locked == "yes" and config.development == "yes":
+ variant += "-locked"
name = f"{image}-{config.product}-{config.edition.replace('-', '')}-{variant}"
address = 0 if image == "bootloader-stage0" else 0x2000
else:
### scripts/build_product.py
@@ -36,25 +36,26 @@ def run(command: list[str], cwd: Path = ROOT) -> None:
def cmake(config: Config, profile: str, targets: list[str]) -> None:
directory = build_dir(config, profile)
run([str(ROOT / "scripts/bootstrap-cargo-config")])
- if not (directory / "Makefile").exists():
- run(
- [
- "cmake",
- "-S",
- str(ROOT),
- "-B",
- str(directory),
- "-DCMAKE_TOOLCHAIN_FILE=arm.cmake",
- f"-DCMAKE_BUILD_TYPE={profile.upper()}",
- ]
- )
+ first_build = not (directory / "Makefile").exists()
+ run(
+ [
+ "cmake",
+ "-S",
+ str(ROOT),
+ "-B",
+ str(directory),
+ "-DCMAKE_TOOLCHAIN_FILE=arm.cmake",
+ f"-DCMAKE_BUILD_TYPE={profile.upper()}",
+ ]
+ )
+ if first_build:
run(["make", "-C", str(ROOT / "py/bitbox02")])
run(["make", "-C", str(directory), *targets])
-def build_image(config: Config, image: str, variant: str = "development") -> None:
+def build_image(config: Config, image: str) -> None:
profile = config.profile
- info = image_info(config, image, variant=variant)
+ info = image_info(config, image)
if config.product != "bitbox03":
cmake(config, profile, [f"{info.name}.elf"])
return
@@ -84,22 +85,6 @@ def dispatch(config: Config, target: str) -> None:
elif target.startswith("firmware-blupgrade-"):
product = target.split("-")[2]
cmake(defaults(product), "relwithdebinfo", [target + ".elf"])
- elif target in (
- "bootloader-stage0-production",
- "bootloader-stage0-development",
- "bootloader-stage1-production",
- "bootloader-stage1-development",
- ):
- image, variant = target.rsplit("-", 1)
- # These aggregates retain their original all-product/all-edition coverage.
- for product in ("bitbox02", "bitbox02nova"):
- for edition in ("multi", "btc-only"):
- base = defaults(product)
- build_image(
- Config(product, base.board, edition, base.probe_software),
- image,
- variant=variant,
- )
elif target in ("bootloader-upgrade-assets", "bootloader-upgrade-assets-development"):
suffix = "-development" if target.endswith("-development") else ""
for product in ("bitbox02", "bitbox02nova"):
### src/CMakeLists.txt
@@ -500,14 +500,19 @@ if(CMAKE_CROSSCOMPILING)
)
set(BB02_BLUPD_FIRMWARE_TARGETS ${BB02_BLUPD_FIRMWARE_TARGETS} PARENT_SCOPE)
- function(add_bb02_stage1_target target rustlib product product_id bootloader_type is_plus)
+ function(add_bb02_stage1_target target rustlib product product_id development locked is_plus)
set(header_dir ${CMAKE_CURRENT_BINARY_DIR}/bootloader/${target})
set(header_manifest ${header_dir}/image_header.json)
set(header_bin ${header_dir}/image_header.bin)
set(header_obj ${header_dir}/image_header.o)
set(header_flags 0)
- if(bootloader_type STREQUAL "BOOTLOADER_DEVDEVICE")
+ set(bootloader_definitions)
+ if(development)
set(header_flags 1)
+ list(APPEND bootloader_definitions BOOTLOADER_DEVELOPMENT)
+ endif()
+ if(locked)
+ list(APPEND bootloader_definitions BOOTLOADER_LOCKED)
endif()
configure_file(bootloader/image_header.json.in ${header_manifest} @ONLY)
add_custom_command(
@@ -553,7 +558,7 @@ if(CMAKE_CROSSCOMPILING)
target_include_directories(${target}.elf PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/bootloader)
target_compile_definitions(${target}.elf PRIVATE
BOOTLOADER
- ${bootloader_type}
+ ${bootloader_definitions}
${product}
"APP_U2F=0"
${LVGL_DEFINITIONS}
@@ -577,80 +582,9 @@ if(CMAKE_CROSSCOMPILING)
set_property(TARGET ${target}.elf PROPERTY EXCLUDE_FROM_ALL ON)
endfunction()
- # Product IDs must match bootloader/bootloader_product.h.
- add_bb02_stage1_target(
- bootloader-stage1-bitbox02-btconly-development
- bb02-bl-btconly-development_rust_c
- PRODUCT_BITBOX_BTCONLY
- 2
- BOOTLOADER_DEVDEVICE
- FALSE)
- add_bb02_stage1_target(
- bootloader-stage1-bitbox02-btconly-production
- bb02-bl-btconly-production_rust_c
- PRODUCT_BITBOX_BTCONLY
- 2
- BOOTLOADER_PRODUCTION
- FALSE)
- add_bb02_stage1_target(
- bootloader-stage1-bitbox02-multi-development
- bb02-bl-multi-development_rust_c
- PRODUCT_BITBOX_MULTI
- 1
- BOOTLOADER_DEVDEVICE
- FALSE)
- add_bb02_stage1_target(
- bootloader-stage1-bitbox02-multi-production
- bb02-bl-multi-production_rust_c
- PRODUCT_BITBOX_MULTI
- 1
- BOOTLOADER_PRODUCTION
- FALSE)
- add_bb02_stage1_target(
- bootloader-stage1-bitbox02nova-btconly-development
- bb02p-bl-btconly-development_rust_c
- PRODUCT_BITBOX_PLUS_BTCONLY
- 4
- BOOTLOADER_DEVDEVICE
- TRUE)
- add_bb02_stage1_target(
- bootloader-stage1-bitbox02nova-btconly-production
- bb02p-bl-btconly-production_rust_c
- PRODUCT_BITBOX_PLUS_BTCONLY
- 4
- BOOTLOADER_PRODUCTION
- TRUE)
- add_bb02_stage1_target(
- bootloader-stage1-bitbox02nova-multi-development
- bb02p-bl-multi-development_rust_c
- PRODUCT_BITBOX_PLUS_MULTI
- 3
- BOOTLOADER_DEVDEVICE
- TRUE)
- add_bb02_stage1_target(
- bootloader-stage1-bitbox02nova-multi-production
- bb02p-bl-multi-production_rust_c
- PRODUCT_BITBOX_PLUS_MULTI
- 3
- BOOTLOADER_PRODUCTION
- TRUE)
-
- # Bare stage1 target names are exported for J-Link script generation.
- set(BB02_STAGE1_TARGETS
- bootloader-stage1-bitbox02-btconly-production
- bootloader-stage1-bitbox02-multi-production
- bootloader-stage1-bitbox02nova-btconly-production
- bootloader-stage1-bitbox02nova-multi-production
- bootloader-stage1-bitbox02-btconly-development
- bootloader-stage1-bitbox02-multi-development
- bootloader-stage1-bitbox02nova-btconly-development
- bootloader-stage1-bitbox02nova-multi-development
- )
- set(BB02_STAGE1_TARGETS ${BB02_STAGE1_TARGETS} PARENT_SCOPE)
-
# Builds one stage0 ELF/bin for a product. Production stage0 includes stage1 signature
# verification; development stage0 skips that path and shows a visible development marker.
- function(add_bb02_stage0_target stage0_target product target_product_id development)
+ function(add_bb02_stage0_target stage0_target product target_product_id development locked)
set(stage0_sources
${CMAKE_SOURCE_DIR}/src/bootloader/stage0/stage0.c
${CMAKE_SOURCE_DIR}/src/bootloader/stage0/stage0_descriptor.c
@@ -668,7 +602,7 @@ if(CMAKE_CROSSCOMPILING)
)
set(stage0_compile_definitions)
if(development)
- list(APPEND stage0_compile_definitions BB02_STAGE0_DEVELOPMENT)
+ list(APPEND stage0_compile_definitions BOOTLOADER_DEVELOPMENT)
else()
list(APPEND stage0_sources
${CMAKE_SOURCE_DIR}/src/bootloader_upgrade/stage1_pubkeys.c
@@ -678,6 +612,10 @@ if(CMAKE_CROSSCOMPILING)
)
endif()
+ if(locked)
+ list(APPEND stage0_compile_definitions BOOTLOADER_LOCKED)
+ endif()
+
add_executable(${stage0_target}.elf ${stage0_sources})
target_compile_options(${stage0_target}.elf PRIVATE -flto -ffat-lto-objects)
target_include_directories(${stage0_target}.elf PRIVATE ${INCLUDES})
@@ -710,59 +648,53 @@ if(CMAKE_CROSSCOMPILING)
)
endfunction()
- add_bb02_stage0_target(
- bootloader-stage0-bitbox02-btconly-production
- PRODUCT_BITBOX_BTCONLY
- BB02_STAGE1_PRODUCT_ID_BITBOX_BTCONLY
- FALSE)
- add_bb02_stage0_target(
- bootloader-stage0-bitbox02-multi-production
- PRODUCT_BITBOX_MULTI
- BB02_STAGE1_PRODUCT_ID_BITBOX_MULTI
- FALSE)
- add_bb02_stage0_target(
- bootloader-stage0-bitbox02nova-btconly-production
- PRODUCT_BITBOX_PLUS_BTCONLY
- BB02_STAGE1_PRODUCT_ID_BITBOX_PLUS_BTCONLY
- FALSE)
- add_bb02_stage0_target(
- bootloader-stage0-bitbox02nova-multi-production
- PRODUCT_BITBOX_PLUS_MULTI
- BB02_STAGE1_PRODUCT_ID_BITBOX_PLUS_MULTI
- FALSE)
- add_bb02_stage0_target(
- bootloader-stage0-bitbox02-btconly-development
- PRODUCT_BITBOX_BTCONLY
- BB02_STAGE1_PRODUCT_ID_BITBOX_BTCONLY
- TRUE)
- add_bb02_stage0_target(
- bootloader-stage0-bitbox02-multi-development
- PRODUCT_BITBOX_MULTI
- BB02_STAGE1_PRODUCT_ID_BITBOX_MULTI
- TRUE)
- add_bb02_stage0_target(
- bootloader-stage0-bitbox02nova-btconly-development
- PRODUCT_BITBOX_PLUS_BTCONLY
- BB02_STAGE1_PRODUCT_ID_BITBOX_PLUS_BTCONLY
- TRUE)
- add_bb02_stage0_target(
- bootloader-stage0-bitbox02nova-multi-development
- PRODUCT_BITBOX_PLUS_MULTI
- BB02_STAGE1_PRODUCT_ID_BITBOX_PLUS_MULTI
- TRUE)
-
- # Bare stage0 target names are exported for J-Link script generation.
- set(BB02_STAGE0_TARGETS
- bootloader-stage0-bitbox02-btconly-production
- bootloader-stage0-bitbox02-multi-production
- bootloader-stage0-bitbox02nova-btconly-production
- bootloader-stage0-bitbox02nova-multi-production
- bootloader-stage0-bitbox02-btconly-development
- bootloader-stage0-bitbox02-multi-development
- bootloader-stage0-bitbox02nova-btconly-development
- bootloader-stage0-bitbox02nova-multi-development
- )
+ # Product IDs must match bootloader/bootloader_product.h.
+ # Bare target names are exported for J-Link script generation.
+ set(BB02_STAGE0_TARGETS)
+ set(BB02_STAGE1_TARGETS)
+ foreach(product bitbox02 bitbox02nova)
+ set(is_plus FALSE)
+ set(rust_prefix bb02)
+ set(product_prefix PRODUCT_BITBOX)
+ set(product_id 1)
+ if(product STREQUAL "bitbox02nova")
+ set(is_plus TRUE)
+ set(rust_prefix bb02p)
+ set(product_prefix PRODUCT_BITBOX_PLUS)
+ set(product_id 3)
+ endif()
+ foreach(edition multi btconly)
+ string(TOUPPER ${edition} edition_upper)
+ set(product_definition ${product_prefix}_${edition_upper})
+ if(edition STREQUAL "btconly")
+ math(EXPR product_id "${product_id} + 1")
+ endif()
+ foreach(variant production development development-locked)
+ set(development FALSE)
+ set(locked FALSE)
+ set(rust_variant production)
+ if(variant MATCHES "^development")
+ set(development TRUE)
+ set(rust_variant development)
+ endif()
+ if(variant STREQUAL "production" OR variant STREQUAL "development-locked")
+ set(locked TRUE)
+ endif()
+ set(stage0_target bootloader-stage0-${product}-${edition}-${variant})
+ set(stage1_target bootloader-stage1-${product}-${edition}-${variant})
+ add_bb02_stage0_target(
+ ${stage0_target} ${product_definition} ${product_id} ${development} ${locked})
+ add_bb02_stage1_target(
+ ${stage1_target}
+ ${rust_prefix}-bl-${edition}-${rust_variant}_rust_c
+ ${product_definition} ${product_id} ${development} ${locked} ${is_plus})
+ list(APPEND BB02_STAGE0_TARGETS ${stage0_target})
+ list(APPEND BB02_STAGE1_TARGETS ${stage1_target})
+ endforeach()
+ endforeach()
+ endforeach()
set(BB02_STAGE0_TARGETS ${BB02_STAGE0_TARGETS} PARENT_SCOPE)
+ set(BB02_STAGE1_TARGETS ${BB02_STAGE1_TARGETS} PARENT_SCOPE)
# Creates the embedded prebuilt stage0 image object and stage1 update payload object used by one
# bootloader-upgrade firmware target.
### src/bootloader/bootloader.c
@@ -28,7 +28,7 @@
#include <usb/usb_processing.h>
#include <util.h>
-#if defined(BOOTLOADER_DEVDEVICE) || PLATFORM_BITBOX02PLUS == 1
+#if defined(BOOTLOADER_DEVELOPMENT) || PLATFORM_BITBOX02PLUS == 1
#include <memory/memory_spi.h>
#include <qtouch/qtouch.h>
#endif
@@ -890,7 +890,7 @@ static void _api_setup(void)
static void _check_init(boot_data_t* data)
{
-#ifdef BOOTLOADER_PRODUCTION
+#ifdef BOOTLOADER_LOCKED
// Enable boot protection if not already enabled. The
// BOOTPROT fuse is persistent and not erased on chip erase.
while (NVMCTRL->STATUS.bit.READY == 0) {
@@ -946,8 +946,8 @@ static void _check_init(boot_data_t* data)
}
}
-#ifdef BOOTLOADER_DEVDEVICE
-static bool _devdevice_enter(secbool_u32 firmware_verified)
+#ifdef BOOTLOADER_DEVELOPMENT
+static bool _development_enter(secbool_u32 firmware_verified)
{
UG_ClearBuffer();
UG_PutString(0, 0, " <Enter bootloader>");
@@ -1023,8 +1023,8 @@ void bootloader_jump(void)
UG_FontSelect(&font_regular_9);
if (!bootloader_wait && shared_data.fields.auto_enter != sectrue_u8) {
-#ifdef BOOTLOADER_DEVDEVICE
- if (!_devdevice_enter(_firmware_verified_jump(&bootdata, secfalse_u32))) {
+#ifdef BOOTLOADER_DEVELOPMENT
+ if (!_development_enter(_firmware_verified_jump(&bootdata, secfalse_u32))) {
_binary_exec();
/* no return */
}
### src/bootloader/stage0/stage0.c
@@ -3,7 +3,7 @@
#include "bootloader/boot_args.h"
#include "bootloader_upgrade/bootloader_upgrade.h"
#include <bootloader/bootloader_product.h>
-#ifndef BB02_STAGE0_DEVELOPMENT
+#ifndef BOOTLOADER_DEVELOPMENT
#include "bootloader_upgrade/stage1_pubkeys.h"
#endif
#include "driver_init.h"
@@ -13,7 +13,7 @@
#include "stage0_install.h"
#include "ui/oled/oled.h"
#include "util.h"
-#ifndef BB02_STAGE0_DEVELOPMENT
+#ifndef BOOTLOADER_DEVELOPMENT
#include "pukcc/curve_p256.h"
#include "pukcc/pukcc.h"
#include "stage1_sigcheck.h"
@@ -117,7 +117,7 @@ static bool _oled_upside_down(void)
return flash_upside_down;
}
-#ifdef BB02_STAGE0_DEVELOPMENT
+#ifdef BOOTLOADER_DEVELOPMENT
static void _oled_development_cross_overlay(void)
{
for (int16_t x = 0; x < OLED_WIDTH; x++) {
@@ -161,7 +161,7 @@ static void _oled_progress(uint8_t done, uint8_t total)
oled_set_pixel(x, y, true);
}
}
-#ifdef BB02_STAGE0_DEVELOPMENT
+#ifdef BOOTLOADER_DEVELOPMENT
_oled_development_cross_overlay();
#endif
oled_send_buffer();
@@ -239,7 +239,7 @@ static void _nvm_check_errors(void)
}
}
-#ifndef BB02_STAGE0_DEVELOPMENT
+#ifdef BOOTLOADER_LOCKED
static void _lock_debug_access(void)
{
// Hard lock the Device Service Unit, i.e., set the PAC write-protection bit,
@@ -427,7 +427,7 @@ static uint32_t _stage1_vector_addr(const bb02_stage1_header_t* header)
static secbool_u32 _stage1_flags_ok(const bb02_stage1_header_t* header)
{
-#ifndef BB02_STAGE0_DEVELOPMENT
+#ifndef BOOTLOADER_DEVELOPMENT
if ((header->flags & BB02_STAGE1_FLAG_DEVELOPMENT) != 0) {
return secfalse_u32;
}
@@ -460,7 +460,7 @@ static void _stage1_hash(const bb02_stage1_header_t* header, uint8_t hash_out[32
sha_sync_sha256_finish(&HASH_ALGORITHM_0, hash_out);
}
-#ifndef BB02_STAGE0_DEVELOPMENT
+#ifndef BOOTLOADER_DEVELOPMENT
static secbool_u32 _header_signatures_ok(const bb02_stage1_header_t* header)
{
return stage1_sigcheck_image_ok(header, bb02_stage1_pubkeys);
@@ -478,7 +478,7 @@ static secbool_u32 __attribute__((noinline, noclone)) _stage1_image_ok(
}
_stage1_hash(header, hash_out);
-#ifdef BB02_STAGE0_DEVELOPMENT
+#ifdef BOOTLOADER_DEVELOPMENT
return sectrue_u32;
#else
return _header_signatures_ok(header);
@@ -611,11 +611,12 @@ static void _boot_stage1(const bb02_stage1_header_t* stage1, const volatile secb
static void __attribute__((noreturn, noinline)) _stage0_main(void)
{
-#ifdef BB02_STAGE0_DEVELOPMENT
+#ifdef BOOTLOADER_LOCKED
+ _lock_debug_access();
+#endif
+#ifdef BOOTLOADER_DEVELOPMENT
_oled_init();
_oled_development_cross();
-#else
- _lock_debug_access();
#endif
uint8_t installed_hash[32];
@@ -643,7 +644,7 @@ static void __attribute__((noreturn, noinline)) _stage0_main(void)
_boot_stage1(installed, &boot_auth);
}
}
-#ifndef BB02_STAGE0_DEVELOPMENT
+#ifndef BOOTLOADER_DEVELOPMENT
_oled_init();
#endif
_oled_progress(0, 6);
### src/bootloader/stage0/stage0_descriptor.c
@@ -4,7 +4,7 @@
#include "bootloader_upgrade/bootloader_upgrade.h"
#include <bootloader/bootloader_product.h>
-#ifdef BB02_STAGE0_DEVELOPMENT
+#ifdef BOOTLOADER_DEVELOPMENT
#define BB02_STAGE0_DESCRIPTOR_FLAGS BB02_STAGE0_FLAG_DEVELOPMENT
#else
#define BB02_STAGE0_DESCRIPTOR_FLAGS 0u
### src/bootloader/startup.c
@@ -15,7 +15,7 @@
#include <usb/class/hid/hww/hid_hww.h>
#include <usb/usb_processing.h>
-#if defined(BOOTLOADER_DEVDEVICE) || PLATFORM_BITBOX02PLUS == 1
+#if defined(BOOTLOADER_DEVELOPMENT) || PLATFORM_BITBOX02PLUS == 1
#include <qtouch.h>
#endif
@@ -70,7 +70,7 @@ int main(void)
platform_init();
__stack_chk_guard = rand_sync_read32(&RAND_0);
screen_init(oled_set_pixel, oled_mirror, oled_clear_buffer);
-#if defined(BOOTLOADER_DEVDEVICE) || PLATFORM_BITBOX02PLUS == 1
+#if defined(BOOTLOADER_DEVELOPMENT) || PLATFORM_BITBOX02PLUS == 1
qtouch_init();
#endif
bootloader_jump();
### src/platform/driver_init.c
@@ -384,8 +384,8 @@ void bootloader_init(void)
_oled_set_pins();
_ptc_clock_init();
-#if defined(BOOTLOADER_DEVDEVICE) || PLATFORM_BITBOX02PLUS == 1
- // Only needed for qtouch, which is only needed in the devdevice bootloader.
+#if defined(BOOTLOADER_DEVELOPMENT) || PLATFORM_BITBOX02PLUS == 1
+ // Only needed for qtouch, which is only needed in the development bootloader.
_timer_peripheral_init();
#endif
_delay_driver_init();
@@ -420,7 +420,7 @@ void stage0_init(void)
_flash_memory_init();
_sha_init();
_rand_init();
-#ifndef BB02_STAGE0_DEVELOPMENT
+#ifndef BOOTLOADER_DEVELOPMENT
_ecdsa_init();
#endif
}
### src/usb/class/usb_desc_common.h
@@ -57,10 +57,10 @@
DIGITAL_BITBOX_VERSION_W16
#endif
-#if defined(BOOTLOADER_DEVDEVICE) && defined(BOOTLOADER_VERSION_HAS_METADATA)
+#if defined(BOOTLOADER_DEVELOPMENT) && defined(BOOTLOADER_VERSION_HAS_METADATA)
#define BOOTLOADER_VERSION_APPEND_LEN 4
#define BOOTLOADER_VERSION_APPEND_W16 '.', 0, 'd', 0, 'e', 0, 'v', 0,
-#elif defined(BOOTLOADER_DEVDEVICE)
+#elif defined(BOOTLOADER_DEVELOPMENT)
#define BOOTLOADER_VERSION_APPEND_LEN 4
#define BOOTLOADER_VERSION_APPEND_W16 '+', 0, 'd', 0, 'e', 0, 'v', 0,
#else
### test/scripts/test_build_config.py
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: Apache-2.0
+
+import argparse
+import contextlib
+from dataclasses import replace
+import io
+from pathlib import Path
+import tempfile
+import unittest
+from unittest.mock import patch
+
+from scripts import build_config
+
+
+class TestBuildConfig(unittest.TestCase):
+ def test_bootloader_modes(self) -> None:
+ modes = (
+ ("no", "yes", "development"),
+ ("yes", "no", "production"),
+ ("yes", "yes", "development-locked"),
+ )
+ for product in ("bitbox02", "bitbox02nova"):
+ for edition in build_config.EDITIONS:
+ for debug in ("no", "yes"):
+ for locked, development, variant in modes:
+ with self.subTest(
+ product=product,
+ edition=edition,
+ debug=debug,
+ locked=locked,
+ development=development,
+ ):
+ config = replace(
+ build_config.defaults(product),
+ edition=edition,
+ debug=debug,
+ locked=locked,
+ development=development,
+ )
+ for stage, vectors in ((0, 0), (1, 0x2400)):
+ info = build_config.image_info(config, f"bootloader-stage{stage}")
+ expected = (
+ f"bootloader-stage{stage}-{product}-"
+ f"{edition.replace('-', '')}-{variant}"
+ )
+ self.assertEqual(info.name, expected)
+ self.assertEqual(info.elf.name, expected + ".elf")
+ self.assertEqual(info.vectors, vectors)
+ profile = "debug" if debug == "yes" else "relwithdebinfo"
+ self.assertEqual(
+ info.elf.parent.parent.name,
+ f"build-{product}-cmake-{profile}",
+ )
+
+ def test_config_flags_roundtrip(self) -> None:
+ parser = argparse.ArgumentParser()
+ build_config.add_config_arguments(parser)
+ defaults = build_config.from_args(parser.parse_args([]))
+ self.assertEqual((defaults.locked, defaults.development), ("no", "yes"))
+ for locked, development in (("no", "yes"), ("yes", "no"), ("yes", "yes")):
+ with self.subTest(locked=locked, development=development):
+ config = build_config.from_args(
+ parser.parse_args(["--locked", locked, "--development", development])
+ )
+ with tempfile.TemporaryDirectory() as directory:
+ path = Path(directory) / "config.mk"
+ build_config.save_config(path, config)
+ saved = build_config.read_config(path)
+ self.assertEqual(saved["LOCKED"], locked)
+ self.assertEqual(saved["DEVELOPMENT"], development)
+ with patch("builtins.input", return_value=""), contextlib.redirect_stdout(
+ io.StringIO()
+ ):
+ self.assertEqual(build_config.interactive(saved), config)
+
+ def test_unlocked_non_development_rejected(self) -> None:
+ parser = argparse.ArgumentParser()
+ build_config.add_config_arguments(parser)
+ for product in ("bitbox02", "bitbox02nova"):
+ with self.subTest(product=product):
+ args = parser.parse_args(
+ ["--product", product, "--locked", "no", "--development", "no"]
+ )
+ with self.assertRaisesRegex(ValueError, "DEVELOPMENT=no requires LOCKED=yes"):
+ build_config.from_args(args)
+ config = replace(build_config.defaults(product), development="no")
+ for image in build_config.IMAGES:
+ with self.assertRaisesRegex(ValueError, "DEVELOPMENT=no requires LOCKED=yes"):
+ build_config.image_info(config, image)
+
+ def test_invalid_flags_preserve_saved_config(self) -> None:
+ with tempfile.TemporaryDirectory() as directory:
+ path = Path(directory) / "config.mk"
+ build_config.save_config(path, build_config.Config())
+ previous = path.read_bytes()
+ for config in (
+ replace(build_config.Config(), locked="invalid"),
+ replace(build_config.Config(), development="invalid"),
+ replace(build_config.Config(), development="no"),
+ ):
+ with self.subTest(config=config), self.assertRaises(ValueError):
+ build_config.save_config(path, config)
+ self.assertEqual(path.read_bytes(), previous)
+
+ def test_interactive_unlock_requires_development(self) -> None:
+ saved = {"LOCKED": "yes", "DEVELOPMENT": "no"}
+ with patch(
+ "builtins.input", side_effect=["", "", "", "no", "", ""]
+ ), contextlib.redirect_stdout(io.StringIO()):
+ config = build_config.interactive(saved)
+ self.assertEqual((config.locked, config.development), ("no", "yes"))
+
+ def test_bitbox03_rejects_unimplemented_modes(self) -> None:
+ base = build_config.defaults("bitbox03")
+ base.validate()
+ for config in (replace(base, locked="yes"), replace(base, development="no")):
+ with self.assertRaisesRegex(ValueError, "not implemented for BitBox03"):
+ config.validate()
+
+ def test_interactive_product_change_resets_unsupported_modes(self) -> None:
+ saved = {"LOCKED": "yes", "DEVELOPMENT": "no"}
+ with patch(
+ "builtins.input", side_effect=["bitbox03", "", "", "", ""]
+ ), contextlib.redirect_stdout(io.StringIO()):
+ config = build_config.interactive(saved)
+ self.assertEqual(config, build_config.defaults("bitbox03"))
+
+
+if __name__ == "__main__":
+ unittest.main()
### test/scripts/test_load_firmware.py
@@ -84,7 +84,7 @@ def test_parse_signed_firmware_rejects_invalid_payload_size(self) -> None:
with self.subTest(size=len(payload)), self.assertRaises(ValueError):
bootloader_module.parse_signed_firmware(MAGIC + SIGDATA + payload)
- def test_is_devdevice(self) -> None:
+ def test_is_development(self) -> None:
for serial_number in (
"bb02.bl:v1.0.0-dev",
"v1.2.2+dev",
@@ -94,9 +94,9 @@ def test_is_devdevice(self) -> None:
bootloader = bootloader_module.Bootloader(
DummyTransport(), device_info(serial_number)
)
- self.assertTrue(bootloader.is_devdevice())
+ self.assertTrue(bootloader.is_development())
- def test_is_devdevice_rejects_other_version_identifiers(self) -> None:
+ def test_is_development_rejects_other_version_identifiers(self) -> None:
for serial_number in (
"v1.2.2",
"v1.2.2+git.123",
@@ -107,9 +107,9 @@ def test_is_devdevice_rejects_other_version_identifiers(self) -> None:
bootloader = bootloader_module.Bootloader(
DummyTransport(), device_info(serial_number)
)
- self.assertFalse(bootloader.is_devdevice())
+ self.assertFalse(bootloader.is_development())
- def test_is_devdevice_preserves_normalized_version(self) -> None:
+ def test_is_development_preserves_normalized_version(self) -> None:
bootloader = bootloader_module.Bootloader(
DummyTransport(), device_info("bb02.bl:v1.0.0-dev")
)
@@ -196,7 +196,7 @@ def setUp(self) -> None:
self.progress = mock.Mock()
def test_unsigned_development_firmware(self) -> None:
- self.bootloader.is_devdevice.return_value = True
+ self.bootloader.is_development.return_value = True
firmware = LOAD_FIRMWARE.FirmwareInput(PAYLOAD, None, None)
self.assertTrue(
LOAD_FIRMWARE._flash_firmware(
@@ -207,7 +207,7 @@ def test_unsigned_development_firmware(self) -> None:
self.bootloader.flash_sigdata.assert_not_called()
def test_unsigned_production_firmware_is_allowed_with_warning(self) -> None:
- self.bootloader.is_devdevice.return_value = False
+ self.bootloader.is_development.return_value = False
firmware = LOAD_FIRMWARE.FirmwareInput(PAYLOAD, None, None)
stderr = io.StringIO()
with contextlib.redirect_stderr(stderr):
@@ -219,7 +219,7 @@ def test_unsigned_production_firmware_is_allowed_with_warning(self) -> None:
self.bootloader.flash_unsigned_firmware.assert_called_once_with(PAYLOAD, self.progress)
def test_signed_production_firmware(self) -> None:
- self.bootloader.is_devdevice.return_value = False
+ self.bootloader.is_development.return_value = False
firmware = signed_input()
self.assertTrue(
LOAD_FIRMWARE._flash_firmware(
@@ -230,7 +230,7 @@ def test_signed_production_firmware(self) -> None:
self.bootloader.flash_sigdata.assert_called_once_with(SIGDATA)
def test_mismatched_signed_production_firmware_is_attempted(self) -> None:
- self.bootloader.is_devdevice.return_value = False
+ self.bootloader.is_development.return_value = False
stderr = io.StringIO()
with contextlib.redirect_stderr(stderr):
result = LOAD_FIRMWARE._flash_firmware(
@@ -242,7 +242,7 @@ def test_mismatched_signed_production_firmware_is_attempted(self) -> None:
self.bootloader.flash_sigdata.assert_called_once_with(SIGDATA)
def test_signed_development_firmware_attempts_sigdata(self) -> None:
- self.bootloader.is_devdevice.return_value = True
+ self.bootloader.is_development.return_value = True
firmware = signed_input()
events = []
self.bootloader.flash_unsigned_firmware.side_effect = lambda *_args: events.append(
@@ -257,7 +257,7 @@ def test_signed_development_firmware_attempts_sigdata(self) -> None:
self.assertEqual(events, ["firmware", "sigdata"])
def test_signed_development_sigdata_error_is_warning(self) -> None:
- self.bootloader.is_devdevice.return_value = True
+ self.bootloader.is_development.return_value = True
self.bootloader.flash_sigdata.side_effect = bootloader_module.BootloaderError(ord("V"))
stderr = io.StringIO()
with contextlib.redirect_stderr(stderr):
@@ -269,7 +269,7 @@ def test_signed_development_sigdata_error_is_warning(self) -> None:
self.assertIn("downgrade", stderr.getvalue())
def test_signed_development_payload_error_is_fatal(self) -> None:
- self.bootloader.is_devdevice.return_value = True
+ self.bootloader.is_development.return_value = True
self.bootloader.flash_unsigned_firmware.side_effect = bootloader_module.BootloaderError(
ord("W")
)
@@ -282,7 +282,7 @@ def test_signed_development_payload_error_is_fatal(self) -> None:
self.bootloader.flash_sigdata.assert_not_called()
def test_signed_development_transport_error_is_warning(self) -> None:
- self.bootloader.is_devdevice.return_value = True
+ self.bootloader.is_development.return_value = True
self.bootloader.flash_sigdata.side_effect = Exception("transport failed")
stderr = io.StringIO()
with contextlib.redirect_stderr(stderr):
@@ -293,7 +293,7 @@ def test_signed_development_transport_error_is_warning(self) -> None:
self.assertIn("transport failed", stderr.getvalue())
def test_flash_can_be_declined(self) -> None:
- self.bootloader.is_devdevice.return_value = True
+ self.bootloader.is_development.return_value = True
with mock.patch.object(LOAD_FIRMWARE, "_confirm_flash", return_value=False) as confirm:
with contextlib.redirect_stderr(io.StringIO()):
result = LOAD_FIRMWARE._flash_firmware(
@@ -309,7 +309,7 @@ def test_flash_can_be_declined(self) -> None:
self.bootloader.flash_sigdata.assert_not_called()
def test_flash_can_be_confirmed(self) -> None:
- self.bootloader.is_devdevice.return_value = True
+ self.bootloader.is_development.return_value = True
with mock.patch.object(LOAD_FIRMWARE, "_confirm_flash", return_value=True) as confirm:
with contextlib.redirect_stderr(io.StringIO()):
result = LOAD_FIRMWARE._flash_firmware(
@@ -325,7 +325,7 @@ def test_flash_can_be_confirmed(self) -> None:
self.bootloader.flash_sigdata.assert_called_once_with(SIGDATA)
def test_yes_skips_confirmation(self) -> None:
- self.bootloader.is_devdevice.return_value = True
+ self.bootloader.is_development.return_value = True
firmware = LOAD_FIRMWARE.FirmwareInput(PAYLOAD, None, None)
with mock.patch.object(LOAD_FIRMWARE, "_confirm_flash") as confirm:
LOAD_FIRMWARE._flash_firmware(
@@ -362,8 +362,8 @@ def test_help_documents_flashing_matrix(self) -> None:
self.assertEqual(raised.exception.code, 0)
help_text = stdout.getvalue()
self.assertIn("signed firmware + production device", help_text)
- self.assertIn("signed firmware + development device", help_text)
- self.assertIn("unsigned firmware + development device", help_text)
+ self.assertIn("signed firmware + development", help_text)
+ self.assertIn("unsigned firmware + development", help_text)
self.assertIn("unsigned firmware + production device", help_text)
self.assertIn("--yes", help_text)
self.assertNotIn("--unsigned", help_text)
@@ -392,7 +392,7 @@ def test_confirmation_rejects_eof(self) -> None:
def test_sigdata_warning_still_reboots(self) -> None:
bootloader = mock.Mock()
bootloader.erased.return_value = True
- bootloader.is_devdevice.return_value = True
+ bootloader.is_development.return_value = True
bootloader.expected_magic = MAGIC
bootloader.flash_sigdata.side_effect = bootloader_module.BootloaderError(ord("V"))
with mock.patch.object(
@@ -417,7 +417,7 @@ def test_sigdata_warning_still_reboots(self) -> None:
def test_production_bootloader_error_is_fatal(self) -> None:
bootloader = mock.Mock()
bootloader.erased.return_value = True
- bootloader.is_devdevice.return_value = False
+ bootloader.is_development.return_value = False
bootloader.expected_magic = MAGIC
bootloader.flash_sigdata.side_effect = bootloader_module.BootloaderError(ord("V"))
stderr = io.StringIO()Why this scored 37/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.