summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorHenrik Nordström <henrik@henriknordstrom.net>2013-11-10 10:26:56 -0700
committerSimon Glass <sjg@chromium.org>2014-01-08 17:24:03 -0700
commitf4d8de48f5a2aa1885daa0d425b8c0568a2ccb69 (patch)
treed86aea3653bfff137f2a94bea66d5fbddcb59853 /common
parent60d18d3fe9d1a5db663711063cd0d5c915af377a (diff)
downloadblackbird-obmc-uboot-f4d8de48f5a2aa1885daa0d425b8c0568a2ccb69.tar.gz
blackbird-obmc-uboot-f4d8de48f5a2aa1885daa0d425b8c0568a2ccb69.zip
sandbox: block driver using host file/device as backing store
Provide a way to use any host file or device as a block device in U-Boot. This can be used to provide filesystem access within U-Boot to an ext2 image file on the host, for example. The support is plumbed into the filesystem and partition interfaces. We don't want to print a message in the driver every time we find a missing device. Pass the information back to the caller where a message can be printed if desired. Signed-off-by: Henrik Nordström <henrik@henriknordstrom.net> Signed-off-by: Simon Glass <sjg@chromium.org> - Removed change to part.c get_device_and_partition() Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/cmd_sandbox.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/common/cmd_sandbox.c b/common/cmd_sandbox.c
index 8d59364b63..00982b164d 100644
--- a/common/cmd_sandbox.c
+++ b/common/cmd_sandbox.c
@@ -6,6 +6,9 @@
#include <common.h>
#include <fs.h>
+#include <part.h>
+#include <sandboxblockdev.h>
+#include <asm/errno.h>
static int do_sandbox_load(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
@@ -25,10 +28,69 @@ static int do_sandbox_save(cmd_tbl_t *cmdtp, int flag, int argc,
return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
}
+static int do_sandbox_bind(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+ if (argc < 2 || argc > 3)
+ return CMD_RET_USAGE;
+ char *ep;
+ char *dev_str = argv[1];
+ char *file = argc >= 3 ? argv[2] : NULL;
+ int dev = simple_strtoul(dev_str, &ep, 16);
+ if (*ep) {
+ printf("** Bad device specification %s **\n", dev_str);
+ return CMD_RET_USAGE;
+ }
+ return host_dev_bind(dev, file);
+}
+
+static int do_sandbox_info(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+ if (argc < 1 || argc > 2)
+ return CMD_RET_USAGE;
+ int min_dev = 0;
+ int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
+ if (argc >= 2) {
+ char *ep;
+ char *dev_str = argv[1];
+ int dev = simple_strtoul(dev_str, &ep, 16);
+ if (*ep) {
+ printf("** Bad device specification %s **\n", dev_str);
+ return CMD_RET_USAGE;
+ }
+ min_dev = dev;
+ max_dev = dev;
+ }
+ int dev;
+ printf("%3s %12s %s\n", "dev", "blocks", "path");
+ for (dev = min_dev; dev <= max_dev; dev++) {
+ block_dev_desc_t *blk_dev;
+ int ret;
+
+ printf("%3d ", dev);
+ ret = host_get_dev_err(dev, &blk_dev);
+ if (ret) {
+ if (ret == -ENOENT)
+ puts("Not bound to a backing file\n");
+ else if (ret == -ENODEV)
+ puts("Invalid host device number\n");
+
+ continue;
+ }
+ struct host_block_dev *host_dev = blk_dev->priv;
+ printf("%12lu %s\n", (unsigned long)blk_dev->lba,
+ host_dev->filename);
+ }
+ return 0;
+}
+
static cmd_tbl_t cmd_sandbox_sub[] = {
U_BOOT_CMD_MKENT(load, 7, 0, do_sandbox_load, "", ""),
U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", ""),
U_BOOT_CMD_MKENT(save, 6, 0, do_sandbox_save, "", ""),
+ U_BOOT_CMD_MKENT(bind, 3, 0, do_sandbox_bind, "", ""),
+ U_BOOT_CMD_MKENT(info, 3, 0, do_sandbox_info, "", ""),
};
static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -57,4 +119,6 @@ U_BOOT_CMD(
"sb ls host <filename> - list files on host\n"
"sb save host <dev> <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"
);
OpenPOWER on IntegriCloud