Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Dec 2014 02:13:07 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r276355 - user/nwhitehorn/kboot/powerpc/kboot
Message-ID:  <201412290213.sBT2D7tA024021@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nwhitehorn
Date: Mon Dec 29 02:13:06 2014
New Revision: 276355
URL: https://svnweb.freebsd.org/changeset/base/276355

Log:
  Add block device support. This can't autoload the kernel for some reason,
  but can manually. Not sure why.

Added:
  user/nwhitehorn/kboot/powerpc/kboot/hostdisk.c   (contents, props changed)
Modified:
  user/nwhitehorn/kboot/powerpc/kboot/Makefile
  user/nwhitehorn/kboot/powerpc/kboot/conf.c
  user/nwhitehorn/kboot/powerpc/kboot/host_syscall.S
  user/nwhitehorn/kboot/powerpc/kboot/host_syscall.h
  user/nwhitehorn/kboot/powerpc/kboot/hostcons.c
  user/nwhitehorn/kboot/powerpc/kboot/main.c

Modified: user/nwhitehorn/kboot/powerpc/kboot/Makefile
==============================================================================
--- user/nwhitehorn/kboot/powerpc/kboot/Makefile	Mon Dec 29 00:35:44 2014	(r276354)
+++ user/nwhitehorn/kboot/powerpc/kboot/Makefile	Mon Dec 29 02:13:06 2014	(r276355)
@@ -10,7 +10,7 @@ INSTALLFLAGS=	-b
 
 # Architecture-specific loader code
 SRCS=		conf.c metadata.c vers.c main.c ppc64_elf_freebsd.c
-SRCS+=		host_syscall.S hostcons.c
+SRCS+=		host_syscall.S hostcons.c hostdisk.c
 SRCS+=		ucmpdi2.c
 
 LOADER_DISK_SUPPORT?=	yes

Modified: user/nwhitehorn/kboot/powerpc/kboot/conf.c
==============================================================================
--- user/nwhitehorn/kboot/powerpc/kboot/conf.c	Mon Dec 29 00:35:44 2014	(r276354)
+++ user/nwhitehorn/kboot/powerpc/kboot/conf.c	Mon Dec 29 02:13:06 2014	(r276355)
@@ -34,8 +34,7 @@ __FBSDID("$FreeBSD$");
 #include "dev_net.h"
 #endif
 
