All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mateusz Zalega <m.zalega@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 06/13] dfu: mmc: raw data write fix
Date: Tue, 15 Apr 2014 15:06:54 +0200	[thread overview]
Message-ID: <1397567221-2065-7-git-send-email-m.zalega@samsung.com> (raw)
In-Reply-To: <1397567221-2065-1-git-send-email-m.zalega@samsung.com>

When user attempted to perform a raw write using DFU (vide
dfu_fill_entity_mmc) with MMC interface not initialized before,
get_mmc_blk_size() reported invalid (zero) block size - it wasn't
possible to write ie. a new u-boot image.

This commit fixes that by initializing device in get_mmc_blk_size() when
needed.

Tested on Samsung Goni.

Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
---
 drivers/dfu/dfu_mmc.c        | 106 ++++++++++++++++++++++++++-----------------
 include/configs/am335x_evm.h |   8 ++--
 include/configs/trats.h      |   2 +-
 include/configs/trats2.h     |   2 +-
 include/dfu.h                |   5 --
 5 files changed, 70 insertions(+), 53 deletions(-)

diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
index 651cfff..2f7ae21 100644
--- a/drivers/dfu/dfu_mmc.c
+++ b/drivers/dfu/dfu_mmc.c
@@ -184,66 +184,88 @@ int dfu_read_medium_mmc(struct dfu_entity *dfu, u64 offset, void *buf,
 	return ret;
 }
 
