From patchwork Thu Nov 22 19:12:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 201142 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id A37B42C0089 for ; Fri, 23 Nov 2012 06:16:04 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8F5CC4A054; Thu, 22 Nov 2012 20:16:00 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xA2KxiY2a6if; Thu, 22 Nov 2012 20:16:00 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A1DF14A092; Thu, 22 Nov 2012 20:15:01 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 366E34A04B for ; Thu, 22 Nov 2012 20:14:54 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XGNHQNCdBIXG for ; Thu, 22 Nov 2012 20:14:51 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-la0-f74.google.com (mail-la0-f74.google.com [209.85.215.74]) by theia.denx.de (Postfix) with ESMTPS id F29274A021 for ; Thu, 22 Nov 2012 20:14:47 +0100 (CET) Received: by mail-la0-f74.google.com with SMTP id v3so595640lag.3 for ; Thu, 22 Nov 2012 11:14:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=U30PH+MLaIrHc6H9iuQwK7g3TOpcxGDUvBAPLBPnyvY=; b=VUFHWW3U2EoB1K9bGe5ixqq9ccA6meYsHaluNdyS4+AL3yR+92gol8q5kOJr9orL5z QxpDBPIx+BSusxbG2qfz2ftxAWkPj79/VWEHo1XZ0tKIcMQne89st1vfpO7LDD9L6OPc 9HM6wbQaMNo1IkW4wBTU7OwFBgIbUEwA/b4euKfF+xO45CnW6TJPF4566+9wkiYknrvI 2Qt/+AoAzxRjOKVqcZpngHwMA516TQAl5PXHlX2Rs22q08ADuRLZbDezRIvBjAInuxEz jGVtqIVWi137b5EePjkcO2SOGvfBdn20XWTIJjhWHe1kq+Y4IWHzZJHTy9K6tZfjL5P+ xf8w== Received: by 10.14.213.135 with SMTP id a7mr2199053eep.2.1353611686570; Thu, 22 Nov 2012 11:14:46 -0800 (PST) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id u8si1008012een.1.2012.11.22.11.14.46 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 22 Nov 2012 11:14:46 -0800 (PST) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id F1046200059; Thu, 22 Nov 2012 11:14:45 -0800 (PST) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 535A9160935; Thu, 22 Nov 2012 11:14:45 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 22 Nov 2012 11:12:47 -0800 Message-Id: <1353611587-18186-4-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1353611587-18186-1-git-send-email-sjg@chromium.org> References: <1353611587-18186-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQmeiJGa+pNueJAk5Z5TxN4f17K1rqpbj7DX7pFcKN/J4pmhQfGHl/cNqJsHVm7eQWBSECElKQ8U9dlSW51pTkT3ANnC0VyXgtzaK14L4I/s8t+9luXbO2V/tn8S5Ow8pX2RP1v3Cj5e+cGdvubcvUpW78Ws8Xf3ArBXGcJNRThdpnvNaJnffyYEb5uzeHkxMUypx9m3 Cc: Tom Rini , Kenneth Waters Subject: [U-Boot] [PATCH v2 03/23] Add a command to read raw blocks from a partition X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Kenneth Waters Sometimes data is on a block device and within a partition, but not in a particular filesystem. This commands permits reading raw data from a partition. Signed-off-by: Kenneth Waters Signed-off-by: Simon Glass --- Changes in v2: None README | 1 + common/Makefile | 1 + common/cmd_read.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ include/config_cmd_all.h | 1 + 4 files changed, 84 insertions(+), 0 deletions(-) create mode 100644 common/cmd_read.c diff --git a/README b/README index 9aeef80..6378101 100644 --- a/README +++ b/README @@ -856,6 +856,7 @@ The following options need to be configured: CONFIG_CMD_PING * send ICMP ECHO_REQUEST to network host CONFIG_CMD_PORTIO * Port I/O + CONFIG_CMD_READ * Read raw data from partition CONFIG_CMD_REGINFO * Register dump CONFIG_CMD_RUN run command in env variable CONFIG_CMD_SAVES * save S record dump diff --git a/common/Makefile b/common/Makefile index 0fb79ed..84968f8 100644 --- a/common/Makefile +++ b/common/Makefile @@ -142,6 +142,7 @@ endif COBJS-y += cmd_pcmcia.o COBJS-$(CONFIG_CMD_PORTIO) += cmd_portio.o COBJS-$(CONFIG_CMD_PXE) += cmd_pxe.o +COBJS-$(CONFIG_CMD_READ) += cmd_read.o COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o diff --git a/common/cmd_read.c b/common/cmd_read.c new file mode 100644 index 0000000..f0fc9bf --- /dev/null +++ b/common/cmd_read.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + */ + +#include +#include +#include + +int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + char *ep; + block_dev_desc_t *dev_desc = NULL; + int dev; + int part = 0; + disk_partition_t part_info; + ulong offset = 0u; + ulong limit = 0u; + void *addr; + uint blk; + uint cnt; + + if (argc != 6) { + cmd_usage(cmdtp); + return 1; + } + + dev = (int)simple_strtoul(argv[2], &ep, 16); + if (*ep) { + if (*ep != ':') { + printf("Invalid block device %s\n", argv[2]); + return 1; + } + part = (int)simple_strtoul(++ep, NULL, 16); + } + + dev_desc = get_dev(argv[1], dev); + if (dev_desc == NULL) { + printf("Block device %s %d not supported\n", argv[1], dev); + return 1; + } + + addr = (void *)simple_strtoul(argv[3], NULL, 16); + blk = simple_strtoul(argv[4], NULL, 16); + cnt = simple_strtoul(argv[5], NULL, 16); + + if (part != 0) { + if (get_partition_info(dev_desc, part, &part_info)) { + printf("Cannot find partition %d\n", part); + return 1; + } + offset = part_info.start; + limit = part_info.size; + } else { + /* Largest address not available in block_dev_desc_t. */ + limit = ~0; + } + + if (cnt + blk > limit) { + printf("Read out of range\n"); + return 1; + } + + if (dev_desc->block_read(dev, offset + blk, cnt, addr) < 0) { + printf("Error reading blocks\n"); + return 1; + } + + return 0; +} + +U_BOOT_CMD( + read, 6, 0, do_read, + "Load binary data from a partition", + " addr blk# cnt" +); diff --git a/include/config_cmd_all.h b/include/config_cmd_all.h index b87967e..148d676 100644 --- a/include/config_cmd_all.h +++ b/include/config_cmd_all.h @@ -71,6 +71,7 @@ #define CONFIG_CMD_REGINFO /* Register dump */ #define CONFIG_CMD_REISER /* Reiserfs support */ #define CONFIG_CMD_RARP /* rarpboot support */ +#define CONFIG_CMD_READ /* Read data from partition */ #define CONFIG_CMD_RUN /* run command in env variable */ #define CONFIG_CMD_SAVEENV /* saveenv */ #define CONFIG_CMD_SAVES /* save S record dump */