Simon Schwarz | 9ea5c6e | 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 | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 6 | */ |
| 7 | #include <common.h> |
Tom Rini | d97b4ce | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 8 | #include <config.h> |
Tom Rini | 47f7bca | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 9 | #include <spl.h> |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 10 | #include <asm/io.h> |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 11 | #include <nand.h> |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 12 | |
Heiko Schocher | 0c3117b | 2014-10-31 08:31:00 +0100 | [diff] [blame] | 13 | #if defined(CONFIG_SPL_NAND_RAW_ONLY) |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 14 | int spl_nand_load_image(void) |
Heiko Schocher | 0c3117b | 2014-10-31 08:31:00 +0100 | [diff] [blame] | 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(); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 23 | |
| 24 | return 0; |
Heiko Schocher | 0c3117b | 2014-10-31 08:31:00 +0100 | [diff] [blame] | 25 | } |
| 26 | #else |
Nikita Kiryanov | 483ab3d | 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 | |
Marek Vasut | 7e0f226 | 2016-04-29 00:44:54 +0200 | [diff] [blame^] | 35 | err = spl_parse_image_header(header); |
| 36 | if (err) |
| 37 | return err; |
| 38 | |
Nikita Kiryanov | 483ab3d | 2015-11-08 17:11:42 +0200 | [diff] [blame] | 39 | return nand_spl_load_image(offset, spl_image.size, |
| 40 | (void *)(unsigned long)spl_image.load_addr); |
| 41 | } |
| 42 | |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 43 | int spl_nand_load_image(void) |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 44 | { |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 45 | int err; |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 46 | struct image_header *header; |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 47 | int *src __attribute__((unused)); |
| 48 | int *dst __attribute__((unused)); |
| 49 | |
Ahmed Samir Khalil | 8122d21 | 2016-03-25 13:13:17 +0100 | [diff] [blame] | 50 | #ifdef CONFIG_SPL_NAND_SOFTECC |
| 51 | debug("spl: nand - using sw ecc\n"); |
| 52 | #else |
Tom Rini | 8082fda | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 53 | debug("spl: nand - using hw ecc\n"); |
Ahmed Samir Khalil | 8122d21 | 2016-03-25 13:13:17 +0100 | [diff] [blame] | 54 | #endif |
Tom Rini | 8082fda | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 55 | nand_init(); |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 56 | |
| 57 | /*use CONFIG_SYS_TEXT_BASE as temporary storage area */ |
| 58 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE); |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 59 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 60 | if (!spl_start_uboot()) { |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 61 | /* |
| 62 | * load parameter image |
| 63 | * load to temp position since nand_spl_load_image reads |
| 64 | * a whole block which is typically larger than |
Marek Vasut | b6e95fd | 2012-03-31 07:47:17 +0000 | [diff] [blame] | 65 | * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 66 | * following sections like BSS |
| 67 | */ |
| 68 | nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS, |
| 69 | CONFIG_CMD_SPL_WRITE_SIZE, |
| 70 | (void *)CONFIG_SYS_TEXT_BASE); |
| 71 | /* copy to destintion */ |
| 72 | for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR, |
| 73 | src = (int *)CONFIG_SYS_TEXT_BASE; |
| 74 | src < (int *)(CONFIG_SYS_TEXT_BASE + |
| 75 | CONFIG_CMD_SPL_WRITE_SIZE); |
| 76 | src++, dst++) { |
| 77 | writel(readl(src), dst); |
| 78 | } |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 79 | |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 80 | /* load linux */ |
| 81 | nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, |
Masahiro Yamada | c13bb16 | 2014-07-10 20:43:16 +0900 | [diff] [blame] | 82 | sizeof(*header), (void *)header); |
Marek Vasut | 7e0f226 | 2016-04-29 00:44:54 +0200 | [diff] [blame^] | 83 | err = spl_parse_image_header(header); |
| 84 | if (err) |
| 85 | return err; |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 86 | if (header->ih_os == IH_OS_LINUX) { |
| 87 | /* happy - was a linux */ |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 88 | err = nand_spl_load_image( |
| 89 | CONFIG_SYS_NAND_SPL_KERNEL_OFFS, |
| 90 | spl_image.size, |
| 91 | (void *)spl_image.load_addr); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 92 | nand_deselect(); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 93 | return err; |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 94 | } else { |
Tom Rini | d97b4ce | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 95 | puts("The Expected Linux image was not " |
| 96 | "found. Please check your NAND " |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 97 | "configuration.\n"); |
Tom Rini | d97b4ce | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 98 | puts("Trying to start u-boot now...\n"); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 99 | } |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 100 | } |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 101 | #endif |
| 102 | #ifdef CONFIG_NAND_ENV_DST |
Nikita Kiryanov | 483ab3d | 2015-11-08 17:11:42 +0200 | [diff] [blame] | 103 | spl_nand_load_element(CONFIG_ENV_OFFSET, header); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 104 | #ifdef CONFIG_ENV_OFFSET_REDUND |
Nikita Kiryanov | 483ab3d | 2015-11-08 17:11:42 +0200 | [diff] [blame] | 105 | spl_nand_load_element(CONFIG_ENV_OFFSET_REDUND, header); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 106 | #endif |
| 107 | #endif |
| 108 | /* Load u-boot */ |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 109 | err = spl_nand_load_element(CONFIG_SYS_NAND_U_BOOT_OFFS, header); |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 110 | nand_deselect(); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 111 | return err; |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 112 | } |
Heiko Schocher | 0c3117b | 2014-10-31 08:31:00 +0100 | [diff] [blame] | 113 | #endif |