Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 |
| 3 | * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 6 | */ |
| 7 | #include <common.h> |
Tom Rini | 9ef51bd | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 8 | #include <config.h> |
Tom Rini | 28591df | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 9 | #include <spl.h> |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 10 | #include <asm/io.h> |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 11 | #include <nand.h> |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 12 | |
Heiko Schocher | cf00027 | 2014-10-31 08:31:00 +0100 | [diff] [blame] | 13 | #if defined(CONFIG_SPL_NAND_RAW_ONLY) |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 14 | int spl_nand_load_image(void) |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 15 | { |
Heiko Schocher | cf00027 | 2014-10-31 08:31:00 +0100 | [diff] [blame] | 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(); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 23 | |
| 24 | return 0; |
Heiko Schocher | cf00027 | 2014-10-31 08:31:00 +0100 | [diff] [blame] | 25 | } |
| 26 | #else |
Nikita Kiryanov | 08fb32e6 | 2015-11-08 17:11:42 +0200 | [diff] [blame] | 27 | static 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 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 40 | int spl_nand_load_image(void) |
Heiko Schocher | cf00027 | 2014-10-31 08:31:00 +0100 | [diff] [blame] | 41 | { |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 42 | int err; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 43 | struct image_header *header; |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 44 | int *src __attribute__((unused)); |
| 45 | int *dst __attribute__((unused)); |
| 46 | |
Ahmed Samir Khalil | b976eb2 | 2016-03-25 13:13:17 +0100 | [diff] [blame] | 47 | #ifdef CONFIG_SPL_NAND_SOFTECC |
| 48 | debug("spl: nand - using sw ecc\n"); |
| 49 | #else |
Tom Rini | 09ebf1a | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 50 | debug("spl: nand - using hw ecc\n"); |
Ahmed Samir Khalil | b976eb2 | 2016-03-25 13:13:17 +0100 | [diff] [blame] | 51 | #endif |
Tom Rini | 09ebf1a | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 52 | nand_init(); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 53 | |
| 54 | /*use CONFIG_SYS_TEXT_BASE as temporary storage area */ |
| 55 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE); |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 56 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 57 | if (!spl_start_uboot()) { |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 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 |
Marek Vasut | 6d01676 | 2012-03-31 07:47:17 +0000 | [diff] [blame] | 62 | * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 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 | } |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 76 | |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 77 | /* load linux */ |
| 78 | nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, |
Masahiro Yamada | eac6cd6 | 2014-07-10 20:43:16 +0900 | [diff] [blame] | 79 | sizeof(*header), (void *)header); |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 80 | spl_parse_image_header(header); |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 81 | if (header->ih_os == IH_OS_LINUX) { |
| 82 | /* happy - was a linux */ |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 83 | err = nand_spl_load_image( |
| 84 | CONFIG_SYS_NAND_SPL_KERNEL_OFFS, |
| 85 | spl_image.size, |
| 86 | (void *)spl_image.load_addr); |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 87 | nand_deselect(); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 88 | return err; |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 89 | } else { |
Tom Rini | 9ef51bd | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 90 | puts("The Expected Linux image was not " |
| 91 | "found. Please check your NAND " |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 92 | "configuration.\n"); |
Tom Rini | 9ef51bd | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 93 | puts("Trying to start u-boot now...\n"); |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 94 | } |
| 95 | } |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 96 | #endif |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 97 | #ifdef CONFIG_NAND_ENV_DST |
Nikita Kiryanov | 08fb32e6 | 2015-11-08 17:11:42 +0200 | [diff] [blame] | 98 | spl_nand_load_element(CONFIG_ENV_OFFSET, header); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 99 | #ifdef CONFIG_ENV_OFFSET_REDUND |
Nikita Kiryanov | 08fb32e6 | 2015-11-08 17:11:42 +0200 | [diff] [blame] | 100 | spl_nand_load_element(CONFIG_ENV_OFFSET_REDUND, header); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 101 | #endif |
| 102 | #endif |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 103 | /* Load u-boot */ |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 104 | err = spl_nand_load_element(CONFIG_SYS_NAND_U_BOOT_OFFS, header); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 105 | nand_deselect(); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 106 | return err; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 107 | } |
Heiko Schocher | cf00027 | 2014-10-31 08:31:00 +0100 | [diff] [blame] | 108 | #endif |