From 5067d9bcb1495e540212ee3e430023cade23c7a0 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 10 Mar 2011 14:47:23 +0100 Subject: ARM i.MX51: set barebox_loc according to boot source Signed-off-by: Sascha Hauer --- arch/arm/mach-imx/imx51.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/arch/arm/mach-imx/imx51.c b/arch/arm/mach-imx/imx51.c index 8b7c80792a..f2c886e331 100644 --- a/arch/arm/mach-imx/imx51.c +++ b/arch/arm/mach-imx/imx51.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -89,3 +90,89 @@ static int imx51_init(void) return 0; } coredevice_initcall(imx51_init); + +/* + * Saves the boot source media into the $barebox_loc enviroment variable + * + * This information is useful for barebox init scripts as we can then easily + * use a kernel image stored on the same media that we launch barebox with + * (for example). + * + * imx25 and imx35 can boot into barebox from several media such as + * nand, nor, mmc/sd cards, serial roms. "mmc" is used to represent several + * sources as its impossible to distinguish between them. + * + * Some sources such as serial roms can themselves have 3 different boot + * possibilities (i2c1, i2c2 etc). It is assumed that any board will + * only be using one of these at any one time. + * + * Note also that I suspect that the boot source pins are only sampled at + * power up. + */ + +#define SRC_SBMR 0x4 +#define SBMR_BT_MEM_TYPE_SHIFT 7 +#define SBMR_BT_MEM_CTL_SHIFT 0 +#define SBMR_BMOD_SHIFT 14 + +static int imx51_boot_save_loc(void) +{ + const char *bareboxloc = NULL; + uint32_t reg; + unsigned int ctrl, type; + + /* [CTRL][TYPE] */ + const char *const locations[4][4] = { + { /* CTRL = WEIM */ + "nor", + NULL, + "onenand", + NULL, + }, { /* CTRL == NAND */ + "nand", + "nand", + "nand", + "nand", + }, { /* CTRL == reserved */ + NULL, + NULL, + NULL, + NULL, + }, { /* CTRL == expansion */ + "mmc", + NULL, + "i2c", + "spi", + } + }; + + reg = readl(MX51_SRC_BASE_ADDR + SRC_SBMR); + + switch ((reg >> SBMR_BMOD_SHIFT) & 0x3) { + case 0: + case 2: + /* internal boot */ + ctrl = (reg >> SBMR_BT_MEM_CTL_SHIFT) & 0x3; + type = (reg >> SBMR_BT_MEM_TYPE_SHIFT) & 0x3; + + bareboxloc = locations[ctrl][type]; + break; + case 1: + /* reserved */ + bareboxloc = "unknown"; + break; + case 3: + bareboxloc = "serial"; + break; + + } + + if (bareboxloc) { + setenv("barebox_loc", bareboxloc); + export("barebox_loc"); + } + + return 0; +} + +coredevice_initcall(imx51_boot_save_loc); -- cgit v1.2.3