Message ID | 20200330152258.2375526-1-lusus@denx.de |
---|---|
State | Accepted |
Delegated to: | Tom Rini |
Headers | show |
Series | [v3,1/1] cmd: blkls: Add blkls command | expand |
On Mon, Mar 30, 2020 at 05:22:58PM +0200, Niel Fourie wrote: > 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 <lusus@denx.de> > Cc: Simon Glass <sjg@chromium.org> > Cc: Stefan Roese <sr@denx.de> > Reviewed-by: Simon Glass <sjg@chromium.org> > Reviewed-by: Stefan Roese <sr@denx.de> Applied to u-boot/master, thanks!
On 7/8/20 5:02 AM, Tom Rini wrote: > On Mon, Mar 30, 2020 at 05:22:58PM +0200, Niel Fourie wrote: > >> 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 <lusus@denx.de> >> Cc: Simon Glass <sjg@chromium.org> >> Cc: Stefan Roese <sr@denx.de> >> Reviewed-by: Simon Glass <sjg@chromium.org> >> Reviewed-by: Stefan Roese <sr@denx.de> > > Applied to u-boot/master, thanks! > Compiling with CONFIG_CMD_LSB results in a bunch of errors: cmd/lsblk.c:46:9: error: ‘CMD_RET_SUCCESS’ undeclared (first use in this function) return CMD_RET_SUCCESS; ^~~~~~~~~~~~~~~ cmd/lsblk.c: At top level: cmd/lsblk.c:49:18: error: expected ‘)’ before numeric constant U_BOOT_CMD(lsblk, 1, 0, do_lsblk, "list block drivers and devices", ^~ ) cmd/lsblk.c:10:12: warning: ‘do_lsblk’ defined but not used [-Wunused-function] cmd/lsblk.c: In function ‘do_lsblk’: cmd/lsblk.c:38:11: warning: implicit declaration of function ‘blk_get_if_type_name’; did you mean ‘dev_get_uclass_name’? [-Wimplicit-function-declaration] blk_get_if_type_name(desc->if_type), ^~~~~~~~~~~~~~~~~~~~ dev_get_uclass_name cmd/lsblk.c:38:36: error: dereferencing pointer to incomplete type ‘struct blk_desc’ blk_get_if_type_name(desc->if_type), ^~ make[1]: *** [scripts/Makefile.build:265: cmd/lsblk.o] Error 1 make: *** [Makefile:1791: cmd] Error 2 make: *** Waiting for unfinished jobs.... LD drivers/i2c/built-in.o Was this ever compiled before merging? Best regards Heinrich
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 <common.h> +#include <dm.h> + +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(": <none>"); + 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