-extern struct devsw kbootdisk;
-extern struct devsw kbootcdrom;
+extern struct devsw hostdisk;
 
 /*
  * We could use linker sets for some or all of these, but
@@ -48,13 +47,8 @@ extern struct devsw kbootcdrom;
 
 /* Exported for libstand */
 struct devsw *devsw[] = {
-#if 0 /* XXX */
-#if defined(LOADER_CD9660_SUPPORT)
-    &kbootcdrom,
-#endif
-#if defined(LOADER_DISK_SUPPORT)
-    &kbootdisk,
-#endif
+#if defined(LOADER_DISK_SUPPORT) || defined(LOADER_CD9660_SUPPORT)
+    &hostdisk,
 #endif
 #if defined(LOADER_NET_SUPPORT)
     &netdev,

Modified: user/nwhitehorn/kboot/powerpc/kboot/host_syscall.S
==============================================================================
--- user/nwhitehorn/kboot/powerpc/kboot/host_syscall.S	Mon Dec 29 00:35:44 2014	(r276354)
+++ user/nwhitehorn/kboot/powerpc/kboot/host_syscall.S	Mon Dec 29 02:13:06 2014	(r276355)
@@ -10,6 +10,11 @@ ENTRY(host_write)
 	sc
 	blr
 
+ENTRY(host_seek)
+	li %r0, 478 # SYS_lseek
+	sc
+	blr
+
 ENTRY(host_open)
 	li %r0, 5 # SYS_open
 	sc

Modified: user/nwhitehorn/kboot/powerpc/kboot/host_syscall.h
==============================================================================
--- user/nwhitehorn/kboot/powerpc/kboot/host_syscall.h	Mon Dec 29 00:35:44 2014	(r276354)
+++ user/nwhitehorn/kboot/powerpc/kboot/host_syscall.h	Mon Dec 29 02:13:06 2014	(r276355)
@@ -32,6 +32,7 @@
 
 ssize_t host_read(int fd, void *buf, size_t nbyte);
 ssize_t host_write(int fd, const void *buf, size_t nbyte);
+ssize_t host_seek(int fd, uint64_t offset, int whence);
 int host_open(char *path, int flags, int mode);
 int host_close(int fd);
 void *host_getmem(void *addr, size_t len);

Modified: user/nwhitehorn/kboot/powerpc/kboot/hostcons.c
==============================================================================
--- user/nwhitehorn/kboot/powerpc/kboot/hostcons.c	Mon Dec 29 00:35:44 2014	(r276354)
+++ user/nwhitehorn/kboot/powerpc/kboot/hostcons.c	Mon Dec 29 02:13:06 2014	(r276355)
@@ -76,7 +76,7 @@ hostcons_getchar()
 {
 	uint8_t ch;
 
-	host_read(1, &ch, 1);
+	host_read(0, &ch, 1);
 	return (ch);
 }
 

Added: user/nwhitehorn/kboot/powerpc/kboot/hostdisk.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/nwhitehorn/kboot/powerpc/kboot/hostdisk.c	Mon Dec 29 02:13:06 2014	(r276355)
@@ -0,0 +1,126 @@
+/*-
+ * Copyright (C) 2014 Nathan Whitehorn
+ * 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 ``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 TOOLS GMBH 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>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <stdarg.h>
+#include "bootstrap.h"
+#include "host_syscall.h"
+
+static int hostdisk_init(void);
+static int hostdisk_strategy(void *devdata, int flag, daddr_t dblk,
+    size_t size, char *buf, size_t *rsize);
+static int hostdisk_open(struct open_file *f, ...);
+static int hostdisk_close(struct open_file *f);
+static int hostdisk_ioctl(struct open_file *f, u_long cmd, void *data);
+static void hostdisk_print(int verbose);
+
+struct devsw hostdisk = {
+	"a",
+	DEVT_DISK,
+	hostdisk_init,
+	hostdisk_strategy,
+	hostdisk_open,
+	hostdisk_close,
+	hostdisk_ioctl,
+	hostdisk_print,
+};
+
+static int
+hostdisk_init(void)
+{
+
+	return (0);
+}
+
+static int
+hostdisk_strategy(void *devdata, int flag, daddr_t dblk, size_t size,
+    char *buf, size_t *rsize)
+{
+	struct devdesc *desc = devdata;
+	daddr_t pos;
+	int n;
+	
+	pos = dblk * 512;
+
+	if (host_seek(desc->d_unit, pos, 0) < 0)
+		return (EIO);
+	n = host_read(desc->d_unit, buf, size);
+
+	if (n < 0)
+		return (EIO);
+
+	*rsize = n;
+	return (0);
+}
+
+static int
+hostdisk_open(struct open_file *f, ...)
+{
+	struct devdesc *desc;
+	char *path;
+	va_list vl;
+
+	va_start(vl, f);
+	desc = va_arg(vl, struct devdesc *);
+	va_end(vl);
+
+	path = malloc(strlen((char *)(desc->d_opendata)) + 6);
+	strcpy(path, "/dev/");
+	strcat(path, (char *)(desc->d_opendata));
+
+	desc->d_unit = host_open(path, O_RDONLY, 0);
+	free(path);
+
+	if (desc->d_unit < 0)
+		return (ENOENT);
+
+	return (0);
+}
+
+static int
+hostdisk_close(struct open_file *f)
+{
+	struct devdesc *desc = f->f_devdata;
+
+	host_close(desc->d_unit);
+	return (0);
+}
+
+static int
+hostdisk_ioctl(struct open_file *f, u_long cmd, void *data)
+{
+
+	return (EINVAL);
+}
+
+static void
+hostdisk_print(int verbose)
+{
+
+}
+

Modified: user/nwhitehorn/kboot/powerpc/kboot/main.c
==============================================================================
--- user/nwhitehorn/kboot/powerpc/kboot/main.c	Mon Dec 29 00:35:44 2014	(r276354)
+++ user/nwhitehorn/kboot/powerpc/kboot/main.c	Mon Dec 29 02:13:06 2014	(r276355)
@@ -55,17 +55,16 @@ kboot_getdev(void **vdev, const char *de
 	int i;
 	const char *devpath, *filepath;
 	struct devsw *dv;
+	struct devdesc *desc;
 
-	if (devspec[0] == '/') {
-		devpath = getenv("currdev");
-		filepath = devspec;
-	} else {
+	if (strchr(devspec, ':') != NULL) {
 		devpath = devspec;
-		if (strchr(devspec, ':') == NULL)
-			filepath = NULL;
-		else
-			filepath = strchr(devspec, ':') + 1;
+		filepath = strchr(devspec, ':') + 1;
+	} else {
+		devpath = getenv("currdev");
+		filepath = &devspec[1];
 	}
+
 	for (i = 0; (dv = devsw[i]) != NULL; i++) {
 		if (strncmp(dv->dv_name, devpath, strlen(dv->dv_name)) == 0)
 			goto found;
@@ -73,11 +72,20 @@ kboot_getdev(void **vdev, const char *de
 	return (ENOENT);
 
 found:
-	if (path != NULL)
+	if (path != NULL && filepath != NULL)
 		*path = filepath;
 	else if (path != NULL)
 		*path = strchr(devspec, ':') + 1;
-	*vdev = strdup(devpath);
+
+	if (vdev != NULL) {
+		desc = malloc(sizeof(*desc));
+		desc->d_dev = dv;
+		desc->d_unit = 0;
+		desc->d_opendata = strdup(devpath);
+		*vdev = desc;
+	}
+
+	return (0);
 }
 
 int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201412290213.sBT2D7tA024021>