Merge tag 'u-boot-amlogic-20200708' of https://gitlab.denx.de/u-boot/custodians/u...
[platform/kernel/u-boot.git] / cmd / lsblk.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2020
4  * Niel Fourie, DENX Software Engineering, lusus@denx.de.
5  */
6
7 #include <common.h>
8 #include <dm.h>
9
10 static int do_lsblk(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
11 {
12         struct driver *d = ll_entry_start(struct driver, driver);
13         const int n_ents = ll_entry_count(struct driver, driver);
14         struct driver *entry;
15         struct udevice *udev;
16         struct uclass *uc;
17         struct blk_desc *desc;
18         int ret, i;
19
20         ret = uclass_get(UCLASS_BLK, &uc);
21         if (ret) {
22                 puts("Could not get BLK uclass.\n");
23                 return CMD_RET_FAILURE;
24         }
25         puts("Block Driver          Devices\n");
26         puts("-----------------------------\n");
27         for (entry = d; entry < d + n_ents; entry++) {
28                 if (entry->id != UCLASS_BLK)
29                         continue;
30                 i = 0;
31                 printf("%-20.20s", entry->name);
32                 uclass_foreach_dev(udev, uc) {
33                         if (udev->driver != entry)
34                                 continue;
35                         desc = dev_get_uclass_platdata(udev);
36                         printf("%c %s %u", i ? ',' : ':',
37                                blk_get_if_type_name(desc->if_type),
38                                desc->devnum);
39                         i++;
40                 }
41                 if (!i)
42                         puts(": <none>");
43                 puts("\n");
44         }
45
46         return CMD_RET_SUCCESS;
47 }
48
49 U_BOOT_CMD(lsblk, 1, 0, do_lsblk, "list block drivers and devices",
50            "- display list of block device drivers and attached block devices"
51 );