summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/mach-imx/imx51.c87
1 files changed, 87 insertions, 0 deletions
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 <init.h>
#include <common.h>
#include <sizes.h>
+#include <environment.h>
#include <asm/io.h>
#include <mach/imx51-regs.h>
@@ -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);