diff options
Diffstat (limited to 'sys/arch/powerpc64')
-rw-r--r-- | sys/arch/powerpc64/dev/kexec.c | 25 | ||||
-rw-r--r-- | sys/arch/powerpc64/include/kexec.h | 10 | ||||
-rw-r--r-- | sys/arch/powerpc64/stand/rdboot/cmd.h | 4 | ||||
-rw-r--r-- | sys/arch/powerpc64/stand/rdboot/rdboot.c | 35 |
4 files changed, 38 insertions, 36 deletions
diff --git a/sys/arch/powerpc64/dev/kexec.c b/sys/arch/powerpc64/dev/kexec.c index 01c881603a7..a00f6b63556 100644 --- a/sys/arch/powerpc64/dev/kexec.c +++ b/sys/arch/powerpc64/dev/kexec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kexec.c,v 1.1 2020/07/16 19:37:58 kettenis Exp $ */ +/* $OpenBSD: kexec.c,v 1.2 2020/07/18 10:23:44 kettenis Exp $ */ /* * Copyright (c) 2019-2020 Visa Hankala @@ -22,12 +22,15 @@ #include <sys/exec_elf.h> #include <sys/malloc.h> #include <sys/proc.h> +#include <sys/reboot.h> #include <uvm/uvm_extern.h> #include <machine/kexec.h> #include <machine/opal.h> +#include <dev/ofw/fdt.h> + int kexec_kexec(struct kexec_args *, struct proc *); int kexec_read(struct kexec_args *, void *, size_t, off_t); void kexec(paddr_t, paddr_t); @@ -93,7 +96,8 @@ kexec_kexec(struct kexec_args *kargs, struct proc *p) vsize_t align = 0;; caddr_t addr; size_t phsize, shsize, size; - int error, i; + void *node; + int error, random, i; /* * Read the headers and validate them. @@ -160,12 +164,29 @@ kexec_kexec(struct kexec_args *kargs, struct proc *p) } } + random = 0; for (i = 0; i < eh.e_phnum; i++) { if (ph[i].p_type != PT_OPENBSD_RANDOMIZE) continue; /* Assume that the segment is inside a LOAD segment. */ arc4random_buf(addr + ph[i].p_vaddr - start, ph[i].p_filesz); + random = 1; + } + + if (random == 0) + kargs->boothowto &= ~RB_GOODRANDOM; + + node = fdt_find_node("/chosen"); + if (node) { + uint32_t boothowto = htobe32(kargs->boothowto); + + fdt_node_add_property(node, "openbsd,boothowto", + &boothowto, sizeof(boothowto)); + fdt_node_add_property(node, "openbsd,bootduid", + kargs->bootduid, sizeof(kargs->bootduid)); + + fdt_finalize(); } printf("launching kernel\n"); diff --git a/sys/arch/powerpc64/include/kexec.h b/sys/arch/powerpc64/include/kexec.h index 6ddeb970131..02ff50ecc8e 100644 --- a/sys/arch/powerpc64/include/kexec.h +++ b/sys/arch/powerpc64/include/kexec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: kexec.h,v 1.2 2020/07/17 08:57:39 kettenis Exp $ */ +/* $OpenBSD: kexec.h,v 1.3 2020/07/18 10:23:44 kettenis Exp $ */ /* * Copyright (c) 2019-2020 Visa Hankala @@ -25,12 +25,12 @@ struct kexec_args { char *kimg; /* kernel image buffer */ - size_t klen; /* size of kernel image */ - char *argv[KEXEC_MAX_ARGS]; - /* kernel boot arguments */ + size_t klen; /* size of kernel image */ + int boothowto; + u_char bootduid[8]; }; #define KIOC_KEXEC _IOW('K', 1, struct kexec_args) -#define KIOC_GETBOOTDUID _IOR('K', 2, char[8]) +#define KIOC_GETBOOTDUID _IOR('K', 2, u_char[8]) #endif /* _MACHINE_KEXEC_H_ */ diff --git a/sys/arch/powerpc64/stand/rdboot/cmd.h b/sys/arch/powerpc64/stand/rdboot/cmd.h index 1bbe0af07c9..ffd9e52ebe2 100644 --- a/sys/arch/powerpc64/stand/rdboot/cmd.h +++ b/sys/arch/powerpc64/stand/rdboot/cmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.h,v 1.1 2020/07/16 19:48:58 kettenis Exp $ */ +/* $OpenBSD: cmd.h,v 1.2 2020/07/18 10:23:44 kettenis Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff @@ -43,7 +43,7 @@ struct cmd_table { struct cmd_state { char bootdev[BOOTDEVLEN]; /* device */ char image[MAXPATHLEN - 16]; /* image */ - unsigned char bootduid[8]; /* duid of root disk */ + u_char bootduid[8]; /* duid of root disk */ int boothowto; /* howto */ int hasduid; char *conf; /* /etc/boot.conf normally */ diff --git a/sys/arch/powerpc64/stand/rdboot/rdboot.c b/sys/arch/powerpc64/stand/rdboot/rdboot.c index 704e8945181..2e942b94efe 100644 --- a/sys/arch/powerpc64/stand/rdboot/rdboot.c +++ b/sys/arch/powerpc64/stand/rdboot/rdboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rdboot.c,v 1.1 2020/07/16 19:48:58 kettenis Exp $ */ +/* $OpenBSD: rdboot.c,v 1.2 2020/07/18 10:23:44 kettenis Exp $ */ /* * Copyright (c) 2019-2020 Visa Hankala @@ -56,7 +56,7 @@ const char version[] = "0.1"; int main(void) { - char bootduid[8]; + u_char bootduid[8]; int fd, hasboot; fd = open(_PATH_CONSOLE, O_RDWR); @@ -77,16 +77,12 @@ main(void) strlcpy(cmd.image, KERNEL, sizeof(cmd.image)); cmd.timeout = 5; -#if 0 if (ioctl(kexecfd, KIOC_GETBOOTDUID, bootduid) == -1) { - if (errno != ENOENT) - fprintf(stderr, "cannot get bootduid from kernel: %s\n", - strerror(errno)); + fprintf(stderr, "cannot get bootduid from kernel: %s\n", + strerror(errno)); } else { - snprintf(cmd.bootdev, sizeof(cmd.bootdev), "%s%sa", - rootdev, isduid(rootdev, OPENDEV_PART) ? "." : ""); + memcpy(cmd.bootduid, bootduid, sizeof(cmd.bootduid)); } -#endif disk_init(); @@ -169,13 +165,11 @@ kexec(void) { struct kexec_args kargs; struct stat sb; - char boothowtostr[32]; - char rootdev[32]; char *kimg = NULL; const char *path; ssize_t n; off_t pos; - int argc, fd = -1, ret; + int fd = -1, ret; path = disk_open(cmd.path); if (path == NULL) @@ -209,21 +203,8 @@ kexec(void) memset(&kargs, 0, sizeof(kargs)); kargs.kimg = kimg; kargs.klen = sb.st_size; - argc = 0; - if (cmd.boothowto != 0) { - snprintf(boothowtostr, sizeof(boothowtostr), "boothowto=%d", - cmd.boothowto); - kargs.argv[argc++] = boothowtostr; - } - if (cmd.hasduid) { - snprintf(rootdev, sizeof(rootdev), - "rootdev=%02x%02x%02x%02x%02x%02x%02x%02x", - cmd.bootduid[0], cmd.bootduid[1], - cmd.bootduid[2], cmd.bootduid[3], - cmd.bootduid[4], cmd.bootduid[5], - cmd.bootduid[6], cmd.bootduid[7]); - kargs.argv[argc++] = rootdev; - } + kargs.boothowto = cmd.boothowto; + memcpy(kargs.bootduid, cmd.bootduid, sizeof(kargs.bootduid)); printf("booting %s\n", cmd.path); ret = ioctl(kexecfd, KIOC_KEXEC, &kargs); |