1*cfcc706cSMiquel Raynal /*
2*cfcc706cSMiquel Raynal * (C) Copyright 2009
3*cfcc706cSMiquel Raynal * Magnus Lilja <lilja.magnus@gmail.com>
4*cfcc706cSMiquel Raynal *
5*cfcc706cSMiquel Raynal * (C) Copyright 2008
6*cfcc706cSMiquel Raynal * Maxim Artamonov, <scn1874 at yandex.ru>
7*cfcc706cSMiquel Raynal *
8*cfcc706cSMiquel Raynal * (C) Copyright 2006-2008
9*cfcc706cSMiquel Raynal * Stefan Roese, DENX Software Engineering, sr at denx.de.
10*cfcc706cSMiquel Raynal *
11*cfcc706cSMiquel Raynal * SPDX-License-Identifier: GPL-2.0+
12*cfcc706cSMiquel Raynal */
13*cfcc706cSMiquel Raynal
14*cfcc706cSMiquel Raynal #include <common.h>
15*cfcc706cSMiquel Raynal #include <nand.h>
16*cfcc706cSMiquel Raynal #include <asm/arch/imx-regs.h>
17*cfcc706cSMiquel Raynal #include <asm/io.h>
18*cfcc706cSMiquel Raynal #include "mxc_nand.h"
19*cfcc706cSMiquel Raynal
20*cfcc706cSMiquel Raynal #if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
21*cfcc706cSMiquel Raynal static struct mxc_nand_regs *const nfc = (void *)NFC_BASE_ADDR;
22*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V3_2)
23*cfcc706cSMiquel Raynal static struct mxc_nand_regs *const nfc = (void *)NFC_BASE_ADDR_AXI;
24*cfcc706cSMiquel Raynal static struct mxc_nand_ip_regs *const nfc_ip = (void *)NFC_BASE_ADDR;
25*cfcc706cSMiquel Raynal #endif
26*cfcc706cSMiquel Raynal
nfc_wait_ready(void)27*cfcc706cSMiquel Raynal static void nfc_wait_ready(void)
28*cfcc706cSMiquel Raynal {
29*cfcc706cSMiquel Raynal uint32_t tmp;
30*cfcc706cSMiquel Raynal
31*cfcc706cSMiquel Raynal #if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
32*cfcc706cSMiquel Raynal while (!(readnfc(&nfc->config2) & NFC_V1_V2_CONFIG2_INT))
33*cfcc706cSMiquel Raynal ;
34*cfcc706cSMiquel Raynal
35*cfcc706cSMiquel Raynal /* Reset interrupt flag */
36*cfcc706cSMiquel Raynal tmp = readnfc(&nfc->config2);
37*cfcc706cSMiquel Raynal tmp &= ~NFC_V1_V2_CONFIG2_INT;
38*cfcc706cSMiquel Raynal writenfc(tmp, &nfc->config2);
39*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V3_2)
40*cfcc706cSMiquel Raynal while (!(readnfc(&nfc_ip->ipc) & NFC_V3_IPC_INT))
41*cfcc706cSMiquel Raynal ;
42*cfcc706cSMiquel Raynal
43*cfcc706cSMiquel Raynal /* Reset interrupt flag */
44*cfcc706cSMiquel Raynal tmp = readnfc(&nfc_ip->ipc);
45*cfcc706cSMiquel Raynal tmp &= ~NFC_V3_IPC_INT;
46*cfcc706cSMiquel Raynal writenfc(tmp, &nfc_ip->ipc);
47*cfcc706cSMiquel Raynal #endif
48*cfcc706cSMiquel Raynal }
49*cfcc706cSMiquel Raynal
nfc_nand_init(void)50*cfcc706cSMiquel Raynal static void nfc_nand_init(void)
51*cfcc706cSMiquel Raynal {
52*cfcc706cSMiquel Raynal #if defined(MXC_NFC_V3_2)
53*cfcc706cSMiquel Raynal int ecc_per_page = CONFIG_SYS_NAND_PAGE_SIZE / 512;
54*cfcc706cSMiquel Raynal int tmp;
55*cfcc706cSMiquel Raynal
56*cfcc706cSMiquel Raynal tmp = (readnfc(&nfc_ip->config2) & ~(NFC_V3_CONFIG2_SPAS_MASK |
57*cfcc706cSMiquel Raynal NFC_V3_CONFIG2_EDC_MASK | NFC_V3_CONFIG2_PS_MASK)) |
58*cfcc706cSMiquel Raynal NFC_V3_CONFIG2_SPAS(CONFIG_SYS_NAND_OOBSIZE / 2) |
59*cfcc706cSMiquel Raynal NFC_V3_CONFIG2_INT_MSK | NFC_V3_CONFIG2_ECC_EN |
60*cfcc706cSMiquel Raynal NFC_V3_CONFIG2_ONE_CYCLE;
61*cfcc706cSMiquel Raynal if (CONFIG_SYS_NAND_PAGE_SIZE == 4096)
62*cfcc706cSMiquel Raynal tmp |= NFC_V3_CONFIG2_PS_4096;
63*cfcc706cSMiquel Raynal else if (CONFIG_SYS_NAND_PAGE_SIZE == 2048)
64*cfcc706cSMiquel Raynal tmp |= NFC_V3_CONFIG2_PS_2048;
65*cfcc706cSMiquel Raynal else if (CONFIG_SYS_NAND_PAGE_SIZE == 512)
66*cfcc706cSMiquel Raynal tmp |= NFC_V3_CONFIG2_PS_512;
67*cfcc706cSMiquel Raynal /*
68*cfcc706cSMiquel Raynal * if spare size is larger that 16 bytes per 512 byte hunk
69*cfcc706cSMiquel Raynal * then use 8 symbol correction instead of 4
70*cfcc706cSMiquel Raynal */
71*cfcc706cSMiquel Raynal if (CONFIG_SYS_NAND_OOBSIZE / ecc_per_page > 16)
72*cfcc706cSMiquel Raynal tmp |= NFC_V3_CONFIG2_ECC_MODE_8;
73*cfcc706cSMiquel Raynal else
74*cfcc706cSMiquel Raynal tmp &= ~NFC_V3_CONFIG2_ECC_MODE_8;
75*cfcc706cSMiquel Raynal writenfc(tmp, &nfc_ip->config2);
76*cfcc706cSMiquel Raynal
77*cfcc706cSMiquel Raynal tmp = NFC_V3_CONFIG3_NUM_OF_DEVS(0) |
78*cfcc706cSMiquel Raynal NFC_V3_CONFIG3_NO_SDMA |
79*cfcc706cSMiquel Raynal NFC_V3_CONFIG3_RBB_MODE |
80*cfcc706cSMiquel Raynal NFC_V3_CONFIG3_SBB(6) | /* Reset default */
81*cfcc706cSMiquel Raynal NFC_V3_CONFIG3_ADD_OP(0);
82*cfcc706cSMiquel Raynal #ifndef CONFIG_SYS_NAND_BUSWIDTH_16
83*cfcc706cSMiquel Raynal tmp |= NFC_V3_CONFIG3_FW8;
84*cfcc706cSMiquel Raynal #endif
85*cfcc706cSMiquel Raynal writenfc(tmp, &nfc_ip->config3);
86*cfcc706cSMiquel Raynal
87*cfcc706cSMiquel Raynal writenfc(0, &nfc_ip->delay_line);
88*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V2_1)
89*cfcc706cSMiquel Raynal int ecc_per_page = CONFIG_SYS_NAND_PAGE_SIZE / 512;
90*cfcc706cSMiquel Raynal int config1;
91*cfcc706cSMiquel Raynal
92*cfcc706cSMiquel Raynal writenfc(CONFIG_SYS_NAND_OOBSIZE / 2, &nfc->spare_area_size);
93*cfcc706cSMiquel Raynal
94*cfcc706cSMiquel Raynal /* unlocking RAM Buff */
95*cfcc706cSMiquel Raynal writenfc(0x2, &nfc->config);
96*cfcc706cSMiquel Raynal
97*cfcc706cSMiquel Raynal /* hardware ECC checking and correct */
98*cfcc706cSMiquel Raynal config1 = readnfc(&nfc->config1) | NFC_V1_V2_CONFIG1_ECC_EN |
99*cfcc706cSMiquel Raynal NFC_V1_V2_CONFIG1_INT_MSK | NFC_V2_CONFIG1_ONE_CYCLE |
100*cfcc706cSMiquel Raynal NFC_V2_CONFIG1_FP_INT;
101*cfcc706cSMiquel Raynal /*
102*cfcc706cSMiquel Raynal * if spare size is larger that 16 bytes per 512 byte hunk
103*cfcc706cSMiquel Raynal * then use 8 symbol correction instead of 4
104*cfcc706cSMiquel Raynal */
105*cfcc706cSMiquel Raynal if (CONFIG_SYS_NAND_OOBSIZE / ecc_per_page > 16)
106*cfcc706cSMiquel Raynal config1 &= ~NFC_V2_CONFIG1_ECC_MODE_4;
107*cfcc706cSMiquel Raynal else
108*cfcc706cSMiquel Raynal config1 |= NFC_V2_CONFIG1_ECC_MODE_4;
109*cfcc706cSMiquel Raynal writenfc(config1, &nfc->config1);
110*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V1)
111*cfcc706cSMiquel Raynal /* unlocking RAM Buff */
112*cfcc706cSMiquel Raynal writenfc(0x2, &nfc->config);
113*cfcc706cSMiquel Raynal
114*cfcc706cSMiquel Raynal /* hardware ECC checking and correct */
115*cfcc706cSMiquel Raynal writenfc(NFC_V1_V2_CONFIG1_ECC_EN | NFC_V1_V2_CONFIG1_INT_MSK,
116*cfcc706cSMiquel Raynal &nfc->config1);
117*cfcc706cSMiquel Raynal #endif
118*cfcc706cSMiquel Raynal }
119*cfcc706cSMiquel Raynal
nfc_nand_command(unsigned short command)120*cfcc706cSMiquel Raynal static void nfc_nand_command(unsigned short command)
121*cfcc706cSMiquel Raynal {
122*cfcc706cSMiquel Raynal writenfc(command, &nfc->flash_cmd);
123*cfcc706cSMiquel Raynal writenfc(NFC_CMD, &nfc->operation);
124*cfcc706cSMiquel Raynal nfc_wait_ready();
125*cfcc706cSMiquel Raynal }
126*cfcc706cSMiquel Raynal
nfc_nand_address(unsigned short address)127*cfcc706cSMiquel Raynal static void nfc_nand_address(unsigned short address)
128*cfcc706cSMiquel Raynal {
129*cfcc706cSMiquel Raynal writenfc(address, &nfc->flash_addr);
130*cfcc706cSMiquel Raynal writenfc(NFC_ADDR, &nfc->operation);
131*cfcc706cSMiquel Raynal nfc_wait_ready();
132*cfcc706cSMiquel Raynal }
133*cfcc706cSMiquel Raynal
nfc_nand_page_address(unsigned int page_address)134*cfcc706cSMiquel Raynal static void nfc_nand_page_address(unsigned int page_address)
135*cfcc706cSMiquel Raynal {
136*cfcc706cSMiquel Raynal unsigned int page_count;
137*cfcc706cSMiquel Raynal
138*cfcc706cSMiquel Raynal nfc_nand_address(0x00);
139*cfcc706cSMiquel Raynal
140*cfcc706cSMiquel Raynal /* code only for large page flash */
141*cfcc706cSMiquel Raynal if (CONFIG_SYS_NAND_PAGE_SIZE > 512)
142*cfcc706cSMiquel Raynal nfc_nand_address(0x00);
143*cfcc706cSMiquel Raynal
144*cfcc706cSMiquel Raynal page_count = CONFIG_SYS_NAND_SIZE / CONFIG_SYS_NAND_PAGE_SIZE;
145*cfcc706cSMiquel Raynal
146*cfcc706cSMiquel Raynal if (page_address <= page_count) {
147*cfcc706cSMiquel Raynal page_count--; /* transform 0x01000000 to 0x00ffffff */
148*cfcc706cSMiquel Raynal do {
149*cfcc706cSMiquel Raynal nfc_nand_address(page_address & 0xff);
150*cfcc706cSMiquel Raynal page_address = page_address >> 8;
151*cfcc706cSMiquel Raynal page_count = page_count >> 8;
152*cfcc706cSMiquel Raynal } while (page_count);
153*cfcc706cSMiquel Raynal }
154*cfcc706cSMiquel Raynal
155*cfcc706cSMiquel Raynal nfc_nand_address(0x00);
156*cfcc706cSMiquel Raynal }
157*cfcc706cSMiquel Raynal
nfc_nand_data_output(void)158*cfcc706cSMiquel Raynal static void nfc_nand_data_output(void)
159*cfcc706cSMiquel Raynal {
160*cfcc706cSMiquel Raynal #ifdef NAND_MXC_2K_MULTI_CYCLE
161*cfcc706cSMiquel Raynal int i;
162*cfcc706cSMiquel Raynal #endif
163*cfcc706cSMiquel Raynal
164*cfcc706cSMiquel Raynal #if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
165*cfcc706cSMiquel Raynal writenfc(0, &nfc->buf_addr);
166*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V3_2)
167*cfcc706cSMiquel Raynal int config1 = readnfc(&nfc->config1);
168*cfcc706cSMiquel Raynal config1 &= ~NFC_V3_CONFIG1_RBA_MASK;
169*cfcc706cSMiquel Raynal writenfc(config1, &nfc->config1);
170*cfcc706cSMiquel Raynal #endif
171*cfcc706cSMiquel Raynal writenfc(NFC_OUTPUT, &nfc->operation);
172*cfcc706cSMiquel Raynal nfc_wait_ready();
173*cfcc706cSMiquel Raynal #ifdef NAND_MXC_2K_MULTI_CYCLE
174*cfcc706cSMiquel Raynal /*
175*cfcc706cSMiquel Raynal * This NAND controller requires multiple input commands
176*cfcc706cSMiquel Raynal * for pages larger than 512 bytes.
177*cfcc706cSMiquel Raynal */
178*cfcc706cSMiquel Raynal for (i = 1; i < CONFIG_SYS_NAND_PAGE_SIZE / 512; i++) {
179*cfcc706cSMiquel Raynal writenfc(i, &nfc->buf_addr);
180*cfcc706cSMiquel Raynal writenfc(NFC_OUTPUT, &nfc->operation);
181*cfcc706cSMiquel Raynal nfc_wait_ready();
182*cfcc706cSMiquel Raynal }
183*cfcc706cSMiquel Raynal #endif
184*cfcc706cSMiquel Raynal }
185*cfcc706cSMiquel Raynal
nfc_nand_check_ecc(void)186*cfcc706cSMiquel Raynal static int nfc_nand_check_ecc(void)
187*cfcc706cSMiquel Raynal {
188*cfcc706cSMiquel Raynal #if defined(MXC_NFC_V1)
189*cfcc706cSMiquel Raynal u16 ecc_status = readw(&nfc->ecc_status_result);
190*cfcc706cSMiquel Raynal return (ecc_status & 0x3) == 2 || (ecc_status >> 2) == 2;
191*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V2_1) || defined(MXC_NFC_V3_2)
192*cfcc706cSMiquel Raynal u32 ecc_status = readl(&nfc->ecc_status_result);
193*cfcc706cSMiquel Raynal int ecc_per_page = CONFIG_SYS_NAND_PAGE_SIZE / 512;
194*cfcc706cSMiquel Raynal int err_limit = CONFIG_SYS_NAND_OOBSIZE / ecc_per_page > 16 ? 8 : 4;
195*cfcc706cSMiquel Raynal int subpages = CONFIG_SYS_NAND_PAGE_SIZE / 512;
196*cfcc706cSMiquel Raynal
197*cfcc706cSMiquel Raynal do {
198*cfcc706cSMiquel Raynal if ((ecc_status & 0xf) > err_limit)
199*cfcc706cSMiquel Raynal return 1;
200*cfcc706cSMiquel Raynal ecc_status >>= 4;
201*cfcc706cSMiquel Raynal } while (--subpages);
202*cfcc706cSMiquel Raynal
203*cfcc706cSMiquel Raynal return 0;
204*cfcc706cSMiquel Raynal #endif
205*cfcc706cSMiquel Raynal }
206*cfcc706cSMiquel Raynal
nfc_nand_read_page(unsigned int page_address)207*cfcc706cSMiquel Raynal static void nfc_nand_read_page(unsigned int page_address)
208*cfcc706cSMiquel Raynal {
209*cfcc706cSMiquel Raynal /* read in first 0 buffer */
210*cfcc706cSMiquel Raynal #if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
211*cfcc706cSMiquel Raynal writenfc(0, &nfc->buf_addr);
212*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V3_2)
213*cfcc706cSMiquel Raynal int config1 = readnfc(&nfc->config1);
214*cfcc706cSMiquel Raynal config1 &= ~NFC_V3_CONFIG1_RBA_MASK;
215*cfcc706cSMiquel Raynal writenfc(config1, &nfc->config1);
216*cfcc706cSMiquel Raynal #endif
217*cfcc706cSMiquel Raynal nfc_nand_command(NAND_CMD_READ0);
218*cfcc706cSMiquel Raynal nfc_nand_page_address(page_address);
219*cfcc706cSMiquel Raynal
220*cfcc706cSMiquel Raynal if (CONFIG_SYS_NAND_PAGE_SIZE > 512)
221*cfcc706cSMiquel Raynal nfc_nand_command(NAND_CMD_READSTART);
222*cfcc706cSMiquel Raynal
223*cfcc706cSMiquel Raynal nfc_nand_data_output(); /* fill the main buffer 0 */
224*cfcc706cSMiquel Raynal }
225*cfcc706cSMiquel Raynal
nfc_read_page(unsigned int page_address,unsigned char * buf)226*cfcc706cSMiquel Raynal static int nfc_read_page(unsigned int page_address, unsigned char *buf)
227*cfcc706cSMiquel Raynal {
228*cfcc706cSMiquel Raynal int i;
229*cfcc706cSMiquel Raynal u32 *src;
230*cfcc706cSMiquel Raynal u32 *dst;
231*cfcc706cSMiquel Raynal
232*cfcc706cSMiquel Raynal nfc_nand_read_page(page_address);
233*cfcc706cSMiquel Raynal
234*cfcc706cSMiquel Raynal if (nfc_nand_check_ecc())
235*cfcc706cSMiquel Raynal return -EBADMSG;
236*cfcc706cSMiquel Raynal
237*cfcc706cSMiquel Raynal src = (u32 *)&nfc->main_area[0][0];
238*cfcc706cSMiquel Raynal dst = (u32 *)buf;
239*cfcc706cSMiquel Raynal
240*cfcc706cSMiquel Raynal /* main copy loop from NAND-buffer to SDRAM memory */
241*cfcc706cSMiquel Raynal for (i = 0; i < CONFIG_SYS_NAND_PAGE_SIZE / 4; i++) {
242*cfcc706cSMiquel Raynal writel(readl(src), dst);
243*cfcc706cSMiquel Raynal src++;
244*cfcc706cSMiquel Raynal dst++;
245*cfcc706cSMiquel Raynal }
246*cfcc706cSMiquel Raynal
247*cfcc706cSMiquel Raynal return 0;
248*cfcc706cSMiquel Raynal }
249*cfcc706cSMiquel Raynal
is_badblock(int pagenumber)250*cfcc706cSMiquel Raynal static int is_badblock(int pagenumber)
251*cfcc706cSMiquel Raynal {
252*cfcc706cSMiquel Raynal int page = pagenumber;
253*cfcc706cSMiquel Raynal u32 badblock;
254*cfcc706cSMiquel Raynal u32 *src;
255*cfcc706cSMiquel Raynal
256*cfcc706cSMiquel Raynal /* Check the first two pages for bad block markers */
257*cfcc706cSMiquel Raynal for (page = pagenumber; page < pagenumber + 2; page++) {
258*cfcc706cSMiquel Raynal nfc_nand_read_page(page);
259*cfcc706cSMiquel Raynal
260*cfcc706cSMiquel Raynal src = (u32 *)&nfc->spare_area[0][0];
261*cfcc706cSMiquel Raynal
262*cfcc706cSMiquel Raynal /*
263*cfcc706cSMiquel Raynal * IMPORTANT NOTE: The nand flash controller uses a non-
264*cfcc706cSMiquel Raynal * standard layout for large page devices. This can
265*cfcc706cSMiquel Raynal * affect the position of the bad block marker.
266*cfcc706cSMiquel Raynal */
267*cfcc706cSMiquel Raynal /* Get the bad block marker */
268*cfcc706cSMiquel Raynal badblock = readl(&src[CONFIG_SYS_NAND_BAD_BLOCK_POS / 4]);
269*cfcc706cSMiquel Raynal badblock >>= 8 * (CONFIG_SYS_NAND_BAD_BLOCK_POS % 4);
270*cfcc706cSMiquel Raynal badblock &= 0xff;
271*cfcc706cSMiquel Raynal
272*cfcc706cSMiquel Raynal /* bad block marker verify */
273*cfcc706cSMiquel Raynal if (badblock != 0xff)
274*cfcc706cSMiquel Raynal return 1; /* potential bad block */
275*cfcc706cSMiquel Raynal }
276*cfcc706cSMiquel Raynal
277*cfcc706cSMiquel Raynal return 0;
278*cfcc706cSMiquel Raynal }
279*cfcc706cSMiquel Raynal
nand_spl_load_image(uint32_t from,unsigned int size,void * buf)280*cfcc706cSMiquel Raynal int nand_spl_load_image(uint32_t from, unsigned int size, void *buf)
281*cfcc706cSMiquel Raynal {
282*cfcc706cSMiquel Raynal int i;
283*cfcc706cSMiquel Raynal unsigned int page;
284*cfcc706cSMiquel Raynal unsigned int maxpages = CONFIG_SYS_NAND_SIZE /
285*cfcc706cSMiquel Raynal CONFIG_SYS_NAND_PAGE_SIZE;
286*cfcc706cSMiquel Raynal
287*cfcc706cSMiquel Raynal nfc_nand_init();
288*cfcc706cSMiquel Raynal
289*cfcc706cSMiquel Raynal /* Convert to page number */
290*cfcc706cSMiquel Raynal page = from / CONFIG_SYS_NAND_PAGE_SIZE;
291*cfcc706cSMiquel Raynal i = 0;
292*cfcc706cSMiquel Raynal
293*cfcc706cSMiquel Raynal size = roundup(size, CONFIG_SYS_NAND_PAGE_SIZE);
294*cfcc706cSMiquel Raynal while (i < size / CONFIG_SYS_NAND_PAGE_SIZE) {
295*cfcc706cSMiquel Raynal if (nfc_read_page(page, buf) < 0)
296*cfcc706cSMiquel Raynal return -1;
297*cfcc706cSMiquel Raynal
298*cfcc706cSMiquel Raynal page++;
299*cfcc706cSMiquel Raynal i++;
300*cfcc706cSMiquel Raynal buf = buf + CONFIG_SYS_NAND_PAGE_SIZE;
301*cfcc706cSMiquel Raynal
302*cfcc706cSMiquel Raynal /*
303*cfcc706cSMiquel Raynal * Check if we have crossed a block boundary, and if so
304*cfcc706cSMiquel Raynal * check for bad block.
305*cfcc706cSMiquel Raynal */
306*cfcc706cSMiquel Raynal if (!(page % CONFIG_SYS_NAND_PAGE_COUNT)) {
307*cfcc706cSMiquel Raynal /*
308*cfcc706cSMiquel Raynal * Yes, new block. See if this block is good. If not,
309*cfcc706cSMiquel Raynal * loop until we find a good block.
310*cfcc706cSMiquel Raynal */
311*cfcc706cSMiquel Raynal while (is_badblock(page)) {
312*cfcc706cSMiquel Raynal page = page + CONFIG_SYS_NAND_PAGE_COUNT;
313*cfcc706cSMiquel Raynal /* Check i we've reached the end of flash. */
314*cfcc706cSMiquel Raynal if (page >= maxpages)
315*cfcc706cSMiquel Raynal return -1;
316*cfcc706cSMiquel Raynal }
317*cfcc706cSMiquel Raynal }
318*cfcc706cSMiquel Raynal }
319*cfcc706cSMiquel Raynal
320*cfcc706cSMiquel Raynal return 0;
321*cfcc706cSMiquel Raynal }
322*cfcc706cSMiquel Raynal
323*cfcc706cSMiquel Raynal #ifndef CONFIG_SPL_FRAMEWORK
324*cfcc706cSMiquel Raynal /*
325*cfcc706cSMiquel Raynal * The main entry for NAND booting. It's necessary that SDRAM is already
326*cfcc706cSMiquel Raynal * configured and available since this code loads the main U-Boot image
327*cfcc706cSMiquel Raynal * from NAND into SDRAM and starts it from there.
328*cfcc706cSMiquel Raynal */
nand_boot(void)329*cfcc706cSMiquel Raynal void nand_boot(void)
330*cfcc706cSMiquel Raynal {
331*cfcc706cSMiquel Raynal __attribute__((noreturn)) void (*uboot)(void);
332*cfcc706cSMiquel Raynal
333*cfcc706cSMiquel Raynal /*
334*cfcc706cSMiquel Raynal * CONFIG_SYS_NAND_U_BOOT_OFFS and CONFIG_SYS_NAND_U_BOOT_SIZE must
335*cfcc706cSMiquel Raynal * be aligned to full pages
336*cfcc706cSMiquel Raynal */
337*cfcc706cSMiquel Raynal if (!nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
338*cfcc706cSMiquel Raynal CONFIG_SYS_NAND_U_BOOT_SIZE,
339*cfcc706cSMiquel Raynal (uchar *)CONFIG_SYS_NAND_U_BOOT_DST)) {
340*cfcc706cSMiquel Raynal /* Copy from NAND successful, start U-Boot */
341*cfcc706cSMiquel Raynal uboot = (void *)CONFIG_SYS_NAND_U_BOOT_START;
342*cfcc706cSMiquel Raynal uboot();
343*cfcc706cSMiquel Raynal } else {
344*cfcc706cSMiquel Raynal /* Unrecoverable error when copying from NAND */
345*cfcc706cSMiquel Raynal hang();
346*cfcc706cSMiquel Raynal }
347*cfcc706cSMiquel Raynal }
348*cfcc706cSMiquel Raynal #endif
349*cfcc706cSMiquel Raynal
nand_init(void)350*cfcc706cSMiquel Raynal void nand_init(void) {}
nand_deselect(void)351*cfcc706cSMiquel Raynal void nand_deselect(void) {}
352