Skip to contentSkip to conversation

blk: Use macros for block device vendor/product/rev string size

PATCH New Bin Meng 2 participants 8 messages Sep 10, 2017 Block layer

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH v4 1/4 blk: Use macros for block device vendor/product/rev string size

So far these are using magic numbers. Replace them with macros.

---

Changes in v4: None
Changes in v3:
- Change BLK_XXX_SIZE to not count the ending NULL

Changes in v2: None

 include/blk.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
include/blk.h +7 -3
index a106f9c..27abfdd 100644
@@ -36,6 +36,10 @@ enum if_type {
 	IF_TYPE_COUNT,			/* Number of interface types */
 };
 
+#define BLK_VEN_SIZE		40
+#define BLK_PRD_SIZE		20
+#define BLK_REV_SIZE		8
+
 /*
  * With driver model (CONFIG_BLK) this is uclass platform data, accessible
  * with dev_get_uclass_platdata(dev)
@@ -60,9 +64,9 @@ struct blk_desc {
 	lbaint_t	lba;		/* number of blocks */
 	unsigned long	blksz;		/* block size */
 	int		log2blksz;	/* for convenience: log2(blksz) */
-	char		vendor[40+1];	/* IDE model, SCSI Vendor */
-	char		product[20+1];	/* IDE Serial no, SCSI product */
-	char		revision[8+1];	/* firmware revision */
+	char		vendor[BLK_VEN_SIZE + 1]; /* device vendor string */
+	char		product[BLK_PRD_SIZE + 1]; /* device product number */
+	char		revision[BLK_REV_SIZE + 1]; /* firmware revision */
 #if CONFIG_IS_ENABLED(BLK)
 	/*
 	 * For now we have a few functions which take struct blk_desc as a
Signature · 1 line
2.9.2
author
#1 lore raw

PATCH v4 2/4 block: ide: Fix block read/write with driver model

This converts the IDE driver to driver model so that block read and write are fully functional.

Fixes b7c6baef ("x86: Convert MMC to driver model")

---

Changes in v4:
- Ensure the strings end with '\0'

Changes in v3:
- Updated BLK_XXX_SIZE usage

Changes in v2:
- Fixed 'fatls ide 0' issue

 drivers/block/blk-uclass.c |  2 +-
 drivers/block/ide.c        | 73 ++++++++++++++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h     |  1 +
 3 files changed, 75 insertions(+), 1 deletion(-)
drivers/block/blk-uclass.c +1 -1
index e5f00dc..8e58580 100644
@@ -26,7 +26,7 @@ static const char *if_typename_str[IF_TYPE_COUNT] = {
 };
 
 static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
-	[IF_TYPE_IDE]		= UCLASS_INVALID,
+	[IF_TYPE_IDE]		= UCLASS_IDE,
 	[IF_TYPE_SCSI]		= UCLASS_SCSI,
 	[IF_TYPE_ATAPI]		= UCLASS_INVALID,
 	[IF_TYPE_USB]		= UCLASS_MASS_STORAGE,
drivers/block/ide.c +73 -0

97 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 1a50199..3fc2083 100644
@@ -41,6 +41,7 @@ enum uclass_id {
 	UCLASS_I2C_EEPROM,	/* I2C EEPROM device */
 	UCLASS_I2C_GENERIC,	/* Generic I2C device */
 	UCLASS_I2C_MUX,		/* I2C multiplexer */
+	UCLASS_IDE,		/* IDE device */
 	UCLASS_IRQ,		/* Interrupt controller */
 	UCLASS_KEYBOARD,	/* Keyboard input device */
 	UCLASS_LED,		/* Light-emitting diode (LED) */
Signature · 1 line
2.9.2
#2 lore raw

PATCH v4 2/4 block: ide: Fix block read/write with driver model

Quoted 9 lines · Bin Meng

This converts the IDE driver to driver model so that block read and write are fully functional.

Fixes b7c6baef ("x86: Convert MMC to driver model")

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170910/bbe8729b/attachment.sig>
author
#3 lore raw

PATCH v4 3/4 block: ide: Don't bother to create BLK device if no CDROM inserted

In reply to Bin Meng

When there is no CDROM inserted, the block size is zero hence there is no need to create a BLK device for it.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/block/ide.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/block/ide.c +7 -0
index ed3b27e..9ab01a9 100644
@@ -1202,6 +1202,13 @@ static int ide_probe(struct udevice *udev)
 
 			blksz = ide_dev_desc[i].blksz;
 			size = blksz * ide_dev_desc[i].lba;
+
+			/*
+			 * With CDROM, if there is no CD inserted, blksz will
+			 * be zero, don't bother to create IDE block device.
+			 */
+			if (!blksz)
+				continue;
 			ret = blk_create_devicef(udev, "ide_blk", name,
 						 IF_TYPE_IDE, i,
 						 blksz, size, &blk_dev);
Signature · 1 line
2.9.2
#4 lore raw

PATCH v4 3/4 block: ide: Don't bother to create BLK device if no CDROM inserted

Quoted 5 lines · Bin Meng

When there is no CDROM inserted, the block size is zero hence there is no need to create a BLK device for it.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170910/40026a14/attachment.sig>
author
#5 lore raw

PATCH v4 4/4 cmd: ide: Make the first device the default one

In reply to Bin Meng

At present the IDE device number is initialized to -1, which means we cannot type "ide read" command before setting the device number via "ide device #".

For convenience, let's set the first device as the default one.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 cmd/ide.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/ide.c +1 -1
index e3c3242..bdb5980 100644
@@ -30,7 +30,7 @@
 #endif
 
 /* Current I/O Device	*/
-static int curr_device = -1;
+static int curr_device;
 
 int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 {
Signature · 1 line
2.9.2
#6 lore raw

PATCH v4 4/4 cmd: ide: Make the first device the default one

Quoted 9 lines · Bin Meng

At present the IDE device number is initialized to -1, which means we cannot type "ide read" command before setting the device number via "ide device #".

For convenience, let's set the first device as the default one.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170910/7cb7753b/attachment.sig>
#7 lore raw

PATCH v4 1/4 blk: Use macros for block device vendor/product/rev string size

In reply to Bin Meng
Quoted 5 lines · Bin Meng

So far these are using magic numbers. Replace them with macros.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170910/dbb27dc8/attachment.sig>