Module Name: src Committed By: jmcneill Date: Thu Nov 15 23:52:33 UTC 2018
Modified Files: src/sys/stand/efiboot: boot.c conf.c dev_net.c devopen.c efiboot.h efifdt.c efinet.c efipxe.c version Log Message: Add support for loading kernels over NFS. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/stand/efiboot/boot.c \ src/sys/stand/efiboot/efifdt.c cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/conf.c \ src/sys/stand/efiboot/devopen.c src/sys/stand/efiboot/efinet.c cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/dev_net.c \ src/sys/stand/efiboot/efipxe.c cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/efiboot.h cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/version Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/stand/efiboot/boot.c diff -u src/sys/stand/efiboot/boot.c:1.13 src/sys/stand/efiboot/boot.c:1.14 --- src/sys/stand/efiboot/boot.c:1.13 Fri Nov 2 01:22:39 2018 +++ src/sys/stand/efiboot/boot.c Thu Nov 15 23:52:33 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: boot.c,v 1.13 2018/11/02 01:22:39 jmcneill Exp $ */ +/* $NetBSD: boot.c,v 1.14 2018/11/15 23:52:33 jmcneill Exp $ */ /*- * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org> @@ -72,7 +72,7 @@ static const char *efi_memory_type[] = { static char default_device[32]; static char initrd_path[255]; static char dtb_path[255]; -static char bootfile[255]; +static char netbsd_path[255]; #define DEFTIMEOUT 5 #define DEFFILENAME names[0] @@ -146,7 +146,6 @@ command_dev(char *arg) } else { efi_block_show(); efi_net_show(); - efi_pxe_show(); } if (strlen(default_device) > 0) { @@ -323,9 +322,9 @@ get_dtb_path(void) int set_bootfile(const char *arg) { - if (strlen(arg) + 1 > sizeof(bootfile)) + if (strlen(arg) + 1 > sizeof(netbsd_path)) return ERANGE; - strcpy(bootfile, arg); + strcpy(netbsd_path, arg); return 0; } @@ -388,7 +387,7 @@ boot(void) print_banner(); printf("Press return to boot now, any other key for boot prompt\n"); - if (bootfile[0] != '\0') + if (netbsd_path[0] != '\0') currname = -1; else currname = 0; @@ -396,13 +395,13 @@ boot(void) for (; currname < (int)NUMNAMES; currname++) { if (currname >= 0) set_bootfile(names[currname]); - printf("booting %s - starting in ", bootfile); + printf("booting %s - starting in ", netbsd_path); c = awaitkey(DEFTIMEOUT, 1); if (c != '\r' && c != '\n' && c != '\0') bootprompt(); /* does not return */ - exec_netbsd(bootfile, ""); + exec_netbsd(netbsd_path, ""); } bootprompt(); /* does not return */ Index: src/sys/stand/efiboot/efifdt.c diff -u src/sys/stand/efiboot/efifdt.c:1.13 src/sys/stand/efiboot/efifdt.c:1.14 --- src/sys/stand/efiboot/efifdt.c:1.13 Fri Nov 2 01:22:39 2018 +++ src/sys/stand/efiboot/efifdt.c Thu Nov 15 23:52:33 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: efifdt.c,v 1.13 2018/11/02 01:22:39 jmcneill Exp $ */ +/* $NetBSD: efifdt.c,v 1.14 2018/11/15 23:52:33 jmcneill Exp $ */ /*- * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca> @@ -194,6 +194,7 @@ void efi_fdt_bootargs(const char *bootargs) { struct efi_block_part *bpart = efi_block_boot_part(); + uint8_t macaddr[6]; int chosen; chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH); @@ -229,6 +230,8 @@ efi_fdt_bootargs(const char *bootargs) default: break; } + } else if (efi_net_get_booted_macaddr(macaddr) == 0) { + fdt_setprop(fdt_data, chosen, "netbsd,booted-mac-address", macaddr, sizeof(macaddr)); } } Index: src/sys/stand/efiboot/conf.c diff -u src/sys/stand/efiboot/conf.c:1.3 src/sys/stand/efiboot/conf.c:1.4 --- src/sys/stand/efiboot/conf.c:1.3 Mon Sep 3 00:04:02 2018 +++ src/sys/stand/efiboot/conf.c Thu Nov 15 23:52:33 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: conf.c,v 1.3 2018/09/03 00:04:02 jmcneill Exp $ */ +/* $NetBSD: conf.c,v 1.4 2018/11/15 23:52:33 jmcneill Exp $ */ /*- * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca> @@ -34,6 +34,7 @@ #include <lib/libsa/ufs.h> #include <lib/libsa/dosfs.h> #include <lib/libsa/tftp.h> +#include <lib/libsa/nfs.h> #include <lib/libsa/net.h> #include <lib/libsa/dev_net.h> @@ -59,3 +60,4 @@ int nfsys = __arraycount(file_system); struct fs_ops null_fs_ops = FS_OPS(null); struct fs_ops tftp_fs_ops = FS_OPS(tftp); +struct fs_ops nfs_fs_ops = FS_OPS(nfs); Index: src/sys/stand/efiboot/devopen.c diff -u src/sys/stand/efiboot/devopen.c:1.3 src/sys/stand/efiboot/devopen.c:1.4 --- src/sys/stand/efiboot/devopen.c:1.3 Mon Sep 3 00:04:02 2018 +++ src/sys/stand/efiboot/devopen.c Thu Nov 15 23:52:33 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: devopen.c,v 1.3 2018/09/03 00:04:02 jmcneill Exp $ */ +/* $NetBSD: devopen.c,v 1.4 2018/11/15 23:52:33 jmcneill Exp $ */ /*- * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca> @@ -36,7 +36,12 @@ devopen(struct open_file *f, const char int error; error = efi_net_open(f, fname, file); - file_system[0] = error ? null_fs_ops : tftp_fs_ops; + if (error) + file_system[0] = null_fs_ops; + else if (rootpath[0] != '\0') + file_system[0] = nfs_fs_ops; + else + file_system[0] = tftp_fs_ops; if (error) error = efi_block_open(f, fname, file); Index: src/sys/stand/efiboot/efinet.c diff -u src/sys/stand/efiboot/efinet.c:1.3 src/sys/stand/efiboot/efinet.c:1.4 --- src/sys/stand/efiboot/efinet.c:1.3 Tue Sep 4 21:29:54 2018 +++ src/sys/stand/efiboot/efinet.c Thu Nov 15 23:52:33 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: efinet.c,v 1.3 2018/09/04 21:29:54 jmcneill Exp $ */ +/* $NetBSD: efinet.c,v 1.4 2018/11/15 23:52:33 jmcneill Exp $ */ /*- * Copyright (c) 2001 Doug Rabson @@ -465,7 +465,7 @@ efi_net_show(void) eni = dif->dif_private; net = eni->net; - printf("net net%d", dif->dif_unit); + printf("net%d", dif->dif_unit); if (net->Mode != NULL) { for (UINT32 x = 0; x < net->Mode->HwAddressSize; x++) { printf("%c%02x", x == 0 ? ' ' : ':', @@ -501,6 +501,27 @@ efi_net_get_booted_interface_unit(void) } int +efi_net_get_booted_macaddr(uint8_t *mac) +{ + const struct netif_dif *dif; + const struct efinetinfo *eni; + EFI_SIMPLE_NETWORK *net; + int i; + + for (i = 0; i < efinetif.netif_nifs; i++) { + dif = &efinetif.netif_ifs[i]; + eni = dif->dif_private; + net = eni->net; + if (eni->bootdev && net->Mode != NULL && net->Mode->HwAddressSize == 6) { + memcpy(mac, net->Mode->PermanentAddress.Addr, 6); + return 0; + } + } + + return -1; +} + +int efi_net_open(struct open_file *f, ...) { char **file, pathbuf[PATH_MAX], *default_device, *path, *ep; @@ -508,7 +529,7 @@ efi_net_open(struct open_file *f, ...) struct devdesc desc; intmax_t dev; va_list ap; - int n; + int n, error; va_start(ap, f); fname = va_arg(ap, const char *); @@ -551,5 +572,9 @@ efi_net_open(struct open_file *f, ...) strlcpy(desc.d_name, "net", sizeof(desc.d_name)); desc.d_unit = dev; - return DEV_OPEN(f->f_dev)(f, &desc); + error = DEV_OPEN(f->f_dev)(f, &desc); + if (error) + return error; + + return 0; } Index: src/sys/stand/efiboot/dev_net.c diff -u src/sys/stand/efiboot/dev_net.c:1.1 src/sys/stand/efiboot/dev_net.c:1.2 --- src/sys/stand/efiboot/dev_net.c:1.1 Mon Sep 3 00:04:02 2018 +++ src/sys/stand/efiboot/dev_net.c Thu Nov 15 23:52:33 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: dev_net.c,v 1.1 2018/09/03 00:04:02 jmcneill Exp $ */ +/* $NetBSD: dev_net.c,v 1.2 2018/11/15 23:52:33 jmcneill Exp $ */ /*- * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca> @@ -37,6 +37,7 @@ #include <lib/libsa/netif.h> #include <lib/libsa/bootparam.h> #include <lib/libsa/bootp.h> +#include <lib/libsa/nfs.h> #include "dev_net.h" @@ -68,6 +69,18 @@ net_open(struct open_file *f, ...) printf("boot: client ip: %s\n", inet_ntoa(myip)); printf("boot: server ip: %s\n", inet_ntoa(rootip)); + if (rootpath[0] != '\0') + printf("boot: server path: %s\n", rootpath); + if (bootfile[0] != '\0') + printf("boot: file name: %s\n", bootfile); + } + + if (rootpath[0] != '\0') { + error = nfs_mount(net_socket, rootip, rootpath); + if (error) { + printf("NFS mount error=%d\n", errno); + goto fail; + } } f->f_devdata = &net_socket; Index: src/sys/stand/efiboot/efipxe.c diff -u src/sys/stand/efiboot/efipxe.c:1.1 src/sys/stand/efiboot/efipxe.c:1.2 --- src/sys/stand/efiboot/efipxe.c:1.1 Mon Sep 3 00:04:02 2018 +++ src/sys/stand/efiboot/efipxe.c Thu Nov 15 23:52:33 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: efipxe.c,v 1.1 2018/09/03 00:04:02 jmcneill Exp $ */ +/* $NetBSD: efipxe.c,v 1.2 2018/11/15 23:52:33 jmcneill Exp $ */ /* $OpenBSD: efipxe.c,v 1.3 2018/01/30 20:19:06 naddy Exp $ */ /* @@ -112,21 +112,6 @@ efi_pxe_probe(void) } } -void -efi_pxe_show(void) -{ - const struct efipxeinfo *epi; - UINT32 i, n; - - n = 0; - TAILQ_FOREACH(epi, &efi_pxelist, list) { - printf("pxe pxe%d", n++); - for (i = 0; i < epi->addrsz; i++) - printf("%c%02x", i == 0 ? ' ' : ':', epi->mac.Addr[i]); - printf("\n"); - } -} - bool efi_pxe_match_booted_interface(const EFI_MAC_ADDRESS *mac, UINT32 addrsz) { Index: src/sys/stand/efiboot/efiboot.h diff -u src/sys/stand/efiboot/efiboot.h:1.8 src/sys/stand/efiboot/efiboot.h:1.9 --- src/sys/stand/efiboot/efiboot.h:1.8 Fri Oct 26 20:56:35 2018 +++ src/sys/stand/efiboot/efiboot.h Thu Nov 15 23:52:33 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: efiboot.h,v 1.8 2018/10/26 20:56:35 mrg Exp $ */ +/* $NetBSD: efiboot.h,v 1.9 2018/11/15 23:52:33 jmcneill Exp $ */ /*- * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org> @@ -33,6 +33,7 @@ #include <lib/libkern/libkern.h> #include <loadfile.h> +#include <net.h> #include "efiboot_machdep.h" @@ -45,6 +46,7 @@ struct boot_command { /* conf.c */ extern struct fs_ops null_fs_ops; extern struct fs_ops tftp_fs_ops; +extern struct fs_ops nfs_fs_ops; /* boot.c */ void boot(void); @@ -82,15 +84,19 @@ int efi_device_path_depth(EFI_DEVICE_PAT int efi_device_path_ncmp(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *, int); /* efinet.c */ +struct efi_net_if { + const char *if_name; + uint8_t if_mac[6]; +}; int efi_net_open(struct open_file *, ...); void efi_net_probe(void); void efi_net_show(void); int efi_net_get_booted_interface_unit(void); +int efi_net_get_booted_macaddr(uint8_t *); extern struct netif_driver efinetif; /* efipxe.c */ void efi_pxe_probe(void); -void efi_pxe_show(void); bool efi_pxe_match_booted_interface(const EFI_MAC_ADDRESS *, UINT32); /* exec.c */ Index: src/sys/stand/efiboot/version diff -u src/sys/stand/efiboot/version:1.7 src/sys/stand/efiboot/version:1.8 --- src/sys/stand/efiboot/version:1.7 Thu Nov 1 00:43:38 2018 +++ src/sys/stand/efiboot/version Thu Nov 15 23:52:33 2018 @@ -1,4 +1,4 @@ -$NetBSD: version,v 1.7 2018/11/01 00:43:38 jmcneill Exp $ +$NetBSD: version,v 1.8 2018/11/15 23:52:33 jmcneill Exp $ NOTE ANY CHANGES YOU MAKE TO THE EFI BOOTLOADER HERE. The format of this file is important - make sure the entries are appended on end, last item @@ -11,3 +11,4 @@ is taken as the current. 1.4: Add bootfile support. 1.5: EFI runtime support. 1.6: Add GPT support. +1.7: Add NFS support.