From patchwork Thu Feb 6 17:03:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1234460 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=lofDmHfl; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48D4XN4XYHz9sRm for ; Fri, 7 Feb 2020 04:04:04 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5FBFF8181D; Thu, 6 Feb 2020 18:03:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lofDmHfl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9CF20818F6; Thu, 6 Feb 2020 18:03:58 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_HELO_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8DF60817FB for ; Thu, 6 Feb 2020 18:03:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf42.google.com with SMTP id g6so3175806qvy.5 for ; Thu, 06 Feb 2020 09:03:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QI4L5egmz+uBMsTlsA7s3I2rGBLVEHpBqxkjNuwVeIE=; b=lofDmHflPaIK3BJV6uh9R4g97F6+uo+SPjyU8ANY9/ZC/I7YzN9VNe6r3JEtHHrRS0 nZxffdfVcgJq5caC1XEuSALxhT+BQfTvdlh8VHUYODOUpH3fsOP6RNQ6V7+pSr620OSS Wt89MTWJ/4G9h1gE+zz1DE2x2iqzz051/Jx6tw7jI94zSlHrOGzoc+Nm2YISZVjZ5GQH fdReZNRQ/X8OBJqw45XxJiGwW3IkzFfPm2nTSlB75Mn+x0x5zU/w/0aDg9DROW4hi6PX n1gShHy2NysvTa4glWo7ATppNJnEO5v0VXfslw+jTCurOiWDUtUbiMmsHEykN83GjKJW JeRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QI4L5egmz+uBMsTlsA7s3I2rGBLVEHpBqxkjNuwVeIE=; b=lSlDrqbC5ATgvPIKpaG7C481XK0TOTXt9ddkXS5+goXKDizj95A2sW+bs+9me3g4DI +r/VR4D+gjnkRmMgkC04ZDUqI1hNrzbQLddf8w12obWFz9oVEXgmzNEW74uOk879MtfM 8GskUZGf/bTQFmzUhUEf2p7tKhh1WRmcKz8j5BvbLcT/nTUmj/XP5cUO+MugaNAwy/gf nytp7bZ3SSYYiT3PF7oUCr5cwcNC+Ws7nSNX1czb9oUPHXHL0e/PbBCIvmeF88e9HvBA 9kzZW7prnpzWXGP031iUtjC/MJIQlbHBG0qUZhfUOQ96Fz1taIbaz+RuMHj4deezEJur BHPA== X-Gm-Message-State: APjAAAW80MlEgxoI6r9HvHlemWERxntKJlS1RsNxvXC9GZ3gPP50tGxf 5aPv5yx7gqTRtOKahh2/ci8OyUadHoA= X-Google-Smtp-Source: APXvYqwpLwmA+4R3y1JgTUppLYYZUamRJJpfg3i1v1jrXj1885ysfxXPFS5ue9f119nOcmSn1aCjNg== X-Received: by 2002:ad4:4204:: with SMTP id k4mr3193919qvp.203.1581008633956; Thu, 06 Feb 2020 09:03:53 -0800 (PST) Received: from localhost.localdomain ([75.102.135.197]) by smtp.gmail.com with ESMTPSA id z26sm1940594qtj.12.2020.02.06.09.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2020 09:03:53 -0800 (PST) From: Sean Anderson To: u-boot@lists.denx.de Subject: [PATCH v3] cmd: Add command to dump drivers and compatible strings Date: Thu, 6 Feb 2020 12:03:49 -0500 Message-Id: <20200206170349.1151628-1-seanga2@gmail.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean This adds a subcommand to dm to dump out what drivers are installed, and their compatible strings. I have found this useful in ensuring that I have the correct drivers compiled, and that I have put in the correct compatible strings. Signed-off-by: Sean Anderson Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: Simon Glass --- Changes in v3: - Add python test Changes in v2: - Check if entry->of_match is NULL before accessing it - Remove trailing newline in help message cmd/dm.c | 12 +++++++++++- drivers/core/dump.c | 20 ++++++++++++++++++++ include/dm/util.h | 3 +++ test/py/tests/test_dm.py | 17 +++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/py/tests/test_dm.py diff --git a/cmd/dm.c b/cmd/dm.c index 7b271db0bb..7a90685f8b 100644 --- a/cmd/dm.c +++ b/cmd/dm.c @@ -40,10 +40,19 @@ static int do_dm_dump_devres(cmd_tbl_t *cmdtp, int flag, int argc, return 0; } +static int do_dm_dump_drivers(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + dm_dump_drivers(); + + return 0; +} + 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(devres, 1, 1, do_dm_dump_devres, "", ""), + U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""), }; static __maybe_unused void dm_reloc(void) @@ -84,5 +93,6 @@ U_BOOT_CMD( "Driver model low level access", "tree Dump driver model tree ('*' = activated)\n" "dm uclass Dump list of instances for each uclass\n" - "dm devres Dump list of device resources for each device" + "dm devres Dump list of device resources for each device\n" + "dm drivers Dump list of drivers and their compatible strings" ); diff --git a/drivers/core/dump.c b/drivers/core/dump.c index 4704049aee..b5046398d4 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -96,3 +96,23 @@ void dm_dump_uclass(void) puts("\n"); } } + +void dm_dump_drivers(void) +{ + struct driver *d = ll_entry_start(struct driver, driver); + const int n_ents = ll_entry_count(struct driver, driver); + struct driver *entry; + const struct udevice_id *match; + + puts("Driver Compatible\n"); + puts("--------------------------------\n"); + for (entry = d; entry < d + n_ents; entry++) { + for (match = entry->of_match; + match && match->compatible; match++) + printf("%-20.20s %s\n", + match == entry->of_match ? entry->name : "", + match->compatible); + if (match == entry->of_match) + printf("%-20.20s\n", entry->name); + } +} diff --git a/include/dm/util.h b/include/dm/util.h index 348c2ace3c..0ccb3fbadf 100644 --- a/include/dm/util.h +++ b/include/dm/util.h @@ -39,6 +39,9 @@ static inline void dm_dump_devres(void) } #endif +/* Dump out a list of drivers */ +void dm_dump_drivers(void); + /** * Check if an of node should be or was bound before relocation. * diff --git a/test/py/tests/test_dm.py b/test/py/tests/test_dm.py new file mode 100644 index 0000000000..f6fbf8ba4c --- /dev/null +++ b/test/py/tests/test_dm.py @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 Sean Anderson + +import pytest + +@pytest.mark.buildconfigspec('cmd_dm') +def test_dm_drivers(u_boot_console): + """Test that each driver in `dm tree` is also listed in `dm drivers`.""" + response = u_boot_console.run_command('dm tree') + driver_index = response.find('Driver') + assert driver_index != -1 + drivers = (line[driver_index:].split()[0] + for line in response[:-1].split('\n')[2:]) + + response = u_boot_console.run_command('dm drivers') + for driver in drivers: + assert driver in response