From 9ccb13ab66011f36494f750d1a0149d0a0c9af33 Mon Sep 17 00:00:00 2001 From: naddy Date: Tue, 6 Feb 2018 20:35:21 +0000 Subject: [PATCH] Allow the kernel to recognize that it has been netbooted and to add the 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 | 25 ++++++++++++++++++++++++- sys/arch/arm64/arm64/machdep.c | 21 +++++++++++++++------ sys/arch/arm64/stand/efiboot/conf.c | 4 ++-- sys/arch/arm64/stand/efiboot/efiboot.c | 7 ++++++- sys/arch/arm64/stand/efiboot/efipxe.c | 4 +++- 5 files changed, 50 insertions(+), 11 deletions(-) diff --git a/sys/arch/arm64/arm64/autoconf.c b/sys/arch/arm64/arm64/autoconf.c index ad507aea8c7..4d5222bf02a 100644 --- a/sys/arch/arm64/arm64/autoconf.c +++ b/sys/arch/arm64/arm64/autoconf.c @@ -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. * @@ -20,9 +20,15 @@ #include #include #include +#include #include #include +#include +#include +#include +#include + #include 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 diff --git a/sys/arch/arm64/arm64/machdep.c b/sys/arch/arm64/arm64/machdep.c index 4fbb11c3419..ac3a9f6344b 100644 --- a/sys/arch/arm64/arm64/machdep.c +++ b/sys/arch/arm64/arm64/machdep.c @@ -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 * @@ -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)) diff --git a/sys/arch/arm64/stand/efiboot/conf.c b/sys/arch/arm64/stand/efiboot/conf.c index d9f9b34f1fd..19f172d7a24 100644 --- a/sys/arch/arm64/stand/efiboot/conf.c +++ b/sys/arch/arm64/stand/efiboot/conf.c @@ -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[] = { diff --git a/sys/arch/arm64/stand/efiboot/efiboot.c b/sys/arch/arm64/stand/efiboot/efiboot.c index c8654196bcf..8618a6b5ec0 100644 --- a/sys/arch/arm64/stand/efiboot/efiboot.c +++ b/sys/arch/arm64/stand/efiboot/efiboot.c @@ -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 @@ -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)); diff --git a/sys/arch/arm64/stand/efiboot/efipxe.c b/sys/arch/arm64/stand/efiboot/efipxe.c index d87174492df..688e1cb0895 100644 --- a/sys/arch/arm64/stand/efiboot/efipxe.c +++ b/sys/arch/arm64/stand/efiboot/efipxe.c @@ -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 * @@ -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; } -- 2.20.1