mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCHv4] Enable a way to provide the reason for "being here"
@ 2012-07-13  6:04 Juergen Beisert
  2012-07-13  6:04 ` [PATCH 1/4] " Juergen Beisert
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Juergen Beisert @ 2012-07-13  6:04 UTC (permalink / raw)
  To: barebox

Many architectures support a way to detect why the bootloader is running.
This patch adds a global variable to be able to use the cause in some kind of
shell code to do special things on demand. For example to do an emergency boot,
when the last boot fails and the watchdog reactivates the hanging system.

V2 includes Marc's suggesion.
V3 includes the detection for the i.MX28 SoC and fixes its usage for other
i.MX SoCs.
V4 includes Marc's recent suggestion.

Comments are still welcome.

Juergen

The following changes since commit 279d3c29437ff84d4542ba4fc81de4fff0381233:

  Merge branch 'for-next/tqma53' into next (2012-07-09 09:24:04 +0200)

are available in the git repository at:

  git://git.pengutronix.de/git/jbe/barebox.git next_provide_reset_sourceV4

for you to fetch changes up to 8a94e229a42fad93f5cb5ff2b4b1cbe8e85e2927:

  ARM/MXS: add reset cause detection (2012-07-13 07:36:00 +0200)

----------------------------------------------------------------
Juergen Beisert (4):
      Enable a way to provide the reason for "being here"
      ARM/Samsung: add support to detect the reset source
      ARM/i.MX: add support to detect the reset source
      ARM/MXS: add reset cause detection

 arch/arm/mach-imx/Makefile           |    1 +
 arch/arm/mach-imx/reset_source.c     |   72 ++++++++++++++++++++++++++++++++++
 arch/arm/mach-samsung/Makefile       |    1 +
 arch/arm/mach-samsung/reset_source.c |   56 ++++++++++++++++++++++++++
 common/Makefile                      |    2 +-
 common/reset_source.c                |   44 +++++++++++++++++++++
 drivers/watchdog/im28wd.c            |   25 ++++++++++++
 include/reset_source.h               |   27 +++++++++++++
 8 files changed, 227 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-imx/reset_source.c
 create mode 100644 arch/arm/mach-samsung/reset_source.c
 create mode 100644 common/reset_source.c
 create mode 100644 include/reset_source.h

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

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

* [PATCH 1/4] Enable a way to provide the reason for "being here"
  2012-07-13  6:04 [PATCHv4] Enable a way to provide the reason for "being here" Juergen Beisert
@ 2012-07-13  6:04 ` Juergen Beisert
  2012-07-16  8:37   ` Sascha Hauer
  2012-07-13  6:04 ` [PATCH 2/4] ARM/Samsung: add support to detect the reset source Juergen Beisert
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Juergen Beisert @ 2012-07-13  6:04 UTC (permalink / raw)
  To: barebox

Many architectures support a way to detect why the bootloader is running.
This patch adds a global variable to be able to use the cause in some kind of
shell code to do special things on demand. For example to do an emergency boot,
when the last boot fails and the watchdog reactivate the hanging system.

Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
---
 common/Makefile        |    2 +-
 common/reset_source.c  |   44 ++++++++++++++++++++++++++++++++++++++++++++
 include/reset_source.h |   27 +++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 common/reset_source.c
 create mode 100644 include/reset_source.h

diff --git a/common/Makefile b/common/Makefile
index d99dfa2..baf4539 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -29,7 +29,7 @@ obj-$(CONFIG_UIMAGE) += uimage.o
 obj-y += startup.o
 obj-y += misc.o
 obj-y += memsize.o
-obj-$(CONFIG_GLOBALVAR) += globalvar.o
+obj-$(CONFIG_GLOBALVAR) += globalvar.o reset_source.o
 obj-$(CONFIG_FILETYPE) += filetype.o
 obj-y += resource.o
 obj-$(CONFIG_MENU) += menu.o
