]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/spl/spl_nand.c
Merge branch 'u-boot-microblaze/zynq' into 'u-boot-arm/master'
[people/ms/u-boot.git] / common / spl / spl_nand.c
CommitLineData
9ea5c6ef
SS
1/*
2 * Copyright (C) 2011
3 * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
9ea5c6ef
SS
6 */
7#include <common.h>
d97b4ce8 8#include <config.h>
47f7bcae 9#include <spl.h>
df163a59 10#include <asm/io.h>
9ea5c6ef 11#include <nand.h>
9ea5c6ef 12
9ea5c6ef
SS
13void spl_nand_load_image(void)
14{
15 struct image_header *header;
df163a59
SS
16 int *src __attribute__((unused));
17 int *dst __attribute__((unused));
18
8082fda9 19 debug("spl: nand - using hw ecc\n");
8082fda9 20 nand_init();
9ea5c6ef
SS
21
22 /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
23 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
df163a59 24#ifdef CONFIG_SPL_OS_BOOT
379c19ab 25 if (!spl_start_uboot()) {
df163a59
SS
26 /*
27 * load parameter image
28 * load to temp position since nand_spl_load_image reads
29 * a whole block which is typically larger than
b6e95fd4 30 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
df163a59
SS
31 * following sections like BSS
32 */
33 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
34 CONFIG_CMD_SPL_WRITE_SIZE,
35 (void *)CONFIG_SYS_TEXT_BASE);
36 /* copy to destintion */
37 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
38 src = (int *)CONFIG_SYS_TEXT_BASE;
39 src < (int *)(CONFIG_SYS_TEXT_BASE +
40 CONFIG_CMD_SPL_WRITE_SIZE);
41 src++, dst++) {
42 writel(readl(src), dst);
43 }
9ea5c6ef 44
df163a59
SS
45 /* load linux */
46 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
47 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
48 spl_parse_image_header(header);
379c19ab
SS
49 if (header->ih_os == IH_OS_LINUX) {
50 /* happy - was a linux */
51 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
52 spl_image.size, (void *)spl_image.load_addr);
53 nand_deselect();
54 return;
55 } else {
d97b4ce8
TR
56 puts("The Expected Linux image was not "
57 "found. Please check your NAND "
379c19ab 58 "configuration.\n");
d97b4ce8 59 puts("Trying to start u-boot now...\n");
379c19ab
SS
60 }
61 }
df163a59 62#endif
9ea5c6ef 63#ifdef CONFIG_NAND_ENV_DST
379c19ab
SS
64 nand_spl_load_image(CONFIG_ENV_OFFSET,
65 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
66 spl_parse_image_header(header);
67 nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
68 (void *)spl_image.load_addr);
9ea5c6ef 69#ifdef CONFIG_ENV_OFFSET_REDUND
379c19ab
SS
70 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
71 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
72 spl_parse_image_header(header);
73 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
74 (void *)spl_image.load_addr);
9ea5c6ef
SS
75#endif
76#endif
379c19ab
SS
77 /* Load u-boot */
78 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
50c8d66d 79 sizeof(*header), (void *)header);
379c19ab
SS
80 spl_parse_image_header(header);
81 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
82 spl_image.size, (void *)spl_image.load_addr);
9ea5c6ef
SS
83 nand_deselect();
84}