uboot/common/cmd_sandbox.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2012, Google Inc.
   3 *
   4 * SPDX-License-Identifier:     GPL-2.0+
   5 */
   6
   7#include <common.h>
   8#include <fs.h>
   9#include <part.h>
  10#include <sandboxblockdev.h>
  11#include <asm/errno.h>
  12
  13static int do_sandbox_load(cmd_tbl_t *cmdtp, int flag, int argc,
  14                           char * const argv[])
  15{
  16        return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
  17}
  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
  25static int do_sandbox_save(cmd_tbl_t *cmdtp, int flag, int argc,
  26                           char * const argv[])
  27{
  28        return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
  29}
  30
  31static 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
  88static cmd_tbl_t cmd_sandbox_sub[] = {
  89        U_BOOT_CMD_MKENT(load, 7, 0, do_sandbox_load, "", ""),
  90        U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", ""),
  91        U_BOOT_CMD_MKENT(save, 6, 0, do_sandbox_save, "", ""),
  92        U_BOOT_CMD_MKENT(bind, 3, 0, do_sandbox_bind, "", ""),
  93        U_BOOT_CMD_MKENT(info, 3, 0, do_sandbox_info, "", ""),
  94};
  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(
 115        sb,     8,      1,      do_sandbox,
 116        "Miscellaneous sandbox commands",
 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"
 122        "sb bind <dev> [<filename>] - bind \"host\" device to file\n"
 123        "sb info [<dev>]            - show device binding & info"
 124);
 125