[U-Boot] [PATCH 7/7] dm: Add "dm dump" command
Marek Vasut
marex at denx.de
Tue Aug 21 18:00:53 CEST 2012
Dumps the content of system tree
Signed-off-by: Marek Vasut <marex at denx.de>
---
common/dm/Makefile | 2 +-
common/dm/debug.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++
include/dm/debug.h | 33 ++++++++++++++++
3 files changed, 140 insertions(+), 1 deletion(-)
create mode 100644 common/dm/debug.c
create mode 100644 include/dm/debug.h
diff --git a/common/dm/Makefile b/common/dm/Makefile
index 6510021..2096c6b 100644
--- a/common/dm/Makefile
+++ b/common/dm/Makefile
@@ -21,7 +21,7 @@ include $(TOPDIR)/config.mk
LIB := $(obj)libdm.o
-COBJS := core.o driver.o lists.o tree.o root.o
+COBJS := core.o debug.o driver.o lists.o tree.o root.o
SRCS := $(COBJS:.o=.c)
OBJS := $(addprefix $(obj),$(COBJS))
diff --git a/common/dm/debug.c b/common/dm/debug.c
new file mode 100644
index 0000000..da669b7
--- /dev/null
+++ b/common/dm/debug.c
@@ -0,0 +1,106 @@
+/*
+ * (C) Copyright 2012
+ * Marek Vasut <marex at denx.de>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <malloc.h>
+#include <dm/manager.h>
+#include <dm/structures.h>
+#include <dm/debug.h>
+#include <common.h>
+#include <errno.h>
+
+static int display_succ(struct instance *in, char *buf)
+{
+ int len;
+ int ip = 0;
+ char local[16];
+ struct driver_instance *pos, *n, *prev = NULL, *outer;
+
+ outer = container_of(in, struct driver_instance, i);
+ printf("%s- %s @ 0x%p", buf, in->info->name, in);
+ if (outer->flags & DRIVER_FLAG_ACTIVATED)
+ puts(" - activated");
+ puts("\n");
+
+ if (list_empty(&in->succ))
+ return 0;
+
+ len = strlen(buf);
+ strncpy(local, buf, sizeof(local));
+ snprintf(local + len, 2, "|");
+ if (len && local[len - 1] == '`')
+ local[len - 1] = ' ';
+
+ list_for_each_entry_safe(pos, n, &in->succ, list) {
+ if (ip++)
+ display_succ(&prev->i, local);
+ prev = pos;
+ }
+
+ snprintf(local + len, 2, "`");
+ display_succ(&prev->i, local);
+
+ return 0;
+}
+
+int dm_dump_all()
+{
+ struct instance *root;
+ root = get_root_instance();
+ printf("ROOT 0x%p\n", root);
+ return dm_dump(root);
+}
+
+int dm_dump(struct instance *dev)
+{
+ if (!dev)
+ return -EINVAL;
+ return display_succ(dev, "");
+}
+
+static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ struct instance *root;
+
+ if (argc != 2)
+ return -EINVAL;
+ if (!strncmp(argv[1], "dump", 4))
+ return dm_dump_all();
+
+ if (!strncmp(argv[1], "remove", 6)) {
+ root = get_root_instance();
+ return driver_remove(root);
+ }
+
+ if (!strncmp(argv[1], "unbind", 6)) {
+ root = get_root_instance();
+ return driver_unbind(root);
+ }
+
+ return -EINVAL;
+}
+
+U_BOOT_CMD(
+ dm, 2, 1, do_dm,
+ "Driver model ops",
+ "<op>\n"
+);
diff --git a/include/dm/debug.h b/include/dm/debug.h
new file mode 100644
index 0000000..df86113
--- /dev/null
+++ b/include/dm/debug.h
@@ -0,0 +1,33 @@
+/*
+ * (C) Copyright 2012
+ * Pavel Herrmann <morpheus.ibis at gmail.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+
+#ifndef _DM_DEBUG_H_
+#define _DM_DEBUG_H_ 1
+
+#include <dm/structures.h>
+
+int dm_dump_all(void);
+int dm_dump(struct instance *i);
+
+#endif
--
1.7.10.4
More information about the U-Boot
mailing list