+/*
+ * @param s Parameter string containing space-separated arguments:
+ *	1st:
+ *		raw	(raw read/write)
+ *		fat	(files)
+ *		ext4	(^)
+ *		part	(partition image)
+ *	2nd and 3rd:
+ *		lba_start and lba_size, for raw write
+ *		mmc_dev and mmc_part, for filesystems and part
+ */
 int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
 {
-	int dev, part;
-	struct mmc *mmc;
-	block_dev_desc_t *blk_dev;
-	disk_partition_t partinfo;
-	char *st;
-
-	dfu->dev_type = DFU_DEV_MMC;
-	st = strsep(&s, " ");
-	if (!strcmp(st, "mmc")) {
-		dfu->layout = DFU_RAW_ADDR;
-		dfu->data.mmc.lba_start = simple_strtoul(s, &s, 16);
-		dfu->data.mmc.lba_size = simple_strtoul(++s, &s, 16);
-		dfu->data.mmc.lba_blk_size = get_mmc_blk_size(dfu->dev_num);
-	} else if (!strcmp(st, "fat")) {
-		dfu->layout = DFU_FS_FAT;
-	} else if (!strcmp(st, "ext4")) {
-		dfu->layout = DFU_FS_EXT4;
-	} else if (!strcmp(st, "part")) {
+	const char *argv[3];
+	const char **parg = argv;
+	for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) {
+		*parg = strsep(&s, " ");
+		if (*parg == NULL) {
+			error("Invalid number of arguments.\n");
+			return -ENODEV;
+		}
+	}
 
-		dfu->layout = DFU_RAW_ADDR;
+	const char *entity_type = argv[0];
+	/*
+	 * Base 0 means we'll accept (prefixed with 0x or 0) base 16, 8,
+	 * with default 10.
+	 */
+	size_t second_arg = simple_strtoul(argv[1], NULL, 0);
+	size_t third_arg = simple_strtoul(argv[2], NULL, 0);
 
-		dev = simple_strtoul(s, &s, 10);
-		s++;
-		part = simple_strtoul(s, &s, 10);
+	struct mmc *mmc = find_mmc_device(dfu->dev_num);
+	if (mmc == NULL) {
+		error("Couldn't find MMC device no. %d.\n", dfu->dev_num);
+		return -ENODEV;
+	}
 
-		mmc = find_mmc_device(dev);
-		if (mmc == NULL || mmc_init(mmc)) {
-			printf("%s: could not find mmc device #%d!\n",
-			       __func__, dev);
-			return -ENODEV;
-		}
+	if (mmc_init(mmc)) {
+		error("Couldn't init MMC device.\n");
+		return -ENODEV;
+	}
 
-		blk_dev = &mmc->block_dev;
-		if (get_partition_info(blk_dev, part, &partinfo) != 0) {
-			printf("%s: could not find partition #%d on mmc device #%d!\n",
-			       __func__, part, dev);
+	if (!strcmp(entity_type, "raw")) {
+		dfu->layout			= DFU_RAW_ADDR;
+		dfu->data.mmc.lba_start		= second_arg;
+		dfu->data.mmc.lba_size		= third_arg;
+		dfu->data.mmc.lba_blk_size	= mmc->read_bl_len;
+	} else if (!strcmp(entity_type, "part")) {
+		disk_partition_t partinfo;
+		block_dev_desc_t *blk_dev = &mmc->block_dev;
+		int mmcdev = second_arg;
+		int mmcpart = third_arg;
+
+		if (get_partition_info(blk_dev, mmcpart, &partinfo) != 0) {
+			error("Couldn't find part #%d on mmc device #%d\n",
+			      mmcpart, mmcdev);
 			return -ENODEV;
 		}
 
-		dfu->data.mmc.lba_start = partinfo.start;
-		dfu->data.mmc.lba_size = partinfo.size;
-		dfu->data.mmc.lba_blk_size = partinfo.blksz;
-
+		dfu->layout			= DFU_RAW_ADDR;
+		dfu->data.mmc.lba_start		= partinfo.start;
+		dfu->data.mmc.lba_size		= partinfo.size;
+		dfu->data.mmc.lba_blk_size	= partinfo.blksz;
+	} else if (!strcmp(entity_type, "fat")) {
+		dfu->layout = DFU_FS_FAT;
+	} else if (!strcmp(entity_type, "ext4")) {
+		dfu->layout = DFU_FS_EXT4;
 	} else {
-		printf("%s: Memory layout (%s) not supported!\n", __func__, st);
+		error("Memory layout (%s) not supported!\n", entity_type);
 		return -ENODEV;
 	}
 
-	if (dfu->layout == DFU_FS_EXT4 || dfu->layout == DFU_FS_FAT) {
-		dfu->data.mmc.dev = simple_strtoul(s, &s, 10);
-		dfu->data.mmc.part = simple_strtoul(++s, &s, 10);
+	/* if it's NOT a raw write */
+	if (strcmp(entity_type, "raw")) {
+		dfu->data.mmc.dev = second_arg;
+		dfu->data.mmc.part = third_arg;
 	}
 
+	dfu->dev_type = DFU_DEV_MMC;
 	dfu->read_medium = dfu_read_medium_mmc;
 	dfu->write_medium = dfu_write_medium_mmc;
 	dfu->flush_medium = dfu_flush_medium_mmc;
-
-	/* initial state */
 	dfu->inited = 0;
 
 	return 0;
diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h
index ea9e758..4147f9f 100644
--- a/include/configs/am335x_evm.h
+++ b/include/configs/am335x_evm.h
@@ -320,10 +320,10 @@
 	"boot part 0 1;" \
 	"rootfs part 0 2;" \
 	"MLO fat 0 1;" \
-	"MLO.raw mmc 100 100;" \
-	"u-boot.img.raw mmc 300 400;" \
-	"spl-os-args.raw mmc 80 80;" \
-	"spl-os-image.raw mmc 900 2000;" \
+	"MLO.raw mmc 0x100 0x100;" \
+	"u-boot.img.raw mmc 0x300 0x400;" \
+	"spl-os-args.raw mmc 0x80 0x80;" \
+	"spl-os-image.raw mmc 0x900 0x2000;" \
 	"spl-os-args fat 0 1;" \
 	"spl-os-image fat 0 1;" \
 	"u-boot.img fat 0 1;" \
diff --git a/include/configs/trats.h b/include/configs/trats.h
index 5d8bd60..8461343 100644
--- a/include/configs/trats.h
+++ b/include/configs/trats.h
@@ -101,7 +101,7 @@
 	"name="PARTS_UMS",size=-,uuid=${uuid_gpt_"PARTS_UMS"}\0" \
 
 #define CONFIG_DFU_ALT \
-	"u-boot mmc 80 400;" \
+	"u-boot raw 0x80 0x400;" \
 	"uImage ext4 0 2;" \
 	"modem.bin ext4 0 2;" \
 	"exynos4210-trats.dtb ext4 0 2;" \
diff --git a/include/configs/trats2.h b/include/configs/trats2.h
index 53d449c..03e88ee 100644
--- a/include/configs/trats2.h
+++ b/include/configs/trats2.h
@@ -91,7 +91,7 @@
 	"name="PARTS_UMS",size=-,uuid=${uuid_gpt_"PARTS_UMS"}\0" \
 
 #define CONFIG_DFU_ALT \
-	"u-boot mmc 80 800;" \
+	"u-boot raw 0x80 0x800;" \
 	"uImage ext4 0 2;" \
 	"modem.bin ext4 0 2;" \
 	"exynos4412-trats2.dtb ext4 0 2;" \
diff --git a/include/dfu.h b/include/dfu.h
index 6c71ecb..dcd3215 100644
--- a/include/dfu.h
+++ b/include/dfu.h
@@ -64,11 +64,6 @@ struct ram_internal_data {
 	unsigned int	size;
 };
 
-static inline unsigned int get_mmc_blk_size(int dev)
-{
-	return find_mmc_device(dev)->read_bl_len;
-}
-
 #define DFU_NAME_SIZE			32
 #define DFU_CMD_BUF_SIZE		128
 #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
-- 
1.9.0

  parent reply	other threads:[~2014-04-15 13:06 UTC|newest]

Thread overview: 127+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-09 14:31 [U-Boot] [PATCH 1/9] mmc: mmc header fix Mateusz Zalega
2014-01-09 14:31 ` [U-Boot] [PATCH 2/9] part: " Mateusz Zalega
2014-01-09 14:31 ` [U-Boot] [PATCH v3 3/9] arm:goni: Update configuration for goni target Mateusz Zalega
2014-01-09 14:31 ` [U-Boot] [PATCH 4/9] arm:goni:dfu Add support for DFU to Goni target Mateusz Zalega
2014-01-10  4:55   ` Jaehoon Chung
2014-01-13 14:45     ` Mateusz Zalega
2014-01-09 14:31 ` [U-Boot] [PATCH 5/9] arm:goni: enable GPT command Mateusz Zalega
2014-01-09 14:31 ` [U-Boot] [PATCH 6/9] arm:goni: enable USB Mass Storage Mateusz Zalega
2014-01-09 14:31 ` [U-Boot] [PATCH v3 7/9] dfu:mmc: raw data write fix Mateusz Zalega
2014-01-10  5:03   ` Jaehoon Chung
2014-01-13 13:34     ` Mateusz Zalega
2014-01-09 14:31 ` [U-Boot] [PATCH 8/9] ums: always initialize mmc before ums_disk_init() Mateusz Zalega
2014-01-10  5:08   ` Jaehoon Chung
2014-01-13 14:39     ` Mateusz Zalega
2014-01-13 14:43       ` Michael Trimarchi
2014-01-13 15:00         ` Mateusz Zalega
2014-01-13 10:16   ` Lukasz Majewski
2014-01-14  0:49   ` Minkyu Kang
2014-01-14 10:55     ` Mateusz Zalega
2014-01-09 14:31 ` [U-Boot] [PATCH 9/9] USB: gadget: added a saner gadget downloader registration API Mateusz Zalega
2014-01-10  8:23   ` Lukasz Majewski
2014-01-13  7:07     ` Heiko Schocher
2014-01-13 10:16   ` Lukasz Majewski
2014-01-10  4:46 ` [U-Boot] [PATCH 1/9] mmc: mmc header fix Jaehoon Chung
2014-02-04 17:02 ` [U-Boot] [PATCH v2 00/12] Series v2 Mateusz Zalega
2014-02-04 17:02   ` [U-Boot] [PATCH v2 01/12] mmc: mmc header fix Mateusz Zalega
2014-02-04 17:02   ` [U-Boot] [PATCH v2 02/12] part: " Mateusz Zalega
2014-02-04 17:02   ` [U-Boot] [PATCH v2 03/12] arm:goni: Update configuration for goni target Mateusz Zalega
2014-02-04 17:02   ` [U-Boot] [PATCH v2 04/12] dfu: fix boards wo USB cable detection Mateusz Zalega
2014-02-22  5:06     ` Marek Vasut
2014-02-04 17:02   ` [U-Boot] [PATCH v2 05/12] am335x: dfu: disable DFU in am335x_evm SPL build Mateusz Zalega
2014-02-04 17:02   ` [U-Boot] [PATCH v2 06/12] USB: gadget: added a saner gadget downloader registration API Mateusz Zalega
2014-02-05  7:13     ` Marek Vasut
2014-02-05 12:40       ` Mateusz Zalega
2014-02-05 18:00         ` Marek Vasut
2014-02-06 11:56           ` Mateusz Zalega
2014-02-06 19:59             ` Marek Vasut
2014-02-04 17:02   ` [U-Boot] [PATCH v2 07/12] arm:goni:dfu Add support for DFU to Goni target Mateusz Zalega
2014-02-04 17:02   ` [U-Boot] [PATCH v2 08/12] arm:goni: enable GPT command Mateusz Zalega
2014-02-04 17:02   ` [U-Boot] [PATCH v2 09/12] arm:goni: enable USB Mass Storage Mateusz Zalega
2014-02-04 17:02   ` [U-Boot] [PATCH v2 10/12] dfu:mmc: raw data write fix Mateusz Zalega
2014-02-22  5:09     ` Marek Vasut
2014-02-04 17:02   ` [U-Boot] [PATCH v2 11/12] mmc: postponed needless timer initialization Mateusz Zalega
2014-02-04 17:02   ` [U-Boot] [PATCH v2 12/12] ums: always initialize mmc before ums_disk_init() Mateusz Zalega
2014-02-22  5:12     ` Marek Vasut
2014-03-31 15:48 ` [U-Boot] [PATCH v3 00/13] DFU, MMC, Gadget, Goni, misc Mateusz Zalega
2014-03-31 15:49   ` [U-Boot] [PATCH v3 01/13] mmc: mmc header fix Mateusz Zalega
2014-03-31 15:49   ` [U-Boot] [PATCH v3 02/13] part: " Mateusz Zalega
2014-03-31 15:49   ` [U-Boot] [PATCH v3 03/13] arm:goni: Update configuration for goni target Mateusz Zalega
2014-03-31 15:49   ` [U-Boot] [PATCH v3 04/13] dfu: fix boards wo USB cable detection Mateusz Zalega
2014-04-02  6:33     ` Lukasz Majewski
2014-03-31 15:49   ` [U-Boot] [PATCH v3 05/13] am335x: dfu: disable DFU in am335x_evm SPL build Mateusz Zalega
2014-03-31 15:49   ` [U-Boot] [PATCH v3 06/13] USB: gadget: added a saner gadget downloader registration API Mateusz Zalega
2014-03-31 16:14     ` Marek Vasut
2014-04-02  6:35     ` Lukasz Majewski
2014-04-02 22:28       ` Marek Vasut
2014-04-03  7:46         ` Lukasz Majewski
2014-04-03  8:52           ` Marek Vasut
2014-04-11 11:43             ` Mateusz Zalega
2014-04-11 12:02               ` Marek Vasut
2014-04-15 11:04                 ` Mateusz Zalega
2014-04-15 13:26                   ` Marek Vasut
2014-03-31 15:49   ` [U-Boot] [PATCH v3 07/13] arm:goni:dfu Add support for DFU to Goni target Mateusz Zalega
2014-03-31 15:49   ` [U-Boot] [PATCH v3 08/13] arm:goni: enable GPT command Mateusz Zalega
2014-03-31 15:49   ` [U-Boot] [PATCH v3 09/13] arm:goni: enable USB Mass Storage Mateusz Zalega
2014-03-31 15:49   ` [U-Boot] [PATCH v3 10/13] dfu:mmc: raw data write fix Mateusz Zalega
2014-03-31 15:49   ` [U-Boot] [PATCH v3 11/13] mmc: postponed needless timer initialization Mateusz Zalega
2014-03-31 15:49   ` [U-Boot] [PATCH v3 12/13] ums: always initialize mmc before ums_disk_init() Mateusz Zalega
2014-04-02  6:36     ` Lukasz Majewski
2014-03-31 15:49   ` [U-Boot] [PATCH v3 13/13] common: fixed linker-list example Mateusz Zalega
2014-03-31 16:12     ` Marek Vasut
2014-04-01  7:42       ` Lukasz Majewski
2014-04-15 13:06 ` [U-Boot] [PATCH v4 00/13] DFU, MMC, Gadget, Goni, misc Mateusz Zalega
2014-04-15 13:06   ` [U-Boot] [PATCH v4 01/13] mmc: mmc header fix Mateusz Zalega
2014-04-15 13:06   ` [U-Boot] [PATCH v4 02/13] part: " Mateusz Zalega
2014-04-15 13:06   ` [U-Boot] [PATCH v4 03/13] common: fixed linker-list example Mateusz Zalega
2014-04-15 13:36     ` Marek Vasut
2014-04-15 13:06   ` [U-Boot] [PATCH v4 04/13] usb: dfu: fix boards wo USB cable detection Mateusz Zalega
2014-04-15 13:38     ` Marek Vasut
2014-04-15 14:23     ` Lukasz Majewski
2014-04-15 13:06   ` [U-Boot] [PATCH v4 05/13] mmc: postponed needless timer initialization Mateusz Zalega
2014-04-15 13:06   ` Mateusz Zalega [this message]
2014-04-15 13:06   ` [U-Boot] [PATCH v4 07/13] ums: always initialize mmc before ums_disk_init() Mateusz Zalega
2014-04-15 14:24     ` Lukasz Majewski
2014-04-15 13:06   ` [U-Boot] [PATCH v4 08/13] am335x: dfu: disable DFU in am335x_evm SPL build Mateusz Zalega
2014-04-15 14:25     ` Lukasz Majewski
2014-04-15 13:06   ` [U-Boot] [PATCH v4 09/13] USB: gadget: added a saner gadget downloader registration API Mateusz Zalega
2014-04-15 13:39     ` Marek Vasut
2014-04-15 14:28     ` Lukasz Majewski
2014-04-16  4:23     ` Jaehoon Chung
2014-04-16  9:25       ` Mateusz Zalega
2014-04-15 13:06   ` [U-Boot] [PATCH v4 10/13] arm: goni: Update configuration for Goni target Mateusz Zalega
2014-04-15 13:06   ` [U-Boot] [PATCH v4 11/13] arm: goni: dfu: Add support for DFU to " Mateusz Zalega
2014-04-15 13:07   ` [U-Boot] [PATCH v4 12/13] arm: goni: enable GPT command Mateusz Zalega
2014-04-15 13:07   ` [U-Boot] [PATCH v4 13/13] arm: goni: enable USB Mass Storage Mateusz Zalega
2014-04-28 19:13 ` [U-Boot] [PATCH v5 00/12] DFU, MMC, Gadget, Goni, misc Mateusz Zalega
2014-04-28 19:13   ` [U-Boot] [PATCH v5 01/12] mmc: mmc header fix Mateusz Zalega
2014-04-30  8:35     ` Lukasz Majewski
2014-04-30 10:02       ` Pantelis Antoniou
2014-05-05  7:45     ` Lukasz Majewski
2014-04-28 19:13   ` [U-Boot] [PATCH v5 02/12] part: " Mateusz Zalega
2014-04-30  8:33     ` Lukasz Majewski
2014-05-05  7:48     ` Lukasz Majewski
2014-04-28 19:13   ` [U-Boot] [PATCH v5 03/12] usb: dfu: fix boards wo USB cable detection Mateusz Zalega
2014-04-30  8:18     ` Marek Vasut
2014-05-05  7:50     ` Lukasz Majewski
2014-04-28 19:13   ` [U-Boot] [PATCH v5 04/12] dfu: mmc: raw data write fix Mateusz Zalega
2014-05-05  8:00     ` Lukasz Majewski
2014-04-28 19:13   ` [U-Boot] [PATCH v5 05/12] dfu: mmc: change offset base handling Mateusz Zalega
2014-05-05  8:03     ` Lukasz Majewski
2014-04-28 19:13   ` [U-Boot] [PATCH v5 06/12] ums: always initialize mmc before ums_disk_init() Mateusz Zalega
2014-05-01 20:03     ` Stephen Warren
2014-05-05  8:05     ` Lukasz Majewski
2014-04-28 19:13   ` [U-Boot] [PATCH v5 07/12] am335x: dfu: disable DFU in am335x_evm SPL build Mateusz Zalega
2014-05-05  8:06     ` Lukasz Majewski
2014-04-28 19:13   ` [U-Boot] [PATCH v5 08/12] USB: gadget: added a saner gadget downloader registration API Mateusz Zalega
2014-05-05  8:07     ` Lukasz Majewski
2014-04-28 19:13   ` [U-Boot] [PATCH v5 09/12] arm: goni: Update configuration for Goni target Mateusz Zalega
2014-04-30 11:24     ` Lukasz Majewski
2014-04-30 11:55       ` Minkyu Kang
2014-05-16  6:53     ` Minkyu Kang
2014-04-28 19:13   ` [U-Boot] [PATCH v5 10/12] arm: goni: dfu: Add support for DFU to " Mateusz Zalega
2014-05-16  6:53     ` Minkyu Kang
2014-04-28 19:13   ` [U-Boot] [PATCH v5 11/12] arm: goni: enable GPT command Mateusz Zalega
2014-05-16  6:53     ` Minkyu Kang
2014-04-28 19:13   ` [U-Boot] [PATCH v5 12/12] arm: goni: enable USB Mass Storage Mateusz Zalega
2014-05-16  6:53     ` Minkyu Kang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1397567221-2065-7-git-send-email-m.zalega@samsung.com \
    --to=m.zalega@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.