From ad70f2e22ef29f94bf5208b3a9a2389575330b06 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Wed, 11 Jan 2023 15:14:28 -0700 Subject: [PATCH] stand: create common set_currdev Pull together the nearly identical copies of set_currdev in i386, userboot and efi. Other boot loaders have variances that might be fine to use the common routine, or not. Since they are harder to test for me, and ofw and uboot do handle these setting differently, leave them be for now. Sponsored by: Netflix Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D38005 --- stand/common/bootstrap.h | 1 + stand/common/misc.c | 17 +++++++++++++++++ stand/efi/loader/main.c | 14 -------------- stand/i386/loader/main.c | 5 +---- stand/userboot/userboot/main.c | 10 ---------- 5 files changed, 19 insertions(+), 28 deletions(-) diff --git a/stand/common/bootstrap.h b/stand/common/bootstrap.h index 138e2e51ceff..261eefaac943 100644 --- a/stand/common/bootstrap.h +++ b/stand/common/bootstrap.h @@ -415,6 +415,7 @@ int nvstore_unset_var(void *, const char *); /* common code to set currdev variable. */ int gen_setcurrdev(struct env_var *ev, int flags, const void *value); int mount_currdev(struct env_var *, int, const void *); +void set_currdev(const char *devname); #ifndef CTASSERT #define CTASSERT(x) _Static_assert(x, "compile-time assertion failed") diff --git a/stand/common/misc.c b/stand/common/misc.c index e27191796a72..b80909b9edfb 100644 --- a/stand/common/misc.c +++ b/stand/common/misc.c @@ -206,3 +206,20 @@ gen_setcurrdev(struct env_var *ev, int flags, const void *value) return (mount_currdev(ev, flags, value)); } + +/* + * Wrapper to set currdev and loaddev at the same time. + */ +void +set_currdev(const char *devname) +{ + + env_setenv("currdev", EV_VOLATILE, devname, gen_setcurrdev, + env_nounset); + /* + * Don't execute hook here; the loaddev hook makes it immutable + * once we've determined what the proper currdev is. + */ + env_setenv("loaddev", EV_VOLATILE | EV_NOHOOK, devname, env_noset, + env_nounset); +} diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c index 1e91817410b6..446c267a517a 100644 --- a/stand/efi/loader/main.c +++ b/stand/efi/loader/main.c @@ -185,20 +185,6 @@ has_keyboard(void) return retval; } -static void -set_currdev(const char *devname) -{ - - env_setenv("currdev", EV_VOLATILE, devname, gen_setcurrdev, - env_nounset); - /* - * Don't execute hook here; the loaddev hook makes it immutable - * once we've determined what the proper currdev is. - */ - env_setenv("loaddev", EV_VOLATILE | EV_NOHOOK, devname, env_noset, - env_nounset); -} - static void set_currdev_devdesc(struct devdesc *currdev) { diff --git a/stand/i386/loader/main.c b/stand/i386/loader/main.c index 8337ca378832..76e309d4130b 100644 --- a/stand/i386/loader/main.c +++ b/stand/i386/loader/main.c @@ -383,10 +383,7 @@ extract_currdev(void) init_zfs_boot_options(devformat(&new_currdev.dd)); #endif - env_setenv("currdev", EV_VOLATILE, devformat(&new_currdev.dd), - gen_setcurrdev, env_nounset); - env_setenv("loaddev", EV_VOLATILE, devformat(&new_currdev.dd), - env_noset, env_nounset); + set_currdev(devformat(&new_currdev.dd)); } COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot); diff --git a/stand/userboot/userboot/main.c b/stand/userboot/userboot/main.c index 02118c2ec1ae..40911f35020a 100644 --- a/stand/userboot/userboot/main.c +++ b/stand/userboot/userboot/main.c @@ -224,16 +224,6 @@ loader_main(struct loader_callbacks *cb, void *arg, int version, int ndisks) exit(0); } -static void -set_currdev(const char *devname) -{ - - env_setenv("currdev", EV_VOLATILE, devname, - gen_setcurrdev, env_nounset); - env_setenv("loaddev", EV_VOLATILE, devname, - env_noset, env_nounset); -} - /* * Set the 'current device' by (if possible) recovering the boot device as * supplied by the initial bootstrap.