2 * Copyright (c) 2012, Google Inc.
4 * SPDX-License-Identifier: GPL-2.0+
11 #include <sandboxblockdev.h>
12 #include <linux/errno.h>
14 static int host_curr_device = -1;
16 static int do_host_load(cmd_tbl_t *cmdtp, int flag, int argc,
19 return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
22 static int do_host_ls(cmd_tbl_t *cmdtp, int flag, int argc,
25 return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
28 static int do_host_size(cmd_tbl_t *cmdtp, int flag, int argc,
31 return do_size(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
34 static int do_host_save(cmd_tbl_t *cmdtp, int flag, int argc,
37 return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
40 static int do_host_bind(cmd_tbl_t *cmdtp, int flag, int argc,
43 if (argc < 2 || argc > 3)
46 char *dev_str = argv[1];
47 char *file = argc >= 3 ? argv[2] : NULL;
48 int dev = simple_strtoul(dev_str, &ep, 16);
50 printf("** Bad device specification %s **\n", dev_str);
53 return host_dev_bind(dev, file);
56 static int do_host_info(cmd_tbl_t *cmdtp, int flag, int argc,
59 if (argc < 1 || argc > 2)
62 int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
65 char *dev_str = argv[1];
66 int dev = simple_strtoul(dev_str, &ep, 16);
68 printf("** Bad device specification %s **\n", dev_str);
75 printf("%3s %12s %s\n", "dev", "blocks", "path");
76 for (dev = min_dev; dev <= max_dev; dev++) {
77 struct blk_desc *blk_dev;
81 ret = host_get_dev_err(dev, &blk_dev);
84 puts("Not bound to a backing file\n");
85 else if (ret == -ENODEV)
86 puts("Invalid host device number\n");
90 struct host_block_dev *host_dev;
93 host_dev = dev_get_priv(blk_dev->bdev);
95 host_dev = blk_dev->priv;
97 printf("%12lu %s\n", (unsigned long)blk_dev->lba,
103 static int do_host_dev(cmd_tbl_t *cmdtp, int flag, int argc,
108 struct blk_desc *blk_dev;
111 if (argc < 1 || argc > 3)
112 return CMD_RET_USAGE;
115 if (host_curr_device < 0) {
116 printf("No current host device\n");
119 printf("Current host device %d\n", host_curr_device);
123 dev = simple_strtoul(argv[1], &ep, 16);
125 printf("** Bad device specification %s **\n", argv[2]);
126 return CMD_RET_USAGE;
129 ret = host_get_dev_err(dev, &blk_dev);
132 puts("Not bound to a backing file\n");
133 else if (ret == -ENODEV)
134 puts("Invalid host device number\n");
139 host_curr_device = dev;
143 static cmd_tbl_t cmd_host_sub[] = {
144 U_BOOT_CMD_MKENT(load, 7, 0, do_host_load, "", ""),
145 U_BOOT_CMD_MKENT(ls, 3, 0, do_host_ls, "", ""),
146 U_BOOT_CMD_MKENT(save, 6, 0, do_host_save, "", ""),
147 U_BOOT_CMD_MKENT(size, 3, 0, do_host_size, "", ""),
148 U_BOOT_CMD_MKENT(bind, 3, 0, do_host_bind, "", ""),
149 U_BOOT_CMD_MKENT(info, 3, 0, do_host_info, "", ""),
150 U_BOOT_CMD_MKENT(dev, 0, 1, do_host_dev, "", ""),
153 static int do_host(cmd_tbl_t *cmdtp, int flag, int argc,
158 /* Skip past 'host' */
162 c = find_cmd_tbl(argv[0], cmd_host_sub,
163 ARRAY_SIZE(cmd_host_sub));
166 return c->cmd(cmdtp, flag, argc, argv);
168 return CMD_RET_USAGE;
173 "Deprecated: use 'host' command instead.", ""
178 "Miscellaneous host commands",
179 "load hostfs - <addr> <filename> [<bytes> <offset>] - "
180 "load a file from host\n"
181 "host ls hostfs - <filename> - list files on host\n"
182 "host save hostfs - <addr> <filename> <bytes> [<offset>] - "
183 "save a file to host\n"
184 "host size hostfs - <filename> - determine size of file on host\n"
185 "host bind <dev> [<filename>] - bind \"host\" device to file\n"
186 "host info [<dev>] - show device binding & info\n"
187 "host dev [<dev>] - Set or retrieve the current host device\n"
188 "host commands use the \"hostfs\" device. The \"host\" device is used\n"
189 "with standard IO commands such as fatls or ext2load"