[U-Boot] [PATCH 2/2] api: storage: Share attributes with block_dev_desc

Che-Liang Chiou clchiou at chromium.org
Fri Oct 21 08:31:48 CEST 2011


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 <clchiou at chromium.org>
---
 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 <ide.h>
 
 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,
-- 
1.7.3.1



More information about the U-Boot mailing list