Patchwork [U-Boot,03/17] ARM: SPL: Move the omap SPL framework to arch/arm/lib

login
register
mail settings
Submitter Tom Rini
Date Aug. 15, 2012, 9:30 p.m.
Message ID <1345066254-6911-4-git-send-email-trini@ti.com>
Download mbox | patch
Permalink /patch/177855/
State Superseded
Delegated to: Tom Rini
Headers show

Comments

Tom Rini - Aug. 15, 2012, 9:30 p.m.
Add a new flag, CONFIG_SPL_FRAMEWORK to opt into the arch/arm/lib SPL
framework, enable on all of the previously using boards.

Signed-off-by: Tom Rini <trini@ti.com>
---
 README                                      |    5 +
 arch/arm/cpu/armv7/omap-common/Makefile     |   13 --
 arch/arm/cpu/armv7/omap-common/spl.c        |  225 ---------------------------
 arch/arm/cpu/armv7/omap-common/spl_mmc.c    |  154 ------------------
 arch/arm/cpu/armv7/omap-common/spl_nand.c   |  111 -------------
 arch/arm/cpu/armv7/omap-common/spl_ymodem.c |   76 ---------
 arch/arm/lib/Makefile                       |    9 +-
 arch/arm/lib/spl.c                          |  225 +++++++++++++++++++++++++++
 arch/arm/lib/spl_mmc.c                      |  154 ++++++++++++++++++
 arch/arm/lib/spl_nand.c                     |  111 +++++++++++++
 arch/arm/lib/spl_ymodem.c                   |   76 +++++++++
 include/configs/am335x_evm.h                |    1 +
 include/configs/am3517_crane.h              |    1 +
 include/configs/am3517_evm.h                |    1 +
 include/configs/devkit8000.h                |    1 +
 include/configs/mcx.h                       |    1 +
 include/configs/omap3_beagle.h              |    1 +
 include/configs/omap3_evm_common.h          |    1 +
 include/configs/omap3_overo.h               |    1 +
 include/configs/omap4_common.h              |    1 +
 include/configs/omap5_evm.h                 |    1 +
 include/configs/tam3517-common.h            |    1 +
 include/configs/tricorder.h                 |    1 +
 23 files changed, 591 insertions(+), 580 deletions(-)
 delete mode 100644 arch/arm/cpu/armv7/omap-common/spl.c
 delete mode 100644 arch/arm/cpu/armv7/omap-common/spl_mmc.c
 delete mode 100644 arch/arm/cpu/armv7/omap-common/spl_nand.c
 delete mode 100644 arch/arm/cpu/armv7/omap-common/spl_ymodem.c
 create mode 100644 arch/arm/lib/spl.c
 create mode 100644 arch/arm/lib/spl_mmc.c
 create mode 100644 arch/arm/lib/spl_nand.c
 create mode 100644 arch/arm/lib/spl_ymodem.c
Stefano Babic - Aug. 16, 2012, 7:45 a.m.
On 15/08/2012 23:30, Tom Rini wrote:
> Add a new flag, CONFIG_SPL_FRAMEWORK to opt into the arch/arm/lib SPL
> framework, enable on all of the previously using boards.
> 
> Signed-off-by: Tom Rini <trini@ti.com>
> ---

Hi Tom,

>  README                                      |    5 +
>  arch/arm/cpu/armv7/omap-common/Makefile     |   13 --
>  arch/arm/cpu/armv7/omap-common/spl.c        |  225 ---------------------------
>  arch/arm/cpu/armv7/omap-common/spl_mmc.c    |  154 ------------------
>  arch/arm/cpu/armv7/omap-common/spl_nand.c   |  111 -------------
>  arch/arm/cpu/armv7/omap-common/spl_ymodem.c |   76 ---------
>  arch/arm/lib/Makefile                       |    9 +-
>  arch/arm/lib/spl.c                          |  225 +++++++++++++++++++++++++++
>  arch/arm/lib/spl_mmc.c                      |  154 ++++++++++++++++++
>  arch/arm/lib/spl_nand.c                     |  111 +++++++++++++
>  arch/arm/lib/spl_ymodem.c                   |   76 +++++++++
>  include/configs/am335x_evm.h                |    1 +
>  include/configs/am3517_crane.h              |    1 +
>  include/configs/am3517_evm.h                |    1 +
>  include/configs/devkit8000.h                |    1 +
>  include/configs/mcx.h                       |    1 +
>  include/configs/omap3_beagle.h              |    1 +
>  include/configs/omap3_evm_common.h          |    1 +
>  include/configs/omap3_overo.h               |    1 +
>  include/configs/omap4_common.h              |    1 +
>  include/configs/omap5_evm.h                 |    1 +
>  include/configs/tam3517-common.h            |    1 +
>  include/configs/tricorder.h                 |    1 +
>  23 files changed, 591 insertions(+), 580 deletions(-)
>  delete mode 100644 arch/arm/cpu/armv7/omap-common/spl.c
>  delete mode 100644 arch/arm/cpu/armv7/omap-common/spl_mmc.c
>  delete mode 100644 arch/arm/cpu/armv7/omap-common/spl_nand.c
>  delete mode 100644 arch/arm/cpu/armv7/omap-common/spl_ymodem.c
>  create mode 100644 arch/arm/lib/spl.c
>  create mode 100644 arch/arm/lib/spl_mmc.c
>  create mode 100644 arch/arm/lib/spl_nand.c
>  create mode 100644 arch/arm/lib/spl_ymodem.c
> 

In my attempt I moved files from arch/arm/cpu/armv7/omap-common/ to
common. This is because to make it available to all SOCs, not only
armv7. What do you think about ? I would like to add an example with an
arm1136 (MX35).


