From a931f49296fa2406abf3c21ea97697513571b7fb Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Sun, 3 Apr 2011 18:23:52 +0200 Subject: [PATCH 1/5] NAND: Fix integer overflow in ONFI detection of chips >= 4GiB This patch sync with David's patch on Linux in nand_flash_detect_onfi() commit 4ccb3b4497ce01fab4933704fe21581e30fda1a5 Author: David Woodhouse Date: Fri Dec 3 16:36:34 2010 +0000 mtd: nand: Fix integer overflow in ONFI detection of chips >= 4GiB Signed-off-by: David Woodhouse Signed-off-by: Florian Fainelli --- drivers/mtd/nand/nand_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index fa286a8..3cb92c1 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -2482,7 +2482,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, mtd->writesize = le32_to_cpu(p->byte_per_page); mtd->erasesize = le32_to_cpu(p->pages_per_block) * mtd->writesize; mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page); - chip->chipsize = le32_to_cpu(p->blocks_per_lun) * mtd->erasesize; + chip->chipsize = (uint64_t)le32_to_cpu(p->blocks_per_lun) * mtd->erasesize; *busw = 0; if (le16_to_cpu(p->features) & 1) *busw = NAND_BUSWIDTH_16; From aad99bbc396a2e3b2913adcb02ed61d6d7e0f1ec Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Sun, 3 Apr 2011 18:23:56 +0200 Subject: [PATCH 2/5] NAND: rearrange ONFI revision checking, add ONFI 2.3 This patch sync with Brian's patch on Linux in nand_flash_detect_onfi() commit b7b1a29d94c17e4341856381bccb4d17495bea60 Author: Brian Norris Date: Sun Dec 12 00:23:33 2010 -0800 mtd: nand: rearrange ONFI revision checking, add ONFI 2.3 In checking for the ONFI revision, the first conditional (for checking "unsupported" ONFI) seems unnecessary. All ONFI revisions should be backwards-compatible; even if this is not the case on some newer ONFI revision, it should simply fail the second version-checking if-else block (i.e., the bit-fields for 1.0, 2.0, etc. would not be set to 1). Thus, we move our "unsupported" condition after having checked each bit field. Also, it's simple enough to add a condition for ONFI revision 2.3. Note that this does *NOT* mean we handle all new features of ONFI versions above 1.0. Signed-off-by: Brian Norris Acked-by: Florian Fainelli Signed-off-by: David Woodhouse Signed-off-by: Florian Fainelli --- drivers/mtd/nand/nand_base.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 3cb92c1..52f8575 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -2461,20 +2461,24 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, /* check version */ val = le16_to_cpu(p->revision); - if (val == 1 || val > (1 << 4)) { - printk(KERN_INFO "%s: unsupported ONFI " - "version: %d\n", __func__, val); - return 0; - } - - if (val & (1 << 4)) + if (val & (1 << 5)) + chip->onfi_version = 23; + else if (val & (1 << 4)) chip->onfi_version = 22; else if (val & (1 << 3)) chip->onfi_version = 21; else if (val & (1 << 2)) chip->onfi_version = 20; - else + else if (val & (1 << 1)) chip->onfi_version = 10; + else + chip->onfi_version = 0; + + if (!chip->onfi_version) { + printk(KERN_INFO "%s: unsupported ONFI " + "version: %d\n", __func__, val); + return 0; + } if (!mtd->name) mtd->name = p->model; From 62974546888c1f9abfdb4ba9f66465a5d102d4d3 Mon Sep 17 00:00:00 2001 From: Matthew McClintock Date: Tue, 5 Apr 2011 14:39:34 -0500 Subject: [PATCH 3/5] nand/spl: Assuming a static nand page size to reduce code size Change variables to const to reduce code size, these values are hardcoded via defines anyways so we might as well assume they are constants Signed-off-by: Matthew McClintock cc: Scott Wood --- nand_spl/nand_boot_fsl_elbc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nand_spl/nand_boot_fsl_elbc.c b/nand_spl/nand_boot_fsl_elbc.c index 9547d44..502605b 100644 --- a/nand_spl/nand_boot_fsl_elbc.c +++ b/nand_spl/nand_boot_fsl_elbc.c @@ -51,11 +51,11 @@ static void nand_load(unsigned int offs, int uboot_size, uchar *dst) { fsl_lbc_t *regs = LBC_BASE_ADDR; uchar *buf = (uchar *)CONFIG_SYS_NAND_BASE; - int large = in_be32(®s->bank[0].or) & OR_FCM_PGS; - int block_shift = large ? 17 : 14; - int block_size = 1 << block_shift; - int page_size = large ? 2048 : 512; - int bad_marker = large ? page_size + 0 : page_size + 5; + const int large = CONFIG_SYS_NAND_OR_PRELIM & OR_FCM_PGS; + const int block_shift = large ? 17 : 14; + const int block_size = 1 << block_shift; + const int page_size = large ? 2048 : 512; + const int bad_marker = large ? page_size + 0 : page_size + 5; int fmr = (15 << FMR_CWTO_SHIFT) | (2 << FMR_AL_SHIFT) | 2; int pos = 0; From 65a9db7be0868be91ba81b9b5bf821de82e6d9b0 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Wed, 6 Apr 2011 16:01:52 -0400 Subject: [PATCH 4/5] nand_spl: Fix large page nand_command() This patch changes the large page nand_command() routine to use a word offset instead of a byte offset. The 'offs' argument gets divided by 2 so that the offset passed to nand_command() is still by byte offset. Originally, the offset was not shifted and when too high an offset was requested the nand chip would attempt to read non-existent data. Signed-off-by: Alex Waterman --- nand_spl/nand_boot.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nand_spl/nand_boot.c b/nand_spl/nand_boot.c index 76b8566..4a96878 100644 --- a/nand_spl/nand_boot.c +++ b/nand_spl/nand_boot.c @@ -90,6 +90,10 @@ static int nand_command(struct mtd_info *mtd, int block, int page, int offs, u8 cmd = NAND_CMD_READ0; } + /* Shift the offset from byte addressing to word addressing. */ + if (this->options & NAND_BUSWIDTH_16) + offs >>= 1; + /* Begin command latch cycle */ this->cmd_ctrl(mtd, cmd, NAND_CTRL_CLE | NAND_CTRL_CHANGE); /* Set ALE and clear CLE to start address cycle */ From e1f703810ed12dadb9151f8074bbe731a240f719 Mon Sep 17 00:00:00 2001 From: Dipen Dudhat Date: Sat, 9 Apr 2011 12:52:32 -0500 Subject: [PATCH 5/5] powerpc/85xx: Modify NAND loader makefiles to compile NAND_SPL linker script Modify eLBC based platform's NAND loader Makefile to preprocess nand loader linker script and then use it. Signed-off-by: Dipen Dudhat CC: Scott Wood Signed-off-by: Kumar Gala --- nand_spl/board/freescale/mpc8536ds/Makefile | 11 +++++++---- nand_spl/board/freescale/mpc8569mds/Makefile | 11 +++++++---- nand_spl/board/freescale/mpc8572ds/Makefile | 11 +++++++---- nand_spl/board/freescale/p1_p2_rdb/Makefile | 11 +++++++---- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/nand_spl/board/freescale/mpc8536ds/Makefile b/nand_spl/board/freescale/mpc8536ds/Makefile index a0e1455..43da3df 100644 --- a/nand_spl/board/freescale/mpc8536ds/Makefile +++ b/nand_spl/board/freescale/mpc8536ds/Makefile @@ -2,7 +2,7 @@ # (C) Copyright 2007 # Stefan Roese, DENX Software Engineering, sr@denx.de. # -# Copyright 2009 Freescale Semiconductor, Inc. +# Copyright 2009-2011 Freescale Semiconductor, Inc. # # See file CREDITS for list of people who contributed to this # project. @@ -32,8 +32,8 @@ include $(TOPDIR)/config.mk nandobj := $(OBJTREE)/nand_spl/ LDSCRIPT= $(TOPDIR)/$(CPUDIR)/u-boot-nand_spl.lds -LDFLAGS := -T $(LDSCRIPT) -Ttext $(CONFIG_SYS_TEXT_BASE_SPL) $(LDFLAGS) \ - $(LDFLAGS_FINAL) +LDFLAGS := -T $(nandobj)u-boot-nand_spl.lds -Ttext $(CONFIG_SYS_TEXT_BASE_SPL) \ + $(LDFLAGS) $(LDFLAGS_FINAL) AFLAGS += -DCONFIG_NAND_SPL CFLAGS += -DCONFIG_NAND_SPL @@ -56,11 +56,14 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl $(nandobj)u-boot-spl.bin: $(nandobj)u-boot-spl $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@ -$(nandobj)u-boot-spl: $(OBJS) +$(nandobj)u-boot-spl: $(OBJS) $(nandobj)u-boot-nand_spl.lds cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) $(PLATFORM_LIBS) \ -Map $(nandobj)u-boot-spl.map \ -o $(nandobj)u-boot-spl +$(nandobj)u-boot-nand_spl.lds: $(LDSCRIPT) + $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@ + # create symbolic links for common files $(obj)cache.c: diff --git a/nand_spl/board/freescale/mpc8569mds/Makefile b/nand_spl/board/freescale/mpc8569mds/Makefile index a0e1455..43da3df 100644 --- a/nand_spl/board/freescale/mpc8569mds/Makefile +++ b/nand_spl/board/freescale/mpc8569mds/Makefile @@ -2,7 +2,7 @@ # (C) Copyright 2007 # Stefan Roese, DENX Software Engineering, sr@denx.de. # -# Copyright 2009 Freescale Semiconductor, Inc. +# Copyright 2009-2011 Freescale Semiconductor, Inc. # # See file CREDITS for list of people who contributed to this # project. @@ -32,8 +32,8 @@ include $(TOPDIR)/config.mk nandobj := $(OBJTREE)/nand_spl/ LDSCRIPT= $(TOPDIR)/$(CPUDIR)/u-boot-nand_spl.lds -LDFLAGS := -T $(LDSCRIPT) -Ttext $(CONFIG_SYS_TEXT_BASE_SPL) $(LDFLAGS) \ - $(LDFLAGS_FINAL) +LDFLAGS := -T $(nandobj)u-boot-nand_spl.lds -Ttext $(CONFIG_SYS_TEXT_BASE_SPL) \ + $(LDFLAGS) $(LDFLAGS_FINAL) AFLAGS += -DCONFIG_NAND_SPL CFLAGS += -DCONFIG_NAND_SPL @@ -56,11 +56,14 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl $(nandobj)u-boot-spl.bin: $(nandobj)u-boot-spl $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@ -$(nandobj)u-boot-spl: $(OBJS) +$(nandobj)u-boot-spl: $(OBJS) $(nandobj)u-boot-nand_spl.lds cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) $(PLATFORM_LIBS) \ -Map $(nandobj)u-boot-spl.map \ -o $(nandobj)u-boot-spl +$(nandobj)u-boot-nand_spl.lds: $(LDSCRIPT) + $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@ + # create symbolic links for common files $(obj)cache.c: diff --git a/nand_spl/board/freescale/mpc8572ds/Makefile b/nand_spl/board/freescale/mpc8572ds/Makefile index 092ce14..43da3df 100644 --- a/nand_spl/board/freescale/mpc8572ds/Makefile +++ b/nand_spl/board/freescale/mpc8572ds/Makefile @@ -2,7 +2,7 @@ # (C) Copyright 2007 # Stefan Roese, DENX Software Engineering, sr@denx.de. # -# Copyright 2009-2010 Freescale Semiconductor, Inc. +# Copyright 2009-2011 Freescale Semiconductor, Inc. # # See file CREDITS for list of people who contributed to this # project. @@ -32,8 +32,8 @@ include $(TOPDIR)/config.mk nandobj := $(OBJTREE)/nand_spl/ LDSCRIPT= $(TOPDIR)/$(CPUDIR)/u-boot-nand_spl.lds -LDFLAGS := -T $(LDSCRIPT) -Ttext $(CONFIG_SYS_TEXT_BASE_SPL) $(LDFLAGS) \ - $(LDFLAGS_FINAL) +LDFLAGS := -T $(nandobj)u-boot-nand_spl.lds -Ttext $(CONFIG_SYS_TEXT_BASE_SPL) \ + $(LDFLAGS) $(LDFLAGS_FINAL) AFLAGS += -DCONFIG_NAND_SPL CFLAGS += -DCONFIG_NAND_SPL @@ -56,11 +56,14 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl $(nandobj)u-boot-spl.bin: $(nandobj)u-boot-spl $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@ -$(nandobj)u-boot-spl: $(OBJS) +$(nandobj)u-boot-spl: $(OBJS) $(nandobj)u-boot-nand_spl.lds cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) $(PLATFORM_LIBS) \ -Map $(nandobj)u-boot-spl.map \ -o $(nandobj)u-boot-spl +$(nandobj)u-boot-nand_spl.lds: $(LDSCRIPT) + $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@ + # create symbolic links for common files $(obj)cache.c: diff --git a/nand_spl/board/freescale/p1_p2_rdb/Makefile b/nand_spl/board/freescale/p1_p2_rdb/Makefile index a0e1455..43da3df 100644 --- a/nand_spl/board/freescale/p1_p2_rdb/Makefile +++ b/nand_spl/board/freescale/p1_p2_rdb/Makefile @@ -2,7 +2,7 @@ # (C) Copyright 2007 # Stefan Roese, DENX Software Engineering, sr@denx.de. # -# Copyright 2009 Freescale Semiconductor, Inc. +# Copyright 2009-2011 Freescale Semiconductor, Inc. # # See file CREDITS for list of people who contributed to this # project. @@ -32,8 +32,8 @@ include $(TOPDIR)/config.mk nandobj := $(OBJTREE)/nand_spl/ LDSCRIPT= $(TOPDIR)/$(CPUDIR)/u-boot-nand_spl.lds -LDFLAGS := -T $(LDSCRIPT) -Ttext $(CONFIG_SYS_TEXT_BASE_SPL) $(LDFLAGS) \ - $(LDFLAGS_FINAL) +LDFLAGS := -T $(nandobj)u-boot-nand_spl.lds -Ttext $(CONFIG_SYS_TEXT_BASE_SPL) \ + $(LDFLAGS) $(LDFLAGS_FINAL) AFLAGS += -DCONFIG_NAND_SPL CFLAGS += -DCONFIG_NAND_SPL @@ -56,11 +56,14 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl $(nandobj)u-boot-spl.bin: $(nandobj)u-boot-spl $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@ -$(nandobj)u-boot-spl: $(OBJS) +$(nandobj)u-boot-spl: $(OBJS) $(nandobj)u-boot-nand_spl.lds cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) $(PLATFORM_LIBS) \ -Map $(nandobj)u-boot-spl.map \ -o $(nandobj)u-boot-spl +$(nandobj)u-boot-nand_spl.lds: $(LDSCRIPT) + $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@ + # create symbolic links for common files $(obj)cache.c: