summaryrefslogtreecommitdiffstats
path: root/common/bootm.c
diff options
context:
space:
mode:
authorBastian Krause <bst@pengutronix.de>2019-09-27 11:59:54 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-09-30 20:39:04 +0200
commitfbf03e24b9111aea4a11fea1ac67fee446ad2c63 (patch)
treee06a10a94e6fb44637144fd32b15b08aa8308ec2 /common/bootm.c
parentb0ac975d9277b06081b5eff1a49d5bec19a64684 (diff)
downloadbarebox-fbf03e24b9111aea4a11fea1ac67fee446ad2c63.tar.gz
bootm: allow providing machine id to Kernel
By default systemd generates a machine id on first boot and tries to persist it (see `man machine-id`). When the root file system is read-only systemd cannot persist the machine id. In case multiple redundant slots are used the machine id will vary. When not handled explicitly the machine id will also change during system updates. It is possible to pass a machine id to the kernel which will be used by systemd (systemd.machine_id=). If global.bootm.provide_machine_id (or nv.bootm.provide_machine_id) is true then provide the machine id from global.machine_id as systemd.machine_id= parameter to the Kernel. Note that global.machine_id must be set, either by the machine_id_set_bootarg late init call or by setting it manually with nv.machine_id if necessary. Signed-off-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/bootm.c')
-rw-r--r--common/bootm.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/common/bootm.c b/common/bootm.c
index b50b76e..366f314 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -51,6 +51,7 @@ static struct image_handler *bootm_find_handler(enum filetype filetype,
}
static int bootm_appendroot;
+static int bootm_provide_machine_id;
static int bootm_verbosity;
void bootm_data_init_defaults(struct bootm_data *data)
@@ -65,6 +66,7 @@ void bootm_data_init_defaults(struct bootm_data *data)
data->initrd_file = getenv_nonempty("global.bootm.initrd");
data->verify = bootm_get_verify_mode();
data->appendroot = bootm_appendroot;
+ data->provide_machine_id = bootm_provide_machine_id;
data->verbose = bootm_verbosity;
}
@@ -646,6 +648,21 @@ int bootm_boot(struct bootm_data *bootm_data)
}
}
+ if (bootm_data->provide_machine_id) {
+ const char *machine_id = getenv_nonempty("global.machine_id");
+ char *machine_id_bootarg;
+
+ if (!machine_id) {
+ printf("Providing machine id is enabled but no machine id set\n");
+ ret = -EINVAL;
+ goto err_out;
+ }
+
+ machine_id_bootarg = basprintf("systemd.machine_id=%s", machine_id);
+ globalvar_add_simple("linux.bootargs.machine_id", machine_id_bootarg);
+ free(machine_id_bootarg);
+ }
+
printf("\nLoading %s '%s'", file_type_to_string(os_type),
data->os_file);
if (os_type == filetype_uimage &&
@@ -711,6 +728,7 @@ static int bootm_init(void)
globalvar_add_simple("bootm.oftree", NULL);
globalvar_add_simple("bootm.tee", NULL);
globalvar_add_simple_bool("bootm.appendroot", &bootm_appendroot);
+ globalvar_add_simple_bool("bootm.provide_machine_id", &bootm_provide_machine_id);
if (IS_ENABLED(CONFIG_BOOTM_INITRD)) {
globalvar_add_simple("bootm.initrd", NULL);
globalvar_add_simple("bootm.initrd.loadaddr", NULL);
@@ -738,3 +756,4 @@ BAREBOX_MAGICVAR_NAMED(global_bootm_tee, global.bootm.tee, "bootm default tee im
BAREBOX_MAGICVAR_NAMED(global_bootm_verify, global.bootm.verify, "bootm default verify level");
BAREBOX_MAGICVAR_NAMED(global_bootm_verbose, global.bootm.verbose, "bootm default verbosity level (0=quiet)");
BAREBOX_MAGICVAR_NAMED(global_bootm_appendroot, global.bootm.appendroot, "Add root= option to Kernel to mount rootfs from the device the Kernel comes from");
+BAREBOX_MAGICVAR_NAMED(global_bootm_provide_machine_id, global.bootm.provide_machine_id, "If true, add systemd.machine_id= with value of global.machine_id to Kernel");