> --- a/arch/arm/cpu/armv7/omap-common/Makefile
> +++ b/arch/arm/cpu/armv7/omap-common/Makefile
> @@ -45,19 +45,6 @@ COBJS	+= boot-common.o
>  SOBJS	+= lowlevel_init.o
>  endif
>  
> -ifdef CONFIG_SPL_BUILD
> -COBJS	+= spl.o
> -ifdef CONFIG_SPL_NAND_SUPPORT
> -COBJS	+= spl_nand.o
> -endif
> -ifdef CONFIG_SPL_MMC_SUPPORT
> -COBJS	+= spl_mmc.o
> -endif
> -ifdef CONFIG_SPL_YMODEM_SUPPORT
> -COBJS	+= spl_ymodem.o
> -endif
> -endif
> -
>  ifndef CONFIG_SPL_BUILD
>  ifneq ($(CONFIG_OMAP44XX)$(CONFIG_OMAP54XX),)
>  COBJS	+= mem-common.o
> diff --git a/arch/arm/cpu/armv7/omap-common/spl.c b/arch/arm/cpu/armv7/omap-common/spl.c
> deleted file mode 100644
> index b10832a..0000000
> --- a/arch/arm/cpu/armv7/omap-common/spl.c
> +++ /dev/null
> @@ -1,225 +0,0 @@
> -/*
> - * (C) Copyright 2010
> - * Texas Instruments, <www.ti.com>
> - *
> - * Aneesh V <aneesh@ti.com>
> - *
> - * See file CREDITS for list of people who contributed to this
> - * project.
> - *
> - * This program is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU General Public License as
> - * published by the Free Software Foundation; either version 2 of
> - * the License, or (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write to the Free Software
> - * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> - * MA 02111-1307 USA
> - */
> -#include <common.h>
> -#include <asm/u-boot.h>
> -#include <asm/utils.h>
> -#include <asm/arch/sys_proto.h>
> -#include <nand.h>
> -#include <mmc.h>
> -#include <fat.h>
> -#include <version.h>
> -#include <asm/omap_common.h>
> -#include <asm/arch/mmc_host_def.h>
> -#include <i2c.h>
> -#include <image.h>
> -#include <malloc.h>
> -#include <linux/compiler.h>
> -
> -DECLARE_GLOBAL_DATA_PTR;
> -
> -u32* boot_params_ptr = NULL;
> -struct spl_image_info spl_image;
> -
> -/* Define global data structure pointer to it*/
> -static gd_t gdata __attribute__ ((section(".data")));
> -static bd_t bdata __attribute__ ((section(".data")));
> -
> -inline void hang(void)
> -{
> -	puts("### ERROR ### Please RESET the board ###\n");
> -	for (;;)
> -		;
> -}
> -
> -void board_init_f(ulong dummy)
> -{
> -	/*
> -	 * We call relocate_code() with relocation target same as the
> -	 * CONFIG_SYS_SPL_TEXT_BASE. This will result in relocation getting
> -	 * skipped. Instead, only .bss initialization will happen. That's
> -	 * all we need
> -	 */
> -	debug(">>board_init_f()\n");
> -	relocate_code(CONFIG_SPL_STACK, &gdata, CONFIG_SPL_TEXT_BASE);
> -}
> -
> -/*
> - * Default function to determine if u-boot or the OS should
> - * be started. This implementation always returns 1.
> - *
> - * Please implement your own board specific funcion to do this.
> - *
> - * RETURN
> - * 0 to not start u-boot
> - * positive if u-boot should start
> - */
> -#ifdef CONFIG_SPL_OS_BOOT
> -__weak int spl_start_uboot(void)
> -{
> -	printf("SPL: Please implement spl_start_uboot() for your board\n");
> -	printf("SPL: Direct Linux boot not active!\n");
> -	return 1;
> -}
> -#endif
> -
> -void spl_parse_image_header(const struct image_header *header)
> -{
> -	u32 header_size = sizeof(struct image_header);
> -
> -	if (__be32_to_cpu(header->ih_magic) == IH_MAGIC) {
> -		spl_image.size = __be32_to_cpu(header->ih_size) + header_size;
> -		spl_image.entry_point = __be32_to_cpu(header->ih_load);
> -		/* Load including the header */
> -		spl_image.load_addr = spl_image.entry_point - header_size;
> -		spl_image.os = header->ih_os;
> -		spl_image.name = (const char *)&header->ih_name;
> -		debug("spl: payload image: %s load addr: 0x%x size: %d\n",
> -			spl_image.name, spl_image.load_addr, spl_image.size);
> -	} else {
> -		/* Signature not found - assume u-boot.bin */
> -		printf("mkimage signature not found - ih_magic = %x\n",
> -			header->ih_magic);
> -		debug("Assuming u-boot.bin ..\n");
> -		/* Let's assume U-Boot will not be more than 200 KB */
> -		spl_image.size = 200 * 1024;
> -		spl_image.entry_point = CONFIG_SYS_TEXT_BASE;
> -		spl_image.load_addr = CONFIG_SYS_TEXT_BASE;
> -		spl_image.os = IH_OS_U_BOOT;
> -		spl_image.name = "U-Boot";
> -	}
> -}
> -
> -/*
> - * This function jumps to an image with argument. Normally an FDT or ATAGS
> - * image.
> - * arg: Pointer to paramter image in RAM
> - */
> -#ifdef CONFIG_SPL_OS_BOOT
> -static void __noreturn jump_to_image_linux(void *arg)
> -{
> -	debug("Entering kernel arg pointer: 0x%p\n", arg);
> -	typedef void (*image_entry_arg_t)(int, int, void *)
> -		__attribute__ ((noreturn));
> -	image_entry_arg_t image_entry =
> -		(image_entry_arg_t) spl_image.entry_point;
> -	cleanup_before_linux();
> -	image_entry(0, CONFIG_MACH_TYPE, arg);
> -}
> -#endif
> -
> -static void __noreturn jump_to_image_no_args(void)
> -{
> -	typedef void __noreturn (*image_entry_noargs_t)(u32 *);
> -	image_entry_noargs_t image_entry =
> -			(image_entry_noargs_t) spl_image.entry_point;
> -
> -	debug("image entry point: 0x%X\n", spl_image.entry_point);
> -	/* Pass the saved boot_params from rom code */
> -#if defined(CONFIG_VIRTIO) || defined(CONFIG_ZEBU)
> -	image_entry = (image_entry_noargs_t)0x80100000;
> -#endif
> -	u32 boot_params_ptr_addr = (u32)&boot_params_ptr;
> -	image_entry((u32 *)boot_params_ptr_addr);
> -}
> -
> -void board_init_r(gd_t *id, ulong dummy)
> -{
> -	u32 boot_device;
> -	debug(">>spl:board_init_r()\n");
> -
> -	mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
> -			CONFIG_SYS_SPL_MALLOC_SIZE);
> -
> -#ifdef CONFIG_SPL_BOARD_INIT
> -	spl_board_init();
> -#endif
> -
> -	boot_device = omap_boot_device();
> -	debug("boot device - %d\n", boot_device);
> -	switch (boot_device) {
> -#ifdef CONFIG_SPL_MMC_SUPPORT
> -	case BOOT_DEVICE_MMC1:
> -	case BOOT_DEVICE_MMC2:
> -	case BOOT_DEVICE_MMC2_2:
> -		spl_mmc_load_image();
> -		break;
> -#endif
> -#ifdef CONFIG_SPL_NAND_SUPPORT
> -	case BOOT_DEVICE_NAND:
> -		spl_nand_load_image();
> -		break;
> -#endif
> -#ifdef CONFIG_SPL_YMODEM_SUPPORT
> -	case BOOT_DEVICE_UART:
> -		spl_ymodem_load_image();
> -		break;
> -#endif
> -	default:
> -		printf("SPL: Un-supported Boot Device - %d!!!\n", boot_device);
> -		hang();
> -		break;
> -	}
> -
> -	switch (spl_image.os) {
> -	case IH_OS_U_BOOT:
> -		debug("Jumping to U-Boot\n");
> -		jump_to_image_no_args();
> -		break;
> -#ifdef CONFIG_SPL_OS_BOOT
> -	case IH_OS_LINUX:
> -		debug("Jumping to Linux\n");
> -		spl_board_prepare_for_linux();
> -		jump_to_image_linux((void *)CONFIG_SYS_SPL_ARGS_ADDR);
> -		break;
> -#endif
> -	default:
> -		puts("Unsupported OS image.. Jumping nevertheless..\n");
> -		jump_to_image_no_args();
> -	}
> -}
> -
> -/* This requires UART clocks to be enabled */
> -void preloader_console_init(void)
> -{
> -	const char *u_boot_rev = U_BOOT_VERSION;
> -
> -	gd = &gdata;
> -	gd->bd = &bdata;
> -	gd->flags |= GD_FLG_RELOC;
> -	gd->baudrate = CONFIG_BAUDRATE;
> -
> -	serial_init();		/* serial communications setup */
> -
> -	gd->have_console = 1;
> -
> -	/* Avoid a second "U-Boot" coming from this string */
> -	u_boot_rev = &u_boot_rev[7];
> -
> -	printf("\nU-Boot SPL %s (%s - %s)\n", u_boot_rev, U_BOOT_DATE,
> -		U_BOOT_TIME);
> -#ifdef CONFIG_SPL_DISPLAY_PRINT
> -	spl_display_print();
> -#endif
> -}




