aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuomas Tynkkynen2018-10-15 02:21:12 -0700
committerSimon Glass2018-11-14 09:16:27 -0800
commit78e12901f3fc8d228bd050f35594e1994f6a7d35 (patch)
treec2640b7f9fe4ca591608c06552c0489666377e45
parentf4802209e59da759b2d1bfcf136d6855984a5d05 (diff)
virtio: cmd: Add virtio command for virtio devices
Add 'virtio' command in U-Boot command line. Signed-off-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi> Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--cmd/Kconfig7
-rw-r--r--cmd/Makefile1
-rw-r--r--cmd/virtio.c38
3 files changed, 46 insertions, 0 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index ad14c9ce712..d609f9d1c96 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1065,6 +1065,13 @@ config CMD_USB_MASS_STORAGE
help
USB mass storage support
+config CMD_VIRTIO
+ bool "virtio"
+ depends on VIRTIO
+ default y if VIRTIO
+ help
+ VirtIO block device support
+
config CMD_AXI
bool "axi"
depends on AXI
diff --git a/cmd/Makefile b/cmd/Makefile
index ac4830a692f..12a1330b062 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -135,6 +135,7 @@ obj-$(CONFIG_CMD_UBI) += ubi.o
obj-$(CONFIG_CMD_UBIFS) += ubifs.o
obj-$(CONFIG_CMD_UNIVERSE) += universe.o
obj-$(CONFIG_CMD_UNZIP) += unzip.o
+obj-$(CONFIG_CMD_VIRTIO) += virtio.o
obj-$(CONFIG_CMD_LZMADEC) += lzmadec.o
obj-$(CONFIG_CMD_USB) += usb.o disk.o
diff --git a/cmd/virtio.c b/cmd/virtio.c
new file mode 100644
index 00000000000..b7082bc63ad
--- /dev/null
+++ b/cmd/virtio.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
+ * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <virtio_types.h>
+#include <virtio.h>
+
+static int virtio_curr_dev;
+
+static int do_virtio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ if (argc == 2 && !strcmp(argv[1], "scan")) {
+ /* make sure all virtio devices are enumerated */
+ virtio_init();
+
+ return CMD_RET_SUCCESS;
+ }
+
+ return blk_common_cmd(argc, argv, IF_TYPE_VIRTIO, &virtio_curr_dev);
+}
+
+U_BOOT_CMD(
+ virtio, 8, 1, do_virtio,
+ "virtio block devices sub-system",
+ "scan - initialize virtio bus\n"
+ "virtio info - show all available virtio block devices\n"
+ "virtio device [dev] - show or set current virtio block device\n"
+ "virtio part [dev] - print partition table of one or all virtio block devices\n"
+ "virtio read addr blk# cnt - read `cnt' blocks starting at block\n"
+ " `blk#' to memory address `addr'\n"
+ "virtio write addr blk# cnt - write `cnt' blocks starting at block\n"
+ " `blk#' from memory address `addr'"
+);