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 do_host_load(cmd_tbl_t *cmdtp, int flag, int argc,
16 return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
19 static int do_host_ls(cmd_tbl_t *cmdtp, int flag, int argc,
22 return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
25 static int do_host_save(cmd_tbl_t *cmdtp, int flag, int argc,
28 return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
31 static int do_host_bind(cmd_tbl_t *cmdtp, int flag, int argc,
34 if (argc < 2 || argc > 3)
37 char *dev_str = argv[1];
38 char *file = argc >= 3 ? argv[2] : NULL;
39 int dev = simple_strtoul(dev_str, &ep, 16);
41 printf("** Bad device specification %s **\n", dev_str);
44 return host_dev_bind(dev, file);
47 static int do_host_info(cmd_tbl_t *cmdtp, int flag, int argc,
50 if (argc < 1 || argc > 2)
53 int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
56 char *dev_str = argv[1];
57 int dev = simple_strtoul(dev_str, &ep, 16);
59 printf("** Bad device specification %s **\n", dev_str);
66 printf("%3s %12s %s\n", "dev", "blocks", "path");
67 for (dev = min_dev; dev <= max_dev; dev++) {
68 block_dev_desc_t *blk_dev;
72 ret = host_get_dev_err(dev, &blk_dev);
75 puts("Not bound to a backing file\n");
76 else if (ret == -ENODEV)
77 puts("Invalid host device number\n");
81 struct host_block_dev *host_dev = blk_dev->priv;
82 printf("%12lu %s\n", (unsigned long)blk_dev->lba,
88 static cmd_tbl_t cmd_host_sub[] = {
89 U_BOOT_CMD_MKENT(load, 7, 0, do_host_load, "", ""),
90 U_BOOT_CMD_MKENT(ls, 3, 0, do_host_ls, "", ""),
91 U_BOOT_CMD_MKENT(save, 6, 0, do_host_save, "", ""),
92 U_BOOT_CMD_MKENT(bind, 3, 0, do_host_bind, "", ""),
93 U_BOOT_CMD_MKENT(info, 3, 0, do_host_info, "", ""),
96 static int do_host(cmd_tbl_t *cmdtp, int flag, int argc,
101 /* Skip past 'host' */
105 c = find_cmd_tbl(argv[0], cmd_host_sub,
106 ARRAY_SIZE(cmd_host_sub));
109 return c->cmd(cmdtp, flag, argc, argv);
111 return CMD_RET_USAGE;
116 "Deprecated: use 'host' command instead.", ""
121 "Miscellaneous host commands",
122 "load hostfs - <addr> <filename> [<bytes> <offset>] - "
123 "load a file from host\n"
124 "host ls hostfs - <filename> - list files on host\n"
125 "host save hostfs - <addr> <filename> <bytes> [<offset>] - "
126 "save a file to host\n"
127 "host bind <dev> [<filename>] - bind \"host\" device to file\n"
128 "host info [<dev>] - show device binding & info\n"
129 "host commands use the \"hostfs\" device. The \"host\" device is used\n"
130 "with standard IO commands such as fatls or ext2load"