All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v3 1/4] blk: Use macros for block device vendor/product/rev string size
@ 2017-09-06  7:30 Bin Meng
  2017-09-06  7:30 ` [U-Boot] [PATCH v3 2/4] block: ide: Fix block read/write with driver model Bin Meng
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Bin Meng @ 2017-09-06  7:30 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

---

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(-)

diff --git a/include/blk.h b/include/blk.h
index a106f9c..27abfdd 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -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
-- 
2.9.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v3 2/4] block: ide: Fix block read/write with driver model
  2017-09-06  7:30 [U-Boot] [PATCH v3 1/4] blk: Use macros for block device vendor/product/rev string size Bin Meng
@ 2017-09-06  7:30 ` Bin Meng
  2017-09-09  0:30   ` Bin Meng
  2017-09-06  7:30 ` [U-Boot] [PATCH v3 3/4] block: ide: Don't bother to create BLK device if no CDROM inserted Bin Meng
  2017-09-06  7:30 ` [U-Boot] [PATCH v3 4/4] cmd: ide: Make the first device the default one Bin Meng
  2 siblings, 1 reply; 7+ messages in thread
From: Bin Meng @ 2017-09-06  7:30 UTC (permalink / raw)
  To: u-boot

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")
Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---

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        | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h     |  1 +
 3 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index e5f00dc..8e58580 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -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,
diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index ce51153..1b5476e 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -827,12 +827,20 @@ void ide_init(void)
 		ide_ident(&ide_dev_desc[i]);
 		dev_print(&ide_dev_desc[i]);
 
+#ifndef CONFIG_BLK
 		if ((ide_dev_desc[i].lba > 0) && (ide_dev_desc[i].blksz > 0)) {
 			/* initialize partition type */
 			part_init(&ide_dev_desc[i]);
 		}
+#endif
 	}
 	WATCHDOG_RESET();
+
+#ifdef CONFIG_BLK
+	struct udevice *dev;
+
+	uclass_first_device(UCLASS_IDE, &dev);
+#endif
 }
 
 /* We only need to swap data if we are running on a big endian cpu. */
@@ -1147,6 +1155,23 @@ int ide_device_present(int dev)
 #endif
 
 #ifdef CONFIG_BLK
+static int ide_blk_probe(struct udevice *udev)
+{
+	struct blk_desc *desc = dev_get_uclass_platdata(udev);
+
+	/* fill in device vendor/product/rev strings */
+	strncpy(desc->vendor, ide_dev_desc[desc->devnum].vendor,
+		BLK_VEN_SIZE + 1);
+	strncpy(desc->product, ide_dev_desc[desc->devnum].product,
+		BLK_PRD_SIZE + 1);
+	strncpy(desc->revision, ide_dev_desc[desc->devnum].revision,
+		BLK_REV_SIZE + 1);
+
+	part_init(desc);
+
+	return 0;
+}
+
 static const struct blk_ops ide_blk_ops = {
 	.read	= ide_read,
 	.write	= ide_write,
@@ -1156,6 +1181,51 @@ U_BOOT_DRIVER(ide_blk) = {
 	.name		= "ide_blk",
 	.id		= UCLASS_BLK,
 	.ops		= &ide_blk_ops,
+	.probe		= ide_blk_probe,
+};
+
+static int ide_probe(struct udevice *udev)
+{
+	struct udevice *blk_dev;
+	char name[20];
+	int blksz;
+	lbaint_t size;
+	int i;
+	int ret;
+
+	for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
+		if (ide_dev_desc[i].type != DEV_TYPE_UNKNOWN) {
+			sprintf(name, "blk#%d", i);
+
+			blksz = ide_dev_desc[i].blksz;
+			size = blksz * ide_dev_desc[i].lba;
+			ret = blk_create_devicef(udev, "ide_blk", name,
+						 IF_TYPE_IDE, i,
+						 blksz, size, &blk_dev);
+			if (ret)
+				return ret;
+		}
+	}
+
+	return 0;
+}
+
+U_BOOT_DRIVER(ide) = {
+	.name		= "ide",
+	.id		= UCLASS_IDE,
+	.probe		= ide_probe,
+};
+
+struct pci_device_id ide_supported[] = {
+	{ PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_IDE << 8, 0xffff00) },
+	{ }
+};
+
+U_BOOT_PCI_DEVICE(ide, ide_supported);
+
+UCLASS_DRIVER(ide) = {
+	.name		= "ide",
+	.id		= UCLASS_IDE,
 };
 #else
 U_BOOT_LEGACY_BLK(ide) = {
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 1a50199..3fc2083 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -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) */
-- 
2.9.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v3 3/4] block: ide: Don't bother to create BLK device if no CDROM inserted
  2017-09-06  7:30 [U-Boot] [PATCH v3 1/4] blk: Use macros for block device vendor/product/rev string size Bin Meng
  2017-09-06  7:30 ` [U-Boot] [PATCH v3 2/4] block: ide: Fix block read/write with driver model Bin Meng
@ 2017-09-06  7:30 ` Bin Meng
  2017-09-06  7:30 ` [U-Boot] [PATCH v3 4/4] cmd: ide: Make the first device the default one Bin Meng
  2 siblings, 0 replies; 7+ messages in thread
From: Bin Meng @ 2017-09-06  7:30 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2: None

 drivers/block/ide.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 1b5476e..0631fae 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -1199,6 +1199,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);
