Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sandpoint/stand/netboot - add IDE/SATA diskboot fac...



details:   https://anonhg.NetBSD.org/src/rev/4a08be10ec2c
branches:  trunk
changeset: 755891:4a08be10ec2c
user:      phx <phx%NetBSD.org@localhost>
date:      Sat Jun 26 21:45:49 2010 +0000

description:
- add IDE/SATA diskboot facility
known ok with KuroBox PCIIDE, need more debug on SiI3512 SATA
which fails reading sectors from a drive.

- now capable of TFTP loading

Code submitted by Toru Nishimura.

diffstat:

 sys/arch/sandpoint/stand/netboot/Makefile   |    4 +-
 sys/arch/sandpoint/stand/netboot/brdsetup.c |   25 ++++-
 sys/arch/sandpoint/stand/netboot/dev_net.c  |   73 ++++++++++------
 sys/arch/sandpoint/stand/netboot/devopen.c  |   75 ++++++++--------
 sys/arch/sandpoint/stand/netboot/globals.h  |   90 +++++++++++++++++++-
 sys/arch/sandpoint/stand/netboot/main.c     |  119 ++++++++++++++++-----------
 sys/arch/sandpoint/stand/netboot/nif.c      |   23 +++-
 sys/arch/sandpoint/stand/netboot/pci.c      |   14 +---
 sys/arch/sandpoint/stand/netboot/pciide.c   |  119 +++++++++++++--------------
 sys/arch/sandpoint/stand/netboot/siisata.c  |  120 +++++++++------------------
 10 files changed, 371 insertions(+), 291 deletions(-)

diffs (truncated from 1053 to 300 lines):

diff -r a3795cf27f72 -r 4a08be10ec2c sys/arch/sandpoint/stand/netboot/Makefile
--- a/sys/arch/sandpoint/stand/netboot/Makefile Sat Jun 26 16:34:47 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/Makefile Sat Jun 26 21:45:49 2010 +0000
@@ -1,10 +1,10 @@
-#      $NetBSD: Makefile,v 1.19 2010/05/27 06:58:15 dholland Exp $
+#      $NetBSD: Makefile,v 1.20 2010/06/26 21:45:49 phx Exp $
 
 S=             ${.CURDIR}/../../../..
 
 PROG=          netboot
 SRCS=          entry.S main.c brdsetup.c pci.c devopen.c dev_net.c nif.c \
-               fxp.c tlp.c rge.c skg.c printf.c
+               fxp.c tlp.c rge.c skg.c dsk.c pciide.c siisata.c printf.c
 CLEANFILES+=   vers.c vers.o ${PROG} ${PROG}.bin
 CFLAGS+=       -Wall -Wno-main -ffreestanding -msoft-float -mmultiple
 CFLAGS+=       -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith
diff -r a3795cf27f72 -r 4a08be10ec2c sys/arch/sandpoint/stand/netboot/brdsetup.c
--- a/sys/arch/sandpoint/stand/netboot/brdsetup.c       Sat Jun 26 16:34:47 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/brdsetup.c       Sat Jun 26 21:45:49 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: brdsetup.c,v 1.20 2010/05/28 15:45:11 phx Exp $ */
+/* $NetBSD: brdsetup.c,v 1.21 2010/06/26 21:45:49 phx Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -37,6 +37,8 @@
 #include <lib/libsa/net.h>
 #include <lib/libkern/libkern.h>
 
+#include <machine/bootinfo.h>
+
 #include "globals.h"
 
 #define BRD_DECL(xxx) \
@@ -105,7 +107,7 @@
 };
 
 static struct brdprop *brdprop;
-static uint32_t ns_per_tick;
+static uint32_t ticks_per_sec, ns_per_tick;
 
 static void brdfixup(void);
 static void setup(void);
@@ -138,7 +140,7 @@
 #define UART_READ(base, r)     *(volatile char *)(base + (r))
 #define UART_WRITE(base, r, v) *(volatile char *)(base + (r)) = (v)
 
-void brdsetup(void);
+void brdsetup(void);   /* called by entry.S */
 
 void
 brdsetup(void)
@@ -155,8 +157,14 @@
                20, 25, 20, 30, 35, 40, 40, 20,
                30, 25, 40, 30, 30, 25, 35, 00
        };
+       char *consname;
+       int consport;
        uint32_t extclk;
        unsigned pchb, pcib, val;
+       extern struct btinfo_memory bi_mem;
+       extern struct btinfo_console bi_cons;
+       extern struct btinfo_clock bi_clk;
+       extern struct btinfo_prodfamily bi_fam;
 
        /*
         * CHRP specification "Map-B" BAT012 layout
@@ -217,11 +225,9 @@
        ticks_per_sec = busclock >> 2;
        ns_per_tick = 1000000000 / ticks_per_sec;
 
+       /* now prepare serial console */
        consname = brdprop->consname;
        consport = brdprop->consport;
-       consspeed = brdprop->consspeed;
-
-       /* now prepare serial console */
        if (strcmp(consname, "eumb") == 0) {
                uart1base = 0xfc000000 + consport;      /* 0x4500, 0x4600 */
                UART_WRITE(uart1base, DCR, 0x01);       /* enable DUART mode */
@@ -231,6 +237,13 @@
 
        /* more brd adjustments */
        brdfixup();
+
+       bi_mem.memsize = mpc107memsize();
+       snprintf(bi_cons.devname, sizeof(bi_cons.devname), consname);
+       bi_cons.addr = consport;
+       bi_cons.speed = brdprop->consspeed;
+       bi_clk.ticks_per_sec = ticks_per_sec;
+       snprintf(bi_fam.name, sizeof(bi_fam.name), brdprop->family);
 }
 
 struct brdprop *
diff -r a3795cf27f72 -r 4a08be10ec2c sys/arch/sandpoint/stand/netboot/dev_net.c
--- a/sys/arch/sandpoint/stand/netboot/dev_net.c        Sat Jun 26 16:34:47 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/dev_net.c        Sat Jun 26 21:45:49 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dev_net.c,v 1.8 2010/05/13 10:40:02 phx Exp $ */
+/* $NetBSD: dev_net.c,v 1.9 2010/06/26 21:45:49 phx Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -38,8 +38,10 @@
 #include <lib/libsa/net.h>
 #include <lib/libsa/bootp.h>
 #include <lib/libsa/nfs.h>
+#include <lib/libkern/libkern.h>
 
-#include <lib/libkern/libkern.h>
+#include <machine/bootinfo.h>
+#include <machine/stdarg.h>
 
 #include "globals.h"
 
@@ -48,51 +50,66 @@
 
 int
 net_open(struct open_file *f, ...)
+
 {
-       int error = 0;
+       va_list ap;
+       char *file, *proto;
+       int error;
+       extern struct btinfo_bootpath bi_path;
        
-       if (netdev_opens == 0) {
-               if ((netdev_sock = netif_open(NULL)) < 0) {
-                       error = errno;
-                       goto bad;
-               }
+       va_start(ap, f);
+       file = va_arg(ap, char *);
+       proto = va_arg(ap, char *);
+       va_end(ap);
 
-               /* send DHCP request */
-               bootp(netdev_sock);
+       if (netdev_opens > 0)
+               return 0;
+
+       if ((netdev_sock = netif_open(NULL)) < 0)
+               return ENXIO;   /* never fails indeed */
 
-               /* IP address was not found */
-               if (myip.s_addr == 0) {
-                       error = ENOENT;
-                       goto bad;
-               }
+       error = 0;
+       bootp(netdev_sock);     /* send DHCP request */
+       if (myip.s_addr == 0) {
+               error = ENOENT; /* IP address was not found */
+               goto bad;
+       }
 
-               if (bootfile[0] == '\0')
-                       strcpy(bootfile, "netbsd");
+       if (file[0] != '\0') 
+               snprintf(bootfile, sizeof(bootfile), file);
+       else if (bootfile[0] == '\0')
+               snprintf(bootfile, sizeof(bootfile), "netbsd");
 
-               if (nfs_mount(netdev_sock, rootip, rootpath) != 0) {
-                       error = errno;
-                       goto bad;
-               }
-       }
+       if (strcmp(proto, "nfs") == 0
+           && (error = nfs_mount(netdev_sock, rootip, rootpath)) != 0)
+               goto bad;
+
+       snprintf(bi_path.bootpath, sizeof(bi_path.bootpath), bootfile);
+       f->f_devdata = &netdev_sock;
        netdev_opens++;
