Commit 2662b40cace272da5759040622561d821c878d56

Authored by Stefan Roese
1 parent 05d8dce9d0

* Changes/fixes for drivers/cfi_flash.c:

- Add Intel legacy lock/unlock support to common CFI driver

    On some Intel flash's (e.g. Intel J3) legacy unlocking is
    supported, meaning that unlocking of one sector will unlock
    all sectors of this bank. Using this feature, unlocking
    of all sectors upon startup (via env var "unlock=yes") will
    get much faster.

  - Fixed problem with multiple reads of envronment variable
    "unlock" as pointed out by Reinhard Arlt & Anders Larsen.

  - Removed unwanted linefeeds from "protect" command when
    CFG_FLASH_PROTECTION is enabled.

  - Changed p3p400 board to use CFG_FLASH_PROTECTION

  Patch by Stefan Roese, 01 Apr 2006

* Changes/fixes for drivers/cfi_flash.c:
  - Correctly handle the cases where CFG_HZ != 1000 (several
    XScale-based boards)
  - Fix the timeout calculation of buffered writes (off by a
    factor of 1000)
  Patch by Anders Larsen, 31 Mar 2006

Showing 5 changed files with 95 additions and 13 deletions Side-by-side Diff

... ... @@ -2,6 +2,33 @@
2 2 Changes since U-Boot 1.1.4:
3 3 ======================================================================
4 4  
  5 +* Changes/fixes for drivers/cfi_flash.c:
  6 +
  7 + - Add Intel legacy lock/unlock support to common CFI driver
  8 +
  9 + On some Intel flash's (e.g. Intel J3) legacy unlocking is
  10 + supported, meaning that unlocking of one sector will unlock
  11 + all sectors of this bank. Using this feature, unlocking
  12 + of all sectors upon startup (via env var "unlock=yes") will
  13 + get much faster.
  14 +
  15 + - Fixed problem with multiple reads of envronment variable
  16 + "unlock" as pointed out by Reinhard Arlt & Anders Larsen.
  17 +
  18 + - Removed unwanted linefeeds from "protect" command when
  19 + CFG_FLASH_PROTECTION is enabled.
  20 +
  21 + - Changed p3p400 board to use CFG_FLASH_PROTECTION
  22 +
  23 + Patch by Stefan Roese, 01 Apr 2006
  24 +
  25 +* Changes/fixes for drivers/cfi_flash.c:
  26 + - Correctly handle the cases where CFG_HZ != 1000 (several
  27 + XScale-based boards)
  28 + - Fix the timeout calculation of buffered writes (off by a
  29 + factor of 1000)
  30 + Patch by Anders Larsen, 31 Mar 2006
  31 +
5 32 * Enable Quad UART om MCC200 board.
6 33  
7 34 * Cleanup MCC200 board configuration; omit non-existent stuff.
... ... @@ -455,6 +455,7 @@
455 455 #ifdef CONFIG_HAS_DATAFLASH
456 456 int status;
457 457 #endif
  458 +
458 459 if (argc < 3) {
459 460 printf ("Usage:\n%s\n", cmdtp->usage);
460 461 return 1;
461 462  
462 463  
... ... @@ -655,10 +656,10 @@
655 656 #endif /* CFG_FLASH_PROTECTION */
656 657 }
657 658 }
  659 + }
658 660 #if defined(CFG_FLASH_PROTECTION)
659   - if (!rcode) putc ('\n');
  661 + puts (" done\n");
660 662 #endif /* CFG_FLASH_PROTECTION */
661   - }
662 663  
663 664 printf ("%sProtected %d sectors\n",
664 665 p ? "" : "Un-", protected);
... ... @@ -117,6 +117,7 @@
117 117 #define FLASH_OFFSET_CFI 0x55
118 118 #define FLASH_OFFSET_CFI_RESP 0x10
119 119 #define FLASH_OFFSET_PRIMARY_VENDOR 0x13
  120 +#define FLASH_OFFSET_EXT_QUERY_T_P_ADDR 0x15 /* extended query table primary addr */
120 121 #define FLASH_OFFSET_WTOUT 0x1F
121 122 #define FLASH_OFFSET_WBTOUT 0x20
122 123 #define FLASH_OFFSET_ETOUT 0x21
... ... @@ -346,6 +347,10 @@
346 347 unsigned long size = 0;
347 348 int i;
348 349  
  350 +#ifdef CFG_FLASH_PROTECTION
  351 + char *s = getenv("unlock");
  352 +#endif
  353 +
