Technical Note: Patching The Linux Kernel and U-Boot For Micron M29 Flash Memory
Technical Note: Patching The Linux Kernel and U-Boot For Micron M29 Flash Memory
Introduction
Technical Note
Patching the Linux Kernel and U-Boot for Micron® M29 Flash Memory
Introduction
This application note provides a guide for modifying the memory technology device
(MTD) layer software for the purpose of correctly using Micron® M29 family Flash
memory devices in a Linux environment.
This document is also useful for all Linux operating system users who are migrating from
Spansion® GL™ parts to Micron M29 family Flash memory devices (M29W and
M29EW). The document briefly outlines the primary specification differences between
both families of devices. For a deeper analysis of hardware differences, please refer to the
specific migration guide available on the Micron website at www.Micron.com. The
section “Reference Documentation” on page 25 provides a URL for locating related
migration guides.
This document also describes the modifications that are required to make a Linux envi-
ronment work with M29 Flash memory devices.
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 1 ©2012 Micron Technology, Inc. All rights reserved.
Products and specifications discussed herein are for evaluation and reference purposes only and are subject to change by
Micron without notice. Products are only warranted by Micron to meet Micron’s production data sheet specifications. All
information discussed herein is provided on an “as is” basis, without warranties of any kind.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Comparison of Spansion GL and Micron M29
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 2 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programing Functionality in 2.4.x Kernels
retry:
cfi_spin_lock(chip->mutex);
if (chip->state != FL_READY) {
set_current_state(TASK_UNINTERRUPTIBLE);
add_wait_queue(&chip->wq, &wait);
cfi_spin_unlock(chip->mutex);
schedule();
remove_wait_queue(&chip->wq, &wait);
timeo = jiffies + HZ;
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 3 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programing Functionality in 2.4.x Kernels
goto retry;
}
chip->state = FL_WRITING_TO_BUFFER;
#ifdef CONFIG_TANGO2
if (adr == 0)
oldv = get_unaligned((__u32*)buf);
else
oldv = *(volatile unsigned int *)map->map_priv_1;
#endif
adr += chip->start;
ENABLE_VPP(map);
/* Write data */
for (z = 0; z < len; z += CFIDEV_BUSWIDTH) {
if (cfi_buswidth_is_2()) {
datum = *((__u16*)buf);
buf += sizeof(__u16);
cfi_write(map, datum, adr + z);
//map->write16 (map, datum, adr+z);
} else if (cfi_buswidth_is_4()) {
datum = *((__u32*)buf);
buf += sizeof(__u32);
cfi_write(map, datum, adr + z);
//map->write32 (map, datum, adr+z);
}
}
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 4 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programing Functionality in 2.4.x Kernels
/* start program */
cfi_write(map, CMD(0x29), adr);
cfi_spin_unlock(chip->mutex);
cfi_udelay(chip->buffer_write_time);
cfi_spin_lock(chip->mutex);
#ifdef CONFIG_TANGO2
newv = *(volatile unsigned int *)map->map_priv_1;
if ((oldv & mask) == (newv & mask)) {
#endif
if( (dq7 & status) == (dq7 & datum) )
break;
if( ((dq5 & status) == dq5) ||
((dq1 & status) == dq1) ) {
status = cfi_read( map, adr+z );
if( (dq7 & status) != (dq7 & datum) )
{
ret = -EIO;
break;
} else break;
}
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 5 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programing Functionality in 2.4.x Kernels
#ifdef CONFIG_TANGO2
}
#endif
if (need_resched()) {
cfi_spin_unlock(chip->mutex);
yield();
cfi_spin_lock(chip->mutex);
} else
udelay(1);
ret = -EIO;
}
DISABLE_VPP(map);
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 6 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programing Functionality in 2.4.x Kernels
chip->state = FL_READY;
wake_up(&chip->wq);
cfi_spin_unlock(chip->mutex);
return ret;
}
To export the new write buffer feature to the MTD user, the following modifications must
be applied to the cfi_cmdset_0002.c file:
@@ -33,6 +33,9 @@
#include <linux/mtd/cfi.h>
#define AMD_BOOTLOC_BUG
+#define DEBUG_CFI_FEATURES
+#define MAXCIR
+//#define FORCE_SINGLE_WRITE
#ifdef CONFIG_MTD_CFI_AMDSTD_RETRY
@@ -82,6 +85,7 @@ do { \
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 7 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programing Functionality in 2.4.x Kernels
+ {
+ printk( "Using buffer write method\n" );
+ mtd->write = cfi_amdstd_write_buffers;
+ } else {
+#endif
+ printk( "Using word write method\n" );
+ mtd->write = cfi_amdstd_write;
+#ifndef FORCE_SINGLE_WRITE
+ }
+#endif
break;
default:
@@ -968,6 +1129,81 @@ static int cfi_amdstd_write (struct
mtd_info *mtd, loff_t to , size_t len, size_
return 0;
}
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 8 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programing Functionality in 2.4.x Kernels
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 9 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programing Functionality in 2.4.x Kernels
/*
* Handle devices with one erase region, that only implement
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 10 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling 1KB Buffered Programing for M29EW Devices
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 11 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling 1KB Buffered Programing for M29EW in U-Boot
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 12 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling 1KB Buffered Programing for M29EW in U-Boot
+
+static void flash_make_cmd (flash_info_t * info, ulong cmd, void *cmdbuf)
+{
+ int i;
+ int cword_offset;
+ int cp_offset;
+ uchar val;
+ uchar *cp = (uchar *) cmdbuf;
+
+ for (i = info->portwidth; i > 0; i--){
+ cword_offset = (info->portwidth-i)%info->chipwidth;
+#if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
+ cp_offset = info->portwidth - i;
+ val = *((uchar*)&cmd + cword_offset);
+#else
+ cp_offset = i - 1;
+ val = *((uchar*)&cmd + sizeof(ulong) - cword_offset - 1);
+#endif
+ cp[cp_offset] = (cword_offset >= sizeof(ulong)) ? 0x00 : val;
+ }
}
/*
* Write a proper sized command to the correct address
*/
-static void flash_write_cmd (flash_info_t * info, flash_sect_t sect, uint off-
set, uchar cmd)
+static void flash_write_cmd (flash_info_t * info, flash_sect_t sect, uint off-
set, ulong cmd)
{
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 13 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programming for M29EW in x8 Mode
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 14 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programming for M29EW in x8 Mode
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 15 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programming for M29EW in x8 Mode
+
#ifdef DEBUG_CFI
/* Dump the information therein */
print_cfi_ident(cfi->cfiq);
diff --git a/include/linux/mtd/cfi.h b/include/linux/mtd/cfi.h
old mode 100644
new mode 100755
index 88d3d8f..43d6a77
--- a/include/linux/mtd/cfi.h
+++ b/include/linux/mtd/cfi.h
@@ -522,6 +522,7 @@ struct cfi_fixup {
#define CFI_MFR_ATMEL 0x001F
#define CFI_MFR_SAMSUNG 0x00EC
#define CFI_MFR_ST 0x0020 /* STMicroelectronics */
+#define CFI_MFR_NMX 0x0089 /* Micron */
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 16 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Enabling Buffered Programming for M29EW in x8 Mode in U-
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 17 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
0xFF Command Intolerance for M29W128G
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 18 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
0xFF Command Intolerance for M29W128G
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 19 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Correcting Erase Suspend Hang Ups
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 20 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Correcting Erase Suspend Hang Ups
chip->oldstate = FL_READY;
@@ -600,6 +605,11 @@ static void put_chip(struct map_info *map,
struct flchip *chip, unsigned long ad
switch(chip->oldstate) {
case FL_ERASING:
chip->state = chip->oldstate;
+ /* before resume, insert a dummy 0xF0 cycle for Micron M29EW
devices */
+ if ( (cfi->mfr == 0x0089) &&
+ (((cfi->device_type == CFI_DEVICETYPE_X8) && ((cfi->id & 0xff)
== 0x7e))
+ || ((cfi->device_type == CFI_DEVICETYPE_X16) && (cfi->id ==
0x227e))) )
+ map_write(map, CMD(0xF0), chip->in_progress_block_addr);
map_write(map, CMD(0x30), chip->in_progress_block_addr);
chip->oldstate = FL_READY;
chip->state = FL_ERASING;
@@ -743,6 +753,11 @@ static void __xipram xip_udelay(struct
map_info *map, struct flchip *chip,
local_irq_disable();
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 21 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Resolving the Delay After Resume Issue
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 22 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
0x554 Command Tolerance
return addr;
}
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 23 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Summary of Available Patches
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 24 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Reference Documentation
Reference Documentation
For additional information, refer to the migration guides for the Micron M29 Flash
memory devices, which are available here: http://www.micron.com/products/nor-
flash/parallel-nor-flash.
Conclusion
Micron recognizes the value of open source and the importance of supporting the open
source community. Support for Micron Flash memory devices are enabled by contrib-
uting regular patches and updates to the Linux MTD and Linux file systems.
To request support for specific Linux issues, software or incompatibility with Micron
Flash memory devices, contact your Micron representative or submit a request from
www.micron.com.
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 25 ©2012 Micron Technology, Inc. All rights reserved.
TN-13-07 Patching the Linux Kernel and U-Boot for M29 Flash
Revision History
Revision History
Rev. F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .01/12
• Updated hyperlinks
Rev. E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .04/11
• Added the “Enabling 1KB Buffered Programing for M29EW in U-Boot” section
• Added the “Enabling Buffered Programming for M29EW in x8 Mode in U-Boot”
section
• Rebranded document as a technical note
Rev. D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10/10
• Corrected title on inside pages.
Rev. C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .07/10
• Applied branding and formatting.
Rev. 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .02/10
• Added the Resolving the Delay After Resume Issue section.
• Updated the Summary of Available Patches section.
Rev. 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10/09
Initial release authored by Giuseppe Russo and Massimo Cirillo.
PDF: 09005aef846285ae/Source: 09005aef846285c8 Micron Technology, Inc., reserves the right to change products or specifications without notice.
tn1307_patching_linux_kernel_for_m29.fm - Rev. F 1/12 EN 26 ©2012 Micron Technology, Inc. All rights reserved.