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 | * |
| 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> |
| 24 | #include <asm/u-boot.h> |
| 25 | #include <asm/utils.h> |
| 26 | #include <asm/arch/sys_proto.h> |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 27 | #include <asm/io.h> |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 28 | #include <nand.h> |
Simon Glass | 5040241 | 2011-10-10 08:55:19 +0000 | [diff] [blame] | 29 | #include <version.h> |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 30 | #include <asm/omap_common.h> |
| 31 | |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 32 | void spl_nand_load_image(void) |
| 33 | { |
| 34 | struct image_header *header; |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 35 | int *src __attribute__((unused)); |
| 36 | int *dst __attribute__((unused)); |
| 37 | |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 38 | switch (omap_boot_mode()) { |
| 39 | case NAND_MODE_HW_ECC: |
| 40 | debug("spl: nand - using hw ecc\n"); |
| 41 | gpmc_init(); |
| 42 | nand_init(); |
| 43 | break; |
| 44 | default: |
| 45 | puts("spl: ERROR: This bootmode is not implemented - hanging"); |
| 46 | hang(); |
| 47 | } |
| 48 | |
| 49 | /*use CONFIG_SYS_TEXT_BASE as temporary storage area */ |
| 50 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE); |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 51 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 52 | if (!spl_start_uboot()) { |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 53 | /* |
| 54 | * load parameter image |
| 55 | * load to temp position since nand_spl_load_image reads |
| 56 | * a whole block which is typically larger than |
Marek Vasut | 6d01676 | 2012-03-31 07:47:17 +0000 | [diff] [blame] | 57 | * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 58 | * following sections like BSS |
| 59 | */ |
| 60 | nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS, |
| 61 | CONFIG_CMD_SPL_WRITE_SIZE, |
| 62 | (void *)CONFIG_SYS_TEXT_BASE); |
| 63 | /* copy to destintion */ |
| 64 | for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR, |
| 65 | src = (int *)CONFIG_SYS_TEXT_BASE; |
| 66 | src < (int *)(CONFIG_SYS_TEXT_BASE + |
| 67 | CONFIG_CMD_SPL_WRITE_SIZE); |
| 68 | src++, dst++) { |
| 69 | writel(readl(src), dst); |
| 70 | } |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 71 | |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 72 | /* load linux */ |
| 73 | nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, |
| 74 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 75 | spl_parse_image_header(header); |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 76 | if (header->ih_os == IH_OS_LINUX) { |
| 77 | /* happy - was a linux */ |
| 78 | nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, |
| 79 | spl_image.size, (void *)spl_image.load_addr); |
| 80 | nand_deselect(); |
| 81 | return; |
| 82 | } else { |
| 83 | printf("The Expected Linux image was not" |
| 84 | "found. Please check your NAND" |
| 85 | "configuration.\n"); |
| 86 | printf("Trying to start u-boot now...\n"); |
| 87 | } |
| 88 | } |
Simon Schwarz | 6c3ddde | 2012-03-15 04:01:36 +0000 | [diff] [blame] | 89 | #endif |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 90 | #ifdef CONFIG_NAND_ENV_DST |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 91 | nand_spl_load_image(CONFIG_ENV_OFFSET, |
| 92 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 93 | spl_parse_image_header(header); |
| 94 | nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size, |
| 95 | (void *)spl_image.load_addr); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 96 | #ifdef CONFIG_ENV_OFFSET_REDUND |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 97 | nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, |
| 98 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 99 | spl_parse_image_header(header); |
| 100 | nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size, |
| 101 | (void *)spl_image.load_addr); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 102 | #endif |
| 103 | #endif |
Simon Schwarz | 305bc4c | 2012-03-15 04:01:38 +0000 | [diff] [blame] | 104 | /* Load u-boot */ |
| 105 | nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS, |
| 106 | CONFIG_SYS_NAND_PAGE_SIZE, (void *)header); |
| 107 | spl_parse_image_header(header); |
| 108 | nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS, |
| 109 | spl_image.size, (void *)spl_image.load_addr); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 110 | nand_deselect(); |
| 111 | } |