Skip to content

Commit

Permalink
tegra-bootinfo: fix --initialize and --force-initialize handling
Browse files Browse the repository at this point in the history
With the split of the bootinfo low-level code into a library, part
of the initialization logic got slightly mangled.

For the case where initialization is requested and we find no valid
bootinfo blocks, set the 'current' index to 0 after zeroing out both
blocks, rather than leaving it at -1 (which triggers a spurious error).

For the force-init case, add a BOOTINFO_O_FORCE_INIT flag to bootinfo_open().
When present, initialization is done even if we find a valid bootinfo block.

Signed-off-by: Matt Madison <[email protected]>
  • Loading branch information
madisongh committed Dec 10, 2022
1 parent c84a48c commit 4668121
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion bootinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,9 @@ bootinfo_open (unsigned int flags, struct bootinfo_context_s **ctxp)
}
/*
* Caller can pass the CREAT flag to tell us to try
* initializing if no valid data is found.
* initializing if no valid data is found, and add the
* FORCE_INIT flag to tell us to initialize even if valid
* data is found.
*
* Otherwise, choose the current block based on
* which is valid, and if both, which has the
Expand All @@ -664,11 +666,17 @@ bootinfo_open (unsigned int flags, struct bootinfo_context_s **ctxp)
if (flags & BOOTINFO_O_CREAT) {
if (boot_devinfo_init(ctx) < 0)
goto failure_exit;
ctx->current = 0;
/* If successful, fall through */
} else {
errno = ENODATA;
goto failure_exit;
}
} else if (flags & BOOTINFO_O_FORCE_INIT) {
if (boot_devinfo_init(ctx) < 0)
goto failure_exit;
ctx->current = 0;
/* If successful, fall through */
} else if (i < 2 && ctx->valid[1-i]) {
/* both of the first two are valid */
struct device_info *dp1 = (struct device_info *) (ctx->infobuf[1]);
Expand Down
1 change: 1 addition & 0 deletions bootinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef struct bootinfo_var_iter_context_s bootinfo_var_iter_context_t;
#define BOOTINFO_O_RDONLY (0<<0)
#define BOOTINFO_O_RDWR (3<<0)
#define BOOTINFO_O_CREAT (1<<2)
#define BOOTINFO_O_FORCE_INIT (1<<3)

int bootinfo_open(unsigned int flags, bootinfo_context_t **ctxp);
int bootinfo_close(bootinfo_context_t *ctx);
Expand Down
2 changes: 1 addition & 1 deletion tegra-bootinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ init_bootinfo (bool force_init)
unsigned int flags = BOOTINFO_O_RDWR;

if (force_init)
flags |= BOOTINFO_O_CREAT;
flags |= BOOTINFO_O_CREAT|BOOTINFO_O_FORCE_INIT;

if (bootinfo_open(flags, &ctx) < 0) {
perror("bootinfo_open");
Expand Down

0 comments on commit 4668121

Please sign in to comment.