Merge tag 'u-boot-imx-next-20230404' of https://gitlab.denx.de/u-boot/custodians...
[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 <blk.h>
9 #include <command.h>
10 #include <dm.h>
11
12 static int do_lsblk(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
13 {
14         struct driver *d = ll_entry_start(struct driver, driver);
15         const int n_ents = ll_entry_count(struct driver, driver);
16         struct driver *entry;
17         struct udevice *udev;
18         struct uclass *uc;
19         struct blk_desc *desc;
20         int ret, i;
21
22         ret = uclass_get(UCLASS_BLK, &uc);
23         if (ret) {
24                 puts("Could not get BLK uclass.\n");
25                 return CMD_RET_FAILURE;
26         }
27         puts("Block Driver          Devices\n");
28         puts("-----------------------------\n");
29         for (entry = d; entry < d + n_ents; entry++) {
30                 if (entry->id != UCLASS_BLK)
31                         continue;
32                 i = 0;
33                 printf("%-20.20s", entry->name);
34                 uclass_foreach_dev(udev, uc) {
35                         if (udev->driver != entry)
36                                 continue;
37                         desc = dev_get_uclass_plat(udev);
38                         printf("%c %s %u", i ? ',' : ':',
39                                blk_get_uclass_name(desc->uclass_id),
40                                desc->devnum);
41                         i++;
42                 }
43                 if (!i)
44                         puts(": <none>");
45                 puts("\n");
46         }
47
48         return CMD_RET_SUCCESS;
49 }
50
51 U_BOOT_CMD(lsblk, 1, 0, do_lsblk, "list block drivers and devices",
52            "- display list of block device drivers and attached block devices"
53 );