blob: d214dafc3bee0353e39b251131153b34cbafa2f0 [file] [log] [blame]
Niel Fourie09262bb2020-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
Tom Riniabb9a042024-05-18 20:20:43 -06007#include <common.h>
Heinrich Schuchardtb1edfd22020-07-13 22:22:31 +02008#include <blk.h>
9#include <command.h>
Niel Fourie09262bb2020-03-30 17:22:58 +020010#include <dm.h>
11
12static 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;
Simon Glass71fa5b42020-12-03 16:55:18 -070037 desc = dev_get_uclass_plat(udev);
Niel Fourie09262bb2020-03-30 17:22:58 +020038 printf("%c %s %u", i ? ',' : ':',
Simon Glassfada3f92022-09-17 09:00:09 -060039 blk_get_uclass_name(desc->uclass_id),
Niel Fourie09262bb2020-03-30 17:22:58 +020040 desc->devnum);
41 i++;
42 }
43 if (!i)
44 puts(": <none>");
45 puts("\n");
46 }
47
48 return CMD_RET_SUCCESS;
49}
50
51U_BOOT_CMD(lsblk, 1, 0, do_lsblk, "list block drivers and devices",
52 "- display list of block device drivers and attached block devices"
53);