Commit e619a75ff6201b567a539e787aa9af9bc63a3187

Authored by Justin Treon
Committed by David Woodhouse
1 parent 842b1a105c

[MTD] Unlocking all Intel flash that is locked on power up.

Patch for unlocking all Intel flash that has instant locking on power up.
The patch has been tested on Intel M18, P30 and J3D Strata Flash.
  1.    The automatic unlocking can be disabled for a particular partition
         in the map or the command line.
     a. For the bit mask in the map it should look like:
         .mask_flags   = MTD_POWERUP_LOCK,
     b. For the command line parsing it should look like:
         mtdparts=0x80000(bootloader)lk
  2.    This will only unlock parts with instant individual block locking.
         Intel parts with legacy unlocking will not be unlocked.

Signed-off-by: Justin Treon <justin_treon@yahoo.com>
Signed-off-by: Jared Hulbert <jaredeh@gmail.com>
Acked-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>

Showing 5 changed files with 23 additions and 10 deletions Side-by-side Diff

drivers/mtd/chips/cfi_cmdset_0001.c
... ... @@ -269,10 +269,16 @@
269 269 /*
270 270 * Some chips power-up with all sectors locked by default.
271 271 */
272   -static void fixup_use_powerup_lock(struct mtd_info *mtd, void *param)
  272 +static void fixup_unlock_powerup_lock(struct mtd_info *mtd, void *param)
273 273 {
274   - printk(KERN_INFO "Using auto-unlock on power-up/resume\n" );
275   - mtd->flags |= MTD_STUPID_LOCK;
  274 + struct map_info *map = mtd->priv;
  275 + struct cfi_private *cfi = map->fldrv_priv;
  276 + struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
  277 +
  278 + if (cfip->FeatureSupport&32) {
  279 + printk(KERN_INFO "Using auto-unlock on power-up/resume\n" );
  280 + mtd->flags |= MTD_POWERUP_LOCK;
  281 + }
276 282 }
277 283  
278 284 static struct cfi_fixup cfi_fixup_table[] = {
... ... @@ -288,7 +294,7 @@
288 294 #endif
289 295 { CFI_MFR_ST, 0x00ba, /* M28W320CT */ fixup_st_m28w320ct, NULL },
290 296 { CFI_MFR_ST, 0x00bb, /* M28W320CB */ fixup_st_m28w320cb, NULL },
291   - { MANUFACTURER_INTEL, 0x891c, fixup_use_powerup_lock, NULL, },
  297 + { MANUFACTURER_INTEL, CFI_ID_ANY, fixup_unlock_powerup_lock, NULL, },
292 298 { 0, 0, NULL, NULL }
293 299 };
294 300  
... ... @@ -2349,7 +2355,7 @@
2349 2355 struct flchip *chip;
2350 2356 int ret = 0;
2351 2357  
2352   - if ((mtd->flags & MTD_STUPID_LOCK)
  2358 + if ((mtd->flags & MTD_POWERUP_LOCK)
2353 2359 && extp && (extp->FeatureSupport & (1 << 5)))
2354 2360 cfi_intelext_save_locks(mtd);
2355 2361  
... ... @@ -2460,7 +2466,7 @@
2460 2466 spin_unlock(chip->mutex);
2461 2467 }
2462 2468  
2463   - if ((mtd->flags & MTD_STUPID_LOCK)
  2469 + if ((mtd->flags & MTD_POWERUP_LOCK)
2464 2470 && extp && (extp->FeatureSupport & (1 << 5)))
2465 2471 cfi_intelext_restore_locks(mtd);
2466 2472 }
drivers/mtd/chips/cfi_cmdset_0002.c
... ... @@ -217,7 +217,7 @@
217 217 {
218 218 mtd->lock = cfi_atmel_lock;
219 219 mtd->unlock = cfi_atmel_unlock;
220   - mtd->flags |= MTD_STUPID_LOCK;
  220 + mtd->flags |= MTD_POWERUP_LOCK;
221 221 }
222 222  
223 223 static struct cfi_fixup cfi_fixup_table[] = {
drivers/mtd/cmdlinepart.c
... ... @@ -9,7 +9,7 @@
9 9 *
10 10 * mtdparts=<mtddef>[;<mtddef]
11 11 * <mtddef> := <mtd-id>:<partdef>[,<partdef>]
12   - * <partdef> := <size>[@offset][<name>][ro]
  12 + * <partdef> := <size>[@offset][<name>][ro][lk]
13 13 * <mtd-id> := unique name used in mapping driver/device (mtd->name)
14 14 * <size> := standard linux memsize OR "-" to denote all remaining space
15 15 * <name> := '(' NAME ')'
... ... @@ -140,6 +140,13 @@
140 140 if (strncmp(s, "ro", 2) == 0)
141 141 {
142 142 mask_flags |= MTD_WRITEABLE;
  143 + s += 2;
  144 + }
  145 +
  146 + /* if lk is found do NOT unlock the MTD partition*/
  147 + if (strncmp(s, "lk", 2) == 0)
  148 + {
  149 + mask_flags |= MTD_POWERUP_LOCK;
143 150 s += 2;
144 151 }
145 152  
drivers/mtd/mtdcore.c
... ... @@ -61,7 +61,7 @@
61 61  
62 62 /* Some chips always power up locked. Unlock them now */
63 63 if ((mtd->flags & MTD_WRITEABLE)
64   - && (mtd->flags & MTD_STUPID_LOCK) && mtd->unlock) {
  64 + && (mtd->flags & MTD_POWERUP_LOCK) && mtd->unlock) {
65 65 if (mtd->unlock(mtd, 0, mtd->size))
66 66 printk(KERN_WARNING
67 67 "%s: unlock failed, "
include/mtd/mtd-abi.h
... ... @@ -29,7 +29,7 @@
29 29 #define MTD_WRITEABLE 0x400 /* Device is writeable */
30 30 #define MTD_BIT_WRITEABLE 0x800 /* Single bits can be flipped */
31 31 #define MTD_NO_ERASE 0x1000 /* No erase necessary */
32   -#define MTD_STUPID_LOCK 0x2000 /* Always locked after reset */
  32 +#define MTD_POWERUP_LOCK 0x2000 /* Always locked after reset */
33 33  
34 34 // Some common devices / combinations of capabilities
35 35 #define MTD_CAP_ROM 0