Skip to contentSkip to conversation

Bootmode override on i.MX6

RFC PATCH In review Philipp Zabel 2 participants 4 messages Jan 22, 2014 – Jan 27, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Bootmode override on i.MX6

The i.MX6 boot rom copies parts of the (persistent across reset) GPR9 register into SMBR1 if the GPR10[28] bit is set.
This allows to override the boot mode bits which are otherwise sampled from fuses or gpios, and can be used to temporarily (until the next power cycle) boot from a different device.
This patchset adds a bootmode command that conveniently writes to the GPR9/10 registers to tell the boot rom from which device to boot.

Example:
<power-on reset, boot ROM loads barebox from mmc3 as fused> # bootmode -l
mmc2
* mmc3
# barebox_update -t mmc2 /path/to/barebox.img
# bootmode mmc2
# reset
<boot ROM loads untested barebox from mmc2>
# barebox_update -t mmc3 /path/to/barebox.img <either power cycle, or>
# bootmode mmc3 ; reset
<boot ROM loads tested barebox from mmc3>

Philipp Zabel (2):
ARM i.MX6: Add bootmode setting code
commands: add bootmode command

 arch/arm/mach-imx/boot.c                 |  75 ++++++++++++++++
 arch/arm/mach-imx/imx6.c                 |   2 +
 arch/arm/mach-imx/include/mach/generic.h |   6 ++
 commands/Kconfig                         |   9 ++
 commands/Makefile                        |   1 +
 commands/bootmode.c                      | 143 +++++++++++++++++++++++++++++++
 common/Kconfig                           |   3 +
 common/Makefile                          |   1 +
 common/bootmode.c                        |  39 +++++++++
 include/bootmode.h                       |  34 ++++++++
 10 files changed, 313 insertions(+)
 create mode 100644 commands/bootmode.c
 create mode 100644 common/bootmode.c
 create mode 100644 include/bootmode.h

The SBMR1 override using GPR9/10 is based on the U-Boot rsmode patch by Troy Kisky:

    http://lists.denx.de/pipermail/u-boot/2012-May/125283.html

Tested on GK802 and BD-SL with mmc and spi nor flash.

I chose to use device names as parameter to the bootmode command, but I'm unsure about that. Maybe reusing the bbu target name list would be better for consistency?

regards
Philipp

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

RFC PATCH 1/2 ARM i.MX6: Add bootmode setting code

This patch allows to set the bootmode parameters that the boot rom interprets to determine the boot source. This allows to set the bootsource for the next reboot. Only tested for mmc boot on GK802.

---
 arch/arm/mach-imx/boot.c                 | 75 ++++++++++++++++++++++++++++++++
 arch/arm/mach-imx/imx6.c                 |  2 +
 arch/arm/mach-imx/include/mach/generic.h |  6 +++
 common/bootmode.c                        | 39 +++++++++++++++++
 include/bootmode.h                       | 34 +++++++++++++++
 5 files changed, 156 insertions(+)
 create mode 100644 common/bootmode.c
 create mode 100644 include/bootmode.h
arch/arm/mach-imx/boot.c +75 -0
index 4d81fd4..7a46cd0 100644
@@ -282,3 +282,78 @@ internal_boot:
 
 	return;
 }
