All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anatolij Gustschin <agust@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] ARM: Consolidate bootcount_{store|load}
Date: Mon, 13 Sep 2010 21:31:59 +0200	[thread overview]
Message-ID: <1284406319-9032-1-git-send-email-agust@denx.de> (raw)

This patch consolidates bootcount_{store|load} for ARM by
implementing a common version in arch/arm/lib/bootcount.c. This
code is now used by all ARM variants that currently have these
functions implemented.

Also supports two different bootcount versions:

    a) Use 2 separate words (2 * 32bit) to store the bootcounter
    b) Use only 1 word (2 * 16bit) to store the bootcounter

The latter was already used by AT91.

Signed-off-by: Anatolij Gustschin <agust@denx.de>
---
 arch/arm/cpu/arm926ejs/at91/cpu.c |   34 -------------------------
 arch/arm/cpu/ixp/cpu.c            |   22 ----------------
 arch/arm/lib/Makefile             |    1 +
 arch/arm/lib/bootcount.c          |   49 +++++++++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+), 56 deletions(-)
 create mode 100644 arch/arm/lib/bootcount.c

diff --git a/arch/arm/cpu/arm926ejs/at91/cpu.c b/arch/arm/cpu/arm926ejs/at91/cpu.c
index 141a7d1..1094f8c 100644
--- a/arch/arm/cpu/arm926ejs/at91/cpu.c
+++ b/arch/arm/cpu/arm926ejs/at91/cpu.c
@@ -35,13 +35,6 @@
 #define CONFIG_SYS_AT91_MAIN_CLOCK 0
 #endif
 
-/*
- * The at91sam9260 has 4 GPBR (0-3), we'll use the last one, nr 3,
- * to keep track of the bootcount.
- */
-#define AT91_GPBR_BOOTCOUNT_REGISTER 3
-#define AT91_BOOTCOUNT_ADDRESS (AT91_GPBR + 4*AT91_GPBR_BOOTCOUNT_REGISTER)
-
 int arch_cpu_init(void)
 {
 	return at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK);
@@ -63,30 +56,3 @@ int print_cpuinfo(void)
 	return 0;
 }
 #endif
-
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-/*
- * Just as the mpc5xxx, we combine the BOOTCOUNT_MAGIC and boocount
- * in one 32-bit register. This is done, as the AT91SAM9260 only has
- * 4 GPBR.
- */
-void bootcount_store (ulong a)
-{
-	volatile ulong *save_addr =
-		(volatile ulong *)(AT91_BASE_SYS + AT91_BOOTCOUNT_ADDRESS);
-
-	*save_addr = (BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff);
-}
-
-ulong bootcount_load (void)
-{
-	volatile ulong *save_addr =
-		(volatile ulong *)(AT91_BASE_SYS + AT91_BOOTCOUNT_ADDRESS);
-
-	if ((*save_addr & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
-		return 0;
-	else
-		return (*save_addr & 0x0000ffff);
-}
-
-#endif /* CONFIG_BOOTCOUNT_LIMIT */
diff --git a/arch/arm/cpu/ixp/cpu.c b/arch/arm/cpu/ixp/cpu.c
index ce275e5..b35b1cd 100644
--- a/arch/arm/cpu/ixp/cpu.c
+++ b/arch/arm/cpu/ixp/cpu.c
@@ -112,28 +112,6 @@ void pci_init(void)
 }
 */
 
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-
-void bootcount_store (ulong a)
-{
-	volatile ulong *save_addr = (volatile ulong *)(CONFIG_SYS_BOOTCOUNT_ADDR);
-
-	save_addr[0] = a;
-	save_addr[1] = BOOTCOUNT_MAGIC;
-}
-
-ulong bootcount_load (void)
-{
-	volatile ulong *save_addr = (volatile ulong *)(CONFIG_SYS_BOOTCOUNT_ADDR);
-
-	if (save_addr[1] != BOOTCOUNT_MAGIC)
-		return 0;
-	else
-		return save_addr[0];
-}
-
-#endif /* CONFIG_BOOTCOUNT_LIMIT */
-
 int cpu_eth_init(bd_t *bis)
 {
 #ifdef CONFIG_IXP4XX_NPE
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 0293348..4d26fe7 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -44,6 +44,7 @@ COBJS-y	+= cache-cp15.o
 endif
 COBJS-y	+= interrupts.o
 COBJS-y	+= reset.o
+COBJS-$(CONFIG_BOOTCOUNT_LIMIT) += bootcount.o
 
 SRCS	:= $(GLSOBJS:.o=.S) $(GLCOBJS:.o=.c) \
 	   $(SOBJS-y:.o=.S) $(COBJS-y:.o=.c)
diff --git a/arch/arm/lib/bootcount.c b/arch/arm/lib/bootcount.c
new file mode 100644
index 0000000..22f96bd
--- /dev/null
+++ b/arch/arm/lib/bootcount.c
@@ -0,0 +1,49 @@
+#include <common.h>
+
+#ifdef CONFIG_AT91SAM9260
+#include <asm/arch/hardware.h>
+
+/*
+ * The at91sam9260 has 4 GPBR (0-3), we'll use the last one, nr 3,
+ * to keep track of the bootcount.
+ */
+#define AT91_GPBR_BOOTCOUNT_REGISTER 3
+#define AT91_BOOTCOUNT_ADDRESS	(AT91_GPBR + 4 * AT91_GPBR_BOOTCOUNT_REGISTER)
+#define CONFIG_SYS_BOOTCOUNT_ADDR	(AT91_BASE_SYS + AT91_BOOTCOUNT_ADDRESS)
+/*
+ * Just as the mpc5xxx, we combine the BOOTCOUNT_MAGIC and bootcount
+ * in one 32-bit register. This is done, as the AT91SAM9260 only has
+ * 4 GPBR.
+ */
+#define CONFIG_SYS_BOOTCOUNT_SINGLEWORD
+
+#endif /* CONFIG_AT91SAM9260 */
+
+void bootcount_store(ulong a)
+{
+	volatile ulong *addr = (volatile ulong *)(CONFIG_SYS_BOOTCOUNT_ADDR);
+
+#if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
+	addr[0] = (BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff);
+#else
+	addr[0] = a;
+	addr[1] = BOOTCOUNT_MAGIC;
+#endif
+}
+
+ulong bootcount_load(void)
+{
+	volatile ulong *addr = (volatile ulong *)(CONFIG_SYS_BOOTCOUNT_ADDR);
+
+#if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
+	if ((addr[0] & 0xffff0000) == (BOOTCOUNT_MAGIC & 0xffff0000))
+		return addr[0] & 0x0000ffff;
+	else
+		return 0;
+#else
+	if (addr[1] == BOOTCOUNT_MAGIC)
+		return addr[0];
+	else
+		return 0;
+#endif
+}
-- 
1.7.0.4

             reply	other threads:[~2010-09-13 19:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-13 19:31 Anatolij Gustschin [this message]
2010-09-14  0:33 ` [U-Boot] [PATCH] ARM: Consolidate bootcount_{store|load} Reinhard Meyer
2010-09-14  1:11 ` Reinhard Meyer
2010-09-14  9:42   ` Anatolij Gustschin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1284406319-9032-1-git-send-email-agust@denx.de \
    --to=agust@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.