Commit 0681195977ce04347f7de8ba88d9ebba10cae6dc
Committed by
Tom Rini
1 parent
2e7d35d2a6
Exists in
v2017.01-smarct4x
and in
48 other branches
dm: Add a 'dm' command for testing
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>
Showing 3 changed files with 135 additions and 0 deletions Side-by-side Diff
include/configs/sandbox.h
test/dm/Makefile
test/dm/cmd_dm.c
1 | +/* | |
2 | + * Copyright (c) 2013 Google, Inc | |
3 | + * | |
4 | + * (C) Copyright 2012 | |
5 | + * Marek Vasut <marex@denx.de> | |
6 | + * | |
7 | + * SPDX-License-Identifier: GPL-2.0+ | |
8 | + */ | |
9 | + | |
10 | +#include <common.h> | |
11 | +#include <dm.h> | |
12 | +#include <malloc.h> | |
13 | +#include <errno.h> | |
14 | +#include <asm/io.h> | |
15 | +#include <dm/root.h> | |
16 | +#include <dm/test.h> | |
17 | +#include <dm/uclass-internal.h> | |
18 | + | |
19 | +static int display_succ(struct device *in, char *buf) | |
20 | +{ | |
21 | + int len; | |
22 | + int ip = 0; | |
23 | + char local[16]; | |
24 | + struct device *pos, *n, *prev = NULL; | |
25 | + | |
26 | + printf("%s- %s @ %08x", buf, in->name, map_to_sysmem(in)); | |
27 | + if (in->flags & DM_FLAG_ACTIVATED) | |
28 | + puts(" - activated"); | |
29 | + puts("\n"); | |
30 | + | |
31 | + if (list_empty(&in->child_head)) | |
32 | + return 0; | |
33 | + | |
34 | + len = strlen(buf); | |
35 | + strncpy(local, buf, sizeof(local)); | |
36 | + snprintf(local + len, 2, "|"); | |
37 | + if (len && local[len - 1] == '`') | |
38 | + local[len - 1] = ' '; | |
39 | + | |
40 | + list_for_each_entry_safe(pos, n, &in->child_head, sibling_node) { | |
41 | + if (ip++) | |
42 | + display_succ(prev, local); | |
43 | + prev = pos; | |
44 | + } | |
45 | + | |
46 | + snprintf(local + len, 2, "`"); | |
47 | + display_succ(prev, local); | |
48 | + | |
49 | + return 0; | |
50 | +} | |
51 | + | |
52 | +static int dm_dump(struct device *dev) | |
53 | +{ | |
54 | + if (!dev) | |
55 | + return -EINVAL; | |
56 | + return display_succ(dev, ""); | |
57 | +} | |
58 | + | |
59 | +static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc, | |
60 | + char * const argv[]) | |
61 | +{ | |
62 | + struct device *root; | |
63 | + | |
64 | + root = dm_root(); | |
65 | + printf("ROOT %08x\n", map_to_sysmem(root)); | |
66 | + return dm_dump(root); | |
67 | +} | |
68 | + | |
69 | +static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc, | |
70 | + char * const argv[]) | |
71 | +{ | |
72 | + struct uclass *uc; | |
73 | + int ret; | |
74 | + int id; | |
75 | + | |
76 | + for (id = 0; id < UCLASS_COUNT; id++) { | |
77 | + struct device *dev; | |
78 | + | |
79 | + ret = uclass_get(id, &uc); | |
80 | + if (ret) | |
81 | + continue; | |
82 | + | |
83 | + printf("uclass %d: %s\n", id, uc->uc_drv->name); | |
84 | + for (ret = uclass_first_device(id, &dev); | |
85 | + dev; | |
86 | + ret = uclass_next_device(&dev)) { | |
87 | + printf(" %s @ %08x:\n", dev->name, | |
88 | + map_to_sysmem(dev)); | |
89 | + } | |
90 | + puts("\n"); | |
91 | + } | |
92 | + | |
93 | + return 0; | |
94 | +} | |
95 | + | |
96 | +static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc, | |
97 | + char * const argv[]) | |
98 | +{ | |
99 | + return dm_test_main(); | |
100 | +} | |
101 | + | |
102 | +static cmd_tbl_t test_commands[] = { | |
103 | + U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""), | |
104 | + U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""), | |
105 | + U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""), | |
106 | +}; | |
107 | + | |
108 | +static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
109 | +{ | |
110 | + cmd_tbl_t *test_cmd; | |
111 | + int ret; | |
112 | + | |
113 | + if (argc != 2) | |
114 | + return CMD_RET_USAGE; | |
115 | + test_cmd = find_cmd_tbl(argv[1], test_commands, | |
116 | + ARRAY_SIZE(test_commands)); | |
117 | + argc -= 2; | |
118 | + argv += 2; | |
119 | + if (!test_cmd || argc > test_cmd->maxargs) | |
120 | + return CMD_RET_USAGE; | |
121 | + | |
122 | + ret = test_cmd->cmd(test_cmd, flag, argc, argv); | |
123 | + | |
124 | + return cmd_process_error(test_cmd, ret); | |
125 | +} | |
126 | + | |
127 | +U_BOOT_CMD( | |
128 | + dm, 2, 1, do_dm, | |
129 | + "Driver model low level access", | |
130 | + "tree Dump driver model tree\n" | |
131 | + "dm uclass Dump list of instances for each uclass\n" | |
132 | + "dm test Run tests" | |
133 | +); |