imx27: nandboot with 2k pages
PATCH 1/1 imx27: nandboot with 2k pages
--- drivers/nand/nand_imx.c | 94 +++++++++++++++++++++++++++++------ include/asm-arm/arch-imx/imx-nand.h | 2 +- 2 files changed, 79 insertions(+), 17 deletions(-)
drivers/nand/nand_imx.c +19 -5
@@ -1090,26 +1090,74 @@ static struct driver_d imx_nand_driver = { static void __nand_boot_init nfc_addr(struct imx_nand_host *host, u32 offs) { -send_addr (host, offs &0xff ); -send_addr (host, (offs >>9 ) &0xff ); -send_addr (host, (offs >>17 ) &0xff ); -send_addr (host, (offs >>25 ) &0xff ); +if (!host->pagesize_2k) { +send_addr (host, offs &0xff ); +send_addr (host, (offs >>9 ) &0xff ); +send_addr (host, (offs >>17 ) &0xff ); +send_addr (host, (offs >>25 ) &0xff ); + }else { +/* imx27 Nand flash controller can only read full 2k page */ +send_addr (host,0 ); +send_addr (host,0 ); +send_addr (host, (offs >>11 ) &0xff ); +send_addr (host, (offs >>19 ) &0xff ); +/* FIXME: add another send_addr for nandflash > 1Gbit +* if (read electronic signature byte 5 > 1 Gbit) +* send_addr(host, (offs >> 28) & 0xff); +*/ + +/* send read start command */ +send_cmd (host,NAND_CMD_READSTART ); + } } -static int __nand_boot_init block_is_bad(struct imx_nand_host *host,
u32 offs)
+static int __nand_boot_init block_is_bad(struct imx_nand_host *host, u32 offs,
+ u32 pagesize)
{
- send_cmd(host, NAND_CMD_READOOB);
- nfc_addr(host, offs);
- send_read_page(host, 0, 1);
-
- return (readw(host->regs + SPARE_AREA0) & 0xff) == 0xff ? 0 : 1;
+ if (!host->pagesize_2k) {
+ send_cmd(host, NAND_CMD_READOOB);
+ nfc_addr(host, offs);
+ send_read_page(host, 0, 1);
+ if ((readw(host->regs + SPARE_AREA0) & 0xff) != 0xff)
+ return 1;
+ } else {
+ /* The AdvancedToolKit Mark the two first page of each block */
+ /* check first page */
+ send_cmd(host, NAND_CMD_READ0);
+ nfc_addr(host, offs);
+ send_read_page(host, 0, 1);
+ send_read_page(host, 1, 1);
+ send_read_page(host, 2, 1);
+ send_read_page(host, 3, 1);+
+ if (readw(host->regs + NFC_ECC_STATUS_RESULT) & 0xa)
+ return 1;
+
+ if ((readw(host->regs + SPARE_AREA0 + 4) & 0xFF00) != 0xFF00)
+ return 1;
+
+ /* check second page */ + send_cmd(host, NAND_CMD_READ0); + nfc_addr(host, offs + pagesize); + send_read_page(host, 0, 1); + send_read_page(host, 1, 1); + send_read_page(host, 2, 1); + send_read_page(host, 3, 1);
+
+ if (readw(host->regs + NFC_ECC_STATUS_RESULT) & 0xa)
+ return 1;
+
+ if ((readw(host->regs + SPARE_AREA0 + 4) & 0xFF00) != 0xFF00)
+ return 1;
+
+ }
+ return 0;
}
-void __nand_boot_init imx_nand_load_image(void *dest, int size, int pagesize,
- int blocksize)
+void __nand_boot_init imx_nand_load_image(void *dest, int size, int blocksize)
{
struct imx_nand_host host;- u32 tmp, page, block;
+ u32 tmp, page, block, pagesize;
PCCR1 |= PCCR1_NFC_BAUDEN;
@@ -1117,6 +1165,10 @@ void __nand_boot_init imx_nand_load_image(void *dest, int size, int pagesize,
case GPCR_BOOT_8BIT_NAND_2k:
case GPCR_BOOT_16BIT_NAND_2k:
host.pagesize_2k = 1;
+ pagesize = 2048;
+ break;
+ default:
+ pagesize = 512;
}
host.regs = (void __iomem *)IMX_NFC_BASE;
@@ -1134,14 +1186,19 @@ void __nand_boot_init imx_nand_load_image(void
*dest, int size, int pagesize,
/* Unlock Block Command for given address range */
writew(0x4, host.regs + NFC_WRPROT);+ /* clear all operation */
+ writew(0x8000, host.regs + NFC_CONFIG1);
+
+ /* enable ECC, disable spare only and interrupt */
tmp = readw(host.regs + NFC_CONFIG1);
- tmp |= NFC_ECC_EN;
+ tmp |= NFC_ECC_EN | NFC_INT_MSK;
+ tmp &= ~ NFC_SP_EN;
writew(tmp, host.regs + NFC_CONFIG1);
block = page = 0;
while (1) {
- if (!block_is_bad(&host, block * blocksize)) {
+ if (!block_is_bad(&host, block * blocksize, pagesize)) {
page = 0;
while (page * pagesize < blocksize) {
debug("page: %d block: %d dest: %p src "
@@ -1154,8 +1211,13 @@ void __nand_boot_init imx_nand_load_image(void
*dest, int size, int pagesize,
nfc_addr(&host, block * blocksize +
page * pagesize);
send_read_page(&host, 0, 0);
+ if (host.pagesize_2k) {
+ send_read_page(&host, 1, 0);
+ send_read_page(&host, 2, 0);
+ send_read_page(&host, 3, 0);
+ }
page++;
- memcpy32(dest, host.regs, 512);
+ memcpy32(dest, host.regs, pagesize);
dest += pagesize;
size -= pagesize;
if (size <= 0)(quoted diff) +0 -0
b/include/asm-arm/arch-imx/imx-nand.h
index 5ebe0be..eca8fef 100644
include/asm-arm/arch-imx/imx-nand.h +0 -1
@@ -3,7 +3,7 @@#include <linux/mtd/mtd.h> -void imx_nand_load_image(void *dest, int size, int pagesize, int
blocksize);
+void imx_nand_load_image(void *dest, int size, int blocksize);
struct imx_nand_platform_data {
int width;Signature · 16 lines
1.4.4.4 ------------------------------------------------------------------------- Les informations pr?c?dentes peuvent ?tre confidentielles ou privil?gi?es. Si vous n'?tes pas le destinataire pr?vu de ce mail, veuillez en notifier l'exp?diteur en r?pondant ? ce message puis supprimez-en toute trace de vos syst?mes. TIL Technologies Parc du Golf, Bat 43 350 rue J.R Guilibert Gautier de la Lauzi?re 13856 AIX EN PROVENCE Tel. : +33 4 42 37 11 77 -------------------------------------------------------------------------
Sascha Hauer
maintainerPATCH 1/1 imx27: nandboot with 2k pages
Hi Frederic,
The patches look good in general, but unfortunately you mailer turned tabs into spaces and wrapped long lines, so the patches do not apply. Can you send them again please?
one comment inline.
Thanks
Sascha
Quoted 12 lines · frederic Rodo
Signed-off-by Frederic Rodo <[email protected]>--- drivers/nand/nand_imx.c | 94 +++++++++++++++++++++++++++++------ include/asm-arm/arch-imx/imx-nand.h | 2 +- 2 files changed, 79 insertions(+), 17 deletions(-)drivers/nand/nand_imx.c +0
-0
drivers/nand/nand_imx.c static struct driver_d imx_nand_driver = { · line 1093
Quoted 8 lines
drivers/nand/nand_imx.c +1
-4@@ -1090,26 +1090,74 @@ static struct driver_d imx_nand_driver = { static void __nand_boot_init nfc_addr(struct imx_nand_host *host, u32 offs) { -send_addr (host, offs &0xff ); -send_addr (host, (offs >>9 ) &0xff ); -send_addr (host, (offs >>17 ) &0xff ); -send_addr (host, (offs >>25 ) &0xff ); +if (!host->pagesize_2k) {
Can you turn this into positive logic?
Quoted 22 lines
drivers/nand/nand_imx.c +18
-1+send_addr (host, offs &0xff ); +send_addr (host, (offs >>9 ) &0xff ); +send_addr (host, (offs >>17 ) &0xff ); +send_addr (host, (offs >>25 ) &0xff ); + }else { +/* imx27 Nand flash controller can only read full 2k page */ +send_addr (host,0 ); +send_addr (host,0 ); +send_addr (host, (offs >>11 ) &0xff ); +send_addr (host, (offs >>19 ) &0xff ); +/* FIXME: add another send_addr for nandflash > 1Gbit +* if (read electronic signature byte 5 > 1 Gbit) +* send_addr(host, (offs >> 28) & 0xff); +*/ + +/* send read start command */ +send_cmd (host,NAND_CMD_READSTART ); + } } -static int __nand_boot_init block_is_bad(struct imx_nand_host *host, u32 offs)
drivers/nand/nand_imx.c static struct driver_d imx_nand_driver = {
Quoted 10 lines
drivers/nand/nand_imx.c +3
-5+static int __nand_boot_init block_is_bad(struct imx_nand_host *host,u32 offs, +u32 pagesize) { -send_cmd (host ,NAND_CMD_READOOB ); -nfc_addr (host, offs); -send_read_page (host,0 ,1 ); - -return (readw (host->regs +SPARE_AREA0 ) &0xff ) ==0xff ?0 :1 ; +if (!host->pagesize_2k) {
dito
Quoted 137 lines
drivers/nand/nand_imx.c +43
-3+send_cmd (host,NAND_CMD_READOOB ); +nfc_addr (host, offs); +send_read_page (host,0 ,1 ); +if ((readw (host->regs +SPARE_AREA0 ) &0xff ) !=0xff ) +return 1 ; + }else { +/* The AdvancedToolKit Mark the two first page of each block */ +/* check first page */ +send_cmd (host,NAND_CMD_READ0 ); +nfc_addr (host, offs); +send_read_page (host,0 ,1 ); +send_read_page (host,1 ,1 ); +send_read_page (host,2 ,1 ); +send_read_page (host,3 ,1 ); + +if (readw (host->regs +NFC_ECC_STATUS_RESULT ) &0xa ) +return 1 ; + +if ((readw (host->regs +SPARE_AREA0 +4 ) &0xFF00 ) !=0xFF00 ) +return 1 ; + +/* check second page */ +send_cmd (host,NAND_CMD_READ0 ); +nfc_addr (host, offs + pagesize); +send_read_page (host,0 ,1 ); +send_read_page (host,1 ,1 ); +send_read_page (host,2 ,1 ); +send_read_page (host,3 ,1 ); + +if (readw (host->regs +NFC_ECC_STATUS_RESULT ) &0xa ) +return 1 ; + +if ((readw (host->regs +SPARE_AREA0 +4 ) &0xFF00 ) !=0xFF00 ) +return 1 ; + + } +return 0 ; } -void __nand_boot_init imx_nand_load_image(void *dest, int size, int pagesize, -int blocksize) +void __nand_boot_init imx_nand_load_image(void *dest, int size, int blocksize) {struct imx_nand_host host; -u32 tmp, page, block; +u32 tmp, page, block, pagesize;PCCR1 |=PCCR1_NFC_BAUDEN ;@@ -1117,6 +1165,10 @@ void __nand_boot_init imx_nand_load_image(void *dest, int size, int pagesize, case GPCR_BOOT_8BIT_NAND_2k:case GPCR_BOOT_16BIT_NAND_2k: host.pagesize_2k =1 ; + pagesize =2048 ; +break ; +default : + pagesize =512 ; }host.regs = (void __iomem *)IMX_NFC_BASE;drivers/nand/nand_imx.c +7
-2@@ -1134,14 +1186,19 @@ void __nand_boot_init imx_nand_load_image(void *dest, int size, int pagesize,/* Unlock Block Command for given address range */ writew (0x4 , host.regs +NFC_WRPROT ); +/* clear all operation */ +writew (0x8000 , host.regs +NFC_CONFIG1 ); + +/* enable ECC, disable spare only and interrupt */ tmp =readw (host.regs +NFC_CONFIG1 ); - tmp |=NFC_ECC_EN ; + tmp |=NFC_ECC_EN |NFC_INT_MSK ; + tmp &= ~NFC_SP_EN ;writew (tmp, host.regs +NFC_CONFIG1 ); block = page =0 ;while (1 ) { -if (!block_is_bad (&host, block * blocksize)) { +if (!block_is_bad (&host, block * blocksize, pagesize)) { page =0 ;while (page * pagesize < blocksize) {debug("page: %d block: %d dest: %p src "
drivers/nand/nand_imx.c +6
-1@@ -1154,8 +1211,13 @@ void __nand_boot_init imx_nand_load_image(void *dest, int size, int pagesize,nfc_addr (&host, block * blocksize + page * pagesize);send_read_page (&host,0 ,0 ); +if (host.pagesize_2k) { +send_read_page (&host,1 ,0 ); +send_read_page (&host,2 ,0 ); +send_read_page (&host,3 ,0 ); + } page++; -memcpy32 (dest, host.regs,512 ); +memcpy32 (dest, host.regs, pagesize); dest += pagesize; size -= pagesize;if (size <= 0)include/asm-arm/arch-imx/imx-nand.h +1
-1@@ -3,7 +3,7 @@#include <linux/mtd/mtd.h> -void imx_nand_load_image (void *dest,int size,int pagesize,int blocksize); +void imx_nand_load_image (void *dest,int size,int blocksize);struct imx_nand_platform_data {int width;Signature · 16 lines
1.4.4.4 ------------------------------------------------------------------------- Les informations pr?c?dentes peuvent ?tre confidentielles ou privil?gi?es. Si vous n'?tes pas le destinataire pr?vu de ce mail, veuillez en notifier l'exp?diteur en r?pondant ? ce message puis supprimez-en toute trace de vos syst?mes. TIL Technologies Parc du Golf, Bat 43 350 rue J.R Guilibert Gautier de la Lauzi?re 13856 AIX EN PROVENCE Tel. : +33 4 42 37 11 77 -------------------------------------------------------------------------
Signature · 4 lines
Pengutronix e.K. | | Linux Solutions for Science and Industry | Phone: +49-5121-206917-0 | Peiner Strasse 6-8, 31137 Hildesheim, Germany | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |