Niel Fourie | e369790 | 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 | |
| 7 | #include <common.h> |
Heinrich Schuchardt | b961d55 | 2020-07-13 22:22:31 +0200 | [diff] [blame] | 8 | #include <blk.h> |
| 9 | #include <command.h> |
Niel Fourie | e369790 | 2020-03-30 17:22:58 +0200 | [diff] [blame] | 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; |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 37 | desc = dev_get_uclass_plat(udev); |
Niel Fourie | e369790 | 2020-03-30 17:22:58 +0200 | [diff] [blame] | 38 | printf("%c %s %u", i ? ',' : ':', |
| 39 | blk_get_if_type_name(desc->if_type), |
| 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 | ); |