diff options
author | 2018-04-20 14:08:12 +0000 | |
---|---|---|
committer | 2018-04-20 14:08:12 +0000 | |
commit | af751efb3404c529a4f79853ca8cf8ca165b2e13 (patch) | |
tree | 8fe79548b9ba1fa408b70d029929e91a76e3da8f | |
parent | remove the background scan timeout on detach, so we don't crash shortly (diff) | |
download | wireguard-openbsd-af751efb3404c529a4f79853ca8cf8ca165b2e13.tar.xz wireguard-openbsd-af751efb3404c529a4f79853ca8cf8ca165b2e13.zip |
Make loongson bootblocks use disklabel duid instead of PMON device name
when indicating the boot device to the kernel. This should reduce
ambiguity in root device selection.
-rw-r--r-- | sys/arch/loongson/loongson/autoconf.c | 44 | ||||
-rw-r--r-- | sys/arch/loongson/loongson/machdep.c | 5 | ||||
-rw-r--r-- | sys/arch/loongson/stand/boot/conf.c | 4 | ||||
-rw-r--r-- | sys/arch/loongson/stand/boot/dev.c | 12 |
4 files changed, 57 insertions, 8 deletions
diff --git a/sys/arch/loongson/loongson/autoconf.c b/sys/arch/loongson/loongson/autoconf.c index 7351703ddf5..77b9b90d93a 100644 --- a/sys/arch/loongson/loongson/autoconf.c +++ b/sys/arch/loongson/loongson/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.9 2018/01/27 22:55:23 naddy Exp $ */ +/* $OpenBSD: autoconf.c,v 1.10 2018/04/20 14:08:12 visa Exp $ */ /* * Copyright (c) 2009 Miodrag Vallat. * @@ -24,7 +24,10 @@ #include <machine/autoconf.h> +#define DUID_SIZE 8 + extern void dumpconf(void); +int parseduid(const char *, u_char *); void parsepmonbp(void); int cold = 1; @@ -51,8 +54,9 @@ cpu_configure(void) void parsepmonbp(void) { - char *p, *q; - size_t len; + char *p = NULL; + char *q; + size_t len = 0; if (strncmp(pmon_bootp, "tftp://", 7) == 0) { bootdev_class = DV_IFNET; @@ -65,6 +69,10 @@ parsepmonbp(void) /* kernel loaded by our boot blocks */ p = pmon_bootp + 10; len = strlen(p); + } else if (strncmp(pmon_bootp, "bootduid=", 9) == 0) { + /* kernel loaded by our boot blocks */ + if (parseduid(pmon_bootp + 9, bootduid) != 0) + return; } else { /* kernel loaded by PMON */ p = strchr(pmon_bootp, '@'); @@ -85,6 +93,36 @@ parsepmonbp(void) bootdev_class = DV_DISK; } +static unsigned int +parsehex(int c) +{ + if (c >= 'a') + return c - 'a' + 10; + else + return c - '0'; +} + +int +parseduid(const char *str, u_char *duid) +{ + int i; + + for (i = 0; i < DUID_SIZE * 2; i++) { + if (!(str[i] >= '0' && str[i] <= '9') && + !(str[i] >= 'a' && str[i] <= 'f')) + return -1; + } + if (str[DUID_SIZE * 2] != '\0') + return -1; + + for (i = 0; i < DUID_SIZE; i++) { + duid[i] = parsehex(str[i * 2]) * 0x10 + + parsehex(str[i * 2 + 1]); + } + + return 0; +} + void diskconf(void) { diff --git a/sys/arch/loongson/loongson/machdep.c b/sys/arch/loongson/loongson/machdep.c index fe91c31e773..2e710d0dd23 100644 --- a/sys/arch/loongson/loongson/machdep.c +++ b/sys/arch/loongson/loongson/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.82 2017/12/30 20:46:59 guenther Exp $ */ +/* $OpenBSD: machdep.c,v 1.83 2018/04/20 14:08:12 visa Exp $ */ /* * Copyright (c) 2009, 2010, 2014 Miodrag Vallat. @@ -910,7 +910,8 @@ dobootopts(int argc) continue; /* device path */ - if (*arg == '/' || strncmp(arg, "tftp://", 7) == 0) { + if (*arg == '/' || strncmp(arg, "bootduid=", 9) == 0 || + strncmp(arg, "tftp://", 7) == 0) { if (*pmon_bootp == '\0') { strlcpy(pmon_bootp, arg, sizeof pmon_bootp); parsepmonbp(); diff --git a/sys/arch/loongson/stand/boot/conf.c b/sys/arch/loongson/stand/boot/conf.c index b4ca61462b0..f23771d0ea3 100644 --- a/sys/arch/loongson/stand/boot/conf.c +++ b/sys/arch/loongson/stand/boot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.7 2016/09/13 18:27:49 jasper Exp $ */ +/* $OpenBSD: conf.c,v 1.8 2018/04/20 14:08:12 visa Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993 @@ -39,7 +39,7 @@ #include <lib/libsa/ufs.h> #include <lib/libsa/cd9660.h> -const char version[] = "0.5"; +const char version[] = "0.6"; #if 0 /* network code not compiled in */ int debug = 0; #endif diff --git a/sys/arch/loongson/stand/boot/dev.c b/sys/arch/loongson/stand/boot/dev.c index cd093a951bc..d692eacd393 100644 --- a/sys/arch/loongson/stand/boot/dev.c +++ b/sys/arch/loongson/stand/boot/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.8 2015/10/01 20:28:12 krw Exp $ */ +/* $OpenBSD: dev.c,v 1.9 2018/04/20 14:08:12 visa Exp $ */ /* * Copyright (c) 2010 Miodrag Vallat. @@ -103,6 +103,7 @@ pmon_iostrategy(void *f, int rw, daddr32_t dblk, size_t size, void *buf, int pmon_ioopen(struct open_file *f, ...) { + static const u_char zero[8] = { 0 }; struct pmon_iodata *pi; int rc; va_list ap; @@ -145,6 +146,15 @@ pmon_ioopen(struct open_file *f, ...) return EPART; } + if (memcmp(pi->label.d_uid, zero, sizeof(pi->label.d_uid)) != 0) { + const u_char *duid = pi->label.d_uid; + + snprintf(pmon_bootdev, sizeof(pmon_bootdev), + "bootduid=%02x%02x%02x%02x%02x%02x%02x%02x", + duid[0], duid[1], duid[2], duid[3], + duid[4], duid[5], duid[6], duid[7]); + } + pi->partoff = DL_GETPOFFSET(&pi->label.d_partitions[part]); pi->curpos = 0; |