]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: Open host file for read-only access if needed
authorSimon Glass <sjg@chromium.org>
Mon, 28 Feb 2022 22:13:47 +0000 (15:13 -0700)
committerSimon Glass <sjg@chromium.org>
Sat, 19 Mar 2022 01:24:24 +0000 (19:24 -0600)
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>
drivers/block/sandbox.c

index 53925ce9b6921da543eb06baec519edf61db9df8..1388498a1d34ecce5dad57adf794e811dedfdd69 100644 (file)
@@ -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,