2 * Copyright (c) 2012, Google Inc.
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <sandboxblockdev.h>
11 #include <asm/errno.h>
13 static int do_sandbox_load(cmd_tbl_t *cmdtp, int flag, int argc,
16 return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
19 static int do_sandbox_ls(cmd_tbl_t *cmdtp, int flag, int argc,
22 return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
25 static int do_sandbox_save(cmd_tbl_t *cmdtp, int flag, int argc,
28 return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
31 static int do_sandbox_bind(cmd_tbl_t *cmdtp, int flag, int argc,
34 if (argc < 2 || argc > 3)
37 char *dev_str = argv[1];
38 char *file = argc >= 3 ? argv[2] : NULL;
39 int dev = simple_strtoul(dev_str, &ep, 16);
41 printf("** Bad device specification %s **\n", dev_str);
44 return host_dev_bind(dev, file);
47 static int do_sandbox_info(cmd_tbl_t *cmdtp, int flag, int argc,
50 if (argc < 1 || argc > 2)
53 int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
56 char *dev_str = argv[1];
57 int dev = simple_strtoul(dev_str, &ep, 16);
59 printf("** Bad device specification %s **\n", dev_str);
66 printf("%3s %12s %s\n", "dev", "blocks", "path");
67 for (dev = min_dev; dev <= max_dev; dev++) {
68 block_dev_desc_t *blk_dev;
72 ret = host_get_dev_err(dev, &blk_dev);
75 puts("Not bound to a backing file\n");
76 else if (ret == -ENODEV)
77 puts("Invalid host device number\n");
81 struct host_block_dev *host_dev = blk_dev->priv;
82 printf("%12lu %s\n", (unsigned long)blk_dev->lba,
88 static cmd_tbl_t cmd_sandbox_sub[] = {
89 U_BOOT_CMD_MKENT(load, 7, 0, do_sandbox_load, "", ""),
90 U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", ""),
91 U_BOOT_CMD_MKENT(save, 6, 0, do_sandbox_save, "", ""),
92 U_BOOT_CMD_MKENT(bind, 3, 0, do_sandbox_bind, "", ""),
93 U_BOOT_CMD_MKENT(info, 3, 0, do_sandbox_info, "", ""),
96 static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc,
101 /* Skip past 'sandbox' */
105 c = find_cmd_tbl(argv[0], cmd_sandbox_sub,
106 ARRAY_SIZE(cmd_sandbox_sub));
109 return c->cmd(cmdtp, flag, argc, argv);
111 return CMD_RET_USAGE;
115 sb, 8, 1, do_sandbox,
116 "Miscellaneous sandbox commands",
117 "load host <dev> <addr> <filename> [<bytes> <offset>] - "
118 "load a file from host\n"
119 "sb ls host <filename> - list files on host\n"
120 "sb save host <dev> <filename> <addr> <bytes> [<offset>] - "
121 "save a file to host\n"
122 "sb bind <dev> [<filename>] - bind \"host\" device to file\n"
123 "sb info [<dev>] - show device binding & info"