Skip to contentSkip to conversation

Improve DFU support, enable for am335x_evm

PATCH New Tom Rini 3 participants 15 messages Mar 14, 2013 – Apr 11, 2013

Subsystems (2)
lore
Share & tools
lore

Tom Rini

author
#0 lore raw

v6 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 v6:
- Correct the check for attempting to write out of bounds on RAW MMC.
- Pass correct buffer when reading a file from MMC.
- Drop 1 line helper functions that were called only twice in dfu_mmc.c
- Remove offset from MMC file ops as it was unused.
- Fix checkpatch new checkpatch warnings
- Update dfu_nand.c based on Scott's feedback

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            |  249 +++++++++++++++++++++++++++++++++---------
 drivers/dfu/dfu_mmc.c        |  108 ++++++++++++------
 drivers/dfu/dfu_nand.c       |  187 +++++++++++++++++++++++++++++++
 drivers/mtd/nand/nand_util.c |   68 ++++++++++--
 include/configs/am335x_evm.h |   52 ++++++++-
 include/dfu.h                |   53 ++++++++-
 include/nand.h               |    4 +-
 11 files changed, 674 insertions(+), 129 deletions(-)
 create mode 100644 drivers/dfu/dfu_nand.c
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v6 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 v6: None
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 869694f..648d26e 100644
@@ -1326,6 +1326,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 v6 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 v6:
- Correct the check for attempting to write out of bounds on RAW MMC.
- Pass correct buffer when reading a file from MMC.
- Drop 1 line helper functions that were called only twice in dfu_mmc.c
- Remove offset from MMC file ops as it was unused.
- Fix checkpatch new checkpatch warnings

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     |  243 ++++++++++++++++++++++++++++++++++++++-----------
 drivers/dfu/dfu_mmc.c |  108 ++++++++++++++--------
 include/dfu.h         |   26 +++++-
 4 files changed, 292 insertions(+), 92 deletions(-)
README +7 -0
index 648d26e..b0798c9 100644
@@ -1339,6 +1339,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 +190 -53

280 lines not on this page · raw message

drivers/dfu/dfu_mmc.c +72 -36

194 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
author
#3 lore raw

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

In reply to Tom Rini

---
Changes in v6: None
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
#4 lore raw

PATCH v6 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 v6: None
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..110c78c 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
author
#5 lore raw

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

Quoted 10 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.

Quoted 4 lines

The changes were started by Pantelis and finished by Tom.

With current master, the following changes are needed to adapt cm_t35 to these call changes:

board/cm_t35/cm_t35.c +2 -0
index 629ce4a..84c36ba 100644
@@ -91,6 +91,7 @@ static int splash_load_from_nand(u32 bmp_load_addr)
 
 	res = nand_read_skip_bad(&nand_info[nand_curr_device],
 			splash_screen_nand_offset, &bmp_header_size,
+			NULL, nand_info[nand_curr_device].size,
 			(u_char *)bmp_load_addr);
 	if (res < 0)
 		return res;
@@ -103,6 +104,7 @@ static int splash_load_from_nand(u32 bmp_load_addr)
 
 	return nand_read_skip_bad(&nand_info[nand_curr_device],
 			splash_screen_nand_offset, &bmp_size,
+			NULL, nand_info[nand_curr_device].size,
 			(u_char *)bmp_load_addr);
 
 splash_address_too_high:
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/20130410/f7f4e395/attachment.pgp>
#6 lore raw

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

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

Quoted 12 lines · Tom Rini
Quoted 10 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.

Quoted 7 lines
Quoted 4 lines

The changes were started by Pantelis and finished by Tom.

With current master, the following changes are needed to adapt cm_t35 to these call changes:

I guess, you will squash both patches into one, right?

Quoted 15 lines
board/cm_t35/cm_t35.c +1 -0
index 629ce4a..84c36ba 100644
@@ -91,6 +91,7 @@ static int splash_load_from_nand(u32 bmp_load_addr)
 
 	res = nand_read_skip_bad(&nand_info[nand_curr_device],
 			splash_screen_nand_offset, &bmp_header_size,
+			NULL, nand_info[nand_curr_device].size,
 			(u_char *)bmp_load_addr);
 	if (res < 0)
 		return res;

board/cm_t35/cm_t35.c static int splash_load_from_nand(u32 bmp_load_addr) · line 110

Quoted 7 lines
board/cm_t35/cm_t35.c +1 -0
@@ -103,6 +104,7 @@ static int splash_load_from_nand(u32 bmp_load_addr)
 
 	return nand_read_skip_bad(&nand_info[nand_curr_device],
 			splash_screen_nand_offset, &bmp_size,
+			NULL, nand_info[nand_curr_device].size,
 			(u_char *)bmp_load_addr);
 
 splash_address_too_high:

