public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Detlev Zundel <dzu@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] cfi: Problem with Intel Strata 28F320 flash
Date: Wed, 09 Mar 2011 14:21:14 +0100	[thread overview]
Message-ID: <m2y64oh1kl.fsf@ohwell.denx.de> (raw)
In-Reply-To: <4D77211F.9090203@denx.de> (Heiko Schocher's message of "Wed, 09 Mar 2011 07:41:35 +0100")

Hi Heiko,

> Maybe a way to go ... more comments?
>
> Below a patch, which introduces a function, which checks for
> "protection bugfixes", and if no bugfix is found the old code is
> executed. Just a fast RFC patch.
>
> bye,
> Heiko
>
> diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
> index dd394a8..9d3fdcc 100644
> --- a/drivers/mtd/cfi_flash.c
> +++ b/drivers/mtd/cfi_flash.c
> @@ -1376,6 +1376,38 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
>   */
>  #ifdef CONFIG_SYS_FLASH_PROTECTION
>
> +static int cfi_protect_bugfix(flash_info_t * info, long sector, int prot)
> +{
> +	if ((info->manufacturer_id == 0x89) && (info->device_id == 0x8922)) {
> +		/*
> +		 * see errata called
> +		 * "Numonyx Axcell P33/P30 Specification Update" :)
> +		 */
> +		flash_write_cmd (info, sector, 0, FLASH_CMD_READ_ID);
> +		if (!flash_isequal (info, sector, FLASH_OFFSET_PROTECT,
> +				    prot)) {
> +			/*
> +			 * cmd must come before FLASH_CMD_PROTECT + 20us
> +			 * Disable interrupts which might cause a timeout here.
> +			 */
> +			int flag = disable_interrupts ();
> +			unsigned short cmd;
> +				if (prot)
> +				cmd = FLASH_CMD_PROTECT_SET;
> +			else
> +				cmd = FLASH_CMD_PROTECT_CLEAR;
> +				flash_write_cmd (info, sector, 0,
> +					  FLASH_CMD_PROTECT);
> +			flash_write_cmd (info, sector, 0, cmd);
> +			/* re-enable interrupts if necessary */
> +			if (flag)
> +				enable_interrupts ();
> +		}
> +		return 1;
> +	}
> +	return 0;
> +}
> +
>  int flash_real_protect (flash_info_t * info, long sector, int prot)
>  {
>  	int retcode = 0;
> @@ -1384,31 +1416,18 @@ int flash_real_protect (flash_info_t * info, long sector, int prot)
>  		case CFI_CMDSET_INTEL_PROG_REGIONS:
>  		case CFI_CMDSET_INTEL_STANDARD:
>  		case CFI_CMDSET_INTEL_EXTENDED:
> -			/*
> -			 * see errata called
> -			 * "Numonyx Axcell P33/P30 Specification Update" :)
> -			 */
> -			flash_write_cmd (info, sector, 0, FLASH_CMD_READ_ID);
> -			if (!flash_isequal (info, sector, FLASH_OFFSET_PROTECT,
> -					    prot)) {
> -				/*
> -				 * cmd must come before FLASH_CMD_PROTECT + 20us
> -				 * Disable interrupts which might cause a timeout here.
> -				 */
> -				int flag = disable_interrupts ();
> -				unsigned short cmd;
> -
> +			if (!cfi_protect_bugfix(info, sector, prot)) {
> +				flash_write_cmd (info, sector, 0,
> +					 FLASH_CMD_CLEAR_STATUS);
> +				flash_write_cmd (info, sector, 0,
> +					FLASH_CMD_PROTECT);
>  				if (prot)
> -					cmd = FLASH_CMD_PROTECT_SET;
> +					flash_write_cmd (info, sector, 0,
> +						FLASH_CMD_PROTECT_SET);
>  				else
> -					cmd = FLASH_CMD_PROTECT_CLEAR;
> +					flash_write_cmd (info, sector, 0,
> +						FLASH_CMD_PROTECT_CLEAR);
>
> -				flash_write_cmd (info, sector, 0,
> -						  FLASH_CMD_PROTECT);
> -				flash_write_cmd (info, sector, 0, cmd);
> -				/* re-enable interrupts if necessary */
> -				if (flag)
> -					enable_interrupts ();
>  			}
>  			break;
>  		case CFI_CMDSET_AMD_EXTENDED:

Can't we introduce a field "chip_quirk" in flash_info_t, and upon flash
enumeration check for the specific chip version and for example put a
CFI_QUIRK_PROTECT in it for this chip.  The core code can then check for
this flag and call functions appropriately.

In other words, why not introduce a generic infrastructure for handling
chip quirks that may need different handling for other functions also.

Cheers
  Detlev

-- 
Programming X-Windows is like trying to find the square root of pi
using roman numerals.
                                          -- The UNIX Haters Handbook
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de

  reply	other threads:[~2011-03-09 13:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-08 13:08 [U-Boot] cfi: Problem with Intel Strata 28F320 flash Heiko Schocher
2011-03-08 14:26 ` Philippe De Muyter
2011-03-09  6:41   ` Heiko Schocher
2011-03-09 13:21     ` Detlev Zundel [this message]
2012-07-27 14:11       ` Gerlando Falauto
2012-07-30 11:07         ` Heiko Schocher
2012-07-30 11:11           ` Stefan Roese
2012-08-03  8:01           ` Stefan Roese

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=m2y64oh1kl.fsf@ohwell.denx.de \
    --to=dzu@denx.de \
    --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