Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 1 | /* |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 2 | * (C) Copyright 2006-2008 |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <nand.h> |
Stefan Roese | c568f77 | 2008-01-05 16:49:37 +0100 | [diff] [blame] | 10 | #include <asm/io.h> |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 11 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 12 | static int nand_ecc_pos[] = CONFIG_SYS_NAND_ECCPOS; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 13 | |
Scott Wood | 25efd99 | 2012-01-11 15:41:01 -0600 | [diff] [blame] | 14 | #define ECCSTEPS (CONFIG_SYS_NAND_PAGE_SIZE / \ |
| 15 | CONFIG_SYS_NAND_ECCSIZE) |
| 16 | #define ECCTOTAL (ECCSTEPS * CONFIG_SYS_NAND_ECCBYTES) |
| 17 | |
| 18 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 19 | #if (CONFIG_SYS_NAND_PAGE_SIZE <= 512) |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 20 | /* |
| 21 | * NAND command for small page NAND devices (512) |
| 22 | */ |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 23 | static int nand_command(struct mtd_info *mtd, int block, int page, int offs, u8 cmd) |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 24 | { |
Wolfgang Denk | 511d0c7 | 2006-10-09 00:42:01 +0200 | [diff] [blame] | 25 | struct nand_chip *this = mtd->priv; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 26 | int page_addr = page + block * CONFIG_SYS_NAND_PAGE_COUNT; |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 27 | |
Stefan Roese | e29816f | 2011-05-16 13:04:00 +0200 | [diff] [blame] | 28 | while (!this->dev_ready(mtd)) |
| 29 | ; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 30 | |
| 31 | /* Begin command latch cycle */ |
Scott Wood | 4f32d77 | 2008-08-05 11:15:59 -0500 | [diff] [blame] | 32 | this->cmd_ctrl(mtd, cmd, NAND_CTRL_CLE | NAND_CTRL_CHANGE); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 33 | /* Set ALE and clear CLE to start address cycle */ |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 34 | /* Column address */ |
Scott Wood | 4f32d77 | 2008-08-05 11:15:59 -0500 | [diff] [blame] | 35 | this->cmd_ctrl(mtd, offs, NAND_CTRL_ALE | NAND_CTRL_CHANGE); |
Scott Wood | 1dac3a5 | 2009-06-24 17:23:49 -0500 | [diff] [blame] | 36 | this->cmd_ctrl(mtd, page_addr & 0xff, NAND_CTRL_ALE); /* A[16:9] */ |
| 37 | this->cmd_ctrl(mtd, (page_addr >> 8) & 0xff, |
| 38 | NAND_CTRL_ALE); /* A[24:17] */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 39 | #ifdef CONFIG_SYS_NAND_4_ADDR_CYCLE |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 40 | /* One more address cycle for devices > 32MiB */ |
Scott Wood | 1dac3a5 | 2009-06-24 17:23:49 -0500 | [diff] [blame] | 41 | this->cmd_ctrl(mtd, (page_addr >> 16) & 0x0f, |
| 42 | NAND_CTRL_ALE); /* A[28:25] */ |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 43 | #endif |
| 44 | /* Latch in address */ |
Stefan Roese | c568f77 | 2008-01-05 16:49:37 +0100 | [diff] [blame] | 45 | this->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Wait a while for the data to be ready |
| 49 | */ |
Stefan Roese | a9c847c | 2011-05-04 11:44:14 +0200 | [diff] [blame] | 50 | while (!this->dev_ready(mtd)) |
| 51 | ; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 52 | |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 53 | return 0; |
| 54 | } |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 55 | #else |
| 56 | /* |
| 57 | * NAND command for large page NAND devices (2k) |
| 58 | */ |
| 59 | static int nand_command(struct mtd_info *mtd, int block, int page, int offs, u8 cmd) |
| 60 | { |
| 61 | struct nand_chip *this = mtd->priv; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 62 | int page_addr = page + block * CONFIG_SYS_NAND_PAGE_COUNT; |
Alex Waterman | 83709783 | 2011-05-04 09:10:15 -0400 | [diff] [blame] | 63 | void (*hwctrl)(struct mtd_info *mtd, int cmd, |
| 64 | unsigned int ctrl) = this->cmd_ctrl; |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 65 | |
Stefan Roese | a9c847c | 2011-05-04 11:44:14 +0200 | [diff] [blame] | 66 | while (!this->dev_ready(mtd)) |
| 67 | ; |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 68 | |
| 69 | /* Emulate NAND_CMD_READOOB */ |
| 70 | if (cmd == NAND_CMD_READOOB) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 71 | offs += CONFIG_SYS_NAND_PAGE_SIZE; |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 72 | cmd = NAND_CMD_READ0; |
| 73 | } |
| 74 | |
Alex Waterman | 65a9db7 | 2011-04-06 16:01:52 -0400 | [diff] [blame] | 75 | /* Shift the offset from byte addressing to word addressing. */ |
| 76 | if (this->options & NAND_BUSWIDTH_16) |
| 77 | offs >>= 1; |
| 78 | |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 79 | /* Begin command latch cycle */ |
Alex Waterman | 83709783 | 2011-05-04 09:10:15 -0400 | [diff] [blame] | 80 | hwctrl(mtd, cmd, NAND_CTRL_CLE | NAND_CTRL_CHANGE); |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 81 | /* Set ALE and clear CLE to start address cycle */ |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 82 | /* Column address */ |
Alex Waterman | 83709783 | 2011-05-04 09:10:15 -0400 | [diff] [blame] | 83 | hwctrl(mtd, offs & 0xff, |
Wolfgang Denk | 4b07080 | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 84 | NAND_CTRL_ALE | NAND_CTRL_CHANGE); /* A[7:0] */ |
Alex Waterman | 83709783 | 2011-05-04 09:10:15 -0400 | [diff] [blame] | 85 | hwctrl(mtd, (offs >> 8) & 0xff, NAND_CTRL_ALE); /* A[11:9] */ |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 86 | /* Row address */ |
Alex Waterman | 83709783 | 2011-05-04 09:10:15 -0400 | [diff] [blame] | 87 | hwctrl(mtd, (page_addr & 0xff), NAND_CTRL_ALE); /* A[19:12] */ |
| 88 | hwctrl(mtd, ((page_addr >> 8) & 0xff), |
Scott Wood | 1dac3a5 | 2009-06-24 17:23:49 -0500 | [diff] [blame] | 89 | NAND_CTRL_ALE); /* A[27:20] */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 90 | #ifdef CONFIG_SYS_NAND_5_ADDR_CYCLE |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 91 | /* One more address cycle for devices > 128MiB */ |
Alex Waterman | 83709783 | 2011-05-04 09:10:15 -0400 | [diff] [blame] | 92 | hwctrl(mtd, (page_addr >> 16) & 0x0f, |
Scott Wood | 1dac3a5 | 2009-06-24 17:23:49 -0500 | [diff] [blame] | 93 | NAND_CTRL_ALE); /* A[31:28] */ |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 94 | #endif |
| 95 | /* Latch in address */ |
Alex Waterman | 83709783 | 2011-05-04 09:10:15 -0400 | [diff] [blame] | 96 | hwctrl(mtd, NAND_CMD_READSTART, |
Wolfgang Denk | 4b07080 | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 97 | NAND_CTRL_CLE | NAND_CTRL_CHANGE); |
Alex Waterman | 83709783 | 2011-05-04 09:10:15 -0400 | [diff] [blame] | 98 | hwctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 99 | |
| 100 | /* |
| 101 | * Wait a while for the data to be ready |
| 102 | */ |
Stefan Roese | a9c847c | 2011-05-04 11:44:14 +0200 | [diff] [blame] | 103 | while (!this->dev_ready(mtd)) |
| 104 | ; |
Stefan Roese | 46f3738 | 2008-04-08 10:31:00 +0200 | [diff] [blame] | 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | #endif |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 109 | |
| 110 | static int nand_is_bad_block(struct mtd_info *mtd, int block) |
| 111 | { |
| 112 | struct nand_chip *this = mtd->priv; |
| 113 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 114 | nand_command(mtd, block, 0, CONFIG_SYS_NAND_BAD_BLOCK_POS, NAND_CMD_READOOB); |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 115 | |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 116 | /* |
Alex Waterman | eced462 | 2011-05-19 15:08:36 -0400 | [diff] [blame] | 117 | * Read one byte (or two if it's a 16 bit chip). |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 118 | */ |
Alex Waterman | eced462 | 2011-05-19 15:08:36 -0400 | [diff] [blame] | 119 | if (this->options & NAND_BUSWIDTH_16) { |
| 120 | if (readw(this->IO_ADDR_R) != 0xffff) |
| 121 | return 1; |
| 122 | } else { |
| 123 | if (readb(this->IO_ADDR_R) != 0xff) |
| 124 | return 1; |
| 125 | } |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Heiko Schocher | dc7cd8e | 2011-07-16 00:06:49 +0000 | [diff] [blame] | 130 | #if defined(CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST) |
| 131 | static int nand_read_page(struct mtd_info *mtd, int block, int page, uchar *dst) |
| 132 | { |
| 133 | struct nand_chip *this = mtd->priv; |
Scott Wood | 25efd99 | 2012-01-11 15:41:01 -0600 | [diff] [blame] | 134 | u_char ecc_calc[ECCTOTAL]; |
| 135 | u_char ecc_code[ECCTOTAL]; |
| 136 | u_char oob_data[CONFIG_SYS_NAND_OOBSIZE]; |
Heiko Schocher | dc7cd8e | 2011-07-16 00:06:49 +0000 | [diff] [blame] | 137 | int i; |
| 138 | int eccsize = CONFIG_SYS_NAND_ECCSIZE; |
| 139 | int eccbytes = CONFIG_SYS_NAND_ECCBYTES; |
Scott Wood | 25efd99 | 2012-01-11 15:41:01 -0600 | [diff] [blame] | 140 | int eccsteps = ECCSTEPS; |
Heiko Schocher | dc7cd8e | 2011-07-16 00:06:49 +0000 | [diff] [blame] | 141 | uint8_t *p = dst; |
Heiko Schocher | dc7cd8e | 2011-07-16 00:06:49 +0000 | [diff] [blame] | 142 | |
Heiko Schocher | dc7cd8e | 2011-07-16 00:06:49 +0000 | [diff] [blame] | 143 | nand_command(mtd, block, page, 0, NAND_CMD_READOOB); |
| 144 | this->read_buf(mtd, oob_data, CONFIG_SYS_NAND_OOBSIZE); |
| 145 | nand_command(mtd, block, page, 0, NAND_CMD_READ0); |
| 146 | |
| 147 | /* Pick the ECC bytes out of the oob data */ |
Scott Wood | 25efd99 | 2012-01-11 15:41:01 -0600 | [diff] [blame] | 148 | for (i = 0; i < ECCTOTAL; i++) |
Heiko Schocher | dc7cd8e | 2011-07-16 00:06:49 +0000 | [diff] [blame] | 149 | ecc_code[i] = oob_data[nand_ecc_pos[i]]; |
| 150 | |
| 151 | |
| 152 | for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { |
| 153 | this->ecc.hwctl(mtd, NAND_ECC_READ); |
| 154 | this->read_buf(mtd, p, eccsize); |
| 155 | this->ecc.calculate(mtd, p, &ecc_calc[i]); |
Anatolij Gustschin | 40a0682 | 2011-12-07 11:58:56 +0000 | [diff] [blame] | 156 | this->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); |
Heiko Schocher | dc7cd8e | 2011-07-16 00:06:49 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | #else |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 162 | static int nand_read_page(struct mtd_info *mtd, int block, int page, uchar *dst) |
| 163 | { |
Wolfgang Denk | 511d0c7 | 2006-10-09 00:42:01 +0200 | [diff] [blame] | 164 | struct nand_chip *this = mtd->priv; |
Scott Wood | 25efd99 | 2012-01-11 15:41:01 -0600 | [diff] [blame] | 165 | u_char ecc_calc[ECCTOTAL]; |
| 166 | u_char ecc_code[ECCTOTAL]; |
| 167 | u_char oob_data[CONFIG_SYS_NAND_OOBSIZE]; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 168 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 169 | int eccsize = CONFIG_SYS_NAND_ECCSIZE; |
| 170 | int eccbytes = CONFIG_SYS_NAND_ECCBYTES; |
Scott Wood | 25efd99 | 2012-01-11 15:41:01 -0600 | [diff] [blame] | 171 | int eccsteps = ECCSTEPS; |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 172 | uint8_t *p = dst; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 173 | |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 174 | nand_command(mtd, block, page, 0, NAND_CMD_READ0); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 175 | |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 176 | for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { |
Stefan Roese | c568f77 | 2008-01-05 16:49:37 +0100 | [diff] [blame] | 177 | this->ecc.hwctl(mtd, NAND_ECC_READ); |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 178 | this->read_buf(mtd, p, eccsize); |
Stefan Roese | c568f77 | 2008-01-05 16:49:37 +0100 | [diff] [blame] | 179 | this->ecc.calculate(mtd, p, &ecc_calc[i]); |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 180 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 181 | this->read_buf(mtd, oob_data, CONFIG_SYS_NAND_OOBSIZE); |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 182 | |
| 183 | /* Pick the ECC bytes out of the oob data */ |
Scott Wood | 25efd99 | 2012-01-11 15:41:01 -0600 | [diff] [blame] | 184 | for (i = 0; i < ECCTOTAL; i++) |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 185 | ecc_code[i] = oob_data[nand_ecc_pos[i]]; |
| 186 | |
Scott Wood | 25efd99 | 2012-01-11 15:41:01 -0600 | [diff] [blame] | 187 | eccsteps = ECCSTEPS; |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 188 | p = dst; |
| 189 | |
| 190 | for (i = 0 ; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { |
| 191 | /* No chance to do something with the possible error message |
| 192 | * from correct_data(). We just hope that all possible errors |
| 193 | * are corrected by this routine. |
| 194 | */ |
Stefan Roese | 6d68621 | 2011-11-15 08:02:54 +0000 | [diff] [blame] | 195 | this->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); |
Stefan Roese | 42be56f | 2007-06-01 15:23:04 +0200 | [diff] [blame] | 196 | } |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 197 | |
| 198 | return 0; |
| 199 | } |
Heiko Schocher | dc7cd8e | 2011-07-16 00:06:49 +0000 | [diff] [blame] | 200 | #endif /* #if defined(CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST) */ |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 201 | |
Guennadi Liakhovetski | aa64664 | 2008-08-06 21:42:07 +0200 | [diff] [blame] | 202 | static int nand_load(struct mtd_info *mtd, unsigned int offs, |
Wolfgang Denk | 4b07080 | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 203 | unsigned int uboot_size, uchar *dst) |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 204 | { |
Guennadi Liakhovetski | aa64664 | 2008-08-06 21:42:07 +0200 | [diff] [blame] | 205 | unsigned int block, lastblock; |
| 206 | unsigned int page; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 207 | |
| 208 | /* |
Guennadi Liakhovetski | aa64664 | 2008-08-06 21:42:07 +0200 | [diff] [blame] | 209 | * offs has to be aligned to a page address! |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 210 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 211 | block = offs / CONFIG_SYS_NAND_BLOCK_SIZE; |
| 212 | lastblock = (offs + uboot_size - 1) / CONFIG_SYS_NAND_BLOCK_SIZE; |
| 213 | page = (offs % CONFIG_SYS_NAND_BLOCK_SIZE) / CONFIG_SYS_NAND_PAGE_SIZE; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 214 | |
Guennadi Liakhovetski | aa64664 | 2008-08-06 21:42:07 +0200 | [diff] [blame] | 215 | while (block <= lastblock) { |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 216 | if (!nand_is_bad_block(mtd, block)) { |
| 217 | /* |
| 218 | * Skip bad blocks |
| 219 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 220 | while (page < CONFIG_SYS_NAND_PAGE_COUNT) { |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 221 | nand_read_page(mtd, block, page, dst); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 222 | dst += CONFIG_SYS_NAND_PAGE_SIZE; |
Guennadi Liakhovetski | aa64664 | 2008-08-06 21:42:07 +0200 | [diff] [blame] | 223 | page++; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Guennadi Liakhovetski | aa64664 | 2008-08-06 21:42:07 +0200 | [diff] [blame] | 226 | page = 0; |
| 227 | } else { |
| 228 | lastblock++; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | block++; |
| 232 | } |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
Stefan Roese | 64852d0 | 2008-06-02 14:35:44 +0200 | [diff] [blame] | 237 | /* |
| 238 | * The main entry for NAND booting. It's necessary that SDRAM is already |
| 239 | * configured and available since this code loads the main U-Boot image |
| 240 | * from NAND into SDRAM and starts it from there. |
| 241 | */ |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 242 | void nand_boot(void) |
| 243 | { |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 244 | struct nand_chip nand_chip; |
| 245 | nand_info_t nand_info; |
Scott Wood | e4c0950 | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 246 | __attribute__((noreturn)) void (*uboot)(void); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 247 | |
| 248 | /* |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 249 | * Init board specific nand support |
| 250 | */ |
Sughosh Ganu | 48571ff | 2010-11-30 11:25:01 -0500 | [diff] [blame] | 251 | nand_chip.select_chip = NULL; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 252 | nand_info.priv = &nand_chip; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 253 | nand_chip.IO_ADDR_R = nand_chip.IO_ADDR_W = (void __iomem *)CONFIG_SYS_NAND_BASE; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 254 | nand_chip.dev_ready = NULL; /* preset to NULL */ |
Stefan Roese | a89a990 | 2011-05-04 11:44:44 +0200 | [diff] [blame] | 255 | nand_chip.options = 0; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 256 | board_nand_init(&nand_chip); |
| 257 | |
Guennadi Liakhovetski | aa64664 | 2008-08-06 21:42:07 +0200 | [diff] [blame] | 258 | if (nand_chip.select_chip) |
| 259 | nand_chip.select_chip(&nand_info, 0); |
| 260 | |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 261 | /* |
| 262 | * Load U-Boot image from NAND into RAM |
| 263 | */ |
Stefan Roese | 6d68621 | 2011-11-15 08:02:54 +0000 | [diff] [blame] | 264 | nand_load(&nand_info, CONFIG_SYS_NAND_U_BOOT_OFFS, CONFIG_SYS_NAND_U_BOOT_SIZE, |
| 265 | (uchar *)CONFIG_SYS_NAND_U_BOOT_DST); |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 266 | |
Guennadi Liakhovetski | b74ab73 | 2009-05-18 16:07:22 +0200 | [diff] [blame] | 267 | #ifdef CONFIG_NAND_ENV_DST |
| 268 | nand_load(&nand_info, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
| 269 | (uchar *)CONFIG_NAND_ENV_DST); |
| 270 | |
| 271 | #ifdef CONFIG_ENV_OFFSET_REDUND |
| 272 | nand_load(&nand_info, CONFIG_ENV_OFFSET_REDUND, CONFIG_ENV_SIZE, |
| 273 | (uchar *)CONFIG_NAND_ENV_DST + CONFIG_ENV_SIZE); |
| 274 | #endif |
| 275 | #endif |
| 276 | |
Guennadi Liakhovetski | aa64664 | 2008-08-06 21:42:07 +0200 | [diff] [blame] | 277 | if (nand_chip.select_chip) |
| 278 | nand_chip.select_chip(&nand_info, -1); |
| 279 | |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 280 | /* |
| 281 | * Jump to U-Boot image |
| 282 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 283 | uboot = (void *)CONFIG_SYS_NAND_U_BOOT_START; |
Stefan Roese | 887e2ec | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 284 | (*uboot)(); |
| 285 | } |