-- 
2.9.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v3 4/4] cmd: ide: Make the first device the default one
  2017-09-06  7:30 [U-Boot] [PATCH v3 1/4] blk: Use macros for block device vendor/product/rev string size Bin Meng
  2017-09-06  7:30 ` [U-Boot] [PATCH v3 2/4] block: ide: Fix block read/write with driver model Bin Meng
  2017-09-06  7:30 ` [U-Boot] [PATCH v3 3/4] block: ide: Don't bother to create BLK device if no CDROM inserted Bin Meng
@ 2017-09-06  7:30 ` Bin Meng
  2 siblings, 0 replies; 7+ messages in thread
From: Bin Meng @ 2017-09-06  7:30 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

---

Changes in v3: None
Changes in v2: None

 cmd/ide.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/ide.c b/cmd/ide.c
index e3c3242..bdb5980 100644
--- a/cmd/ide.c
+++ b/cmd/ide.c
@@ -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[])
 {
-- 
2.9.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v3 2/4] block: ide: Fix block read/write with driver model
  2017-09-06  7:30 ` [U-Boot] [PATCH v3 2/4] block: ide: Fix block read/write with driver model Bin Meng
@ 2017-09-09  0:30   ` Bin Meng
  2017-09-09  3:25     ` Tom Rini
  0 siblings, 1 reply; 7+ messages in thread
From: Bin Meng @ 2017-09-09  0:30 UTC (permalink / raw)
  To: u-boot

Hi Tom,

On Wed, Sep 6, 2017 at 3:30 PM, Bin Meng <bmeng.cn@gmail.com> wrote:
> 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")
> Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>
> 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        | 70 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/dm/uclass-id.h     |  1 +
>  3 files changed, 72 insertions(+), 1 deletion(-)
>

Will you take this series in 2017.09?

Regards,
Bin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v3 2/4] block: ide: Fix block read/write with driver model
  2017-09-09  0:30   ` Bin Meng
@ 2017-09-09  3:25     ` Tom Rini
  2017-09-10 12:09       ` Bin Meng
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Rini @ 2017-09-09  3:25 UTC (permalink / raw)
  To: u-boot

On Sat, Sep 09, 2017 at 08:30:44AM +0800, Bin Meng wrote:
> Hi Tom,
> 
> On Wed, Sep 6, 2017 at 3:30 PM, Bin Meng <bmeng.cn@gmail.com> wrote:
> > 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")
> > Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> >
> > Reviewed-by: Simon Glass <sjg@chromium.org>
> > Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> > ---
> >
> > 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        | 70 ++++++++++++++++++++++++++++++++++++++++++++++
> >  include/dm/uclass-id.h     |  1 +
> >  3 files changed, 72 insertions(+), 1 deletion(-)
> >
> 
> Will you take this series in 2017.09?

I would swear that we declare vendor/etc as size + 1 so that we can
ensure that size+1==NULL and only write up to size into the field.  But
the rest of this patch strncpy's to size+1.  That feels wrong, but I'm
not totally sure.  Are you?  Thanks!

-- 
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/20170908/8a1c8814/attachment.sig>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v3 2/4] block: ide: Fix block read/write with driver model
  2017-09-09  3:25     ` Tom Rini
@ 2017-09-10 12:09       ` Bin Meng
  0 siblings, 0 replies; 7+ messages in thread
From: Bin Meng @ 2017-09-10 12:09 UTC (permalink / raw)
  To: u-boot

Hi Tom,

On Sat, Sep 9, 2017 at 11:25 AM, Tom Rini <trini@konsulko.com> wrote:
> On Sat, Sep 09, 2017 at 08:30:44AM +0800, Bin Meng wrote:
>> Hi Tom,
>>
>> On Wed, Sep 6, 2017 at 3:30 PM, Bin Meng <bmeng.cn@gmail.com> wrote:
>> > 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")
>> > Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>> >
>> > Reviewed-by: Simon Glass <sjg@chromium.org>
>> > Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> > ---
>> >
>> > 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        | 70 ++++++++++++++++++++++++++++++++++++++++++++++
>> >  include/dm/uclass-id.h     |  1 +
>> >  3 files changed, 72 insertions(+), 1 deletion(-)
>> >
>>
>> Will you take this series in 2017.09?
>
> I would swear that we declare vendor/etc as size + 1 so that we can
> ensure that size+1==NULL and only write up to size into the field.  But
> the rest of this patch strncpy's to size+1.  That feels wrong, but I'm
> not totally sure.  Are you?  Thanks!
>

OK, v4 was just sent. Please take a look and hope it makes it before
the release.

Regards,
Bin

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-09-10 12:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-06  7:30 [U-Boot] [PATCH v3 1/4] blk: Use macros for block device vendor/product/rev string size Bin Meng
2017-09-06  7:30 ` [U-Boot] [PATCH v3 2/4] block: ide: Fix block read/write with driver model Bin Meng
2017-09-09  0:30   ` Bin Meng
2017-09-09  3:25     ` Tom Rini
2017-09-10 12:09       ` Bin Meng
2017-09-06  7:30 ` [U-Boot] [PATCH v3 3/4] block: ide: Don't bother to create BLK device if no CDROM inserted Bin Meng
2017-09-06  7:30 ` [U-Boot] [PATCH v3 4/4] cmd: ide: Make the first device the default one Bin Meng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.