nand util: read/write: accept unaligned length
Subsystems (2)
PATCH 1/5 nand util: read/write: accept unaligned length
The underlying code in nand_base.c already supports non-page-aligned reads and writes, but the block-skipping wrapper code did not.
With block skipping, an unaligned start address is not useful since you really want to be starting at the beginning of a partition -- or at least that's where you want to start checking for blocks to skip, but we don't (yet) support that. So we still require the start address to be aligned.
An unaligned length, though, is useful for passing $filesize to the read/write command, and handling it does not complicate block skipping.
--- drivers/mtd/nand/nand_base.c | 7 --- drivers/mtd/nand/nand_util.c | 93 ++++++++++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 37 deletions(-)
drivers/mtd/nand/nand_base.c +0 -7
@@ -2001,13 +2001,6 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,if (!writelen)return 0 ; -/* reject writes, which are not page aligned */ -if (NOTALIGNED (to) ||NOTALIGNED (ops->len)) { -printk (KERN_NOTICE "nand_write: " -"Attempt to write not page aligned data\n" ); -return -EINVAL ; - } - column = to & (mtd->writesize -1 ); subpage = column || (writelen & (mtd->writesize -1 ));
drivers/mtd/nand/nand_util.c +63 -30
154 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 1/5 nand util: read/write: accept unaligned length
Quoted 10 lines · Scott Wood
The underlying code in
nand_base.calready supports non-page-aligned reads and writes, but the block-skipping wrapper code did not.With block skipping, an unaligned start address is not useful since you really want to be starting at the beginning of a partition -- or at least that's where you want to start checking for blocks to skip, but we don't (yet) support that. ?So we still require the start address to be aligned.
An unaligned length, though, is useful for passing $filesize to the read/write command, and handling it does not complicate block skipping.
This is a great feature.
Quoted 1 line
Signed-off-by Scott Wood <[email protected]>
applies to 962ad59e25640e586e2bceabf67a628a27f8f508 ofgit://git.denx.de/u-boot.git -- some checkpatch errors.
Tested on da850evm_config with NAND enabled;
Quoted 40 lines
?/**
(quoted diff) +17
-8@@ -474,29 +487,41 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, ?{ ? ? ? ?int rval; ? ? ? ?size_t left_to_write = *length; - ? ? ? size_t len_incl_bad; ? ? ? ?u_char *p_buffer = buffer; + ? ? ? int need_skip; - ? ? ? /* Reject writes, which are not page aligned */ - ? ? ? if ((offset & (nand->writesize - 1)) != 0 || - ? ? ? ? ? (*length & (nand->writesize - 1)) != 0) { + ? ? ? /* + ? ? ? ?* nand_write() handles unaligned, partial page writes. + ? ? ? ?* + ? ? ? ?* We allow length to be unaligned, for convenience in + ? ? ? ?* using the $filesize variable. + ? ? ? ?* + ? ? ? ?* However, starting at an unaligned offset makes the + ? ? ? ?* semantics of bad block skipping ambiguous (really, + ? ? ? ?* you should only start a block skipping access at a + ? ? ? ?* partition boundary). ?So don't try to handle that. + ? ? ? ?*/ + ? ? ? if ((offset & (nand->writesize - 1)) != 0) { ? ? ? ? ? ? ? ?printf ("Attempt to write non page aligned data\n"); + ? ? ? ? ? ? ? *length = 0; ? ? ? ? ? ? ? ?return -EINVAL; ? ? ? ?} - ? ? ? len_incl_bad = get_len_incl_bad (nand, offset, *length); - - ? ? ? if ((offset + len_incl_bad) > nand->size) { + ? ? ? need_skip = check_skip_len(nand, offset, *length); + ? ? ? if (need_skip < 0) { ? ? ? ? ? ? ? ?printf ("Attempt to write outside the flash area\n"); + ? ? ? ? ? ? ? *length = 0; ? ? ? ? ? ? ? ?return -EINVAL; ? ? ? ?} - ? ? ? if (len_incl_bad == *length) {
Review int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, · line 523
Quoted 10 lines
(quoted diff) +5
-3+ ? ? ? if (!need_skip) { ? ? ? ? ? ? ? ?rval = nand_write (nand, offset, length, buffer); - ? ? ? ? ? ? ? if (rval != 0) - ? ? ? ? ? ? ? ? ? ? ? printf ("NAND write to offset %llx failed %d\n", - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? offset, rval); + ? ? ? ? ? ? ? if (rval == 0) + ? ? ? ? ? ? ? ? ? ? ? return 0; + ? ? ? ? ? ? ? *length = 0; + ? ? ? ? ? ? ? printf ("NAND write to offset %llx failed %d\n",
no space between printf and the open parenthesis.
Quoted 5 lines
(quoted diff) +1
-0+ ? ? ? ? ? ? ? ? ? ? ? offset, rval); ? ? ? ? ? ? ? ?return rval; ? ? ? ?}
Review int nand_read_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, · line 585
Quoted 10 lines
(quoted diff) +3
-2@@ -553,20 +578,28 @@ int nand_read_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, ?{ ? ? ? ?int rval; ? ? ? ?size_t left_to_read = *length; - ? ? ? size_t len_incl_bad; ? ? ? ?u_char *p_buffer = buffer; + ? ? ? int need_skip; - ? ? ? len_incl_bad = get_len_incl_bad (nand, offset, *length); + ? ? ? if ((offset & (nand->writesize - 1)) != 0) { + ? ? ? ? ? ? ? printf ("Attempt to read non page aligned data\n");
no space between the printf and open parenthesis.
Best Regards,
Ben Gardiner
---
Nanometrics Inc.
http://www.nanometrics.ca
PATCH 1/5 nand util: read/write: accept unaligned length
In reply to Scott WoodQuoted 8 lines · On Mon, 30 Aug 2010 18:03:28 -0500 Scott Wood <[email protected]> wrote:
The underlying code in
nand_base.calready supports non-page-aligned reads and writes, but the block-skipping wrapper code did not.With block skipping, an unaligned start address is not useful since you really want to be starting at the beginning of a partition -- or at least that's where you want to start checking for blocks to skip, but we don't (yet) support that. So we still require the start address to be aligned.
Quoted 4 lines
An unaligned length, though, is useful for passing $filesize to the read/write command, and handling it does not complicate block skipping.
Signed-off-by Scott Wood <[email protected]>
Applied patches 1-5 to u-boot-nand-flash next
-Scott