[Midnightbsd-cvs] src [10367] trunk/usr.sbin: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jun 3 19:10:51 EDT 2018


Revision: 10367
          http://svnweb.midnightbsd.org/src/?rev=10367
Author:   laffer1
Date:     2018-06-03 19:10:50 -0400 (Sun, 03 Jun 2018)
Log Message:
-----------
sync with freebsd

Added Paths:
-----------
    trunk/usr.sbin/nvram/
    trunk/usr.sbin/nvram/Makefile
    trunk/usr.sbin/nvram/nvram.8
    trunk/usr.sbin/nvram/nvram.c
    trunk/usr.sbin/ofwdump/
    trunk/usr.sbin/ofwdump/Makefile
    trunk/usr.sbin/ofwdump/ofw_util.c
    trunk/usr.sbin/ofwdump/ofw_util.h
    trunk/usr.sbin/ofwdump/ofwdump.8
    trunk/usr.sbin/ofwdump/ofwdump.c
    trunk/usr.sbin/ofwdump/pathnames.h

Added: trunk/usr.sbin/nvram/Makefile
===================================================================
--- trunk/usr.sbin/nvram/Makefile	                        (rev 0)
+++ trunk/usr.sbin/nvram/Makefile	2018-06-03 23:10:50 UTC (rev 10367)
@@ -0,0 +1,8 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/nvram/Makefile 201390 2010-01-02 11:07:44Z ed $
+
+PROG=	nvram
+MAN=	nvram.8
+MANSUBDIR= /powerpc
+
+.include <bsd.prog.mk>


Property changes on: trunk/usr.sbin/nvram/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/nvram/nvram.8
===================================================================
--- trunk/usr.sbin/nvram/nvram.8	                        (rev 0)
+++ trunk/usr.sbin/nvram/nvram.8	2018-06-03 23:10:50 UTC (rev 10367)
@@ -0,0 +1,119 @@
+.\" $MidnightBSD$
+.\"-
+.\" Copyright (c) 2006 Maxim Sobolev <sobomax at FreeBSD.org>
+.\" 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 THE AUTHOR 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.
+.\"
+.\" $FreeBSD: stable/10/usr.sbin/nvram/nvram.8 162893 2006-09-30 19:07:03Z ru $
+.\"
+.Dd August 1, 2006
+.Dt NVRAM 8 powerpc
+.Os
+.Sh NAME
+.Nm nvram
+.Nd "display or modify contents of the EEPROM or NVRAM"
+.Sh SYNOPSIS
+.Nm
+.Fl p
+.Nm
+.Oo Fl d Ar name Oc Ar ...
+.Op Ar name Ns = Ns Ar value ...
+.Sh DESCRIPTION
+The
+.Nm
+utility provides an interface for displaying and changing the system's
+configuration variables contained in EEPROM or NVRAM.
+In the first synopsis form, all available configuration variables and their
+current values are printed.
+In the second form, the variable selected by
+.Ar name
+is either removed or its value is changed to the
+.Ar value
+following by
+.Ql =
+sign.
+.Pp
+The following options are available:
+.Bl -tag -width indent
+.It Fl d Ar name
+Delete the variable selected by
+.Ar name
+from the EEPROM or NVRAM.
+The
+.Fl d
+flag can be specified multiple times, in which case multiple variables
+will be removed.
+.It Fl p
+Print all available configuration variables and their current values.
+.El
+.Sh EXAMPLES
+Print all available configuration variables and their current values:
+.Pp
+.Dl "nvram -p"
+.Pp
+Remove the variable named
+.Va local-mac-address? :
+.Pp
+.Dl "nvram -d local-mac-address\e?"
+.Pp
+Set the value of the
+.Va local-mac-address?
+variable to
+.Dq Li true :
+.Pp
+.Dl "nvram local-mac-address\e?=true"
+.Pp
+Note that the
+.Ql \e
+in the above examples is used to keep the shell from interpreting the
+.Ql \&? .
+.Pp
+Remove variables named
+.Va foo
+and
+.Va bar
+and set variable named
+.Va baz
+to
+.Dq Li 100 :
+.Pp
+.Dl "nvram -d foo -d bar baz=100"
+.Sh SEE ALSO
+.Xr powermac_nvram 4 ,
+.Xr eeprom 8
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Fx 7.0 .
+It is inspired by the
+Darwin/Mac OS X
+.Nm
+utility.
+.Sh AUTHORS
+.An Maxim Sobolev Aq sobomax at FreeBSD.org
+.Sh BUGS
+Currently,
+.Nm
+only supports systems equipped with AMD flash and is only tested on Apple
+G4-based Mac Mini machines.


