2012-12-26 18:53:36 +09:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012, Google Inc.
|
|
|
|
*
|
2013-07-08 16:37:19 +09:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2012-12-26 18:53:36 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <fs.h>
|
2013-11-11 02:26:56 +09:00
|
|
|
#include <part.h>
|
|
|
|
#include <sandboxblockdev.h>
|
|
|
|
#include <asm/errno.h>
|
2012-12-26 18:53:36 +09:00
|
|
|
|
2015-04-14 05:54:23 +09:00
|
|
|
static int host_curr_device = -1;
|
|
|
|
|
2015-04-14 05:54:22 +09:00
|
|
|
static int do_host_load(cmd_tbl_t *cmdtp, int flag, int argc,
|
2012-12-26 18:53:36 +09:00
|
|
|
char * const argv[])
|
|
|
|
{
|
2013-10-10 23:46:22 +09:00
|
|
|
return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
|
2012-12-26 18:53:36 +09:00
|
|
|
}
|
|
|
|
|
2015-04-14 05:54:22 +09:00
|
|
|
static int do_host_ls(cmd_tbl_t *cmdtp, int flag, int argc,
|
2012-12-26 18:53:36 +09:00
|
|
|
char * const argv[])
|
|
|
|
{
|
|
|
|
return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
|
|
|
|
}
|
|
|
|
|
2015-04-14 05:54:22 +09:00
|
|
|
static int do_host_save(cmd_tbl_t *cmdtp, int flag, int argc,
|
2013-04-20 17:42:51 +09:00
|
|
|
char * const argv[])
|
|
|
|
{
|
2013-10-10 23:46:22 +09:00
|
|
|
return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
|
2013-04-20 17:42:51 +09:00
|
|
|
}
|
|
|
|
|
2015-04-14 05:54:22 +09:00
|
|
|
static int do_host_bind(cmd_tbl_t *cmdtp, int flag, int argc,
|
2013-11-11 02:26:56 +09:00
|
|
|
char * const argv[])
|
|
|
|
{
|
|
|
|
if (argc < 2 || argc > 3)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
char *ep;
|
|
|
|
char *dev_str = argv[1];
|
|
|
|
char *file = argc >= 3 ? argv[2] : NULL;
|
|
|
|
int dev = simple_strtoul(dev_str, &ep, 16);
|
|
|
|
if (*ep) {
|
|
|
|
printf("** Bad device specification %s **\n", dev_str);
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
return host_dev_bind(dev, file);
|
|
|
|
}
|
|
|
|
|
2015-04-14 05:54:22 +09:00
|
|
|
static int do_host_info(cmd_tbl_t *cmdtp, int flag, int argc,
|
2013-11-11 02:26:56 +09:00
|
|
|
char * const argv[])
|
|
|
|
{
|
|
|
|
if (argc < 1 || argc > 2)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
int min_dev = 0;
|
|
|
|
int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
|
|
|
|
if (argc >= 2) {
|
|
|
|
char *ep;
|
|
|
|
char *dev_str = argv[1];
|
|
|
|
int dev = simple_strtoul(dev_str, &ep, 16);
|
|
|
|
if (*ep) {
|
|
|
|
printf("** Bad device specification %s **\n", dev_str);
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
min_dev = dev;
|
|
|
|
max_dev = dev;
|
|
|
|
}
|
|
|
|
int dev;
|
|
|
|
printf("%3s %12s %s\n", "dev", "blocks", "path");
|
|
|
|
for (dev = min_dev; dev <= max_dev; dev++) {
|
2016-03-01 07:25:34 +09:00
|
|
|
struct blk_desc *blk_dev;
|
2013-11-11 02:26:56 +09:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
printf("%3d ", dev);
|
|
|
|
ret = host_get_dev_err(dev, &blk_dev);
|
|
|
|
if (ret) {
|
|
|
|
if (ret == -ENOENT)
|
|
|
|
puts("Not bound to a backing file\n");
|
|
|
|
else if (ret == -ENODEV)
|
|
|
|
puts("Invalid host device number\n");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
struct host_block_dev *host_dev = blk_dev->priv;
|
|
|
|
printf("%12lu %s\n", (unsigned long)blk_dev->lba,
|
|
|
|
host_dev->filename);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-14 05:54:23 +09:00
|
|
|
static int do_host_dev(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char * const argv[])
|
|
|
|
{
|
|
|
|
int dev;
|
|
|
|
char *ep;
|
2016-03-01 07:25:34 +09:00
|
|
|
struct blk_desc *blk_dev;
|
2015-04-14 05:54:23 +09:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (argc < 1 || argc > 3)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
if (host_curr_device < 0) {
|
|
|
|
printf("No current host device\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
printf("Current host device %d\n", host_curr_device);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev = simple_strtoul(argv[1], &ep, 16);
|
|
|
|
if (*ep) {
|
|
|
|
printf("** Bad device specification %s **\n", argv[2]);
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = host_get_dev_err(dev, &blk_dev);
|
|
|
|
if (ret) {
|
|
|
|
if (ret == -ENOENT)
|
|
|
|
puts("Not bound to a backing file\n");
|
|
|
|
else if (ret == -ENODEV)
|
|
|
|
puts("Invalid host device number\n");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
host_curr_device = dev;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-14 05:54:22 +09:00
|
|
|
static cmd_tbl_t cmd_host_sub[] = {
|
|
|
|
U_BOOT_CMD_MKENT(load, 7, 0, do_host_load, "", ""),
|
|
|
|
U_BOOT_CMD_MKENT(ls, 3, 0, do_host_ls, "", ""),
|
|
|
|
U_BOOT_CMD_MKENT(save, 6, 0, do_host_save, "", ""),
|
|
|
|
U_BOOT_CMD_MKENT(bind, 3, 0, do_host_bind, "", ""),
|
|
|
|
U_BOOT_CMD_MKENT(info, 3, 0, do_host_info, "", ""),
|
2015-04-14 05:54:23 +09:00
|
|
|
U_BOOT_CMD_MKENT(dev, 0, 1, do_host_dev, "", ""),
|
2012-12-26 18:53:36 +09:00
|
|
|
};
|
|
|
|
|
2015-04-14 05:54:22 +09:00
|
|
|
static int do_host(cmd_tbl_t *cmdtp, int flag, int argc,
|
2012-12-26 18:53:36 +09:00
|
|
|
char * const argv[])
|
|
|
|
{
|
|
|
|
cmd_tbl_t *c;
|
|
|
|
|
2015-04-14 05:54:22 +09:00
|
|
|
/* Skip past 'host' */
|
2012-12-26 18:53:36 +09:00
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
|
2015-04-14 05:54:22 +09:00
|
|
|
c = find_cmd_tbl(argv[0], cmd_host_sub,
|
|
|
|
ARRAY_SIZE(cmd_host_sub));
|
2012-12-26 18:53:36 +09:00
|
|
|
|
|
|
|
if (c)
|
|
|
|
return c->cmd(cmdtp, flag, argc, argv);
|
|
|
|
else
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
2015-04-14 05:54:22 +09:00
|
|
|
sb, 8, 1, do_host,
|
|
|
|
"Deprecated: use 'host' command instead.", ""
|
|
|
|
);
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
host, 8, 1, do_host,
|
|
|
|
"Miscellaneous host commands",
|
2014-06-13 01:28:32 +09:00
|
|
|
"load hostfs - <addr> <filename> [<bytes> <offset>] - "
|
2013-04-20 17:42:51 +09:00
|
|
|
"load a file from host\n"
|
2015-04-14 05:54:22 +09:00
|
|
|
"host ls hostfs - <filename> - list files on host\n"
|
|
|
|
"host save hostfs - <addr> <filename> <bytes> [<offset>] - "
|
2013-04-20 17:42:51 +09:00
|
|
|
"save a file to host\n"
|
2015-04-14 05:54:22 +09:00
|
|
|
"host bind <dev> [<filename>] - bind \"host\" device to file\n"
|
|
|
|
"host info [<dev>] - show device binding & info\n"
|
2015-04-14 05:54:23 +09:00
|
|
|
"host dev [<dev>] - Set or retrieve the current host device\n"
|
2015-04-14 05:54:22 +09:00
|
|
|
"host commands use the \"hostfs\" device. The \"host\" device is used\n"
|
2014-06-13 01:28:32 +09:00
|
|
|
"with standard IO commands such as fatls or ext2load"
|
2012-12-26 18:53:36 +09:00
|
|
|
);
|