2 * NAND boot for Freescale Enhanced Local Bus Controller, Flash Control Machine
4 * (C) Copyright 2006-2008
5 * Stefan Roese, DENX Software Engineering, sr@denx.de.
7 * Copyright (c) 2008 Freescale Semiconductor, Inc.
8 * Author: Scott Wood <scottwood@freescale.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <asm/fsl_lbc.h>
31 #define WINDOW_SIZE 8192
33 static void nand_wait(void)
35 fsl_lbc_t *regs = LBC_BASE_ADDR;
38 uint32_t status = in_be32(®s->ltesr);
44 puts("read failed (ltesr)\n");
50 static int nand_load_image(uint32_t offs, unsigned int uboot_size, void *vdst)
52 fsl_lbc_t *regs = LBC_BASE_ADDR;
53 uchar *buf = (uchar *)CONFIG_SYS_NAND_BASE;
54 const int large = CONFIG_SYS_NAND_OR_PRELIM & OR_FCM_PGS;
55 const int block_shift = large ? 17 : 14;
56 const int block_size = 1 << block_shift;
57 const int page_size = large ? 2048 : 512;
58 const int bad_marker = large ? page_size + 0 : page_size + 5;
59 int fmr = (15 << FMR_CWTO_SHIFT) | (2 << FMR_AL_SHIFT) | 2;
63 if (offs & (block_size - 1)) {
70 out_be32(®s->fcr, (NAND_CMD_READ0 << FCR_CMD0_SHIFT) |
71 (NAND_CMD_READSTART << FCR_CMD1_SHIFT));
73 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
74 (FIR_OP_CA << FIR_OP1_SHIFT) |
75 (FIR_OP_PA << FIR_OP2_SHIFT) |
76 (FIR_OP_CW1 << FIR_OP3_SHIFT) |
77 (FIR_OP_RBW << FIR_OP4_SHIFT));
79 out_be32(®s->fcr, NAND_CMD_READ0 << FCR_CMD0_SHIFT);
81 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
82 (FIR_OP_CA << FIR_OP1_SHIFT) |
83 (FIR_OP_PA << FIR_OP2_SHIFT) |
84 (FIR_OP_RBW << FIR_OP3_SHIFT));
87 out_be32(®s->fbcr, 0);
88 clrsetbits_be32(®s->bank[0].br, BR_DECC, BR_DECC_CHK_GEN);
90 while (pos < uboot_size) {
92 out_be32(®s->fbar, offs >> block_shift);
96 unsigned int page_offs = (offs & (block_size - 1)) << 1;
98 out_be32(®s->ltesr, ~0);
99 out_be32(®s->lteatr, 0);
100 out_be32(®s->fpar, page_offs);
101 out_be32(®s->fmr, fmr);
102 out_be32(®s->lsor, 0);
105 page_offs %= WINDOW_SIZE;
108 * If either of the first two pages are marked bad,
109 * continue to the next block.
111 if (i++ < 2 && buf[page_offs + bad_marker] != 0xff) {
113 offs = (offs + block_size) & ~(block_size - 1);
114 pos &= ~(block_size - 1);
118 for (j = 0; j < page_size; j++)
119 dst[pos + j] = buf[page_offs + j];
123 } while ((offs & (block_size - 1)) && (pos < uboot_size));
130 * The main entry for NAND booting. It's necessary that SDRAM is already
131 * configured and available since this code loads the main U-Boot image
132 * from NAND into SDRAM and starts it from there.
136 __attribute__((noreturn)) void (*uboot)(void);
138 * Load U-Boot image from NAND into RAM
140 nand_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
141 CONFIG_SYS_NAND_U_BOOT_SIZE,
142 (void *)CONFIG_SYS_NAND_U_BOOT_DST);
144 #ifdef CONFIG_NAND_ENV_DST
145 nand_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
146 (void *)CONFIG_NAND_ENV_DST);
148 #ifdef CONFIG_ENV_OFFSET_REDUND
149 nand_load_image(CONFIG_ENV_OFFSET_REDUND, CONFIG_ENV_SIZE,
150 (void *)CONFIG_NAND_ENV_DST + CONFIG_ENV_SIZE);
154 #ifdef CONFIG_SPL_FLUSH_IMAGE
156 * Clean d-cache and invalidate i-cache, to
157 * make sure that no stale data is executed.
159 flush_cache(CONFIG_SYS_NAND_U_BOOT_DST, CONFIG_SYS_NAND_U_BOOT_SIZE);
162 puts("transfering control\n");
164 * Jump to U-Boot image
166 uboot = (void *)CONFIG_SYS_NAND_U_BOOT_START;