X-Git-Url: https://git.kernelconcepts.de/?a=blobdiff_plain;f=common%2Fcmd_sandbox.c;h=00982b164dd3c41e562fadffa0adf522c8841e66;hb=1ecab0f30f9051821fdb5ec1c689b7c531b4feda;hp=a28a844ae0e3b01da2fb3e818bdc480378ef7cdc;hpb=cac423a730d3506154744485af1bbc1cd3a1e6a8;p=karo-tx-uboot.git diff --git a/common/cmd_sandbox.c b/common/cmd_sandbox.c index a28a844ae0..00982b164d 100644 --- a/common/cmd_sandbox.c +++ b/common/cmd_sandbox.c @@ -1,29 +1,19 @@ /* * Copyright (c) 2012, Google Inc. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ #include #include +#include +#include +#include static int do_sandbox_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX, 16); + return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX); } static int do_sandbox_ls(cmd_tbl_t *cmdtp, int flag, int argc, @@ -35,13 +25,72 @@ static int do_sandbox_ls(cmd_tbl_t *cmdtp, int flag, int argc, static int do_sandbox_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX, 16); + return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX); +} + +static int do_sandbox_bind(cmd_tbl_t *cmdtp, int flag, int argc, + 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); +} + +static int do_sandbox_info(cmd_tbl_t *cmdtp, int flag, int argc, + 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++) { + block_dev_desc_t *blk_dev; + 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; } static cmd_tbl_t cmd_sandbox_sub[] = { U_BOOT_CMD_MKENT(load, 7, 0, do_sandbox_load, "", ""), U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", ""), U_BOOT_CMD_MKENT(save, 6, 0, do_sandbox_save, "", ""), + U_BOOT_CMD_MKENT(bind, 3, 0, do_sandbox_bind, "", ""), + U_BOOT_CMD_MKENT(info, 3, 0, do_sandbox_info, "", ""), }; static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc, @@ -70,4 +119,6 @@ U_BOOT_CMD( "sb ls host - list files on host\n" "sb save host [] - " "save a file to host\n" + "sb bind [] - bind \"host\" device to file\n" + "sb info [] - show device binding & info" );