summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2024-10-30 16:22:34 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2024-10-30 16:22:34 +0000
commitf0a1bc65fbbec65e167cbe045019fb29a5b6fc2b (patch)
tree55f34a88184540b60b052f9d2f42cc39f1f86c94 /usr.sbin
parent9c9e7b1f084fd9a1a45c486c2a33fbdeebac40ba (diff)
Install a copy of the UEFI bootloader in /efi/openbsd on the EFI system
partition. This will allow us to create boot options for the firmware boot manager that other OSes won't interfere with. ok phessler@, tobhe@, kn@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/installboot/efi_installboot.c36
-rw-r--r--usr.sbin/installboot/i386_installboot.c38
2 files changed, 72 insertions, 2 deletions
diff --git a/usr.sbin/installboot/efi_installboot.c b/usr.sbin/installboot/efi_installboot.c
index 39811b2e2c5..402ab8087c6 100644
--- a/usr.sbin/installboot/efi_installboot.c
+++ b/usr.sbin/installboot/efi_installboot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: efi_installboot.c,v 1.10 2023/04/26 18:04:21 kn Exp $ */
+/* $OpenBSD: efi_installboot.c,v 1.11 2024/10/30 16:22:33 kettenis Exp $ */
/* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */
/*
@@ -309,6 +309,40 @@ write_filesystem(struct disklabel *dl, char part)
goto umount;
}
+ /* Create "/efi/openbsd" directory in <duid>.<part>. */
+ dst[mntlen] = '\0';
+ if (strlcat(dst, "/efi/openbsd", sizeof(dst)) >= sizeof(dst)) {
+ rslt = -1;
+ warn("unable to build /efi/openbsd directory");
+ goto umount;
+ }
+ rslt = mkdir(dst, 0755);
+ if (rslt == -1 && errno != EEXIST) {
+ warn("mkdir('%s') failed", dst);
+ goto umount;
+ }
+
+ /* Copy EFI bootblocks to /efi/openbsd/. */
+ if (strlcat(dst, "/" BOOTEFI_DST, sizeof(dst)) >= sizeof(dst)) {
+ rslt = -1;
+ warn("unable to build /%s path", BOOTEFI_DST);
+ goto umount;
+ }
+ src = fileprefix(root, "/usr/mdec/" BOOTEFI_SRC);
+ if (src == NULL) {
+ rslt = -1;
+ goto umount;
+ }
+ srclen = strlen(src);
+ if (verbose)
+ fprintf(stderr, "%s %s to %s\n",
+ (nowrite ? "would copy" : "copying"), src, dst);
+ if (!nowrite) {
+ rslt = filecopy(src, dst);
+ if (rslt == -1)
+ goto umount;
+ }
+
dst[mntlen] = '\0';
rslt = write_firmware(root, dst);
if (rslt == -1)
diff --git a/usr.sbin/installboot/i386_installboot.c b/usr.sbin/installboot/i386_installboot.c
index 277ef92f848..eaee1178bf1 100644
--- a/usr.sbin/installboot/i386_installboot.c
+++ b/usr.sbin/installboot/i386_installboot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: i386_installboot.c,v 1.46 2023/06/11 14:00:04 krw Exp $ */
+/* $OpenBSD: i386_installboot.c,v 1.47 2024/10/30 16:22:33 kettenis Exp $ */
/* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */
/*
@@ -415,6 +415,42 @@ write_filesystem(struct disklabel *dl, char part)
goto umount;
}
+#ifdef __amd64__
+ /* Create "/efi/openbsd" directory in <duid>.<part>. */
+ dst[mntlen] = '\0';
+ if (strlcat(dst, "/efi/openbsd", sizeof(dst)) >= sizeof(dst)) {
+ rslt = -1;
+ warn("unable to build /efi/openbsd directory");
+ goto umount;
+ }
+ rslt = mkdir(dst, 0755);
+ if (rslt == -1 && errno != EEXIST) {
+ warn("mkdir('%s') failed", dst);
+ goto umount;
+ }
+
+ /* Copy BOOTX64.EFI to /efi/openbsd/. */
+ if (strlcat(dst, "/BOOTX64.EFI", sizeof(dst)) >= sizeof(dst)) {
+ rslt = -1;
+ warn("unable to build /BOOTX64.EFI path");
+ goto umount;
+ }
+ src = fileprefix(root, "/usr/mdec/BOOTX64.EFI");
+ if (src == NULL) {
+ rslt = -1;
+ goto umount;
+ }
+ srclen = strlen(src);
+ if (verbose)
+ fprintf(stderr, "%s %s to %s\n",
+ (nowrite ? "would copy" : "copying"), src, dst);
+ if (!nowrite) {
+ rslt = filecopy(src, dst);
+ if (rslt == -1)
+ goto umount;
+ }
+#endif
+
rslt = 0;
umount: