Niel Fourie | 09262bb | 2020-03-30 17:22:58 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2020 |
| 4 | * Niel Fourie, DENX Software Engineering, lusus@denx.de. |
| 5 | */ |
| 6 | |
Heinrich Schuchardt | b1edfd2 | 2020-07-13 22:22:31 +0200 | [diff] [blame] | 7 | #include <blk.h> |
| 8 | #include <command.h> |
Niel Fourie | 09262bb | 2020-03-30 17:22:58 +0200 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | |
| 11 | static 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 Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 36 | desc = dev_get_uclass_plat(udev); |
Niel Fourie | 09262bb | 2020-03-30 17:22:58 +0200 | [diff] [blame] | 37 | printf("%c %s %u", i ? ',' : ':', |
Simon Glass | fada3f9 | 2022-09-17 09:00:09 -0600 | [diff] [blame] | 38 | blk_get_uclass_name(desc->uclass_id), |
Niel Fourie | 09262bb | 2020-03-30 17:22:58 +0200 | [diff] [blame] | 39 | desc->devnum); |
| 40 | i++; |
| 41 | } |
| 42 | if (!i) |
| 43 | puts(": <none>"); |
| 44 | puts("\n"); |
| 45 | } |
| 46 | |
| 47 | return CMD_RET_SUCCESS; |
| 48 | } |
| 49 | |
| 50 | U_BOOT_CMD(lsblk, 1, 0, do_lsblk, "list block drivers and devices", |
| 51 | "- display list of block device drivers and attached block devices" |
| 52 | ); |