Property changes on: trunk/usr.sbin/nvram/nvram.8
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/nvram/nvram.c
===================================================================
--- trunk/usr.sbin/nvram/nvram.c	                        (rev 0)
+++ trunk/usr.sbin/nvram/nvram.c	2018-06-03 23:10:50 UTC (rev 10367)
@@ -0,0 +1,227 @@
+/* $MidnightBSD$ */
+/*
+ * Copyright (c) 2006 Maxim Sobolev <sobomax at FreeBSD.org>
+ * 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 THE AUTHOR 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.
+ *
+ * $FreeBSD: stable/10/usr.sbin/nvram/nvram.c 253162 2013-07-10 18:07:01Z rdivacky $
+ */
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <dev/powermac_nvram/powermac_nvramvar.h>
+
+#define	DEVICE_NAME	(_PATH_DEV "powermac_nvram")
+
+static void usage(void);
+static int remove_var(uint8_t *, int, const char *);
+static int append_var(uint8_t *, int, const char *, const char *);
+
+struct deletelist {
+	char *name;
+	struct deletelist *next;
+	struct deletelist *last;
+};
+
+static union {
+	uint8_t buf[sizeof(struct chrp_header)];
+	struct chrp_header header;
+} conv;
+
+int
+main(int argc, char **argv)
+{
+	int opt, dump, fd, res, i, size;
+	uint8_t buf[NVRAM_SIZE], *cp, *common;
+	struct deletelist *dl;
+
+	dump = 0;
+	dl = NULL;
+
+	while((opt = getopt(argc, argv, "d:p")) != -1) {
+		switch(opt) {
+		case 'p':
+			dump = 1;
+			break;
+
+		case 'd':
+			if (dl == NULL) {
+				dl = malloc(sizeof(*dl));
+				if (dl == NULL)
+					err(1, "malloc");
+				bzero(dl, sizeof(*dl));
+				dl->last = dl;
+			} else {
+				dl->last->next = malloc(sizeof(*dl));
+				if (dl->last->next == NULL)
+					err(1, "malloc");
+				dl->last = dl->last->next;
+				bzero(dl->last, sizeof(*dl));
+			}
+			dl->last->name = optarg;
+			break;
+
+		default:
+			usage();
+			/* Not reached */
+		}
+	}
+	argc -= optind;
+	argv += optind;
+
+	if (argc == 0 && dump == 0 && dl == NULL) {
+		usage();
+		/* Not reached */
+	}
+
+	fd = open(DEVICE_NAME, O_RDWR);
+	if (fd == -1)
+		err(1, DEVICE_NAME);
+	for (i = 0; i < (int)sizeof(buf);) {
+		res = read(fd, buf + i, sizeof(buf) - i);
+		if (res == -1 && errno != EINTR)
+			err(1, DEVICE_NAME);
+		if (res == 0)
+			break;
+		if (res > 0)
+			i += res;
+	}
+	if (i != sizeof(buf))
+		errx(1, "%s: short read", DEVICE_NAME);
+
+	/* Locate common block */
+	size = 0;
+	for (cp = buf; cp < buf + sizeof(buf); cp += size) {
+		memcpy(conv.buf, cp, sizeof(struct chrp_header));
+		size = conv.header.length * 0x10;
+		if (strncmp(conv.header.name, "common", 7) == 0)
+			break;
+	}
+	if (cp >= buf + sizeof(buf) || size <= (int)sizeof(struct chrp_header))
+		errx(1, "%s: no common block", DEVICE_NAME);
+	common = cp + sizeof(struct chrp_header);
+	size -= sizeof(struct chrp_header);
+
+	if (dump != 0) {
+		while (size > 0) {
+			i = strlen(common) + 1;
+			if (i == 1)
+				break;
+			printf("%s\n", common);
+			size -= i;
+			common += i;
+		}
+		exit(0);
+	}
+
+	for (;dl != NULL; dl = dl->next) {
+		if (remove_var(common, size, dl->name) == 0)
+			warnx("%s: no such variable", dl->name);
+	}
+
+	for (; argc > 0; argc--, argv++) {
+		cp = strchr(*argv, '=');
+		if (cp == NULL)
+			errx(1, "%s: invalid argument", *argv);
+		cp[0] = '\0';
+		cp++;
+		remove_var(common, size, *argv);
+		if (append_var(common, size, *argv, cp) == -1)
+			errx(1, "%s: error setting variable", *argv);
+	}
+
+	for (i = 0; i < (int)sizeof(buf);) {
+		res = write(fd, buf + i, sizeof(buf) - i);
+		if (res == -1 && errno != EINTR)
+			err(1, DEVICE_NAME);
+		if (res == 0)
+			break;
+		if (res > 0)
+			i += res;
+	}
+	if (i != sizeof(buf))
+		errx(1, "%s: short write", DEVICE_NAME);
+	if (close(fd) == -1)
+		err(1, DEVICE_NAME);
+
+	exit(0);
+}
+
+static void
+usage(void)
+{
+
+	fprintf(stderr, "usage: nvram [-p] | [-d name ...] [name=value ...]\n");
+	exit(1);
+}
+
+static int
+remove_var(uint8_t *buf, int len, const char *var_name)
+{
+	int nremoved, i, name_len;
+
+	nremoved = 0;
+	name_len = strlen(var_name);
+	while (len > 0) {
+		i = strlen(buf) + 1;
+		if (i == 1)
+			break;
+		if (strncmp(buf, var_name, name_len) == 0 && buf[name_len] == '=') {
+			memmove(buf, buf + i, len - i);
+			memset(buf + len - i, '\0', i);
+			nremoved += 1;
+			continue;
+		}
+		len -= i;
+		buf += i;
+	}
+	return nremoved;
+}
+
+static int
+append_var(uint8_t *buf, int len, const char *var_name, const char *var_value)
+{
+	int i, append_len;
+
+	while (len > 0) {
+		i = strlen(buf) + 1;
+		if (i == 1)
+			break;
+		len -= i;
+		buf += i;
+	}
+	append_len = strlen(var_name) + strlen(var_value) + 2;
+	if (len < append_len)
+		return -1;
+	sprintf(buf, "%s=%s", var_name, var_value);
+	return 0;
+}


