diff mbox series

[U-Boot,2/2] distro_bootcmd: refactor virtio to support PCI block devices

Message ID 20190703125045.28116-3-david.abdurachmanov@sifive.com
State Superseded
Delegated to: Tom Rini
Headers show
Series Enable booting from VirtIO PCI connected storage | expand

Commit Message

David Abdurachmanov July 3, 2019, 12:50 p.m. UTC
libvirt v5.3.0 with QEMU 4.0.0 use PCI automatically and thus storage
is connected via PCI, which is not visible to U-Boot automatically.
Refactor to do "pci enum" followed by "virtio scan" to see PCI
connected storage.

Tested with Fedora/RISCV using the latest releases: libvirt 5.4.0,
QEMU 4.0.0 and U-Boot 2019.07 RC4.

Signed-off-by: David Abdurachmanov <david.abdurachmanov@sifive.com>
---
 include/config_distro_bootcmd.h | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

Comments

Bin Meng July 3, 2019, 1:32 p.m. UTC | #1
Hi David,

On Wed, Jul 3, 2019 at 8:52 PM David Abdurachmanov
<david.abdurachmanov@gmail.com> wrote:
>
> libvirt v5.3.0 with QEMU 4.0.0 use PCI automatically and thus storage

nits: 5.3.0 or 5.4.0?

> is connected via PCI, which is not visible to U-Boot automatically.
> Refactor to do "pci enum" followed by "virtio scan" to see PCI
> connected storage.
>
> Tested with Fedora/RISCV using the latest releases: libvirt 5.4.0,

Here mentions 5.4.0

> QEMU 4.0.0 and U-Boot 2019.07 RC4.
>
> Signed-off-by: David Abdurachmanov <david.abdurachmanov@sifive.com>
> ---
>  include/config_distro_bootcmd.h | 27 +++++++++++++++++++++------
>  1 file changed, 21 insertions(+), 6 deletions(-)
>
> diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
> index 26e61ef196..3570a32dff 100644
> --- a/include/config_distro_bootcmd.h
> +++ b/include/config_distro_bootcmd.h
> @@ -254,11 +254,11 @@
>  #endif
>
>  #if defined(CONFIG_DM_PCI)
> -#define BOOTENV_RUN_NET_PCI_ENUM "run boot_net_pci_enum; "
> +#define BOOTENV_RUN_PCI_ENUM "run boot_pci_enum; "
>  #define BOOTENV_SHARED_PCI \
> -       "boot_net_pci_enum=pci enum\0"
> +       "boot_pci_enum=pci enum\0"
>  #else
> -#define BOOTENV_RUN_NET_PCI_ENUM
> +#define BOOTENV_RUN_PCI_ENUM
>  #define BOOTENV_SHARED_PCI
>  #endif
>
> @@ -281,10 +281,24 @@
>  #endif
>
>  #ifdef CONFIG_CMD_VIRTIO
> -#define BOOTENV_SHARED_VIRTIO  BOOTENV_SHARED_BLKDEV(virtio)
> +#define BOOTENV_RUN_VIRTIO_INIT "run virtio_init; "
> +#define BOOTENV_SET_VIRTIO_NEED_INIT "virtio_need_init=; "
> +#define BOOTENV_SHARED_VIRTIO \
> +       "virtio_init=" \
> +               "if ${virtio_need_init}; then " \
> +                       "virtio_need_init=false; " \
> +                       "virtio scan; " \
> +               "fi\0" \
> +       \
> +       "virtio_boot=" \
> +               BOOTENV_RUN_PCI_ENUM \
> +               BOOTENV_RUN_VIRTIO_INIT \
> +               BOOTENV_SHARED_BLKDEV_BODY(virtio)

The changes should be surrounded by "#if defined(CONFIG_DM_PCI)".