> diff --git a/arch/arm/cpu/armv7/omap-common/spl_mmc.c b/arch/arm/cpu/armv7/omap-common/spl_mmc.c
> deleted file mode 100644
> index 7552f6c..0000000
> --- a/arch/arm/cpu/armv7/omap-common/spl_mmc.c
> +++ /dev/null
> @@ -1,154 +0,0 @@
> -/*
> - * (C) Copyright 2010
> - * Texas Instruments, <www.ti.com>
> - *
> - * Aneesh V <aneesh@ti.com>
> - *
> - * See file CREDITS for list of people who contributed to this
> - * project.
> - *
> - * This program is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU General Public License as
> - * published by the Free Software Foundation; either version 2 of
> - * the License, or (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write to the Free Software
> - * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> - * MA 02111-1307 USA
> - */
> -#include <common.h>
> -#include <asm/u-boot.h>
> -#include <asm/utils.h>
> -#include <asm/arch/sys_proto.h>
> -#include <mmc.h>
> -#include <fat.h>
> -#include <version.h>
> -#include <asm/omap_common.h>
> -#include <asm/arch/mmc_host_def.h>
> -
> -DECLARE_GLOBAL_DATA_PTR;
> -
> -#ifdef CONFIG_GENERIC_MMC
> -int board_mmc_init(bd_t *bis)
> -{
> -	switch (omap_boot_device()) {
> -	case BOOT_DEVICE_MMC1:
> -		omap_mmc_init(0, 0, 0);
> -		break;
> -	case BOOT_DEVICE_MMC2:
> -	case BOOT_DEVICE_MMC2_2:
> -		omap_mmc_init(1, 0, 0);
> -		break;
> -	}
> -	return 0;
> -}
> -#endif
> -
> -static void mmc_load_image_raw(struct mmc *mmc)
> -{
> -	u32 image_size_sectors, err;
> -	const struct image_header *header;
> -
> -	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
> -						sizeof(struct image_header));
> -
> -	/* read image header to find the image size & load address */
> -	err = mmc->block_dev.block_read(0,
> -			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, 1,
> -			(void *)header);
> -
> -	if (err <= 0)
> -		goto end;
> -
> -	spl_parse_image_header(header);
> -
> -	/* convert size to sectors - round up */
> -	image_size_sectors = (spl_image.size + MMCSD_SECTOR_SIZE - 1) /
> -				MMCSD_SECTOR_SIZE;
> -
> -	/* Read the header too to avoid extra memcpy */
> -	err = mmc->block_dev.block_read(0,
> -			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR,
> -			image_size_sectors, (void *)spl_image.load_addr);
> -
> -end:
> -	if (err <= 0) {
> -		printf("spl: mmc blk read err - %d\n", err);
> -		hang();
> -	}
> -}
> -
> -#ifdef CONFIG_SPL_FAT_SUPPORT
> -static void mmc_load_image_fat(struct mmc *mmc)
> -{
> -	s32 err;
> -	struct image_header *header;
> -
> -	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
> -						sizeof(struct image_header));
> -
> -	err = fat_register_device(&mmc->block_dev,
> -				CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION);
> -	if (err) {
> -		printf("spl: fat register err - %d\n", err);
> -		hang();
> -	}
> -
> -	err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME,
> -				(u8 *)header, sizeof(struct image_header));
> -	if (err <= 0)
> -		goto end;
> -
> -	spl_parse_image_header(header);
> -
> -	err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME,
> -				(u8 *)spl_image.load_addr, 0);
> -
> -end:
> -	if (err <= 0) {
> -		printf("spl: error reading image %s, err - %d\n",
> -			CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, err);
> -		hang();
> -	}
> -}
> -#endif
> -
> -void spl_mmc_load_image(void)
> -{
> -	struct mmc *mmc;
> -	int err;
> -	u32 boot_mode;
> -
> -	mmc_initialize(gd->bd);
> -	/* We register only one device. So, the dev id is always 0 */
> -	mmc = find_mmc_device(0);
> -	if (!mmc) {
> -		puts("spl: mmc device not found!!\n");
> -		hang();
> -	}
> -
> -	err = mmc_init(mmc);
> -	if (err) {
> -		printf("spl: mmc init failed: err - %d\n", err);
> -		hang();
> -	}
> -	boot_mode = omap_boot_mode();
> -	if (boot_mode == MMCSD_MODE_RAW) {
> -		debug("boot mode - RAW\n");
> -		mmc_load_image_raw(mmc);
> -#ifdef CONFIG_SPL_FAT_SUPPORT
> -	} else if (boot_mode == MMCSD_MODE_FAT) {
> -		debug("boot mode - FAT\n");
> -		mmc_load_image_fat(mmc);
> -#endif
> -	} else {
> -		puts("spl: wrong MMC boot mode\n");
> -		hang();
> -	}
> -}
> diff --git a/arch/arm/cpu/armv7/omap-common/spl_nand.c b/arch/arm/cpu/armv7/omap-common/spl_nand.c
> deleted file mode 100644
> index 8cf55c9..0000000
> --- a/arch/arm/cpu/armv7/omap-common/spl_nand.c
> +++ /dev/null
> @@ -1,111 +0,0 @@
> -/*
> - * Copyright (C) 2011
> - * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
> - *
> - * See file CREDITS for list of people who contributed to this
> - * project.
> - *
> - * This program is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU General Public License as
> - * published by the Free Software Foundation; either version 2 of
> - * the License, or (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write to the Free Software
> - * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> - * MA 02111-1307 USA
> - */
> -#include <common.h>
> -#include <asm/u-boot.h>
> -#include <asm/utils.h>
> -#include <asm/arch/sys_proto.h>
> -#include <asm/io.h>
> -#include <nand.h>
> -#include <version.h>
> -#include <asm/omap_common.h>
> -
> -void spl_nand_load_image(void)
> -{
> -	struct image_header *header;
> -	int *src __attribute__((unused));
> -	int *dst __attribute__((unused));
> -
> -	switch (omap_boot_mode()) {
> -	case NAND_MODE_HW_ECC:
> -		debug("spl: nand - using hw ecc\n");
> -		gpmc_init();
> -		nand_init();
> -		break;
> -	default:
> -		puts("spl: ERROR: This bootmode is not implemented - hanging");
> -		hang();
> -	}
> -
> -	/*use CONFIG_SYS_TEXT_BASE as temporary storage area */
> -	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
> -#ifdef CONFIG_SPL_OS_BOOT
> -	if (!spl_start_uboot()) {
> -		/*
> -		 * load parameter image
> -		 * load to temp position since nand_spl_load_image reads
> -		 * a whole block which is typically larger than
> -		 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
> -		 * following sections like BSS
> -		 */
> -		nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
> -			CONFIG_CMD_SPL_WRITE_SIZE,
> -			(void *)CONFIG_SYS_TEXT_BASE);
> -		/* copy to destintion */
> -		for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
> -				src = (int *)CONFIG_SYS_TEXT_BASE;
> -				src < (int *)(CONFIG_SYS_TEXT_BASE +
> -				CONFIG_CMD_SPL_WRITE_SIZE);
> -				src++, dst++) {
> -			writel(readl(src), dst);
> -		}
> -
> -		/* load linux */
> -		nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
> -			CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
> -		spl_parse_image_header(header);
> -		if (header->ih_os == IH_OS_LINUX) {
> -			/* happy - was a linux */
> -			nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
> -				spl_image.size, (void *)spl_image.load_addr);
> -			nand_deselect();
> -			return;
> -		} else {
> -			printf("The Expected Linux image was not"
> -				"found. Please check your NAND"
> -				"configuration.\n");
> -			printf("Trying to start u-boot now...\n");
> -		}
> -	}
> -#endif
> -#ifdef CONFIG_NAND_ENV_DST
> -	nand_spl_load_image(CONFIG_ENV_OFFSET,
> -		CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
> -	spl_parse_image_header(header);
> -	nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
> -		(void *)spl_image.load_addr);
> -#ifdef CONFIG_ENV_OFFSET_REDUND
> -	nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
> -		CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
> -	spl_parse_image_header(header);
> -	nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
> -		(void *)spl_image.load_addr);
> -#endif
> -#endif
> -	/* Load u-boot */
> -	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
> -		CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
> -	spl_parse_image_header(header);
> -	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
> -		spl_image.size, (void *)spl_image.load_addr);
> -	nand_deselect();
> -}
> diff --git a/arch/arm/cpu/armv7/omap-common/spl_ymodem.c b/arch/arm/cpu/armv7/omap-common/spl_ymodem.c
> deleted file mode 100644
> index 47663f7..0000000
> --- a/arch/arm/cpu/armv7/omap-common/spl_ymodem.c
> +++ /dev/null
> @@ -1,76 +0,0 @@
> -/*
> - * (C) Copyright 2000-2004
> - * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
> - *
> - * (C) Copyright 2011
> - * Texas Instruments, <www.ti.com>
> - *
> - * Matt Porter <mporter@ti.com>
> - *
> - * See file CREDITS for list of people who contributed to this
> - * project.
> - *
> - * This program is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU General Public License as
> - * published by the Free Software Foundation; either version 2 of
> - * the License, or (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write to the Free Software
> - * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> - * MA 02111-1307 USA
> - */
> -#include <common.h>
> -#include <xyzModem.h>
> -#include <asm/u-boot.h>
> -#include <asm/utils.h>
> -#include <asm/arch/sys_proto.h>
> -#include <asm/omap_common.h>
> -
> -#define BUF_SIZE 1024
> -
> -static int getcymodem(void) {
> -	if (tstc())
> -		return (getc());
> -	return -1;
> -}
> -
> -void spl_ymodem_load_image(void)
> -{
> -	int size = 0;
> -	int err;
> -	int res;
> -	int ret;
> -	connection_info_t info;
> -	char buf[BUF_SIZE];
> -	ulong store_addr = ~0;
> -	ulong addr = 0;
> -
> -	info.mode = xyzModem_ymodem;
> -	ret = xyzModem_stream_open(&info, &err);
> -
> -	if (!ret) {
> -		while ((res =
> -			xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) {
> -			if (addr == 0)
> -				spl_parse_image_header((struct image_header *)buf);
> -			store_addr = addr + spl_image.load_addr;
> -			size += res;
> -			addr += res;
> -			memcpy((char *)(store_addr), buf, res);
> -		}
> -	} else {
> -		printf("spl: ymodem err - %s\n", xyzModem_error(err));
> -		hang();
> -	}
> -
> -	xyzModem_stream_close(&err);
> -	xyzModem_stream_terminate(false, &getcymodem);
> -
> -	printf("Loaded %d bytes\n", size);
> -}
> diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
> index 39a9550..abf550a 100644
> --- a/arch/arm/lib/Makefile
> +++ b/arch/arm/lib/Makefile
> @@ -26,7 +26,14 @@ include $(TOPDIR)/config.mk
>  LIB	= $(obj)lib$(ARCH).o
>  LIBGCC	= $(obj)libgcc.o
>  
> -ifndef CONFIG_SPL_BUILD
> +ifdef CONFIG_SPL_BUILD
> +ifdef CONFIG_SPL_FRAMEWORK
> +COBJS-$(CONFIG_SPL_FRAMEWORK)		+= spl.o
> +COBJS-$(CONFIG_SPL_NAND_SUPPORT)	+= spl_nand.o
> +COBJS-$(CONFIG_SPL_MMC_SUPPORT)		+= spl_mmc.o
> +COBJS-$(CONFIG_SPL_YMODEM_SUPPORT)	+= spl_ymodem.o
> +endif
> +else
>  GLSOBJS	+= _ashldi3.o
>  GLSOBJS	+= _ashrdi3.o
>  GLSOBJS	+= _divsi3.o
> diff --git a/arch/arm/lib/spl.c b/arch/arm/lib/spl.c
> new file mode 100644
> index 0000000..b10832a
> --- /dev/null
> +++ b/arch/arm/lib/spl.c
> @@ -0,0 +1,225 @@
> +/*
> + * (C) Copyright 2010
> + * Texas Instruments, <www.ti.com>
> + *
> + * Aneesh V <aneesh@ti.com>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +#include <common.h>
> +#include <asm/u-boot.h>
> +#include <asm/utils.h>
> +#include <asm/arch/sys_proto.h>
> +#include <nand.h>
> +#include <mmc.h>
> +#include <fat.h>
> +#include <version.h>
> +#include <asm/omap_common.h>

This is a conflict I got. This file should be generic code, and should
not have reference to a specific SOC or SOC family, as omap here. So I
have added a include/spl.h with only the SPL relevant part, dropping
other OMAP specific from this file (I see you did the same with
omap_boot_device and omap_boot_mode).


> +#include <asm/arch/mmc_host_def.h>

As far as I have understood, this is only for MMCSD_SECTOR_SIZE, that
can be moved into another header file. Not all SOCs have
asm/arch/mmc_host_def.h


> +#include <common.h>
> +#include <asm/u-boot.h>
> +#include <asm/utils.h>
> +#include <asm/arch/sys_proto.h>
> +#include <mmc.h>
> +#include <fat.h>
> +#include <version.h>
> +#include <asm/omap_common.h>
> +#include <asm/arch/mmc_host_def.h>

Both files are OMAP specific

> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +#ifdef CONFIG_GENERIC_MMC
> +int board_mmc_init(bd_t *bis)
> +{
> +	switch (omap_boot_device()) {

And this is also omap specific. Replaced by soc_boot_device ?

Cheers,
Stefano
Tom Rini - Aug. 16, 2012, 2:38 p.m.
On 08/16/2012 12:45 AM, Stefano Babic wrote:
> On 15/08/2012 23:30, Tom Rini wrote:
>> Add a new flag, CONFIG_SPL_FRAMEWORK to opt into the arch/arm/lib SPL
>> framework, enable on all of the previously using boards.
>>
>> Signed-off-by: Tom Rini <trini@ti.com>
>> ---
> 
> Hi Tom,
> 
>>  README                                      |    5 +
>>  arch/arm/cpu/armv7/omap-common/Makefile     |   13 --
>>  arch/arm/cpu/armv7/omap-common/spl.c        |  225 ---------------------------
>>  arch/arm/cpu/armv7/omap-common/spl_mmc.c    |  154 ------------------
>>  arch/arm/cpu/armv7/omap-common/spl_nand.c   |  111 -------------
>>  arch/arm/cpu/armv7/omap-common/spl_ymodem.c |   76 ---------
>>  arch/arm/lib/Makefile                       |    9 +-
>>  arch/arm/lib/spl.c                          |  225 +++++++++++++++++++++++++++
>>  arch/arm/lib/spl_mmc.c                      |  154 ++++++++++++++++++
>>  arch/arm/lib/spl_nand.c                     |  111 +++++++++++++
>>  arch/arm/lib/spl_ymodem.c                   |   76 +++++++++
>>  include/configs/am335x_evm.h                |    1 +
>>  include/configs/am3517_crane.h              |    1 +
>>  include/configs/am3517_evm.h                |    1 +
>>  include/configs/devkit8000.h                |    1 +
>>  include/configs/mcx.h                       |    1 +
>>  include/configs/omap3_beagle.h              |    1 +
>>  include/configs/omap3_evm_common.h          |    1 +
>>  include/configs/omap3_overo.h               |    1 +
>>  include/configs/omap4_common.h              |    1 +
>>  include/configs/omap5_evm.h                 |    1 +
>>  include/configs/tam3517-common.h            |    1 +
>>  include/configs/tricorder.h                 |    1 +
>>  23 files changed, 591 insertions(+), 580 deletions(-)
>>  delete mode 100644 arch/arm/cpu/armv7/omap-common/spl.c
>>  delete mode 100644 arch/arm/cpu/armv7/omap-common/spl_mmc.c
>>  delete mode 100644 arch/arm/cpu/armv7/omap-common/spl_nand.c
>>  delete mode 100644 arch/arm/cpu/armv7/omap-common/spl_ymodem.c
>>  create mode 100644 arch/arm/lib/spl.c
>>  create mode 100644 arch/arm/lib/spl_mmc.c
>>  create mode 100644 arch/arm/lib/spl_nand.c
>>  create mode 100644 arch/arm/lib/spl_ymodem.c
>>
> 
> In my attempt I moved files from arch/arm/cpu/armv7/omap-common/ to
> common. This is because to make it available to all SOCs, not only
> armv7. What do you think about ? I would like to add an example with an
> arm1136 (MX35).

Second request so yes, for v2 I'll move things to common/

[snip]
>> +#include <asm/omap_common.h>
> 
> This is a conflict I got. This file should be generic code, and should
> not have reference to a specific SOC or SOC family, as omap here. So I
> have added a include/spl.h with only the SPL relevant part, dropping
> other OMAP specific from this file (I see you did the same with
> omap_boot_device and omap_boot_mode).
> 
> 
>> +#include <asm/arch/mmc_host_def.h>
> 
> As far as I have understood, this is only for MMCSD_SECTOR_SIZE, that
> can be moved into another header file. Not all SOCs have
> asm/arch/mmc_host_def.h

Yes, mandating what the asm/ mmc header file names should be is
something I've thought about but not had to step on, yet.

>> +#include <common.h>
>> +#include <asm/u-boot.h>
>> +#include <asm/utils.h>
>> +#include <asm/arch/sys_proto.h>
>> +#include <mmc.h>
>> +#include <fat.h>
>> +#include <version.h>
>> +#include <asm/omap_common.h>
>> +#include <asm/arch/mmc_host_def.h>
> 
> Both files are OMAP specific
> 
>> +
>> +DECLARE_GLOBAL_DATA_PTR;
>> +
>> +#ifdef CONFIG_GENERIC_MMC
>> +int board_mmc_init(bd_t *bis)
>> +{
>> +	switch (omap_boot_device()) {
> 
> And this is also omap specific. Replaced by soc_boot_device ?

My goal with this series, and part of why I added CONFIG_SPL_FRAMEWORK
was that indeed, there's a lot of omap-isms in the code at the start.  I
believe by the end of the series they're all removed and the code is
common.  If it's a concern I can re-work things so that the move is one
of the last steps.
Stefano Babic - Aug. 17, 2012, 8:25 a.m.
On 16/08/2012 16:38, Tom Rini wrote:
> On 08/16/2012 12:45 AM, Stefano Babic wrote:
>> On 15/08/2012 23:30, Tom Rini wrote:
>>> Add a new flag, CONFIG_SPL_FRAMEWORK to opt into the arch/arm/lib SPL
>>> framework, enable on all of the previously using boards.
>>>
>>> Signed-off-by: Tom Rini <trini@ti.com>
>>> ---
>>

Hi Tom,
> 
> My goal with this series, and part of why I added CONFIG_SPL_FRAMEWORK
> was that indeed, there's a lot of omap-isms in the code at the start.  I
> believe by the end of the series they're all removed and the code is
> common.  If it's a concern I can re-work things so that the move is one
> of the last steps.

No, it is not a problem. I am setting on top of your tree and it looks
great.

Regards,
Stefano

Patch

diff --git a/README b/README
index f1a12a5..de6b6c5 100644
--- a/README
+++ b/README
@@ -2564,6 +2564,11 @@  FIT uImage format:
 		CONFIG_SYS_SPL_MALLOC_SIZE
 		The size of the malloc pool used in SPL.
 
+		CONFIG_SPL_FRAMEWORK
+		For ARM, enable the SPL framework under arch/arm/lib, which
+		supports MMC, NAND and YMODEM loading of U-Boot and NAND
+		NAND loading of the Linux Kernel.
+
 		CONFIG_SPL_DISPLAY_PRINT
 		For ARM, enable an optional function to print more information
 		about the running system.
diff --git a/arch/arm/cpu/armv7/omap-common/Makefile b/arch/arm/cpu/armv7/omap-common/Makefile
index 2a6625f..0e0b641 100644
--- a/arch/arm/cpu/armv7/omap-common/Makefile
+++ b/arch/arm/cpu/armv7/omap-common/Makefile
@@ -45,19 +45,6 @@  COBJS	+= boot-common.o
 SOBJS	+= lowlevel_init.o
 endif
 
-ifdef CONFIG_SPL_BUILD
-COBJS	+= spl.o
-ifdef CONFIG_SPL_NAND_SUPPORT
-COBJS	+= spl_nand.o
-endif
-ifdef CONFIG_SPL_MMC_SUPPORT
-COBJS	+= spl_mmc.o
-endif
-ifdef CONFIG_SPL_YMODEM_SUPPORT
-COBJS	+= spl_ymodem.o
-endif
-endif
-
 ifndef CONFIG_SPL_BUILD
 ifneq ($(CONFIG_OMAP44XX)$(CONFIG_OMAP54XX),)
 COBJS	+= mem-common.o
diff --git a/arch/arm/cpu/armv7/omap-common/spl.c b/arch/arm/cpu/armv7/omap-common/spl.c
deleted file mode 100644
index b10832a..0000000
--- a/arch/arm/cpu/armv7/omap-common/spl.c
+++ /dev/null
@@ -1,225 +0,0 @@ 
-/*
- * (C) Copyright 2010
- * Texas Instruments, <www.ti.com>
- *
- * Aneesh V <aneesh@ti.com>
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-#include <common.h>
-#include <asm/u-boot.h>
-#include <asm/utils.h>
-#include <asm/arch/sys_proto.h>
-#include <nand.h>
-#include <mmc.h>
-#include <fat.h>
-#include <version.h>
-#include <asm/omap_common.h>
-#include <asm/arch/mmc_host_def.h>
-#include <i2c.h>
-#include <image.h>
-#include <malloc.h>
-#include <linux/compiler.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-u32* boot_params_ptr = NULL;
-struct spl_image_info spl_image;
-
-/* Define global data structure pointer to it*/
-static gd_t gdata __attribute__ ((section(".data")));
-static bd_t bdata __attribute__ ((section(".data")));
-
-inline void hang(void)
-{
-	puts("### ERROR ### Please RESET the board ###\n");
-	for (;;)
-		;
-}
-
-void board_init_f(ulong dummy)
-{
-	/*
-	 * We call relocate_code() with relocation target same as the
-	 * CONFIG_SYS_SPL_TEXT_BASE. This will result in relocation getting
-	 * skipped. Instead, only .bss initialization will happen. That's
-	 * all we need
-	 */
-	debug(">>board_init_f()\n");
-	relocate_code(CONFIG_SPL_STACK, &gdata, CONFIG_SPL_TEXT_BASE);
-}
-
-/*
- * Default function to determine if u-boot or the OS should
- * be started. This implementation always returns 1.
- *
- * Please implement your own board specific funcion to do this.
- *
- * RETURN
- * 0 to not start u-boot
- * positive if u-boot should start
- */
-#ifdef CONFIG_SPL_OS_BOOT
-__weak int spl_start_uboot(void)
-{
-	printf("SPL: Please implement spl_start_uboot() for your board\n");
-	printf("SPL: Direct Linux boot not active!\n");
-	return 1;
-}
-#endif
-
-void spl_parse_image_header(const struct image_header *header)
-{
-	u32 header_size = sizeof(struct image_header);
-
-	if (__be32_to_cpu(header->ih_magic) == IH_MAGIC) {
-		spl_image.size = __be32_to_cpu(header->ih_size) + header_size;
-		spl_image.entry_point = __be32_to_cpu(header->ih_load);
-		/* Load including the header */
-		spl_image.load_addr = spl_image.entry_point - header_size;
-		spl_image.os = header->ih_os;
-		spl_image.name = (const char *)&header->ih_name;
-		debug("spl: payload image: %s load addr: 0x%x size: %d\n",
-			spl_image.name, spl_image.load_addr, spl_image.size);
-	} else {
-		/* Signature not found - assume u-boot.bin */
-		printf("mkimage signature not found - ih_magic = %x\n",
-			header->ih_magic);
-		debug("Assuming u-boot.bin ..\n");
-		/* Let's assume U-Boot will not be more than 200 KB */
-		spl_image.size = 200 * 1024;
-		spl_image.entry_point = CONFIG_SYS_TEXT_BASE;
-		spl_image.load_addr = CONFIG_SYS_TEXT_BASE;
-		spl_image.os = IH_OS_U_BOOT;
-		spl_image.name = "U-Boot";
-	}
-}
-
-/*
- * This function jumps to an image with argument. Normally an FDT or ATAGS
- * image.
- * arg: Pointer to paramter image in RAM
- */
-#ifdef CONFIG_SPL_OS_BOOT
-static void __noreturn jump_to_image_linux(void *arg)
-{
-	debug("Entering kernel arg pointer: 0x%p\n", arg);
-	typedef void (*image_entry_arg_t)(int, int, void *)
-		__attribute__ ((noreturn));
-	image_entry_arg_t image_entry =
-		(image_entry_arg_t) spl_image.entry_point;
-	cleanup_before_linux();
-	image_entry(0, CONFIG_MACH_TYPE, arg);
-}
-#endif
-
-static void __noreturn jump_to_image_no_args(void)
-{
-	typedef void __noreturn (*image_entry_noargs_t)(u32 *);
-	image_entry_noargs_t image_entry =
-			(image_entry_noargs_t) spl_image.entry_point;
-
-	debug("image entry point: 0x%X\n", spl_image.entry_point);
-	/* Pass the saved boot_params from rom code */
-#if defined(CONFIG_VIRTIO) || defined(CONFIG_ZEBU)
-	image_entry = (image_entry_noargs_t)0x80100000;
-#endif
-	u32 boot_params_ptr_addr = (u32)&boot_params_ptr;
-	image_entry((u32 *)boot_params_ptr_addr);
-}
-
-void board_init_r(gd_t *id, ulong dummy)
-{
-	u32 boot_device;
-	debug(">>spl:board_init_r()\n");
-
-	mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
-			CONFIG_SYS_SPL_MALLOC_SIZE);
-
-#ifdef CONFIG_SPL_BOARD_INIT
-	spl_board_init();
-#endif
-
-	boot_device = omap_boot_device();
-	debug("boot device - %d\n", boot_device);
-	switch (boot_device) {
-#ifdef CONFIG_SPL_MMC_SUPPORT
-	case BOOT_DEVICE_MMC1:
-	case BOOT_DEVICE_MMC2:
-	case BOOT_DEVICE_MMC2_2:
-		spl_mmc_load_image();
-		break;
-#endif
-#ifdef CONFIG_SPL_NAND_SUPPORT
-	case BOOT_DEVICE_NAND:
-		spl_nand_load_image();
-		break;
-#endif
-#ifdef CONFIG_SPL_YMODEM_SUPPORT
-	case BOOT_DEVICE_UART:
-		spl_ymodem_load_image();
-		break;
-#endif
-	default:
-		printf("SPL: Un-supported Boot Device - %d!!!\n", boot_device);
-		hang();
-		break;
-	}
-
-	switch (spl_image.os) {
-	case IH_OS_U_BOOT:
-		debug("Jumping to U-Boot\n");
-		jump_to_image_no_args();
-		break;
-#ifdef CONFIG_SPL_OS_BOOT
-	case IH_OS_LINUX:
-		debug("Jumping to Linux\n");
-		spl_board_prepare_for_linux();
-		jump_to_image_linux((void *)CONFIG_SYS_SPL_ARGS_ADDR);
-		break;
-#endif
-	default:
-		puts("Unsupported OS image.. Jumping nevertheless..\n");
-		jump_to_image_no_args();
-	}
-}
-
-/* This requires UART clocks to be enabled */
-void preloader_console_init(void)
-{
-	const char *u_boot_rev = U_BOOT_VERSION;
-
-	gd = &gdata;
-	gd->bd = &bdata;
-	gd->flags |= GD_FLG_RELOC;
-	gd->baudrate = CONFIG_BAUDRATE;
-
-	serial_init();		/* serial communications setup */
-
-	gd->have_console = 1;
-
-	/* Avoid a second "U-Boot" coming from this string */
-	u_boot_rev = &u_boot_rev[7];
-
-	printf("\nU-Boot SPL %s (%s - %s)\n", u_boot_rev, U_BOOT_DATE,
-		U_BOOT_TIME);
-#ifdef CONFIG_SPL_DISPLAY_PRINT
-	spl_display_print();
-#endif
-}
diff --git a/arch/arm/cpu/armv7/omap-common/spl_mmc.c b/arch/arm/cpu/armv7/omap-common/spl_mmc.c
deleted file mode 100644
index 7552f6c..0000000
--- a/arch/arm/cpu/armv7/omap-common/spl_mmc.c
+++ /dev/null
@@ -1,154 +0,0 @@ 
-/*
- * (C) Copyright 2010
- * Texas Instruments, <www.ti.com>
- *
- * Aneesh V <aneesh@ti.com>
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-#include <common.h>
-#include <asm/u-boot.h>
-#include <asm/utils.h>
-#include <asm/arch/sys_proto.h>
-#include <mmc.h>
-#include <fat.h>
-#include <version.h>
-#include <asm/omap_common.h>
-#include <asm/arch/mmc_host_def.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-#ifdef CONFIG_GENERIC_MMC
-int board_mmc_init(bd_t *bis)
-{
-	switch (omap_boot_device()) {
-	case BOOT_DEVICE_MMC1:
-		omap_mmc_init(0, 0, 0);
-		break;
-	case BOOT_DEVICE_MMC2:
-	case BOOT_DEVICE_MMC2_2:
-		omap_mmc_init(1, 0, 0);
-		break;
-	}
-	return 0;
-}
-#endif
-
-static void mmc_load_image_raw(struct mmc *mmc)
-{
-	u32 image_size_sectors, err;
-	const struct image_header *header;
-
-	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
-						sizeof(struct image_header));
-
-	/* read image header to find the image size & load address */
-	err = mmc->block_dev.block_read(0,
-			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, 1,
-			(void *)header);
-
-	if (err <= 0)
-		goto end;
-
-	spl_parse_image_header(header);
-
-	/* convert size to sectors - round up */
-	image_size_sectors = (spl_image.size + MMCSD_SECTOR_SIZE - 1) /
-				MMCSD_SECTOR_SIZE;
-
-	/* Read the header too to avoid extra memcpy */
-	err = mmc->block_dev.block_read(0,
-			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR,
-			image_size_sectors, (void *)spl_image.load_addr);
-
-end:
-	if (err <= 0) {
-		printf("spl: mmc blk read err - %d\n", err);
-		hang();
-	}
-}
-
-#ifdef CONFIG_SPL_FAT_SUPPORT
-static void mmc_load_image_fat(struct mmc *mmc)
-{
-	s32 err;
-	struct image_header *header;
-
-	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
-						sizeof(struct image_header));
-
-	err = fat_register_device(&mmc->block_dev,
-				CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION);
-	if (err) {
-		printf("spl: fat register err - %d\n", err);
-		hang();
-	}
-
-	err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME,
-				(u8 *)header, sizeof(struct image_header));
-	if (err <= 0)
-		goto end;
-
-	spl_parse_image_header(header);
-
-	err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME,
-				(u8 *)spl_image.load_addr, 0);
-
-end:
-	if (err <= 0) {
-		printf("spl: error reading image %s, err - %d\n",
-			CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, err);
-		hang();
-	}
-}
-#endif
-
-void spl_mmc_load_image(void)
-{
-	struct mmc *mmc;
-	int err;
-	u32 boot_mode;
-
-	mmc_initialize(gd->bd);
-	/* We register only one device. So, the dev id is always 0 */
-	mmc = find_mmc_device(0);
-	if (!mmc) {
-		puts("spl: mmc device not found!!\n");
-		hang();
-	}
-
-	err = mmc_init(mmc);
-	if (err) {
-		printf("spl: mmc init failed: err - %d\n", err);
-		hang();
-	}
-	boot_mode = omap_boot_mode();
-	if (boot_mode == MMCSD_MODE_RAW) {
-		debug("boot mode - RAW\n");
-		mmc_load_image_raw(mmc);
-#ifdef CONFIG_SPL_FAT_SUPPORT
-	} else if (boot_mode == MMCSD_MODE_FAT) {
-		debug("boot mode - FAT\n");
-		mmc_load_image_fat(mmc);
-#endif
-	} else {
-		puts("spl: wrong MMC boot mode\n");
-		hang();
-	}
-}
diff --git a/arch/arm/cpu/armv7/omap-common/spl_nand.c b/arch/arm/cpu/armv7/omap-common/spl_nand.c
deleted file mode 100644
index 8cf55c9..0000000
--- a/arch/arm/cpu/armv7/omap-common/spl_nand.c
+++ /dev/null
@@ -1,111 +0,0 @@ 
-/*
- * Copyright (C) 2011
- * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-#include <common.h>
-#include <asm/u-boot.h>
-#include <asm/utils.h>
-#include <asm/arch/sys_proto.h>
-#include <asm/io.h>
-#include <nand.h>
-#include <version.h>
-#include <asm/omap_common.h>
-
-void spl_nand_load_image(void)
-{
-	struct image_header *header;
-	int *src __attribute__((unused));
-	int *dst __attribute__((unused));
-
-	switch (omap_boot_mode()) {
-	case NAND_MODE_HW_ECC:
-		debug("spl: nand - using hw ecc\n");
-		gpmc_init();
-		nand_init();
-		break;
-	default:
-		puts("spl: ERROR: This bootmode is not implemented - hanging");
-		hang();
-	}
-
-	/*use CONFIG_SYS_TEXT_BASE as temporary storage area */
-	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
-#ifdef CONFIG_SPL_OS_BOOT
-	if (!spl_start_uboot()) {
-		/*
-		 * load parameter image
-		 * load to temp position since nand_spl_load_image reads
-		 * a whole block which is typically larger than
-		 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
-		 * following sections like BSS
-		 */
-		nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
-			CONFIG_CMD_SPL_WRITE_SIZE,
-			(void *)CONFIG_SYS_TEXT_BASE);
-		/* copy to destintion */
-		for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
-				src = (int *)CONFIG_SYS_TEXT_BASE;
-				src < (int *)(CONFIG_SYS_TEXT_BASE +
-				CONFIG_CMD_SPL_WRITE_SIZE);
-				src++, dst++) {
-			writel(readl(src), dst);
-		}
-
-		/* load linux */
-		nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
-			CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
-		spl_parse_image_header(header);
-		if (header->ih_os == IH_OS_LINUX) {
-			/* happy - was a linux */
-			nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
-				spl_image.size, (void *)spl_image.load_addr);
-			nand_deselect();
-			return;
-		} else {
-			printf("The Expected Linux image was not"
-				"found. Please check your NAND"
-				"configuration.\n");
-			printf("Trying to start u-boot now...\n");
-		}
-	}
-#endif
-#ifdef CONFIG_NAND_ENV_DST
-	nand_spl_load_image(CONFIG_ENV_OFFSET,
-		CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
-	spl_parse_image_header(header);
-	nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
-		(void *)spl_image.load_addr);
-#ifdef CONFIG_ENV_OFFSET_REDUND
-	nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
-		CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
-	spl_parse_image_header(header);
-	nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
-		(void *)spl_image.load_addr);
-#endif
-#endif
-	/* Load u-boot */
-	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
-		CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
-	spl_parse_image_header(header);
-	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
-		spl_image.size, (void *)spl_image.load_addr);
-	nand_deselect();
-}
diff --git a/arch/arm/cpu/armv7/omap-common/spl_ymodem.c b/arch/arm/cpu/armv7/omap-common/spl_ymodem.c
deleted file mode 100644
index 47663f7..0000000
--- a/arch/arm/cpu/armv7/omap-common/spl_ymodem.c
+++ /dev/null
@@ -1,76 +0,0 @@ 
-/*
- * (C) Copyright 2000-2004
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * (C) Copyright 2011
- * Texas Instruments, <www.ti.com>
- *
- * Matt Porter <mporter@ti.com>
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-#include <common.h>
-#include <xyzModem.h>
-#include <asm/u-boot.h>
-#include <asm/utils.h>
-#include <asm/arch/sys_proto.h>
-#include <asm/omap_common.h>
-
-#define BUF_SIZE 1024
-
-static int getcymodem(void) {
-	if (tstc())
-		return (getc());
-	return -1;
-}
-
-void spl_ymodem_load_image(void)
-{
-	int size = 0;
-	int err;
-	int res;
-	int ret;
-	connection_info_t info;
-	char buf[BUF_SIZE];
-	ulong store_addr = ~0;
-	ulong addr = 0;
-
-	info.mode = xyzModem_ymodem;
-	ret = xyzModem_stream_open(&info, &err);
-
-	if (!ret) {
-		while ((res =
-			xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) {
-			if (addr == 0)
-				spl_parse_image_header((struct image_header *)buf);
-			store_addr = addr + spl_image.load_addr;
-			size += res;
-			addr += res;
-			memcpy((char *)(store_addr), buf, res);
-		}
-	} else {
-		printf("spl: ymodem err - %s\n", xyzModem_error(err));
-		hang();
-	}
-
-	xyzModem_stream_close(&err);
-	xyzModem_stream_terminate(false, &getcymodem);
-
-	printf("Loaded %d bytes\n", size);
-}
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 39a9550..abf550a 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -26,7 +26,14 @@  include $(TOPDIR)/config.mk
 LIB	= $(obj)lib$(ARCH).o
 LIBGCC	= $(obj)libgcc.o
 
-ifndef CONFIG_SPL_BUILD
+ifdef CONFIG_SPL_BUILD
+ifdef CONFIG_SPL_FRAMEWORK
+COBJS-$(CONFIG_SPL_FRAMEWORK)		+= spl.o
+COBJS-$(CONFIG_SPL_NAND_SUPPORT)	+= spl_nand.o
+COBJS-$(CONFIG_SPL_MMC_SUPPORT)		+= spl_mmc.o
+COBJS-$(CONFIG_SPL_YMODEM_SUPPORT)	+= spl_ymodem.o
+endif
+else
 GLSOBJS	+= _ashldi3.o
 GLSOBJS	+= _ashrdi3.o
 GLSOBJS	+= _divsi3.o
diff --git a/arch/arm/lib/spl.c b/arch/arm/lib/spl.c
new file mode 100644
index 0000000..b10832a
--- /dev/null
+++ b/arch/arm/lib/spl.c
@@ -0,0 +1,225 @@ 
+/*
+ * (C) Copyright 2010
+ * Texas Instruments, <www.ti.com>
+ *
+ * Aneesh V <aneesh@ti.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <common.h>
+#include <asm/u-boot.h>
+#include <asm/utils.h>
+#include <asm/arch/sys_proto.h>
+#include <nand.h>
+#include <mmc.h>
+#include <fat.h>
+#include <version.h>
+#include <asm/omap_common.h>
+#include <asm/arch/mmc_host_def.h>
+#include <i2c.h>
+#include <image.h>
+#include <malloc.h>
+#include <linux/compiler.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+u32* boot_params_ptr = NULL;
+struct spl_image_info spl_image;
+
+/* Define global data structure pointer to it*/
+static gd_t gdata __attribute__ ((section(".data")));
+static bd_t bdata __attribute__ ((section(".data")));
+
+inline void hang(void)
+{
+	puts("### ERROR ### Please RESET the board ###\n");
+	for (;;)
+		;
+}
+
+void board_init_f(ulong dummy)
+{
+	/*
+	 * We call relocate_code() with relocation target same as the
+	 * CONFIG_SYS_SPL_TEXT_BASE. This will result in relocation getting
+	 * skipped. Instead, only .bss initialization will happen. That's
+	 * all we need
+	 */
+	debug(">>board_init_f()\n");
+	relocate_code(CONFIG_SPL_STACK, &gdata, CONFIG_SPL_TEXT_BASE);
+}
+
+/*
+ * Default function to determine if u-boot or the OS should
+ * be started. This implementation always returns 1.
+ *
+ * Please implement your own board specific funcion to do this.
+ *
+ * RETURN
+ * 0 to not start u-boot
+ * positive if u-boot should start
+ */
+#ifdef CONFIG_SPL_OS_BOOT
+__weak int spl_start_uboot(void)
+{
+	printf("SPL: Please implement spl_start_uboot() for your board\n");
+	printf("SPL: Direct Linux boot not active!\n");
+	return 1;
+}
+#endif
+
+void spl_parse_image_header(const struct image_header *header)
+{
+	u32 header_size = sizeof(struct image_header);
+
+	if (__be32_to_cpu(header->ih_magic) == IH_MAGIC) {
+		spl_image.size = __be32_to_cpu(header->ih_size) + header_size;
+		spl_image.entry_point = __be32_to_cpu(header->ih_load);
+		/* Load including the header */
+		spl_image.load_addr = spl_image.entry_point - header_size;
+		spl_image.os = header->ih_os;
+		spl_image.name = (const char *)&header->ih_name;
+		debug("spl: payload image: %s load addr: 0x%x size: %d\n",
+			spl_image.name, spl_image.load_addr, spl_image.size);
+	} else {
+		/* Signature not found - assume u-boot.bin */
+		printf("mkimage signature not found - ih_magic = %x\n",
+			header->ih_magic);
+		debug("Assuming u-boot.bin ..\n");
+		/* Let's assume U-Boot will not be more than 200 KB */
+		spl_image.size = 200 * 1024;
+		spl_image.entry_point = CONFIG_SYS_TEXT_BASE;
+		spl_image.load_addr = CONFIG_SYS_TEXT_BASE;
+		spl_image.os = IH_OS_U_BOOT;
+		spl_image.name = "U-Boot";
+	}
+}
+
+/*
+ * This function jumps to an image with argument. Normally an FDT or ATAGS
+ * image.
+ * arg: Pointer to paramter image in RAM
+ */
+#ifdef CONFIG_SPL_OS_BOOT
+static void __noreturn jump_to_image_linux(void *arg)
+{
+	debug("Entering kernel arg pointer: 0x%p\n", arg);
+	typedef void (*image_entry_arg_t)(int, int, void *)
+		__attribute__ ((noreturn));
+	image_entry_arg_t image_entry =
+		(image_entry_arg_t) spl_image.entry_point;
+	cleanup_before_linux();
+	image_entry(0, CONFIG_MACH_TYPE, arg);
+}
+#endif
+
+static void __noreturn jump_to_image_no_args(void)
+{
+	typedef void __noreturn (*image_entry_noargs_t)(u32 *);
+	image_entry_noargs_t image_entry =
+			(image_entry_noargs_t) spl_image.entry_point;
+
+	debug("image entry point: 0x%X\n", spl_image.entry_point);
+	/* Pass the saved boot_params from rom code */
+#if defined(CONFIG_VIRTIO) || defined(CONFIG_ZEBU)
+	image_entry = (image_entry_noargs_t)0x80100000;
+#endif
+	u32 boot_params_ptr_addr = (u32)&boot_params_ptr;
+	image_entry((u32 *)boot_params_ptr_addr);
+}
+
+void board_init_r(gd_t *id, ulong dummy)
+{
+	u32 boot_device;
+	debug(">>spl:board_init_r()\n");
+
+	mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
+			CONFIG_SYS_SPL_MALLOC_SIZE);
+
+#ifdef CONFIG_SPL_BOARD_INIT
+	spl_board_init();
+#endif
+
+	boot_device = omap_boot_device();
+	debug("boot device - %d\n", boot_device);
+	switch (boot_device) {
+#ifdef CONFIG_SPL_MMC_SUPPORT
+	case BOOT_DEVICE_MMC1:
+	case BOOT_DEVICE_MMC2:
+	case BOOT_DEVICE_MMC2_2:
+		spl_mmc_load_image();
+		break;
+#endif
+#ifdef CONFIG_SPL_NAND_SUPPORT
+	case BOOT_DEVICE_NAND:
+		spl_nand_load_image();
+		break;
+#endif
+#ifdef CONFIG_SPL_YMODEM_SUPPORT
+	case BOOT_DEVICE_UART:
+		spl_ymodem_load_image();
+		break;
+#endif
+	default:
+		printf("SPL: Un-supported Boot Device - %d!!!\n", boot_device);
+		hang();
+		break;
+	}
+
+	switch (spl_image.os) {
+	case IH_OS_U_BOOT:
+		debug("Jumping to U-Boot\n");
+		jump_to_image_no_args();
+		break;
+#ifdef CONFIG_SPL_OS_BOOT
+	case IH_OS_LINUX:
+		debug("Jumping to Linux\n");
+		spl_board_prepare_for_linux();
+		jump_to_image_linux((void *)CONFIG_SYS_SPL_ARGS_ADDR);
+		break;
+#endif
+	default:
+		puts("Unsupported OS image.. Jumping nevertheless..\n");
+		jump_to_image_no_args();
+	}
+}
+
+/* This requires UART clocks to be enabled */
+void preloader_console_init(void)
+{
+	const char *u_boot_rev = U_BOOT_VERSION;
+
+	gd = &gdata;
+	gd->bd = &bdata;
+	gd->flags |= GD_FLG_RELOC;
+	gd->baudrate = CONFIG_BAUDRATE;
+
+	serial_init();		/* serial communications setup */
+
+	gd->have_console = 1;
+
+	/* Avoid a second "U-Boot" coming from this string */
+	u_boot_rev = &u_boot_rev[7];
+
+	printf("\nU-Boot SPL %s (%s - %s)\n", u_boot_rev, U_BOOT_DATE,
+		U_BOOT_TIME);
+#ifdef CONFIG_SPL_DISPLAY_PRINT
+	spl_display_print();
+#endif
+}
diff --git a/arch/arm/lib/spl_mmc.c b/arch/arm/lib/spl_mmc.c
new file mode 100644
index 0000000..7552f6c
--- /dev/null
+++ b/arch/arm/lib/spl_mmc.c
@@ -0,0 +1,154 @@ 
+/*
+ * (C) Copyright 2010
+ * Texas Instruments, <www.ti.com>
+ *
+ * Aneesh V <aneesh@ti.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <common.h>
+#include <asm/u-boot.h>
+#include <asm/utils.h>
+#include <asm/arch/sys_proto.h>
+#include <mmc.h>
+#include <fat.h>
+#include <version.h>
+#include <asm/omap_common.h>
+#include <asm/arch/mmc_host_def.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#ifdef CONFIG_GENERIC_MMC
+int board_mmc_init(bd_t *bis)
+{
+	switch (omap_boot_device()) {
+	case BOOT_DEVICE_MMC1:
+		omap_mmc_init(0, 0, 0);
+		break;
+	case BOOT_DEVICE_MMC2:
+	case BOOT_DEVICE_MMC2_2:
+		omap_mmc_init(1, 0, 0);
+		break;
+	}
+	return 0;
+}
+#endif
+
+static void mmc_load_image_raw(struct mmc *mmc)
+{
+	u32 image_size_sectors, err;
+	const struct image_header *header;
+
+	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
+						sizeof(struct image_header));
+
+	/* read image header to find the image size & load address */
+	err = mmc->block_dev.block_read(0,
+			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, 1,
+			(void *)header);
+
+	if (err <= 0)
+		goto end;
+
+	spl_parse_image_header(header);
+
+	/* convert size to sectors - round up */
+	image_size_sectors = (spl_image.size + MMCSD_SECTOR_SIZE - 1) /
+				MMCSD_SECTOR_SIZE;
+
+	/* Read the header too to avoid extra memcpy */
+	err = mmc->block_dev.block_read(0,
+			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR,
+			image_size_sectors, (void *)spl_image.load_addr);
+
+end:
+	if (err <= 0) {
+		printf("spl: mmc blk read err - %d\n", err);
+		hang();
+	}
+}
+
+#ifdef CONFIG_SPL_FAT_SUPPORT
+static void mmc_load_image_fat(struct mmc *mmc)
+{
+	s32 err;
+	struct image_header *header;
+
+	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
+						sizeof(struct image_header));
+
+	err = fat_register_device(&mmc->block_dev,
+				CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION);
+	if (err) {
+		printf("spl: fat register err - %d\n", err);
+		hang();
+	}
+
+	err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME,
+				(u8 *)header, sizeof(struct image_header));
+	if (err <= 0)
+		goto end;
+
+	spl_parse_image_header(header);
+
+	err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME,
+				(u8 *)spl_image.load_addr, 0);
+
+end:
+	if (err <= 0) {
+		printf("spl: error reading image %s, err - %d\n",
+			CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, err);
+		hang();
+	}
+}
+#endif
+
+void spl_mmc_load_image(void)
+{
+	struct mmc *mmc;
+	int err;
+	u32 boot_mode;
+
+	mmc_initialize(gd->bd);
+	/* We register only one device. So, the dev id is always 0 */
+	mmc = find_mmc_device(0);
+	if (!mmc) {
+		puts("spl: mmc device not found!!\n");
+		hang();
+	}
+
+	err = mmc_init(mmc);
+	if (err) {
+		printf("spl: mmc init failed: err - %d\n", err);
+		hang();
+	}
+	boot_mode = omap_boot_mode();
+	if (boot_mode == MMCSD_MODE_RAW) {
+		debug("boot mode - RAW\n");
+		mmc_load_image_raw(mmc);
+#ifdef CONFIG_SPL_FAT_SUPPORT
+	} else if (boot_mode == MMCSD_MODE_FAT) {
+		debug("boot mode - FAT\n");
+		mmc_load_image_fat(mmc);
+#endif
+	} else {
+		puts("spl: wrong MMC boot mode\n");
+		hang();
+	}
+}
diff --git a/arch/arm/lib/spl_nand.c b/arch/arm/lib/spl_nand.c
new file mode 100644
index 0000000..8cf55c9
--- /dev/null
+++ b/arch/arm/lib/spl_nand.c
@@ -0,0 +1,111 @@ 
+/*
+ * Copyright (C) 2011
+ * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <common.h>
+#include <asm/u-boot.h>
+#include <asm/utils.h>
+#include <asm/arch/sys_proto.h>
+#include <asm/io.h>
+#include <nand.h>
+#include <version.h>
+#include <asm/omap_common.h>
+
+void spl_nand_load_image(void)
+{
+	struct image_header *header;
+	int *src __attribute__((unused));
+	int *dst __attribute__((unused));
+
+	switch (omap_boot_mode()) {
+	case NAND_MODE_HW_ECC:
+		debug("spl: nand - using hw ecc\n");
+		gpmc_init();
+		nand_init();
+		break;
+	default:
+		puts("spl: ERROR: This bootmode is not implemented - hanging");
+		hang();
+	}
+
+	/*use CONFIG_SYS_TEXT_BASE as temporary storage area */
+	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
+#ifdef CONFIG_SPL_OS_BOOT
+	if (!spl_start_uboot()) {
+		/*
+		 * load parameter image
+		 * load to temp position since nand_spl_load_image reads
+		 * a whole block which is typically larger than
+		 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
+		 * following sections like BSS
+		 */
+		nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
+			CONFIG_CMD_SPL_WRITE_SIZE,
+			(void *)CONFIG_SYS_TEXT_BASE);
+		/* copy to destintion */
+		for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
+				src = (int *)CONFIG_SYS_TEXT_BASE;
+				src < (int *)(CONFIG_SYS_TEXT_BASE +
+				CONFIG_CMD_SPL_WRITE_SIZE);
+				src++, dst++) {
+			writel(readl(src), dst);
+		}
+
+		/* load linux */
+		nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
+			CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
+		spl_parse_image_header(header);
+		if (header->ih_os == IH_OS_LINUX) {
+			/* happy - was a linux */
+			nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
+				spl_image.size, (void *)spl_image.load_addr);
+			nand_deselect();
+			return;
+		} else {
+			printf("The Expected Linux image was not"
+				"found. Please check your NAND"
+				"configuration.\n");
+			printf("Trying to start u-boot now...\n");
+		}
+	}
+#endif
+#ifdef CONFIG_NAND_ENV_DST
+	nand_spl_load_image(CONFIG_ENV_OFFSET,
+		CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
+	spl_parse_image_header(header);
+	nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
+		(void *)spl_image.load_addr);
+#ifdef CONFIG_ENV_OFFSET_REDUND
+	nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
+		CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
+	spl_parse_image_header(header);
+	nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
+		(void *)spl_image.load_addr);
+#endif
+#endif
+	/* Load u-boot */
+	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
+		CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
+	spl_parse_image_header(header);
+	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
+		spl_image.size, (void *)spl_image.load_addr);
+	nand_deselect();
+}
diff --git a/arch/arm/lib/spl_ymodem.c b/arch/arm/lib/spl_ymodem.c
new file mode 100644
index 0000000..47663f7
--- /dev/null
+++ b/arch/arm/lib/spl_ymodem.c
@@ -0,0 +1,76 @@ 
+/*
+ * (C) Copyright 2000-2004
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * (C) Copyright 2011
+ * Texas Instruments, <www.ti.com>
+ *
+ * Matt Porter <mporter@ti.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <common.h>
+#include <xyzModem.h>
+#include <asm/u-boot.h>
+#include <asm/utils.h>
+#include <asm/arch/sys_proto.h>
+#include <asm/omap_common.h>
+
+#define BUF_SIZE 1024
+
+static int getcymodem(void) {
+	if (tstc())
+		return (getc());
+	return -1;
+}
+
+void spl_ymodem_load_image(void)
+{
+	int size = 0;
+	int err;
+	int res;
+	int ret;
+	connection_info_t info;
+	char buf[BUF_SIZE];
+	ulong store_addr = ~0;
+	ulong addr = 0;
+
+	info.mode = xyzModem_ymodem;
+	ret = xyzModem_stream_open(&info, &err);
+
+	if (!ret) {
+		while ((res =
+			xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) {
+			if (addr == 0)
+				spl_parse_image_header((struct image_header *)buf);
+			store_addr = addr + spl_image.load_addr;
+			size += res;
+			addr += res;
+			memcpy((char *)(store_addr), buf, res);
+		}
+	} else {
+		printf("spl: ymodem err - %s\n", xyzModem_error(err));
+		hang();
+	}
+
+	xyzModem_stream_close(&err);
+	xyzModem_stream_terminate(false, &getcymodem);
+
+	printf("Loaded %d bytes\n", size);
+}
diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h
index d0fbc88..cda2c4f 100644
--- a/include/configs/am335x_evm.h
+++ b/include/configs/am335x_evm.h
@@ -126,6 +126,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_TEXT_BASE		0x402F0400
 #define CONFIG_SPL_MAX_SIZE		(46 * 1024)
 #define CONFIG_SPL_STACK		LOW_LEVEL_SRAM_STACK
diff --git a/include/configs/am3517_crane.h b/include/configs/am3517_crane.h
index 54ab3eb..a5799d9 100644
--- a/include/configs/am3517_crane.h
+++ b/include/configs/am3517_crane.h
@@ -322,6 +322,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_NAND_SIMPLE
 #define CONFIG_SPL_TEXT_BASE		0x40200800
 #define CONFIG_SPL_MAX_SIZE		(54 * 1024)	/* 8 KB for stack */
