1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2012, Google Inc.
11 #include <sandboxblockdev.h>
12 #include <dm/device_compat.h>
13 #include <linux/errno.h>
15 static int host_curr_device = -1;
17 static int do_host_load(struct cmd_tbl *cmdtp, int flag, int argc,
20 return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
23 static int do_host_ls(struct cmd_tbl *cmdtp, int flag, int argc,
26 return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
29 static int do_host_size(struct cmd_tbl *cmdtp, int flag, int argc,
32 return do_size(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
35 static int do_host_save(struct cmd_tbl *cmdtp, int flag, int argc,
38 return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
41 static int do_host_bind(struct cmd_tbl *cmdtp, int flag, int argc,
44 bool removable = false;
56 if (!strcmp(argv[0], "-r")) {
65 dev = hextoul(dev_str, &ep);
67 printf("** Bad device specification %s **\n", dev_str);
70 file = argc > 1 ? argv[1] : NULL;
72 return !!host_dev_bind(dev, file, removable);
75 static int do_host_info(struct cmd_tbl *cmdtp, int flag, int argc,
78 if (argc < 1 || argc > 2)
81 int max_dev = SANDBOX_HOST_MAX_DEVICES - 1;
84 char *dev_str = argv[1];
85 int dev = hextoul(dev_str, &ep);
87 printf("** Bad device specification %s **\n", dev_str);
94 printf("%3s %12s %s\n", "dev", "blocks", "path");
95 for (dev = min_dev; dev <= max_dev; dev++) {
96 struct blk_desc *blk_dev;
100 ret = host_get_dev_err(dev, &blk_dev);
103 puts("Not bound to a backing file\n");
104 else if (ret == -ENODEV)
105 puts("Invalid host device number\n");
109 struct host_block_dev *host_dev;
112 host_dev = dev_get_plat(blk_dev->bdev);
114 host_dev = blk_dev->priv;
116 printf("%12lu %s\n", (unsigned long)blk_dev->lba,
122 static int do_host_dev(struct cmd_tbl *cmdtp, int flag, int argc,
127 struct blk_desc *blk_dev;
130 if (argc < 1 || argc > 3)
131 return CMD_RET_USAGE;
134 if (host_curr_device < 0) {
135 printf("No current host device\n");
138 printf("Current host device %d\n", host_curr_device);
142 dev = hextoul(argv[1], &ep);
144 printf("** Bad device specification %s **\n", argv[2]);
145 return CMD_RET_USAGE;
148 ret = host_get_dev_err(dev, &blk_dev);
151 puts("Not bound to a backing file\n");
152 else if (ret == -ENODEV)
153 puts("Invalid host device number\n");
158 host_curr_device = dev;
162 static struct cmd_tbl cmd_host_sub[] = {
163 U_BOOT_CMD_MKENT(load, 7, 0, do_host_load, "", ""),
164 U_BOOT_CMD_MKENT(ls, 3, 0, do_host_ls, "", ""),
165 U_BOOT_CMD_MKENT(save, 6, 0, do_host_save, "", ""),
166 U_BOOT_CMD_MKENT(size, 3, 0, do_host_size, "", ""),
167 U_BOOT_CMD_MKENT(bind, 4, 0, do_host_bind, "", ""),
168 U_BOOT_CMD_MKENT(info, 3, 0, do_host_info, "", ""),
169 U_BOOT_CMD_MKENT(dev, 0, 1, do_host_dev, "", ""),
172 static int do_host(struct cmd_tbl *cmdtp, int flag, int argc,
177 /* Skip past 'host' */
181 c = find_cmd_tbl(argv[0], cmd_host_sub,
182 ARRAY_SIZE(cmd_host_sub));
185 return c->cmd(cmdtp, flag, argc, argv);
187 return CMD_RET_USAGE;
192 "Miscellaneous host commands",
193 "load hostfs - <addr> <filename> [<bytes> <offset>] - "
194 "load a file from host\n"
195 "host ls hostfs - <filename> - list files on host\n"
196 "host save hostfs - <addr> <filename> <bytes> [<offset>] - "
197 "save a file to host\n"
198 "host size hostfs - <filename> - determine size of file on host\n"
199 "host bind [-r] <dev> [<filename>] - bind \"host\" device to file\n"
200 " -r = mark as removable\n"
201 "host info [<dev>] - show device binding & info\n"
202 "host dev [<dev>] - Set or retrieve the current host device\n"
203 "host commands use the \"hostfs\" device. The \"host\" device is used\n"
204 "with standard IO commands such as fatls or ext2load"