[U-Boot] [PATCH V4] nand_spl_simple: store ecc data on the stack

Tom Rini tom.rini at gmail.com
Tue Dec 13 22:30:38 CET 2011


On Tue, Dec 13, 2011 at 12:33 PM, Stefano Babic <sbabic at denx.de> wrote:
> Currently nand_spl_simple puts it's temp data at 0x10000 offset in SDRAM
> which is likely to contain already loaded data.
> The patch saves the oob data and the ecc on the stack replacing
> the fixed address in RAM.
>
> Signed-off-by: Stefano Babic <sbabic at denx.de>
> CC: Ilya Yanok <yanok at emcraft.com>
> CC: Scott Wood <scottwood at freescale.com>
> CC: Tom Rini <tom.rini at gmail.com>
> CC: Simon Schwarz <simonschwarzcor at googlemail.com>
> CC: Wolfgang Denk <wd at denx.de>

Acked-by: Tom Rini <trini at ti.com>

> ---
> V4:
>  - Drop SYS_ from local defines (Wolfgang Denk, Scott Wood)
>  - drop parenthesis around defines (Scott Wood)
>
> V3:
>  - use local defines for CONFIG_SYS_NAND_ECCSTEPS and
>   CONFIG_SYS_NAND_ECCTOTAL (Tom Rini)
>  - drop CONFIG_SYS_NAND_ECCSTEPS from board config files
>
> V2:
>  - CONFIG_SYS_NAND_ECCTOTAL can always be computed (Ilya Yanok)
>  - drop all CONFIG_SYS_NAND_ECCTOTAL in arm boards using nand_simple.c
>
>  drivers/mtd/nand/nand_spl_simple.c     |   42 ++++++++++++-------------------
>  include/configs/am3517_crane.h         |    4 ---
>  include/configs/am3517_evm.h           |    4 ---
>  include/configs/devkit8000.h           |    5 ----
>  include/configs/hawkboard.h            |    5 +---
>  include/configs/omap3_beagle.h         |    4 ---
>  include/configs/omap3_evm.h            |    4 ---
>  include/configs/omap3_evm_quick_nand.h |    4 ---
>  8 files changed, 17 insertions(+), 55 deletions(-)
>
> diff --git a/drivers/mtd/nand/nand_spl_simple.c b/drivers/mtd/nand/nand_spl_simple.c
> index ed821f2..5a1e1a9 100644
> --- a/drivers/mtd/nand/nand_spl_simple.c
> +++ b/drivers/mtd/nand/nand_spl_simple.c
> @@ -27,6 +27,11 @@ static int nand_ecc_pos[] = CONFIG_SYS_NAND_ECCPOS;
>  static nand_info_t mtd;
>  static struct nand_chip nand_chip;
>
> +#define ECCSTEPS       (CONFIG_SYS_NAND_PAGE_SIZE / \
> +                                       CONFIG_SYS_NAND_ECCSIZE)
> +#define ECCTOTAL       (ECCSTEPS * CONFIG_SYS_NAND_ECCBYTES)
> +
> +
>  #if (CONFIG_SYS_NAND_PAGE_SIZE <= 512)
>  /*
>  * NAND command for small page NAND devices (512)
> @@ -145,30 +150,22 @@ static int nand_is_bad_block(int block)
>  static int nand_read_page(int block, int page, uchar *dst)
>  {
>        struct nand_chip *this = mtd.priv;
> -       u_char *ecc_calc;
> -       u_char *ecc_code;
> -       u_char *oob_data;
> +       u_char ecc_calc[ECCTOTAL];
> +       u_char ecc_code[ECCTOTAL];
> +       u_char oob_data[CONFIG_SYS_NAND_OOBSIZE];
>        int i;
>        int eccsize = CONFIG_SYS_NAND_ECCSIZE;
>        int eccbytes = CONFIG_SYS_NAND_ECCBYTES;
> -       int eccsteps = CONFIG_SYS_NAND_ECCSTEPS;
> +       int eccsteps = ECCSTEPS;
>        uint8_t *p = dst;
>        int stat;
>
> -       /*
> -        * No malloc available for now, just use some temporary locations
> -        * in SDRAM
> -        */
> -       ecc_calc = (u_char *)(CONFIG_SYS_SDRAM_BASE + 0x10000);
> -       ecc_code = ecc_calc + 0x100;
> -       oob_data = ecc_calc + 0x200;
> -
>        nand_command(block, page, 0, NAND_CMD_READOOB);
>        this->read_buf(&mtd, oob_data, CONFIG_SYS_NAND_OOBSIZE);
>        nand_command(block, page, 0, NAND_CMD_READ0);
>
>        /* Pick the ECC bytes out of the oob data */
> -       for (i = 0; i < CONFIG_SYS_NAND_ECCTOTAL; i++)
> +       for (i = 0; i < ECCTOTAL; i++)
>                ecc_code[i] = oob_data[nand_ecc_pos[i]];
>
>
> @@ -185,25 +182,18 @@ static int nand_read_page(int block, int page, uchar *dst)
>  static int nand_read_page(int block, int page, void *dst)
>  {
>        struct nand_chip *this = mtd.priv;
> -       u_char *ecc_calc;
> -       u_char *ecc_code;
> -       u_char *oob_data;
> +       u_char ecc_calc[ECCTOTAL];
> +       u_char ecc_code[ECCTOTAL];
> +       u_char oob_data[CONFIG_SYS_NAND_OOBSIZE];
>        int i;
>        int eccsize = CONFIG_SYS_NAND_ECCSIZE;
>        int eccbytes = CONFIG_SYS_NAND_ECCBYTES;
> -       int eccsteps = CONFIG_SYS_NAND_ECCSTEPS;
> +       int eccsteps = ECCSTEPS;
>        uint8_t *p = dst;
>        int stat;
>
>        nand_command(block, page, 0, NAND_CMD_READ0);
>
> -       /* No malloc available for now, just use some temporary locations
> -        * in SDRAM
> -        */
> -       ecc_calc = (u_char *)(CONFIG_SYS_SDRAM_BASE + 0x10000);
> -       ecc_code = ecc_calc + 0x100;
> -       oob_data = ecc_calc + 0x200;
> -
>        for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
>                if (this->ecc.mode != NAND_ECC_SOFT)
>                        this->ecc.hwctl(&mtd, NAND_ECC_READ);
> @@ -213,10 +203,10 @@ static int nand_read_page(int block, int page, void *dst)
>        this->read_buf(&mtd, oob_data, CONFIG_SYS_NAND_OOBSIZE);
>
>        /* Pick the ECC bytes out of the oob data */
> -       for (i = 0; i < CONFIG_SYS_NAND_ECCTOTAL; i++)
> +       for (i = 0; i < ECCTOTAL; i++)
>                ecc_code[i] = oob_data[nand_ecc_pos[i]];
>
> -       eccsteps = CONFIG_SYS_NAND_ECCSTEPS;
> +       eccsteps = ECCSTEPS;
>        p = dst;
>
>        for (i = 0 ; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
> diff --git a/include/configs/am3517_crane.h b/include/configs/am3517_crane.h
> index 0a0c261..b0dd2f0 100644
> --- a/include/configs/am3517_crane.h
> +++ b/include/configs/am3517_crane.h
> @@ -359,10 +359,6 @@
>                                                10, 11, 12, 13}
>  #define CONFIG_SYS_NAND_ECCSIZE                512
>  #define CONFIG_SYS_NAND_ECCBYTES       3
> -#define CONFIG_SYS_NAND_ECCSTEPS       (CONFIG_SYS_NAND_PAGE_SIZE / \
> -                                               CONFIG_SYS_NAND_ECCSIZE)
> -#define CONFIG_SYS_NAND_ECCTOTAL       (CONFIG_SYS_NAND_ECCBYTES * \
> -                                               CONFIG_SYS_NAND_ECCSTEPS)
>  #define CONFIG_SYS_NAND_U_BOOT_START   CONFIG_SYS_TEXT_BASE
>  #define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000
>
> diff --git a/include/configs/am3517_evm.h b/include/configs/am3517_evm.h
> index d44eeec..f797f3f 100644
> --- a/include/configs/am3517_evm.h
> +++ b/include/configs/am3517_evm.h
> @@ -360,10 +360,6 @@
>                                                10, 11, 12, 13}
>  #define CONFIG_SYS_NAND_ECCSIZE                512
>  #define CONFIG_SYS_NAND_ECCBYTES       3
> -#define CONFIG_SYS_NAND_ECCSTEPS       (CONFIG_SYS_NAND_PAGE_SIZE / \
> -                                               CONFIG_SYS_NAND_ECCSIZE)
> -#define CONFIG_SYS_NAND_ECCTOTAL       (CONFIG_SYS_NAND_ECCBYTES * \
> -                                               CONFIG_SYS_NAND_ECCSTEPS)
>  #define CONFIG_SYS_NAND_U_BOOT_START   CONFIG_SYS_TEXT_BASE
>  #define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000
>
> diff --git a/include/configs/devkit8000.h b/include/configs/devkit8000.h
> index fc7f0cd..6ef6a87 100644
> --- a/include/configs/devkit8000.h
> +++ b/include/configs/devkit8000.h
> @@ -344,11 +344,6 @@
>  #define CONFIG_SYS_NAND_ECCSIZE                512
>  #define CONFIG_SYS_NAND_ECCBYTES       3
>
> -#define CONFIG_SYS_NAND_ECCSTEPS       (CONFIG_SYS_NAND_PAGE_SIZE / \
> -                                               CONFIG_SYS_NAND_ECCSIZE)
> -#define CONFIG_SYS_NAND_ECCTOTAL       (CONFIG_SYS_NAND_ECCBYTES * \
> -                                               CONFIG_SYS_NAND_ECCSTEPS)
> -
>  #define CONFIG_SYS_NAND_U_BOOT_START   CONFIG_SYS_TEXT_BASE
>
>  #define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000
> diff --git a/include/configs/hawkboard.h b/include/configs/hawkboard.h
> index 12acb27..65b3b78 100644
> --- a/include/configs/hawkboard.h
> +++ b/include/configs/hawkboard.h
> @@ -138,11 +138,8 @@
>  #define CONFIG_SYS_NAND_BAD_BLOCK_POS  0
>  #define CONFIG_SYS_NAND_ECCSIZE                512
>  #define CONFIG_SYS_NAND_ECCBYTES       10
> -#define CONFIG_SYS_NAND_ECCSTEPS       (CONFIG_SYS_NAND_PAGE_SIZE /     \
> -                                        CONFIG_SYS_NAND_ECCSIZE)
>  #define CONFIG_SYS_NAND_OOBSIZE                64
> -#define CONFIG_SYS_NAND_ECCTOTAL       (CONFIG_SYS_NAND_ECCBYTES *     \
> -                                       CONFIG_SYS_NAND_ECCSTEPS)
> +
>  #endif /* CONFIG_SYS_USE_NAND */
>
>  /*
> diff --git a/include/configs/omap3_beagle.h b/include/configs/omap3_beagle.h
> index 970810c..7a240bb 100644
> --- a/include/configs/omap3_beagle.h
> +++ b/include/configs/omap3_beagle.h
> @@ -426,10 +426,6 @@
>                                                10, 11, 12, 13}
>  #define CONFIG_SYS_NAND_ECCSIZE                512
>  #define CONFIG_SYS_NAND_ECCBYTES       3
> -#define CONFIG_SYS_NAND_ECCSTEPS       (CONFIG_SYS_NAND_PAGE_SIZE / \
> -                                               CONFIG_SYS_NAND_ECCSIZE)
> -#define CONFIG_SYS_NAND_ECCTOTAL       (CONFIG_SYS_NAND_ECCBYTES * \
> -                                               CONFIG_SYS_NAND_ECCSTEPS)
>  #define CONFIG_SYS_NAND_U_BOOT_START   CONFIG_SYS_TEXT_BASE
>  #define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000
>
> diff --git a/include/configs/omap3_evm.h b/include/configs/omap3_evm.h
> index 2ce3959..1fcb7af 100644
> --- a/include/configs/omap3_evm.h
> +++ b/include/configs/omap3_evm.h
> @@ -121,10 +121,6 @@
>                                                10, 11, 12, 13}
>  #define CONFIG_SYS_NAND_ECCSIZE                512
>  #define CONFIG_SYS_NAND_ECCBYTES       3
> -#define CONFIG_SYS_NAND_ECCSTEPS       (CONFIG_SYS_NAND_PAGE_SIZE / \
> -                                               CONFIG_SYS_NAND_ECCSIZE)
> -#define CONFIG_SYS_NAND_ECCTOTAL       (CONFIG_SYS_NAND_ECCBYTES * \
> -                                               CONFIG_SYS_NAND_ECCSTEPS)
>  #define CONFIG_SYS_NAND_U_BOOT_START   CONFIG_SYS_TEXT_BASE
>  #define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000
>
> diff --git a/include/configs/omap3_evm_quick_nand.h b/include/configs/omap3_evm_quick_nand.h
> index 2f879c0..362fa1d 100644
> --- a/include/configs/omap3_evm_quick_nand.h
> +++ b/include/configs/omap3_evm_quick_nand.h
> @@ -91,10 +91,6 @@
>                                                10, 11, 12, 13}
>  #define CONFIG_SYS_NAND_ECCSIZE                512
>  #define CONFIG_SYS_NAND_ECCBYTES       3
> -#define CONFIG_SYS_NAND_ECCSTEPS       (CONFIG_SYS_NAND_PAGE_SIZE / \
> -                                               CONFIG_SYS_NAND_ECCSIZE)
> -#define CONFIG_SYS_NAND_ECCTOTAL       (CONFIG_SYS_NAND_ECCBYTES * \
> -                                               CONFIG_SYS_NAND_ECCSTEPS)
>  #define CONFIG_SYS_NAND_U_BOOT_START   CONFIG_SYS_TEXT_BASE
>  #define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000
>
> --
> 1.7.5.4
>



-- 
Tom


More information about the U-Boot mailing list