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 PXE support.



details:   https://anonhg.NetBSD.org/src/rev/2c15b03c5d83
branches:  trunk
changeset: 366568:2c15b03c5d83
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon Sep 03 00:04:02 2018 +0000

description:
Add PXE support.

diffstat:

 sys/stand/efiboot/Makefile.efiboot |   16 +-
 sys/stand/efiboot/boot.c           |    6 +-
 sys/stand/efiboot/conf.c           |   11 +-
 sys/stand/efiboot/dev_net.c        |   96 ++++++
 sys/stand/efiboot/devopen.c        |    8 +-
 sys/stand/efiboot/efiboot.c        |   12 +-
 sys/stand/efiboot/efiboot.h        |   18 +-
 sys/stand/efiboot/efigetsecs.c     |   81 +++++
 sys/stand/efiboot/efinet.c         |  529 +++++++++++++++++++++++++++++++++++++
 sys/stand/efiboot/efinet.h         |   29 ++
 sys/stand/efiboot/efipxe.c         |  141 +++++++++
 sys/stand/efiboot/version          |    3 +-
 12 files changed, 930 insertions(+), 20 deletions(-)

diffs (truncated from 1136 to 300 lines):

diff -r 32a690f77ac0 -r 2c15b03c5d83 sys/stand/efiboot/Makefile.efiboot
--- a/sys/stand/efiboot/Makefile.efiboot        Sun Sep 02 23:54:25 2018 +0000
+++ b/sys/stand/efiboot/Makefile.efiboot        Mon Sep 03 00:04:02 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.2 2018/08/26 21:28:18 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.3 2018/09/03 00:04:02 jmcneill Exp $
 
 S=             ${.CURDIR}/../../..
 
@@ -21,8 +21,8 @@
 
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=       crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
-SOURCES+=      boot.c conf.c console.c devopen.c exec.c panic.c prompt.c
-SOURCES+=      efiboot.c efichar.c efidev.c efifdt.c efifile.c efiblock.c
+SOURCES+=      boot.c conf.c console.c dev_net.c devopen.c exec.c panic.c prompt.c
+SOURCES+=      efiboot.c efichar.c efidev.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=     -I${S}/external/bsd/libfdt/dist
@@ -68,12 +68,12 @@
 CPPFLAGS+= -DHEAP_VARIABLE
 #CPPFLAGS+= -DSUPPORT_CD9660
 CPPFLAGS+= -D"devb2cdb(bno)=(bno)"
-#CPPFLAGS+= -DSUPPORT_DOSFS
+CPPFLAGS+= -DSUPPORT_DOSFS
 #CPPFLAGS+= -DSUPPORT_EXT2FS
-#CPPFLAGS+= -DSUPPORT_BOOTP
-#CPPFLAGS+= -DSUPPORT_DHCP
+CPPFLAGS+= -DSUPPORT_BOOTP
+CPPFLAGS+= -DSUPPORT_DHCP
 #CPPFLAGS+= -DSUPPORT_NFS
-#CPPFLAGS+= -DSUPPORT_TFTP
+CPPFLAGS+= -DSUPPORT_TFTP
 CPPFLAGS+= -DLIBSA_ENABLE_LS_OP
 
 #CPPFLAGS+= -DARP_DEBUG
@@ -92,7 +92,7 @@
 SA_AS= library
 SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes"
 SAMISCMAKEFLAGS+="SA_USE_CREAD=yes"
-#SAMISCMAKEFLAGS+="SA_INCLUDE_NET=yes"
+SAMISCMAKEFLAGS+="SA_INCLUDE_NET=yes"
 SAMISCMAKEFLAGS+="SA_ENABLE_LS_OP=yes"
 .include "${S}/lib/libsa/Makefile.inc"
 LIBSA= ${SALIB}
