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 if (argc < 2 || argc > 3)
47 char *dev_str = argv[1];
48 char *file = argc >= 3 ? argv[2] : NULL;
49 int dev = simple_strtoul(dev_str, &ep, 16);
51 printf("** Bad device specification %s **\n", dev_str);
54 return !!host_dev_bind(dev, file);
57 static int do_host_info(struct cmd_tbl *cmdtp, int flag, int argc,
60 if (argc < 1 || argc > 2)
63 int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
66 char *dev_str = argv[1];
67 int dev = simple_strtoul(dev_str, &ep, 16);
69 printf("** Bad device specification %s **\n", dev_str);
76 printf("%3s %12s %s\n", "dev", "blocks", "path");
77 for (dev = min_dev; dev <= max_dev; dev++) {
78 struct blk_desc *blk_dev;
82 ret = host_get_dev_err(dev, &blk_dev);
85 puts("Not bound to a backing file\n");
86 else if (ret == -ENODEV)
87 puts("Invalid host device number\n");
91 struct host_block_dev *host_dev;
94 host_dev = dev_get_platdata(blk_dev->bdev);
96 host_dev = blk_dev->priv;
98 printf("%12lu %s\n", (unsigned long)blk_dev->lba,
104 static int do_host_dev(struct cmd_tbl *cmdtp, int flag, int argc,
109 struct blk_desc *blk_dev;
112 if (argc < 1 || argc > 3)
113 return CMD_RET_USAGE;
116 if (host_curr_device < 0) {
117 printf("No current host device\n");
120 printf("Current host device %d\n", host_curr_device);
124 dev = simple_strtoul(argv[1], &ep, 16);
126 printf("** Bad device specification %s **\n", argv[2]);
127 return CMD_RET_USAGE;
130 ret = host_get_dev_err(dev, &blk_dev);
133 puts("Not bound to a backing file\n");
134 else if (ret == -ENODEV)
135 puts("Invalid host device number\n");
140 host_curr_device = dev;
144 static struct cmd_tbl cmd_host_sub[] = {
145 U_BOOT_CMD_MKENT(load, 7, 0, do_host_load, "", ""),
146 U_BOOT_CMD_MKENT(ls, 3, 0, do_host_ls, "", ""),
147 U_BOOT_CMD_MKENT(save, 6, 0, do_host_save, "", ""),
148 U_BOOT_CMD_MKENT(size, 3, 0, do_host_size, "", ""),
149 U_BOOT_CMD_MKENT(bind, 3, 0, do_host_bind, "", ""),
150 U_BOOT_CMD_MKENT(info, 3, 0, do_host_info, "", ""),
151 U_BOOT_CMD_MKENT(dev, 0, 1, do_host_dev, "", ""),
154 static int do_host(struct cmd_tbl *cmdtp, int flag, int argc,
159 /* Skip past 'host' */
163 c = find_cmd_tbl(argv[0], cmd_host_sub,
164 ARRAY_SIZE(cmd_host_sub));
167 return c->cmd(cmdtp, flag, argc, argv);
169 return CMD_RET_USAGE;
174 "Miscellaneous host commands",
175 "load hostfs - <addr> <filename> [<bytes> <offset>] - "
176 "load a file from host\n"
177 "host ls hostfs - <filename> - list files on host\n"
178 "host save hostfs - <addr> <filename> <bytes> [<offset>] - "
179 "save a file to host\n"
180 "host size hostfs - <filename> - determine size of file on host\n"
181 "host bind <dev> [<filename>] - bind \"host\" device to file\n"
182 "host info [<dev>] - show device binding & info\n"
183 "host dev [<dev>] - Set or retrieve the current host device\n"
184 "host commands use the \"hostfs\" device. The \"host\" device is used\n"
185 "with standard IO commands such as fatls or ext2load"