mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] bootsource
@ 2013-04-03  6:52 Sascha Hauer
  2013-04-03  6:52 ` [PATCH 1/5] ARM: i.MX: rename barebox_loc to bootsource Sascha Hauer
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-03  6:52 UTC (permalink / raw)
  To: barebox

This is a series based on earlier work by Marc. It creates an arch
independent framework for storing/retrieving the bootsource. Changes
to Marcs version are:

- rename (currently i.MX specific) barebox_loc environment variable
  to 'bootsource'
- initialize the bootsource instance to unknown (-1) instead of 0
  which is a valid bootsource instance

Sascha

----------------------------------------------------------------
Marc Kleine-Budde (3):
      bootsource: create arch independent bootsource framework
      bootsource: use initcall to export bootsource location to environment
      bootsource: add support for bootsource instance information

Sascha Hauer (2):
      ARM: i.MX: rename barebox_loc to bootsource
      ARM: i.MX53: Add bootsource instance information

 arch/arm/boards/efika-mx-smartbook/board.c         |  3 +-
 .../boards/efika-mx-smartbook/env/init/bootsource  |  2 +-
 arch/arm/boards/karo-tx53/board.c                  |  3 +-
 arch/arm/boards/pcm038/pcm038.c                    |  3 +-
 arch/arm/mach-imx/boot.c                           | 77 ++++++++-----------
 arch/arm/mach-imx/imx51.c                          |  2 +-
 arch/arm/mach-imx/include/mach/generic.h           | 15 ----
 common/Makefile                                    |  1 +
 common/bootsource.c                                | 86 ++++++++++++++++++++++
 include/bootsource.h                               | 23 ++++++
 10 files changed, 148 insertions(+), 67 deletions(-)
 create mode 100644 common/bootsource.c
 create mode 100644 include/bootsource.h

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] ARM: i.MX: rename barebox_loc to bootsource
  2013-04-03  6:52 [PATCH] bootsource Sascha Hauer
@ 2013-04-03  6:52 ` Sascha Hauer
  2013-04-03  6:52 ` [PATCH 2/5] bootsource: create arch independent bootsource framework Sascha Hauer
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-03  6:52 UTC (permalink / raw)
  To: barebox

Rename the barebox_loc environment variable to bootsource, since
- barebox_loc is a mixture between abbriviation and fulltext which is not nice
- technically it describes the source the SoC has booted from. This is not
  necessarily barebox but could also be some other first stage loader.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/efika-mx-smartbook/env/init/bootsource | 2 +-
 arch/arm/mach-imx/boot.c                               | 8 ++++----
 arch/arm/mach-imx/imx51.c                              | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/arm/boards/efika-mx-smartbook/env/init/bootsource b/arch/arm/boards/efika-mx-smartbook/env/init/bootsource
index fb08469..380e855 100644
--- a/arch/arm/boards/efika-mx-smartbook/env/init/bootsource
+++ b/arch/arm/boards/efika-mx-smartbook/env/init/bootsource
@@ -3,7 +3,7 @@
 # by default pick kernel from MMC card if booting from
 # it, otherwise default to boot from internal harddisk
 
-if [ $barebox_loc = mmc ]; then
+if [ $bootsource = mmc ]; then
 	global.boot.default=mmc-left
 else
 	global.boot.default=hd-internal
diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 95a7673..3d0b09b 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -42,8 +42,8 @@ void imx_set_bootsource(enum imx_bootsource src)
 
 	bootsource = src;
 
-	setenv("barebox_loc", bootsource_str[src]);
-	export("barebox_loc");
+	setenv("bootsource", bootsource_str[src]);
+	export("bootsource");
 }
 
 enum imx_bootsource imx_bootsource(void)
@@ -51,7 +51,7 @@ enum imx_bootsource imx_bootsource(void)
 	return bootsource;
 }
 
-BAREBOX_MAGICVAR(barebox_loc, "The source barebox has been booted from");
+BAREBOX_MAGICVAR(bootsource, "The source barebox has been booted from");
 
 /* [CTRL][TYPE] */
 static const enum imx_bootsource locations[4][4] = {
@@ -79,7 +79,7 @@ static const enum imx_bootsource locations[4][4] = {
 };
 
 /*
- * Saves the boot source media into the $barebox_loc environment variable
+ * Saves the boot source media into the $bootsource environment 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
diff --git a/arch/arm/mach-imx/imx51.c b/arch/arm/mach-imx/imx51.c
index cffcca3..96ac3b6 100644
--- a/arch/arm/mach-imx/imx51.c
+++ b/arch/arm/mach-imx/imx51.c
@@ -77,7 +77,7 @@ static int imx51_init(void)
 postcore_initcall(imx51_init);
 
 /*
- * Saves the boot source media into the $barebox_loc environment variable
+ * Saves the boot source media into the $bootsource environment 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
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/5] bootsource: create arch independent bootsource framework
  2013-04-03  6:52 [PATCH] bootsource Sascha Hauer
  2013-04-03  6:52 ` [PATCH 1/5] ARM: i.MX: rename barebox_loc to bootsource Sascha Hauer
