cmd: blkls: Add blkls command
PATCH v2 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.
cmd/Kconfig | 8 ++++++ cmd/Makefile | 1 + cmd/lsblk.c | 52 +++++++++++++++++++++++++++++++++++++ test/py/tests/test_lsblk.py | 13 ++++++++++ 4 files changed, 74 insertions(+) create mode 100644 cmd/lsblk.c create mode 100644 test/py/tests/test_lsblk.py
cmd/Kconfig +8 -0
@@ -1047,6 +1047,14 @@ 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" + default n + 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
@@ -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 +52 -0
52 lines not on this page · raw message
test/py/tests/test_lsblk.py new file +13 -0
@@ -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
PATCH v2 1/1 cmd: blkls: Add blkls command
Quoted 13 lines · Niel Fourie
Add a command to print a list of available block device drivers, and for each, the list of known block devices.
Signed-off-by Niel Fourie <[email protected]>Cc Simon Glass <[email protected]>Cc Stefan Roese <[email protected]>---
Changes in v2:
- Removed legacy block device variant of blkls and its test.
- Handle return value ofuclass_get().
- Removed unnecessary ifdefs, fixedKconfigdepends.
Quoted 7 lines
cmd/Kconfig | 8 ++++++ cmd/Makefile | 1 + cmd/lsblk.c | 52 +++++++++++++++++++++++++++++++++++++ test/py/tests/test_lsblk.py | 13 ++++++++++ 4 files changed, 74 insertions(+) create mode 100644 cmd/lsblk.c create mode 100644 test/py/tests/test_lsblk.py
nits below
cmd/Kconfig config CMD_LOADS · line 1053
Quoted 13 lines
cmd/Kconfig +4
-0@@ -1047,6 +1047,14 @@ 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" + default n
You can omit this since it is the default anyway.
Quoted 25 lines
cmd/Kconfig +4
-0+ help + Print list of available block device drivers, and for each, the list + of known block devices. + config CMD_MMC bool "mmc" helpcmd/Makefile +1
-0@@ -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.ocmd/lsblk.c new file +0
-0
cmd/lsblk.c line 7
Quoted 7 lines
cmd/lsblk.c new file +7
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* (C) Copyright 2020 +* Niel Fourie, DENX Software Engineering, lusus at denx.de. +*/ + +#include <config.h>
You can drop this
cmd/lsblk.c line 10
Quoted 3 lines
cmd/lsblk.c new file +3
-0+#include <common.h> +#include <dm/uclass.h> +#include <dm/device.h>
You can replace both of these with <dm.h>
Quoted 26 lines
cmd/lsblk.c new file +26
-0+ +static int do_lsblk (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ + struct driver *d = ll_entry_start(struct driver, driver); + const int n_ents = ll_entry_count(struct driver, driver); +struct driver *entry; +struct udevice *udev; +struct uclass *uc; +struct blk_desc *desc; +int ret, i; + + ret =uclass_get (UCLASS_BLK , &uc); +if (ret) { +puts ("Could not get BLK uclass.\n" ); +return CMD_RET_FAILURE ; + } +puts ("Block Driver Devices\n" ); +puts ("-----------------------------\n" ); +for (entry = d; entry < d + n_ents; entry++) { +if (entry->id !=UCLASS_BLK ) +continue ; + i =0 ; +printf ("%-20.20s" , entry->name); + uclass_foreach_dev(udev, uc) { +if (udev->driver != entry) +continue ;
cmd/lsblk.c line 46
Quoted 10 lines
cmd/lsblk.c new file +10
-0+ desc =dev_get_uclass_platdata (udev); +printf ("%c %s %u" , i ?',' :':' , +blk_get_if_type_name (desc->if_type), + desc->devnum); + i++; + } +if (!i) +puts (": <none>" ); +puts ("\n" ); + }
blank line before return
test/py/tests/test_lsblk.py line 1
Quoted 13 lines
cmd/lsblk.c new file +6
-0+return CMD_RET_SUCCESS ; +} + +U_BOOT_CMD (lsblk,1 ,0 , do_lsblk,"list block drivers and devices" , +"- display list of block device drivers and attached block devices" +);test/py/tests/test_lsblk.py new file +1
-0@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0
2.0+ ?
Quoted 13 lines
test/py/tests/test_lsblk.py new file +12
-1+# 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 --
Quoted 2 lines
2.25.1
Regards,
Simon
PATCH v2 1/1 cmd: blkls: Add blkls command
In reply to Niel FourieHi Niel,
Quoted 11 lines · Niel Fourie
Add a command to print a list of available block device drivers, and for each, the list of known block devices.
Signed-off-by Niel Fourie <[email protected]>Cc Simon Glass <[email protected]>Cc Stefan Roese <[email protected]>---
Changes in v2:
- Removed legacy block device variant of blkls and its test.
- Handle return value ofuclass_get().
- Removed unnecessary ifdefs, fixedKconfigdepends.
After addressing Simons comments, feel free to add my:
Thanks,
Stefan
Quoted 107 lines
cmd/Kconfig | 8 ++++++ cmd/Makefile | 1 + cmd/lsblk.c | 52 +++++++++++++++++++++++++++++++++++++ test/py/tests/test_lsblk.py | 13 ++++++++++ 4 files changed, 74 insertions(+)create mode 100644
cmd/lsblk.c
create mode 100644test/py/tests/test_lsblk.pycmd/Kconfig +8
-0@@ -1047,6 +1047,14 @@ 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" + default n + help + Print list of available block device drivers, and for each, the list + of known block devices. + config CMD_MMC bool "mmc" helpcmd/Makefile +1
-0@@ -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.ocmd/lsblk.c new file +52
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* (C) Copyright 2020 +* Niel Fourie, DENX Software Engineering, lusus at denx.de. +*/ + +#include <config.h> +#include <common.h> +#include <dm/uclass.h> +#include <dm/device.h> + +static int do_lsblk (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ + struct driver *d = ll_entry_start(struct driver, driver); + const int n_ents = ll_entry_count(struct driver, driver); +struct driver *entry; +struct udevice *udev; +struct uclass *uc; +struct blk_desc *desc; +int ret, i; + + ret =uclass_get (UCLASS_BLK , &uc); +if (ret) { +puts ("Could not get BLK uclass.\n" ); +return CMD_RET_FAILURE ; + } +puts ("Block Driver Devices\n" ); +puts ("-----------------------------\n" ); +for (entry = d; entry < d + n_ents; entry++) { +if (entry->id !=UCLASS_BLK ) +continue ; + i =0 ; +printf ("%-20.20s" , entry->name); + uclass_foreach_dev(udev, uc) { +if (udev->driver != entry) +continue ; + desc =dev_get_uclass_platdata (udev); +printf ("%c %s %u" , i ?',' :':' , +blk_get_if_type_name (desc->if_type), + desc->devnum); + i++; + } +if (!i) +puts (": <none>" ); +puts ("\n" ); + } +return CMD_RET_SUCCESS ; +} + +U_BOOT_CMD (lsblk,1 ,0 , do_lsblk,"list block drivers and devices" , +"- display list of block device drivers and attached block devices" +);test/py/tests/test_lsblk.py new file +3
-0@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 +# Niel Fourie, DENX Software Engineering, lusus at denx.de
test/py/tests/test_lsblk.py line 13
Quoted 10 lines
test/py/tests/test_lsblk.py new file +10
-0+ +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
Viele Gr??e,
Stefan
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de