diff --git a/drivers/mmc/sandbox_mmc.c b/drivers/mmc/sandbox_mmc.c index f49cb4b146a..74427db7e06 100644 --- a/drivers/mmc/sandbox_mmc.c +++ b/drivers/mmc/sandbox_mmc.c @@ -170,11 +170,20 @@ static int sandbox_mmc_probe(struct udevice *dev) int ret; if (plat->fname) { - ret = os_map_file(plat->fname, OS_O_RDWR | OS_O_CREAT, + const char *fname = plat->fname; + char buf[256]; + + /* + * Try persistent data directory first, then fall back to the + * filename as given (for absolute paths or current directory) + */ + if (!os_persistent_file(buf, sizeof(buf), plat->fname)) + fname = buf; + ret = os_map_file(fname, OS_O_RDWR | OS_O_CREAT, (void **)&priv->buf, &priv->size); if (ret) { log_err("%s: Unable to map file '%s'\n", dev->name, - plat->fname); + fname); return ret; } priv->csize = priv->size / SIZE_MULTIPLE - 1; diff --git a/drivers/scsi/sandbox_scsi.c b/drivers/scsi/sandbox_scsi.c index 3c451313109..97afeddc2e9 100644 --- a/drivers/scsi/sandbox_scsi.c +++ b/drivers/scsi/sandbox_scsi.c @@ -104,9 +104,18 @@ static int sandbox_scsi_probe(struct udevice *dev) info->block_size = SANDBOX_SCSI_BLOCK_LEN; if (priv->pathname) { - priv->fd = os_open(priv->pathname, OS_O_RDONLY); + const char *pathname = priv->pathname; + char buf[256]; + + /* + * Try persistent data directory first, then fall back to the + * pathname as given (for absolute paths or current directory) + */ + if (!os_persistent_file(buf, sizeof(buf), priv->pathname)) + pathname = buf; + priv->fd = os_open(pathname, OS_O_RDONLY); if (priv->fd >= 0) { - ret = os_get_filesize(priv->pathname, &info->file_size); + ret = os_get_filesize(pathname, &info->file_size); if (ret) return log_msg_ret("sz", ret); } diff --git a/drivers/usb/emul/sandbox_flash.c b/drivers/usb/emul/sandbox_flash.c index 25d968e91c7..82aa7062865 100644 --- a/drivers/usb/emul/sandbox_flash.c +++ b/drivers/usb/emul/sandbox_flash.c @@ -339,11 +339,19 @@ static int sandbox_flash_probe(struct udevice *dev) struct sandbox_flash_plat *plat = dev_get_plat(dev); struct sandbox_flash_priv *priv = dev_get_priv(dev); struct scsi_emul_info *info = &priv->eminfo; + const char *pathname = plat->pathname; + char buf[256]; int ret; - priv->fd = os_open(plat->pathname, OS_O_RDWR); + /* + * Try persistent data directory first, then fall back to the + * pathname as given (for absolute paths or current directory) + */ + if (!os_persistent_file(buf, sizeof(buf), plat->pathname)) + pathname = buf; + priv->fd = os_open(pathname, OS_O_RDWR); if (priv->fd >= 0) { - ret = os_get_filesize(plat->pathname, &info->file_size); + ret = os_get_filesize(pathname, &info->file_size); if (ret) return log_msg_ret("sz", ret); } diff --git a/test/py/img/armbian.py b/test/py/img/armbian.py index e1ae9b0aae9..db7fb43ddf6 100644 --- a/test/py/img/armbian.py +++ b/test/py/img/armbian.py @@ -126,7 +126,7 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} utils.run_and_log_no_ubman(log, f'echo here {kernel} {symlink}') os.symlink(kernel, symlink) fsh.mk_fs() - img = DiskHelper(config, mmc_dev, 'mmc', True) + img = DiskHelper(config, mmc_dev, 'mmc') img.add_fs(fsh, DiskHelper.EXT4) img.create() fsh.cleanup() diff --git a/test/py/img/common.py b/test/py/img/common.py index 547066b24a5..25edc84944e 100644 --- a/test/py/img/common.py +++ b/test/py/img/common.py @@ -84,7 +84,7 @@ def setup_extlinux_image(config, log, devnum, basename, vmlinux, initrd, dtbdir, fsh.mk_fs() - img = DiskHelper(config, devnum, basename, True) + img = DiskHelper(config, devnum, basename) img.add_fs(fsh, DiskHelper.VFAT, bootable=True) ext4 = FsHelper(config, 'ext4', max(1, part2_size - 30), prefix=basename, diff --git a/test/py/img/efi.py b/test/py/img/efi.py index 8239b4c247f..4cb55c957ec 100644 --- a/test/py/img/efi.py +++ b/test/py/img/efi.py @@ -31,7 +31,7 @@ def setup_efi_image(config): fsh.mk_fs() - img = DiskHelper(config, devnum, 'flash', True) + img = DiskHelper(config, devnum, 'flash') img.add_fs(fsh, DiskHelper.VFAT) img.create() fsh.cleanup() diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index b9ba240c848..70a748a31f9 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -34,7 +34,8 @@ from img.localboot import setup_localboot_image def test_ut_dm_init(ubman): """Initialize data for ut dm tests.""" - fn = ubman.config.source_dir + '/testflash.bin' + # This is used by flash-stick@0 in test.py + fn = ubman.config.persistent_data_dir + '/testflash.bin' if not os.path.exists(fn): data = b'this is a test' data += b'\x00' * ((4 * 1024 * 1024) - len(data)) @@ -47,8 +48,8 @@ def test_ut_dm_init(ubman): with open(fn, 'wb') as fh: fh.write(data) - # Create a file with a single partition - fn = ubman.config.source_dir + '/scsi.img' + # Create a file with a single partition (used by /scsi in test.dts) */ + fn = ubman.config.persistent_data_dir + '/scsi.img' if not os.path.exists(fn): data = b'\x00' * (2 * 1024 * 1024) with open(fn, 'wb') as fh: @@ -56,11 +57,13 @@ def test_ut_dm_init(ubman): utils.run_and_log( ubman, f'sfdisk {fn}', stdin=b'type=83') + # These two are used by test/dm/host.c FsHelper(ubman.config, 'ext2', 2, '2MB').mk_fs() FsHelper(ubman.config, 'fat32', 1, '1MB').mk_fs() + # This is used by test/cmd/mbr.c mmc_dev = 6 - fn = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') + fn = os.path.join(ubman.config.persistent_data_dir, f'mmc{mmc_dev}.img') data = b'\x00' * (12 * 1024 * 1024) with open(fn, 'wb') as fh: fh.write(data)