Property changes on: trunk/usr.sbin/nvram/nvram.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/ofwdump/Makefile
===================================================================
--- trunk/usr.sbin/ofwdump/Makefile	                        (rev 0)
+++ trunk/usr.sbin/ofwdump/Makefile	2018-06-03 23:10:50 UTC (rev 10367)
@@ -0,0 +1,8 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/ofwdump/Makefile 201390 2010-01-02 11:07:44Z ed $
+
+PROG=	ofwdump
+MAN=	ofwdump.8
+SRCS=	ofwdump.c ofw_util.c
+
+.include <bsd.prog.mk>


Property changes on: trunk/usr.sbin/ofwdump/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/ofwdump/ofw_util.c
===================================================================
--- trunk/usr.sbin/ofwdump/ofw_util.c	                        (rev 0)
+++ trunk/usr.sbin/ofwdump/ofw_util.c	2018-06-03 23:10:50 UTC (rev 10367)
@@ -0,0 +1,231 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 by Thomas Moestl <tmm at FreeBSD.org>.
+ * 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 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.sbin/ofwdump/ofw_util.c 129589 2004-05-22 16:51:11Z marius $");
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include <dev/ofw/openfirmio.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+#include "pathnames.h"
+#include "ofw_util.h"
+
+#define	OFW_IOCTL(fd, cmd, val)	do {					\
+	if (ioctl(fd, cmd, val) == -1)					\
+		err(EX_IOERR, "ioctl(..., " #cmd ", ...) failed");	\
+} while (0)
+
+int
+ofw_open(int mode)
+{
+	int fd;
+
+	if ((fd = open(PATH_DEV_OPENFIRM, mode)) == -1)
+		err(EX_UNAVAILABLE, "could not open " PATH_DEV_OPENFIRM);
+	return (fd);
+}
+
+void
+ofw_close(int fd)
+{
+
+	close(fd);
+}
+
+phandle_t
+ofw_root(int fd)
+{
+
+	return (ofw_peer(fd, 0));
+}
+
+phandle_t
+ofw_optnode(int fd)
+{
+	phandle_t rv;
+
+	OFW_IOCTL(fd, OFIOCGETOPTNODE, &rv);
+	return (rv);
+}
+
+phandle_t
+ofw_peer(int fd, phandle_t node)
+{
+	phandle_t rv;
+
+	rv = node;
+	OFW_IOCTL(fd, OFIOCGETNEXT, &rv);
+	return (rv);
+}
+
+phandle_t
+ofw_child(int fd, phandle_t node)
+{
+	phandle_t rv;
+
+	rv = node;
+	OFW_IOCTL(fd, OFIOCGETCHILD, &rv);
+	return (rv);
+}
+
+phandle_t
+ofw_finddevice(int fd, const char *name)
+{
+	struct ofiocdesc d;
+
+	d.of_nodeid = 0;
+	d.of_namelen = strlen(name);
+	d.of_name = name;
+	d.of_buflen = 0;
+	d.of_buf = NULL;
+	if (ioctl(fd, OFIOCFINDDEVICE, &d) == -1) {
+		if (errno == ENOENT)
+			err(EX_UNAVAILABLE, "Node '%s' not found", name);
+		else
+			err(EX_IOERR,
+			    "ioctl(..., OFIOCFINDDEVICE, ...) failed");
+	}
+	return (d.of_nodeid);
+}
+
+int
+ofw_firstprop(int fd, phandle_t node, char *buf, int buflen)
+{
+
+	return (ofw_nextprop(fd, node, NULL, buf, buflen));
+}
+
+int
+ofw_nextprop(int fd, phandle_t node, const char *prev, char *buf, int buflen)
+{
+	struct ofiocdesc d;
+
+	d.of_nodeid = node;
+	d.of_namelen = prev != NULL ? strlen(prev) : 0;
+	d.of_name = prev;
+	d.of_buflen = buflen;
+	d.of_buf = buf;
+	if (ioctl(fd, OFIOCNEXTPROP, &d) == -1) {
+		if (errno == ENOENT)
+			return (0);
+		else
+			err(EX_IOERR, "ioctl(..., OFIOCNEXTPROP, ...) failed");
+	}
+	return (d.of_buflen);
+}
+
+static void *
+ofw_malloc(int size)
+{
+	void *p;
+
+	if ((p = malloc(size)) == NULL)
+		err(EX_OSERR, "malloc() failed");
+	return (p);
+}
+
+int
+ofw_getprop(int fd, phandle_t node, const char *name, void *buf, int buflen)
+{
+	struct ofiocdesc d;
+
+	d.of_nodeid = node;
+	d.of_namelen = strlen(name);
+	d.of_name = name;
+	d.of_buflen = buflen;
+	d.of_buf = buf;
+	OFW_IOCTL(fd, OFIOCGET, &d);
+	return (d.of_buflen);
+}
+
+int
+ofw_setprop(int fd, phandle_t node, const char *name, const void *buf,
+    int buflen)
+{
+	struct ofiocdesc d;
+
+	d.of_nodeid = node;
+	d.of_namelen = strlen(name);
+	d.of_name = name;
+	d.of_buflen = buflen;
+	d.of_buf = ofw_malloc(buflen);
+	memcpy(d.of_buf, buf, buflen);
+	OFW_IOCTL(fd, OFIOCSET, &d);
+	free(d.of_buf);
+	return (d.of_buflen);
+}
+
+int
+ofw_getproplen(int fd, phandle_t node, const char *name)
+{
+	struct ofiocdesc d;
+
+	d.of_nodeid = node;
+	d.of_namelen = strlen(name);
+	d.of_name = name;
+	OFW_IOCTL(fd, OFIOCGETPROPLEN, &d);
+	return (d.of_buflen);
+}
+
+int
+ofw_getprop_alloc(int fd, phandle_t node, const char *name, void **buf,
+    int *buflen, int reserve)
+{
+	struct ofiocdesc d;
+	int len, rv;
+
+	do {
+		len = ofw_getproplen(fd, node, name);
+		if (len < 0)
+			return (len);
+		if (*buflen < len + reserve) {
+			if (*buf != NULL)
+				free(*buf);
+			*buflen = len + reserve + OFIOCMAXVALUE;
+			*buf = ofw_malloc(*buflen);
+		}
+		d.of_nodeid = node;
+		d.of_namelen = strlen(name);
+		d.of_name = name;
+		d.of_buflen = *buflen - reserve;
+		d.of_buf = *buf;
+		rv = ioctl(fd, OFIOCGET, &d);
+	} while (rv == -1 && errno == ENOMEM);
+	if (rv == -1)
+		err(EX_IOERR, "ioctl(..., OFIOCGET, ...) failed");
+	return (d.of_buflen);
+}


