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) |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 14 | void spl_nand_load_image(void) |
| 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(); |
| 23 | } |
| 24 | #else |
| 25 | void spl_nand_load_image(void) |
| 26 | { |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 27 | struct image_header *header; |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 28 | int *src __attribute__((unused)); |
| 29 | int *dst __attribute__((unused)); |
| 30 | |
Tom Rini | 09ebf1a | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 31 | debug("spl: nand - using hw ecc\n"); |
Tom Rini | 09ebf1a | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 32 | nand_init(); |
Simon Schwarz | e21d2d8 | 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 | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 36 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 37 | if (!spl_start_uboot()) { |
Simon Schwarz | 6c3ddde | 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 | 6d01676 | 2012-03-31 07:47:17 +0000 | [diff] [blame] | 42 | * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite |
Simon Schwarz | 6c3ddde | 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 | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 56 | |
Simon Schwarz | 6c3ddde | 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 | eac6cd6 | 2014-07-10 20:43:16 +0900 | [diff] [blame] | 59 | sizeof(*header), (void *)header); |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 60 | spl_parse_image_header(header); |
Simon Schwarz | 305bc4c | 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 | 9ef51bd | 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 | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 70 | "configuration.\n"); |
Tom Rini | 9ef51bd | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 71 | puts("Trying to start u-boot now...\n"); |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 74 | #endif |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 75 | #ifdef CONFIG_NAND_ENV_DST |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 76 | nand_spl_load_image(CONFIG_ENV_OFFSET, |
Masahiro Yamada | eac6cd6 | 2014-07-10 20:43:16 +0900 | [diff] [blame] | 77 | sizeof(*header), (void *)header); |
Simon Schwarz | 305bc4c | 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); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 81 | #ifdef CONFIG_ENV_OFFSET_REDUND |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 82 | nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, |
Masahiro Yamada | eac6cd6 | 2014-07-10 20:43:16 +0900 | [diff] [blame] | 83 | sizeof(*header), (void *)header); |
Simon Schwarz | 305bc4c | 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); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 87 | #endif |
| 88 | #endif |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 89 | /* Load u-boot */ |
| 90 | nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS, |
Tim Harvey | d32e80b | 2014-05-07 22:16:12 -0700 | [diff] [blame] | 91 | sizeof(*header), (void *)header); |
Simon Schwarz | 305bc4c | 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, |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 94 | spl_image.size, (void *)(unsigned long)spl_image.load_addr); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 95 | nand_deselect(); |
| 96 | } |
Heiko Schocher | cf00027 | 2014-10-31 08:31:00 +0100 | [diff] [blame] | 97 | #endif |