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) |
| 14 | void spl_nand_load_image(void) |
| 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(); |
| 23 | } |
| 24 | #else |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 25 | void spl_nand_load_image(void) |
| 26 | { |
| 27 | struct image_header *header; |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 28 | int *src __attribute__((unused)); |
| 29 | int *dst __attribute__((unused)); |
| 30 | |
Tom Rini | 8082fda | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 31 | debug("spl: nand - using hw ecc\n"); |
Tom Rini | 8082fda | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 32 | nand_init(); |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 33 | |
| 34 | /*use CONFIG_SYS_TEXT_BASE as temporary storage area */ |
| 35 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE); |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 36 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 37 | if (!spl_start_uboot()) { |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 38 | /* |
| 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 Vasut | b6e95fd | 2012-03-31 07:47:17 +0000 | [diff] [blame] | 42 | * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 43 | * 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 Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 56 | |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 57 | /* load linux */ |
| 58 | nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, |
Masahiro Yamada | c13bb16 | 2014-07-10 20:43:16 +0900 | [diff] [blame] | 59 | sizeof(*header), (void *)header); |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 60 | spl_parse_image_header(header); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 61 | 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 Rini | d97b4ce | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 68 | puts("The Expected Linux image was not " |
| 69 | "found. Please check your NAND " |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 70 | "configuration.\n"); |
Tom Rini | d97b4ce | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 71 | puts("Trying to start u-boot now...\n"); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 72 | } |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 73 | } |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 74 | #endif |
| 75 | #ifdef CONFIG_NAND_ENV_DST |
| 76 | nand_spl_load_image(CONFIG_ENV_OFFSET, |
Masahiro Yamada | c13bb16 | 2014-07-10 20:43:16 +0900 | [diff] [blame] | 77 | sizeof(*header), (void *)header); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 78 | spl_parse_image_header(header); |
| 79 | nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size, |
| 80 | (void *)spl_image.load_addr); |
| 81 | #ifdef CONFIG_ENV_OFFSET_REDUND |
| 82 | nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, |
Masahiro Yamada | c13bb16 | 2014-07-10 20:43:16 +0900 | [diff] [blame] | 83 | sizeof(*header), (void *)header); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 84 | spl_parse_image_header(header); |
| 85 | nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size, |
| 86 | (void *)spl_image.load_addr); |
| 87 | #endif |
| 88 | #endif |
| 89 | /* Load u-boot */ |
| 90 | nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS, |
Tim Harvey | 50c8d66 | 2014-05-07 22:16:12 -0700 | [diff] [blame] | 91 | sizeof(*header), (void *)header); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 92 | 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 Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 95 | nand_deselect(); |
| 96 | } |
Heiko Schocher | 0c3117b | 2014-10-31 08:31:00 +0100 | [diff] [blame] | 97 | #endif |