]> Git Repo - u-boot.git/blame - common/spl/spl_nand.c
imx: imx-common: print i.MX 7 SoC names consistently
[u-boot.git] / common / spl / spl_nand.c
CommitLineData
9ea5c6ef
SS
1/*
2 * Copyright (C) 2011
3 * Corscience GmbH & Co. KG - Simon Schwarz <[email protected]>
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
0c3117b1 13#if defined(CONFIG_SPL_NAND_RAW_ONLY)
36afd451 14int spl_nand_load_image(void)
0c3117b1
HS
15{
16 nand_init();
17
18 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
19 CONFIG_SYS_NAND_U_BOOT_SIZE,
20 (void *)CONFIG_SYS_NAND_U_BOOT_DST);
21 spl_set_header_raw_uboot();
22 nand_deselect();
36afd451
NK
23
24 return 0;
0c3117b1
HS
25}
26#else
483ab3dc
NK
27static int spl_nand_load_element(int offset, struct image_header *header)
28{
29 int err;
30
31 err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
32 if (err)
33 return err;
34
35 spl_parse_image_header(header);
36 return nand_spl_load_image(offset, spl_image.size,
37 (void *)(unsigned long)spl_image.load_addr);
38}
39
36afd451 40int spl_nand_load_image(void)
9ea5c6ef 41{
36afd451 42 int err;
9ea5c6ef 43 struct image_header *header;
df163a59
SS
44 int *src __attribute__((unused));
45 int *dst __attribute__((unused));
46
8122d216
ASK
47#ifdef CONFIG_SPL_NAND_SOFTECC
48 debug("spl: nand - using sw ecc\n");
49#else
8082fda9 50 debug("spl: nand - using hw ecc\n");
8122d216 51#endif
8082fda9 52 nand_init();
9ea5c6ef
SS
53
54 /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
55 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
df163a59 56#ifdef CONFIG_SPL_OS_BOOT
379c19ab 57 if (!spl_start_uboot()) {
df163a59
SS
58 /*
59 * load parameter image
60 * load to temp position since nand_spl_load_image reads
61 * a whole block which is typically larger than
b6e95fd4 62 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
df163a59
SS
63 * following sections like BSS
64 */
65 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
66 CONFIG_CMD_SPL_WRITE_SIZE,
67 (void *)CONFIG_SYS_TEXT_BASE);
68 /* copy to destintion */
69 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
70 src = (int *)CONFIG_SYS_TEXT_BASE;
71 src < (int *)(CONFIG_SYS_TEXT_BASE +
72 CONFIG_CMD_SPL_WRITE_SIZE);
73 src++, dst++) {
74 writel(readl(src), dst);
75 }
9ea5c6ef 76
df163a59
SS
77 /* load linux */
78 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
c13bb167 79 sizeof(*header), (void *)header);
df163a59 80 spl_parse_image_header(header);
379c19ab
SS
81 if (header->ih_os == IH_OS_LINUX) {
82 /* happy - was a linux */
36afd451
NK
83 err = nand_spl_load_image(
84 CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
85 spl_image.size,
86 (void *)spl_image.load_addr);
379c19ab 87 nand_deselect();
36afd451 88 return err;
379c19ab 89 } else {
d97b4ce8
TR
90 puts("The Expected Linux image was not "
91 "found. Please check your NAND "
379c19ab 92 "configuration.\n");
d97b4ce8 93 puts("Trying to start u-boot now...\n");
379c19ab
SS
94 }
95 }
df163a59 96#endif
9ea5c6ef 97#ifdef CONFIG_NAND_ENV_DST
483ab3dc 98 spl_nand_load_element(CONFIG_ENV_OFFSET, header);
9ea5c6ef 99#ifdef CONFIG_ENV_OFFSET_REDUND
483ab3dc 100 spl_nand_load_element(CONFIG_ENV_OFFSET_REDUND, header);
9ea5c6ef
SS
101#endif
102#endif
379c19ab 103 /* Load u-boot */
36afd451 104 err = spl_nand_load_element(CONFIG_SYS_NAND_U_BOOT_OFFS, header);
9ea5c6ef 105 nand_deselect();
36afd451 106 return err;
9ea5c6ef 107}
0c3117b1 108#endif
This page took 0.170399 seconds and 4 git commands to generate.