diff --git a/common/reset_source.c b/common/reset_source.c
new file mode 100644
index 0000000..2a7f9ff
--- /dev/null
+++ b/common/reset_source.c
@@ -0,0 +1,44 @@
+/*
+ * (C) Copyright 2012 Juergen Beisert - <kernel@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 <init.h>
+#include <environment.h>
+#include <globalvar.h>
+#include <reset_source.h>
+
+static const char * const reset_src_names[] = {
+	[RESET_UKWN] = "unknown",
+	[RESET_POR] = "POR",
+	[RESET_RST] = "RST",
+	[RESET_WDG] = "WDG",
+	[RESET_WKE] = "WKE",
+	[RESET_JTAG] = "JTAG",
+};
+
+void set_reset_source(enum reset_src_type st)
+{
+	setenv("global.system.reset", reset_src_names[st]);
+}
+EXPORT_SYMBOL(set_reset_source);
+
+/* ensure this runs after the 'global' device is already registerd */
+static int init_reset_source(void)
+{
+	globalvar_add_simple("system.reset");
+	set_reset_source(RESET_UKWN);
+	return 0;
+}
+
+coredevice_initcall(init_reset_source);
diff --git a/include/reset_source.h b/include/reset_source.h
new file mode 100644
index 0000000..8bb366c
--- /dev/null
+++ b/include/reset_source.h
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+#ifndef __INCLUDE_RESET_SOURCE_H
+# define __INCLUDE_RESET_SOURCE_H
+
+enum reset_src_type {
+	RESET_UKWN,	/* maybe the SoC cannot detect the reset source */
+	RESET_POR,	/* Power On Reset (cold start) */
+	RESET_RST,	/* generic ReSeT (warm start) */
+	RESET_WDG,	/* watchdog */
+	RESET_WKE,	/* wake-up (some SoCs can handle this) */
+	RESET_JTAG,	/* JTAG reset */
+};
+
+extern void set_reset_source(enum reset_src_type);
+
+#endif /* __INCLUDE_RESET_SOURCE_H */
-- 
1.7.10.4


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

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

* [PATCH 2/4] ARM/Samsung: add support to detect the reset source
  2012-07-13  6:04 [PATCHv4] Enable a way to provide the reason for "being here" Juergen Beisert
  2012-07-13  6:04 ` [PATCH 1/4] " Juergen Beisert
@ 2012-07-13  6:04 ` Juergen Beisert
  2012-07-13  6:04 ` [PATCH 3/4] ARM/i.MX: " Juergen Beisert
  2012-07-13  6:04 ` [PATCH 4/4] ARM/MXS: add reset cause detection Juergen Beisert
  3 siblings, 0 replies; 8+ messages in thread
From: Juergen Beisert @ 2012-07-13  6:04 UTC (permalink / raw)
  To: barebox

Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
---
 arch/arm/mach-samsung/Makefile       |    1 +
 arch/arm/mach-samsung/reset_source.c |   56 ++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 arch/arm/mach-samsung/reset_source.c

diff --git a/arch/arm/mach-samsung/Makefile b/arch/arm/mach-samsung/Makefile
index 6020587..5ac8e3c 100644
--- a/arch/arm/mach-samsung/Makefile
+++ b/arch/arm/mach-samsung/Makefile
@@ -1,4 +1,5 @@
 obj-y += s3c-timer.o generic.o
+obj-$(CONFIG_GLOBALVAR) += reset_source.o
 obj-lowlevel-$(CONFIG_ARCH_S3C24xx) += lowlevel-s3c24x0.o
 obj-lowlevel-$(CONFIG_ARCH_S5PCxx) += lowlevel-s5pcxx.o
 obj-$(CONFIG_ARCH_S3C24xx) += gpio-s3c24x0.o s3c24xx-clocks.o mem-s3c24x0.o
