blob: 3d9fce7e554883f8dbb6b886d17420704f2f8a03 [file] [log] [blame]
Simon Glassbf6ce792012-12-26 09:53:36 +00001/*
2 * Copyright (c) 2012, Google Inc.
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Simon Glassbf6ce792012-12-26 09:53:36 +00005 */
6
7#include <common.h>
8#include <fs.h>
Henrik Nordström26f9a6c2013-11-10 10:26:56 -07009#include <part.h>
10#include <sandboxblockdev.h>
11#include <asm/errno.h>
Simon Glassbf6ce792012-12-26 09:53:36 +000012
13static int do_sandbox_load(cmd_tbl_t *cmdtp, int flag, int argc,
14 char * const argv[])
15{
Tom Rini089078a2013-10-10 10:46:22 -040016 return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
Simon Glassbf6ce792012-12-26 09:53:36 +000017}
18
19static int do_sandbox_ls(cmd_tbl_t *cmdtp, int flag, int argc,
20 char * const argv[])
21{
22 return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
23}
24
Simon Glassea307e82013-04-20 08:42:51 +000025static int do_sandbox_save(cmd_tbl_t *cmdtp, int flag, int argc,
26 char * const argv[])
27{
Tom Rini089078a2013-10-10 10:46:22 -040028 return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
Simon Glassea307e82013-04-20 08:42:51 +000029}
30
Henrik Nordström26f9a6c2013-11-10 10:26:56 -070031static int do_sandbox_bind(cmd_tbl_t *cmdtp, int flag, int argc,
32 char * const argv[])
33{
34 if (argc < 2 || argc > 3)
35 return CMD_RET_USAGE;
36 char *ep;
37 char *dev_str = argv[1];
38 char *file = argc >= 3 ? argv[2] : NULL;
39 int dev = simple_strtoul(dev_str, &ep, 16);
40 if (*ep) {
41 printf("** Bad device specification %s **\n", dev_str);
42 return CMD_RET_USAGE;
43 }
44 return host_dev_bind(dev, file);
45}
46
47static int do_sandbox_info(cmd_tbl_t *cmdtp, int flag, int argc,
48 char * const argv[])
49{
50 if (argc < 1 || argc > 2)
51 return CMD_RET_USAGE;
52 int min_dev = 0;
53 int max_dev = CONFIG_HOST_MAX_DEVICES - 1;
54 if (argc >= 2) {
55 char *ep;
56 char *dev_str = argv[1];
57 int dev = simple_strtoul(dev_str, &ep, 16);
58 if (*ep) {
59 printf("** Bad device specification %s **\n", dev_str);
60 return CMD_RET_USAGE;
61 }
62 min_dev = dev;
63 max_dev = dev;
64 }
65 int dev;
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;
69 int ret;
70
71 printf("%3d ", dev);
72 ret = host_get_dev_err(dev, &blk_dev);
73 if (ret) {
74 if (ret == -ENOENT)
75 puts("Not bound to a backing file\n");
76 else if (ret == -ENODEV)
77 puts("Invalid host device number\n");
78
79 continue;
80 }
81 struct host_block_dev *host_dev = blk_dev->priv;
82 printf("%12lu %s\n", (unsigned long)blk_dev->lba,
83 host_dev->filename);
84 }
85 return 0;
86}
87
Simon Glassbf6ce792012-12-26 09:53:36 +000088static cmd_tbl_t cmd_sandbox_sub[] = {
Simon Glassea307e82013-04-20 08:42:51 +000089 U_BOOT_CMD_MKENT(load, 7, 0, do_sandbox_load, "", ""),
Simon Glassbf6ce792012-12-26 09:53:36 +000090 U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", ""),
Simon Glassea307e82013-04-20 08:42:51 +000091 U_BOOT_CMD_MKENT(save, 6, 0, do_sandbox_save, "", ""),
Henrik Nordström26f9a6c2013-11-10 10:26:56 -070092 U_BOOT_CMD_MKENT(bind, 3, 0, do_sandbox_bind, "", ""),
93 U_BOOT_CMD_MKENT(info, 3, 0, do_sandbox_info, "", ""),
Simon Glassbf6ce792012-12-26 09:53:36 +000094};
95
96static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc,
97 char * const argv[])
98{
99 cmd_tbl_t *c;
100
101 /* Skip past 'sandbox' */
102 argc--;
103 argv++;
104
105 c = find_cmd_tbl(argv[0], cmd_sandbox_sub,
106 ARRAY_SIZE(cmd_sandbox_sub));
107
108 if (c)
109 return c->cmd(cmdtp, flag, argc, argv);
110 else
111 return CMD_RET_USAGE;
112}
113
114U_BOOT_CMD(
Simon Glassea307e82013-04-20 08:42:51 +0000115 sb, 8, 1, do_sandbox,
Simon Glassbf6ce792012-12-26 09:53:36 +0000116 "Miscellaneous sandbox commands",
Stephen Warrenbff6c312014-06-12 10:28:32 -0600117 "load hostfs - <addr> <filename> [<bytes> <offset>] - "
Simon Glassea307e82013-04-20 08:42:51 +0000118 "load a file from host\n"
Stephen Warrenbff6c312014-06-12 10:28:32 -0600119 "sb ls hostfs - <filename> - list files on host\n"
120 "sb save hostfs - <filename> <addr> <bytes> [<offset>] - "
Simon Glassea307e82013-04-20 08:42:51 +0000121 "save a file to host\n"
Henrik Nordström26f9a6c2013-11-10 10:26:56 -0700122 "sb bind <dev> [<filename>] - bind \"host\" device to file\n"
Stephen Warrenbff6c312014-06-12 10:28:32 -0600123 "sb info [<dev>] - show device binding & info\n"
124 "sb commands use the \"hostfs\" device. The \"host\" device is used\n"
125 "with standard IO commands such as fatls or ext2load"
Simon Glassbf6ce792012-12-26 09:53:36 +0000126);