Init virtio before loading ENV from EXT4 or FAT

Specifying a file in an EXT4 or FAT partition on a virtio device as
environment location failed because virtio hadn't been initialized by
the time the environment was loaded. This patch mirrors commit
54ee5ae841 ("Add SCSI scan for ENV in EXT4 or FAT") in issue and
fix, just for a different kind of block device.

The additional include in include/virtio.h is needed so all functions
called there are defined, the alternative would have been to include
dm/device.h separately in the env/ sources.

Checkpatch suggests using "if (IS_ENABLED(CONFIG...))" instead of
"#if defined(CONFIG_...)", I'm sticking to the style of the existing
code here.

Signed-off-by: Fiona Klute <fiona.klute@gmx.de>
CC: Joe Hershberger <joe.hershberger@ni.com>
CC: Bin Meng <bmeng.cn@gmail.com>
CC: Rogier Stam <rogier@unrailed.org>
This commit is contained in:
Fiona Klute 2024-05-01 10:54:09 +02:00 committed by Tom Rini
parent ad7dce5abd
commit 3be9f399e9
3 changed files with 11 additions and 0 deletions

5
env/ext4.c vendored
View file

@ -31,6 +31,7 @@
#include <ext4fs.h>
#include <mmc.h>
#include <scsi.h>
#include <virtio.h>
#include <asm/global_data.h>
DECLARE_GLOBAL_DATA_PTR;
@ -150,6 +151,10 @@ static int env_ext4_load(void)
if (!strcmp(ifname, "scsi"))
scsi_scan(true);
#endif
#if defined(CONFIG_VIRTIO)
if (!strcmp(ifname, "virtio"))
virtio_init();
#endif
part = blk_get_device_part_str(ifname, dev_and_part,
&dev_desc, &info, 1);

5
env/fat.c vendored
View file

@ -17,6 +17,7 @@
#include <fat.h>
#include <mmc.h>
#include <scsi.h>
#include <virtio.h>
#include <asm/cache.h>
#include <asm/global_data.h>
#include <linux/stddef.h>
@ -133,6 +134,10 @@ static int env_fat_load(void)
if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "scsi"))
scsi_scan(true);
#endif
#if defined(CONFIG_VIRTIO)
if (!strcmp(ifname, "virtio"))
virtio_init();
#endif
#endif
part = blk_get_device_part_str(ifname, dev_and_part,
&dev_desc, &info, 1);

View file

@ -21,6 +21,7 @@
#define __VIRTIO_H__
#include <virtio_types.h>
#include <dm/device.h>
#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/typecheck.h>