From patchwork Wed Jun 19 03:52:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 252482 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id B94D72C034A for ; Wed, 19 Jun 2013 13:57:18 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 254C74A22B; Wed, 19 Jun 2013 05:56:16 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GllbOpfS5Wp2; Wed, 19 Jun 2013 05:56:15 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C64604A0B3; Wed, 19 Jun 2013 05:54:09 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C16884A09F for ; Wed, 19 Jun 2013 05:53:59 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 09t3JEOEq-87 for ; Wed, 19 Jun 2013 05:53:54 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-vb0-f73.google.com (mail-vb0-f73.google.com [209.85.212.73]) by theia.denx.de (Postfix) with ESMTPS id 6C3864A032 for ; Wed, 19 Jun 2013 05:53:06 +0200 (CEST) Received: by mail-vb0-f73.google.com with SMTP id f12so550539vbg.2 for ; Tue, 18 Jun 2013 20:53:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=WeO71iQK5/L7lKuK0NudPmlhHd0EYlUl+yCN7PPyT0g=; b=jIdJ32bnpyZ7oLBb6rapwVEkjXGioC7YlZw9xUn6YoXHf+4xVQvAdskC4G8HUo73u9 j4XlTy9RmK4RefHGJgSCn5kaDGHUACqNcpL9u1H2afTKVak3Qz04T/tIbDzrY0484ArF CSODGCu/rwbHn7ZQBC15XQUPZlW8MlNr371zJVOc9QsZ6uC84Z1AW2fbMQs8UoAkFnhc 2TI5tYP+SRu4YBeWAGaOoD8bo5oFugZn4PlkPnXq5lgw9R3wS5lG+WPSnZ/U4nfL167T WA30ikO2NqNnkz1nUWNtL3/vR7Rc50HyC0L+zvLzJWknc3Vf+VliDcnlQ58JX78Ls/5u rbJQ== X-Received: by 10.236.92.194 with SMTP id j42mr536313yhf.38.1371613983961; Tue, 18 Jun 2013 20:53:03 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id b80si1350197yhi.2.2013.06.18.20.53.03 for (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Tue, 18 Jun 2013 20:53:03 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.83.1]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id B5B5031C016; Tue, 18 Jun 2013 20:53:03 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 905841609FB; Tue, 18 Jun 2013 20:53:03 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 18 Jun 2013 20:52:34 -0700 Message-Id: <1371613960-28678-11-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.3 In-Reply-To: <1371613960-28678-1-git-send-email-sjg@chromium.org> References: <1371613960-28678-1-git-send-email-sjg@chromium.org> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQk0TARor+UmIIVpVB1LCyIwmo8hjzUuw01O9fnFGLZxTprbvlhoP65oG/x0bxkhbDQwqJNwbdL1AWd2eAWXnGCc0JPxcyXkL27pgfJrx94I+ctjwCS4sH2g0cC1UvX9yUqd2IwjRpKNDRUiT7nL8B30UDrcVKh5b05TEk+Wn2RMuG/Lx2gN5XSpx4ojqCaXkYt9hmcY Cc: Marek Vasut , u-boot-review@google.com, Tom Rini Subject: [U-Boot] [PATCH v3 10/16] dm: Add a 'dm' command for testing X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 Signed-off-by: Marek Vasut Signed-off-by: Pavel Herrmann Signed-off-by: Viktor Křivák Signed-off-by: Tomas Hlavacek --- Changes in v3: None Changes in v2: None include/configs/sandbox.h | 1 + test/dm/Makefile | 1 + test/dm/cmd_dm.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 test/dm/cmd_dm.c diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 38e0384..8e9a661 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -23,6 +23,7 @@ #define __CONFIG_H #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 310aa05..8f67215 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -21,6 +21,7 @@ include $(TOPDIR)/config.mk LIB = $(obj)libtestdm.o +COBJS-$(CONFIG_CMD_DM) += cmd_dm.o COBJS-$(CONFIG_DM_TEST) += test-driver.o COBJS-$(CONFIG_DM_TEST) += test-fdt.o COBJS-$(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..49d7887 --- /dev/null +++ b/test/dm/cmd_dm.c @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2013 Google, Inc + * + * (C) Copyright 2012 + * Marek Vasut + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +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(dump, 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", + "dump Dump driver model tree\n" + "dm uclass Dump list of instances for each uclass\n" + "dm test Run tests" +);