blob: 7c00bfdc7a09a0b28adca7a00bfe82587a174fba [file] [log] [blame]
Niel Fouriee3697902020-03-30 17:22:58 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2020
4 * Niel Fourie, DENX Software Engineering, lusus@denx.de.
5 */
6
Heinrich Schuchardtb961d552020-07-13 22:22:31 +02007#include <blk.h>
8#include <command.h>
Niel Fouriee3697902020-03-30 17:22:58 +02009#include <dm.h>
10
11static int do_lsblk(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
12{
13 struct driver *d = ll_entry_start(struct driver, driver);
14 const int n_ents = ll_entry_count(struct driver, driver);
15 struct driver *entry;
16 struct udevice *udev;
17 struct uclass *uc;
18 struct blk_desc *desc;
19 int ret, i;
20
21 ret = uclass_get(UCLASS_BLK, &uc);
22 if (ret) {
23 puts("Could not get BLK uclass.\n");
24 return CMD_RET_FAILURE;
25 }
26 puts("Block Driver Devices\n");
27 puts("-----------------------------\n");
28 for (entry = d; entry < d + n_ents; entry++) {
29 if (entry->id != UCLASS_BLK)
30 continue;
31 i = 0;
32 printf("%-20.20s", entry->name);
33 uclass_foreach_dev(udev, uc) {
34 if (udev->driver != entry)
35 continue;
Simon Glasscaa4daa2020-12-03 16:55:18 -070036 desc = dev_get_uclass_plat(udev);
Niel Fouriee3697902020-03-30 17:22:58 +020037 printf("%c %s %u", i ? ',' : ':',
Simon Glass8149b152022-09-17 09:00:09 -060038 blk_get_uclass_name(desc->uclass_id),
Niel Fouriee3697902020-03-30 17:22:58 +020039 desc->devnum);
40 i++;
41 }
42 if (!i)
43 puts(": <none>");
44 puts("\n");
45 }
46
47 return CMD_RET_SUCCESS;
48}
49
50U_BOOT_CMD(lsblk, 1, 0, do_lsblk, "list block drivers and devices",
51 "- display list of block device drivers and attached block devices"
52);