Property changes on: trunk/usr.sbin/ofwdump/ofw_util.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/ofwdump/ofw_util.h
===================================================================
--- trunk/usr.sbin/ofwdump/ofw_util.h	                        (rev 0)
+++ trunk/usr.sbin/ofwdump/ofw_util.h	2018-06-03 23:10:50 UTC (rev 10367)
@@ -0,0 +1,51 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 by Thomas Moestl <tmm at FreeBSD.org>.
+ * 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 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.
+ *
+ * $FreeBSD: stable/10/usr.sbin/ofwdump/ofw_util.h 129589 2004-05-22 16:51:11Z marius $
+ */
+
+#ifndef OFW_UTIL_H
+#define	OFW_UTIL_H
+
+#include <dev/ofw/openfirm.h>
+
+int		ofw_open(int);
+void		ofw_close(int);
+
+phandle_t	ofw_root(int);
+phandle_t	ofw_optnode(int);
+phandle_t	ofw_peer(int, phandle_t);
+phandle_t	ofw_child(int, phandle_t);
+phandle_t	ofw_finddevice(int, const char *);
+
+int		ofw_firstprop(int, phandle_t, char *, int);
+int		ofw_nextprop(int, phandle_t, const char *, char *, int);
+int		ofw_getprop(int, phandle_t, const char *, void *, int);
+int		ofw_setprop(int, phandle_t, const char *, const void *, int);
+int		ofw_getproplen(int, phandle_t, const char *);
+int		ofw_getprop_alloc(int, phandle_t, const char *, void **, int *,
+    int);
+
+#endif /* OFW_UTIL_H */


