Skip to contentSkip to conversation

cmd: blkls: Add blkls command

PATCH New Niel Fourie 3 participants 3 messages Mar 30, 2020 – Jul 9, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 cmd: blkls: Add blkls command

Add a command to print a list of available block device drivers, and for each, the list of known block devices.

---
Changes in v2:
- Removed legacy block device variant of blkls and its test.
- Handle return value of uclass_get().
- Removed unnecessary ifdefs, fixed Kconfig depends.

Changes is v3:
- Removed redundant "default n" in Kconfig.
- Corrected included headers, fixed formatting.
- Corrected license of the test.

 cmd/Kconfig                 |  7 +++++
 cmd/Makefile                |  1 +
 cmd/lsblk.c                 | 51 +++++++++++++++++++++++++++++++++++++
 test/py/tests/test_lsblk.py | 13 ++++++++++
 4 files changed, 72 insertions(+)
 create mode 100644 cmd/lsblk.c
 create mode 100644 test/py/tests/test_lsblk.py
cmd/Kconfig +7 -0
index 6403bc45a5..52c14d5420 100644
@@ -1047,6 +1047,13 @@ config CMD_LOADS
 	help
 	  Load an S-Record file over serial line
 
+config CMD_LSBLK
+	depends on BLK
+	bool "lsblk - list block drivers and devices"
+	help
+	  Print list of available block device drivers, and for each, the list
+	  of known block devices.
+
 config CMD_MMC
 	bool "mmc"
 	help
cmd/Makefile +1 -0
index f1dd513a4b..6f80974a55 100644
@@ -83,6 +83,7 @@ obj-$(CONFIG_CMD_LED) += led.o
 obj-$(CONFIG_CMD_LICENSE) += license.o
 obj-y += load.o
 obj-$(CONFIG_CMD_LOG) += log.o
+obj-$(CONFIG_CMD_LSBLK) += lsblk.o
 obj-$(CONFIG_ID_EEPROM) += mac.o
 obj-$(CONFIG_CMD_MD5SUM) += md5sum.o
 obj-$(CONFIG_CMD_MEMORY) += mem.o
cmd/lsblk.c new file +51 -0

51 lines not on this page · raw message

test/py/tests/test_lsblk.py new file +13 -0
new file mode 100644
index 0000000000..40ffe01263
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2020
+# Niel Fourie, DENX Software Engineering, lusus at denx.de
+
+import pytest
+
+ at pytest.mark.buildconfigspec('blk')
+ at pytest.mark.buildconfigspec('cmd_lsblk')
+def test_lsblk(u_boot_console):
+    """Test that `lsblk` prints a result which includes `host`."""
+    output = u_boot_console.run_command('lsblk')
+    assert "Block Driver" in output
+    assert "sandbox_host_blk" in output
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/1 cmd: blkls: Add blkls command

Quoted 8 lines · Niel Fourie

Add a command to print a list of available block device drivers, and for each, the list of known block devices.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200707/9a2efd2c/attachment.sig>
#2 lore raw

PATCH v3 1/1 cmd: blkls: Add blkls command

Quoted 5 lines · Tom Rini
Quoted 3 lines · Niel Fourie

Add a command to print a list of available block device drivers, and for each, the list of known block devices.

Quoted 8 lines
Quoted 5 lines

Applied to u-boot/master, thanks!

Compiling with CONFIG_CMD_LSB results in a bunch of errors:

cmd/lsblk.c:46:9: error: ?CMD_RET_SUCCESS? undeclared (first use in this function)

  return CMD_RET_SUCCESS;
         ^~~~~~~~~~~~~~~
cmd/lsblk.c: At top level:
cmd/lsblk.c:49:18: error: expected ?)? before numeric constant
 U_BOOT_CMD(lsblk, 1, 0, do_lsblk, "list block drivers and devices",
                  ^~
                  )

cmd/lsblk.c:10:12: warning: ?do_lsblk? defined but not used [-Wunused-function]

cmd/lsblk.c: In function ?do_lsblk?:
cmd/lsblk.c:38:11: warning: implicit declaration of function ?blk_get_if_type_name?; did you mean ?dev_get_uclass_name?? [-Wimplicit-function-declaration]

           blk_get_if_type_name(desc->if_type),
           ^~~~~~~~~~~~~~~~~~~~
           dev_get_uclass_name
cmd/lsblk.c:38:36: error: dereferencing pointer to incomplete type
?struct blk_desc?
           blk_get_if_type_name(desc->if_type),
                                    ^~

make[1]: *** [scripts/Makefile.build:265: cmd/lsblk.o] Error 1
make: *** [Makefile:1791: cmd] Error 2
make: *** Waiting for unfinished jobs....
LD drivers/i2c/built-in.o

Was this ever compiled before merging?

Best regards

Heinrich