aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/ofwdump
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/ofwdump')
-rw-r--r--usr.sbin/ofwdump/Makefile5
-rw-r--r--usr.sbin/ofwdump/Makefile.depend17
-rw-r--r--usr.sbin/ofwdump/ofw_util.c227
-rw-r--r--usr.sbin/ofwdump/ofw_util.h48
-rw-r--r--usr.sbin/ofwdump/ofwdump.8105
-rw-r--r--usr.sbin/ofwdump/ofwdump.c249
-rw-r--r--usr.sbin/ofwdump/pathnames.h28
7 files changed, 679 insertions, 0 deletions
diff --git a/usr.sbin/ofwdump/Makefile b/usr.sbin/ofwdump/Makefile
new file mode 100644
index 000000000000..0565d3af9044
--- /dev/null
+++ b/usr.sbin/ofwdump/Makefile
@@ -0,0 +1,5 @@
+PROG= ofwdump
+MAN= ofwdump.8
+SRCS= ofwdump.c ofw_util.c
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/ofwdump/Makefile.depend b/usr.sbin/ofwdump/Makefile.depend
new file mode 100644
index 000000000000..ee629ba230bb
--- /dev/null
+++ b/usr.sbin/ofwdump/Makefile.depend
@@ -0,0 +1,17 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ gnu/lib/csu \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libc_nonshared \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/usr.sbin/ofwdump/ofw_util.c b/usr.sbin/ofwdump/ofw_util.c
new file mode 100644
index 000000000000..0e825a4e5430
--- /dev/null
+++ b/usr.sbin/ofwdump/ofw_util.c
@@ -0,0 +1,227 @@
+/*-
+ * Copyright (c) 2002 by Thomas Moestl <tmm@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/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);
+}
diff --git a/usr.sbin/ofwdump/ofw_util.h b/usr.sbin/ofwdump/ofw_util.h
new file mode 100644
index 000000000000..f843496e537c
--- /dev/null
+++ b/usr.sbin/ofwdump/ofw_util.h
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2002 by Thomas Moestl <tmm@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.
+ */
+
+#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 */
diff --git a/usr.sbin/ofwdump/ofwdump.8 b/usr.sbin/ofwdump/ofwdump.8
new file mode 100644
index 000000000000..2e9b280d4ab5
--- /dev/null
+++ b/usr.sbin/ofwdump/ofwdump.8
@@ -0,0 +1,105 @@
+.\" Copyright (c) 2002 by Thomas Moestl <tmm@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.
+.\"
+.Dd October 23, 2023
+.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 openfirm 4
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Fx 5.0 .
+.Sh AUTHORS
+The
+.Nm
+utility
+was written by
+.An Thomas Moestl Aq Mt tmm@FreeBSD.org .
diff --git a/usr.sbin/ofwdump/ofwdump.c b/usr.sbin/ofwdump/ofwdump.c
new file mode 100644
index 000000000000..335ae38afa5d
--- /dev/null
+++ b/usr.sbin/ofwdump/ofwdump.c
@@ -0,0 +1,249 @@
+/*-
+ * Copyright (c) 2002 by Thomas Moestl <tmm@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>
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/openfirmio.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdbool.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, bool, bool);
+static void ofw_dump_property(int fd, phandle_t n, int level,
+ const char *prop, bool raw, bool str);
+static void ofw_dump(int, const char *, bool, bool, const char *, bool, bool);
+
+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;
+ bool aflag, pflag, rflag, Rflag, Sflag;
+ char *Parg;
+
+ aflag = pflag = rflag = Rflag = Sflag = false;
+ Parg = NULL;
+ while ((opt = getopt(argc, argv, "-aprP:RS")) != -1) {
+ if (opt == '-')
+ break;
+ switch (opt) {
+ case 'a':
+ aflag = true;
+ rflag = true;
+ break;
+ case 'p':
+ if (Parg != NULL)
+ usage();
+ pflag = true;
+ break;
+ case 'r':
+ rflag = true;
+ break;
+ case 'P':
+ if (pflag)
+ usage();
+ pflag = true;
+ Parg = optarg;
+ break;
+ case 'R':
+ if (Sflag)
+ usage();
+ Rflag = true;
+ break;
+ case 'S':
+ if (Rflag)
+ usage();
+ Sflag = true;
+ 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, bool raw, bool str)
+{
+ int nlen;
+ char prop[OFIOCSUGGPROPNAMELEN];
+
+ for (nlen = ofw_firstprop(fd, n, prop, sizeof(prop)); nlen != 0;
+ nlen = ofw_nextprop(fd, n, prop, prop, sizeof(prop)))
+ ofw_dump_property(fd, n, level, prop, raw, str);
+}
+
+static void
+ofw_dump_property(int fd, phandle_t n, int level, const char *prop, bool raw,
+ bool str)
+{
+ static void *pbuf = NULL;
+ static char *visbuf = NULL;
+ static char printbuf[CHARSPERLINE + 1];
+ static int pblen = 0, vblen = 0;
+ int len, i, j, max, vlen;
+
+ len = ofw_getprop_alloc(fd, n, prop, &pbuf, &pblen, 1);
+ if (len < 0)
+ return;
+ 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, bool raw, bool 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) {
+ if (pmatch)
+ ofw_dump_property(fd, n, level, pmatch, raw, str);
+ else
+ ofw_dump_properties(fd, n, level, 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, bool rec, bool prop, const char *pmatch,
+ bool raw, bool 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);
+}
diff --git a/usr.sbin/ofwdump/pathnames.h b/usr.sbin/ofwdump/pathnames.h
new file mode 100644
index 000000000000..86d45dfcfe15
--- /dev/null
+++ b/usr.sbin/ofwdump/pathnames.h
@@ -0,0 +1,28 @@
+/*-
+ * Copyright (c) 2002 by Thomas Moestl <tmm@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 <paths.h>
+
+#define PATH_DEV_OPENFIRM _PATH_DEV "openfirm"