public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Bartlomiej Sieka <tur@semihalf.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 1/6] flash: factor out adjusting of Flash address to the end of sector
Date: Wed, 08 Oct 2008 09:39:08 +0200	[thread overview]
Message-ID: <48EC639C.3080400@semihalf.com> (raw)
In-Reply-To: <1222867592-58285-2-git-send-email-tur@semihalf.com>

Hello Stefan,

Do you have any comments on the below patch?

Regards,
Bartlomiej Sieka

Bartlomiej Sieka wrote:
> The upcoming automatic update feature needs the ability to adjust an
> address within Flash to the end of its respective sector. Factor out
> this functionality to a new function flash_sect_roundb().
> 
> Signed-off-by: Rafal Czubak <rcz@semihalf.com>
> Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
> ---
>  common/cmd_flash.c |   75 +++++++++++++++++++++++++++++-----------------------
>  include/flash.h    |    1 +
>  2 files changed, 43 insertions(+), 33 deletions(-)
> 
> diff --git a/common/cmd_flash.c b/common/cmd_flash.c
> index 18d2250..29e5b6d 100644
> --- a/common/cmd_flash.c
> +++ b/common/cmd_flash.c
> @@ -105,6 +105,47 @@ abbrev_spec (char *str, flash_info_t ** pinfo, int *psf, int *psl)
>  }
>  
>  /*
> + * Take *addr in Flash and adjust it to fall on the end of its sector
> + */
> +int flash_sect_roundb (ulong *addr)
> +{
> +	flash_info_t *info;
> +	ulong bank, sector_end_addr;
> +	char found;
> +	int i;
> +
> +	/* find the end addr of the sector where the *addr is */
> +	found = 0;
> +	for (bank = 0; bank < CFG_MAX_FLASH_BANKS && !found; ++bank) {
> +		info = &flash_info[bank];
> +		for (i = 0; i < info->sector_count && !found; ++i) {
> +			/* get the end address of the sector */
> +			if (i == info->sector_count - 1) {
> +				sector_end_addr = info->start[0] +
> +								info->size - 1;
> +			} else {
> +				sector_end_addr = info->start[i+1] - 1;
> +			}
> +
> +			if (*addr <= sector_end_addr &&
> +						*addr >= info->start[i]) {
> +				found = 1;
> +				/* adjust *addr if necessary */
> +				if (*addr < sector_end_addr)
> +					*addr = sector_end_addr;
> +			} /* sector */
> +		} /* bank */
> +	}
> +	if (!found) {
> +		/* error, addres not in flash */
> +		printf("Error: end address (0x%08lx) not in flash!\n", *addr);
> +		return 1;
> +	}
> +
> +	return 0;
> +}
> +
> +/*
>   * This function computes the start and end addresses for both
>   * erase and protect commands. The range of the addresses on which
>   * either of the commands is to operate can be given in two forms:
> @@ -126,8 +167,6 @@ addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last)
>  {
>  	char *ep;
>  	char len_used; /* indicates if the "start +length" form used */
> -	char found;
> -	ulong bank;
>  
>  	*addr_first = simple_strtoul(arg1, &ep, 16);
>  	if (ep == arg1 || *ep != '\0')
> @@ -157,38 +196,8 @@ addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last)
>  		 * sector boundary, so that the commands don't fail later on.
>  		 */
>  
> -		/* find the end addr of the sector where the *addr_last is */
> -		found = 0;
> -		for (bank = 0; bank < CFG_MAX_FLASH_BANKS && !found; ++bank){
> -			int i;
> -			flash_info_t *info = &flash_info[bank];
> -			for (i = 0; i < info->sector_count && !found; ++i){
> -				/* get the end address of the sector */
> -				ulong sector_end_addr;
> -				if (i == info->sector_count - 1){
> -					sector_end_addr =
> -						info->start[0] + info->size - 1;
> -				} else {
> -					sector_end_addr =
> -						info->start[i+1] - 1;
> -				}
> -				if (*addr_last <= sector_end_addr &&
> -						*addr_last >= info->start[i]){
> -					/* sector found */
> -					found = 1;
> -					/* adjust *addr_last if necessary */
> -					if (*addr_last < sector_end_addr){
> -						*addr_last = sector_end_addr;
> -					}
> -				}
> -			} /* sector */
> -		} /* bank */
> -		if (!found){
> -			/* error, addres not in flash */
> -			printf("Error: end address (0x%08lx) not in flash!\n",
> -								*addr_last);
> +		if (flash_sect_roundb(addr_last) > 0)
>  			return -1;
> -		}
>  	} /* "start +length" from used */
>  
>  	return 1;
> diff --git a/include/flash.h b/include/flash.h
> index af8a7c0..6f5d7d5 100644
> --- a/include/flash.h
> +++ b/include/flash.h
> @@ -91,6 +91,7 @@ extern void flash_print_info (flash_info_t *);
>  extern int flash_erase	(flash_info_t *, int, int);
>  extern int flash_sect_erase (ulong addr_first, ulong addr_last);
>  extern int flash_sect_protect (int flag, ulong addr_first, ulong addr_last);
> +extern int flash_sect_roundb (ulong *addr);
>  
>  /* common/flash.c */
>  extern void flash_protect (int flag, ulong from, ulong to, flash_info_t *info);

  reply	other threads:[~2008-10-08  7:39 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-18 15:03 [U-Boot] Automatic software updates in U-Boot Bartlomiej Sieka
2008-09-18 15:03 ` [U-Boot] [PATCH 1/3] net: Make TFTP server timeout configurable Bartlomiej Sieka
2008-09-18 15:17   ` Jerry Van Baren
2008-09-18 21:54     ` Graeme Russ
2008-09-19  1:37       ` Jerry Van Baren
2008-09-19  5:52     ` Bartlomiej Sieka
2008-09-22 20:42       ` Wolfgang Denk
2008-09-25  6:17         ` Bartlomiej Sieka
2008-09-18 15:03 ` [U-Boot] [PATCH 2/3] Automatic software update from TFTP server Bartlomiej Sieka
2008-09-22 21:03   ` Wolfgang Denk
2008-09-25  8:16     ` Bartlomiej Sieka
2008-09-25  8:55       ` Wolfgang Denk
2008-09-25  9:49         ` Bartlomiej Sieka
2008-09-25 10:01           ` Wolfgang Denk
2008-09-26  8:46             ` Detlev Zundel
2008-09-25 15:33       ` Andrew Dyer
2008-09-25 16:28         ` Kim Phillips
2008-09-25 16:24           ` Jerry Van Baren
2008-09-25 18:17           ` Wolfgang Denk
2008-09-25 19:21             ` Kim Phillips
2008-09-26  8:08               ` Bartlomiej Sieka
2008-09-26  8:29                 ` Wolfgang Denk
2008-09-26  8:29                   ` Bartlomiej Sieka
2008-09-18 15:03 ` [U-Boot] [PATCH 3/3] FIT: output image load address for type 'firmware', fix debug msg while there Bartlomiej Sieka
2008-10-01 13:26 ` [U-Boot] Automatic software updates in U-Boot -- version 2 Bartlomiej Sieka
2008-10-13 22:57   ` Wolfgang Denk
2008-10-14 12:42     ` Bartlomiej Sieka
2008-10-14 13:47       ` Wolfgang Denk
2008-10-14 20:07       ` Wolfgang Denk
2008-10-15  9:45         ` Bartlomiej Sieka
2008-10-01 13:26 ` [U-Boot] [PATCH v2 1/6] flash: factor out adjusting of Flash address to the end of sector Bartlomiej Sieka
2008-10-08  7:39   ` Bartlomiej Sieka [this message]
2008-10-08  7:47     ` Stefan Roese
2008-10-08  8:05       ` Bartlomiej Sieka
2008-10-08  8:16         ` Wolfgang Denk
2008-10-08 12:02           ` Stefan Roese
2008-10-13 22:28             ` Wolfgang Denk
2008-10-08 17:38           ` Ben Warren
2008-10-13 22:30             ` Wolfgang Denk
2008-10-01 13:26 ` [U-Boot] [PATCH v2 2/6] net: express the first argument to NetSetTimeout() in milliseconds Bartlomiej Sieka
2008-10-06  5:13   ` Ben Warren
2008-10-01 13:26 ` [U-Boot] [PATCH v2 3/6] net: Make TFTP server timeout configurable Bartlomiej Sieka
2008-10-06  5:13   ` Ben Warren
2008-10-01 13:26 ` [U-Boot] [PATCH v2 4/6] Restore alphabetic ordering in common/Makefile Bartlomiej Sieka
2008-10-08 12:29   ` Jean-Christophe PLAGNIOL-VILLARD
2008-10-08 12:58     ` Bartlomiej Sieka
2008-10-08 14:50       ` Jean-Christophe PLAGNIOL-VILLARD
2008-10-09  8:40         ` Bartlomiej Sieka
2008-10-01 13:26 ` [U-Boot] [PATCH v2 5/6] Automatic software update from TFTP server Bartlomiej Sieka
2008-10-13 22:37   ` Wolfgang Denk
2008-10-01 13:26 ` [U-Boot] [PATCH v2 6/6] FIT: output image load address for type 'firmware', fix message while there Bartlomiej Sieka

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=48EC639C.3080400@semihalf.com \
    --to=tur@semihalf.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