Skip to content

Commit

Permalink
firehose: Handle multiple primary bootloaders
Browse files Browse the repository at this point in the history
Builds with multiple copies of the primary bootloader does not make
sense, but after successfully flashing all the partitions of such build
it makes more sense to make one of them bootable, at least more than
skipping the step and saying that none was found.

Pick the first found primary bootloader and warn the user about the
situation.

Signed-off-by: Bjorn Andersson <[email protected]>
  • Loading branch information
quic-bjorande authored and andersson committed Dec 20, 2024
1 parent 23c8416 commit 321e776
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
13 changes: 10 additions & 3 deletions firehose.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ static int firehose_reset(struct qdl_device *qdl)

int firehose_run(struct qdl_device *qdl, const char *incdir, const char *storage, bool allow_missing)
{
bool multiple;
int bootable;
int ret;

Expand Down Expand Up @@ -789,11 +790,17 @@ int firehose_run(struct qdl_device *qdl, const char *incdir, const char *storage
if (ret)
return ret;

bootable = program_find_bootable_partition();
if (bootable < 0)
bootable = program_find_bootable_partition(&multiple);
if (bootable < 0) {
fprintf(stderr, "no boot partition found\n");
else
} else {
if (multiple) {
fprintf(stderr,
"WARNING: Multiple candidates for primary bootloader found, using partition %d\n",
bootable);
}
firehose_set_bootable(qdl, bootable);
}

firehose_reset(qdl);

Expand Down
13 changes: 9 additions & 4 deletions program.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,28 @@ int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, s
*
* Scan program tags for a partition with the label "sbl1", "xbl" or "xbl_a"
* and return the partition number for this. If more than one line matches
* we're assuming our logic is flawed and return an error.
* we're informing the caller so that they can warn the user about the
* uncertainty of this logic.
*/
int program_find_bootable_partition(void)
int program_find_bootable_partition(bool *multiple_found)
{
struct program *program;
const char *label;
int part = -ENOENT;

*multiple_found = false;

for (program = programes; program; program = program->next) {
label = program->label;
if (!label)
continue;

if (!strcmp(label, "xbl") || !strcmp(label, "xbl_a") ||
!strcmp(label, "sbl1")) {
if (part != -ENOENT)
return -EINVAL;
if (part != -ENOENT) {
*multiple_found = true;
continue;
}

part = program->partition;
}
Expand Down
2 changes: 1 addition & 1 deletion program.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int program_load(const char *program_file, bool is_nand);
int program_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct program *program, int fd),
const char *incdir, bool allow_missing);
int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct program *program));
int program_find_bootable_partition(void);
int program_find_bootable_partition(bool *multiple_found);
void free_programs(void);

#endif

0 comments on commit 321e776

Please sign in to comment.