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 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_save(cmd_tbl_t *cmdtp, int flag, int argc,
30 return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
33 static int do_host_bind(cmd_tbl_t *cmdtp, int flag, int argc,
36 if (argc < 2 || argc > 3)
39 char *dev_str = argv[1];
40 char *file = argc >= 3 ? argv[2] : NULL;
41 int dev = simple_strtoul(dev_str, &ep, 16);
43 printf("** Bad device specification %s **\n", dev_str);
46 return host_dev_bind(dev, file);
49 static int do_host_info(cmd_tbl_t *cmdtp, int flag, int argc,
52 if (argc < 1 || argc > 2)
55 int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
58 char *dev_str = argv[1];
59 int dev = simple_strtoul(dev_str, &ep, 16);
61 printf("** Bad device specification %s **\n", dev_str);
68 printf("%3s %12s %s\n", "dev", "blocks", "path");
69 for (dev = min_dev; dev <= max_dev; dev++) {
70 block_dev_desc_t *blk_dev;
74 ret = host_get_dev_err(dev, &blk_dev);
77 puts("Not bound to a backing file\n");
78 else if (ret == -ENODEV)
79 puts("Invalid host device number\n");
83 struct host_block_dev *host_dev = blk_dev->priv;
84 printf("%12lu %s\n", (unsigned long)blk_dev->lba,
90 static int do_host_dev(cmd_tbl_t *cmdtp, int flag, int argc,
95 block_dev_desc_t *blk_dev;
98 if (argc < 1 || argc > 3)
102 if (host_curr_device < 0) {
103 printf("No current host device\n");
106 printf("Current host device %d\n", host_curr_device);
110 dev = simple_strtoul(argv[1], &ep, 16);
112 printf("** Bad device specification %s **\n", argv[2]);
113 return CMD_RET_USAGE;
116 ret = host_get_dev_err(dev, &blk_dev);
119 puts("Not bound to a backing file\n");
120 else if (ret == -ENODEV)
121 puts("Invalid host device number\n");
126 host_curr_device = dev;
130 static cmd_tbl_t cmd_host_sub[] = {
131 U_BOOT_CMD_MKENT(load, 7, 0, do_host_load, "", ""),
132 U_BOOT_CMD_MKENT(ls, 3, 0, do_host_ls, "", ""),
133 U_BOOT_CMD_MKENT(save, 6, 0, do_host_save, "", ""),
134 U_BOOT_CMD_MKENT(bind, 3, 0, do_host_bind, "", ""),
135 U_BOOT_CMD_MKENT(info, 3, 0, do_host_info, "", ""),
136 U_BOOT_CMD_MKENT(dev, 0, 1, do_host_dev, "", ""),
139 static int do_host(cmd_tbl_t *cmdtp, int flag, int argc,
144 /* Skip past 'host' */
148 c = find_cmd_tbl(argv[0], cmd_host_sub,
149 ARRAY_SIZE(cmd_host_sub));
152 return c->cmd(cmdtp, flag, argc, argv);
154 return CMD_RET_USAGE;
159 "Deprecated: use 'host' command instead.", ""
164 "Miscellaneous host commands",
165 "load hostfs - <addr> <filename> [<bytes> <offset>] - "
166 "load a file from host\n"
167 "host ls hostfs - <filename> - list files on host\n"
168 "host save hostfs - <addr> <filename> <bytes> [<offset>] - "
169 "save a file to host\n"
170 "host bind <dev> [<filename>] - bind \"host\" device to file\n"
171 "host info [<dev>] - show device binding & info\n"
172 "host dev [<dev>] - Set or retrieve the current host device\n"
173 "host commands use the \"hostfs\" device. The \"host\" device is used\n"
174 "with standard IO commands such as fatls or ext2load"