diff --git a/arch/arm/mach-samsung/reset_source.c b/arch/arm/mach-samsung/reset_source.c
new file mode 100644
index 0000000..2456e3f
--- /dev/null
+++ b/arch/arm/mach-samsung/reset_source.c
@@ -0,0 +1,56 @@
+/*
+ * (C) Copyright 2012 Juergen Beisert - <kernel@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 <init.h>
+#include <io.h>
+#include <reset_source.h>
+#include <mach/s3c-iomap.h>
+
+/* S3C2440 relevant */
+#define S3C2440_GSTATUS2 0xb4
+# define S3C2440_GSTATUS2_PWRST (1 << 0)
+# define S3C2440_GSTATUS2_SLEEPRST (1 << 1)
+# define S3C2440_GSTATUS2_WDRST (1 << 2)
+
+static int s3c_detect_reset_source(void)
+{
+	u32 reg = readl(S3C_GPIO_BASE + S3C2440_GSTATUS2);
+
+	if (reg & S3C2440_GSTATUS2_PWRST) {
+		set_reset_source(RESET_POR);
+		writel(S3C2440_GSTATUS2_PWRST,
+					S3C_GPIO_BASE + S3C2440_GSTATUS2);
+		return 0;
+	}
+
+	if (reg & S3C2440_GSTATUS2_SLEEPRST) {
+		set_reset_source(RESET_WKE);
+		writel(S3C2440_GSTATUS2_SLEEPRST,
+					S3C_GPIO_BASE + S3C2440_GSTATUS2);
+		return 0;
+	}
+
+	if (reg & S3C2440_GSTATUS2_WDRST) {
+		set_reset_source(RESET_WDG);
+		writel(S3C2440_GSTATUS2_WDRST,
+					S3C_GPIO_BASE + S3C2440_GSTATUS2);
+		return 0;
+	}
+
+	/* else keep the default 'unknown' state */
+	return 0;
+}
+
+device_initcall(s3c_detect_reset_source);
-- 
1.7.10.4


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

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

* [PATCH 3/4] ARM/i.MX: add support to detect the reset source
  2012-07-13  6:04 [PATCHv4] Enable a way to provide the reason for "being here" Juergen Beisert
  2012-07-13  6:04 ` [PATCH 1/4] " Juergen Beisert
  2012-07-13  6:04 ` [PATCH 2/4] ARM/Samsung: add support to detect the reset source Juergen Beisert
@ 2012-07-13  6:04 ` Juergen Beisert
  2012-07-13  6:04 ` [PATCH 4/4] ARM/MXS: add reset cause detection Juergen Beisert
  3 siblings, 0 replies; 8+ messages in thread
From: Juergen Beisert @ 2012-07-13  6:04 UTC (permalink / raw)
  To: barebox

Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
---
 arch/arm/mach-imx/Makefile       |    1 +
 arch/arm/mach-imx/reset_source.c |   72 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100644 arch/arm/mach-imx/reset_source.c

diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 89a8946..d6380ba 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -1,4 +1,5 @@
 obj-y += clocksource.o gpio.o
+obj-$(CONFIG_GLOBALVAR) += reset_source.o
 obj-$(CONFIG_ARCH_IMX1)  += speed-imx1.o  imx1.o  iomux-v1.o
 obj-$(CONFIG_ARCH_IMX25) += speed-imx25.o imx25.o iomux-v3.o
 obj-$(CONFIG_ARCH_IMX21) += speed-imx21.o imx21.o iomux-v1.o
