]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
virtio: cmd: Add virtio command for virtio devices
authorTuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Mon, 15 Oct 2018 09:21:12 +0000 (02:21 -0700)
committerSimon Glass <sjg@chromium.org>
Wed, 14 Nov 2018 17:16:27 +0000 (09:16 -0800)
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>
cmd/Kconfig
cmd/Makefile
cmd/virtio.c [new file with mode: 0644]

index ad14c9ce712489a03ecc4e8ea3cc7343bab64deb..d609f9d1c96078de90a195253751a63c0b1853b0 100644 (file)
@@ -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
index ac4830a692f22c60bf63460416f890b07e42a806..12a1330b0629fd9e151510340101e2b5f363bf72 100644 (file)
@@ -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 (file)
index 0000000..b7082bc
--- /dev/null
@@ -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'"
+);