Property changes on: trunk/usr.sbin/ofwdump/ofw_util.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/ofwdump/ofwdump.8
===================================================================
--- trunk/usr.sbin/ofwdump/ofwdump.8	                        (rev 0)
+++ trunk/usr.sbin/ofwdump/ofwdump.8	2018-06-03 23:10:50 UTC (rev 10367)
@@ -0,0 +1,108 @@
+.\" $MidnightBSD$
+.\" Copyright (c) 2002 by Thomas Moestl <tmm at FreeBSD.org>.
+.\" 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 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.
+.\"
+.\" $FreeBSD: stable/10/usr.sbin/ofwdump/ofwdump.8 175857 2008-01-31 14:58:55Z ru $
+.\"
+.Dd October 18, 2002
+.Dt OFWDUMP 8
+.Os
+.Sh NAME
+.Nm ofwdump
+.Nd examine the Open Firmware device tree
+.Sh SYNOPSIS
+.Nm
+.Fl a
+.Op Fl p | P Ar property
+.Op Fl R | S
+.Nm
+.Op Fl p | P Ar property
+.Op Fl r
+.Op Fl R | S
+.Op Fl -
+.Ar nodes
+.Sh DESCRIPTION
+The
+.Nm
+utility is used to examine the Open Firmware device tree.
+In the first synopsis form, the complete device tree is printed; in the
+second form, only the selected
+.Ar nodes
+will be examined.
+.Pp
+The following options are available:
+.Bl -tag -width ".Fl P Ar property"
+.It Fl a
+Print the complete device tree.
+.It Fl p
+Print all available properties.
+.It Fl P Ar property
+Only print properties of the given name.
+.It Fl R
+Print properties in
+.Dq raw
+format, i.e., omit all headings and indentation and just write the
+property values unaltered to the standard output.
+This is intended to be used with the
+.Fl P
+option to extract the value of a single property.
+.It Fl S
+Print properties as strings; this is analogous to the
+.Fl R
+option, except that each property is only output to the first
+.Dv NUL
+character, and that newline is appended to each.
+.It Fl r
+Recursively print all children of the specified nodes.
+.El
+.Sh EXAMPLES
+Print the complete device tree:
+.Pp
+.Dl "ofwdump -a"
+.Pp
+Print the complete device subtree of the
+.Dq Li /pci
+node, including all available properties:
+.Pp
+.Dl "ofwdump -pr /pci"
+.Pp
+Print the
+.Dq Li compatible
+property of the
+.Dq Li /pci
+node as plain string:
+.Pp
+.Dl "ofwdump -P compatible -S /pci"
+.Sh SEE ALSO
+.Xr eeprom 8
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Fx 5.0 .
+.Sh AUTHORS
+The
+.Nm
+utility
+was written by
+.An Thomas Moestl Aq tmm at FreeBSD.org .