>  #define BOOTENV_DEV_VIRTIO     BOOTENV_DEV_BLKDEV
>  #define BOOTENV_DEV_NAME_VIRTIO        BOOTENV_DEV_NAME_BLKDEV
>  #else
> +#define BOOTENV_RUN_VIRTIO_INIT
> +#define BOOTENV_SET_VIRTIO_NEED_INIT
>  #define BOOTENV_SHARED_VIRTIO
>  #define BOOTENV_DEV_VIRTIO \
>         BOOT_TARGET_DEVICES_references_VIRTIO_without_CONFIG_CMD_VIRTIO
> @@ -350,7 +364,7 @@
>  #define BOOTENV_DEV_DHCP(devtypeu, devtypel, instance) \
>         "bootcmd_dhcp=" \
>                 BOOTENV_RUN_NET_USB_START \
> -               BOOTENV_RUN_NET_PCI_ENUM \
> +               BOOTENV_RUN_PCI_ENUM \
>                 "if dhcp ${scriptaddr} ${boot_script_dhcp}; then " \
>                         "source ${scriptaddr}; " \
>                 "fi;" \
> @@ -369,7 +383,7 @@
>  #define BOOTENV_DEV_PXE(devtypeu, devtypel, instance) \
>         "bootcmd_pxe=" \
>                 BOOTENV_RUN_NET_USB_START \
> -               BOOTENV_RUN_NET_PCI_ENUM \
> +               BOOTENV_RUN_PCI_ENUM \
>                 "dhcp; " \
>                 "if pxe get; then " \
>                         "pxe boot; " \
> @@ -465,6 +479,7 @@
>         "distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT                      \
>                 BOOTENV_SET_NVME_NEED_INIT                                \
>                 BOOTENV_SET_IDE_NEED_INIT                                 \
> +               BOOTENV_SET_VIRTIO_NEED_INIT                              \
>                 "for target in ${boot_targets}; do "                      \
>                         "run bootcmd_${target}; "                         \
>                 "done\0"
> --

Regards,
Bin
diff mbox series

Patch

diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
index 26e61ef196..3570a32dff 100644
--- a/include/config_distro_bootcmd.h
+++ b/include/config_distro_bootcmd.h
@@ -254,11 +254,11 @@ 
 #endif
 
 #if defined(CONFIG_DM_PCI)
-#define BOOTENV_RUN_NET_PCI_ENUM "run boot_net_pci_enum; "
+#define BOOTENV_RUN_PCI_ENUM "run boot_pci_enum; "
 #define BOOTENV_SHARED_PCI \
-	"boot_net_pci_enum=pci enum\0"
+	"boot_pci_enum=pci enum\0"
 #else
-#define BOOTENV_RUN_NET_PCI_ENUM
+#define BOOTENV_RUN_PCI_ENUM
 #define BOOTENV_SHARED_PCI
 #endif
 
@@ -281,10 +281,24 @@ 
 #endif
 
 #ifdef CONFIG_CMD_VIRTIO
-#define BOOTENV_SHARED_VIRTIO	BOOTENV_SHARED_BLKDEV(virtio)
+#define BOOTENV_RUN_VIRTIO_INIT "run virtio_init; "
+#define BOOTENV_SET_VIRTIO_NEED_INIT "virtio_need_init=; "
+#define BOOTENV_SHARED_VIRTIO \
+	"virtio_init=" \
+		"if ${virtio_need_init}; then " \
+			"virtio_need_init=false; " \
+			"virtio scan; " \
+		"fi\0" \
+	\
+	"virtio_boot=" \
+		BOOTENV_RUN_PCI_ENUM \
+		BOOTENV_RUN_VIRTIO_INIT \
+		BOOTENV_SHARED_BLKDEV_BODY(virtio)
 #define BOOTENV_DEV_VIRTIO	BOOTENV_DEV_BLKDEV
 #define BOOTENV_DEV_NAME_VIRTIO	BOOTENV_DEV_NAME_BLKDEV
 #else
+#define BOOTENV_RUN_VIRTIO_INIT
+#define BOOTENV_SET_VIRTIO_NEED_INIT
 #define BOOTENV_SHARED_VIRTIO
 #define BOOTENV_DEV_VIRTIO \
 	BOOT_TARGET_DEVICES_references_VIRTIO_without_CONFIG_CMD_VIRTIO
@@ -350,7 +364,7 @@ 
 #define BOOTENV_DEV_DHCP(devtypeu, devtypel, instance) \
 	"bootcmd_dhcp=" \
 		BOOTENV_RUN_NET_USB_START \
-		BOOTENV_RUN_NET_PCI_ENUM \
+		BOOTENV_RUN_PCI_ENUM \
 		"if dhcp ${scriptaddr} ${boot_script_dhcp}; then " \
 			"source ${scriptaddr}; " \
 		"fi;" \
@@ -369,7 +383,7 @@ 
 #define BOOTENV_DEV_PXE(devtypeu, devtypel, instance) \
 	"bootcmd_pxe=" \
 		BOOTENV_RUN_NET_USB_START \
-		BOOTENV_RUN_NET_PCI_ENUM \
+		BOOTENV_RUN_PCI_ENUM \
 		"dhcp; " \
 		"if pxe get; then " \
 			"pxe boot; " \
@@ -465,6 +479,7 @@ 
 	"distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT                      \
 		BOOTENV_SET_NVME_NEED_INIT                                \
 		BOOTENV_SET_IDE_NEED_INIT                                 \
+		BOOTENV_SET_VIRTIO_NEED_INIT                              \
 		"for target in ${boot_targets}; do "                      \
 			"run bootcmd_${target}; "                         \
 		"done\0"