1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2012, Google Inc.
10 #include <sandboxblockdev.h>
11 #include <linux/errno.h>
13 static int host_curr_device = -1;
15 static int do_host_load(cmd_tbl_t *cmdtp, int flag, int argc,
18 return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
21 static int do_host_ls(cmd_tbl_t *cmdtp, int flag, int argc,
24 return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
27 static int do_host_size(cmd_tbl_t *cmdtp, int flag, int argc,
30 return do_size(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
33 static int do_host_save(cmd_tbl_t *cmdtp, int flag, int argc,
36 return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
39 static int do_host_bind(cmd_tbl_t *cmdtp, int flag, int argc,
42 if (argc < 2 || argc > 3)
45 char *dev_str = argv[1];
46 char *file = argc >= 3 ? argv[2] : NULL;
47 int dev = simple_strtoul(dev_str, &ep, 16);
49 printf("** Bad device specification %s **\n", dev_str);
52 return host_dev_bind(dev, file);
55 static int do_host_info(cmd_tbl_t *cmdtp, int flag, int argc,
58 if (argc < 1 || argc > 2)
61 int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
64 char *dev_str = argv[1];
65 int dev = simple_strtoul(dev_str, &ep, 16);
67 printf("** Bad device specification %s **\n", dev_str);
74 printf("%3s %12s %s\n", "dev", "blocks", "path");
75 for (dev = min_dev; dev <= max_dev; dev++) {
76 struct blk_desc *blk_dev;
80 ret = host_get_dev_err(dev, &blk_dev);
83 puts("Not bound to a backing file\n");
84 else if (ret == -ENODEV)
85 puts("Invalid host device number\n");
89 struct host_block_dev *host_dev;
92 host_dev = dev_get_priv(blk_dev->bdev);
94 host_dev = blk_dev->priv;
96 printf("%12lu %s\n", (unsigned long)blk_dev->lba,
102 static int do_host_dev(cmd_tbl_t *cmdtp, int flag, int argc,
107 struct blk_desc *blk_dev;
110 if (argc < 1 || argc > 3)
111 return CMD_RET_USAGE;
114 if (host_curr_device < 0) {
115 printf("No current host device\n");
118 printf("Current host device %d\n", host_curr_device);
122 dev = simple_strtoul(argv[1], &ep, 16);
124 printf("** Bad device specification %s **\n", argv[2]);
125 return CMD_RET_USAGE;
128 ret = host_get_dev_err(dev, &blk_dev);
131 puts("Not bound to a backing file\n");
132 else if (ret == -ENODEV)
133 puts("Invalid host device number\n");
138 host_curr_device = dev;
142 static cmd_tbl_t cmd_host_sub[] = {
143 U_BOOT_CMD_MKENT(load, 7, 0, do_host_load, "", ""),
144 U_BOOT_CMD_MKENT(ls, 3, 0, do_host_ls, "", ""),
145 U_BOOT_CMD_MKENT(save, 6, 0, do_host_save, "", ""),
146 U_BOOT_CMD_MKENT(size, 3, 0, do_host_size, "", ""),
147 U_BOOT_CMD_MKENT(bind, 3, 0, do_host_bind, "", ""),
148 U_BOOT_CMD_MKENT(info, 3, 0, do_host_info, "", ""),
149 U_BOOT_CMD_MKENT(dev, 0, 1, do_host_dev, "", ""),
152 static int do_host(cmd_tbl_t *cmdtp, int flag, int argc,
157 /* Skip past 'host' */
161 c = find_cmd_tbl(argv[0], cmd_host_sub,
162 ARRAY_SIZE(cmd_host_sub));
165 return c->cmd(cmdtp, flag, argc, argv);
167 return CMD_RET_USAGE;
172 "Deprecated: use 'host' command instead.", ""
177 "Miscellaneous host commands",
178 "load hostfs - <addr> <filename> [<bytes> <offset>] - "
179 "load a file from host\n"
180 "host ls hostfs - <filename> - list files on host\n"
181 "host save hostfs - <addr> <filename> <bytes> [<offset>] - "
182 "save a file to host\n"
183 "host size hostfs - <filename> - determine size of file on host\n"
184 "host bind <dev> [<filename>] - bind \"host\" device to file\n"
185 "host info [<dev>] - show device binding & info\n"
186 "host dev [<dev>] - Set or retrieve the current host device\n"
187 "host commands use the \"hostfs\" device. The \"host\" device is used\n"
188 "with standard IO commands such as fatls or ext2load"