Property changes on: trunk/usr.sbin/ofwdump/ofwdump.8
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/ofwdump/ofwdump.c
===================================================================
--- trunk/usr.sbin/ofwdump/ofwdump.c	                        (rev 0)
+++ trunk/usr.sbin/ofwdump/ofwdump.c	2018-06-03 23:10:50 UTC (rev 10367)
@@ -0,0 +1,241 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 by Thomas Moestl <tmm at FreeBSD.org>.
+ * 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 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.sbin/ofwdump/ofwdump.c 129589 2004-05-22 16:51:11Z marius $");
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/openfirmio.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
+#include <vis.h>
+
+#include "ofw_util.h"
+
+/* Constants controlling the layout of the output. */
+#define	LVLINDENT	2
+#define	NAMEINDENT	2
+#define	DUMPINDENT	4
+#define	CHARSPERLINE	60
+#define	BYTESPERLINE	(CHARSPERLINE / 3)
+
+static void	usage(void);
+static void	ofw_indent(int);
+static void	ofw_dump_properties(int, phandle_t, int, const char *, int,
+		    int);
+static void	ofw_dump(int, const char *, int, int, const char *, int, int);
+
+static void
+usage(void)
+{
+
+	fprintf(stderr,
+	    "usage: ofwdump -a [-p | -P property] [-R | -S]\n"
+	    "       ofwdump [-p | -P property] [-r] [-R | -S] [--] nodes\n");
+	exit(EX_USAGE);
+}
+
+int
+main(int argc, char *argv[])
+{
+	int opt, i, fd;
+	int aflag, pflag, rflag, Rflag, Sflag;
+	char *Parg;
+
+	aflag = pflag = rflag = Rflag = Sflag = 0;
+	Parg = NULL;
+	while ((opt = getopt(argc, argv, "-aprP:RS")) != -1) {
+		if (opt == '-')
+			break;
+		switch (opt) {
+		case 'a':
+			aflag = 1;
+			rflag = 1;
+			break;
+		case 'p':
+			if (Parg != NULL)
+				usage();
+			pflag = 1;
+			break;
+		case 'r':
+			rflag = 1;
+			break;
+		case 'P':
+			if (pflag)
+				usage();
+			pflag = 1;
+			Parg = optarg;
+			break;
+		case 'R':
+			if (Sflag)
+				usage();
+			Rflag = 1;
+			break;
+		case 'S':
+			if (Rflag)
+				usage();
+			Sflag = 1;
+			break;
+		case '?':
+		default:
+			usage();
+			/* NOTREACHED */
+		}
+	}
+	argc -= optind;
+	argv += optind;
+
+	fd = ofw_open(O_RDONLY);
+	if (aflag) {
+		if (argc != 0)
+			usage();
+		ofw_dump(fd, NULL, rflag, pflag, Parg, Rflag, Sflag);
+	} else {
+		/*
+		 * For the sake of scripts, usage() is not called here if
+		 * argc == 0.
+		 */
+		for (i = 0; i < argc; i++)
+			ofw_dump(fd, argv[i], rflag, pflag, Parg, Rflag, Sflag);
+	}
+	ofw_close(fd);
+	return (EX_OK);
+}
+
+static void
+ofw_indent(int level)
+{
+	int i;
+
+	for (i = 0; i < level; i++)
+		putchar(' ');
+}
+
+static void
+ofw_dump_properties(int fd, phandle_t n, int level, const char *pmatch, int raw,
+    int str)
+{
+	static void *pbuf = NULL;
+	static char *visbuf = NULL;
+	static char printbuf[CHARSPERLINE + 1];
+	static int pblen = 0, vblen = 0;
+	char prop[32];
+	int nlen, len, i, j, max, vlen;
+
+	for (nlen = ofw_firstprop(fd, n, prop, sizeof(prop)); nlen != 0;
+	     nlen = ofw_nextprop(fd, n, prop, prop, sizeof(prop))) {
+		if (pmatch != NULL && strcmp(pmatch, prop) != 0)
+			continue;
+		len = ofw_getprop_alloc(fd, n, prop, &pbuf, &pblen, 1);
+		if (len < 0)
+			continue;
+		if (raw)
+			write(STDOUT_FILENO, pbuf, len);
+		else if (str)
+			printf("%.*s\n", len, (char *)pbuf);
+		else {
+			ofw_indent(level * LVLINDENT + NAMEINDENT);
+			printf("%s:\n", prop);
+			/* Print in hex. */
+			for (i = 0; i < len; i += BYTESPERLINE) {
+				max = len - i;
+				max = max > BYTESPERLINE ? BYTESPERLINE : max;
+				ofw_indent(level * LVLINDENT + DUMPINDENT);
+				for (j = 0; j < max; j++)
+					printf("%02x ",
+					    ((unsigned char *)pbuf)[i + j]);
+				printf("\n");
+			}
+			/*
+			 * strvis() and print if it looks like it is
+			 * zero-terminated.
+			 */
+			if (((char *)pbuf)[len - 1] == '\0' &&
+			    strlen(pbuf) == (unsigned)len - 1) {
+				if (vblen < (len - 1) * 4 + 1) {
+					if (visbuf != NULL)
+						free(visbuf);
+					vblen = (OFIOCMAXVALUE + len) * 4 + 1;
+					if ((visbuf = malloc(vblen)) == NULL)
+						err(EX_OSERR,
+						    "malloc() failed");
+				}
+				vlen = strvis(visbuf, pbuf, VIS_TAB | VIS_NL);
+				for (i = 0; i < vlen; i += CHARSPERLINE) {
+					ofw_indent(level * LVLINDENT +
+					    DUMPINDENT);
+					strlcpy(printbuf, &visbuf[i],
+					    sizeof(printbuf));
+					printf("'%s'\n", printbuf);
+				}
+			}
+		}
+	}
+}
+
+static void
+ofw_dump_node(int fd, phandle_t n, int level, int rec, int prop,
+    const char *pmatch, int raw, int str)
+{
+	static void *nbuf = NULL;
+	static int nblen = 0;
+	int plen;
+	phandle_t c;
+
+	if (!(raw || str)) {
+		ofw_indent(level * LVLINDENT);
+		printf("Node %#lx", (unsigned long)n);
+		plen = ofw_getprop_alloc(fd, n, "name", &nbuf, &nblen, 1);
+		if (plen > 0)
+			printf(": %.*s\n", (int)plen, (char *)nbuf);
+		else
+			putchar('\n');
+	}
+	if (prop)
+		ofw_dump_properties(fd, n, level, pmatch, raw, str);
+	if (rec) {
+		for (c = ofw_child(fd, n); c != 0; c = ofw_peer(fd, c)) {
+			ofw_dump_node(fd, c, level + 1, rec, prop, pmatch,
+			    raw, str);
+		}
+	}
+}
+
+static void
+ofw_dump(int fd, const char *start, int rec, int prop, const char *pmatch,
+    int raw, int str)
+{
+	phandle_t n;
+
+	n = start == NULL ? ofw_root(fd) : ofw_finddevice(fd, start);
+	ofw_dump_node(fd, n, 0, rec, prop, pmatch, raw, str);
+}


Property changes on: trunk/usr.sbin/ofwdump/ofwdump.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/ofwdump/pathnames.h
===================================================================
--- trunk/usr.sbin/ofwdump/pathnames.h	                        (rev 0)
+++ trunk/usr.sbin/ofwdump/pathnames.h	2018-06-03 23:10:50 UTC (rev 10367)
@@ -0,0 +1,31 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 by Thomas Moestl <tmm at FreeBSD.org>.
+ * 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 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.
+ *
+ * $FreeBSD: stable/10/usr.sbin/ofwdump/pathnames.h 105401 2002-10-18 15:37:15Z tmm $
+ */
+
+#include <paths.h>
+
+#define PATH_DEV_OPENFIRM	_PATH_DEV "openfirm"


Property changes on: trunk/usr.sbin/ofwdump/pathnames.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property


More information about the Midnightbsd-cvs mailing list