]> git.sur5r.net Git - u-boot/blobdiff - drivers/mtd/cfi_flash.c
CFI: cfi_flash write fix for AMD legacy
[u-boot] / drivers / mtd / cfi_flash.c
index 03ea2d040d7a3fda49cb6403b4f37e20b55a32bc..7bfdc43da14e3a1455691a8104acdfd85a1bc199 100644 (file)
@@ -255,7 +255,7 @@ u64 flash_read64(void *addr)__attribute__((weak, alias("__flash_read64")));
 
 /*-----------------------------------------------------------------------
  */
-#if defined(CFG_ENV_IS_IN_FLASH) || defined(CFG_ENV_ADDR_REDUND) || (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
+#if defined(CONFIG_ENV_IS_IN_FLASH) || defined(CONFIG_ENV_ADDR_REDUND) || (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
 static flash_info_t *flash_get_info(ulong base)
 {
        int i;
@@ -516,7 +516,7 @@ static int flash_isequal (flash_info_t * info, flash_sect_t sect,
                retval = (flash_read16(addr) == cword.w);
                break;
        case FLASH_CFI_32BIT:
-               debug ("is= %8.8lx %8.8lx\n", flash_read32(addr), cword.l);
+               debug ("is= %8.8x %8.8lx\n", flash_read32(addr), cword.l);
                retval = (flash_read32(addr) == cword.l);
                break;
        case FLASH_CFI_64BIT:
@@ -681,7 +681,7 @@ static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
        case CFI_CMDSET_INTEL_PROG_REGIONS:
        case CFI_CMDSET_INTEL_EXTENDED:
        case CFI_CMDSET_INTEL_STANDARD:
-               if ((retcode == ERR_OK)
+               if ((retcode != ERR_OK)
                    && !flash_isequal (info, sector, 0, FLASH_STATUS_DONE)) {
                        retcode = ERR_INVAL;
                        printf ("Flash %s error at address %lx\n", prompt,
@@ -777,6 +777,7 @@ static int flash_write_cfiword (flash_info_t * info, ulong dest,
 {
        void *dstaddr;
        int flag;
+       flash_sect_t sect;
 
        dstaddr = map_physmem(dest, info->portwidth, MAP_NOCACHE);
 
@@ -818,8 +819,9 @@ static int flash_write_cfiword (flash_info_t * info, ulong dest,
 #ifdef CONFIG_FLASH_CFI_LEGACY
        case CFI_CMDSET_AMD_LEGACY:
 #endif
-               flash_unlock_seq (info, 0);
-               flash_write_cmd (info, 0, info->addr_unlock1, AMD_CMD_WRITE);
+               sect = find_sector(info, dest);
+               flash_unlock_seq (info, sect);
+               flash_write_cmd (info, sect, info->addr_unlock1, AMD_CMD_WRITE);
                break;
        }
 
@@ -1932,9 +1934,10 @@ ulong flash_get_size (ulong base, int banknum)
                        /* XXX - Need to test on x8/x16 in parallel. */
                        info->portwidth >>= 1;
                }
+
+               flash_write_cmd (info, 0, 0, info->cmd_reset);
        }
 
-       flash_write_cmd (info, 0, 0, info->cmd_reset);
        return (info->size);
 }
 
@@ -2031,19 +2034,19 @@ unsigned long flash_init (void)
 #endif
 
        /* Environment protection ON by default */
-#ifdef CFG_ENV_IS_IN_FLASH
+#ifdef CONFIG_ENV_IS_IN_FLASH
        flash_protect (FLAG_PROTECT_SET,
-                      CFG_ENV_ADDR,
-                      CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
-                      flash_get_info(CFG_ENV_ADDR));
+                      CONFIG_ENV_ADDR,
+                      CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
+                      flash_get_info(CONFIG_ENV_ADDR));
 #endif
 
        /* Redundant environment protection ON by default */
-#ifdef CFG_ENV_ADDR_REDUND
+#ifdef CONFIG_ENV_ADDR_REDUND
        flash_protect (FLAG_PROTECT_SET,
-                      CFG_ENV_ADDR_REDUND,
-                      CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
-                      flash_get_info(CFG_ENV_ADDR_REDUND));
+                      CONFIG_ENV_ADDR_REDUND,
+                      CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SIZE_REDUND - 1,
+                      flash_get_info(CONFIG_ENV_ADDR_REDUND));
 #endif
 
 #if defined(CFG_FLASH_AUTOPROTECT_LIST)