diff options
author | Simon Glass <sjg@chromium.org> | 2022-02-28 15:13:47 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2022-03-18 19:24:24 -0600 |
commit | 7aa9dbd0abd6a223da41e3ad363f0ed28a6109ad (patch) | |
tree | a034a3063575d0ab0ef246ce76705a4be0e40d97 /drivers | |
parent | acc874a4c5d96d26658bbd90c9da500828b7ed96 (diff) | |
download | u-boot-7aa9dbd0abd6a223da41e3ad363f0ed28a6109ad.tar.gz u-boot-7aa9dbd0abd6a223da41e3ad363f0ed28a6109ad.tar.bz2 u-boot-7aa9dbd0abd6a223da41e3ad363f0ed28a6109ad.zip |
sandbox: Open host file for read-only access if needed
Some files cannot be written but read-only access is still useful for
tests. Add a fallback to read-only access when needed.
This is useful in CI when opening a large data file provided by docker,
where read/write access would result in copying the file, thus needing
a lot of extra disk space.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/block/sandbox.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c index 53925ce9b6..1388498a1d 100644 --- a/drivers/block/sandbox.c +++ b/drivers/block/sandbox.c @@ -125,9 +125,14 @@ int host_dev_bind(int devnum, char *filename, bool removable) fd = os_open(filename, OS_O_RDWR); if (fd == -1) { - printf("Failed to access host backing file '%s'\n", filename); - ret = -ENOENT; - goto err; + printf("Failed to access host backing file '%s', trying read-only\n", + filename); + fd = os_open(filename, OS_O_RDONLY); + if (fd == -1) { + printf("- still failed\n"); + ret = -ENOENT; + goto err; + } } ret = blk_create_device(gd->dm_root, "sandbox_host_blk", str, IF_TYPE_HOST, devnum, 512, |