From patchwork Fri Oct 21 06:31:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Che-liang Chiou X-Patchwork-Id: 120936 X-Patchwork-Delegate: vapier@gentoo.org 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 62303B6F8F for ; Fri, 21 Oct 2011 17:32:37 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5D4512937D; Fri, 21 Oct 2011 08:32:25 +0200 (CEST) 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 VaQaJF3hEDHX; Fri, 21 Oct 2011 08:32:25 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6D4D82936F; Fri, 21 Oct 2011 08:32:22 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 859CC28F40 for ; Fri, 21 Oct 2011 08:32:06 +0200 (CEST) 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 dQMMYmsqgsFg for ; Fri, 21 Oct 2011 08:32:05 +0200 (CEST) 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-yw0-f44.google.com (mail-yw0-f44.google.com [209.85.213.44]) by theia.denx.de (Postfix) with ESMTPS id 0C21C28D0B for ; Fri, 21 Oct 2011 08:32:03 +0200 (CEST) Received: by ywt2 with SMTP id 2so38522ywt.3 for ; Thu, 20 Oct 2011 23:32:02 -0700 (PDT) Received: by 10.150.103.8 with SMTP id a8mr12606149ybc.11.1319178722339; Thu, 20 Oct 2011 23:32:02 -0700 (PDT) Received: from localhost.localdomain (weier.tpe.corp.google.com [172.30.210.5]) by mx.google.com with ESMTPS id j13sm33068243ani.19.2011.10.20.23.32.00 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 20 Oct 2011 23:32:02 -0700 (PDT) From: Che-Liang Chiou To: u-boot@lists.denx.de Date: Fri, 21 Oct 2011 14:31:48 +0800 Message-Id: <1319178708-10881-3-git-send-email-clchiou@chromium.org> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1319178708-10881-1-git-send-email-clchiou@chromium.org> References: <1319178708-10881-1-git-send-email-clchiou@chromium.org> Subject: [U-Boot] [PATCH 2/2] api: storage: Share attributes with block_dev_desc X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 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 struct device_info in api_public.h defined its own subset of attributes of block_dev_desc, which limits the capability of external apps. This patch let struct device_info and block_dev_desc share the same set of attributes so that an external app has equal amount of information of block device compared to U-Boot. The export.h and _export.h have somewhat addressed the same issue. That is, sharing declarations between U-Boot and external apps. Signed-off-by: Che-Liang Chiou --- api/api_storage.c | 17 +++++++++++++++-- examples/api/demo.c | 15 +++++++++++++-- include/api_public.h | 8 +------- include/block_dev_attr.h | 39 +++++++++++++++++++++++++++++++++++++++ include/part.h | 16 +++------------- 5 files changed, 71 insertions(+), 24 deletions(-) create mode 100644 include/block_dev_attr.h diff --git a/api/api_storage.c b/api/api_storage.c index c535712..ab4cad5 100644 --- a/api/api_storage.c +++ b/api/api_storage.c @@ -165,8 +165,21 @@ static int dev_stor_get(int type, int first, int *more, struct device_info *di) debugf("device instance exists, but is not active.."); found = 0; } else { - di->di_stor.block_count = dd->lba; - di->di_stor.block_size = dd->blksz; +#define COPY_ATTR(a) di->di_stor.a = dd->a + COPY_ATTR(if_type); + COPY_ATTR(dev); + COPY_ATTR(part_type); + COPY_ATTR(target); + COPY_ATTR(lun); + COPY_ATTR(type); + COPY_ATTR(removable); + COPY_ATTR(lba48); + COPY_ATTR(lba); + COPY_ATTR(blksz); +#undef COPY_ATTR + strcpy(di->di_stor.vendor, dd->vendor); + strcpy(di->di_stor.product, dd->product); + strcpy(di->di_stor.revision, dd->revision); } } diff --git a/examples/api/demo.c b/examples/api/demo.c index 65e7491..0c65ae9 100644 --- a/examples/api/demo.c +++ b/examples/api/demo.c @@ -294,7 +294,18 @@ void test_dump_di(int handle) } else if (di->type & DEV_TYP_STOR) { printf(" type\t\t= %s\n", test_stor_typ(di->type)); - printf(" blk size\t\t= %d\n", (unsigned int)di->di_stor.block_size); - printf(" blk count\t\t= %d\n", (unsigned int)di->di_stor.block_count); + printf(" if_type\t\t= %d\n", di->di_stor.if_type); + printf(" dev\t\t= %d\n", di->di_stor.dev); + printf(" part_type\t\t= %d\n", di->di_stor.part_type); + printf(" target\t\t= %d\n", di->di_stor.target); + printf(" lun\t\t= %d\n", di->di_stor.lun); + printf(" device type\t\t= %d\n", di->di_stor.type); + printf(" removable\t\t= %d\n", di->di_stor.removable); + printf(" lba48\t\t= %d\n", di->di_stor.lba48); + printf(" blk size\t\t= %d\n", (unsigned int)di->di_stor.blksz); + printf(" blk count\t\t= %d\n", (unsigned int)di->di_stor.lba); + printf(" vendor\t\t= %s\n", di->di_stor.vendor); + printf(" product\t\t= %s\n", di->di_stor.product); + printf(" revision\t\t= %s\n", di->di_stor.revision); } } diff --git a/include/api_public.h b/include/api_public.h index 5940d81..245904f 100644 --- a/include/api_public.h +++ b/include/api_public.h @@ -111,12 +111,7 @@ struct sys_info { int mr_no; /* number of memory regions */ }; -#undef CONFIG_SYS_64BIT_LBA -#ifdef CONFIG_SYS_64BIT_LBA -typedef u_int64_t lbasize_t; -#else typedef unsigned long lbasize_t; -#endif typedef unsigned long lbastart_t; #define DEV_TYP_NONE 0x0000 @@ -138,8 +133,7 @@ struct device_info { union { struct { - lbasize_t block_count; /* no of blocks */ - unsigned long block_size; /* size of one block */ + #include "block_dev_attr.h" } storage; struct { diff --git a/include/block_dev_attr.h b/include/block_dev_attr.h new file mode 100644 index 0000000..07a76d8 --- /dev/null +++ b/include/block_dev_attr.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * See file CREDITS for list of people who contributed to this + * project. + * + * 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 + */ + +/* + * These are attributes for struct like block_dev_desc. Include this header + * inside a struct definition to populate that struct with these attributes. + */ + +int if_type; /* type of the interface */ +int dev; /* device number */ +unsigned char part_type; /* partition type */ +unsigned char target; /* target SCSI ID */ +unsigned char lun; /* target LUN */ +unsigned char type; /* device type */ +unsigned char removable; /* removable device */ +unsigned char lba48; /* device can use 48bit addr (ATA/ATAPI v7) */ +uint64_t lba; /* number of blocks */ +unsigned long blksz; /* block size */ +char vendor[40+1]; /* IDE model, SCSI Vendor */ +char product[20+1]; /* IDE Serial no, SCSI product */ +char revision[8+1]; /* firmware revision */ diff --git a/include/part.h b/include/part.h index be0a22e..2d2b599 100644 --- a/include/part.h +++ b/include/part.h @@ -26,19 +26,9 @@ #include typedef struct block_dev_desc { - int if_type; /* type of the interface */ - int dev; /* device number */ - unsigned char part_type; /* partition type */ - unsigned char target; /* target SCSI ID */ - unsigned char lun; /* target LUN */ - unsigned char type; /* device type */ - unsigned char removable; /* removable device */ - unsigned char lba48; /* device can use 48bit addr (ATA/ATAPI v7) */ - uint64_t lba; /* number of blocks */ - unsigned long blksz; /* block size */ - char vendor [40+1]; /* IDE model, SCSI Vendor */ - char product[20+1]; /* IDE Serial no, SCSI product */ - char revision[8+1]; /* firmware revision */ + + #include "block_dev_attr.h" + unsigned long (*block_read)(int dev, unsigned long start, lbaint_t blkcnt,