Skip to contentSkip to conversation

Improve DFU support, enable for am335x_evm

PATCH Superseded Tom Rini 5 participants 23 messages Mar 8, 2013 – Mar 14, 2013

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

v5 cover Improve DFU support, enable for am335x_evm

This series does a few things. I've updated Pantelis Antoniou's patch that allows for transfering of files larger than 4MiB to still allow for filesystem writes to work. I also document the existing DFU CONFIG options, and then the new options this series adds. Then we update nand_(read|write)_skip_bad so that we can add DFU support for NAND (started by Pantelis). Finally, we enable all of this for am335x_evm. This series has been compile-tested on all ARM and PowerPC targets and run-time tested on am335x_evm for NAND and MMC and eMMC.

This series depends on u-boot-usb/master but with a09f955 removed (as we replace that patch here).

--
Tom

Changes in v5:
- New patch to document existing DFU CONFIG options
- Rework Pantelis' "dfu: Support larger than memory transfers" to not break filesystem writing
- New patch to re-align defines in <dfu.h>
- Document CONFIG_DFU_NAND in README
- Add RAW MMC examples to include/configs/am335x_evm.h

Changes in v4:
- Further reword nand_util.c comments, from Scott
- In nand_write_skip_bad make sure *actual is 0 for YAFFS2 errors too, reminded by Scott.
- In cmd_nand.c don't drop the size is less than maxsize check in arg_off_size as other nand functions need this still (Scott).
- Add patch to fix CONFIG_CMD_NAND_YAFFS

Changes in v3:
- Reworked skip_check_len changes to just add accounting for *used to the logic.
- Allow for actual to be NULL in nand_(read|write)_skip_bad, only DFU calls this with a non-NULL parameter. Make sure the comments for both functions explain the parameters and their behavior.
- Other style changes requested by Scott.
- As nand_(write|read)_skip_bad passes back just a used length now.
- Rework logic in nand_block_op for nand_(read|write)_skip_bad returning just a size for actual used length.
- Remove unused externs from drivers/dfu/dfu_nand.c
- Fix checkpatch.pl warnings in include/configs/am335x_evm.h

Changes in v2:
- NAND skip_check_len changes reworked to allow nand_(read|write)_skip_bad to return this information to the caller.
- nand_block_op calls nand_(read|write)_skip_bad directly.
- Bugfix in dfu_nand to make sure we set dfu->skip_bad to 0 on each iteration.
- Add CONFIG_CMD_MTDPARTS and relevant information to am335x_evm
- Enable DFU for NAND and MMC, set dfu_alt_info_(nand|mmc) as examples for both in am335x_evm.h
- Increase CONFIG_SYS_MAXARGS due to hush parsing bugs that would otherwise prevent 'setenv dfu_alt_info ${dfu_alt_info_nand}' on am335x_evm

Pantelis Antoniou (4):
dfu: Support larger than memory transfers.
dfu: NAND specific routines for DFU operation
am335x_evm: Define CONFIG_SYS_CACHELINE_SIZE
am335x_evm: Enable DFU for NAND and MMC, provide example alt_infos

Tom Rini (5):
README: Document current DFU CONFIG options
dfu: Change indentation of defines in <dfu.h>
nand: Extend nand_(read|write)_skip_bad with *actual and limit
parameters
cmd_nand.c: Fix CONFIG_CMD_NAND_YAFFS
am335x_evm: Add CONFIG_CMD_MTDPARTS and relevant defaults

 README                       |   23 ++++
 common/cmd_nand.c            |   55 +++++----
 common/env_nand.c            |    3 +-
 drivers/dfu/Makefile         |    1 +
 drivers/dfu/dfu.c            |  251 +++++++++++++++++++++++++++++++++---------
 drivers/dfu/dfu_mmc.c        |  116 ++++++++++++++-----
 drivers/dfu/dfu_nand.c       |  195 ++++++++++++++++++++++++++++++++
 drivers/mtd/nand/nand_util.c |   68 ++++++++++--
 include/configs/am335x_evm.h |   52 ++++++++-
 include/dfu.h                |   53 ++++++++-
 include/nand.h               |    4 +-
 11 files changed, 700 insertions(+), 121 deletions(-)
 create mode 100644 drivers/dfu/dfu_nand.c
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v5 1/9 README: Document current DFU CONFIG options

Add documentation for the current DFU config options. DFU is a standard USB device class so more information is available from usb.org

---
Changes in v5:
- New patch to document existing DFU CONFIG options

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

 README |   13 +++++++++++++
 1 file changed, 13 insertions(+)
README +13 -0
index 42544ce..900ae5f 100644
@@ -1325,6 +1325,19 @@ The following options need to be configured:
 			CONFIG_SH_MMCIF_CLK
 			Define the clock frequency for MMCIF
 
+- USB Device Firmware Update (DFU) class support:
+		CONFIG_DFU_FUNCTION
+		This enables the USB portion of the DFU USB class
+
+		CONFIG_CMD_DFU
+		This enables the command "dfu" which is used to have
+		U-Boot create a DFU class device via USB.  This command
+		requires that the "dfu_alt_info" environment variable be
+		set and define the alt settings to expose to the host.
+
+		CONFIG_DFU_MMC
+		This enables support for exposing (e)MMC devices via DFU.
+
 - Journaling Flash filesystem support:
 		CONFIG_JFFS2_NAND, CONFIG_JFFS2_NAND_OFF, CONFIG_JFFS2_NAND_SIZE,
 		CONFIG_JFFS2_NAND_DEV
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH v5 2/9 dfu: Support larger than memory transfers.

In reply to Tom Rini

From: Pantelis Antoniou <[email protected]>

Previously we didn't support upload/download larger than available memory. This is pretty bad when you have to update your root filesystem for example.

This patch removes that limitation (and the crashes when you transfered any file larger than 4MB) by making raw image writes be done in chunks and making file maximum size be configurable.

The sequence number is a 16 bit counter; make sure we handle rollover correctly. This fixes the wrong transfers for large (> 256MB) images.

Also utilize a variable to handle initialization, so that we don't rely on just the counter sent by the host.

---
Changes in v5:
- Rework Pantelis' "dfu: Support larger than memory transfers" to not break filesystem writing

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

 README                |    7 ++
 drivers/dfu/dfu.c     |  245 ++++++++++++++++++++++++++++++++++++++-----------
 drivers/dfu/dfu_mmc.c |  116 +++++++++++++++++------
 include/dfu.h         |   26 +++++-
 4 files changed, 310 insertions(+), 84 deletions(-)
README +7 -0
index 900ae5f..154b82f 100644
@@ -1338,6 +1338,13 @@ The following options need to be configured:
 		CONFIG_DFU_MMC
 		This enables support for exposing (e)MMC devices via DFU.
 
+		CONFIG_SYS_DFU_MAX_FILE_SIZE
+		When updating files rather than the raw storage device,
+		we use a static buffer to copy the file into and then write
+		the buffer once we've been given the whole file.  Define
+		this to the maximum filesize (in bytes) for the buffer.
+		Default is 4 MiB if undefined.
+
 - Journaling Flash filesystem support:
 		CONFIG_JFFS2_NAND, CONFIG_JFFS2_NAND_OFF, CONFIG_JFFS2_NAND_SIZE,
 		CONFIG_JFFS2_NAND_DEV
drivers/dfu/dfu.c +192 -53

282 lines not on this page · raw message

drivers/dfu/dfu_mmc.c +88 -28

207 lines not on this page · raw message

include/dfu.h +23 -3
index 5350d79..5182c6c 100644
@@ -59,7 +59,10 @@ static inline unsigned int get_mmc_blk_size(int dev)
 
 #define DFU_NAME_SIZE 32
 #define DFU_CMD_BUF_SIZE 128
-#define DFU_DATA_BUF_SIZE (1024*1024*4) /* 4 MiB */
+#define DFU_DATA_BUF_SIZE		(64 << 10)	/* 64 KiB */
+#ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE
+#define CONFIG_SYS_DFU_MAX_FILE_SIZE	(4 << 20)	/* 4 MiB */
+#endif
 
 struct dfu_entity {
 	char			name[DFU_NAME_SIZE];
@@ -73,10 +76,27 @@ struct dfu_entity {
 		struct mmc_internal_data mmc;
 	} data;
 
-	int (*read_medium)(struct dfu_entity *dfu, void *buf, long *len);
-	int (*write_medium)(struct dfu_entity *dfu, void *buf, long *len);
+	int (*read_medium)(struct dfu_entity *dfu,
+			u64 offset, void *buf, long *len);
+
+	int (*write_medium)(struct dfu_entity *dfu,
+			u64 offset, void *buf, long *len);
+
+	int (*flush_medium)(struct dfu_entity *dfu);
 
 	struct list_head list;
+
+	/* on the fly state */
+	u32 crc;
+	u64 offset;
+	int i_blk_seq_num;
+	u8 *i_buf;
+	u8 *i_buf_start;
+	u8 *i_buf_end;
+	long r_left;
+	long b_left;
+
+	unsigned int inited:1;
 };
 
 int dfu_config_entities(char *s, char *interface, int num);
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v5 2/9 dfu: Support larger than memory transfers.

Hi Tom,

Quoted 10 lines

From: Pantelis Antoniou <[email protected]>

Previously we didn't support upload/download larger than available memory. This is pretty bad when you have to update your root filesystem for example.

This patch removes that limitation (and the crashes when you transfered any file larger than 4MB) by making raw image writes be done in chunks and making file maximum size be configurable.

Quoted 8 lines

The sequence number is a 16 bit counter; make sure we handle rollover correctly. This fixes the wrong transfers for large (> 256MB) images.

Also utilize a variable to handle initialization, so that we don't rely on just the counter sent by the host.

Test-hw: Exynos 4210 (Trats)

Quoted 617 lines

---
Changes in v5:
- Rework Pantelis' "dfu: Support larger than memory transfers" to not break filesystem writing

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

 README                |    7 ++
 drivers/dfu/dfu.c     |  245

++++++++++++++++++++++++++++++++++++++-----------
drivers/dfu/dfu_mmc.c | 116 +++++++++++++++++------
include/dfu.h | 26 +++++- 4 files changed, 310
insertions(+), 84 deletions(-)

README +0 -0
index 900ae5f..154b82f 100644
@@ -1338,6 +1338,13 @@ The following options need to be configured:
 		CONFIG_DFU_MMC
 		This enables support for exposing (e)MMC devices via

DFU.

README +2 -0
+		CONFIG_SYS_DFU_MAX_FILE_SIZE
+		When updating files rather than the raw storage

device,

README +1 -0
+		we use a static buffer to copy the file into and

then write

README +1 -0
+		the buffer once we've been given the whole file.

Define

README +1 -0
+		this to the maximum filesize (in bytes) for the

buffer.

README +2 -0
+		Default is 4 MiB if undefined.
+
 - Journaling Flash filesystem support:
 		CONFIG_JFFS2_NAND, CONFIG_JFFS2_NAND_OFF,

CONFIG_JFFS2_NAND_SIZE, CONFIG_JFFS2_NAND_DEV

drivers/dfu/dfu.c +53 -8
index e8477fb..2fecf77 100644
@@ -44,90 +44,229 @@ static int dfu_find_alt_num(const char *s)
 static unsigned char __aligned(CONFIG_SYS_CACHELINE_SIZE)
 				     dfu_buf[DFU_DATA_BUF_SIZE];
 