diff --git a/include/configs/am3517_evm.h b/include/configs/am3517_evm.h
index ed0a601..62da56e 100644
--- a/include/configs/am3517_evm.h
+++ b/include/configs/am3517_evm.h
@@ -321,6 +321,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_NAND_SIMPLE
 #define CONFIG_SPL_TEXT_BASE		0x40200800
 #define CONFIG_SPL_MAX_SIZE		(54 * 1024)	/* 8 KB for stack */
diff --git a/include/configs/devkit8000.h b/include/configs/devkit8000.h
index 037a5bb..47187cf 100644
--- a/include/configs/devkit8000.h
+++ b/include/configs/devkit8000.h
@@ -305,6 +305,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_NAND_SIMPLE
 
 #define CONFIG_SPL_LIBCOMMON_SUPPORT
diff --git a/include/configs/mcx.h b/include/configs/mcx.h
index 970c882..d91258a 100644
--- a/include/configs/mcx.h
+++ b/include/configs/mcx.h
@@ -309,6 +309,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_NAND_SIMPLE
 #define CONFIG_SPL_NAND_SOFTECC
 
diff --git a/include/configs/omap3_beagle.h b/include/configs/omap3_beagle.h
index 657780e..1b4e2ee 100644
--- a/include/configs/omap3_beagle.h
+++ b/include/configs/omap3_beagle.h
@@ -398,6 +398,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_NAND_SIMPLE
 #define CONFIG_SPL_TEXT_BASE		0x40200800
 #define CONFIG_SPL_MAX_SIZE		(54 * 1024)	/* 8 KB for stack */