diff --git a/arch/arm/mach-imx/reset_source.c b/arch/arm/mach-imx/reset_source.c
new file mode 100644
index 0000000..e7b2a90
--- /dev/null
+++ b/arch/arm/mach-imx/reset_source.c
@@ -0,0 +1,72 @@
+/*
+ * (C) Copyright 2012 Juergen Beisert - <kernel@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 <init.h>
+#include <io.h>
+#include <reset_source.h>
+#include <mach/imx-regs.h>
+
+#ifdef CONFIG_ARCH_IMX1
+#  define IMX_RESET_SRC_WDOG (1 << 1)
+#  define IMX_RESET_SRC_HRDRESET (1 << 0)
+/* let the compiler sort out useless code on this arch */
+#  define IMX_RESET_SRC_WARMSTART 0
+#  define IMX_RESET_SRC_COLDSTART 0
+#else
+  /* WRSR checked for i.MX25, i.MX27, i.MX31, i.MX35 and i.MX51 */
+# define WDOG_WRSR 0x04
+  /* valid for i.MX25, i.MX27, i.MX31, i.MX35, i.MX51 */
+#  define IMX_RESET_SRC_WARMSTART (1 << 0)
+  /* valid for i.MX25, i.MX27, i.MX31, i.MX35, i.MX51 */
+#  define IMX_RESET_SRC_WDOG (1 << 1)
+  /* valid for i.MX27, i.MX31, always '0' on i.MX25, i.MX35, i.MX51 */
+#  define IMX_RESET_SRC_HRDRESET (1 << 3)
+  /* valid for i.MX27, i.MX31, always '0' on i.MX25, i.MX35, i.MX51 */
+#  define IMX_RESET_SRC_COLDSTART (1 << 4)
+#endif
+
+static unsigned read_detection_register(void)
+{
+#ifdef CONFIG_ARCH_IMX1
+	return readl(IMX_SYSCTRL_BASE);
+#else
+	return readw(IMX_WDT_BASE + WDOG_WRSR);
+#endif
+}
+
+static int imx_detect_reset_source(void)
+{
+	unsigned reg = read_detection_register();
+
+	if (reg & IMX_RESET_SRC_COLDSTART) {
+		set_reset_source(RESET_POR);
+		return 0;
+	}
+
+	if (reg & (IMX_RESET_SRC_HRDRESET | IMX_RESET_SRC_WARMSTART)) {
+		set_reset_source(RESET_RST);
+		return 0;
+	}
+
+	if (reg & IMX_RESET_SRC_WDOG) {
+		set_reset_source(RESET_WDG);
+		return 0;
+	}
+
+	/* else keep the default 'unknown' state */
+	return 0;
+}
+
+device_initcall(imx_detect_reset_source);
-- 
1.7.10.4


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

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

* [PATCH 4/4] ARM/MXS: add reset cause detection
  2012-07-13  6:04 [PATCHv4] Enable a way to provide the reason for "being here" Juergen Beisert
                   ` (2 preceding siblings ...)
  2012-07-13  6:04 ` [PATCH 3/4] ARM/i.MX: " Juergen Beisert
