Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/stand/efiboot Add support for loading kernels over NFS.



details:   https://anonhg.NetBSD.org/src/rev/5484e4ea5bc5
branches:  trunk
changeset: 445879:5484e4ea5bc5
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Thu Nov 15 23:52:33 2018 +0000

description:
Add support for loading kernels over NFS.

diffstat:

 sys/stand/efiboot/boot.c    |  15 +++++++--------
 sys/stand/efiboot/conf.c    |   4 +++-
 sys/stand/efiboot/dev_net.c |  15 ++++++++++++++-
 sys/stand/efiboot/devopen.c |   9 +++++++--
 sys/stand/efiboot/efiboot.h |  10 ++++++++--
 sys/stand/efiboot/efifdt.c  |   5 ++++-
 sys/stand/efiboot/efinet.c  |  33 +++++++++++++++++++++++++++++----
 sys/stand/efiboot/efipxe.c  |  17 +----------------
 sys/stand/efiboot/version   |   3 ++-
 9 files changed, 75 insertions(+), 36 deletions(-)

diffs (truncated from 327 to 300 lines):

diff -r 3ccd5372f3cd -r 5484e4ea5bc5 sys/stand/efiboot/boot.c
--- a/sys/stand/efiboot/boot.c  Thu Nov 15 23:01:45 2018 +0000
+++ b/sys/stand/efiboot/boot.c  Thu Nov 15 23:52:33 2018 +0000
@@ -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 <nonaka%netbsd.org@localhost>
@@ -72,7 +72,7 @@
 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 @@
        } else {
                efi_block_show();
                efi_net_show();
-               efi_pxe_show();
        }
 
        if (strlen(default_device) > 0) {
@@ -323,9 +322,9 @@
 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 @@
        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 @@
        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 */
diff -r 3ccd5372f3cd -r 5484e4ea5bc5 sys/stand/efiboot/conf.c
--- a/sys/stand/efiboot/conf.c  Thu Nov 15 23:01:45 2018 +0000
+++ b/sys/stand/efiboot/conf.c  Thu Nov 15 23:52:33 2018 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
 
 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);
diff -r 3ccd5372f3cd -r 5484e4ea5bc5 sys/stand/efiboot/dev_net.c
--- a/sys/stand/efiboot/dev_net.c       Thu Nov 15 23:01:45 2018 +0000
+++ b/sys/stand/efiboot/dev_net.c       Thu Nov 15 23:52:33 2018 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
 
                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;
diff -r 3ccd5372f3cd -r 5484e4ea5bc5 sys/stand/efiboot/devopen.c
--- a/sys/stand/efiboot/devopen.c       Thu Nov 15 23:01:45 2018 +0000
+++ b/sys/stand/efiboot/devopen.c       Thu Nov 15 23:52:33 2018 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -36,7 +36,12 @@
        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);
diff -r 3ccd5372f3cd -r 5484e4ea5bc5 sys/stand/efiboot/efiboot.h
--- a/sys/stand/efiboot/efiboot.h       Thu Nov 15 23:01:45 2018 +0000
+++ b/sys/stand/efiboot/efiboot.h       Thu Nov 15 23:52:33 2018 +0000
@@ -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 <nonaka%netbsd.org@localhost>
@@ -33,6 +33,7 @@
 #include <lib/libkern/libkern.h>
 
 #include <loadfile.h>
+#include <net.h>
 
 #include "efiboot_machdep.h"
 
@@ -45,6 +46,7 @@
 /* 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_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 */
diff -r 3ccd5372f3cd -r 5484e4ea5bc5 sys/stand/efiboot/efifdt.c
--- a/sys/stand/efiboot/efifdt.c        Thu Nov 15 23:01:45 2018 +0000
+++ b/sys/stand/efiboot/efifdt.c        Thu Nov 15 23:52:33 2018 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -194,6 +194,7 @@
 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 @@
                default:
                        break;
                }
+       } else if (efi_net_get_booted_macaddr(macaddr) == 0) {
+               fdt_setprop(fdt_data, chosen, "netbsd,booted-mac-address", macaddr, sizeof(macaddr));
        }
 }
 
diff -r 3ccd5372f3cd -r 5484e4ea5bc5 sys/stand/efiboot/efinet.c
--- a/sys/stand/efiboot/efinet.c        Thu Nov 15 23:01:45 2018 +0000
+++ b/sys/stand/efiboot/efinet.c        Thu Nov 15 23:52:33 2018 +0000
@@ -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 @@
                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 @@
 }
 
 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 @@
        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 @@
        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;
 }
diff -r 3ccd5372f3cd -r 5484e4ea5bc5 sys/stand/efiboot/efipxe.c
--- a/sys/stand/efiboot/efipxe.c        Thu Nov 15 23:01:45 2018 +0000
+++ b/sys/stand/efiboot/efipxe.c        Thu Nov 15 23:52:33 2018 +0000
@@ -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 @@
        }
 }
 
-void
-efi_pxe_show(void)
-{
-       const struct efipxeinfo *epi;
-       UINT32 i, n;



Home | Main Index | Thread Index | Old Index