diff -r 32a690f77ac0 -r 2c15b03c5d83 sys/stand/efiboot/boot.c
--- a/sys/stand/efiboot/boot.c  Sun Sep 02 23:54:25 2018 +0000
+++ b/sys/stand/efiboot/boot.c  Mon Sep 03 00:04:02 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.3 2018/08/26 21:28:18 jmcneill Exp $        */
+/*     $NetBSD: boot.c,v 1.4 2018/09/03 00:04:02 jmcneill Exp $        */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -63,7 +63,7 @@
 const struct boot_command commands[] = {
        { "boot",       command_boot,           "boot [fsN:][filename] [args]\n     (ex. \"fs0:\\netbsd.old -s\"" },
        { "dev",        command_dev,            "dev" },
-       { "ls",         command_ls,             "ls [hdNn:/path]\n" },
+       { "ls",         command_ls,             "ls [hdNn:/path]" },
        { "version",    command_version,        "version" },
        { "help",       command_help,           "help|?" },
        { "?",          command_help,           NULL },
@@ -99,6 +99,8 @@
                set_default_device(arg);
        } else {
                efi_block_show();
+               efi_net_show();
+               efi_pxe_show();
        }
 
        if (strlen(default_device) > 0) {
diff -r 32a690f77ac0 -r 2c15b03c5d83 sys/stand/efiboot/conf.c
--- a/sys/stand/efiboot/conf.c  Sun Sep 02 23:54:25 2018 +0000
+++ b/sys/stand/efiboot/conf.c  Mon Sep 03 00:04:02 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: conf.c,v 1.2 2018/08/26 21:28:18 jmcneill Exp $ */
+/* $NetBSD: conf.c,v 1.3 2018/09/03 00:04:02 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -33,20 +33,29 @@
 #include <lib/libsa/stand.h>
 #include <lib/libsa/ufs.h>
 #include <lib/libsa/dosfs.h>
+#include <lib/libsa/tftp.h>
+#include <lib/libsa/net.h>
+#include <lib/libsa/dev_net.h>
 
 struct devsw devsw[] = {
        { "efifile", efi_file_strategy, efi_file_open, efi_file_close, noioctl },
        { "efiblock", efi_block_strategy, efi_block_open, efi_block_close, noioctl },
+       { "net", net_strategy, net_open, net_close, noioctl },
 };
 int ndevs = __arraycount(devsw);
 
 struct netif_driver *netif_drivers[] = {
+       &efinetif,
 };
 int n_netif_drivers = __arraycount(netif_drivers);
 
 struct fs_ops file_system[] = {
+       FS_OPS(null),
        FS_OPS(ffsv1),
        FS_OPS(ffsv2),
        FS_OPS(dosfs),
 };
 int nfsys = __arraycount(file_system);
+
+struct fs_ops null_fs_ops = FS_OPS(null);
+struct fs_ops tftp_fs_ops = FS_OPS(tftp);
diff -r 32a690f77ac0 -r 2c15b03c5d83 sys/stand/efiboot/dev_net.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/stand/efiboot/dev_net.c       Mon Sep 03 00:04:02 2018 +0000
@@ -0,0 +1,96 @@
+/*     $NetBSD: dev_net.c,v 1.1 2018/09/03 00:04:02 jmcneill Exp $     */
+
+/*-
+ * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "efiboot.h"
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+
+#include <lib/libsa/net.h>
+#include <lib/libsa/netif.h>
+#include <lib/libsa/bootparam.h>
+#include <lib/libsa/bootp.h>
+
+#include "dev_net.h"
+
+static int     net_socket = -1;
+
+int
+net_open(struct open_file *f, ...)
+{
+       va_list ap;
+       char *devname;
+       int error;
+
+       va_start(ap, f);
+       devname = va_arg(ap, char *);
+       va_end(ap);
+
+       if (net_socket < 0)
+               net_socket = netif_open(devname);
+       if (net_socket < 0)
+               return ENXIO;
+
+       if (myip.s_addr == INADDR_ANY) {
+               bootp(net_socket);
+
+               if (myip.s_addr == INADDR_ANY) {
+                       error = EIO;
+                       goto fail;
+               }
+
+               printf("boot: client ip: %s\n", inet_ntoa(myip));
+               printf("boot: server ip: %s\n", inet_ntoa(rootip));
+       }
+
+       f->f_devdata = &net_socket;
+
+       return 0;
+
+fail:
+       printf("net_open failed: %d\n", error);
+       netif_close(net_socket);
+       net_socket = -1;
+       return error;   
+}
+
+int
+net_close(struct open_file *f)
+{
+       f->f_devdata = NULL;
+
+       return 0;
+}
+
+int
+net_strategy(void *devdata, int rw, daddr_t dblk, size_t size, void *buf, size_t *rsize)
+{
+       return EIO;
+}
diff -r 32a690f77ac0 -r 2c15b03c5d83 sys/stand/efiboot/devopen.c
--- a/sys/stand/efiboot/devopen.c       Sun Sep 02 23:54:25 2018 +0000
+++ b/sys/stand/efiboot/devopen.c       Mon Sep 03 00:04:02 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: devopen.c,v 1.2 2018/08/26 21:28:18 jmcneill Exp $ */
+/* $NetBSD: devopen.c,v 1.3 2018/09/03 00:04:02 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -35,7 +35,11 @@
 {
        int error;
 
-       error = efi_block_open(f, fname, file);
+       error = efi_net_open(f, fname, file);
+       file_system[0] = error ? null_fs_ops : tftp_fs_ops;
+
+       if (error)
+               error = efi_block_open(f, fname, file);
        if (error)
                error = efi_file_open(f, fname);
 
diff -r 32a690f77ac0 -r 2c15b03c5d83 sys/stand/efiboot/efiboot.c
--- a/sys/stand/efiboot/efiboot.c       Sun Sep 02 23:54:25 2018 +0000
+++ b/sys/stand/efiboot/efiboot.c       Mon Sep 03 00:04:02 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.4 2018/08/26 21:28:18 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.5 2018/09/03 00:04:02 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -31,7 +31,7 @@
 #include "efiblock.h"
 #include "efifdt.h"
 
-EFI_HANDLE efi_ih;
+EFI_HANDLE IH;
 EFI_DEVICE_PATH *efi_bootdp;
 EFI_LOADED_IMAGE *efi_li;
 
@@ -47,7 +47,7 @@
        EFI_STATUS status;
        u_int sz = EFI_SIZE_TO_PAGES(heap_size);
 
-       efi_ih = imageHandle;
+       IH = imageHandle;
 
        InitializeLib(imageHandle, systemTable);
 
@@ -76,6 +76,8 @@
        efi_fdt_probe();
        efi_file_system_probe();
        efi_block_probe();
+       efi_pxe_probe();
+       efi_net_probe();
 
        boot();
 
@@ -91,7 +93,7 @@
 
        LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
 
-       status = uefi_call_wrapper(BS->ExitBootServices, 2, efi_ih, mapkey);
+       status = uefi_call_wrapper(BS->ExitBootServices, 2, IH, mapkey);
        if (EFI_ERROR(status))
                printf("WARNING: ExitBootServices failed\n");
 }
@@ -101,7 +103,7 @@
 {
        EFI_STATUS status;
 
-       status = uefi_call_wrapper(BS->Exit, 4, efi_ih, EFI_ABORTED, 0, NULL);
+       status = uefi_call_wrapper(BS->Exit, 4, IH, EFI_ABORTED, 0, NULL);
        if (EFI_ERROR(status))
                printf("WARNING: Exit failed\n");
 }
diff -r 32a690f77ac0 -r 2c15b03c5d83 sys/stand/efiboot/efiboot.h
--- a/sys/stand/efiboot/efiboot.h       Sun Sep 02 23:54:25 2018 +0000
+++ b/sys/stand/efiboot/efiboot.h       Mon Sep 03 00:04:02 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: efiboot.h,v 1.2 2018/08/26 21:28:18 jmcneill Exp $     */
+/*     $NetBSD: efiboot.h,v 1.3 2018/09/03 00:04:02 jmcneill Exp $     */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -40,6 +40,10 @@
        const char *c_help;
 };



Home | Main Index | Thread Index | Old Index