- --
Regards,
Igor.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRZlo8AAoJEBDE8YO64EfazSoP/1u/f8FQwl7zZDcwlUIWSJPe nsk66wJxMteHKPG9Ib3DGKNW+ncAEfNYWH7Pzqg9rnsp+oWf/bMpTil/qWV0J8Qp QSTC3ez5QOYONBn/Zb8MyOyMcHVnbOFrKiHIR+7zjPhaWWRzVAM7VBxiYS/gtGUY tiK8ccqH9w8r+t4s6fbWZ8WWTX0ZryKcCiGxiNnjFGz5xphsS9+AvTbIL7n2r+ji mie9SD/Lb6GCeEhgYT9XBgo7gjx6Q0RNEXZL5fP+YWpII73KPFzvzzMTRo2jwWxr /vggymfjJ3amAFvMuFuIk3OEbH5CSWKnfX5pwyW2TIZ+GZttiFw040ZurmA6k3f9 LdwhFdgrp0BzRkwC92FLR+aMyV8A8WgFYkMysuqDlJkiaSXLVFlcLB43le6kuuyq uKbRDTMMNiyHncet6znIjgmH3wzYECXlRyAkH7K0mz6DrkmAGraYizUy/XwxK6cr /Zh0rmR0Owg/XZKZRRdhQnwGf/B9+FufNZehgYJlhOFHVFwm9bbHX02k16RD2PP5 P/AgdV8psCR0HvH9dJ+/93Y0r/paIp3PeAAt4nZxMwiHp07cJwqpjwgQUWDjxPkK q3R6H0otAh7cDzE84QotNzeHlR1GuxFU6wQLuTE16EDrGE7BHyMaYjuhRXH9zHek ptNpTuQm5/O7yn6tQHvV
=6ma+
-----END PGP SIGNATURE-----

author
#7 lore raw

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

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

Quoted 16 lines · Igor Grinberg
Quoted 15 lines · Tom Rini
Quoted 13 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.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

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

With current master, the following changes are needed to adapt cm_t35 to these call changes:

I guess, you will squash both patches into one, right?

Yes, Marek already squashed this in as part of his pull request that I need to switch hats and grab.

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

iQIcBAEBAgAGBQJRZqeDAAoJENk4IS6UOR1WLuIP/RWThgn2nc7xMuMA2soKHQQQ rSrF/wAAvVNRV3g0g6qQ7VZ/+IkH8C+cjPhpD/VUVbeodx+0b24kiW1Zfxcpblmw G5cgIMDtAT9prs7upcktjzUwnU/JuZDx0HAfIeA7kWu/hpm2xhe7p3JIID47/sr1 k5Cw+8X+pKYVCt4px68TWhy+gEdKgfvK5rXKVpB4RCLVjTC9hyfmdySo7h6n1M+t JhmuoHRbDmQsB/qVcauZypirO5AidrRU+baak83XBqgQnwTAPy/i6jDOegHYlaou 9rVzpyOpCUDXNEqDNrU9lOslFpSf0NfpRsAsWsvu35AbcA7yMnRR2kNXeOr2Djur sUvWpaLpWYpvhT16GGvk8xyoj6eaA3G+LycBFdTcRZPsdeIfs4/lnjRn0Nreq1jQ CST9w6HyMzBEUhwV4BarPmR4nk1tRwbmX6hfkRbH4iENhG63PYRuX5A18uC8O8uS wCOZo71a2GvOHFvDSNd2Qkscs3A1QC+6jcm9FBbvydzU4NXo9yIFt+QlsWjenhwv MWHsFZX5tBP4U2N/mkkRoaJfrpTW137RqPvxwsqB96JObeafdw0SNGGlks6N7X1Z /83jyM2iEy7icg8e3g+cVTtrJUwAifyZI6wjBGiEV4rxtthLyxNBhm0nerJcXvX+ B8AiXe67JK9wju7t7fRt
=ACw6
-----END PGP SIGNATURE-----

author
#8 lore raw

PATCH v6 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 v6: None
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 110c78c..e9d3d3c 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
#9 lore raw

PATCH v6 5/9 cmd_nand.c: Fix CONFIG_CMD_NAND_YAFFS

Quoted 10 lines · Tom Rini

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

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

Quoted 5 lines

Changes in v3: None
Changes in v2: None

 common/cmd_nand.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-Scott

author
#10 lore raw

PATCH v6 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 v6:
- Update dfu_nand.c based on Scott's feedback

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 |  187 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/dfu.h          |   23 ++++++
 5 files changed, 222 insertions(+)
 create mode 100644 drivers/dfu/dfu_nand.c
README +3 -0
index b0798c9..947a26f 100644
@@ -1339,6 +1339,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 609061d..6af6890 100644
@@ -85,6 +85,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);
@@ -233,6 +234,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;
 	}
 
@@ -262,6 +265,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;
 	}
 
@@ -284,6 +289,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 +187 -0

187 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
#11 lore raw

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

Quoted 25 lines · Tom Rini

From: Pantelis Antoniou <[email protected]>

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

---
Changes in v6:
- Update dfu_nand.c based on Scott's feedback

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.

Quoted 8 lines
 README                 |    3 +
 drivers/dfu/Makefile   |    1 +
 drivers/dfu/dfu.c      |    8 +++
 drivers/dfu/dfu_nand.c |  187  
++++++++++++++++++++++++++++++++++++++++++++++++
 include/dfu.h          |   23 ++++++
 5 files changed, 222 insertions(+)
 create mode 100644 drivers/dfu/dfu_nand.c

-Scott

author
#12 lore raw

PATCH v6 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 v6: None
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
#13 lore raw

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

In reply to Tom Rini

---
Changes in v6: None
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
#14 lore raw

PATCH v6 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 v6: None
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