feat(core/bootloader_emu): take the boot command from a file with -B [no changelog]
What changed, and why it matters
This change adds a new command-line option (-B) to the Trezor bootloader emulator so it can read a boot command and arguments from a file. It is a testing/development convenience feature for the emulator only and does not appear to introduce a security vulnerability. The file is read in a fixed-size binary format and passed to the existing bootargs_set function.
No security action required. As a routine code-quality step, reviewers may confirm that bootargs_file_t is a fixed-size POD struct and that the command value is validated by downstream consumers of bootargs_set().
Security signals we found
No security-relevant signals detected in the diff
New emulator-only CLI option for test reproducibility
Fixed-size file read with length validation
Evidence from the diff
The commit adds bootargs_emu_load_file() to load a serialized bootargs_file_t from disk and call bootargs_set(). It is wired to the -B FILE option in the bootloader emulator’s main(). The function reads exactly sizeof(bootargs_file_t) bytes, validates the read length, and uses the existing bootargs_set() path. No parsing of untrusted variable-length data or unsafe memory operations is visible in the diff. The feature is limited to the emulator build (unix startup/bootutils).
Changed components
core/embed/projects/bootloader/emulator.ccore/embed/sys/startup/inc/sys/unix/bootutils_emu.hcore/embed/sys/startup/unix/bootutils.cInspect captured patch +32 / −1
### core/embed/projects/bootloader/emulator.c
@@ -50,6 +50,8 @@ void usage(void) {
printf("Options:\n");
printf(" -a disable animations\n");
printf(" -s stay in bootloader\n");
+ printf(" -B FILE boot with the command and arguments from FILE (the\n");
+ printf(" format a previous run wrote to trezor.bootargs)\n");
printf(" -w wipe any firmware before booting\n");
printf(" -e MESSAGE [TITLE [FOOTER]] display error screen and stop\n");
printf(" -c COLOR_VARIANT set color variant\n");
@@ -163,14 +165,19 @@ int main(int argc, char **argv) {
uint8_t set_variant = 0xff;
uint8_t color_variant = 0;
uint8_t bitcoin_only = 0;
- while ((opt = getopt(argc, argv, "ahslewc:b:f:i:")) != -1) {
+ while ((opt = getopt(argc, argv, "ahslewc:b:f:i:B:")) != -1) {
switch (opt) {
case 'a':
disable_animation(true);
break;
case 's':
bootargs_set(BOOT_COMMAND_STOP_AND_WAIT, NULL, 0);
break;
+ case 'B':
+ if (!bootargs_emu_load_file(optarg)) {
+ exit(BOOTUTILS_EMU_EXIT_USAGE);
+ }
+ break;
case 'e':
display_error = true;
break;
### core/embed/sys/startup/inc/sys/unix/bootutils_emu.h
@@ -55,3 +55,7 @@ typedef enum {
// exit code.
void __attribute__((noreturn)) bootutils_emu_exit(
bootutils_emu_exit_code_t code);
+
+// Sets the boot command and arguments from a file in the format written
+// by `bootutils_emu_exit()`. Returns false if the file cannot be read.
+bool bootargs_emu_load_file(const char *path);
### core/embed/sys/startup/unix/bootutils.c
@@ -56,6 +56,26 @@ static const char* bootargs_path(void) {
return path;
}
+bool bootargs_emu_load_file(const char* path) {
+ FILE* f = fopen(path, "rb");
+ if (f == NULL) {
+ LOG_ERR("cannot open bootargs file '%s'", path);
+ return false;
+ }
+
+ bootargs_file_t file = {0};
+ size_t read = fread(&file, 1, sizeof(file), f);
+ fclose(f);
+
+ if (read != sizeof(file)) {
+ LOG_ERR("malformed bootargs file '%s'", path);
+ return false;
+ }
+
+ bootargs_set((boot_command_t)file.command, file.args, BOOT_ARGS_MAX_SIZE);
+ return true;
+}
+
void bootargs_set(boot_command_t command, const void* args, size_t args_size) {
// save boot command
g_boot_command = command;Why 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.