+
+#define IMX6_SRC_GPR9	0x40
+#define IMX6_SRC_GPR10	0x44
+
+int imx6_bootmode_set(enum bootsource src, int instance,
+		      struct device_node *node, void *data)
+{
+	void __iomem *src_base = data;
+	int bus_width, chip_sel;
+	unsigned int gpr9;
+
+	switch (src) {
+	case BOOTSOURCE_SERIAL:
+		/* Reserved value, fallback to serial */
+		gpr9 = 0x00000001;
+		break;
+	case BOOTSOURCE_NOR:
+	case BOOTSOURCE_NAND:
+		/* TODO */
+		return -EINVAL;
+	case BOOTSOURCE_MMC:
+		gpr9 = 1 << 6;
+
+		if (instance < 0 || instance > 3)
+			return -EINVAL;
+		gpr9 |= instance << 11;
+
+		if (of_property_read_u32(node, "bus-width", &bus_width) < 0)
+			bus_width = 1;
+		switch (bus_width) {
+		case 1:
+			gpr9 |= 0 << 13;
+			break;
+		case 4:
+			gpr9 |= 1 << 13;
+			break;
+		case 8:
+			gpr9 |= 2 << 13;
+			gpr9 |= 1 << 5; /* eMMC */
+			break;
+		default:
+			return -EINVAL;
+		}
+		break;
+	case BOOTSOURCE_HD:
+		gpr9 = 2 << 4;
+		break;
+	case BOOTSOURCE_SPI:
+		gpr9 = 3 << 4;
+
+		if (instance < 0 || instance > 4)
+			return -EINVAL;
+		gpr9 |= instance << 24;
+
+		if (of_property_read_u32(node, "reg", &chip_sel) < 0)
+			return -EINVAL;
+		gpr9 |= chip_sel << 28;
+
+		gpr9 |= 1 << 27; /* 24-bit */
+		break;
+	case BOOTSOURCE_I2C:
+		gpr9 = 3 << 4;
+		if (instance < 0  || instance > 2)
+			return -EINVAL;
+		gpr9 |= (instance + 5) << 24;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	writel(gpr9, src_base + IMX6_SRC_GPR9);
+	writel(BIT(28), src_base + IMX6_SRC_GPR10);
+
+	return 0;
+}
arch/arm/mach-imx/imx6.c +2 -0
index 304b1c0..de5527a 100644
@@ -12,6 +12,7 @@
  */
 
 #include <init.h>
+#include <bootmode.h>
 #include <common.h>
 #include <io.h>
 #include <sizes.h>
@@ -96,6 +97,7 @@ int imx6_init(void)
 	u32 mx6_silicon_revision;
 
 	imx6_boot_save_loc((void *)MX6_SRC_BASE_ADDR);
+	bootmode_register_handler(imx6_bootmode_set, (void *)MX6_SRC_BASE_ADDR);
 
 	rev = readl(MX6_ANATOP_BASE_ADDR + SI_REV);
 	switch (rev & 0xff) {
arch/arm/mach-imx/include/mach/generic.h +6 -0
index 506b1da..77a00fb 100644
@@ -33,6 +33,12 @@ int imx51_devices_init(void);
 int imx53_devices_init(void);
 int imx6_devices_init(void);
 
+enum bootsource;
+struct device_node;
+
+int imx6_bootmode_set(enum bootsource src, int instance,
+		      struct device_node *node, void *data);
+
 /* There's a off-by-one betweem the gpio bank number and the gpiochip */
 /* range e.g. GPIO_1_5 is gpio 5 under linux */
 #define IMX_GPIO_NR(bank, nr)		(((bank) - 1) * 32 + (nr))
common/bootmode.c new file +39 -0
new file mode 100644
index 0000000..74809a6
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2013 Philipp Zabel
+ *
+ * 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.
+ *
+ */
+#include <bootsource.h>
+#include <common.h>
+
+static int (*bootmode_handler)(enum bootsource src, int instance,
+			       struct device_node *node, void *data);
+static void *bootmode_handler_data;
+
+int bootmode_register_handler(int (*handler)(enum bootsource src, int instance,
+					     struct device_node *node,
+					     void *data), void *data)
+{
+	bootmode_handler = handler;
+	bootmode_handler_data = data;
+
+	return 0;
+}
+
+int bootmode_set(enum bootsource src, int instance,
+		 struct device_node *node)
+{
+	if (!bootmode_handler)
+		return -ENODEV;
+
+	return bootmode_handler(src, instance, node, bootmode_handler_data);
+}
include/bootmode.h new file +34 -0
new file mode 100644
index 0000000..cbd4617
@@ -0,0 +1,34 @@
+#ifndef __INCLUDE_BOOTMODE_H
+#define __INCLUDE_BOOTMODE_H
+
+#include <bootsource.h>
+#include <common.h>
+
+#ifdef CONFIG_BOOTMODE
+
+int bootmode_register_handler(int (*handler)(enum bootsource src, int instance,
+					     struct device_node *node,
+					     void *data), void *data);
+
+int bootmode_set(enum bootsource src, int instance,
+		 struct device_node *node);
+
+#else
+
+static inline int bootmode_register_handler(int (*handler)(enum bootsource src,
+					    int instance,
+					    struct device_node *node,
+					    void *data), void *data)
+{
+	return -EINVAL;
+}
+
+int bootmode_set(enum bootsource src, int instance,
+		 struct device_node *node)
+{
+	return -ENODEV;
+}
+
+#endif
+
+#endif /* __INCLUDE_BOOTMODE_H */
Signature · 7 lines
1.8.5.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

RFC PATCH 2/2 commands: add bootmode command

In reply to Philipp Zabel

On some SoCs the boot rom can be instructed to boot from a specific device, once, after the next reset. The bootmode command allows to list boot device candidates and to set up one of those devices as boot source after the next reset.

---
 commands/Kconfig    |   9 ++++
 commands/Makefile   |   1 +
 commands/bootmode.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/Kconfig      |   3 ++
 common/Makefile     |   1 +
 5 files changed, 157 insertions(+)
 create mode 100644 commands/bootmode.c
commands/Kconfig +9 -0
index 1e07b5b..851a14a 100644
@@ -770,6 +770,15 @@ config CMD_WD_DEFAULT_TIMOUT
 	  enabled and re-triggered with the default timeout value).
 endif
 
+config CMD_BOOTMODE
+	bool
+	depends on OFTREE
+	prompt "bootmode command"
+	select BOOTMODE
+	help
+	  The 'bootmode' command on some SoCs allows to instruct the boot rom
+	  from which bootsource to boot, once, after the next reset.
+
 endmenu
 
 endif
commands/Makefile +1 -0
index 58d27fa..9e63e3f 100644
@@ -93,3 +93,4 @@ obj-$(CONFIG_CMD_MIITOOL)	+= miitool.o
 obj-$(CONFIG_CMD_DETECT)	+= detect.o
 obj-$(CONFIG_CMD_BOOT)		+= boot.o
 obj-$(CONFIG_CMD_DEVINFO)	+= devinfo.o
+obj-$(CONFIG_CMD_BOOTMODE)	+= bootmode.o
commands/bootmode.c new file +143 -0

143 lines not on this page · raw message

common/Kconfig +3 -0
index ce426f2..95f4756 100644
@@ -62,6 +62,9 @@ config STDDEV
 config BAREBOX_UPDATE
 	bool
 
+config BOOTMODE
+	bool
+
 menu "General Settings"
 
 config LOCALVERSION
common/Makefile +1 -0
index 6f6e360..78b59bc 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_PASSWORD) += password.o
 obj-$(CONFIG_MODULES) += module.o
 obj-$(CONFIG_FLEXIBLE_BOOTARGS) += bootargs.o
 obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
