Source-Changes-HG archive

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

[src/sommerfeld_i386mp_1]: src/sys/arch/i386/stand/pxeboot Change scan step f...



details:   https://anonhg.NetBSD.org/src/rev/8a5586c3dae6
branches:  sommerfeld_i386mp_1
changeset: 482509:8a5586c3dae6
user:      kanaoka <kanaoka%NetBSD.org@localhost>
date:      Tue Mar 26 08:02:06 2002 +0000

description:
Change scan step from 16 to 2, when pxe_init() check the presence of PXE.
This change improve checking the presence of PXE.

diffstat:

 sys/arch/i386/stand/pxeboot/pxe.c |  479 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 479 insertions(+), 0 deletions(-)

diffs (truncated from 483 to 300 lines):

diff -r 782ff521d269 -r 8a5586c3dae6 sys/arch/i386/stand/pxeboot/pxe.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/stand/pxeboot/pxe.c Tue Mar 26 08:02:06 2002 +0000
@@ -0,0 +1,479 @@
+/*     $NetBSD: pxe.c,v 1.4.2.2 2002/03/26 08:02:06 kanaoka Exp $      */
+
+/*
+ * Copyright 2001 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Jason R. Thorpe for Wasabi Systems, Inc.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed for the NetBSD Project by
+ *     Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ *    or promote products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
+ * 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.
+ */
+
+/*      
+ * Copyright (c) 2000 Alfred Perlstein <alfred%freebsd.org@localhost>
+ * All rights reserved.
+ * Copyright (c) 2000 Paul Saab <ps%freebsd.org@localhost>
+ * All rights reserved.
+ * Copyright (c) 2000 John Baldwin <jhb%freebsd.org@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 AUTHOR 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 AUTHOR 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. 
+ */
+
+/*
+ * Support for the Intel Preboot Execution Environment (PXE).
+ *
+ * PXE provides a UDP implementation as well as a UNDI network device
+ * driver.  UNDI is much more complicated to use than PXE UDP, so we
+ * use PXE UDP as a cheap and easy way to get PXE support.
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#ifdef _STANDALONE
+#include <lib/libkern/libkern.h>
+#else
+#include <string.h>
+#endif
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/udp.h>
+#include <netinet/udp_var.h>
+
+#include <net/if_ether.h>
+
+#include <lib/libsa/stand.h>
+#include <lib/libsa/net.h>
+#include <lib/libsa/netif.h>
+#include <lib/libsa/bootp.h>
+
+#include <libi386.h>
+#include <bootinfo.h>
+
+#include "pxeboot.h"
+#include "pxe.h"
+
+void   (*pxe_call)(u_int16_t);
+
+void   pxecall_bangpxe(u_int16_t);     /* pxe_call.S */
+void   pxecall_pxenv(u_int16_t);       /* pxe_call.S */
+
+char pxe_command_buf[256];
+
+BOOTPLAYER bootplayer;
+
+/*****************************************************************************
+ * This section is a replacement for libsa/udp.c
+ *****************************************************************************/
+
+/* Caller must leave room for ethernet, ip, and udp headers in front!! */
+ssize_t
+sendudp(struct iodesc *d, void *pkt, size_t len)
+{
+       t_PXENV_UDP_WRITE *uw = (void *) pxe_command_buf;
+
+       uw->status = 0;
+
+       uw->ip = d->destip.s_addr;
+       uw->gw = gateip.s_addr;
+       uw->src_port = d->myport;
+       uw->dst_port = d->destport;
+       uw->buffer_size = len;
+       uw->buffer.segment = VTOPSEG(pkt);
+       uw->buffer.offset = VTOPOFF(pkt);
+
+       pxe_call(PXENV_UDP_WRITE);
+
+       if (uw->status != PXENV_STATUS_SUCCESS) {
+               /* XXX This happens a lot; it shouldn't. */
+               if (uw->status != PXENV_STATUS_FAILURE)
+                       printf("sendudp: PXENV_UDP_WRITE failed: 0x%x\n",
+                           uw->status);
+               return (-1);
+       }
+
+       return (len);
+}
+
+/*
+ * Receive a UDP packet and validate it for us.
+ * Caller leaves room for the headers (Ether, IP, UDP).
+ */
+ssize_t
+readudp(struct iodesc *d, void *pkt, size_t len, time_t tleft)
+{
+       t_PXENV_UDP_READ *ur = (void *) pxe_command_buf;
+       struct udphdr *uh;
+       struct ip *ip;
+
+       uh = (struct udphdr *)pkt - 1;
+       ip = (struct ip *)uh - 1;
+
+       bzero(ur, sizeof(*ur));
+
+       ur->dest_ip = d->myip.s_addr;
+       ur->d_port = d->myport;
+       ur->buffer_size = len;
+       ur->buffer.segment = VTOPSEG(pkt);
+       ur->buffer.offset = VTOPOFF(pkt);
+
+       /* XXX Timeout unused. */
+
+       pxe_call(PXENV_UDP_READ);
+
+       if (ur->status != PXENV_STATUS_SUCCESS) {
+               /* XXX This happens a lot; it shouldn't. */
+               if (ur->status != PXENV_STATUS_FAILURE)
+                       printf("readudp: PXENV_UDP_READ_failed: 0x%0x\n",
+                           ur->status);
+               return (-1);
+       }
+
+       ip->ip_src.s_addr = ur->src_ip;
+       uh->uh_sport = ur->s_port;
+       uh->uh_dport = d->myport;
+
+       return (len);
+}
+
+/*****************************************************************************
+ * PXE "netif" back-end
+ *****************************************************************************/
+
+int    pxe_netif_match(struct netif *, void *);
+int    pxe_netif_probe(struct netif *, void *);
+void   pxe_netif_init(struct iodesc *, void *);
+int    pxe_netif_get(struct iodesc *, void *, size_t, time_t);
+int    pxe_netif_put(struct iodesc *, void *, size_t);
+void   pxe_netif_end(struct netif *);
+
+struct netif_stats pxe_netif_stats;
+
+struct netif_dif pxe0_dif = {
+       0,                      /* unit */
+       1,                      /* nsel */
+       &pxe_netif_stats,
+       0,
+       0,
+};
+
+struct netif_driver pxe_netif_driver = {
+       "pxe",                  /* netif_bname */
+       pxe_netif_match,        /* match */
+       pxe_netif_probe,        /* probe */
+       pxe_netif_init,         /* init */
+       pxe_netif_get,          /* get */
+       pxe_netif_put,          /* put */
+       pxe_netif_end,          /* end */
+       &pxe0_dif,              /* netif_ifs */
+       1,                      /* netif_nifs */
+};
+
+int
+pxe_netif_match(struct netif *nif, void *machdep_hint)
+{
+
+       return (1);
+}
+
+int
+pxe_netif_probe(struct netif *nif, void *machdep_hint)
+{
+       t_PXENV_UDP_OPEN *uo = (void *) pxe_command_buf;
+
+       pxe_init();
+
+       if (pxe_call == NULL)
+               return (1);
+
+       bzero(uo, sizeof(*uo));
+
+       uo->src_ip = bootplayer.yip;
+
+       pxe_call(PXENV_UDP_OPEN);
+
+       if (uo->status != PXENV_STATUS_SUCCESS) {
+               printf("pxe_netif_probe: PXENV_UDP_OPEN failed: 0x%x\n",
+                   uo->status);
+               pxe_fini();
+               return (1);
+       }
+
+       return (0);
+}
+
+void
+pxe_netif_init(struct iodesc *desc, void *machdep_hint)
+{
+       struct netif *nif = desc->io_netif;
+
+       bcopy(bootplayer.CAddr, desc->myea, ETHER_ADDR_LEN);
+
+       /*
+        * Since the PXE BIOS has already done DHCP, make sure we
+        * don't reuse any of its transaction IDs.
+        */
+       desc->xid = bootplayer.ident;
+
+       printf("%s%d: Ethernet address %s\n", nif->nif_driver->netif_bname,
+           nif->nif_unit, ether_sprintf(desc->myea));
+}
+
+int
+pxe_netif_put(struct iodesc *desc, void *pkt, size_t len)
+{
+       
+       return (-1);
+}
+
+int
+pxe_netif_get(struct iodesc *desc, void *pkt, size_t len, time_t tleft)
+{
+
+       return (-1);
+}
+
+void
+pxe_netif_end(struct netif *nif)
+{
+       t_PXENV_UDP_CLOSE *uc = (void *) pxe_command_buf;
+
+       uc->status = 0;
+
+       pxe_call(PXENV_UDP_CLOSE);
+
+       if (uc->status != PXENV_STATUS_SUCCESS)
+               printf("pxe_netif_end: PXENV_UDP_CLOSE failed: 0x%x\n",
+                   uc->status);



Home | Main Index | Thread Index | Old Index