@ 2013-04-03  6:52 ` Sascha Hauer
  2013-04-03  6:52 ` [PATCH 3/5] bootsource: use initcall to export bootsource location to environment Sascha Hauer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-03  6:52 UTC (permalink / raw)
  To: barebox

From: Marc Kleine-Budde <mkl@pengutronix.de>

This patch seperates the imx independent from the arch independent code. The
following functions and enums are renamed:

- imx_bootsource() -> bootsource_get()
- imx_set_bootsource() -> bootsource_set()
- enum imx_bootsource -> enum bootsource

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/efika-mx-smartbook/board.c |  3 +-
 arch/arm/boards/karo-tx53/board.c          |  3 +-
 arch/arm/boards/pcm038/pcm038.c            |  3 +-
 arch/arm/mach-imx/boot.c                   | 57 +++++++-----------------------
 arch/arm/mach-imx/include/mach/generic.h   | 15 --------
 common/Makefile                            |  1 +
 common/bootsource.c                        | 53 +++++++++++++++++++++++++++
 include/bootsource.h                       | 19 ++++++++++
 8 files changed, 92 insertions(+), 62 deletions(-)
 create mode 100644 common/bootsource.c
 create mode 100644 include/bootsource.h

diff --git a/arch/arm/boards/efika-mx-smartbook/board.c b/arch/arm/boards/efika-mx-smartbook/board.c
index 03399a3..e9b6062 100644
--- a/arch/arm/boards/efika-mx-smartbook/board.c
+++ b/arch/arm/boards/efika-mx-smartbook/board.c
@@ -14,6 +14,7 @@
  */
 
 #include <common.h>
+#include <bootsource.h>
 #include <net.h>
 #include <init.h>
 #include <environment.h>