-bad:
-       return (error);
+       return 0;
+ bad:
+       netif_close(netdev_sock);
+       netdev_sock = -1;
+       return error;
 }
 
 int
 net_close(struct open_file *f)
        
 {
+       f->f_devdata = NULL;
        if (--netdev_opens > 0)
-               return (0);
+               return 0;
        netif_close(netdev_sock);
        netdev_sock = -1;
-       return (0);
+       return 0;
 }
 
 int
-net_strategy(void *d, int f, daddr_t b, size_t s, void *buf, size_t *r)
+net_strategy(void *devdata, int rw, daddr_t dblk, size_t size,
+       void *p, size_t *rsize)
 {
 
-       return (EIO);
+       return EIO;
 }
diff -r a3795cf27f72 -r 4a08be10ec2c sys/arch/sandpoint/stand/netboot/devopen.c
--- a/sys/arch/sandpoint/stand/netboot/devopen.c        Sat Jun 26 16:34:47 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/devopen.c        Sat Jun 26 21:45:49 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: devopen.c,v 1.10 2009/07/20 11:43:09 nisimura Exp $ */
+/* $NetBSD: devopen.c,v 1.11 2010/06/26 21:45:49 phx Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -35,68 +35,62 @@
 
 #include <lib/libsa/stand.h>
 #include <lib/libsa/nfs.h>
+#include <lib/libsa/ufs.h>
+#include <lib/libsa/tftp.h>
 #include <lib/libkern/libkern.h>
 
 #include "globals.h"
 
-struct devsw devsw[] = {
-       { "net", net_strategy, net_open, net_close, noioctl },
-};
-int ndevs = sizeof(devsw) / sizeof(devsw[0]);
+struct devsw devnet = { "net", net_strategy, net_open, net_close, noioctl };
+struct devsw devdsk = { "dsk", dsk_strategy, dsk_open, dsk_close, noioctl };
 
-struct fs_ops fssw[] = {
-       FS_OPS(nfs),
-};
-struct fs_ops file_system[1];
+struct fs_ops file_system[1] = { FS_OPS(null) };
 int nfsys = 1;
+struct fs_ops fs_nfs   = FS_OPS(nfs);
+struct fs_ops fs_tftp  = FS_OPS(tftp);
+struct fs_ops fs_ffsv2 = FS_OPS(ffsv2);
+struct fs_ops fs_ffsv1 = FS_OPS(ffsv1);
+extern char *fsmod;
+
+static void parseunit(const char *, int *, int *, char **);
 
 int
 devopen(struct open_file *of, const char *name, char **file)
 {
        int error;
+       int unit, part;
        extern char bootfile[]; /* handed by DHCP */
 
        if (of->f_flags != F_READ)
                return EPERM;
 
-       if (strcmp("net:", name) == 0) {
-               of->f_dev = &devsw[0];
-               if ((error = net_open(of, name)) != 0)
+       if (strncmp("net:", name, 4) == 0 || strncmp("nfs:", name, 4) == 0) {
+               of->f_dev = &devnet;
+               if ((error = net_open(of, &name[4], "nfs")) != 0)
                        return error;
-               file_system[0] = fssw[0];
+               file_system[0] = fs_nfs;
                *file = bootfile;       /* resolved fname */
                return 0;               /* NFS */
        }
-#if 0 /* later */
+       if (strncmp("tftp:", name, 5) == 0) {
+               of->f_dev = &devnet;
+               if ((error = net_open(of, &name[5], "tftp")) != 0)
+                       return error;
+               file_system[0] = fs_tftp;
+               *file = bootfile;       /* resolved fname */
+               return 0;               /* TFTP */
+       }
        if (name[0] == 'w' && name[1] == 'd') {
                parseunit(&name[2], &unit, &part, file);
-               of->f_dev = &devsw[1];
-               if ((error = wdopen(of, unit, part)) != 0)
+               of->f_dev = &devdsk;
+               if ((error = dsk_open(of, unit, part, *file)) != 0)
                        return error;
-               switch (parsefstype(of->f_devdata)) {
-               default:
-               case FS_BSDFFS:
-                       file_system[0] = fssw[1]; break;
-               case FS_EX2FS:
-                       file_system[0] = fssw[2]; break;
-               case FS_MSDOS:
-                       file_system[0] = fssw[3]; break;
-               }
-               return 0;
+               file_system[0] = *dsk_fsops(of);
+               return 0;               /* FFS */
        }
-#endif



Home | Main Index | Thread Index | Old Index