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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | #include <common.h> |
Tom Rini | d97b4ce | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 24 | #include <config.h> |
Tom Rini | 47f7bca | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 25 | #include <spl.h> |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 26 | #include <asm/io.h> |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 27 | #include <nand.h> |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 28 | |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 29 | void spl_nand_load_image(void) |
| 30 | { |
| 31 | struct image_header *header; |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 32 | int *src __attribute__((unused)); |
| 33 | int *dst __attribute__((unused)); |
| 34 | |
Tom Rini | 8082fda | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 35 | debug("spl: nand - using hw ecc\n"); |
Tom Rini | 8082fda | 2012-08-13 14:11:06 -0700 | [diff] [blame] | 36 | nand_init(); |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 37 | |
| 38 | /*use CONFIG_SYS_TEXT_BASE as temporary storage area */ |
| 39 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE); |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 40 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 41 | if (!spl_start_uboot()) { |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 42 | /* |
| 43 | * load parameter image |
| 44 | * load to temp position since nand_spl_load_image reads |
| 45 | * a whole block which is typically larger than |
Marek Vasut | b6e95fd | 2012-03-31 07:47:17 +0000 | [diff] [blame] | 46 | * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 47 | * following sections like BSS |
| 48 | */ |
| 49 | nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS, |
| 50 | CONFIG_CMD_SPL_WRITE_SIZE, |
| 51 | (void *)CONFIG_SYS_TEXT_BASE); |
| 52 | /* copy to destintion */ |
| 53 | for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR, |
| 54 | src = (int *)CONFIG_SYS_TEXT_BASE; |
| 55 | src < (int *)(CONFIG_SYS_TEXT_BASE + |
| 56 | CONFIG_CMD_SPL_WRITE_SIZE); |
| 57 | src++, dst++) { |
| 58 | writel(readl(src), dst); |
| 59 | } |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 60 | |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 61 | /* load linux */ |
| 62 | nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, |
| 63 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 64 | spl_parse_image_header(header); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 65 | if (header->ih_os == IH_OS_LINUX) { |
| 66 | /* happy - was a linux */ |
| 67 | nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, |
| 68 | spl_image.size, (void *)spl_image.load_addr); |
| 69 | nand_deselect(); |
| 70 | return; |
| 71 | } else { |
Tom Rini | d97b4ce | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 72 | puts("The Expected Linux image was not " |
| 73 | "found. Please check your NAND " |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 74 | "configuration.\n"); |
Tom Rini | d97b4ce | 2012-08-14 14:33:02 -0700 | [diff] [blame] | 75 | puts("Trying to start u-boot now...\n"); |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 76 | } |
Simon Schwarz | df163a5 | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 77 | } |
Simon Schwarz | 379c19a | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 78 | #endif |
| 79 | #ifdef CONFIG_NAND_ENV_DST |
| 80 | nand_spl_load_image(CONFIG_ENV_OFFSET, |
| 81 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 82 | spl_parse_image_header(header); |
| 83 | nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size, |
| 84 | (void *)spl_image.load_addr); |
| 85 | #ifdef CONFIG_ENV_OFFSET_REDUND |
| 86 | nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, |
| 87 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 88 | spl_parse_image_header(header); |
| 89 | nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size, |
| 90 | (void *)spl_image.load_addr); |
| 91 | #endif |
| 92 | #endif |
| 93 | /* Load u-boot */ |
| 94 | nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS, |
| 95 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 96 | spl_parse_image_header(header); |
| 97 | nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS, |
| 98 | spl_image.size, (void *)spl_image.load_addr); |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 99 | nand_deselect(); |
| 100 | } |