@ 2012-07-13  6:04 ` Juergen Beisert
  3 siblings, 0 replies; 8+ messages in thread
From: Juergen Beisert @ 2012-07-13  6:04 UTC (permalink / raw)
  To: barebox

Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
---
 drivers/watchdog/im28wd.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/watchdog/im28wd.c b/drivers/watchdog/im28wd.c
index b016910..eb6099a 100644
--- a/drivers/watchdog/im28wd.c
+++ b/drivers/watchdog/im28wd.c
@@ -21,6 +21,7 @@
 #include <errno.h>
 #include <malloc.h>
 #include <watchdog.h>
+#include <reset_source.h>
 
 #define MXS_RTC_CTRL 0x0
 #define MXS_RTC_SET_ADDR 0x4
@@ -73,6 +74,27 @@ static int imx28_watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
 	return 0;
 }
 
+static void __maybe_unused imx28_detect_reset_source(const struct imx28_wd *p)
+{
+	u32 reg;
+
+	reg = readl(p->regs + MXS_RTC_PERSISTENT0);
+	if (reg & MXS_RTC_PERSISTENT0_EXT_RST) {
+		writel(MXS_RTC_PERSISTENT0_EXT_RST,
+			p->regs + MXS_RTC_PERSISTENT0 + MXS_RTC_CLR_ADDR);
+		set_reset_source(RESET_POR);
+		return;
+	}
+	if (reg & MXS_RTC_PERSISTENT0_THM_RST) {
+		writel(MXS_RTC_PERSISTENT0_THM_RST,
+			p->regs + MXS_RTC_PERSISTENT0 + MXS_RTC_CLR_ADDR);
+		set_reset_source(RESET_RST);
+		return;
+	}
+
+	set_reset_source(RESET_RST);
+}
+
 static int imx28_wd_probe(struct device_d *dev)
 {
 	struct imx28_wd *priv;
@@ -94,6 +116,9 @@ static int imx28_wd_probe(struct device_d *dev)
 	if (rc != 0)
 		goto on_error;
 
+	if (IS_ENABLED(CONFIG_GLOBALVAR))
+		imx28_detect_reset_source(priv);
+
 	dev->priv = priv;
 	return 0;
 
-- 
1.7.10.4


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

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

* Re: [PATCH 1/4] Enable a way to provide the reason for "being here"
  2012-07-13  6:04 ` [PATCH 1/4] " Juergen Beisert
@ 2012-07-16  8:37   ` Sascha Hauer
  0 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2012-07-16  8:37 UTC (permalink / raw)
  To: Juergen Beisert; +Cc: barebox

On Fri, Jul 13, 2012 at 08:04:46AM +0200, Juergen Beisert wrote:
> Many architectures support a way to detect why the bootloader is running.
> This patch adds a global variable to be able to use the cause in some kind of
> shell code to do special things on demand. For example to do an emergency boot,
> when the last boot fails and the watchdog reactivate the hanging system.
> 
> Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
> ---
>  common/Makefile        |    2 +-
>  common/reset_source.c  |   44 ++++++++++++++++++++++++++++++++++++++++++++
>  include/reset_source.h |   27 +++++++++++++++++++++++++++
>  3 files changed, 72 insertions(+), 1 deletion(-)
>  create mode 100644 common/reset_source.c
>  create mode 100644 include/reset_source.h
> 
> diff --git a/common/Makefile b/common/Makefile
> index d99dfa2..baf4539 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -29,7 +29,7 @@ obj-$(CONFIG_UIMAGE) += uimage.o
>  obj-y += startup.o
>  obj-y += misc.o
>  obj-y += memsize.o
> -obj-$(CONFIG_GLOBALVAR) += globalvar.o
> +obj-$(CONFIG_GLOBALVAR) += globalvar.o reset_source.o

This should be a separate config option which depends on GLOBALVAR.


> +	RESET_WKE,	/* wake-up (some SoCs can handle this) */
> +	RESET_JTAG,	/* JTAG reset */
> +};
> +
> +extern void set_reset_source(enum reset_src_type);

'extern' is not needed in function declarations.

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 1/4] Enable a way to provide the reason for "being here"
  2012-07-18  8:46 [PATCHv5] Enable a way to provide the reason for "being here" Juergen Beisert
@ 2012-07-18  8:46 ` Juergen Beisert
  0 siblings, 0 replies; 8+ messages in thread
From: Juergen Beisert @ 2012-07-18  8:46 UTC (permalink / raw)
  To: barebox

Many architectures support a way to detect why the bootloader is running.
This patch adds a global variable to be able to use the cause in some kind of
shell code to do special things on demand. For example to do an emergency boot,
when the last boot fails and the watchdog reactivate the hanging system.

Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
---
 common/Kconfig         |    8 ++++++++
 common/Makefile        |    1 +
 common/reset_source.c  |   44 ++++++++++++++++++++++++++++++++++++++++++++
 include/reset_source.h |   27 +++++++++++++++++++++++++++
 4 files changed, 80 insertions(+)
 create mode 100644 common/reset_source.c
 create mode 100644 include/reset_source.h

