[U-Boot] [PATCH V2] sandbox: restore ability to access host fs through standard commands

From: Stephen Warren swarren@nvidia.com
Commit 95fac6ab4589 "sandbox: Use os functions to read host device tree" removed the ability for get_device_and_partition() to handle the "host" device type, and redirect accesses to it to the host filesystem. This broke some unit tests that use this feature. So, revert that change. The code added back by this patch is slightly different to pacify checkpatch.
However, we're then left with "host" being both: - A pseudo device that accesses the hosts real filesystem. - An emulated block device, which accesses "sectors" inside a file stored on the host.
In order to resolve this discrepancy, rename the pseudo device from host to hostfs, and adjust the unit-tests for this change.
The "help sb" output is modified to reflect this rename, and state where the host and hostfs devices should be used.
Signed-off-by: Stephen Warren swarren@nvidia.com --- V2: * Fix typo due to fixing checkpatch and not recompiling:-( * Fix "help sb" output. --- common/cmd_sandbox.c | 10 ++++++---- disk/part.c | 19 +++++++++++++++++++ test/command_ut.c | 8 ++++---- 3 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/common/cmd_sandbox.c b/common/cmd_sandbox.c index 00982b164dd3..3d9fce7e5548 100644 --- a/common/cmd_sandbox.c +++ b/common/cmd_sandbox.c @@ -114,11 +114,13 @@ static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc, U_BOOT_CMD( sb, 8, 1, do_sandbox, "Miscellaneous sandbox commands", - "load host <dev> <addr> <filename> [<bytes> <offset>] - " + "load hostfs - <addr> <filename> [<bytes> <offset>] - " "load a file from host\n" - "sb ls host <filename> - list files on host\n" - "sb save host <dev> <filename> <addr> <bytes> [<offset>] - " + "sb ls hostfs - <filename> - list files on host\n" + "sb save hostfs - <filename> <addr> <bytes> [<offset>] - " "save a file to host\n" "sb bind <dev> [<filename>] - bind "host" device to file\n" - "sb info [<dev>] - show device binding & info" + "sb info [<dev>] - show device binding & info\n" + "sb commands use the "hostfs" device. The "host" device is used\n" + "with standard IO commands such as fatls or ext2load" ); diff --git a/disk/part.c b/disk/part.c index b3097e32f0eb..baceb19c60c7 100644 --- a/disk/part.c +++ b/disk/part.c @@ -510,6 +510,25 @@ int get_device_and_partition(const char *ifname, const char *dev_part_str, int part; disk_partition_t tmpinfo;
+ /* + * Special-case a psuedo block device "hostfs", to allow access to the + * host's own filesystem. + */ + if (0 == strcmp(ifname, "hostfs")) { + *dev_desc = NULL; + info->start = 0; + info->size = 0; + info->blksz = 0; + info->bootable = 0; + strcpy((char *)info->type, BOOT_PART_TYPE); + strcpy((char *)info->name, "Sandbox host"); +#ifdef CONFIG_PARTITION_UUIDS + info->uuid[0] = 0; +#endif + + return 0; + } + /* If no dev_part_str, use bootdevice environment variable */ if (!dev_part_str || !strlen(dev_part_str) || !strcmp(dev_part_str, "-")) diff --git a/test/command_ut.c b/test/command_ut.c index b2666bfc182b..ae6466d0ed83 100644 --- a/test/command_ut.c +++ b/test/command_ut.c @@ -165,12 +165,12 @@ static int do_ut_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
#ifdef CONFIG_SANDBOX /* File existence */ - HUSH_TEST(e, "-e host - creating_this_file_breaks_uboot_unit_test", n); - run_command("sb save host - creating_this_file_breaks_uboot_unit_test 0 1", 0); - HUSH_TEST(e, "-e host - creating_this_file_breaks_uboot_unit_test", y); + HUSH_TEST(e, "-e hostfs - creating_this_file_breaks_uboot_unit_test", n); + run_command("sb save hostfs - creating_this_file_breaks_uboot_unit_test 0 1", 0); + HUSH_TEST(e, "-e hostfs - creating_this_file_breaks_uboot_unit_test", y); /* Perhaps this could be replaced by an "rm" shell command one day */ assert(!os_unlink("creating_this_file_breaks_uboot_unit_test")); - HUSH_TEST(e, "-e host - creating_this_file_breaks_uboot_unit_test", n); + HUSH_TEST(e, "-e hostfs - creating_this_file_breaks_uboot_unit_test", n); #endif #endif

Hi, Stephen
On 6/12/2014 12:20 AM, Stephen Warren wrote:
From: Stephen Warren swarren@nvidia.com
Commit 95fac6ab4589 "sandbox: Use os functions to read host device tree" removed the ability for get_device_and_partition() to handle the "host" device type, and redirect accesses to it to the host filesystem. This broke some unit tests that use this feature. So, revert that change. The code added back by this patch is slightly different to pacify checkpatch.
However, we're then left with "host" being both:
- A pseudo device that accesses the hosts real filesystem.
- An emulated block device, which accesses "sectors" inside a file stored on the host.
In order to resolve this discrepancy, rename the pseudo device from host to hostfs, and adjust the unit-tests for this change.
The "help sb" output is modified to reflect this rename, and state where the host and hostfs devices should be used.
Signed-off-by: Stephen Warren swarren@nvidia.com
Tested-by: Josh Wu josh.wu@atmel.com
Best Regards, Josh Wu
V2:
- Fix typo due to fixing checkpatch and not recompiling:-(
- Fix "help sb" output.
common/cmd_sandbox.c | 10 ++++++---- disk/part.c | 19 +++++++++++++++++++ test/command_ut.c | 8 ++++---- 3 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/common/cmd_sandbox.c b/common/cmd_sandbox.c index 00982b164dd3..3d9fce7e5548 100644 --- a/common/cmd_sandbox.c +++ b/common/cmd_sandbox.c @@ -114,11 +114,13 @@ static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc, U_BOOT_CMD( sb, 8, 1, do_sandbox, "Miscellaneous sandbox commands",
- "load host <dev> <addr> <filename> [<bytes> <offset>] - "
- "load hostfs - <addr> <filename> [<bytes> <offset>] - " "load a file from host\n"
- "sb ls host <filename> - list files on host\n"
- "sb save host <dev> <filename> <addr> <bytes> [<offset>] - "
- "sb ls hostfs - <filename> - list files on host\n"
- "sb save hostfs - <filename> <addr> <bytes> [<offset>] - " "save a file to host\n" "sb bind <dev> [<filename>] - bind "host" device to file\n"
- "sb info [<dev>] - show device binding & info"
- "sb info [<dev>] - show device binding & info\n"
- "sb commands use the "hostfs" device. The "host" device is used\n"
- "with standard IO commands such as fatls or ext2load" );
diff --git a/disk/part.c b/disk/part.c index b3097e32f0eb..baceb19c60c7 100644 --- a/disk/part.c +++ b/disk/part.c @@ -510,6 +510,25 @@ int get_device_and_partition(const char *ifname, const char *dev_part_str, int part; disk_partition_t tmpinfo;
- /*
* Special-case a psuedo block device "hostfs", to allow access to the
* host's own filesystem.
*/
- if (0 == strcmp(ifname, "hostfs")) {
*dev_desc = NULL;
info->start = 0;
info->size = 0;
info->blksz = 0;
info->bootable = 0;
strcpy((char *)info->type, BOOT_PART_TYPE);
strcpy((char *)info->name, "Sandbox host");
+#ifdef CONFIG_PARTITION_UUIDS
info->uuid[0] = 0;
+#endif
return 0;
- }
- /* If no dev_part_str, use bootdevice environment variable */ if (!dev_part_str || !strlen(dev_part_str) || !strcmp(dev_part_str, "-"))
diff --git a/test/command_ut.c b/test/command_ut.c index b2666bfc182b..ae6466d0ed83 100644 --- a/test/command_ut.c +++ b/test/command_ut.c @@ -165,12 +165,12 @@ static int do_ut_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
#ifdef CONFIG_SANDBOX /* File existence */
- HUSH_TEST(e, "-e host - creating_this_file_breaks_uboot_unit_test", n);
- run_command("sb save host - creating_this_file_breaks_uboot_unit_test 0 1", 0);
- HUSH_TEST(e, "-e host - creating_this_file_breaks_uboot_unit_test", y);
- HUSH_TEST(e, "-e hostfs - creating_this_file_breaks_uboot_unit_test", n);
- run_command("sb save hostfs - creating_this_file_breaks_uboot_unit_test 0 1", 0);
- HUSH_TEST(e, "-e hostfs - creating_this_file_breaks_uboot_unit_test", y); /* Perhaps this could be replaced by an "rm" shell command one day */ assert(!os_unlink("creating_this_file_breaks_uboot_unit_test"));
- HUSH_TEST(e, "-e host - creating_this_file_breaks_uboot_unit_test", n);
- HUSH_TEST(e, "-e hostfs - creating_this_file_breaks_uboot_unit_test", n); #endif #endif

Hi Stephen,
On 11 June 2014 12:20, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
Commit 95fac6ab4589 "sandbox: Use os functions to read host device tree" removed the ability for get_device_and_partition() to handle the "host" device type, and redirect accesses to it to the host filesystem. This broke some unit tests that use this feature. So, revert that change. The code added back by this patch is slightly different to pacify checkpatch.
However, we're then left with "host" being both:
- A pseudo device that accesses the hosts real filesystem.
- An emulated block device, which accesses "sectors" inside a file stored on the host.
In order to resolve this discrepancy, rename the pseudo device from host to hostfs, and adjust the unit-tests for this change.
The "help sb" output is modified to reflect this rename, and state where the host and hostfs devices should be used.
Signed-off-by: Stephen Warren swarren@nvidia.com
One more thing to be complete - can you please update line 17 of test/vboot/vboot_test.sh to use this? You can then test it with something like:
make O=sandbox sandbox_config all O=sandbox ./test/vboot/vboot_test.sh
Regards, Simon
participants (3)
-
Josh Wu
-
Simon Glass
-
Stephen Warren