@@ -479,7 +480,7 @@ device_initcall(efikamx_devices_init);
 
 static int efikamx_part_init(void)
 {
-	if (imx_bootsource() == BOOTSOURCE_MMC) {
+	if (bootsource_get() == BOOTSOURCE_MMC) {
 		devfs_add_partition("mmc_left", 0x00000, 0x80000,
 				DEVFS_PARTITION_FIXED, "self0");
 		devfs_add_partition("mmc_left", 0x80000, 0x80000,
diff --git a/arch/arm/boards/karo-tx53/board.c b/arch/arm/boards/karo-tx53/board.c
index f3976ee..6ead6a9 100644
--- a/arch/arm/boards/karo-tx53/board.c
+++ b/arch/arm/boards/karo-tx53/board.c
@@ -13,6 +13,7 @@
  *
  */
 #include <common.h>
+#include <bootsource.h>
 #include <environment.h>
 #include <fcntl.h>
 #include <fec.h>
@@ -234,7 +235,7 @@ static int tx53_part_init(void)
 {
 	const char *envdev;
 
-	switch (imx_bootsource()) {
+	switch (bootsource_get()) {
 	case BOOTSOURCE_MMC:
 		devfs_add_partition("disk0", 0x00000, SZ_512K, DEVFS_PARTITION_FIXED, "self0");
 		devfs_add_partition("disk0", SZ_512K, SZ_1M, DEVFS_PARTITION_FIXED, "env0");
diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
index 78ed2ef..df8b1f9 100644
--- a/arch/arm/boards/pcm038/pcm038.c
+++ b/arch/arm/boards/pcm038/pcm038.c
@@ -16,6 +16,7 @@
 #define pr_fmt(fmt) "pcm038: " fmt
 
 #include <common.h>
+#include <bootsource.h>
 #include <net.h>
 #include <init.h>
 #include <environment.h>
@@ -299,7 +300,7 @@ static int pcm038_devices_init(void)
 	 */
 	imx27_add_fec(&fec_info);
 
-	switch (imx_bootsource()) {
+	switch (bootsource_get()) {
 	case BOOTSOURCE_NAND:
 		devfs_add_partition("nand0", 0x00000, 0x80000,
 					DEVFS_PARTITION_FIXED, "self_raw");
diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 3d0b09b..7824206 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -12,6 +12,7 @@
  */
 
 #include <common.h>
+#include <bootsource.h>
 #include <environment.h>
 #include <init.h>
 #include <magicvar.h>
@@ -21,40 +22,8 @@
 #include <mach/imx25-regs.h>
 #include <mach/imx35-regs.h>
 
-static const char *bootsource_str[] = {
-	[BOOTSOURCE_UNKNOWN] = "unknown",
-	[BOOTSOURCE_NAND] = "nand",
-	[BOOTSOURCE_NOR] = "nor",
-	[BOOTSOURCE_MMC] = "mmc",
-	[BOOTSOURCE_I2C] = "i2c",
-	[BOOTSOURCE_SPI] = "spi",
-	[BOOTSOURCE_SERIAL] = "serial",
-	[BOOTSOURCE_ONENAND] = "onenand",
-	[BOOTSOURCE_HD] = "harddisk",
-};
-
-static enum imx_bootsource bootsource;
-
-void imx_set_bootsource(enum imx_bootsource src)
-{
-	if (src >= ARRAY_SIZE(bootsource_str))
-		src = BOOTSOURCE_UNKNOWN;
-
-	bootsource = src;
-
-	setenv("bootsource", bootsource_str[src]);
-	export("bootsource");
-}
-
-enum imx_bootsource imx_bootsource(void)
-{
-	return bootsource;
-}
-
-BAREBOX_MAGICVAR(bootsource, "The source barebox has been booted from");
-
 /* [CTRL][TYPE] */
-static const enum imx_bootsource locations[4][4] = {
+static const enum bootsource locations[4][4] = {
 	{ /* CTRL = WEIM */
 		BOOTSOURCE_NOR,
 		BOOTSOURCE_UNKNOWN,
@@ -98,11 +67,11 @@ static const enum imx_bootsource locations[4][4] = {
  */
 static void imx25_35_boot_save_loc(unsigned int ctrl, unsigned int type)
 {
-	enum imx_bootsource src;
+	enum bootsource src;
 
 	src = locations[ctrl][type];
 
-	imx_set_bootsource(src);
+	bootsource_set(src);
 }
 
 void imx25_boot_save_loc(void __iomem *ccm_base)
@@ -136,7 +105,7 @@ void imx35_boot_save_loc(void __iomem *ccm_base)
 
 void imx27_boot_save_loc(void __iomem *sysctrl_base)
 {
-	enum imx_bootsource src;
+	enum bootsource src;
 	uint32_t val;
 
 	val = readl(sysctrl_base + IMX27_SYSCTRL_GPCR);
@@ -158,7 +127,7 @@ void imx27_boot_save_loc(void __iomem *sysctrl_base)
 		break;
 	}
 
-	imx_set_bootsource(src);
+	bootsource_set(src);
 }
 
 #define IMX51_SRC_SBMR			0x4
@@ -168,7 +137,7 @@ void imx27_boot_save_loc(void __iomem *sysctrl_base)
 
 void imx51_boot_save_loc(void __iomem *src_base)
 {
-	enum imx_bootsource src = BOOTSOURCE_UNKNOWN;
+	enum bootsource src = BOOTSOURCE_UNKNOWN;
 	uint32_t reg;
 	unsigned int ctrl, type;
 
@@ -193,13 +162,13 @@ void imx51_boot_save_loc(void __iomem *src_base)
 
 	}
 
-	imx_set_bootsource(src);
+	bootsource_set(src);
 }
 
 #define IMX53_SRC_SBMR	0x4
 void imx53_boot_save_loc(void __iomem *src_base)
 {
-	enum imx_bootsource src = BOOTSOURCE_UNKNOWN;
+	enum bootsource src = BOOTSOURCE_UNKNOWN;
 	uint32_t cfg1 = readl(src_base + IMX53_SRC_SBMR) & 0xff;
 
 	switch (cfg1 >> 4) {
@@ -225,7 +194,7 @@ void imx53_boot_save_loc(void __iomem *src_base)
 	if (cfg1 & (1 << 7))
 		src = BOOTSOURCE_NAND;
 
-	imx_set_bootsource(src);
+	bootsource_set(src);
 }
 
 #define IMX6_SRC_SBMR1	0x04
@@ -233,7 +202,7 @@ void imx53_boot_save_loc(void __iomem *src_base)
 
 void imx6_boot_save_loc(void __iomem *src_base)
 {
-	enum imx_bootsource src = BOOTSOURCE_UNKNOWN;
+	enum bootsource src = BOOTSOURCE_UNKNOWN;
 	uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2) >> 24;
 	uint32_t cfg1 = readl(src_base + IMX6_SRC_SBMR1) & 0xff;
 	uint32_t boot_cfg_4_2_0;
@@ -252,7 +221,7 @@ void imx6_boot_save_loc(void __iomem *src_base)
 		break;
 	};
 
-	imx_set_bootsource(src);
+	bootsource_set(src);
 
 	return;
 
@@ -283,7 +252,7 @@ internal_boot:
 	if (cfg1 & (1 << 7))
 		src = BOOTSOURCE_NAND;
 
-	imx_set_bootsource(src);
+	bootsource_set(src);
 
 	return;
 }
diff --git a/arch/arm/mach-imx/include/mach/generic.h b/arch/arm/mach-imx/include/mach/generic.h
index 58d487a..189b32f 100644
--- a/arch/arm/mach-imx/include/mach/generic.h
+++ b/arch/arm/mach-imx/include/mach/generic.h
@@ -3,21 +3,6 @@
 
 u64 imx_uid(void);
 
-enum imx_bootsource {
-	BOOTSOURCE_UNKNOWN,
-	BOOTSOURCE_NAND,
-	BOOTSOURCE_NOR,
-	BOOTSOURCE_MMC,
-	BOOTSOURCE_I2C,
-	BOOTSOURCE_SPI,
-	BOOTSOURCE_SERIAL,
-	BOOTSOURCE_ONENAND,
-	BOOTSOURCE_HD,
-};
-
-enum imx_bootsource imx_bootsource(void);
-void imx_set_bootsource(enum imx_bootsource src);
-
 void imx25_boot_save_loc(void __iomem *ccm_base);
 void imx35_boot_save_loc(void __iomem *ccm_base);
 void imx27_boot_save_loc(void __iomem *sysctrl_base);
diff --git a/common/Makefile b/common/Makefile
index 1b3b009..dcb07c2 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_PASSWORD) += password.o
 obj-$(CONFIG_MODULES) += module.o
 obj-$(CONFIG_FLEXIBLE_BOOTARGS) += bootargs.o
 obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
+obj-y += bootsource.o
 extra-$(CONFIG_MODULES) += module.lds
 extra-y += barebox_default_env barebox_default_env.h
 
diff --git a/common/bootsource.c b/common/bootsource.c
new file mode 100644
index 0000000..6f9ae54
--- /dev/null
+++ b/common/bootsource.c
@@ -0,0 +1,53 @@
+/*
+ *
+ * Copyright (C) 2011 Marc Reilly <marc@cpdesign.com.au>
+ * Copyright (C) 2013 Marc Kleine-Budde <mkl@pengutronix.de>
+ *
+ * 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 <common.h>
+#include <bootsource.h>
+#include <environment.h>
+#include <magicvar.h>
+
+static const char *bootsource_str[] = {
+	[BOOTSOURCE_UNKNOWN] = "unknown",
+	[BOOTSOURCE_NAND] = "nand",
+	[BOOTSOURCE_NOR] = "nor",
+	[BOOTSOURCE_MMC] = "mmc",
+	[BOOTSOURCE_I2C] = "i2c",
+	[BOOTSOURCE_SPI] = "spi",
+	[BOOTSOURCE_SERIAL] = "serial",
+	[BOOTSOURCE_ONENAND] = "onenand",
+	[BOOTSOURCE_HD] = "harddisk",
+};
+
+static enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
+
+void bootsource_set(enum bootsource src)
+{
+	if (src >= ARRAY_SIZE(bootsource_str))
+		src = BOOTSOURCE_UNKNOWN;
+
+	bootsource = src;
+
+	setenv("bootsource", bootsource_str[src]);
+	export("bootsource");
+}
+
+enum bootsource bootsource_get(void)
+{
+	return bootsource;
+}
+
+BAREBOX_MAGICVAR(bootsource, "The source barebox has been booted from");
diff --git a/include/bootsource.h b/include/bootsource.h
new file mode 100644
index 0000000..ecd5938
--- /dev/null
+++ b/include/bootsource.h
@@ -0,0 +1,19 @@
+#ifndef __BOOTSOURCE_H__
+#define __BOOTSOURCE_H__
+
+enum bootsource {
+	BOOTSOURCE_UNKNOWN,
+	BOOTSOURCE_NAND,
+	BOOTSOURCE_NOR,
+	BOOTSOURCE_MMC,
+	BOOTSOURCE_I2C,
+	BOOTSOURCE_SPI,
+	BOOTSOURCE_SERIAL,
+	BOOTSOURCE_ONENAND,
+	BOOTSOURCE_HD,
+};
+
+enum bootsource bootsource_get(void);
+void bootsource_set(enum bootsource src);
+
+#endif	/* __BOOTSOURCE_H__ */
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/5] bootsource: use initcall to export bootsource location to environment
  2013-04-03  6:52 [PATCH] bootsource Sascha Hauer
  2013-04-03  6:52 ` [PATCH 1/5] ARM: i.MX: rename barebox_loc to bootsource Sascha Hauer
  2013-04-03  6:52 ` [PATCH 2/5] bootsource: create arch independent bootsource framework Sascha Hauer
@ 2013-04-03  6:52 ` Sascha Hauer
  2013-04-03  6:52 ` [PATCH 4/5] bootsource: add support for bootsource instance information Sascha Hauer
  2013-04-03  6:52 ` [PATCH 5/5] ARM: i.MX53: Add " Sascha Hauer
  4 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-03  6:52 UTC (permalink / raw)
  To: barebox

From: Marc Kleine-Budde <mkl@pengutronix.de>

This way the bootsource is exported to the environment, even if unknown.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/bootsource.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/common/bootsource.c b/common/bootsource.c
index 6f9ae54..5f1d40c 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -19,6 +19,7 @@
 #include <bootsource.h>
 #include <environment.h>
 #include <magicvar.h>
+#include <init.h>
 
 static const char *bootsource_str[] = {
 	[BOOTSOURCE_UNKNOWN] = "unknown",
@@ -42,7 +43,6 @@ void bootsource_set(enum bootsource src)
 	bootsource = src;
 
 	setenv("bootsource", bootsource_str[src]);
-	export("bootsource");
 }
 
 enum bootsource bootsource_get(void)
@@ -51,3 +51,12 @@ enum bootsource bootsource_get(void)
 }
 
 BAREBOX_MAGICVAR(bootsource, "The source barebox has been booted from");
+
+static int bootsource_init(void)
+{
+	bootsource_set(bootsource);
+	export("bootsource");
+
+	return 0;
+}
+coredevice_initcall(bootsource_init);
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/5] bootsource: add support for bootsource instance information
  2013-04-03  6:52 [PATCH] bootsource Sascha Hauer
                   ` (2 preceding siblings ...)
  2013-04-03  6:52 ` [PATCH 3/5] bootsource: use initcall to export bootsource location to environment Sascha Hauer
@ 2013-04-03  6:52 ` Sascha Hauer
  2013-04-03  8:04   ` Marc Kleine-Budde
  2013-04-03  6:52 ` [PATCH 5/5] ARM: i.MX53: Add " Sascha Hauer
  4 siblings, 1 reply; 7+ messages in thread
From: Sascha Hauer @ 2013-04-03  6:52 UTC (permalink / raw)
  To: barebox

From: Marc Kleine-Budde <mkl@pengutronix.de>

Add a C interface to set and get the bootsource instance:

    int bootsource_get_instance(void);
    void bootsource_set_instance(int instance);

Also export the shell variable "barebox_loc_instance".

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/bootsource.c  | 24 ++++++++++++++++++++++++
 include/bootsource.h |  4 ++++
 2 files changed, 28 insertions(+)

diff --git a/common/bootsource.c b/common/bootsource.c
index 5f1d40c..7367215 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -34,6 +34,7 @@ static const char *bootsource_str[] = {
 };
 
 static enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
+static int bootsource_instance = BOOTSOURCE_INSTANCE_UNKNOWN;
 
 void bootsource_set(enum bootsource src)
 {
@@ -45,6 +46,20 @@ void bootsource_set(enum bootsource src)
 	setenv("bootsource", bootsource_str[src]);
 }
 
+void bootsource_set_instance(int instance)
+{
+	char buf[32];
+
+	bootsource_instance = instance;
+
+	if (instance < 0)
+		sprintf(buf, "unknown");
+	else
+		snprintf(buf, sizeof(buf), "%d", instance);
+
+	setenv("bootsource_instance", buf);
+}
+
 enum bootsource bootsource_get(void)
 {
 	return bootsource;
@@ -52,10 +67,19 @@ enum bootsource bootsource_get(void)
 
 BAREBOX_MAGICVAR(bootsource, "The source barebox has been booted from");
 
+int bootsource_get_instance(void)
+{
+	return bootsource_instance;
+}
+
+BAREBOX_MAGICVAR(bootsource_instance, "The instance of the source barebox has been booted from");
+
 static int bootsource_init(void)
 {
 	bootsource_set(bootsource);
+	bootsource_set_instance(bootsource_instance);
 	export("bootsource");
+	export("bootsource_instance");
 
 	return 0;
 }
diff --git a/include/bootsource.h b/include/bootsource.h
index ecd5938..44b69b1 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -13,7 +13,11 @@ enum bootsource {
 	BOOTSOURCE_HD,
 };
 
+#define BOOTSOURCE_INSTANCE_UNKNOWN	-1
+
 enum bootsource bootsource_get(void);
+int bootsource_get_instance(void);
 void bootsource_set(enum bootsource src);
+void bootsource_set_instance(int instance);
 
 #endif	/* __BOOTSOURCE_H__ */
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/5] ARM: i.MX53: Add bootsource instance information
  2013-04-03  6:52 [PATCH] bootsource Sascha Hauer
                   ` (3 preceding siblings ...)
  2013-04-03  6:52 ` [PATCH 4/5] bootsource: add support for bootsource instance information Sascha Hauer
@ 2013-04-03  6:52 ` Sascha Hauer
  4 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-03  6:52 UTC (permalink / raw)
  To: barebox

The i.MX53 has the bootsource instance information stored
in SBMR[21:22], expose it to the environment.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/boot.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 7824206..bd0cb84 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -169,9 +169,10 @@ void imx51_boot_save_loc(void __iomem *src_base)
 void imx53_boot_save_loc(void __iomem *src_base)
 {
 	enum bootsource src = BOOTSOURCE_UNKNOWN;
-	uint32_t cfg1 = readl(src_base + IMX53_SRC_SBMR) & 0xff;
+	int instance;
+	uint32_t cfg1 = readl(src_base + IMX53_SRC_SBMR);
 
-	switch (cfg1 >> 4) {
+	switch ((cfg1 & 0xff) >> 4) {
 	case 2:
 		src = BOOTSOURCE_HD;
 		break;
@@ -194,7 +195,20 @@ void imx53_boot_save_loc(void __iomem *src_base)
 	if (cfg1 & (1 << 7))
 		src = BOOTSOURCE_NAND;
 
+
+	switch (src) {
+	case BOOTSOURCE_MMC:
+	case BOOTSOURCE_SPI:
+	case BOOTSOURCE_I2C:
+		instance = (cfg1 >> 21) & 0x3;
+		break;
+	default:
+		instance = 0;
+		break;
+	}
+
 	bootsource_set(src);
+	bootsource_set_instance(instance);
 }
 
 #define IMX6_SRC_SBMR1	0x04
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/5] bootsource: add support for bootsource instance information
  2013-04-03  6:52 ` [PATCH 4/5] bootsource: add support for bootsource instance information Sascha Hauer
@ 2013-04-03  8:04   ` Marc Kleine-Budde
  0 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-04-03  8:04 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox


[-- Attachment #1.1: Type: text/plain, Size: 713 bytes --]

On 04/03/2013 08:52 AM, Sascha Hauer wrote:
> From: Marc Kleine-Budde <mkl@pengutronix.de>
> 
> Add a C interface to set and get the bootsource instance:
> 
>     int bootsource_get_instance(void);
>     void bootsource_set_instance(int instance);
> 
> Also export the shell variable "barebox_loc_instance".
                                  ^^^^^^^^^^^^^^^^^^^^

That's not correct anymore. I have an updated series.

Marc
-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-04-03  8:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-03  6:52 [PATCH] bootsource Sascha Hauer
2013-04-03  6:52 ` [PATCH 1/5] ARM: i.MX: rename barebox_loc to bootsource Sascha Hauer
2013-04-03  6:52 ` [PATCH 2/5] bootsource: create arch independent bootsource framework Sascha Hauer
2013-04-03  6:52 ` [PATCH 3/5] bootsource: use initcall to export bootsource location to environment Sascha Hauer
2013-04-03  6:52 ` [PATCH 4/5] bootsource: add support for bootsource instance information Sascha Hauer
2013-04-03  8:04   ` Marc Kleine-Budde
2013-04-03  6:52 ` [PATCH 5/5] ARM: i.MX53: Add " Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox