2 * Copyright (c) 2012, Google Inc.
4 * SPDX-License-Identifier: GPL-2.0+
11 #include <sandboxblockdev.h>
12 #include <asm/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_save(cmd_tbl_t *cmdtp, int flag, int argc,
31 return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
34 static int do_host_bind(cmd_tbl_t *cmdtp, int flag, int argc,
37 if (argc < 2 || argc > 3)
40 char *dev_str = argv[1];
41 char *file = argc >= 3 ? argv[2] : NULL;
42 int dev = simple_strtoul(dev_str, &ep, 16);
44 printf("** Bad device specification %s **\n", dev_str);
47 return host_dev_bind(dev, file);
50 static int do_host_info(cmd_tbl_t *cmdtp, int flag, int argc,
53 if (argc < 1 || argc > 2)
56 int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
59 char *dev_str = argv[1];
60 int dev = simple_strtoul(dev_str, &ep, 16);
62 printf("** Bad device specification %s **\n", dev_str);
69 printf("%3s %12s %s\n", "dev", "blocks", "path");
70 for (dev = min_dev; dev <= max_dev; dev++) {
71 struct blk_desc *blk_dev;
75 ret = host_get_dev_err(dev, &blk_dev);
78 puts("Not bound to a backing file\n");
79 else if (ret == -ENODEV)
80 puts("Invalid host device number\n");
84 struct host_block_dev *host_dev;
87 host_dev = dev_get_priv(blk_dev->bdev);
89 host_dev = blk_dev->priv;
91 printf("%12lu %s\n", (unsigned long)blk_dev->lba,
97 static int do_host_dev(cmd_tbl_t *cmdtp, int flag, int argc,
102 struct blk_desc *blk_dev;
105 if (argc < 1 || argc > 3)
106 return CMD_RET_USAGE;
109 if (host_curr_device < 0) {
110 printf("No current host device\n");
113 printf("Current host device %d\n", host_curr_device);
117 dev = simple_strtoul(argv[1], &ep, 16);
119 printf("** Bad device specification %s **\n", argv[2]);
120 return CMD_RET_USAGE;
123 ret = host_get_dev_err(dev, &blk_dev);
126 puts("Not bound to a backing file\n");
127 else if (ret == -ENODEV)
128 puts("Invalid host device number\n");
133 host_curr_device = dev;
137 static cmd_tbl_t cmd_host_sub[] = {
138 U_BOOT_CMD_MKENT(load, 7, 0, do_host_load, "", ""),
139 U_BOOT_CMD_MKENT(ls, 3, 0, do_host_ls, "", ""),
140 U_BOOT_CMD_MKENT(save, 6, 0, do_host_save, "", ""),
141 U_BOOT_CMD_MKENT(bind, 3, 0, do_host_bind, "", ""),
142 U_BOOT_CMD_MKENT(info, 3, 0, do_host_info, "", ""),
143 U_BOOT_CMD_MKENT(dev, 0, 1, do_host_dev, "", ""),
146 static int do_host(cmd_tbl_t *cmdtp, int flag, int argc,
151 /* Skip past 'host' */
155 c = find_cmd_tbl(argv[0], cmd_host_sub,
156 ARRAY_SIZE(cmd_host_sub));
159 return c->cmd(cmdtp, flag, argc, argv);
161 return CMD_RET_USAGE;
166 "Deprecated: use 'host' command instead.", ""
171 "Miscellaneous host commands",
172 "load hostfs - <addr> <filename> [<bytes> <offset>] - "
173 "load a file from host\n"
174 "host ls hostfs - <filename> - list files on host\n"
175 "host save hostfs - <addr> <filename> <bytes> [<offset>] - "
176 "save a file to host\n"
177 "host bind <dev> [<filename>] - bind \"host\" device to file\n"
178 "host info [<dev>] - show device binding & info\n"
179 "host dev [<dev>] - Set or retrieve the current host device\n"
180 "host commands use the \"hostfs\" device. The \"host\" device is used\n"
181 "with standard IO commands such as fatls or ext2load"