> Date: Mon, 29 Jan 2018 20:23:09 +0100
> From: Christian Weisgerber <[email protected]>
> 
> This allows an arm64 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.
> 
> Welcome to the OpenBSD/arm64 6.2 installation program.
> Starting non-interactive mode in 5 seconds...
> (I)nstall, (U)pgrade, (A)utoinstall or (S)hell?
> 
> There are probably too many printfs in diskconf()...
> 
> bootfile: tftp0a:/bsd
> PXE boot MAC address e0:ff:f7:00:20:3c, interface msk0
> boot device: msk0
> 
> ... but I don't know what we want there.  I'm also uncertain about
> the NFSCLIENT ifdef, but the x86 code evolved into this over a series
> of commits.
> 
> I've omitted the efiboot version bump since that would conflict
> with my other efiboot diff.

The proper Open Firmware way of doing this is to privide a "bootpath"
variable under /chosen, but that won't work for the FDT since the PCI
network interface isn't present in the tree.  So this approach is
prefectly fine with me.

ok kettenis@

> Index: arch/arm64/arm64/autoconf.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/arm64/arm64/autoconf.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 autoconf.c
> --- arch/arm64/arm64/autoconf.c       27 Jan 2018 22:55:23 -0000      1.8
> +++ arch/arm64/arm64/autoconf.c       29 Jan 2018 17:53:28 -0000
> @@ -20,9 +20,15 @@
>  #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);
> @@ -75,6 +82,27 @@ diskconf(void)
>               else
>                       len = strlen(boot_file);
>               bootdv = parsedisk(boot_file, len, 0, &tmpdev);
> +     }
> +
> +     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) {
> +#if defined(NFSCLIENT)
> +                     printf("PXE boot MAC address %s, interface %s\n",
> +                         ether_sprintf(bootmac), ifp->if_xname);
> +                     bootdv = parsedisk(ifp->if_xname, strlen(ifp->if_xname),
> +                         0, &tmpdev);
> +#endif
> +             } else
> +                     printf("PXE boot MAC address %s, interface %s\n",
> +                         ether_sprintf(bootmac), "unknown");
>       }
>  
>       if (bootdv != NULL)
> Index: arch/arm64/arm64/machdep.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/arm64/arm64/machdep.c,v
> retrieving revision 1.27
> diff -u -p -r1.27 machdep.c
> --- arch/arm64/arm64/machdep.c        28 Jan 2018 13:17:45 -0000      1.27
> +++ arch/arm64/arm64/machdep.c        29 Jan 2018 16:38:32 -0000
> @@ -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: arch/arm64/stand/efiboot/efiboot.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/arm64/stand/efiboot/efiboot.c,v
> retrieving revision 1.14
> diff -u -p -r1.14 efiboot.c
> --- arch/arm64/stand/efiboot/efiboot.c        21 Jan 2018 21:35:34 -0000      
> 1.14
> +++ arch/arm64/stand/efiboot/efiboot.c        28 Jan 2018 15:06:35 -0000
> @@ -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))
> @@ -392,6 +393,10 @@ efi_makebootargs(char *bootargs)
>               fdt_node_add_property(node, "openbsd,bootduid", bootduid,
>                   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",
> Index: arch/arm64/stand/efiboot/efipxe.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/arm64/stand/efiboot/efipxe.c,v
> retrieving revision 1.1
> diff -u -p -r1.1 efipxe.c
> --- arch/arm64/stand/efiboot/efipxe.c 21 Jan 2018 21:35:34 -0000      1.1
> +++ arch/arm64/stand/efiboot/efipxe.c 28 Jan 2018 15:04:31 -0000
> @@ -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;
>               }
> -- 
> khristian "naddy" Weisgerber                          [email protected]
> 
> 

Reply via email to