public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] flash erasing: len alignment
Date: Thu, 11 Dec 2008 04:31:34 -0500	[thread overview]
Message-ID: <200812110431.35694.vapier@gentoo.org> (raw)

the different flash subsystems dont exactly all operate the same, specifically 
when it comes to erasing.  some require you to specify lengths that are 
aligned exactly to the erase sector size whereas others are much more 
intelligent: they automatically round up for you.  is there any real arguments 
for a particular method ?

personally, i prefer the latter behavior as it makes scripting a hell of a lot 
easier.  for example, if i want to load a binary file into a flash, the 
loading process (i.e. tftp) will automatically set $(filesize) which i can 
then use as the erase/write length.  otherwise i need to either manually do 
the rounding up based on sector size, or i have to assume ahead of time that 
the file will never exceed a certain max size and use that hardcoded value 
(which leads to wasted time erasing sectors that never actually get used and 
unable to use the same code across multiple platforms).

here's an example change to the SPI flash driver:
--- a/u-boot-2008.10/drivers/mtd/spi/stmicro.c
+++ b/u-boot-2008.10/drivers/mtd/spi/stmicro.c
@@ -262,12 +262,12 @@ int stmicro_erase(struct spi_flash
 
 	sector_size = stm->params->page_size * stm->params->pages_per_sector;
 
-	if (offset % sector_size || len % sector_size) {
+	if (offset % sector_size) {
 		debug("SF: Erase offset/length not multiple of sector size\n");
 		return -1;
 	}
 
-	len /= sector_size;
+	len = len / sector_size + !!(len % sector_size);
 	cmd[0] = CMD_M25PXX_SE;
 	cmd[2] = 0x00;
 	cmd[3] = 0x00;
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20081211/ba1a2e9c/attachment.pgp 

             reply	other threads:[~2008-12-11  9:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-11  9:31 Mike Frysinger [this message]
2008-12-11 10:22 ` [U-Boot] flash erasing: len alignment Wolfgang Denk
2008-12-11 10:37   ` Mike Frysinger
2008-12-11 12:05     ` 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=200812110431.35694.vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --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