blob: b7801cb4605f16c54c99f65e3e8ed93db5d3e564 [file] [log] [blame]
Simon Schwarze21d2d82011-09-14 15:33:34 -04001/*
2 * Copyright (C) 2011
3 * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Simon Schwarze21d2d82011-09-14 15:33:34 -04006 */
7#include <common.h>
Tom Rini9ef51bd2012-08-14 14:33:02 -07008#include <config.h>
Tom Rini28591df2012-08-13 12:03:19 -07009#include <spl.h>
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000010#include <asm/io.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040011#include <nand.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040012
Heiko Schochercf000272014-10-31 08:31:00 +010013#if defined(CONFIG_SPL_NAND_RAW_ONLY)
Simon Schwarze21d2d82011-09-14 15:33:34 -040014void spl_nand_load_image(void)
15{
Heiko Schochercf000272014-10-31 08:31:00 +010016 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();
23}
24#else
25void spl_nand_load_image(void)
26{
Simon Schwarze21d2d82011-09-14 15:33:34 -040027 struct image_header *header;
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000028 int *src __attribute__((unused));
29 int *dst __attribute__((unused));
30
Tom Rini09ebf1a2012-08-13 14:11:06 -070031 debug("spl: nand - using hw ecc\n");
Tom Rini09ebf1a2012-08-13 14:11:06 -070032 nand_init();
Simon Schwarze21d2d82011-09-14 15:33:34 -040033
34 /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
35 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000036#ifdef CONFIG_SPL_OS_BOOT
Simon Schwarz305bc4c2012-03-15 04:01:38 +000037 if (!spl_start_uboot()) {
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000038 /*
39 * load parameter image
40 * load to temp position since nand_spl_load_image reads
41 * a whole block which is typically larger than
Marek Vasut6d016762012-03-31 07:47:17 +000042 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000043 * following sections like BSS
44 */
45 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
46 CONFIG_CMD_SPL_WRITE_SIZE,
47 (void *)CONFIG_SYS_TEXT_BASE);
48 /* copy to destintion */
49 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
50 src = (int *)CONFIG_SYS_TEXT_BASE;
51 src < (int *)(CONFIG_SYS_TEXT_BASE +
52 CONFIG_CMD_SPL_WRITE_SIZE);
53 src++, dst++) {
54 writel(readl(src), dst);
55 }
Simon Schwarze21d2d82011-09-14 15:33:34 -040056
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000057 /* load linux */
58 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
Masahiro Yamadaeac6cd62014-07-10 20:43:16 +090059 sizeof(*header), (void *)header);
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000060 spl_parse_image_header(header);
Simon Schwarz305bc4c2012-03-15 04:01:38 +000061 if (header->ih_os == IH_OS_LINUX) {
62 /* happy - was a linux */
63 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
64 spl_image.size, (void *)spl_image.load_addr);
65 nand_deselect();
66 return;
67 } else {
Tom Rini9ef51bd2012-08-14 14:33:02 -070068 puts("The Expected Linux image was not "
69 "found. Please check your NAND "
Simon Schwarz305bc4c2012-03-15 04:01:38 +000070 "configuration.\n");
Tom Rini9ef51bd2012-08-14 14:33:02 -070071 puts("Trying to start u-boot now...\n");
Simon Schwarz305bc4c2012-03-15 04:01:38 +000072 }
73 }
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000074#endif
Simon Schwarze21d2d82011-09-14 15:33:34 -040075#ifdef CONFIG_NAND_ENV_DST
Simon Schwarz305bc4c2012-03-15 04:01:38 +000076 nand_spl_load_image(CONFIG_ENV_OFFSET,
Masahiro Yamadaeac6cd62014-07-10 20:43:16 +090077 sizeof(*header), (void *)header);
Simon Schwarz305bc4c2012-03-15 04:01:38 +000078 spl_parse_image_header(header);
79 nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
80 (void *)spl_image.load_addr);
Simon Schwarze21d2d82011-09-14 15:33:34 -040081#ifdef CONFIG_ENV_OFFSET_REDUND
Simon Schwarz305bc4c2012-03-15 04:01:38 +000082 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
Masahiro Yamadaeac6cd62014-07-10 20:43:16 +090083 sizeof(*header), (void *)header);
Simon Schwarz305bc4c2012-03-15 04:01:38 +000084 spl_parse_image_header(header);
85 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
86 (void *)spl_image.load_addr);
Simon Schwarze21d2d82011-09-14 15:33:34 -040087#endif
88#endif
Simon Schwarz305bc4c2012-03-15 04:01:38 +000089 /* Load u-boot */
90 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
Tim Harveyd32e80b2014-05-07 22:16:12 -070091 sizeof(*header), (void *)header);
Simon Schwarz305bc4c2012-03-15 04:01:38 +000092 spl_parse_image_header(header);
93 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
94 spl_image.size, (void *)spl_image.load_addr);
Simon Schwarze21d2d82011-09-14 15:33:34 -040095 nand_deselect();
96}
Heiko Schochercf000272014-10-31 08:31:00 +010097#endif