Module Name:    src
Committed By:   nisimura
Date:           Tue Jan 31 11:04:17 UTC 2012

Modified Files:
        src/sys/arch/evbarm/stand/boot2440: Makefile dev_net.c devopen.c

Log Message:
- add TFTP loading facility.
- SD/MMC load default is now "ld0a:netbsd"


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbarm/stand/boot2440/Makefile \
    src/sys/arch/evbarm/stand/boot2440/dev_net.c \
    src/sys/arch/evbarm/stand/boot2440/devopen.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbarm/stand/boot2440/Makefile
diff -u src/sys/arch/evbarm/stand/boot2440/Makefile:1.1 src/sys/arch/evbarm/stand/boot2440/Makefile:1.2
--- src/sys/arch/evbarm/stand/boot2440/Makefile:1.1	Mon Jan 30 03:28:34 2012
+++ src/sys/arch/evbarm/stand/boot2440/Makefile	Tue Jan 31 11:04:17 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.1 2012/01/30 03:28:34 nisimura Exp $
+#	$NetBSD: Makefile,v 1.2 2012/01/31 11:04:17 nisimura Exp $
 
 S=		${.CURDIR}/../../../..
 PROG=		bootmini2440
@@ -11,7 +11,7 @@ CLEANFILES+=	vers.c ${PROG}.elf
 CFLAGS+=	-Wall -Wno-main -ffreestanding -march=armv4
 CPPFLAGS+=	-D_STANDALONE -DSUPPORT_DHCP 
 CPPFLAGS+=	-DDM9000MAC="0x08,0x08,0x11,0x18,0x12,0x27" 
-CPPFLAGS+=	-DDEFAULT_BOOTFILE="ld0e:netbsd;net:"
+CPPFLAGS+=	-DDEFAULT_BOOTFILE="ld0a:netbsd;net:"
 CPPFLAGS+=	-nostdinc -I. -I${.CURDIR} -I${.OBJDIR} -I${S} -I${S}/arch
 DBG=		
 
Index: src/sys/arch/evbarm/stand/boot2440/dev_net.c
diff -u src/sys/arch/evbarm/stand/boot2440/dev_net.c:1.1 src/sys/arch/evbarm/stand/boot2440/dev_net.c:1.2
--- src/sys/arch/evbarm/stand/boot2440/dev_net.c:1.1	Mon Jan 30 03:28:34 2012
+++ src/sys/arch/evbarm/stand/boot2440/dev_net.c	Tue Jan 31 11:04:17 2012
@@ -42,12 +42,16 @@
 extern int netif_open(void*);
 extern int netif_init(unsigned int tag);
 
+extern struct in_addr servip;
+
+static int netdev_sock = -1;
+
 int
 net_open(struct open_file *f, ...)
 {
 	va_list ap;
-	char *path;
-	int sock, error = 0;
+	char *path, *proto;
+	int error = 0;
 
 	if( netif_init(0) == 0 ) {
 		error = ENODEV;
@@ -55,15 +59,16 @@ net_open(struct open_file *f, ...)
 	}
 
 	va_start(ap, f);
-
 	path = va_arg(ap, char *);
-	if ((sock = netif_open(path)) < 0) {
+	proto = va_arg(ap, char *);
+	va_end(ap);
+	if ((netdev_sock = netif_open(path)) < 0) {
 		error = errno;
 		goto out;
 	}
 
 	/* send DHCP request */
-	bootp(sock);
+	bootp(netdev_sock);
 
 	/* IP address was not found */
 	if (myip.s_addr == 0) {
@@ -96,6 +101,9 @@ net_open(struct open_file *f, ...)
 			printf("Root path: %s\n", rootpath);
 			strcpy(bootfile, ++filename);
 			printf("Bootfile: %s\n", bootfile);
+		} else {
+			/* No ':' found, assume it's just a filename */
+			strcpy(bootfile, path);
 		}
 	}
 
@@ -103,12 +111,14 @@ net_open(struct open_file *f, ...)
 	if (bootfile[0] == '\0')
 		strcpy(bootfile, "netbsd");
 
-	if (nfs_mount(sock, rootip, rootpath) != 0) {
+	if (strcmp(proto, "nfs") == 0
+	    && (nfs_mount(netdev_sock, rootip, rootpath) != 0)) {
 		error = errno;
 		goto out;
 	}
+
+	f->f_devdata = &netdev_sock;
 out:
-	va_end(ap);
 	return (error);
 }
 
Index: src/sys/arch/evbarm/stand/boot2440/devopen.c
diff -u src/sys/arch/evbarm/stand/boot2440/devopen.c:1.1 src/sys/arch/evbarm/stand/boot2440/devopen.c:1.2
--- src/sys/arch/evbarm/stand/boot2440/devopen.c:1.1	Mon Jan 30 03:28:34 2012
+++ src/sys/arch/evbarm/stand/boot2440/devopen.c	Tue Jan 31 11:04:17 2012
@@ -34,6 +34,7 @@
 #include <lib/libkern/libkern.h>
 #include <lib/libsa/stand.h>
 #include <lib/libsa/nfs.h>
+#include <lib/libsa/tftp.h>
 #include <lib/libsa/ext2fs.h>
 #include <lib/libsa/dosfs.h>
 #include <lib/libsa/ufs.h>
@@ -58,6 +59,7 @@ struct devsw devsw[] = {
 };
 
 struct fs_ops ops_nfs = FS_OPS(nfs);
+struct fs_ops ops_tftp = FS_OPS(tftp);
 struct fs_ops ops_ext2fs = FS_OPS(ext2fs);
 struct fs_ops ops_dosfs = FS_OPS(dosfs);
 struct fs_ops ops_bsdfs = FS_OPS(ufs);
@@ -78,16 +80,29 @@ devopen(struct open_file *of, const char
 	if (strncmp("net:", name, 4) == 0 ||
 	    strncmp("nfs:", name, 4) == 0 ) {
 		of->f_dev = &devsw[0];
-		if ((error = net_open(of, name+4)) != 0)
+		if ((error = net_open(of, name+4, "nfs")) != 0)
 			return error;
 		file_system[0] = ops_nfs;
 		*file = bootfile;
 		strncpy(bi_path.bootpath, bootfile, sizeof(bi_path.bootpath));
 
 		return 0;
+	} else if (strncmp("tftp:", name, 5) == 0) {
+		of->f_dev = &devsw[0];
+		if ((error = net_open(of, name+5, "tftp")) != 0) {
+			return error;
+		}
+		file_system[0] = ops_tftp;
+		*file = bootfile;
+		strncpy(bi_path.bootpath, bootfile, sizeof(bi_path.bootpath));
+
+		return 0;
 	} else if (name[0] == 'l' && name[1] == 'd') {
 		int unit, part;
 		parseunit(&name[2], &unit, &part, file);
+		if (*file == NULL || strlen(*file) == 0) {
+			strcpy(*file, "netbsd");
+		}
 		of->f_dev = &devsw[1];
 		if ((error = sdmmc_open(of, unit, part)) != 0)
 			return error;

Reply via email to