+obj-$(CONFIG_BOOTMODE) += bootmode.o
 obj-y += bootsource.o
 obj-$(CONFIG_BOOTM) += bootm.o
 extra-$(CONFIG_MODULES) += module.lds
Signature · 7 lines
1.8.5.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#3 lore raw

Re: [RFC PATCH 2/2] commands: add bootmode command

Hi Philipp,

Quoted 48 lines · Philipp Zabel

On some SoCs the boot rom can be instructed to boot from a specific device, once, after the next reset. The bootmode command allows to list boot device candidates and to set up one of those devices as boot source after the next reset.

---
 commands/Kconfig    |   9 ++++
 commands/Makefile   |   1 +
 commands/bootmode.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/Kconfig      |   3 ++
 common/Makefile     |   1 +
 5 files changed, 157 insertions(+)
 create mode 100644 commands/bootmode.c
commands/Kconfig +9 -0
index 1e07b5b..851a14a 100644
@@ -770,6 +770,15 @@ config CMD_WD_DEFAULT_TIMOUT
 	  enabled and re-triggered with the default timeout value).
 endif
 
+config CMD_BOOTMODE
+	bool
+	depends on OFTREE
+	prompt "bootmode command"
+	select BOOTMODE
+	help
+	  The 'bootmode' command on some SoCs allows to instruct the boot rom
+	  from which bootsource to boot, once, after the next reset.
+
 endmenu
 
 endif
commands/Makefile +1 -0
index 58d27fa..9e63e3f 100644
@@ -93,3 +93,4 @@ obj-$(CONFIG_CMD_MIITOOL)	+= miitool.o
 obj-$(CONFIG_CMD_DETECT)	+= detect.o
 obj-$(CONFIG_CMD_BOOT)		+= boot.o
 obj-$(CONFIG_CMD_DEVINFO)	+= devinfo.o
+obj-$(CONFIG_CMD_BOOTMODE)	+= bootmode.o
commands/bootmode.c +3 -0
+
+static struct bootsource_name bootsources[] = {
+	{ BOOTSOURCE_NAND,   "nand" },

commands/bootmode.c line 40

Quoted 10 lines
commands/bootmode.c +10 -0
+	{ BOOTSOURCE_NOR,    "nor"  },
+	{ BOOTSOURCE_MMC,    "mmc"  },
+	{ BOOTSOURCE_I2C,    "i2c"  },
+	{ BOOTSOURCE_SPI,    "m25p" },
+	{ BOOTSOURCE_SERIAL, "cs"   },
+	{ BOOTSOURCE_HD,     "ahci" },
+};
+
+static enum bootsource get_bootsource(struct device_d *dev, int *instance)
+{

For bootsource we currently have bootsource/instance for referring to a bootsource. Using a struct device_d (and therefore also struct device_node) is pretty cool, but should be introduced consistently. With the function above we have to use a devicename to specify the bootsource, but a devicename is not what we get as current bootsource. I suggest to either switch to devicenames completely or to let the bootmode command just understand bootmode <type> <instance>, like bootmode mmc 2.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox