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 | |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 13 | void spl_nand_load_image(void) |
| 14 | { |
| 15 | struct image_header *header; |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 16 | int *src __attribute__((unused)); |
| 17 | int *dst __attribute__((unused)); |
| 18 | |
Tom Rini | 8082fda | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 19 | debug("spl: nand - using hw ecc\n"); |
Tom Rini | 8082fda | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 20 | nand_init(); |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 21 | |
| 22 | /*use CONFIG_SYS_TEXT_BASE as temporary storage area */ |
| 23 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE); |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 24 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 25 | if (!spl_start_uboot()) { |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 26 | /* |
| 27 | * load parameter image |
| 28 | * load to temp position since nand_spl_load_image reads |
| 29 | * a whole block which is typically larger than |
Marek Vasut | b6e95fd | 2012-03-31 07:47:17 +0000 | [diff] [blame] | 30 | * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 31 | * following sections like BSS |
| 32 | */ |
| 33 | nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS, |
| 34 | CONFIG_CMD_SPL_WRITE_SIZE, |
| 35 | (void *)CONFIG_SYS_TEXT_BASE); |
| 36 | /* copy to destintion */ |
| 37 | for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR, |
| 38 | src = (int *)CONFIG_SYS_TEXT_BASE; |
| 39 | src < (int *)(CONFIG_SYS_TEXT_BASE + |
| 40 | CONFIG_CMD_SPL_WRITE_SIZE); |
| 41 | src++, dst++) { |
| 42 | writel(readl(src), dst); |
| 43 | } |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 44 | |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 45 | /* load linux */ |
| 46 | nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, |
| 47 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 48 | spl_parse_image_header(header); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 49 | if (header->ih_os == IH_OS_LINUX) { |
| 50 | /* happy - was a linux */ |
| 51 | nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, |
| 52 | spl_image.size, (void *)spl_image.load_addr); |
| 53 | nand_deselect(); |
| 54 | return; |
| 55 | } else { |
Tom Rini | d97b4ce | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 56 | puts("The Expected Linux image was not " |
| 57 | "found. Please check your NAND " |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 58 | "configuration.\n"); |
Tom Rini | d97b4ce | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 59 | puts("Trying to start u-boot now...\n"); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 60 | } |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 61 | } |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 62 | #endif |
| 63 | #ifdef CONFIG_NAND_ENV_DST |
| 64 | nand_spl_load_image(CONFIG_ENV_OFFSET, |
| 65 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 66 | spl_parse_image_header(header); |
| 67 | nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size, |
| 68 | (void *)spl_image.load_addr); |
| 69 | #ifdef CONFIG_ENV_OFFSET_REDUND |
| 70 | nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, |
| 71 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 72 | spl_parse_image_header(header); |
| 73 | nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size, |
| 74 | (void *)spl_image.load_addr); |
| 75 | #endif |
| 76 | #endif |
| 77 | /* Load u-boot */ |
| 78 | nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS, |
| 79 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 80 | spl_parse_image_header(header); |
| 81 | nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS, |
| 82 | spl_image.size, (void *)spl_image.load_addr); |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 83 | nand_deselect(); |
| 84 | } |