From patchwork Mon Mar 30 15:22:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niel Fourie X-Patchwork-Id: 1264011 X-Patchwork-Delegate: trini@ti.com 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=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=c+udfdS9; 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48rbpH4QZMz9sPF for ; Tue, 31 Mar 2020 02:23:48 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 448AF804CD; Mon, 30 Mar 2020 17:23:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1585581820; bh=dBADcjTtWNe/R4x/+h8Mzry3NUPXUIXoEdmqRLUunkk=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=c+udfdS9vQBqrhScSCLsYaMEFwD2bkKVoyGyG/1vMmqYCVte+Jj8iquB1jaBPtg7D +6SEM69j0RX2RCn173lpmXn6dovSoeShe02TqIUgirXRAZ4921DQU748VC/QZO3Nvv 0TyoBw+qv7DY/I96qMPdI6V8YrPuaO8sknCJ9uUnE0QYS5Ew2lqHwWcmBxpnIsjfi2 vOcycwROHBvRPZxYR6cGlk3YuB5CdV30QfmdxYUyXZJQeYZTfPPmjZeIPOJa0Ui7OT QTAYxfSqT1+oiAUsqOeNkxno2vIjZoOf9RHnvhTt7I2Zlkvy+HWTvn6gkKxKM54KvE I/cUet7QVvYCA== Received: by phobos.denx.de (Postfix, from userid 109) id A8C87812FD; Mon, 30 Mar 2020 17:23:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E232280369 for ; Mon, 30 Mar 2020 17:23:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=lusus@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 48rbnz4Sbxz1rlGN; Mon, 30 Mar 2020 17:23:35 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 48rbnz3q1gz1qqkL; Mon, 30 Mar 2020 17:23:35 +0200 (CEST) Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id zgG4LPoXww5x; Mon, 30 Mar 2020 17:23:34 +0200 (CEST) X-Auth-Info: hZecD5STlCV9AznGkrHRdA3EU2tMpzlqfFQyv9qvjDo= Received: from aldebaran.denx.de (unknown [62.91.23.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Mon, 30 Mar 2020 17:23:34 +0200 (CEST) From: Niel Fourie To: u-boot@lists.denx.de Cc: sjg@chromium.org, sr@denx.de, Niel Fourie Subject: [PATCH v3 1/1] cmd: blkls: Add blkls command Date: Mon, 30 Mar 2020 17:22:58 +0200 Message-Id: <20200330152258.2375526-1-lusus@denx.de> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean Add a command to print a list of available block device drivers, and for each, the list of known block devices. Signed-off-by: Niel Fourie Cc: Simon Glass Cc: Stefan Roese Reviewed-by: Simon Glass Reviewed-by: Stefan Roese --- Changes in v2: - Removed legacy block device variant of blkls and its test. - Handle return value of uclass_get(). - Removed unnecessary ifdefs, fixed Kconfig depends. Changes is v3: - Removed redundant "default n" in Kconfig. - Corrected included headers, fixed formatting. - Corrected license of the test. cmd/Kconfig | 7 +++++ cmd/Makefile | 1 + cmd/lsblk.c | 51 +++++++++++++++++++++++++++++++++++++ test/py/tests/test_lsblk.py | 13 ++++++++++ 4 files changed, 72 insertions(+) create mode 100644 cmd/lsblk.c create mode 100644 test/py/tests/test_lsblk.py diff --git a/cmd/Kconfig b/cmd/Kconfig index 6403bc45a5..52c14d5420 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1047,6 +1047,13 @@ config CMD_LOADS help Load an S-Record file over serial line +config CMD_LSBLK + depends on BLK + bool "lsblk - list block drivers and devices" + help + Print list of available block device drivers, and for each, the list + of known block devices. + config CMD_MMC bool "mmc" help diff --git a/cmd/Makefile b/cmd/Makefile index f1dd513a4b..6f80974a55 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -83,6 +83,7 @@ obj-$(CONFIG_CMD_LED) += led.o obj-$(CONFIG_CMD_LICENSE) += license.o obj-y += load.o obj-$(CONFIG_CMD_LOG) += log.o +obj-$(CONFIG_CMD_LSBLK) += lsblk.o obj-$(CONFIG_ID_EEPROM) += mac.o obj-$(CONFIG_CMD_MD5SUM) += md5sum.o obj-$(CONFIG_CMD_MEMORY) += mem.o diff --git a/cmd/lsblk.c b/cmd/lsblk.c new file mode 100644 index 0000000000..b3e8394203 --- /dev/null +++ b/cmd/lsblk.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2020 + * Niel Fourie, DENX Software Engineering, lusus@denx.de. + */ + +#include +#include + +static int do_lsblk(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + struct driver *d = ll_entry_start(struct driver, driver); + const int n_ents = ll_entry_count(struct driver, driver); + struct driver *entry; + struct udevice *udev; + struct uclass *uc; + struct blk_desc *desc; + int ret, i; + + ret = uclass_get(UCLASS_BLK, &uc); + if (ret) { + puts("Could not get BLK uclass.\n"); + return CMD_RET_FAILURE; + } + puts("Block Driver Devices\n"); + puts("-----------------------------\n"); + for (entry = d; entry < d + n_ents; entry++) { + if (entry->id != UCLASS_BLK) + continue; + i = 0; + printf("%-20.20s", entry->name); + uclass_foreach_dev(udev, uc) { + if (udev->driver != entry) + continue; + desc = dev_get_uclass_platdata(udev); + printf("%c %s %u", i ? ',' : ':', + blk_get_if_type_name(desc->if_type), + desc->devnum); + i++; + } + if (!i) + puts(": "); + puts("\n"); + } + + return CMD_RET_SUCCESS; +} + +U_BOOT_CMD(lsblk, 1, 0, do_lsblk, "list block drivers and devices", + "- display list of block device drivers and attached block devices" +); diff --git a/test/py/tests/test_lsblk.py b/test/py/tests/test_lsblk.py new file mode 100644 index 0000000000..40ffe01263 --- /dev/null +++ b/test/py/tests/test_lsblk.py @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (C) 2020 +# Niel Fourie, DENX Software Engineering, lusus@denx.de + +import pytest + +@pytest.mark.buildconfigspec('blk') +@pytest.mark.buildconfigspec('cmd_lsblk') +def test_lsblk(u_boot_console): + """Test that `lsblk` prints a result which includes `host`.""" + output = u_boot_console.run_command('lsblk') + assert "Block Driver" in output + assert "sandbox_host_blk" in output