Allow the kernel to recognize that it has been netbooted and to add the
authornaddy <naddy@openbsd.org>
Tue, 6 Feb 2018 20:35:21 +0000 (20:35 +0000)
committernaddy <naddy@openbsd.org>
Tue, 6 Feb 2018 20:35:21 +0000 (20:35 +0000)
boot interface to the "netboot" group.  efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@

sys/arch/arm64/arm64/autoconf.c
sys/arch/arm64/arm64/machdep.c
sys/arch/arm64/stand/efiboot/conf.c
sys/arch/arm64/stand/efiboot/efiboot.c
sys/arch/arm64/stand/efiboot/efipxe.c

index ad507ae..4d5222b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: autoconf.c,v 1.8 2018/01/27 22:55:23 naddy Exp $      */
+/*     $OpenBSD: autoconf.c,v 1.9 2018/02/06 20:35:21 naddy Exp $      */
 /*
  * Copyright (c) 2009 Miodrag Vallat.
  *
 #include <sys/conf.h>
 #include <sys/device.h>
 #include <sys/reboot.h>
+#include <sys/socket.h>
 #include <sys/hibernate.h>
 #include <uvm/uvm.h>
 
+#include <net/if.h>
+#include <net/if_types.h>
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+
 #include <machine/bootconfig.h>
 
 extern void dumpconf(void);
@@ -63,6 +69,7 @@ diskconf(void)
        size_t  len;
        char    *p;
        dev_t   tmpdev;
+       extern uint8_t *bootmac;
 
        if (*boot_file != '\0')
                printf("bootfile: %s\n", boot_file);
@@ -77,6 +84,22 @@ diskconf(void)
                bootdv = parsedisk(boot_file, len, 0, &tmpdev);
        }
 
+#if defined(NFSCLIENT)
+       if (bootmac) {
+               struct ifnet *ifp;
+
+               TAILQ_FOREACH(ifp, &ifnet, if_list) {
+                       if (ifp->if_type == IFT_ETHER &&
+                           memcmp(bootmac, ((struct arpcom *)ifp)->ac_enaddr,
+                           ETHER_ADDR_LEN) == 0)
+                               break;
+               }
+               if (ifp)
+                       bootdv = parsedisk(ifp->if_xname, strlen(ifp->if_xname),
+                           0, &tmpdev);
+       }
+#endif
+
        if (bootdv != NULL)
                printf("boot device: %s\n", bootdv->dv_xname);
        else
index 4fbb11c..ac3a9f6 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.28 2018/01/31 23:23:16 kettenis Exp $ */
+/* $OpenBSD: machdep.c,v 1.29 2018/02/06 20:35:21 naddy Exp $ */
 /*
  * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
  *
@@ -52,6 +52,8 @@
 char *boot_args = NULL;
 char *boot_file = "";
 
+uint8_t *bootmac = NULL;
+
 extern uint64_t esym;
 
 int stdout_node = 0;
@@ -778,16 +780,23 @@ initarm(struct arm64_bootparams *abp)
 
        node = fdt_find_node("/chosen");
        if (node != NULL) {
-               char *args, *duid, *prop;
+               char *prop;
                int len;
+               static uint8_t lladdr[6];
 
-               len = fdt_node_property(node, "bootargs", &args);
+               len = fdt_node_property(node, "bootargs", &prop);
                if (len > 0)
-                       collect_kernel_args(args);
+                       collect_kernel_args(prop);
 
-               len = fdt_node_property(node, "openbsd,bootduid", &duid);
+               len = fdt_node_property(node, "openbsd,bootduid", &prop);
                if (len == sizeof(bootduid))
-                       memcpy(bootduid, duid, sizeof(bootduid));
+                       memcpy(bootduid, prop, sizeof(bootduid));
+
+               len = fdt_node_property(node, "openbsd,bootmac", &prop);
+               if (len == sizeof(lladdr)) {
+                       memcpy(lladdr, prop, sizeof(lladdr));
+                       bootmac = lladdr;
+               }
 
                len = fdt_node_property(node, "openbsd,uefi-mmap-start", &prop);
                if (len == sizeof(mmap_start))
index d9f9b34..19f172d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: conf.c,v 1.11 2018/01/30 20:19:06 naddy Exp $ */
+/*     $OpenBSD: conf.c,v 1.12 2018/02/06 20:35:21 naddy Exp $ */
 
 /*
  * Copyright (c) 1996 Michael Shalayeff
@@ -36,7 +36,7 @@
 #include "efidev.h"
 #include "efipxe.h"
 
-const char version[] = "0.10";
+const char version[] = "0.11";
 int    debug = 0;
 
 struct fs_ops file_system[] = {
index c865419..8618a6b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: efiboot.c,v 1.14 2018/01/21 21:35:34 patrick Exp $    */
+/*     $OpenBSD: efiboot.c,v 1.15 2018/02/06 20:35:21 naddy Exp $      */
 
 /*
  * Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
@@ -355,6 +355,7 @@ efi_framebuffer(void)
            "simple-framebuffer", strlen("simple-framebuffer") + 1);
 }
 
+char *bootmac = NULL;
 static EFI_GUID fdt_guid = FDT_TABLE_GUID;
 
 #define        efi_guidcmp(_a, _b)     memcmp((_a), (_b), sizeof(EFI_GUID))
@@ -393,6 +394,10 @@ efi_makebootargs(char *bootargs)
                    sizeof(bootduid));
        }
 
+       /* Pass netboot interface address. */
+       if (bootmac)
+               fdt_node_add_property(node, "openbsd,bootmac", bootmac, 6);
+
        /* Pass EFI system table. */
        fdt_node_add_property(node, "openbsd,uefi-system-table",
            &uefi_system_table, sizeof(uefi_system_table));
index d871744..688e1cb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: efipxe.c,v 1.2 2018/01/30 20:19:06 naddy Exp $        */
+/*     $OpenBSD: efipxe.c,v 1.3 2018/02/06 20:35:21 naddy Exp $        */
 /*
  * Copyright (c) 2017 Patrick Wildt <patrick@blueri.se>
  *
@@ -30,6 +30,7 @@
 extern EFI_BOOT_SERVICES       *BS;
 extern EFI_DEVICE_PATH         *efi_bootdp;
 
+extern char                    *bootmac;
 static UINT8                    boothw[16];
 static EFI_IP_ADDRESS           bootip, servip;
 static EFI_GUID                         devp_guid = DEVICE_PATH_PROTOCOL;
@@ -95,6 +96,7 @@ efi_pxeprobe(void)
                        memcpy(&bootip, dhcp->BootpYiAddr, sizeof(bootip));
                        memcpy(&servip, dhcp->BootpSiAddr, sizeof(servip));
                        memcpy(boothw, dhcp->BootpHwAddr, sizeof(boothw));
+                       bootmac = boothw;
                        PXE = pxe;
                        break;
                }