diff options
author | Niel Fourie <lusus@denx.de> | 2020-03-30 17:22:58 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-07-07 15:37:13 -0400 |
commit | e369790843d87c2089ae93cd2345723a95ace71d (patch) | |
tree | 5a9c0e680c79b08f0d8c46f34ae3a60f3a2c9259 /cmd | |
parent | 2e48836895d1246b40f7e166695651882e7bb68c (diff) |
cmd: blkls: Add blkls command
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>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/Kconfig | 7 | ||||
-rw-r--r-- | cmd/Makefile | 1 | ||||
-rw-r--r-- | cmd/lsblk.c | 51 |
3 files changed, 59 insertions, 0 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig index 192b3b262f..0ead88eff1 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1088,6 +1088,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 974ad48b0a..006075a048 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -84,6 +84,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..ece8bbf108 --- /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(struct cmd_tbl *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" +); |