Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/usermode add a simple disk driver, pass the path to...
details: https://anonhg.NetBSD.org/src/rev/6d84785600ba
branches: trunk
changeset: 768238:6d84785600ba
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Fri Aug 12 12:59:13 2011 +0000
description:
add a simple disk driver, pass the path to the disk image on the kernel command line:
soundwave$ ./netbsd /tmp/test.fs
NetBSD/usermode startup
[...]
ld0 at mainbus0: /tmp/test.fs (33554432)
ld0: 32768 KB, 8322 cyl, 64 head, 63 sec, 1 bytes/sect x 33554432 sectors
boot device: ld0
root on ld0a dumps on ld0b
diffstat:
sys/arch/usermode/conf/GENERIC | 5 +-
sys/arch/usermode/conf/files.usermode | 6 +-
sys/arch/usermode/conf/majors.usermode | 3 +-
sys/arch/usermode/dev/cpu.c | 10 +-
sys/arch/usermode/dev/ld_thunkbus.c | 156 +++++++++++++++++++++++++++++++++
sys/arch/usermode/dev/mainbus.c | 12 ++-
sys/arch/usermode/include/mainbus.h | 9 +-
sys/arch/usermode/include/thunk.h | 10 +-
sys/arch/usermode/usermode/machdep.c | 9 +-
sys/arch/usermode/usermode/thunk.c | 34 ++++++-
10 files changed, 239 insertions(+), 15 deletions(-)
diffs (truncated from 439 to 300 lines):
diff -r 30874f905909 -r 6d84785600ba sys/arch/usermode/conf/GENERIC
--- a/sys/arch/usermode/conf/GENERIC Fri Aug 12 11:37:04 2011 +0000
+++ b/sys/arch/usermode/conf/GENERIC Fri Aug 12 12:59:13 2011 +0000
@@ -1,9 +1,9 @@
-# $NetBSD: GENERIC,v 1.8 2011/08/11 23:04:43 jmcneill Exp $
+# $NetBSD: GENERIC,v 1.9 2011/08/12 12:59:13 jmcneill Exp $
include "arch/usermode/conf/std.usermode"
options INCLUDE_CONFIG_FILE
-#ident "GENERIC-$Revision: 1.8 $"
+#ident "GENERIC-$Revision: 1.9 $"
maxusers 32
makeoptions DEBUG="-g3"
@@ -43,5 +43,6 @@
cpu0 at mainbus?
clock0 at mainbus?
ttycons0 at mainbus?
+ld0 at mainbus?
pseudo-device loop
diff -r 30874f905909 -r 6d84785600ba sys/arch/usermode/conf/files.usermode
--- a/sys/arch/usermode/conf/files.usermode Fri Aug 12 11:37:04 2011 +0000
+++ b/sys/arch/usermode/conf/files.usermode Fri Aug 12 12:59:13 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.usermode,v 1.3 2011/06/12 03:35:48 rmind Exp $
+# $NetBSD: files.usermode,v 1.4 2011/08/12 12:59:13 jmcneill Exp $
maxpartitions 8
maxusers 8 16 64
@@ -23,6 +23,9 @@
attach ttycons at thunkbus
file arch/usermode/dev/ttycons.c ttycons
+attach ld at thunkbus with ld_thunkbus
+file arch/usermode/dev/ld_thunkbus.c ld_thunkbus
+
file arch/usermode/usermode/copy.c
file arch/usermode/usermode/machdep.c
file arch/usermode/usermode/pmap.c
@@ -33,5 +36,6 @@
file arch/usermode/usermode/vm_machdep.c
file dev/cons.c
file dev/md_root.c memory_disk_hooks
+file kern/subr_disk_mbr.c disk
include "arch/usermode/conf/majors.usermode"
diff -r 30874f905909 -r 6d84785600ba sys/arch/usermode/conf/majors.usermode
--- a/sys/arch/usermode/conf/majors.usermode Fri Aug 12 11:37:04 2011 +0000
+++ b/sys/arch/usermode/conf/majors.usermode Fri Aug 12 12:59:13 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: majors.usermode,v 1.1 2007/12/29 14:38:30 jmcneill Exp $
+# $NetBSD: majors.usermode,v 1.2 2011/08/12 12:59:13 jmcneill Exp $
device-major cons char 0
device-major ctty char 1
@@ -10,3 +10,4 @@
device-major log char 7
device-major com char 8 com
device-major md char 24 block 17 md
+device-major ld char 69 block 19 ld
diff -r 30874f905909 -r 6d84785600ba sys/arch/usermode/dev/cpu.c
--- a/sys/arch/usermode/dev/cpu.c Fri Aug 12 11:37:04 2011 +0000
+++ b/sys/arch/usermode/dev/cpu.c Fri Aug 12 12:59:13 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.11 2011/08/12 11:37:04 jmcneill Exp $ */
+/* $NetBSD: cpu.c,v 1.12 2011/08/12 12:59:13 jmcneill Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.11 2011/08/12 11:37:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.12 2011/08/12 12:59:13 jmcneill Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@@ -323,8 +323,12 @@
{
device_t rdev;
- rdev = device_find_by_xname("md0");
+ rdev = device_find_by_xname("ld0");
+ if (rdev == NULL)
+ rdev = device_find_by_xname("md0");
+ aprint_normal("boot device: %s\n",
+ rdev ? device_xname(rdev) : "<unknown>");
setroot(rdev, 0);
}
diff -r 30874f905909 -r 6d84785600ba sys/arch/usermode/dev/ld_thunkbus.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/usermode/dev/ld_thunkbus.c Fri Aug 12 12:59:13 2011 +0000
@@ -0,0 +1,156 @@
+/* $NetBSD: ld_thunkbus.c,v 1.1 2011/08/12 12:59:13 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2011 Jared D. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ld_thunkbus.c,v 1.1 2011/08/12 12:59:13 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/buf.h>
+#include <sys/disk.h>
+
+#include <dev/ldvar.h>
+
+#include <machine/mainbus.h>
+#include <machine/thunk.h>
+
+static int ld_thunkbus_match(device_t, cfdata_t, void *);
+static void ld_thunkbus_attach(device_t, device_t, void *);
+
+static int ld_thunkbus_ldstart(struct ld_softc *, struct buf *);
+static int ld_thunkbus_lddump(struct ld_softc *, void *, int, int);
+static int ld_thunkbus_ldflush(struct ld_softc *, int);
+
+struct ld_thunkbus_softc {
+ struct ld_softc sc_ld;
+
+ int sc_fd;
+ struct stat sc_st;
+};
+
+CFATTACH_DECL_NEW(ld_thunkbus, sizeof(struct ld_thunkbus_softc),
+ ld_thunkbus_match, ld_thunkbus_attach, NULL, NULL);
+
+extern int errno;
+
+static int
+ld_thunkbus_match(device_t parent, cfdata_t match, void *opaque)
+{
+ struct thunkbus_attach_args *taa = opaque;
+
+ if (taa->taa_type != THUNKBUS_TYPE_DISKIMAGE)
+ return 0;
+
+ return 1;
+}
+
+static void
+ld_thunkbus_attach(device_t parent, device_t self, void *opaque)
+{
+ struct ld_thunkbus_softc *sc = device_private(self);
+ struct ld_softc *ld = &sc->sc_ld;
+ struct thunkbus_attach_args *taa = opaque;
+ const char *path = taa->u.diskimage.path;
+
+ ld->sc_dv = self;
+
+ sc->sc_fd = thunk_open(path, O_RDWR, 0);
+ if (sc->sc_fd == -1) {
+ aprint_error(": couldn't open %s: %d\n", path, errno);
+ return;
+ }
+ if (thunk_fstat(sc->sc_fd, &sc->sc_st) == -1) {
+ aprint_error(": couldn't stat %s: %d\n", path, errno);
+ return;
+ }
+
+ aprint_naive("\n");
+ aprint_normal(": %s (%lld)\n", path, (long long)sc->sc_st.st_size);
+
+ ld->sc_flags = LDF_ENABLED;
+ ld->sc_maxxfer = sc->sc_st.st_blksize;
+ ld->sc_secsize = 1;
+ ld->sc_secperunit = sc->sc_st.st_size;
+ ld->sc_maxqueuecnt = 1;
+ ld->sc_start = ld_thunkbus_ldstart;
+ ld->sc_dump = ld_thunkbus_lddump;
+ ld->sc_flush = ld_thunkbus_ldflush;
+
+ ldattach(ld);
+}
+
+static int
+ld_thunkbus_ldstart(struct ld_softc *ld, struct buf *bp)
+{
+ struct ld_thunkbus_softc *sc = (struct ld_thunkbus_softc *)ld;
+ ssize_t len;
+
+ if (bp->b_flags & B_READ)
+ len = thunk_pread(sc->sc_fd, bp->b_data, bp->b_bcount,
+ bp->b_rawblkno);
+ else
+ len = thunk_pwrite(sc->sc_fd, bp->b_data, bp->b_bcount,
+ bp->b_rawblkno);
+
+ if (len == -1)
+ return errno;
+ else if (len != bp->b_bcount)
+ panic("%s: short xfer", __func__);
+ return 0;
+}
+
+static int
+ld_thunkbus_lddump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
+{
+ struct ld_thunkbus_softc *sc = (struct ld_thunkbus_softc *)ld;
+ ssize_t len;
+
+ len = thunk_pwrite(sc->sc_fd, data, blkcnt, blkno);
+ if (len == -1)
+ return errno;
+ else if (len != blkcnt) {
+ device_printf(ld->sc_dv, "%s failed (short xfer)\n", __func__);
+ return EIO;
+ }
+
+ return 0;
+}
+
+static int
+ld_thunkbus_ldflush(struct ld_softc *ld, int flags)
+{
+ struct ld_thunkbus_softc *sc = (struct ld_thunkbus_softc *)ld;
+
+ if (thunk_fsync(sc->sc_fd) == -1)
+ return errno;
+
+ return 0;
+}
+
diff -r 30874f905909 -r 6d84785600ba sys/arch/usermode/dev/mainbus.c
--- a/sys/arch/usermode/dev/mainbus.c Fri Aug 12 11:37:04 2011 +0000
+++ b/sys/arch/usermode/dev/mainbus.c Fri Aug 12 12:59:13 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.c,v 1.3 2009/11/27 03:23:14 rmind Exp $ */
+/* $NetBSD: mainbus.c,v 1.4 2011/08/12 12:59:13 jmcneill Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.3 2009/11/27 03:23:14 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.4 2011/08/12 12:59:13 jmcneill Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@@ -50,6 +50,8 @@
CFATTACH_DECL_NEW(mainbus, sizeof(mainbus_softc_t),
mainbus_match, mainbus_attach, NULL, NULL);
+extern char *usermode_root_image_path;
+
static int
mainbus_match(device_t parent, cfdata_t match, void *opaque)
{
@@ -74,6 +76,12 @@
config_found_ia(self, "thunkbus", &taa, mainbus_print);
taa.taa_type = THUNKBUS_TYPE_TTYCONS;
config_found_ia(self, "thunkbus", &taa, mainbus_print);
+
+ if (usermode_root_image_path) {
+ taa.taa_type = THUNKBUS_TYPE_DISKIMAGE;
+ taa.u.diskimage.path = usermode_root_image_path;
+ config_found_ia(self, "thunkbus", &taa, mainbus_print);
+ }
}
static int
diff -r 30874f905909 -r 6d84785600ba sys/arch/usermode/include/mainbus.h
--- a/sys/arch/usermode/include/mainbus.h Fri Aug 12 11:37:04 2011 +0000
+++ b/sys/arch/usermode/include/mainbus.h Fri Aug 12 12:59:13 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.h,v 1.2 2009/10/21 16:06:59 snj Exp $ */
+/* $NetBSD: mainbus.h,v 1.3 2011/08/12 12:59:13 jmcneill Exp $ */
Home |
Main Index |
Thread Index |
Old Index