Skip to content

Commit

Permalink
blspec: add checking of optional key machine-id
Browse files Browse the repository at this point in the history
For filtering of Bootloader Spec entries, Bootloader Spec
specify an optional key machine-id. By set the
global.boot.machine-id variable the checking of machine-id
key in Bootloader Spec entries will be activate. If the
variable and key match, appropriate boot entry will be
booting. If it not match boot entry will be ignore and
barebox check the next boot entry.

Signed-off-by: Andreas Schmidt <[email protected]>
Signed-off-by: Sascha Hauer <[email protected]>
  • Loading branch information
schmidtandreas authored and saschahauer committed May 8, 2018
1 parent d472b86 commit 70013eb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Documentation/user/booting-linux.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ The entry can be listed with the -l option:
When on barebox the SD card shows up as ``mmc1`` then this entry can be booted with
``boot mmc1`` or with setting ``global.boot.default`` to ``mmc1``.

``machine-id`` is an optional key. If ``global.boot.machine_id`` variable is set to
non-empty value, then barebox accepts only Bootloader Spec entries with ``machine-id``
key. In case if value of global variable and Bootloader Spec key match each other,
barebox will choose the boot entry for booting. All other Bootloader Spec entries will
be ignored.

A bootloader spec entry can also reside on an NFS server in which case a RFC2224
compatible NFS URI string must be passed to the boot command:

Expand Down
31 changes: 30 additions & 1 deletion common/blspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,30 @@ static bool entry_is_of_compatible(struct blspec_entry *entry)
return ret;
}

/*
* entry_is_match_machine_id - check if a bootspec entry is match with
* the machine id given by global variable.
*
* returns true if the entry is match, false otherwise
*/

static bool entry_is_match_machine_id(struct blspec_entry *entry)
{
int ret = true;
const char *env_machineid = getenv_nonempty("global.boot.machine_id");

if (env_machineid) {
const char *machineid = blspec_entry_var_get(entry, "machine-id");
if (!machineid || strcmp(machineid, env_machineid)) {
pr_debug("ignoring entry with missmatched machine-id " \
"\"%s\" != \"%s\"\n", env_machineid, machineid);
ret = false;
}
}

return ret;
}

/*
* blspec_scan_directory - scan over a directory
*
Expand Down Expand Up @@ -504,6 +528,11 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
continue;
}

if (!entry_is_match_machine_id(entry)) {
blspec_entry_free(&entry->entry);
continue;
}

found++;

if (entry->cdev && entry->cdev->dev) {
Expand Down Expand Up @@ -756,4 +785,4 @@ static int blspec_init(void)
{
return bootentry_register_provider(blspec_bootentry_provider);
}
device_initcall(blspec_init);
device_initcall(blspec_init);

0 comments on commit 70013eb

Please sign in to comment.