diff --git a/common/Kconfig b/common/Kconfig
index 5fe997d..9652e5d 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -554,6 +554,14 @@ config BAREBOXENV_TARGET
 config POLLER
 	bool "generic polling infrastructure"
 
+config RESET_SOURCE
+	bool "detect Reset cause"
+	depends on GLOBALVAR
+	help
+	  Provide a global variable at runtine which reflects the possible cause
+	  of the reset and why the bootloader is currently running. It can be
+	  useful for any kind of system recovery or repair.
+
 endmenu
 
 menu "Debugging                     "
diff --git a/common/Makefile b/common/Makefile
index d99dfa2..d74dffb 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -30,6 +30,7 @@ obj-y += startup.o
 obj-y += misc.o
 obj-y += memsize.o
 obj-$(CONFIG_GLOBALVAR) += globalvar.o
+obj-$(CONFIG_RESET_SOURCE) += reset_source.o
 obj-$(CONFIG_FILETYPE) += filetype.o
 obj-y += resource.o
 obj-$(CONFIG_MENU) += menu.o
diff --git a/common/reset_source.c b/common/reset_source.c
new file mode 100644
index 0000000..2a7f9ff
--- /dev/null
+++ b/common/reset_source.c
@@ -0,0 +1,44 @@
+/*
+ * (C) Copyright 2012 Juergen Beisert - <kernel@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 <init.h>
+#include <environment.h>
+#include <globalvar.h>
+#include <reset_source.h>
+
+static const char * const reset_src_names[] = {
+	[RESET_UKWN] = "unknown",
+	[RESET_POR] = "POR",
+	[RESET_RST] = "RST",
+	[RESET_WDG] = "WDG",
+	[RESET_WKE] = "WKE",
+	[RESET_JTAG] = "JTAG",
+};
+
+void set_reset_source(enum reset_src_type st)
+{
+	setenv("global.system.reset", reset_src_names[st]);
+}
+EXPORT_SYMBOL(set_reset_source);
+
+/* ensure this runs after the 'global' device is already registerd */
+static int init_reset_source(void)
+{
+	globalvar_add_simple("system.reset");
+	set_reset_source(RESET_UKWN);
+	return 0;
+}
+
+coredevice_initcall(init_reset_source);
diff --git a/include/reset_source.h b/include/reset_source.h
new file mode 100644
index 0000000..6734fbde
--- /dev/null
+++ b/include/reset_source.h
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+#ifndef __INCLUDE_RESET_SOURCE_H
+# define __INCLUDE_RESET_SOURCE_H
+
+enum reset_src_type {
+	RESET_UKWN,	/* maybe the SoC cannot detect the reset source */
+	RESET_POR,	/* Power On Reset (cold start) */
+	RESET_RST,	/* generic ReSeT (warm start) */
+	RESET_WDG,	/* watchdog */
+	RESET_WKE,	/* wake-up (some SoCs can handle this) */
+	RESET_JTAG,	/* JTAG reset */
+};
+
+void set_reset_source(enum reset_src_type);
+
+#endif /* __INCLUDE_RESET_SOURCE_H */
-- 
1.7.10.4


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

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

* [PATCH 1/4] Enable a way to provide the reason for "being here"
  2012-07-12 13:47 [PATCHv3] " Juergen Beisert
