From 1cf3936829da523a03f3a7bf907eea1fda06aab4 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 8 Apr 2011 15:43:48 +0200 Subject: ARM omap: add xload helper functions Add some common xload helper functions to determine the boot source on omap3/4 and to load images from mmc and nand. Signed-off-by: Sascha Hauer --- arch/arm/mach-omap/Makefile | 2 +- arch/arm/mach-omap/include/mach/xload.h | 16 ++++++++++ arch/arm/mach-omap/omap3_generic.c | 14 +++++++++ arch/arm/mach-omap/omap4_generic.c | 14 +++++++++ arch/arm/mach-omap/xload.c | 54 +++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 arch/arm/mach-omap/include/mach/xload.h create mode 100644 arch/arm/mach-omap/xload.c diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile index 9c3145693e..a4b9a55774 100644 --- a/arch/arm/mach-omap/Makefile +++ b/arch/arm/mach-omap/Makefile @@ -25,4 +25,4 @@ obj-$(CONFIG_ARCH_OMAP3) += omap3_core.o omap3_generic.o obj-$(CONFIG_ARCH_OMAP4) += omap4_generic.o omap4_clock.o obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock_core.o omap3_clock.o obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o -obj-y += omap-uart.o gpio.o +obj-y += omap-uart.o gpio.o xload.o diff --git a/arch/arm/mach-omap/include/mach/xload.h b/arch/arm/mach-omap/include/mach/xload.h new file mode 100644 index 0000000000..844b57f0e5 --- /dev/null +++ b/arch/arm/mach-omap/include/mach/xload.h @@ -0,0 +1,16 @@ +#ifndef _MACH_XLOAD_H +#define _MACH_XLOAD_H + +void *omap_xload_boot_nand(int offset, int size); +void *omap_xload_boot_mmc(void); + +enum omap_boot_src { + OMAP_BOOTSRC_UNKNOWN, + OMAP_BOOTSRC_MMC1, + OMAP_BOOTSRC_NAND, +}; + +enum omap_boot_src omap3_bootsrc(void); +enum omap_boot_src omap4_bootsrc(void); + +#endif /* _MACH_XLOAD_H */ diff --git a/arch/arm/mach-omap/omap3_generic.c b/arch/arm/mach-omap/omap3_generic.c index c1940d266c..661a971fc0 100644 --- a/arch/arm/mach-omap/omap3_generic.c +++ b/arch/arm/mach-omap/omap3_generic.c @@ -46,6 +46,7 @@ #include #include #include +#include /** * @brief Reset the CPU @@ -483,3 +484,16 @@ void a_init(void) #endif } + +#define OMAP3_TRACING_VECTOR1 0x4020ffb4 + +enum omap_boot_src omap3_bootsrc(void) +{ + u32 bootsrc = readl(OMAP3_TRACING_VECTOR1); + + if (bootsrc & (1 << 2)) + return OMAP_BOOTSRC_NAND; + if (bootsrc & (1 << 6)) + return OMAP_BOOTSRC_MMC1; + return OMAP_BOOTSRC_UNKNOWN; +} diff --git a/arch/arm/mach-omap/omap4_generic.c b/arch/arm/mach-omap/omap4_generic.c index 45e6c8664e..e4838e9618 100644 --- a/arch/arm/mach-omap/omap4_generic.c +++ b/arch/arm/mach-omap/omap4_generic.c @@ -5,6 +5,7 @@ #include #include #include +#include void __noreturn reset_cpu(unsigned long addr) { @@ -404,3 +405,16 @@ static int omap_vector_init(void) return 0; } core_initcall(omap_vector_init); + +#define OMAP4_TRACING_VECTOR3 0x4030d048 + +enum omap_boot_src omap4_bootsrc(void) +{ + u32 bootsrc = readl(OMAP4_TRACING_VECTOR3); + + if (bootsrc & (1 << 3)) + return OMAP_BOOTSRC_NAND; + if (bootsrc & (1 << 5)) + return OMAP_BOOTSRC_MMC1; + return OMAP_BOOTSRC_UNKNOWN; +} diff --git a/arch/arm/mach-omap/xload.c b/arch/arm/mach-omap/xload.c new file mode 100644 index 0000000000..216b9b5aba --- /dev/null +++ b/arch/arm/mach-omap/xload.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void *omap_xload_boot_nand(int offset, int size) +{ + int ret; + void *to = xmalloc(size); + struct cdev *cdev; + + devfs_add_partition("nand0", offset, size, PARTITION_FIXED, "x"); + dev_add_bb_dev("x", "bbx"); + + cdev = cdev_open("bbx", O_RDONLY); + if (!cdev) { + printf("failed to open nand\n"); + return NULL; + } + + ret = cdev_read(cdev, to, size, 0, 0); + if (ret != size) { + printf("failed to read from nand\n"); + return NULL; + } + + return to; +} + +void *omap_xload_boot_mmc(void) +{ + int ret; + void *buf; + int len; + + ret = mount("disk0.0", "fat", "/"); + if (ret) { + printf("mounting sd card failed with %d\n", ret); + return NULL; + } + + buf = read_file("/barebox.bin", &len); + if (!buf) { + printf("could not read barebox.bin from sd card\n"); + return NULL; + } + + return buf; +} -- cgit v1.2.3