lsblk.c 1.2 KB

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