@ 2012-07-12 13:47 ` Juergen Beisert
  0 siblings, 0 replies; 8+ messages in thread
From: Juergen Beisert @ 2012-07-12 13:47 UTC (permalink / raw)
  To: barebox

Many architectures support a way to detect why the bootloader is running.
This patch adds a global variable to be able to use the cause in some kind of
shell code to do special things on demand. For example to do an emergency boot,
when the last boot fails and the watchdog reactivate the hanging system.

Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
---
 common/Makefile        |    2 +-
 common/reset_source.c  |   44 ++++++++++++++++++++++++++++++++++++++++++++
 include/reset_source.h |   27 +++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 common/reset_source.c
 create mode 100644 include/reset_source.h

diff --git a/common/Makefile b/common/Makefile
index d99dfa2..baf4539 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -29,7 +29,7 @@ obj-$(CONFIG_UIMAGE) += uimage.o
 obj-y += startup.o
 obj-y += misc.o
 obj-y += memsize.o
-obj-$(CONFIG_GLOBALVAR) += globalvar.o
+obj-$(CONFIG_GLOBALVAR) += globalvar.o reset_source.o
 obj-$(CONFIG_FILETYPE) += filetype.o
 obj-y += resource.o
 obj-$(CONFIG_MENU) += menu.o
diff --git a/common/reset_source.c b/common/reset_source.c
new file mode 100644
index 0000000..2a7f9ff
--- /dev/null
+++ b/common/reset_source.c
@@ -0,0 +1,44 @@
+/*
+ * (C) Copyright 2012 Juergen Beisert - <kernel@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 <init.h>
+#include <environment.h>
+#include <globalvar.h>
+#include <reset_source.h>
+
+static const char * const reset_src_names[] = {
+	[RESET_UKWN] = "unknown",
+	[RESET_POR] = "POR",
+	[RESET_RST] = "RST",
+	[RESET_WDG] = "WDG",
+	[RESET_WKE] = "WKE",
+	[RESET_JTAG] = "JTAG",
+};
+
+void set_reset_source(enum reset_src_type st)
+{
+	setenv("global.system.reset", reset_src_names[st]);
+}
+EXPORT_SYMBOL(set_reset_source);
+
+/* ensure this runs after the 'global' device is already registerd */
+static int init_reset_source(void)
+{
+	globalvar_add_simple("system.reset");
+	set_reset_source(RESET_UKWN);
+	return 0;
+}
+
+coredevice_initcall(init_reset_source);
diff --git a/include/reset_source.h b/include/reset_source.h
new file mode 100644
index 0000000..8bb366c
--- /dev/null
+++ b/include/reset_source.h
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+#ifndef __INCLUDE_RESET_SOURCE_H
+# define __INCLUDE_RESET_SOURCE_H
+
+enum reset_src_type {
+	RESET_UKWN,	/* maybe the SoC cannot detect the reset source */
+	RESET_POR,	/* Power On Reset (cold start) */
+	RESET_RST,	/* generic ReSeT (warm start) */
+	RESET_WDG,	/* watchdog */
+	RESET_WKE,	/* wake-up (some SoCs can handle this) */
+	RESET_JTAG,	/* JTAG reset */
+};
+
+extern void set_reset_source(enum reset_src_type);
+
+#endif /* __INCLUDE_RESET_SOURCE_H */
-- 
1.7.10.4


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

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

end of thread, other threads:[~2012-07-18  8:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-13  6:04 [PATCHv4] Enable a way to provide the reason for "being here" Juergen Beisert
2012-07-13  6:04 ` [PATCH 1/4] " Juergen Beisert
2012-07-16  8:37   ` Sascha Hauer
2012-07-13  6:04 ` [PATCH 2/4] ARM/Samsung: add support to detect the reset source Juergen Beisert
2012-07-13  6:04 ` [PATCH 3/4] ARM/i.MX: " Juergen Beisert
2012-07-13  6:04 ` [PATCH 4/4] ARM/MXS: add reset cause detection Juergen Beisert
  -- strict thread matches above, loose matches on Subject: below --
2012-07-18  8:46 [PATCHv5] Enable a way to provide the reason for "being here" Juergen Beisert
2012-07-18  8:46 ` [PATCH 1/4] " Juergen Beisert
2012-07-12 13:47 [PATCHv3] " Juergen Beisert
2012-07-12 13:47 ` [PATCH 1/4] " Juergen Beisert

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