diff --git a/include/configs/omap3_evm_common.h b/include/configs/omap3_evm_common.h
index 20192a9..22f30f4 100644
--- a/include/configs/omap3_evm_common.h
+++ b/include/configs/omap3_evm_common.h
@@ -280,6 +280,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_TEXT_BASE		0x40200800
 #define CONFIG_SPL_MAX_SIZE		(54 * 1024)	/* 8 KB for stack */
 #define CONFIG_SPL_STACK		LOW_LEVEL_SRAM_STACK
diff --git a/include/configs/omap3_overo.h b/include/configs/omap3_overo.h
index d29b326..8e63802 100644
--- a/include/configs/omap3_overo.h
+++ b/include/configs/omap3_overo.h
@@ -300,6 +300,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_NAND_SIMPLE
 #define CONFIG_SPL_TEXT_BASE		0x40200800
 #define CONFIG_SPL_MAX_SIZE		(54 * 1024)	/* 8 KB for stack */
diff --git a/include/configs/omap4_common.h b/include/configs/omap4_common.h
index 685fde9..1384522 100644
--- a/include/configs/omap4_common.h
+++ b/include/configs/omap4_common.h
@@ -246,6 +246,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_TEXT_BASE		0x40304350
 #define CONFIG_SPL_MAX_SIZE		(38 * 1024)
 #define CONFIG_SPL_STACK		LOW_LEVEL_SRAM_STACK
diff --git a/include/configs/omap5_evm.h b/include/configs/omap5_evm.h
index ef4034c..65a34fa 100644
--- a/include/configs/omap5_evm.h
+++ b/include/configs/omap5_evm.h
@@ -243,6 +243,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_TEXT_BASE		0x40300350
 #define CONFIG_SPL_MAX_SIZE		0x19000	/* 100K */
 #define CONFIG_SPL_STACK		LOW_LEVEL_SRAM_STACK
diff --git a/include/configs/tam3517-common.h b/include/configs/tam3517-common.h
index 777f77c..8646d94 100644
--- a/include/configs/tam3517-common.h
+++ b/include/configs/tam3517-common.h
@@ -241,6 +241,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_CONSOLE
 #define CONFIG_SPL_NAND_SIMPLE
 #define CONFIG_SPL_NAND_SOFTECC
diff --git a/include/configs/tricorder.h b/include/configs/tricorder.h
index 56336ae..0679f18 100644
--- a/include/configs/tricorder.h
+++ b/include/configs/tricorder.h
@@ -275,6 +275,7 @@ 
 
 /* Defines for SPL */
 #define CONFIG_SPL
+#define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_NAND_SIMPLE
 
 #define CONFIG_SPL_BOARD_INIT