U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v9 09/14] dm: Add a 'dm' command for testing
Date: Wed, 26 Feb 2014 15:59:22 -0700	[thread overview]
Message-ID: <1393455567-13378-10-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1393455567-13378-1-git-send-email-sjg@chromium.org>

This command is not required for driver model operation, but can be useful
for testing. It provides simple dumps of internal data structures.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
Signed-off-by: Viktor K?iv?k <viktor.krivak@gmail.com>
Signed-off-by: Tomas Hlavacek <tmshlvck@gmail.com>
---

Changes in v9: None
Changes in v8: None
Changes in v7: None
Changes in v6: None
Changes in v5:
- Change to new SPDX license headers

Changes in v4:
- Change 'dm dump' command to 'dm tree'

Changes in v3: None
Changes in v2: None

 include/configs/sandbox.h |   1 +
 test/dm/Makefile          |   1 +
 test/dm/cmd_dm.c          | 133 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 135 insertions(+)
 create mode 100644 test/dm/cmd_dm.c

diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index c9c8509..8e034a7 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -21,6 +21,7 @@
 #define CONFIG_BOOTSTAGE
 #define CONFIG_BOOTSTAGE_REPORT
 #define CONFIG_DM
+#define CONFIG_CMD_DM
 #define CONFIG_DM_TEST
 
 /* Number of bits in a C 'long' on this architecture */
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 6af85b9..4e9afe6 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -4,6 +4,7 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
+obj-$(CONFIG_CMD_DM) += cmd_dm.o
 obj-$(CONFIG_DM_TEST) += test-driver.o
 obj-$(CONFIG_DM_TEST) += test-fdt.o
 obj-$(CONFIG_DM_TEST) += test-main.o
diff --git a/test/dm/cmd_dm.c b/test/dm/cmd_dm.c
new file mode 100644
index 0000000..a03fe20
--- /dev/null
+++ b/test/dm/cmd_dm.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2013 Google, Inc
+ *
+ * (C) Copyright 2012
+ * Marek Vasut <marex@denx.de>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <malloc.h>
+#include <errno.h>
+#include <asm/io.h>
+#include <dm/root.h>
+#include <dm/test.h>
+#include <dm/uclass-internal.h>
+
+static int display_succ(struct device *in, char *buf)
+{
+	int len;
+	int ip = 0;
+	char local[16];
+	struct device *pos, *n, *prev = NULL;
+
+	printf("%s- %s @ %08x", buf, in->name, map_to_sysmem(in));
+	if (in->flags & DM_FLAG_ACTIVATED)
+		puts(" - activated");
+	puts("\n");
+
+	if (list_empty(&in->child_head))
+		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->child_head, sibling_node) {
+		if (ip++)
+			display_succ(prev, local);
+		prev = pos;
+	}
+
+	snprintf(local + len, 2, "`");
+	display_succ(prev, local);
+
+	return 0;
+}
+
+static int dm_dump(struct device *dev)
+{
+	if (!dev)
+		return -EINVAL;
+	return display_succ(dev, "");
+}
+
+static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
+			  char * const argv[])
+{
+	struct device *root;
+
+	root = dm_root();
+	printf("ROOT %08x\n", map_to_sysmem(root));
+	return dm_dump(root);
+}
+
+static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
+			     char * const argv[])
+{
+	struct uclass *uc;
+	int ret;
+	int id;
+
+	for (id = 0; id < UCLASS_COUNT; id++) {
+		struct device *dev;
+
+		ret = uclass_get(id, &uc);
+		if (ret)
+			continue;
+
+		printf("uclass %d: %s\n", id, uc->uc_drv->name);
+		for (ret = uclass_first_device(id, &dev);
+		     dev;
+		     ret = uclass_next_device(&dev)) {
+			printf("  %s @  %08x:\n", dev->name,
+			       map_to_sysmem(dev));
+		}
+		puts("\n");
+	}
+
+	return 0;
+}
+
+static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
+			  char * const argv[])
+{
+	return dm_test_main();
+}
+
+static cmd_tbl_t test_commands[] = {
+	U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
+	U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
+	U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""),
+};
+
+static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	cmd_tbl_t *test_cmd;
+	int ret;
+
+	if (argc != 2)
+		return CMD_RET_USAGE;
+	test_cmd = find_cmd_tbl(argv[1], test_commands,
+				ARRAY_SIZE(test_commands));
+	argc -= 2;
+	argv += 2;
+	if (!test_cmd || argc > test_cmd->maxargs)
+		return CMD_RET_USAGE;
+
+	ret = test_cmd->cmd(test_cmd, flag, argc, argv);
+
+	return cmd_process_error(test_cmd, ret);
+}
+
+U_BOOT_CMD(
+	dm,	2,	1,	do_dm,
+	"Driver model low level access",
+	"tree         Dump driver model tree\n"
+	"dm uclass        Dump list of instances for each uclass\n"
+	"dm test         Run tests"
+);
-- 
1.9.0.rc1.175.g0b1dcb5

  parent reply	other threads:[~2014-02-26 22:59 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-26 22:59 [U-Boot] [PATCH v9 0/14] Driver model implementation, tests, demo and GPIO Simon Glass
2014-02-26 22:59 ` [U-Boot] [PATCH v9 01/14] sandbox: Build a device tree file for sandbox Simon Glass
2014-03-04 19:16   ` [U-Boot] [U-Boot, v9, " Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 02/14] Add cmd_process_error() to report and process errors Simon Glass
2014-03-04 19:16   ` [U-Boot] [U-Boot, v9, " Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 03/14] yaffs: Remove private list implementation Simon Glass
2014-03-04 19:16   ` [U-Boot] [U-Boot, v9, " Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 04/14] dm: Add README for driver model Simon Glass
2014-03-04 19:16   ` [U-Boot] [U-Boot,v9,04/14] " Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 05/14] dm: Add base driver model support Simon Glass
2014-03-04 19:16   ` [U-Boot] [U-Boot,v9,05/14] " Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 06/14] sandbox: config: Enable driver model Simon Glass
2014-03-04 19:17   ` [U-Boot] [U-Boot, v9, " Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 07/14] dm: Set up driver model after relocation Simon Glass
2014-03-04 19:17   ` [U-Boot] [U-Boot, v9, " Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 08/14] dm: Add basic tests Simon Glass
2014-03-04 19:17   ` [U-Boot] [U-Boot,v9,08/14] " Tom Rini
2014-02-26 22:59 ` Simon Glass [this message]
2014-03-04 19:17   ` [U-Boot] [U-Boot,v9,09/14] dm: Add a 'dm' command for testing Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 10/14] dm: Add a demonstration/example driver Simon Glass
2014-03-04 19:17   ` [U-Boot] [U-Boot, v9, " Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 11/14] dm: Add GPIO support and tests Simon Glass
2014-03-04 19:17   ` [U-Boot] [U-Boot,v9,11/14] " Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 12/14] sandbox: Convert GPIOs to use driver model Simon Glass
2014-03-04 19:17   ` [U-Boot] [U-Boot, v9, " Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 13/14] dm: Enable gpio command to support " Simon Glass
2014-03-04 19:17   ` [U-Boot] [U-Boot, v9, " Tom Rini
2014-02-26 22:59 ` [U-Boot] [PATCH v9 14/14] dm: Remove old driver model documentation Simon Glass
2014-03-04 19:17   ` [U-Boot] [U-Boot, v9, " Tom Rini
2014-02-26 23:01 ` [U-Boot] [PATCH v9 0/14] Driver model implementation, tests, demo and GPIO Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393455567-13378-10-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox