Simon Glass | bf6ce79 | 2012-12-26 09:53:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012, Google Inc. |
| 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | bf6ce79 | 2012-12-26 09:53:36 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <fs.h> |
Henrik Nordström | 26f9a6c | 2013-11-10 10:26:56 -0700 | [diff] [blame] | 9 | #include <part.h> |
| 10 | #include <sandboxblockdev.h> |
| 11 | #include <asm/errno.h> |
Simon Glass | bf6ce79 | 2012-12-26 09:53:36 +0000 | [diff] [blame] | 12 | |
| 13 | static int do_sandbox_load(cmd_tbl_t *cmdtp, int flag, int argc, |
| 14 | char * const argv[]) |
| 15 | { |
Tom Rini | 089078a | 2013-10-10 10:46:22 -0400 | [diff] [blame] | 16 | return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX); |
Simon Glass | bf6ce79 | 2012-12-26 09:53:36 +0000 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | static 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 Glass | ea307e8 | 2013-04-20 08:42:51 +0000 | [diff] [blame] | 25 | static int do_sandbox_save(cmd_tbl_t *cmdtp, int flag, int argc, |
| 26 | char * const argv[]) |
| 27 | { |
Tom Rini | 089078a | 2013-10-10 10:46:22 -0400 | [diff] [blame] | 28 | return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX); |
Simon Glass | ea307e8 | 2013-04-20 08:42:51 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Henrik Nordström | 26f9a6c | 2013-11-10 10:26:56 -0700 | [diff] [blame] | 31 | static 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 | |
| 47 | static 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 Glass | bf6ce79 | 2012-12-26 09:53:36 +0000 | [diff] [blame] | 88 | static cmd_tbl_t cmd_sandbox_sub[] = { |
Simon Glass | ea307e8 | 2013-04-20 08:42:51 +0000 | [diff] [blame] | 89 | U_BOOT_CMD_MKENT(load, 7, 0, do_sandbox_load, "", ""), |
Simon Glass | bf6ce79 | 2012-12-26 09:53:36 +0000 | [diff] [blame] | 90 | U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", ""), |
Simon Glass | ea307e8 | 2013-04-20 08:42:51 +0000 | [diff] [blame] | 91 | U_BOOT_CMD_MKENT(save, 6, 0, do_sandbox_save, "", ""), |
Henrik Nordström | 26f9a6c | 2013-11-10 10:26:56 -0700 | [diff] [blame] | 92 | U_BOOT_CMD_MKENT(bind, 3, 0, do_sandbox_bind, "", ""), |
| 93 | U_BOOT_CMD_MKENT(info, 3, 0, do_sandbox_info, "", ""), |
Simon Glass | bf6ce79 | 2012-12-26 09:53:36 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | static 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 | |
| 114 | U_BOOT_CMD( |
Simon Glass | ea307e8 | 2013-04-20 08:42:51 +0000 | [diff] [blame] | 115 | sb, 8, 1, do_sandbox, |
Simon Glass | bf6ce79 | 2012-12-26 09:53:36 +0000 | [diff] [blame] | 116 | "Miscellaneous sandbox commands", |
Simon Glass | ea307e8 | 2013-04-20 08:42:51 +0000 | [diff] [blame] | 117 | "load host <dev> <addr> <filename> [<bytes> <offset>] - " |
| 118 | "load a file from host\n" |
| 119 | "sb ls host <filename> - list files on host\n" |
| 120 | "sb save host <dev> <filename> <addr> <bytes> [<offset>] - " |
| 121 | "save a file to host\n" |
Henrik Nordström | 26f9a6c | 2013-11-10 10:26:56 -0700 | [diff] [blame] | 122 | "sb bind <dev> [<filename>] - bind \"host\" device to file\n" |
| 123 | "sb info [<dev>] - show device binding & info" |
Simon Glass | bf6ce79 | 2012-12-26 09:53:36 +0000 | [diff] [blame] | 124 | ); |