+static int dfu_write_buffer_drain(struct dfu_entity *dfu)
+{
+	long w_size;
+	int ret;
+
+	/* flush size? */
+	w_size = dfu->i_buf - dfu->i_buf_start;
+	if (w_size == 0)
+		return 0;
+
+	/* update CRC32 */
+	dfu->crc = crc32(dfu->crc, dfu->i_buf_start, w_size);
+
+	ret = dfu->write_medium(dfu, dfu->offset, dfu->i_buf_start,
 &w_size);
+	if (ret)
+		debug("%s: Write error!\n", __func__);
+
+	/* point back */
+	dfu->i_buf = dfu->i_buf_start;
+
+	/* update offset */
+	dfu->offset += w_size;
+
+	puts("#");
+
+	return ret;
+}
+
 int dfu_write(struct dfu_entity *dfu, void *buf, int size, int
 blk_seq_num) {
-	static unsigned char *i_buf;
-	static int i_blk_seq_num;
-	long w_size = 0;
 	int ret = 0;
+	int tret;
+
+	debug("%s: name: %s buf: 0x%p size: 0x%x p_num: 0x%x "
+			"offset: 0x%llx bufoffset: 0x%x\n",
+	       __func__, dfu->name, buf, size, blk_seq_num,
 dfu->offset,
+	       dfu->i_buf - dfu->i_buf_start);
+
+	if (!dfu->inited) {
+		/* initial state */
+		dfu->crc = 0;
+		dfu->offset = 0;
+		dfu->i_blk_seq_num = 0;
+		dfu->i_buf_start = dfu_buf;
+		dfu->i_buf_end = dfu_buf + sizeof(dfu_buf);
+		dfu->i_buf = dfu->i_buf_start;
+
+		dfu->inited = 1;
+	}
 
-	debug("%s: name: %s buf: 0x%p size: 0x%x p_num: 0x%x i_buf:
 0x%p\n",
-	       __func__, dfu->name, buf, size, blk_seq_num, i_buf);
+	if (dfu->i_blk_seq_num != blk_seq_num) {
+		printf("%s: Wrong sequence number! [%d] [%d]\n",
+		       __func__, dfu->i_blk_seq_num, blk_seq_num);
+		return -1;
+	}
 
-	if (blk_seq_num == 0) {
-		i_buf = dfu_buf;
-		i_blk_seq_num = 0;
+	/* DFU 1.1 standard says:
+	 * The wBlockNum field is a block sequence number. It

increments each

drivers/dfu/dfu.c +1 -0
+	 * time a block is transferred, wrapping to zero from

65,535. It is used

drivers/dfu/dfu.c +1 -0
+	 * to provide useful context to the DFU loader in the

device."

drivers/dfu/dfu.c +21 -3
+	 *
+	 * This means that it's a 16 bit counter that roll-overs at
+	 * 0xffff -> 0x0000. By having a typical 4K transfer block
+	 * we roll-over at exactly 256MB. Not very fun to debug.
+	 *
+	 * Handling rollover, and having an inited variable,
+	 * makes things work.
+	 */
+
+	/* handle rollover */
+	dfu->i_blk_seq_num = (dfu->i_blk_seq_num + 1) & 0xffff;
+
+	/* flush buffer if overflow */
+	if ((dfu->i_buf + size) > dfu->i_buf_end) {
+		tret = dfu_write_buffer_drain(dfu);
+		if (ret == 0)
+			ret = tret;
 	}
 
-	if (i_blk_seq_num++ != blk_seq_num) {
-		printf("%s: Wrong sequence number! [%d] [%d]\n",
-		       __func__, i_blk_seq_num, blk_seq_num);
+	/* we should be in buffer now (if not then size too large) */
+	if ((dfu->i_buf + size) > dfu->i_buf_end) {
+		printf("%s: Wrong size! [%d] [%d] - %d\n",
+		       __func__, dfu->i_blk_seq_num, blk_seq_num,

size); return -1;

drivers/dfu/dfu.c +10 -4
 	}
 
-	memcpy(i_buf, buf, size);
-	i_buf += size;
+	memcpy(dfu->i_buf, buf, size);
+	dfu->i_buf += size;
 
+	/* if end or if buffer full flush */
+	if (size == 0 || (dfu->i_buf + size) > dfu->i_buf_end) {
+		tret = dfu_write_buffer_drain(dfu);
+		if (ret == 0)
+			ret = tret;
+	}
+
+	/* end? */
 	if (size == 0) {
-		/* Integrity check (if needed) */
-		debug("%s: %s %d [B] CRC32: 0x%x\n", __func__,

dfu->name,

drivers/dfu/dfu.c +0 -1
-		       i_buf - dfu_buf, crc32(0, dfu_buf, i_buf -

dfu_buf));

drivers/dfu/dfu.c +17 -8
+		/* Now try and flush to the medium if needed. */
+		if (dfu->flush_medium)
+			ret = dfu->flush_medium(dfu);
+		printf("\nDFU complete CRC32: 0x%08x\n", dfu->crc);
 
-		w_size = i_buf - dfu_buf;
-		ret = dfu->write_medium(dfu, dfu_buf, &w_size);
-		if (ret)
-			debug("%s: Write error!\n", __func__);
+		/* clear everything */
+		dfu->crc = 0;
+		dfu->offset = 0;
+		dfu->i_blk_seq_num = 0;
+		dfu->i_buf_start = dfu_buf;
+		dfu->i_buf_end = dfu_buf + sizeof(dfu_buf);
+		dfu->i_buf = dfu->i_buf_start;
+
+		dfu->inited = 0;
 
-		i_blk_seq_num = 0;
-		i_buf = NULL;
-		return ret;
 	}
 
-	return ret;
+	return ret = 0 ? size : ret;
+}
+
+static int dfu_read_buffer_fill(struct dfu_entity *dfu, void *buf,

int size) +{

drivers/dfu/dfu.c +27 -0
+	long chunk;
+	int ret, readn;
+
+	readn = 0;
+	while (size > 0) {
+
+		/* get chunk that can be read */
+		chunk = min(size, dfu->b_left);
+		/* consume */
+		if (chunk > 0) {
+			memcpy(buf, dfu->i_buf, chunk);
+			dfu->crc = crc32(dfu->crc, buf, chunk);
+			dfu->i_buf += chunk;
+			dfu->b_left -= chunk;
+			size -= chunk;
+			buf += chunk;
+			readn += chunk;
+		}
+
+		/* all done */
+		if (size > 0) {
+			/* no more to read */
+			if (dfu->r_left == 0)
+				break;
+
+			dfu->i_buf = dfu->i_buf_start;
+			dfu->b_left = dfu->i_buf_end -

dfu->i_buf_start; +

drivers/dfu/dfu.c +4 -0
+			/* got to read, but buffer is empty */
+			if (dfu->b_left > dfu->r_left)
+				dfu->b_left = dfu->r_left;
+			ret = dfu->read_medium(dfu, dfu->offset,

dfu->i_buf,

drivers/dfu/dfu.c +13 -0
+					&dfu->b_left);
+			if (ret != 0) {
+				debug("%s: Read error!\n", __func__);
+				return ret;
+			}
+			dfu->offset += dfu->b_left;
+			dfu->r_left -= dfu->b_left;
+
+			puts("#");
+		}
+	}
+
+	return readn;
 }
 
 int dfu_read(struct dfu_entity *dfu, void *buf, int size, int

blk_seq_num) {

drivers/dfu/dfu.c +0 -4
-	static unsigned char *i_buf;
-	static int i_blk_seq_num;
-	static long r_size;
-	static u32 crc;
 	int ret = 0;
 
 	debug("%s: name: %s buf: 0x%p size: 0x%x p_num: 0x%x i_buf:

0x%p\n",

drivers/dfu/dfu.c +0 -6
-	       __func__, dfu->name, buf, size, blk_seq_num, i_buf);
-
-	if (blk_seq_num == 0) {
-		i_buf = dfu_buf;
-		ret = dfu->read_medium(dfu, i_buf, &r_size);
-		debug("%s: %s %ld [B]\n", __func__, dfu->name,

r_size);

drivers/dfu/dfu.c +1 -3
-		i_blk_seq_num = 0;
-		/* Integrity check (if needed) */
-		crc = crc32(0, dfu_buf, r_size);
+	       __func__, dfu->name, buf, size, blk_seq_num,

dfu->i_buf); +

drivers/dfu/dfu.c +4 -0
+	if (!dfu->inited) {
+		ret = dfu->read_medium(dfu, 0, NULL, &dfu->r_left);
+		if (ret != 0) {
+			debug("%s: failed to get r_left\n",

__func__);

drivers/dfu/dfu.c +4 -0
+			return ret;
+		}
+
+		debug("%s: %s %ld [B]\n", __func__, dfu->name,

dfu->r_left); +

drivers/dfu/dfu.c +13 -11
+		dfu->i_blk_seq_num = 0;
+		dfu->crc = 0;
+		dfu->offset = 0;
+		dfu->i_buf_start = dfu_buf;
+		dfu->i_buf_end = dfu_buf + sizeof(dfu_buf);
+		dfu->i_buf = dfu->i_buf_start;
+		dfu->b_left = 0;
+
+		dfu->inited = 1;
 	}
 
-	if (i_blk_seq_num++ != blk_seq_num) {
+	if (dfu->i_blk_seq_num != blk_seq_num) {
 		printf("%s: Wrong sequence number! [%d] [%d]\n",
-		       __func__, i_blk_seq_num, blk_seq_num);
+		       __func__, dfu->i_blk_seq_num, blk_seq_num);
 		return -1;
 	}
+	/* handle rollover */
+	dfu->i_blk_seq_num = (dfu->i_blk_seq_num + 1) & 0xffff;
 
-	if (r_size >= size) {
-		memcpy(buf, i_buf, size);
-		i_buf += size;
-		r_size -= size;
-		return size;
-	} else {
-		memcpy(buf, i_buf, r_size);
-		i_buf += r_size;
-		debug("%s: %s CRC32: 0x%x\n", __func__, dfu->name,

crc);

drivers/dfu/dfu.c +8 -1
-		puts("UPLOAD ... done\nCtrl+C to exit ...\n");
+	ret = dfu_read_buffer_fill(dfu, buf, size);
+	if (ret < 0) {
+		printf("%s: Failed to fill buffer\n", __func__);
+		return -1;
+	}
+
+	if (ret < size) {
+		debug("%s: %s CRC32: 0x%x\n", __func__, dfu->name,

dfu->crc);

drivers/dfu/dfu.c +11 -4
+		puts("\nUPLOAD ... done\nCtrl+C to exit ...\n");
 
-		i_buf = NULL;
-		i_blk_seq_num = 0;
-		crc = 0;
-		return r_size;
+		dfu->i_blk_seq_num = 0;
+		dfu->crc = 0;
+		dfu->offset = 0;
+		dfu->i_buf_start = dfu_buf;
+		dfu->i_buf_end = dfu_buf + sizeof(dfu_buf);
+		dfu->i_buf = dfu->i_buf_start;
+		dfu->b_left = 0;
+
+		dfu->inited = 0;
 	}
+
 	return ret;
 }
drivers/dfu/dfu_mmc.c +3 -0
index 083d745..2d5ffd8 100644
@@ -22,6 +22,7 @@
 #include <common.h>
 #include <malloc.h>
 #include <errno.h>
+#include <div64.h>
 #include <dfu.h>
 
 enum dfu_mmc_op {
@@ -29,36 +30,67 @@ enum dfu_mmc_op {
 	DFU_OP_WRITE,
 };
 
+static unsigned char __aligned(CONFIG_SYS_CACHELINE_SIZE)
+

dfu_file_buf[CONFIG_SYS_DFU_MAX_FILE_SIZE]; +static long dfu_file_buf_len; +
static int mmc_block_op(enum dfu_mmc_op op, struct dfu_entity *dfu,

drivers/dfu/dfu_mmc.c +5 -1
-			void *buf, long *len)
+			u64 offset, void *buf, long *len)
 {
 	char cmd_buf[DFU_CMD_BUF_SIZE];
+	u32 blk_start, blk_count;
+
+	/*
+	 * We must ensure that we work in lba_blk_size chunks, so

ALIGN

drivers/dfu/dfu_mmc.c +6 -0
+	 * this value.
+	 */
+	*len = ALIGN(*len, dfu->data.mmc.lba_blk_size);
+
+	blk_start = dfu->data.mmc.lba_start +
+			(u32)lldiv(offset,

dfu->data.mmc.lba_blk_size);

drivers/dfu/dfu_mmc.c +3 -0
+	blk_count = *len / dfu->data.mmc.lba_blk_size;
+	if (*len + blk_start >
+			dfu->data.mmc.lba_size *

dfu->data.mmc.lba_size) {

drivers/dfu/dfu_mmc.c +4 -7
+		puts("Request would exceed designated area!\n");
+		return -EINVAL;
+	}
 
-	sprintf(cmd_buf, "mmc %s 0x%x %x %x",
+	sprintf(cmd_buf, "mmc %s %p %x %x",
 		op == DFU_OP_READ ? "read" : "write",
-		(unsigned int) buf,
-		dfu->data.mmc.lba_start,
-		dfu->data.mmc.lba_size);
-
-	if (op == DFU_OP_READ)
-		*len = dfu->data.mmc.lba_blk_size *

dfu->data.mmc.lba_size;

drivers/dfu/dfu_mmc.c +1 -1
+		 buf, blk_start, blk_count);
 
 	debug("%s: %s 0x%p\n", __func__, cmd_buf, cmd_buf);
 	return run_command(cmd_buf, 0);
 }
 
-static inline int mmc_block_write(struct dfu_entity *dfu, void *buf,

long *len) +static inline int mmc_block_write(struct dfu_entity *dfu,

drivers/dfu/dfu_mmc.c +8 -2
+		u64 offset, void *buf, long *len)
+{
+	return mmc_block_op(DFU_OP_WRITE, dfu, offset, buf, len);
+}
+
+static inline int mmc_block_read(struct dfu_entity *dfu,
+		u64 offset, void *buf, long *len)
 {
-	return mmc_block_op(DFU_OP_WRITE, dfu, buf, len);
+	return mmc_block_op(DFU_OP_READ, dfu, offset, buf, len);
 }
 
-static inline int mmc_block_read(struct dfu_entity *dfu, void *buf,

long *len) +static int mmc_file_buffer(struct dfu_entity *dfu, void *buf, long *len) {

drivers/dfu/dfu_mmc.c +18 -2
-	return mmc_block_op(DFU_OP_READ, dfu, buf, len);
+	if (dfu_file_buf_len + *len > CONFIG_SYS_DFU_MAX_FILE_SIZE) {
+		dfu_file_buf_len = 0;
+		return -EINVAL;
+	}
+
+	/* Add to the current buffer. */
+	memcpy(dfu_file_buf + dfu_file_buf_len, buf, *len);
+	dfu_file_buf_len += *len;
+
+	return 0;
 }
 
 static int mmc_file_op(enum dfu_mmc_op op, struct dfu_entity *dfu,
-			void *buf, long *len)
+			u64 offset, void *buf, long *len)
 {
 	char cmd_buf[DFU_CMD_BUF_SIZE];
 	char *str_env;
@@ -70,8 +102,15 @@ static int mmc_file_op(enum dfu_mmc_op op, struct
 dfu_entity *dfu, op == DFU_OP_READ ? "load" : "write",
 			dfu->data.mmc.dev, dfu->data.mmc.part,
 			(unsigned int) buf, dfu->name, *len);
+		if (op == DFU_OP_READ && offset != 0)
+			sprintf(cmd_buf + strlen(cmd_buf), " %llx",
 offset); break;
 	case DFU_FS_EXT4:
+		if (offset != 0) {
+			debug("%s: Offset value %llx != 0 not
 supported!\n",
+					__func__, offset);
+			return -1;
+		}
 		sprintf(cmd_buf, "ext4%s mmc %d:%d /%s 0x%x %ld",
 			op == DFU_OP_READ ? "load" : "write",
drivers/dfu/dfu_mmc.c +0 -0
 			dfu->data.mmc.dev, dfu->data.mmc.part,
@@ -80,6 +119,7 @@ static int mmc_file_op(enum dfu_mmc_op op, struct

dfu_entity *dfu, default:
printf("%s: Layout (%s) not (yet) supported!\n",
__func__, dfu_get_layout(dfu->layout));

drivers/dfu/dfu_mmc.c +6 -9
+		return -1;
 	}
 
 	debug("%s: %s 0x%p\n", __func__, cmd_buf, cmd_buf);
@@ -102,27 +142,24 @@ static int mmc_file_op(enum dfu_mmc_op op,
 struct dfu_entity *dfu, return ret;
 }
 
-static inline int mmc_file_write(struct dfu_entity *dfu, void *buf,
 long *len) +static inline int mmc_file_read(struct dfu_entity *dfu,
+		u64 offset, void *buf, long *len)
 {
-	return mmc_file_op(DFU_OP_WRITE, dfu, buf, len);
+	return mmc_file_op(DFU_OP_READ, dfu, offset, buf, len);
 }
 
-static inline int mmc_file_read(struct dfu_entity *dfu, void *buf,
 long *len) -{
-	return mmc_file_op(DFU_OP_READ, dfu, buf, len);
-}
-
-int dfu_write_medium_mmc(struct dfu_entity *dfu, void *buf, long
 *len) +int dfu_write_medium_mmc(struct dfu_entity *dfu,
+		u64 offset, void *buf, long *len)
 {
 	int ret = -1;
 
 	switch (dfu->layout) {
 	case DFU_RAW_ADDR:
-		ret = mmc_block_write(dfu, buf, len);
+		ret = mmc_block_write(dfu, offset, buf, len);
 		break;
 	case DFU_FS_FAT:
 	case DFU_FS_EXT4:
-		ret = mmc_file_write(dfu, buf, len);
+		ret = mmc_file_buffer(dfu, buf, len);
 		break;
 	default:
 		printf("%s: Layout (%s) not (yet) supported!\n",

__func__, @@ -132,17 +169,34 @@ int dfu_write_medium_mmc(struct dfu_entity *dfu, void *buf, long *len) return ret;
}

drivers/dfu/dfu_mmc.c +7 -1
-int dfu_read_medium_mmc(struct dfu_entity *dfu, void *buf, long *len)
+int dfu_flush_medium_mmc(struct dfu_entity *dfu)
+{
+	int ret = 0;
+
+	if (dfu->layout != DFU_RAW_ADDR) {
+		/* Do stuff here. */
+		ret = mmc_file_op(DFU_OP_WRITE, dfu, 0,

&dfu_file_buf,

drivers/dfu/dfu_mmc.c +10 -0
+				&dfu_file_buf_len);
+
+		/* Now that we're done */
+		dfu_file_buf_len = 0;
+	}
+
+	return ret;
+}
+
+int dfu_read_medium_mmc(struct dfu_entity *dfu, u64 offset, void

*buf,

drivers/dfu/dfu_mmc.c +3 -2
+		long *len)
 {
 	int ret = -1;
 
 	switch (dfu->layout) {
 	case DFU_RAW_ADDR:
-		ret = mmc_block_read(dfu, buf, len);
+		ret = mmc_block_read(dfu, offset, buf, len);
 		break;
 	case DFU_FS_FAT:
 	case DFU_FS_EXT4:
-		ret = mmc_file_read(dfu, buf, len);
+		ret = mmc_file_read(dfu, offset, buf, len);
 		break;
 	default:
 		printf("%s: Layout (%s) not (yet) supported!\n",

__func__, @@ -181,13 +235,15 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)

drivers/dfu/dfu_mmc.c +0 -1
 		mmc = find_mmc_device(dev);
 		if (mmc == NULL || mmc_init(mmc)) {
-			printf("%s: could not find mmc device

#%d!\n", __func__, dev);

drivers/dfu/dfu_mmc.c +1 -0
+			printf("%s: could not find mmc device

#%d!\n",

drivers/dfu/dfu_mmc.c +1 -0
+					__func__, dev);
 			return -ENODEV;
 		}
 
 		blk_dev = &mmc->block_dev;
 		if (get_partition_info(blk_dev, part, &partinfo) !=

0) {

drivers/dfu/dfu_mmc.c +0 -1
-			printf("%s: could not find partition #%d on

mmc device #%d!\n",

drivers/dfu/dfu_mmc.c +6 -0
+			printf("%s: could not find partition #%d "
+					"on mmc device #%d!\n",
 					__func__, part, dev);
 			return -ENODEV;
 		}
@@ -208,6 +264,10 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu,
 char *s) 
 	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;
 }
include/dfu.h +2 -1
index 5350d79..5182c6c 100644
@@ -59,7 +59,10 @@ static inline unsigned int get_mmc_blk_size(int
 dev) 
 #define DFU_NAME_SIZE 32
 #define DFU_CMD_BUF_SIZE 128
-#define DFU_DATA_BUF_SIZE (1024*1024*4) /* 4 MiB */
+#define DFU_DATA_BUF_SIZE		(64 << 10)	/* 64 KiB
 */ +#ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE
+#define CONFIG_SYS_DFU_MAX_FILE_SIZE	(4 << 20)	/* 4

MiB */ +#endif

struct dfu_entity {

include/dfu.h +19 -2
 	char			name[DFU_NAME_SIZE];
@@ -73,10 +76,27 @@ struct dfu_entity {
 		struct mmc_internal_data mmc;
 	} data;
 
-	int (*read_medium)(struct dfu_entity *dfu, void *buf, long
 *len);
-	int (*write_medium)(struct dfu_entity *dfu, void *buf, long
 *len);
+	int (*read_medium)(struct dfu_entity *dfu,
+			u64 offset, void *buf, long *len);
+
+	int (*write_medium)(struct dfu_entity *dfu,
+			u64 offset, void *buf, long *len);
+
+	int (*flush_medium)(struct dfu_entity *dfu);
 
 	struct list_head list;
+
+	/* on the fly state */
+	u32 crc;
+	u64 offset;
+	int i_blk_seq_num;
+	u8 *i_buf;
+	u8 *i_buf_start;
+	u8 *i_buf_end;
+	long r_left;
+	long b_left;
+
+	unsigned int inited:1;
 };

int dfu_config_entities(char *s, char *interface, int num);

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Poland (SRPOL) | Linux Platform Group
#4 lore raw

PATCH v5 2/9 dfu: Support larger than memory transfers.

Hi Tom,

Quoted 18 lines
Quoted 18 lines

From: Pantelis Antoniou <[email protected]>

Previously we didn't support upload/download larger than available memory. This is pretty bad when you have to update your root filesystem for example.

This patch removes that limitation (and the crashes when you transfered any file larger than 4MB) by making raw image writes be done in chunks and making file maximum size be configurable.

The sequence number is a 16 bit counter; make sure we handle rollover correctly. This fixes the wrong transfers for large (> 256MB) images.

Also utilize a variable to handle initialization, so that we don't rely on just the counter sent by the host.

Quoted 8 lines
Quoted 2 lines

Test-hw: Exynos 4210 (Trats)

Sorry but, I've found a regression for reading image from a file system. It happens with EXT4 mmc read (like uImage).

mmc_file_op: ext4load mmc 0:2 /uImage 0x0 0 0x7f95dc98 ** File not found 0x0 **
dfu: Read error!

ext4load params:
ext4load - load binary file from a Ext4 filesystem

Usage:
ext4load <interface> <dev[:part]> [addr] [filename] [bytes]
- load binary file 'filename' from 'dev' on 'interface' to address 'addr' from ext4 filesystem.
All numeric parameters are assumed to be hex.

Some parameters are wrong (buffer - 0x0) and some are switched (address and filename).

Please find more details below:

Quoted 228 lines
Quoted 228 lines

---
Changes in v5:
- Rework Pantelis' "dfu: Support larger than memory transfers" to not break filesystem writing

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

 README                |    7 ++
 drivers/dfu/dfu.c     |  245

++++++++++++++++++++++++++++++++++++++-----------
drivers/dfu/dfu_mmc.c | 116 +++++++++++++++++------
include/dfu.h | 26 +++++- 4 files changed, 310
insertions(+), 84 deletions(-)

drivers/dfu/dfu.c +14 -0
+static int dfu_write_buffer_drain(struct dfu_entity *dfu)
+{
+	long w_size;
+	int ret;
+
+	/* flush size? */
+	w_size = dfu->i_buf - dfu->i_buf_start;
+	if (w_size == 0)
+		return 0;
+
+	/* update CRC32 */
+	dfu->crc = crc32(dfu->crc, dfu->i_buf_start, w_size);
+
+	ret = dfu->write_medium(dfu, dfu->offset, dfu->i_buf_start,

&w_size);

drivers/dfu/dfu.c +14 -0
+	if (ret)
+		debug("%s: Write error!\n", __func__);
+
+	/* point back */
+	dfu->i_buf = dfu->i_buf_start;
+
+	/* update offset */
+	dfu->offset += w_size;
+
+	puts("#");
+
+	return ret;
+}
+
 int dfu_write(struct dfu_entity *dfu, void *buf, int size, int

blk_seq_num) {

drivers/dfu/dfu.c +5 -3
-	static unsigned char *i_buf;
-	static int i_blk_seq_num;
-	long w_size = 0;
 	int ret = 0;
+	int tret;
+
+	debug("%s: name: %s buf: 0x%p size: 0x%x p_num: 0x%x "
+			"offset: 0x%llx bufoffset: 0x%x\n",
+	       __func__, dfu->name, buf, size, blk_seq_num,

dfu->offset,

drivers/dfu/dfu.c +13 -1
+	       dfu->i_buf - dfu->i_buf_start);
+
+	if (!dfu->inited) {
+		/* initial state */
+		dfu->crc = 0;
+		dfu->offset = 0;
+		dfu->i_blk_seq_num = 0;
+		dfu->i_buf_start = dfu_buf;
+		dfu->i_buf_end = dfu_buf + sizeof(dfu_buf);
+		dfu->i_buf = dfu->i_buf_start;
+
+		dfu->inited = 1;
+	}
 
-	debug("%s: name: %s buf: 0x%p size: 0x%x p_num: 0x%x i_buf:

0x%p\n",

drivers/dfu/dfu.c +7 -4
-	       __func__, dfu->name, buf, size, blk_seq_num, i_buf);
+	if (dfu->i_blk_seq_num != blk_seq_num) {
+		printf("%s: Wrong sequence number! [%d] [%d]\n",
+		       __func__, dfu->i_blk_seq_num, blk_seq_num);
+		return -1;
+	}
 
-	if (blk_seq_num == 0) {
-		i_buf = dfu_buf;
-		i_blk_seq_num = 0;
+	/* DFU 1.1 standard says:
+	 * The wBlockNum field is a block sequence number. It

increments each

(quoted diff) +1 -0
+	 * time a block is transferred, wrapping to zero from

65,535. It is used

(quoted diff) +1 -0
+	 * to provide useful context to the DFU loader in the

device."

drivers/dfu/dfu.c +18 -3
+	 *
+	 * This means that it's a 16 bit counter that roll-overs at
+	 * 0xffff -> 0x0000. By having a typical 4K transfer block
+	 * we roll-over at exactly 256MB. Not very fun to debug.
+	 *
+	 * Handling rollover, and having an inited variable,
+	 * makes things work.
+	 */
+
+	/* handle rollover */
+	dfu->i_blk_seq_num = (dfu->i_blk_seq_num + 1) & 0xffff;
+
+	/* flush buffer if overflow */
+	if ((dfu->i_buf + size) > dfu->i_buf_end) {
+		tret = dfu_write_buffer_drain(dfu);
+		if (ret == 0)
+			ret = tret;
 	}
 
-	if (i_blk_seq_num++ != blk_seq_num) {
-		printf("%s: Wrong sequence number! [%d] [%d]\n",
-		       __func__, i_blk_seq_num, blk_seq_num);
+	/* we should be in buffer now (if not then size too large)

*/

drivers/dfu/dfu.c +3 -0
+	if ((dfu->i_buf + size) > dfu->i_buf_end) {
+		printf("%s: Wrong size! [%d] [%d] - %d\n",
+		       __func__, dfu->i_blk_seq_num, blk_seq_num,

size); return -1;

drivers/dfu/dfu.c +10 -4
 	}
 
-	memcpy(i_buf, buf, size);
-	i_buf += size;
+	memcpy(dfu->i_buf, buf, size);
+	dfu->i_buf += size;
 
+	/* if end or if buffer full flush */
+	if (size == 0 || (dfu->i_buf + size) > dfu->i_buf_end) {
+		tret = dfu_write_buffer_drain(dfu);
+		if (ret == 0)
+			ret = tret;
+	}
+
+	/* end? */
 	if (size == 0) {
-		/* Integrity check (if needed) */
-		debug("%s: %s %d [B] CRC32: 0x%x\n", __func__,

dfu->name,

(quoted diff) +0 -1
-		       i_buf - dfu_buf, crc32(0, dfu_buf, i_buf -

dfu_buf));

drivers/dfu/dfu.c +17 -8
+		/* Now try and flush to the medium if needed. */
+		if (dfu->flush_medium)
+			ret = dfu->flush_medium(dfu);
+		printf("\nDFU complete CRC32: 0x%08x\n", dfu->crc);
 
-		w_size = i_buf - dfu_buf;
-		ret = dfu->write_medium(dfu, dfu_buf, &w_size);
-		if (ret)
-			debug("%s: Write error!\n", __func__);
+		/* clear everything */
+		dfu->crc = 0;
+		dfu->offset = 0;
+		dfu->i_blk_seq_num = 0;
+		dfu->i_buf_start = dfu_buf;
+		dfu->i_buf_end = dfu_buf + sizeof(dfu_buf);
+		dfu->i_buf = dfu->i_buf_start;
+
+		dfu->inited = 0;
 
-		i_blk_seq_num = 0;
-		i_buf = NULL;
-		return ret;
 	}
 
-	return ret;
+	return ret = 0 ? size : ret;
+}
+
+static int dfu_read_buffer_fill(struct dfu_entity *dfu, void *buf,

int size) +{

drivers/dfu/dfu.c +27 -0
+	long chunk;
+	int ret, readn;
+
+	readn = 0;
+	while (size > 0) {
+
+		/* get chunk that can be read */
+		chunk = min(size, dfu->b_left);
+		/* consume */
+		if (chunk > 0) {
+			memcpy(buf, dfu->i_buf, chunk);
+			dfu->crc = crc32(dfu->crc, buf, chunk);
+			dfu->i_buf += chunk;
+			dfu->b_left -= chunk;
+			size -= chunk;
+			buf += chunk;
+			readn += chunk;
+		}
+
+		/* all done */
+		if (size > 0) {
+			/* no more to read */
+			if (dfu->r_left == 0)
+				break;
+
+			dfu->i_buf = dfu->i_buf_start;
+			dfu->b_left = dfu->i_buf_end -

dfu->i_buf_start; +

drivers/dfu/dfu.c +4 -0
+			/* got to read, but buffer is empty */
+			if (dfu->b_left > dfu->r_left)
+				dfu->b_left = dfu->r_left;
+			ret = dfu->read_medium(dfu, dfu->offset,

dfu->i_buf,

drivers/dfu/dfu.c +3 -0
+					&dfu->b_left);
+			if (ret != 0) {
+				debug("%s: Read error!\n",

__func__);

drivers/dfu/dfu.c +10 -0
+				return ret;
+			}
+			dfu->offset += dfu->b_left;
+			dfu->r_left -= dfu->b_left;
+
+			puts("#");
+		}
+	}
+
+	return readn;
 }
 
 int dfu_read(struct dfu_entity *dfu, void *buf, int size, int

blk_seq_num) {

drivers/dfu/dfu.c +0 -4
-	static unsigned char *i_buf;
-	static int i_blk_seq_num;
-	static long r_size;
-	static u32 crc;
 	int ret = 0;
Quoted 16 lines
Quoted 14 lines

debug("%s: name: %s buf: 0x%p size: 0x%x p_num: 0x%x i_buf:
0x%p\n",

drivers/dfu/dfu.c +0 -6
-	       __func__, dfu->name, buf, size, blk_seq_num, i_buf);
-
-	if (blk_seq_num == 0) {
-		i_buf = dfu_buf;
-		ret = dfu->read_medium(dfu, i_buf, &r_size);
-		debug("%s: %s %ld [B]\n", __func__, dfu->name,

r_size);

drivers/dfu/dfu.c +1 -3
-		i_blk_seq_num = 0;
-		/* Integrity check (if needed) */
-		crc = crc32(0, dfu_buf, r_size);
+	       __func__, dfu->name, buf, size, blk_seq_num,

dfu->i_buf); +

drivers/dfu/dfu.c static int dfu_find_alt_num(const char *s) · line 222

Quoted 2 lines
drivers/dfu/dfu.c +2 -0
+	if (!dfu->inited) {
+		ret = dfu->read_medium(dfu, 0, NULL, &dfu->r_left);

^^^^^^^^^^^^ this call causes read error. I suppose, that it is an initial "read". Does it read the whole file at once?

The problem is that the command is fromatted in a wrong way.

On the other hand write operations works on Trats.

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Poland (SRPOL) | Linux Platform Group
author
#5 lore raw

PATCH v5 2/9 dfu: Support larger than memory transfers.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 26 lines · Lukasz Majewski

Hi Tom,

Quoted 23 lines
Quoted 22 lines

From: Pantelis Antoniou <[email protected]>

Previously we didn't support upload/download larger than available memory. This is pretty bad when you have to update your root filesystem for example.

This patch removes that limitation (and the crashes when you transfered any file larger than 4MB) by making raw image writes be done in chunks and making file maximum size be configurable.

The sequence number is a 16 bit counter; make sure we handle rollover correctly. This fixes the wrong transfers for large (> 256MB) images.

Also utilize a variable to handle initialization, so that we don't rely on just the counter sent by the host.

Signed-off-by: Pantelis Antoniou <[email protected]> Signed-off-by: Tom Rini <[email protected]>

Quoted 8 lines
Quoted 5 lines

Test-hw: Exynos 4210 (Trats)

Sorry but, I've found a regression for reading image from a file system. It happens with EXT4 mmc read (like uImage).

Can you please confirm read works as-is today? It's possible that when I tried I was using (what I've now called) a marginal SD card I've finally written too much to the front sectors on, but it wasn't working for me at all. I'll try and reproduce as well. That said, there is a problem:

Quoted 6 lines

mmc_file_op: ext4load mmc 0:2 /uImage 0x0 0 0x7f95dc98 ** File not found 0x0 ** dfu: Read error!

ext4load params: ext4load - load binary file from a Ext4 filesystem

Quoted 7 lines

Usage: ext4load <interface> <dev[:part]> [addr] [filename] [bytes]
- load binary file 'filename' from 'dev' on 'interface' to address 'addr' from ext4 filesystem. All numeric parameters are assumed to be hex.

Some parameters are wrong (buffer - 0x0) and some are switched (address and filename).

I just noticed last week that ext4load has the syntax backwards from fatload for address/filename :( And in this case it's passing in too many params, so I will fix that.

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +1 -0
+	       __func__, dfu->name, buf, size, blk_seq_num, 

dfu->i_buf); + + if (!dfu->inited) { + ret =
dfu->read_medium(dfu, 0, NULL, &dfu->r_left);

^^^^^^^^^^^^ this call causes read error. I suppose, that it is an initial "read". Does it read the whole file at once?

I'll double check what's going on over here.

- --
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRPdQ+AAoJENk4IS6UOR1WYzgP/RwNBOTJ7XPM9mrFFU+3UtyA Z/tUwuyghitC/rBBPuUyoml6Oq+9oVtCd89uZyjYjFUh68HKGSZ6a+XaLl1KC9Yr n/3m91CXgnJAdh3TcrGoX6Gg9dVPb0vomLZpyZg/UK71PNnXcFI9BAvkXlfwUi1r KbPDF10WzNq4qACELdwHKP8gumhBvgB+qyCHjFRalD/jk9HS1Nv7rIpgng2eQpbv kGyRzZRJNmJ5s0/XSlg6G+XP9seE23oAw1eLZRO3bF33PcynC1L2R96iBLU4dIcQ BHQp3jC+3m7v543eXqNvBaBJDIuABkqm8Or0xdw18T8d0unci+VxRXNvVlI2VrdL fhhj47cSEKzAEJ6KTzwwvZl4CUnqfExPds/yTWl5CF+PNukw91b7kZca2uOuEtkM htbQthvt7jzaD5Ji0U8R3FF3cJ39g1XVOARpY1hzPeHMrX83b5dHFPg0LDEj31qK FWkNElx4MHgu2Cir8cBWGaFwAHxXqyG9VfPX2LwHD6zCLHmKryq+UlH+KfZgi3UE u0vDxH24jeGccDc6BIXgJdDvt8AN8SQgXtpV6xrCWEPYR90GBpM8/yOIeTbxzuky hTi2Ke8VxIGYmVWBDQ/YtKoANL1peiZuFB/DmoMA9d6WbQDkZbmgI0lQ+3x6kZxs WRBsQxgaW4Yf6nIUv5X3
=t1hs
-----END PGP SIGNATURE-----

author
#6 lore raw

PATCH v5 2/9 dfu: Support larger than memory transfers.

In reply to Lukasz Majewski
Quoted 37 lines · Lukasz Majewski

Hi Tom,

Quoted 18 lines
Quoted 18 lines

From: Pantelis Antoniou <[email protected]>

Previously we didn't support upload/download larger than available memory. This is pretty bad when you have to update your root filesystem for example.

This patch removes that limitation (and the crashes when you transfered any file larger than 4MB) by making raw image writes be done in chunks and making file maximum size be configurable.

The sequence number is a 16 bit counter; make sure we handle rollover correctly. This fixes the wrong transfers for large (> 256MB) images.

Also utilize a variable to handle initialization, so that we don't rely on just the counter sent by the host.

Quoted 8 lines
Quoted 2 lines

Test-hw: Exynos 4210 (Trats)

Sorry but, I've found a regression for reading image from a file system. It happens with EXT4 mmc read (like uImage).

mmc_file_op: ext4load mmc 0:2 /uImage 0x0 0 0x7f95dc98 ** File not found 0x0 **
dfu: Read error!

Quoted 5 lines

ext4load params:
ext4load - load binary file from a Ext4 filesystem

Usage:
ext4load <interface> <dev[:part]> [addr] [filename] [bytes]

This is a bug, but this is not a regression. As I sent in another email, the issue is that ext4write takes arguments backwards from fatwrite/fatload/ext4load so the line here has always been wrong.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130313/d8ce1aca/attachment.pgp>
author
#7 lore raw

PATCH v5 2/9 dfu: Support larger than memory transfers.

In reply to Lukasz Majewski

On Mon, Mar 11, 2013 at 11:03:41AM +0100, Lukasz Majewski wrote:

[snip]

Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
drivers/dfu/dfu.c +0 -4
-	if (blk_seq_num == 0) {
-		i_buf = dfu_buf;
-		ret = dfu->read_medium(dfu, i_buf, &r_size);
-		debug("%s: %s %ld [B]\n", __func__, dfu->name,
Quoted 8 lines

drivers/dfu/dfu.c static int dfu_find_alt_num(const char *s) · line 222

Quoted 8 lines

r_size);

drivers/dfu/dfu.c +1 -3
-		i_blk_seq_num = 0;
-		/* Integrity check (if needed) */
-		crc = crc32(0, dfu_buf, r_size);
+	       __func__, dfu->name, buf, size, blk_seq_num,

dfu->i_buf); +

drivers/dfu/dfu.c +2 -0
+	if (!dfu->inited) {
+		ret = dfu->read_medium(dfu, 0, NULL, &dfu->r_left);

^^^^^^^^^^^^ this call causes read error. I suppose, that it is an initial "read". Does it read the whole file at once?

Quoted 2 lines

The problem is that the command is fromatted in a wrong way.

And we're also passing NULL as the buffer to read into? That also can't be good. I'll spend a little time here and see what's going on.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130313/50cf9255/attachment.pgp>
author
#8 lore raw

PATCH v5 2/9 dfu: Support larger than memory transfers.

Quoted 19 lines · Tom Rini

On Mon, Mar 11, 2013 at 11:03:41AM +0100, Lukasz Majewski wrote:

[snip]

Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
drivers/dfu/dfu.c +0 -4
-	if (blk_seq_num == 0) {
-		i_buf = dfu_buf;
-		ret = dfu->read_medium(dfu, i_buf, &r_size);
-		debug("%s: %s %ld [B]\n", __func__, dfu->name,
Quoted 8 lines

drivers/dfu/dfu.c static int dfu_find_alt_num(const char *s) · line 222

Quoted 8 lines

r_size);

drivers/dfu/dfu.c +1 -3
-		i_blk_seq_num = 0;
-		/* Integrity check (if needed) */
-		crc = crc32(0, dfu_buf, r_size);
+	       __func__, dfu->name, buf, size, blk_seq_num,

dfu->i_buf); +

drivers/dfu/dfu.c +2 -0
+	if (!dfu->inited) {
+		ret = dfu->read_medium(dfu, 0, NULL, &dfu->r_left);

^^^^^^^^^^^^ this call causes read error. I suppose, that it is an initial "read". Does it read the whole file at once?

Quoted 5 lines
Quoted 2 lines

The problem is that the command is fromatted in a wrong way.

And we're also passing NULL as the buffer to read into? That also can't be good. I'll spend a little time here and see what's going on.

OK, I see and have fixed some minor issues here, but without any of these patches, I'm not seeing DFU read work at all for raw. I keep getting "Wrong sequence number!" errors on the U-Boot side. Using dfu-util 0.5 from Ubuntu 12.04 still. I'm inclined to push back and say, after fixing a few calls now that I re-read my code, DFU read is broken and set that aside as another problem to get fixed.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130313/f9ddaa89/attachment.pgp>
#9 lore raw

PATCH v5 2/9 dfu: Support larger than memory transfers.

Hi Tom,

Quoted 29 lines · Tom Rini
Quoted 21 lines · Lukasz Majewski

[snip]

Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
drivers/dfu/dfu.c +0 -4
-	if (blk_seq_num == 0) {
-		i_buf = dfu_buf;
-		ret = dfu->read_medium(dfu, i_buf, &r_size);
-		debug("%s: %s %ld [B]\n", __func__,

dfu->name, r_size);

Quoted 8 lines
Quoted 8 lines
drivers/dfu/dfu.c +1 -3
-		i_blk_seq_num = 0;
-		/* Integrity check (if needed) */
-		crc = crc32(0, dfu_buf, r_size);
+	       __func__, dfu->name, buf, size, blk_seq_num,

dfu->i_buf); +

(quoted diff) +2 -0
+	if (!dfu->inited) {
+		ret = dfu->read_medium(dfu, 0, NULL,

&dfu->r_left);

			   ^^^^^^^^^^^^ this call causes read

error. I suppose, that it is an initial "read". Does
it read the whole file at once?

Quoted 6 lines
Quoted 2 lines

The problem is that the command is fromatted in a wrong way.

And we're also passing NULL as the buffer to read into? That also can't be good. I'll spend a little time here and see what's going on.

Quoted 7 lines

OK, I see and have fixed some minor issues here, but without any of these patches, I'm not seeing DFU read work at all for raw. I keep getting "Wrong sequence number!" errors on the U-Boot side. Using dfu-util 0.5 from Ubuntu 12.04 still. I'm inclined to push back and say, after fixing a few calls now that I re-read my code, DFU read is broken and set that aside as another problem to get fixed.

Ok, lets first fix the download (with yours patch series).

The DFU read can be fixed later, for example after Marek sends pull request for u-boot-usb branch.

Anyway thanks for looking into the problem.

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Poland (SRPOL) | Linux Platform Group
#11 lore raw

[U-Boot] Nand flash (supports ONFI)

Hi,

Quoted 3 lines · On Mon, Mar 11, 2013 at 5:06 PM, <[email protected]> wrote:

Hi, experts:
I want to know which specific nand chip supports ONFI interface spec? I have googled , but not find any product manual.

Spansion ML series and Micron MT29F series flashes have onfi read parameter page support.

Thanks,
Jagan.

Quoted 6 lines

Best wishes,
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#12 lore raw

[U-Boot] Nand flash (supports ONFI)

Hi, Jagan:
Got it!
Thank you!
I have downloaded a MT29F16G08A data sheet.

Best wishes,

-----????-----
???: Jagan Teki [mailto:jagannadh.teki at gmail.com] ????: 2013?3?11? 19:56
???: Tiger Liu
??: u-boot at lists.denx.de
??: Re: [U-Boot] Nand flash (supports ONFI)

Hi,

Quoted 3 lines · On Mon, Mar 11, 2013 at 5:06 PM, <[email protected]> wrote:

Hi, experts:
I want to know which specific nand chip supports ONFI interface spec? I have googled , but not find any product manual.

Spansion ML series and Micron MT29F series flashes have onfi read parameter page support.

Thanks,
Jagan.

Quoted 6 lines

Best wishes,
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

author
#13 lore raw

PATCH v5 3/9 dfu: Change indentation of defines in <dfu.h>

In reply to Tom Rini

---
Changes in v5:
- New patch to re-align defines in <dfu.h>

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

 include/dfu.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/dfu.h +2 -2
index 5182c6c..0aae856 100644
@@ -57,8 +57,8 @@ 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
+#define DFU_NAME_SIZE			32
+#define DFU_CMD_BUF_SIZE		128
 #define DFU_DATA_BUF_SIZE		(64 << 10)	/* 64 KiB */
 #ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE
 #define CONFIG_SYS_DFU_MAX_FILE_SIZE	(4 << 20)	/* 4 MiB */
Signature · 1 line
1.7.9.5
author
#14 lore raw

PATCH v5 4/9 nand: Extend nand_(read|write)_skip_bad with *actual and limit parameters

In reply to Tom Rini

We make these two functions take a size_t pointer to how much space was used on NAND to read or write the buffer (when reads/writes happen) so that bad blocks can be accounted for. We also make them take an loff_t limit on how much data can be read or written. This means that we can now catch the case of when writing to a partition would exceed the partition size due to bad blocks. To do this we also need to make check_skip_len count not just complete blocks used but partial ones as well. All callers of nand_(read|write)_skip_bad are adjusted to call these with the most sensible limits available.

The changes were started by Pantelis and finished by Tom.

---
Changes in v5: None
Changes in v4:
- Further reword nand_util.c comments, from Scott
- In nand_write_skip_bad make sure *actual is 0 for YAFFS2 errors too, reminded by Scott.
- In cmd_nand.c don't drop the size is less than maxsize check in arg_off_size as other nand functions need this still (Scott).

Changes in v3:
- Reworked skip_check_len changes to just add accounting for *used to the logic.
- Allow for actual to be NULL in nand_(read|write)_skip_bad, only DFU calls this with a non-NULL parameter. Make sure the comments for both functions explain the parameters and their behavior.
- Other style changes requested by Scott.
- As nand_(write|read)_skip_bad passes back just a used length now.

Changes in v2:
- NAND skip_check_len changes reworked to allow nand_(read|write)_skip_bad to return this information to the caller.

 common/cmd_nand.c            |   53 ++++++++++++++++++--------------
 common/env_nand.c            |    3 +-
 drivers/mtd/nand/nand_util.c |   68 +++++++++++++++++++++++++++++++++++++-----
 include/nand.h               |    4 +--
 4 files changed, 95 insertions(+), 33 deletions(-)
common/cmd_nand.c +31 -22
index 32348f3..76f4d3f 100644
@@ -137,7 +137,8 @@ static inline int str2long(const char *p, ulong *num)
 	return *p != '\0' && *endptr == '\0';
 }
 
-static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size)
+static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size,
+		loff_t *maxsize)
 {
 #ifdef CONFIG_CMD_MTDPARTS
 	struct mtd_device *dev;
@@ -160,6 +161,7 @@ static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size)
 
 	*off = part->offset;
 	*size = part->size;
+	*maxsize = part->size;
 	*idx = dev->id->num;
 
 	ret = set_dev(*idx);
@@ -173,10 +175,11 @@ static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size)
 #endif
 }
 
-static int arg_off(const char *arg, int *idx, loff_t *off, loff_t *maxsize)
+static int arg_off(const char *arg, int *idx, loff_t *off, loff_t *size,
+		loff_t *maxsize)
 {
 	if (!str2off(arg, off))
-		return get_part(arg, idx, off, maxsize);
+		return get_part(arg, idx, off, size, maxsize);
 
 	if (*off >= nand_info[*idx].size) {
 		puts("Offset exceeds device limit\n");
@@ -184,36 +187,35 @@ static int arg_off(const char *arg, int *idx, loff_t *off, loff_t *maxsize)
 	}
 
 	*maxsize = nand_info[*idx].size - *off;
+	*size = *maxsize;
 	return 0;
 }
 
 static int arg_off_size(int argc, char *const argv[], int *idx,
-			loff_t *off, loff_t *size)
+			loff_t *off, loff_t *size, loff_t *maxsize)
 {
 	int ret;
-	loff_t maxsize = 0;
 
 	if (argc == 0) {
 		*off = 0;
 		*size = nand_info[*idx].size;
+		*maxsize = *size;
 		goto print;
 	}
 
-	ret = arg_off(argv[0], idx, off, &maxsize);
+	ret = arg_off(argv[0], idx, off, size, maxsize);
 	if (ret)
 		return ret;
 
-	if (argc == 1) {
-		*size = maxsize;
+	if (argc == 1)
 		goto print;
-	}
 
 	if (!str2off(argv[1], size)) {
 		printf("'%s' is not a number\n", argv[1]);
 		return -1;
 	}
 
-	if (*size > maxsize) {
+	if (*size > *maxsize) {
 		puts("Size exceeds partition or device limit\n");
 		return -1;
 	}
@@ -307,7 +309,8 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[])
 		if (argc < 3)
 			goto usage;
 
-		if (arg_off(argv[2], &idx, &addr, &maxsize)) {
+		/* We don't care about size, or maxsize. */
+		if (arg_off(argv[2], &idx, &addr, &maxsize, &maxsize)) {
 			puts("Offset or partition name expected\n");
 			return 1;
 		}
@@ -426,7 +429,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	int i, ret = 0;
 	ulong addr;
-	loff_t off, size;
+	loff_t off, size, maxsize;
 	char *cmd, *s;
 	nand_info_t *nand;
 #ifdef CONFIG_SYS_NAND_QUIET
@@ -551,7 +554,8 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 		printf("\nNAND %s: ", cmd);
 		/* skip first two or three arguments, look for offset and size */
-		if (arg_off_size(argc - o, argv + o, &dev, &off, &size) != 0)
+		if (arg_off_size(argc - o, argv + o, &dev, &off, &size,
+					&maxsize) != 0)
 			return 1;
 
 		nand = &nand_info[dev];
@@ -619,7 +623,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (s && !strcmp(s, ".raw")) {
 			raw = 1;
 
-			if (arg_off(argv[3], &dev, &off, &size))
+			if (arg_off(argv[3], &dev, &off, &size, &maxsize))
 				return 1;
 
 			if (argc > 4 && !str2long(argv[4], &pagecount)) {
@@ -635,7 +639,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			rwsize = pagecount * (nand->writesize + nand->oobsize);
 		} else {
 			if (arg_off_size(argc - 3, argv + 3, &dev,
-						&off, &size) != 0)
+						&off, &size, &maxsize) != 0)
 				return 1;
 
 			rwsize = size;
@@ -645,9 +649,11 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		    !strcmp(s, ".e") || !strcmp(s, ".i")) {
 			if (read)
 				ret = nand_read_skip_bad(nand, off, &rwsize,
+							 NULL, maxsize,
 							 (u_char *)addr);
 			else
 				ret = nand_write_skip_bad(nand, off, &rwsize,
+							  NULL, maxsize,
 							  (u_char *)addr, 0);
 #ifdef CONFIG_CMD_NAND_TRIMFFS
 		} else if (!strcmp(s, ".trimffs")) {
@@ -655,8 +661,8 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 				printf("Unknown nand command suffix '%s'\n", s);
 				return 1;
 			}
-			ret = nand_write_skip_bad(nand, off, &rwsize,
-						(u_char *)addr,
+			ret = nand_write_skip_bad(nand, off, &rwsize, NULL,
+						maxsize, (u_char *)addr,
 						WITH_DROP_FFS);
 #endif
 #ifdef CONFIG_CMD_NAND_YAFFS
@@ -665,8 +671,8 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 				printf("Unknown nand command suffix '%s'.\n", s);
 				return 1;
 			}
-			ret = nand_write_skip_bad(nand, off, &rwsize,
-						(u_char *)addr,
+			ret = nand_write_skip_bad(nand, off, &rwsize, NULL,
+						maxsize, (u_char *)addr,
 						WITH_INLINE_OOB);
 #endif
 		} else if (!strcmp(s, ".oob")) {
@@ -775,7 +781,8 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (s && !strcmp(s, ".allexcept"))
 			allexcept = 1;
 
-		if (arg_off_size(argc - 2, argv + 2, &dev, &off, &size) < 0)
+		if (arg_off_size(argc - 2, argv + 2, &dev, &off, &size,
+					&maxsize) < 0)
 			return 1;
 
 		if (!nand_unlock(&nand_info[dev], off, size, allexcept)) {
@@ -873,7 +880,8 @@ static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
 	printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset);
 
 	cnt = nand->writesize;
-	r = nand_read_skip_bad(nand, offset, &cnt, (u_char *) addr);
+	r = nand_read_skip_bad(nand, offset, &cnt, NULL, nand->size,
+			(u_char *) addr);
 	if (r) {
 		puts("** Read error\n");
 		bootstage_error(BOOTSTAGE_ID_NAND_HDR_READ);
@@ -905,7 +913,8 @@ static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
 	}
 	bootstage_mark(BOOTSTAGE_ID_NAND_TYPE);
 
-	r = nand_read_skip_bad(nand, offset, &cnt, (u_char *) addr);
+	r = nand_read_skip_bad(nand, offset, &cnt, NULL, nand->size,
+			(u_char *) addr);
 	if (r) {
 		puts("** Read error\n");
 		bootstage_error(BOOTSTAGE_ID_NAND_READ);
common/env_nand.c +2 -1
index 5b69889..b745822 100644
@@ -281,7 +281,8 @@ int readenv(size_t offset, u_char *buf)
 		} else {
 			char_ptr = &buf[amount_loaded];
 			if (nand_read_skip_bad(&nand_info[0], offset,
-					       &len, char_ptr))
+					       &len, NULL,
+					       nand_info[0].size, char_ptr))
 				return 1;
 
 			offset += blocksize;
drivers/mtd/nand/nand_util.c +60 -8

151 lines not on this page · raw message

include/nand.h +2 -2
index dded4e2..f0f3bf9 100644
@@ -129,7 +129,7 @@ struct nand_erase_options {
 typedef struct nand_erase_options nand_erase_options_t;
 
 int nand_read_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
-		       u_char *buffer);
+		       size_t *actual, loff_t lim, u_char *buffer);
 
 #define WITH_YAFFS_OOB	(1 << 0) /* whether write with yaffs format. This flag
 				  * is a 'mode' meaning it cannot be mixed with
@@ -137,7 +137,7 @@ int nand_read_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
 #define WITH_DROP_FFS	(1 << 1) /* drop trailing all-0xff pages */
 
 int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
-			u_char *buffer, int flags);
+			size_t *actual, loff_t lim, u_char *buffer, int flags);
 int nand_erase_opts(nand_info_t *meminfo, const nand_erase_options_t *opts);
 int nand_torture(nand_info_t *nand, loff_t offset);
 
Signature · 1 line
1.7.9.5
#15 lore raw

PATCH v5 4/9 nand: Extend nand_(read|write)_skip_bad with *actual and limit parameters

Quoted 38 lines · Tom Rini

We make these two functions take a size_t pointer to how much space was used on NAND to read or write the buffer (when reads/writes happen)
so that bad blocks can be accounted for. We also make them take an loff_t limit on how much data can be read or written. This means that we can now catch the case of when writing to a partition would exceed the partition size due to bad blocks. To do this we also need to make check_skip_len count not just complete blocks used but partial ones as well. All callers of nand_(read|write)_skip_bad are adjusted to call these with the most sensible limits available.

The changes were started by Pantelis and finished by Tom.

---
Changes in v5: None
Changes in v4:
- Further reword nand_util.c comments, from Scott
- In nand_write_skip_bad make sure *actual is 0 for YAFFS2 errors too, reminded by Scott.
- In cmd_nand.c don't drop the size is less than maxsize check in arg_off_size as other nand functions need this still (Scott).

Changes in v3:
- Reworked skip_check_len changes to just add accounting for *used to the logic.
- Allow for actual to be NULL in nand_(read|write)_skip_bad, only DFU calls this with a non-NULL parameter. Make sure the comments for
both
functions explain the parameters and their behavior.
- Other style changes requested by Scott.
- As nand_(write|read)_skip_bad passes back just a used length now.

Changes in v2:
- NAND skip_check_len changes reworked to allow nand_(read|write)_skip_bad to return this information to the caller.

Quoted 6 lines
 common/cmd_nand.c            |   53 ++++++++++++++++++--------------
 common/env_nand.c            |    3 +-
 drivers/mtd/nand/nand_util.c |   68  
+++++++++++++++++++++++++++++++++++++-----
 include/nand.h               |    4 +--
 4 files changed, 95 insertions(+), 33 deletions(-)

-Scott

author
#16 lore raw

PATCH v5 5/9 cmd_nand.c: Fix CONFIG_CMD_NAND_YAFFS

In reply to Tom Rini

The flag changed from WITH_INLINE_OOB to WITH_YAFFS_OOB by accident in 418396e.

---
Changes in v5: None
Changes in v4:
- Add patch to fix CONFIG_CMD_NAND_YAFFS

Changes in v3: None
Changes in v2: None

 common/cmd_nand.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/cmd_nand.c +1 -1
index 76f4d3f..d9010d2 100644
@@ -673,7 +673,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			}
 			ret = nand_write_skip_bad(nand, off, &rwsize, NULL,
 						maxsize, (u_char *)addr,
-						WITH_INLINE_OOB);
+						WITH_YAFFS_OOB);
 #endif
 		} else if (!strcmp(s, ".oob")) {
 			/* out-of-band data */
Signature · 1 line
1.7.9.5
author
#17 lore raw

PATCH v5 6/9 dfu: NAND specific routines for DFU operation

In reply to Tom Rini

From: Pantelis Antoniou <[email protected]>

Support for NAND storage devices to work with the DFU framework.

---
Changes in v5:
- Document CONFIG_DFU_NAND in README

Changes in v4: None
Changes in v3:
- Rework logic in nand_block_op for nand_(read|write)_skip_bad returning just a size for actual used length.
- Remove unused externs from drivers/dfu/dfu_nand.c

Changes in v2:
- nand_block_op calls nand_(read|write)_skip_bad directly.
- Bugfix in dfu_nand to make sure we set dfu->skip_bad to 0 on each iteration.

 README                 |    3 +
 drivers/dfu/Makefile   |    1 +
 drivers/dfu/dfu.c      |    8 ++
 drivers/dfu/dfu_nand.c |  195 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/dfu.h          |   23 ++++++
 5 files changed, 230 insertions(+)
 create mode 100644 drivers/dfu/dfu_nand.c
README +3 -0
index 154b82f..c70251e 100644
@@ -1338,6 +1338,9 @@ The following options need to be configured:
 		CONFIG_DFU_MMC
 		This enables support for exposing (e)MMC devices via DFU.
 
+		CONFIG_DFU_NAND
+		This enables support for exposing NAND devices via DFU.
+
 		CONFIG_SYS_DFU_MAX_FILE_SIZE
 		When updating files rather than the raw storage device,
 		we use a static buffer to copy the file into and then write
drivers/dfu/Makefile +1 -0
index 7b717bc..153095d 100644
@@ -27,6 +27,7 @@ LIB	= $(obj)libdfu.o
 
 COBJS-$(CONFIG_DFU_FUNCTION) += dfu.o
 COBJS-$(CONFIG_DFU_MMC) += dfu_mmc.o
+COBJS-$(CONFIG_DFU_NAND) += dfu_nand.o
 
 SRCS    := $(COBJS-y:.o=.c)
 OBJS	:= $(addprefix $(obj),$(COBJS-y))
drivers/dfu/dfu.c +8 -0
index 2fecf77..84139bd 100644
@@ -86,6 +86,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
 		/* initial state */
 		dfu->crc = 0;
 		dfu->offset = 0;
+		dfu->bad_skip = 0;
 		dfu->i_blk_seq_num = 0;
 		dfu->i_buf_start = dfu_buf;
 		dfu->i_buf_end = dfu_buf + sizeof(dfu_buf);
@@ -235,6 +236,8 @@ int dfu_read(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
 		dfu->i_buf = dfu->i_buf_start;
 		dfu->b_left = 0;
 
+		dfu->bad_skip = 0;
+
 		dfu->inited = 1;
 	}
 
@@ -264,6 +267,8 @@ int dfu_read(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
 		dfu->i_buf = dfu->i_buf_start;
 		dfu->b_left = 0;
 
+		dfu->bad_skip = 0;
+
 		dfu->inited = 0;
 	}
 
@@ -286,6 +291,9 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
 	if (strcmp(interface, "mmc") == 0) {
 		if (dfu_fill_entity_mmc(dfu, s))
 			return -1;
+	} else if (strcmp(interface, "nand") == 0) {
+		if (dfu_fill_entity_nand(dfu, s))
+			return -1;
 	} else {
 		printf("%s: Device %s not (yet) supported!\n",
 		       __func__,  interface);
drivers/dfu/dfu_nand.c new file +195 -0

195 lines not on this page · raw message

include/dfu.h +23 -0
index 0aae856..e856a37 100644
@@ -52,6 +52,15 @@ struct mmc_internal_data {
 	unsigned int part;
 };
 
+struct nand_internal_data {
+	/* RAW programming */
+	u64 start;
+	u64 size;
+
+	unsigned int dev;
+	unsigned int part;
+};
+
 static inline unsigned int get_mmc_blk_size(int dev)
 {
 	return find_mmc_device(dev)->read_bl_len;
@@ -74,6 +83,7 @@ struct dfu_entity {
 
 	union {
 		struct mmc_internal_data mmc;
+		struct nand_internal_data nand;
 	} data;
 
 	int (*read_medium)(struct dfu_entity *dfu,
@@ -96,6 +106,8 @@ struct dfu_entity {
 	long r_left;
 	long b_left;
 
+	u32 bad_skip;	/* for nand use */
+
 	unsigned int inited:1;
 };
 
@@ -120,4 +132,15 @@ static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
 	return -1;
 }
 #endif
+
+#ifdef CONFIG_DFU_NAND
+extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s);
+#else
+static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s)
+{
+	puts("NAND support not available!\n");
+	return -1;
+}
+#endif
+
 #endif /* __DFU_ENTITY_H_ */
Signature · 1 line
1.7.9.5
#18 lore raw

PATCH v5 6/9 dfu: NAND specific routines for DFU operation

Quoted 178 lines · Tom Rini

From: Pantelis Antoniou <[email protected]>

Support for NAND storage devices to work with the DFU framework.

---
Changes in v5:
- Document CONFIG_DFU_NAND in README

Changes in v4: None
Changes in v3:
- Rework logic in nand_block_op for nand_(read|write)_skip_bad returning
just a size for actual used length.
- Remove unused externs from drivers/dfu/dfu_nand.c

Changes in v2:
- nand_block_op calls nand_(read|write)_skip_bad directly.
- Bugfix in dfu_nand to make sure we set dfu->skip_bad to 0 on each iteration.

 README                 |    3 +
 drivers/dfu/Makefile   |    1 +
 drivers/dfu/dfu.c      |    8 ++
 drivers/dfu/dfu_nand.c |  195  
++++++++++++++++++++++++++++++++++++++++++++++++
 include/dfu.h          |   23 ++++++
 5 files changed, 230 insertions(+)
 create mode 100644 drivers/dfu/dfu_nand.c
README +0 -0
index 154b82f..c70251e 100644
@@ -1338,6 +1338,9 @@ The following options need to be configured:
 		CONFIG_DFU_MMC
 		This enables support for exposing (e)MMC devices via  

DFU.

README +3 -0
+		CONFIG_DFU_NAND
+		This enables support for exposing NAND devices via DFU.
+
 		CONFIG_SYS_DFU_MAX_FILE_SIZE
 		When updating files rather than the raw storage device,
 		we use a static buffer to copy the file into and then  

write

drivers/dfu/Makefile +1 -0
index 7b717bc..153095d 100644
@@ -27,6 +27,7 @@ LIB	= $(obj)libdfu.o
 
 COBJS-$(CONFIG_DFU_FUNCTION) += dfu.o
 COBJS-$(CONFIG_DFU_MMC) += dfu_mmc.o
+COBJS-$(CONFIG_DFU_NAND) += dfu_nand.o
 
 SRCS    := $(COBJS-y:.o=.c)
 OBJS	:= $(addprefix $(obj),$(COBJS-y))
drivers/dfu/dfu.c +1 -0
index 2fecf77..84139bd 100644
@@ -86,6 +86,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf,  
 int size, int blk_seq_num)
 		/* initial state */
 		dfu->crc = 0;
 		dfu->offset = 0;
+		dfu->bad_skip = 0;
 		dfu->i_blk_seq_num = 0;
 		dfu->i_buf_start = dfu_buf;
drivers/dfu/dfu.c +7 -0
 		dfu->i_buf_end = dfu_buf + sizeof(dfu_buf);
@@ -235,6 +236,8 @@ int dfu_read(struct dfu_entity *dfu, void *buf,  
 int size, int blk_seq_num)
 		dfu->i_buf = dfu->i_buf_start;
 		dfu->b_left = 0;
 
+		dfu->bad_skip = 0;
+
 		dfu->inited = 1;
 	}
@@ -264,6 +267,8 @@ int dfu_read(struct dfu_entity *dfu, void *buf,  
 int size, int blk_seq_num)
 		dfu->i_buf = dfu->i_buf_start;
 		dfu->b_left = 0;
 
+		dfu->bad_skip = 0;
+
 		dfu->inited = 0;
 	}
@@ -286,6 +291,9 @@ static int dfu_fill_entity(struct dfu_entity  
 *dfu, char *s, int alt,
 	if (strcmp(interface, "mmc") == 0) {
 		if (dfu_fill_entity_mmc(dfu, s))
 			return -1;
+	} else if (strcmp(interface, "nand") == 0) {
+		if (dfu_fill_entity_nand(dfu, s))
+			return -1;
 	} else {
 		printf("%s: Device %s not (yet) supported!\n",
drivers/dfu/dfu.c +0 -0
 		       __func__,  interface);
drivers/dfu/dfu_nand.c new file +10 -0
new file mode 100644
index 0000000..b7f60dd
@@ -0,0 +1,195 @@
+/*
+ * dfu_nand.c -- DFU for NAND routines.
+ *
+ * Copyright (C) 2012-2013 Texas Instruments, Inc.
+ *
+ * Based on dfu_mmc.c which is:
+ * Copyright (C) 2012 Samsung Electronics
+ * author: Lukasz Majewski <[email protected]>
+ *
+ * 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
+ */

drivers/dfu/dfu_nand.c new file +43 -0
+
+#include <common.h>
+#include <malloc.h>
+#include <errno.h>
+#include <div64.h>
+#include <dfu.h>
+#include <linux/mtd/mtd.h>
+#include <jffs2/load_kernel.h>
+#include <nand.h>
+
+enum dfu_nand_op {
+	DFU_OP_READ = 1,
+	DFU_OP_WRITE,
+};
+
+static int nand_block_op(enum dfu_nand_op op, struct dfu_entity *dfu,
+			u64 offset, void *buf, long *len)
+{
+	loff_t start;
+	size_t count, actual;
+	int ret;
+	int dev;
+	nand_info_t *nand;
+
+	/* if buf == NULL return total size of the area */
+	if (buf == NULL) {
+		*len = dfu->data.nand.size;
+		return 0;
+	}
+
+	start = dfu->data.nand.start + offset + dfu->bad_skip;
+	count = *len;
+	if (start + count >
+			dfu->data.nand.start + dfu->data.nand.size) {
+		printf("%s: block_op out of bounds\n", __func__);
+		return -1;
+	}
+
+	dev = nand_curr_device;
+	if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
+		!nand_info[dev].name) {
+		printf("%s: invalid nand device\n", __func__);
+		return -1;

drivers/dfu/dfu_nand.c line 76

Quoted 10 lines
drivers/dfu/dfu_nand.c new file +10 -0
+	}
+
+	nand = &nand_info[dev];
+
+	if (op == DFU_OP_READ)
+		ret = nand_read_skip_bad(nand, start, &count, &actual,
+				nand->size, buf);
+	else
+		ret = nand_write_skip_bad(nand, start, &count, &actual,
+				nand->size, buf, 0);

Shouldn't "lim" be "dfu->data.nand.start + dfu->data.nand.size - start"?

This should let you get rid of the bounds check above, which doesn't factor in bad blocks that have yet to be encountered.

Quoted 18 lines
drivers/dfu/dfu_nand.c new file +3 -0
+	if (ret != 0) {
+		printf("%s: nand_%s_skip_bad call failed at %llx!\n",
+				__func__, op == DFU_OP_READ ? "read" :  

"write",

drivers/dfu/dfu_nand.c new file +6 -0
+				start);
+		return ret;
+	}
+
+	/*
+	 * Find out where we stopped writing data.  This can be deeper  

into

drivers/dfu/dfu_nand.c new file +1 -0
+	 * the NAND than we expected due to having to skip bad blocks.   

So

drivers/dfu/dfu_nand.c new file +4 -0
+	 * we must take this into account for the next write, if any.
+	 */
+	if (actual > count) {
+		printf("%s: skipped 0x%x bad bytes at 0x%llx\n",  

__func__,

drivers/dfu/dfu_nand.c line 94

Quoted 3 lines
drivers/dfu/dfu_nand.c new file +3 -0
+				actual - count, start);
+		dfu->bad_skip += actual - count;
+	}

Hmm, the message suggests the bad blocks are at "start" rather than somewhere between "start" and "start + actual".

nand_write_skip_bad() already prints a message when actually skipping the block, so you probably don't need any print here.

-Scott

author
#19 lore raw

PATCH v5 6/9 dfu: NAND specific routines for DFU operation

Quoted 190 lines · Scott Wood
Quoted 176 lines · Tom Rini

From: Pantelis Antoniou <[email protected]>

Support for NAND storage devices to work with the DFU framework.

---
Changes in v5:
- Document CONFIG_DFU_NAND in README

Changes in v4: None
Changes in v3:
- Rework logic in nand_block_op for nand_(read|write)_skip_bad returning
just a size for actual used length.
- Remove unused externs from drivers/dfu/dfu_nand.c

Changes in v2:
- nand_block_op calls nand_(read|write)_skip_bad directly.
- Bugfix in dfu_nand to make sure we set dfu->skip_bad to 0 on each iteration.

README                 |    3 +
drivers/dfu/Makefile   |    1 +
drivers/dfu/dfu.c      |    8 ++
drivers/dfu/dfu_nand.c |  195
++++++++++++++++++++++++++++++++++++++++++++++++
include/dfu.h          |   23 ++++++
5 files changed, 230 insertions(+)

create mode 100644 drivers/dfu/dfu_nand.c

README +3 -0
index 154b82f..c70251e 100644
@@ -1338,6 +1338,9 @@ The following options need to be configured:
 		CONFIG_DFU_MMC
 		This enables support for exposing (e)MMC devices via DFU.
 
+		CONFIG_DFU_NAND
+		This enables support for exposing NAND devices via DFU.
+
 		CONFIG_SYS_DFU_MAX_FILE_SIZE
 		When updating files rather than the raw storage device,
 		we use a static buffer to copy the file into and then write
drivers/dfu/Makefile +0 -0
index 7b717bc..153095d 100644
@@ -27,6 +27,7 @@ LIB	= $(obj)libdfu.o
 

COBJS-$(CONFIG_DFU_FUNCTION) += dfu.o
COBJS-$(CONFIG_DFU_MMC) += dfu_mmc.o
+COBJS-$(CONFIG_DFU_NAND) += dfu_nand.o

SRCS := $(COBJS-y:.o=.c)
OBJS := $(addprefix $(obj),$(COBJS-y))

drivers/dfu/dfu.c +1 -0
index 2fecf77..84139bd 100644
@@ -86,6 +86,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf,
 int size, int blk_seq_num)
 		/* initial state */
 		dfu->crc = 0;
 		dfu->offset = 0;
+		dfu->bad_skip = 0;
 		dfu->i_blk_seq_num = 0;
 		dfu->i_buf_start = dfu_buf;
		dfu->i_buf_end = dfu_buf + sizeof(dfu_buf);
drivers/dfu/dfu.c +7 -0
@@ -235,6 +236,8 @@ int dfu_read(struct dfu_entity *dfu, void
 *buf, int size, int blk_seq_num)
 		dfu->i_buf = dfu->i_buf_start;
 		dfu->b_left = 0;
 
+		dfu->bad_skip = 0;
+
 		dfu->inited = 1;
 	}
@@ -264,6 +267,8 @@ int dfu_read(struct dfu_entity *dfu, void
 *buf, int size, int blk_seq_num)
 		dfu->i_buf = dfu->i_buf_start;
 		dfu->b_left = 0;
 
+		dfu->bad_skip = 0;
+
 		dfu->inited = 0;
 	}
@@ -286,6 +291,9 @@ static int dfu_fill_entity(struct dfu_entity
 *dfu, char *s, int alt,
 	if (strcmp(interface, "mmc") == 0) {
 		if (dfu_fill_entity_mmc(dfu, s))
 			return -1;
+	} else if (strcmp(interface, "nand") == 0) {
+		if (dfu_fill_entity_nand(dfu, s))
+			return -1;
 	} else {
 		printf("%s: Device %s not (yet) supported!\n",
		       __func__,  interface);
drivers/dfu/dfu_nand.c new file +10 -0
new file mode 100644
index 0000000..b7f60dd
@@ -0,0 +1,195 @@
+/*
+ * dfu_nand.c -- DFU for NAND routines.
+ *
+ * Copyright (C) 2012-2013 Texas Instruments, Inc.
+ *
+ * Based on dfu_mmc.c which is:
+ * Copyright (C) 2012 Samsung Electronics
+ * author: Lukasz Majewski <[email protected]>
+ *
+ * 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
+ */

drivers/dfu/dfu_nand.c new file +43 -0
+
+#include <common.h>
+#include <malloc.h>
+#include <errno.h>
+#include <div64.h>
+#include <dfu.h>
+#include <linux/mtd/mtd.h>
+#include <jffs2/load_kernel.h>
+#include <nand.h>
+
+enum dfu_nand_op {
+	DFU_OP_READ = 1,
+	DFU_OP_WRITE,
+};
+
+static int nand_block_op(enum dfu_nand_op op, struct dfu_entity *dfu,
+			u64 offset, void *buf, long *len)
+{
+	loff_t start;
+	size_t count, actual;
+	int ret;
+	int dev;
+	nand_info_t *nand;
+
+	/* if buf == NULL return total size of the area */
+	if (buf == NULL) {
+		*len = dfu->data.nand.size;
+		return 0;
+	}
+
+	start = dfu->data.nand.start + offset + dfu->bad_skip;
+	count = *len;
+	if (start + count >
+			dfu->data.nand.start + dfu->data.nand.size) {
+		printf("%s: block_op out of bounds\n", __func__);
+		return -1;
+	}
+
+	dev = nand_curr_device;
+	if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
+		!nand_info[dev].name) {
+		printf("%s: invalid nand device\n", __func__);
+		return -1;

drivers/dfu/dfu_nand.c line 76

Quoted 10 lines
drivers/dfu/dfu_nand.c new file +10 -0
+	}
+
+	nand = &nand_info[dev];
+
+	if (op == DFU_OP_READ)
+		ret = nand_read_skip_bad(nand, start, &count, &actual,
+				nand->size, buf);
+	else
+		ret = nand_write_skip_bad(nand, start, &count, &actual,
+				nand->size, buf, 0);

Shouldn't "lim" be "dfu->data.nand.start + dfu->data.nand.size - start"?

Quoted 2 lines

This should let you get rid of the bounds check above, which doesn't factor in bad blocks that have yet to be encountered.

Good point, will re-work.

Quoted 23 lines
Quoted 12 lines
drivers/dfu/dfu_nand.c new file +9 -0
+	if (ret != 0) {
+		printf("%s: nand_%s_skip_bad call failed at %llx!\n",
+				__func__, op == DFU_OP_READ ? "read" : "write",
+				start);
+		return ret;
+	}
+
+	/*
+	 * Find out where we stopped writing data.  This can be deeper

into

drivers/dfu/dfu_nand.c new file +1 -0
+	 * the NAND than we expected due to having to skip bad blocks.

So

drivers/dfu/dfu_nand.c line 94

Quoted 7 lines
drivers/dfu/dfu_nand.c new file +7 -0
+	 * we must take this into account for the next write, if any.
+	 */
+	if (actual > count) {
+		printf("%s: skipped 0x%x bad bytes at 0x%llx\n", __func__,
+				actual - count, start);
+		dfu->bad_skip += actual - count;
+	}

Hmm, the message suggests the bad blocks are at "start" rather than somewhere between "start" and "start + actual".

Quoted 2 lines

nand_write_skip_bad() already prints a message when actually skipping the block, so you probably don't need any print here.

OK, I'll just drop that. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130313/044180dd/attachment.pgp>
author
#20 lore raw

PATCH v5 7/9 am335x_evm: Define CONFIG_SYS_CACHELINE_SIZE

In reply to Tom Rini

From: Pantelis Antoniou <[email protected]>

drivers/usb/gadget/composite.c requires that this is defined early.

---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 include/configs/am335x_evm.h |    2 ++
 1 file changed, 2 insertions(+)
include/configs/am335x_evm.h +2 -0
index 33ee2c4..59647d1 100644
@@ -39,6 +39,8 @@
 #define CONFIG_SETUP_MEMORY_TAGS
 #define CONFIG_INITRD_TAG
 
+#define CONFIG_SYS_CACHELINE_SIZE       64
+
 /* commands to include */
 #include <config_cmd_default.h>
 
Signature · 1 line
1.7.9.5
author
#21 lore raw

PATCH v5 8/9 am335x_evm: Add CONFIG_CMD_MTDPARTS and relevant defaults

In reply to Tom Rini

---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
- Add CONFIG_CMD_MTDPARTS and relevant information to am335x_evm

 include/configs/am335x_evm.h |    9 +++++++++
 1 file changed, 9 insertions(+)
include/configs/am335x_evm.h +9 -0
index 59647d1..61b861d 100644
@@ -60,6 +60,8 @@
 	"fdtfile=\0" \
 	"console=ttyO0,115200n8\0" \
 	"optargs=\0" \
+	"mtdids=" MTDIDS_DEFAULT "\0" \
+	"mtdparts=" MTDPARTS_DEFAULT "\0" \
 	"mmcdev=0\0" \
 	"mmcroot=/dev/mmcblk0p2 ro\0" \
 	"mmcrootfstype=ext4 rootwait\0" \
@@ -341,6 +343,13 @@
 /* NAND support */
 #ifdef CONFIG_NAND
 #define CONFIG_CMD_NAND
+#define CONFIG_CMD_MTDPARTS
+#define MTDIDS_DEFAULT			"nand0=omap2-nand.0"
+#define MTDPARTS_DEFAULT		"mtdparts=omap2-nand.0:128k(SPL)," \
+					"128k(SPL.backup1)," \
+					"128k(SPL.backup2)," \
+					"128k(SPL.backup3),1920k(u-boot)," \
+					"128k(u-boot-env),5m(kernel),-(rootfs)"
 #define CONFIG_NAND_OMAP_GPMC
 #define GPMC_NAND_ECC_LP_x16_LAYOUT	1
 #define CONFIG_SYS_NAND_BASE		(0x08000000)	/* physical address */
Signature · 1 line
1.7.9.5
author
#22 lore raw

PATCH v5 9/9 am335x_evm: Enable DFU for NAND and MMC, provide example alt_infos

In reply to Tom Rini

From: Pantelis Antoniou <[email protected]>

- Add CONFIG_DFU_NAND, CONFIG_DFU_MMC
- Set dfu_alt_info_nand, dfu_alt_info_emmc and dfu_alt_info_mmc to show working examples for those cases.
- Increase CONFIG_SYS_MAXARGS due to hush parsing bugs that would otherwise disallow 'setenv dfu_alt_info ${dfu_alt_info_nand}'.
- Enable CONFIG_FAT_WRITE to allow updating on MMC

---
Changes in v5:
- Add RAW MMC examples to include/configs/am335x_evm.h

Changes in v4: None
Changes in v3:
- Fix checkpatch.pl warnings in include/configs/am335x_evm.h

Changes in v2:
- Enable DFU for NAND and MMC, set dfu_alt_info_(nand|mmc) as examples for both in am335x_evm.h
- Increase CONFIG_SYS_MAXARGS due to hush parsing bugs that would otherwise prevent 'setenv dfu_alt_info ${dfu_alt_info_nand}' on am335x_evm

 include/configs/am335x_evm.h |   41 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)
include/configs/am335x_evm.h +39 -2
index 61b861d..6b487c2 100644
@@ -62,6 +62,9 @@
 	"optargs=\0" \
 	"mtdids=" MTDIDS_DEFAULT "\0" \
 	"mtdparts=" MTDPARTS_DEFAULT "\0" \
+	"dfu_alt_info_mmc=" DFU_ALT_INFO_MMC "\0" \
+	"dfu_alt_info_emmc=rawemmc mmc 0 3751936\0" \
+	"dfu_alt_info_nand=" DFU_ALT_INFO_NAND "\0" \
 	"mmcdev=0\0" \
 	"mmcroot=/dev/mmcblk0p2 ro\0" \
 	"mmcrootfstype=ext4 rootwait\0" \
@@ -118,8 +121,8 @@
 
 #define CONFIG_CMD_ECHO
 
-/* max number of command args */
-#define CONFIG_SYS_MAXARGS		16
+/* We set the max number of command args high to avoid HUSH bugs. */
+#define CONFIG_SYS_MAXARGS		64
 
 /* Console I/O Buffer Size */
 #define CONFIG_SYS_CBSIZE		512
@@ -148,6 +151,7 @@
 #define CONFIG_CMD_MMC
 #define CONFIG_DOS_PARTITION
 #define CONFIG_CMD_FAT
+#define CONFIG_FAT_WRITE
 #define CONFIG_CMD_EXT2
 
 #define CONFIG_SPI
@@ -158,6 +162,38 @@
 #define CONFIG_CMD_SF
 #define CONFIG_SF_DEFAULT_SPEED		(24000000)
 
+/* USB Composite download gadget - g_dnl */
+#define CONFIG_USB_GADGET
+#define CONFIG_USBDOWNLOAD_GADGET
+
+/* USB TI's IDs */
+#define CONFIG_USBD_HS
+#define CONFIG_G_DNL_VENDOR_NUM 0x0403
+#define CONFIG_G_DNL_PRODUCT_NUM 0xBD00
+#define CONFIG_G_DNL_MANUFACTURER "Texas Instruments"
+
+/* USB Device Firmware Update support */
+#define CONFIG_DFU_FUNCTION
+#define CONFIG_DFU_MMC
+#define CONFIG_DFU_NAND
+#define CONFIG_CMD_DFU
+#define DFU_ALT_INFO_MMC \
+	"boot part 0 1;" \
+	"rootfs part 0 2;" \
+	"MLO fat 0 1;" \
+	"MLO.raw mmc 100 100;" \
+	"u-boot.img.raw mmc 300 3C0;" \
+	"u-boot.img fat 0 1;" \
+	"uEnv.txt fat 0 1"
+#define DFU_ALT_INFO_NAND \
+	"SPL part 0 1;" \
+	"SPL.backup1 part 0 2;" \
+	"SPL.backup2 part 0 3;" \
+	"SPL.backup3 part 0 4;" \
+	"u-boot part 0 5;" \
+	"kernel part 0 7;" \
+	"rootfs part 0 8"
+
  /* Physical Memory Map */
 #define CONFIG_NR_DRAM_BANKS		1		/*  1 bank of DRAM */
 #define PHYS_DRAM_1			0x80000000	/* DRAM Bank #1 */
@@ -302,6 +338,7 @@
 #define CONFIG_MUSB_GADGET
 #define CONFIG_MUSB_PIO_ONLY
 #define CONFIG_USB_GADGET_DUALSPEED
+#define CONFIG_USB_GADGET_VBUS_DRAW	2
 #define CONFIG_MUSB_HOST
 #define CONFIG_AM335X_USB0
 #define CONFIG_AM335X_USB0_MODE	MUSB_PERIPHERAL
Signature · 1 line
1.7.9.5