349 354 /* Init: no FLASHes known */
350 355 for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
351 356 flash_info[i].flash_id = FLASH_UNKNOWN;
352 357  
353 358  
354 359  
... ... @@ -357,16 +362,40 @@
357 362 #endif /* CFG_FLASH_QUIET_TEST */
358 363 }
359 364 #ifdef CFG_FLASH_PROTECTION
360   - else {
361   - char *s = getenv("unlock");
  365 + else if ((s != NULL) && (strcmp(s, "yes") == 0)) {
  366 + /*
  367 + * Only the U-Boot image and it's environment is protected,
  368 + * all other sectors are unprotected (unlocked) if flash
  369 + * hardware protection is used (CFG_FLASH_PROTECTION) and
  370 + * the environment variable "unlock" is set to "yes".
  371 + */
  372 + if (flash_info[i].legacy_unlock) {
  373 + int k;
362 374  
363   - if (((s = getenv("unlock")) != NULL) && (strcmp(s, "yes") == 0)) {
364 375 /*
365   - * Only the U-Boot image and it's environment is protected,
366   - * all other sectors are unprotected (unlocked) if flash
367   - * hardware protection is used (CFG_FLASH_PROTECTION) and
368   - * the environment variable "unlock" is set to "yes".
  376 + * Disable legacy_unlock temporarily, since
  377 + * flash_real_protect would relock all other sectors
  378 + * again otherwise.
369 379 */
  380 + flash_info[i].legacy_unlock = 0;
  381 +
  382 + /*
  383 + * Legacy unlocking (e.g. Intel J3) -> unlock only one
  384 + * sector. This will unlock all sectors.
  385 + */
  386 + flash_real_protect (&flash_info[i], 0, 0);
  387 +
  388 + flash_info[i].legacy_unlock = 1;
  389 +
  390 + /*
  391 + * Manually mark other sectors as unlocked (unprotected)
  392 + */
  393 + for (k = 1; k < flash_info[i].sector_count; k++)
  394 + flash_info[i].protect[k] = 0;
  395 + } else {
  396 + /*
  397 + * No legancy unlocking -> unlock all sectors
  398 + */
370 399 flash_protect (FLAG_PROTECT_CLEAR,
371 400 flash_info[i].start[0],
372 401 flash_info[i].start[0] + flash_info[i].size - 1,
... ... @@ -668,8 +697,12 @@
668 697 prot ? "protect" : "unprotect")) == 0) {
669 698  
670 699 info->protect[sector] = prot;
671   - /* Intel's unprotect unprotects all locking */
672   - if (prot == 0) {
  700 +
  701 + /*
  702 + * On some of Intel's flash chips (marked via legacy_unlock)
  703 + * unprotect unprotects all locking.
  704 + */
  705 + if ((prot == 0) && (info->legacy_unlock)) {
673 706 flash_sect_t i;
674 707  
675 708 for (i = 0; i < info->sector_count; i++) {
... ... @@ -746,6 +779,10 @@
746 779 {
747 780 ulong start;
748 781  
  782 +#if CFG_HZ != 1000
  783 + tout *= CFG_HZ/1000;
  784 +#endif
  785 +
749 786 /* Wait for command completion */
750 787 start = get_timer (0);
751 788 while (flash_is_busy (info, sector)) {
... ... @@ -1082,6 +1119,10 @@
1082 1119 uchar num_erase_regions;
1083 1120 int erase_region_size;
1084 1121 int erase_region_count;
  1122 +#ifdef CFG_FLASH_PROTECTION
  1123 + int ext_addr;
  1124 + info->legacy_unlock = 0;
  1125 +#endif
1085 1126  
1086 1127 info->start[0] = base;
1087 1128  
... ... @@ -1095,6 +1136,13 @@
1095 1136 case CFI_CMDSET_INTEL_EXTENDED:
1096 1137 default:
1097 1138 info->cmd_reset = FLASH_CMD_RESET;
  1139 +#ifdef CFG_FLASH_PROTECTION
  1140 + /* read legacy lock/unlock bit from intel flash */
  1141 + ext_addr = flash_read_ushort (info, 0,
  1142 + FLASH_OFFSET_EXT_QUERY_T_P_ADDR);
  1143 + info->legacy_unlock =
  1144 + flash_read_uchar (info, ext_addr + 5) & 0x08;
  1145 +#endif
1098 1146 break;
1099 1147 case CFI_CMDSET_AMD_STANDARD:
1100 1148 case CFI_CMDSET_AMD_EXTENDED:
... ... @@ -1160,8 +1208,9 @@
1160 1208 info->buffer_size = (1 << flash_read_ushort (info, 0, FLASH_OFFSET_BUFFER_SIZE));
1161 1209 tmp = 1 << flash_read_uchar (info, FLASH_OFFSET_ETOUT);
1162 1210 info->erase_blk_tout = (tmp * (1 << flash_read_uchar (info, FLASH_OFFSET_EMAX_TOUT)));
1163   - tmp = 1 << flash_read_uchar (info, FLASH_OFFSET_WBTOUT);
1164   - info->buffer_write_tout = (tmp * (1 << flash_read_uchar (info, FLASH_OFFSET_WBMAX_TOUT)));
  1211 + tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WBTOUT)) *
  1212 + (1 << flash_read_uchar (info, FLASH_OFFSET_WBMAX_TOUT));
  1213 + info->buffer_write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */
1165 1214 tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WTOUT)) *
1166 1215 (1 << flash_read_uchar (info, FLASH_OFFSET_WMAX_TOUT));
1167 1216 info->write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */
include/configs/p3p440.h
... ... @@ -146,6 +146,7 @@
146 146 "cp.b 100000 fffc0000 40000;" \
147 147 "setenv filesize;saveenv\0" \
148 148 "upd=run load;run update\0" \
  149 + "unlock=yes\0" \
149 150 ""
150 151 #define CONFIG_BOOTCOMMAND "run net_nfs"
151 152  
... ... @@ -274,6 +275,9 @@
274 275  
275 276 #define CFG_FLASH_ERASE_TOUT 120000 /* Timeout for Flash Erase (in ms) */
276 277 #define CFG_FLASH_WRITE_TOUT 500 /* Timeout for Flash Write (in ms) */
  278 +
  279 +#define CFG_FLASH_PROTECTION 1 /* use hardware protection */
  280 +#define CFG_FLASH_USE_BUFFER_WRITE 1 /* use buffered writes (20x faster) */
277 281  
278 282 #define CFG_FLASH_EMPTY_INFO /* print 'E' for empty sector on flinfo */
279 283 #define CFG_FLASH_QUIET_TEST 1 /* don't warn upon unknown flash */
... ... @@ -45,6 +45,7 @@
45 45 ushort vendor; /* the primary vendor id */
46 46 ushort cmd_reset; /* Vendor specific reset command */
47 47 ushort interface; /* used for x8/x16 adjustments */
  48 + ushort legacy_unlock; /* support Intel legacy (un)locking */
48 49 #endif
49 50 } flash_info_t;
50 51