From: Derek Ou <dou@siconix.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Pad data length for nand write
Date: Tue, 17 Feb 2009 10:15:07 -0700 [thread overview]
Message-ID: <1234890907-934-2-git-send-email-dou@siconix.com> (raw)
In-Reply-To: <1234890907-934-1-git-send-email-dou@siconix.com>
Signed-off-by: Derek Ou <dou@siconix.com>
---
drivers/mtd/nand/nand_util.c | 25 ++++++++++++++++++-------
1 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
index 6ba52b3..b9d292a 100644
--- a/drivers/mtd/nand/nand_util.c
+++ b/drivers/mtd/nand/nand_util.c
@@ -475,25 +475,36 @@ int nand_write_skip_bad(nand_info_t *nand, size_t offset, size_t *length,
{
int rval;
size_t left_to_write = *length;
+ size_t page_offset, pad_len = 0;
size_t len_incl_bad;
u_char *p_buffer = buffer;
- /* Reject writes, which are not page aligned */
- if ((offset & (nand->writesize - 1)) != 0 ||
- (*length & (nand->writesize - 1)) != 0) {
- printf ("Attempt to write non page aligned data\n");
+ /* Reject writes when offset is not page aligned */
+ if ((offset & (nand->writesize - 1)) != 0 ) {
+ printf ("Attempt to write address non page aligned\n");
return -EINVAL;
}
- len_incl_bad = get_len_incl_bad (nand, offset, *length);
+ /* Pad write length if it's not page aligned */
+ page_offset = left_to_write & (nand->writesize - 1);
+ if (page_offset != 0) {
+ pad_len = nand->writesize - page_offset;
+ left_to_write += pad_len;
+ }
+
+ len_incl_bad = get_len_incl_bad (nand, offset, left_to_write);
if ((offset + len_incl_bad) >= nand->size) {
printf ("Attempt to write outside the flash area\n");
return -EINVAL;
}
- if (len_incl_bad == *length) {
- rval = nand_write (nand, offset, length, buffer);
+ /* now, pad data with 0xff */
+ if (page_offset != 0)
+ memset(buffer + *length, 0xff, pad_len);
+
+ if (len_incl_bad == left_to_write) {
+ rval = nand_write (nand, offset, &left_to_write, buffer);
if (rval != 0)
printf ("NAND write to offset %zx failed %d\n",
offset, rval);
--
1.5.4.3
next prev parent reply other threads:[~2009-02-17 17:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-17 17:15 [U-Boot] [PATCH] Pad data length for nand write Derek Ou
2009-02-17 17:15 ` Derek Ou [this message]
2009-02-17 18:51 ` Scott Wood
2009-02-17 20:54 ` Derek Ou
2009-02-17 21:16 ` Scott Wood
2009-02-17 21:37 ` Derek Ou
2009-02-17 17:55 ` Mike Frysinger
2009-02-17 18:37 ` Derek Ou
2009-02-17 18:41 ` Scott Wood
2009-02-17 20:22 ` Wolfgang Denk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1234890907-934-2-git-send-email-dou@siconix.com \
--to=dou@siconix.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox