Skip to contentSkip to conversation

Consolidate bootcount code into drivers/bootcount

PATCH Superseded Stefan Roese 5 participants 10 messages Jun 5, 2012 – Aug 13, 2012

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Consolidate bootcount code into drivers/bootcount

This patch moves all bootcount implementations into a common
directory: drivers/bootcount. The generic bootcount driver is now usable not only by powerpc platforms, but others as well.

Cc Heiko Schocher <[email protected]>
Cc Valentin Longchamp <[email protected]>
Cc Christian Riesch <[email protected]>
Cc Manfred Rudigier <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Rob Herring <[email protected]>
Cc Reinhard Meyer <[email protected]>

---
v3:
- Moved le-/be-accessors into header so that they now can be used by all bootcount drivers.
- Changed CONFIG_BOOTCOUNT_LE to CONFIG_SYS_BOOTCOUNT_LE
- Enabled CONFIG_SYS_BOOTCOUNT_LE in highbank
- Enabled CONFIG_SYS_BOOTCOUNT_SINGLEWORD in highbank

v2:
- Added CONFIG_BOOTCOUNT_LE to bootcount_davinci.c and enabled it in calimain.h to select little-endian accessors.

 Makefile                                           |    3 +
 arch/arm/cpu/arm926ejs/at91/cpu.c                  |   26 -------
 arch/arm/cpu/armv7/highbank/Makefile               |    2 +-
 arch/arm/cpu/armv7/highbank/bootcount.c            |   36 ----------
 arch/arm/cpu/ixp/cpu.c                             |   22 ------
 arch/powerpc/lib/Makefile                          |    1 -
 board/enbw/enbw_cmc/enbw_cmc.c                     |   29 --------
 board/keymile/km_arm/km_arm.c                      |   51 --------------
 board/omicron/calimain/calimain.c                  |   29 --------
 drivers/bootcount/Makefile                         |   47 +++++++++++++
 .../powerpc/lib => drivers/bootcount}/bootcount.c  |   25 ++++---
 drivers/bootcount/bootcount_at91.c                 |   43 ++++++++++++
 .../bootcount/bootcount_blackfin.c                 |    0
 drivers/bootcount/bootcount_davinci.c              |   49 +++++++++++++
 drivers/bootcount/bootcount_ram.c                  |   72 ++++++++++++++++++++
 include/bootcount.h                                |   42 ++++++++++++
 include/configs/calimain.h                         |    1 +
 include/configs/highbank.h                         |    2 +
 include/configs/km/km_arm.h                        |    2 +
 19 files changed, 276 insertions(+), 206 deletions(-)
 delete mode 100644 arch/arm/cpu/armv7/highbank/bootcount.c
 create mode 100644 drivers/bootcount/Makefile
 rename {arch/powerpc/lib => drivers/bootcount}/bootcount.c (84%)
 create mode 100644 drivers/bootcount/bootcount_at91.c
 rename arch/blackfin/cpu/bootcount.c => drivers/bootcount/bootcount_blackfin.c (100%)
 create mode 100644 drivers/bootcount/bootcount_davinci.c
 create mode 100644 drivers/bootcount/bootcount_ram.c
 create mode 100644 include/bootcount.h
Makefile +3 -0
index 659e8f2..8fd51b8 100644
@@ -249,6 +249,9 @@ LIBS += net/libnet.o
 LIBS += disk/libdisk.o
 LIBS += drivers/bios_emulator/libatibiosemu.o
 LIBS += drivers/block/libblock.o
+ifeq ($(CONFIG_BOOTCOUNT_LIMIT),y)
+LIBS += drivers/bootcount/libbootcount.o
+endif
 LIBS += drivers/dma/libdma.o
 LIBS += drivers/fpga/libfpga.o
 LIBS += drivers/gpio/libgpio.o
arch/arm/cpu/arm926ejs/at91/cpu.c +0 -26
index c47fb31..5cf4fad 100644
@@ -71,29 +71,3 @@ int print_cpuinfo(void)
 	return 0;
 }
 #endif
-
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-/*
- * We combine the BOOTCOUNT_MAGIC and bootcount in one 32-bit register.
- * This is done so we need to use only one of the four GPBR registers.
- */
-void bootcount_store (ulong a)
-{
-	at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
-
-	writel((BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
-		&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
-}
-
-ulong bootcount_load (void)
-{
-	at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
-
-	ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
-	if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
-		return 0;
-	else
-		return val & 0x0000ffff;
-}
-
-#endif /* CONFIG_BOOTCOUNT_LIMIT */
arch/arm/cpu/armv7/highbank/Makefile +1 -1
index 917c3a3..76faeb0 100644
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(SOC).o
 
-COBJS	:= timer.o bootcount.o
+COBJS	:= timer.o
 SOBJS	:=
 
 SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
arch/arm/cpu/armv7/highbank/bootcount.c deleted +0 -36
deleted file mode 100644
index 9ca0656..0000000
@@ -1,36 +0,0 @@
-/*
- * Copyright 2011 Calxeda, Inc.
- *
- * 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 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.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <common.h>
-#include <asm/io.h>
-
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-void bootcount_store(ulong a)
-{
-	writel((BOOTCOUNT_MAGIC & 0xffff0000) | a, CONFIG_SYS_BOOTCOUNT_ADDR);
-}
-
-ulong bootcount_load(void)
-{
-	u32 tmp = readl(CONFIG_SYS_BOOTCOUNT_ADDR);
-
-	if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
-		return 0;
-	else
-		return tmp & 0x0000ffff;
-}
-#endif
arch/arm/cpu/ixp/cpu.c +0 -22
index 942845d..f1864d6 100644
@@ -107,28 +107,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
arch/powerpc/lib/Makefile +0 -1
index cdd62a2..965f9ea 100644
@@ -46,7 +46,6 @@ SOBJS-y	+= reloc.o
 COBJS-$(CONFIG_BAT_RW) += bat_rw.o
 COBJS-y	+= board.o
 COBJS-y	+= bootm.o
-COBJS-$(CONFIG_BOOTCOUNT_LIMIT) += bootcount.o
 COBJS-y	+= cache.o
 COBJS-y	+= extable.o
 COBJS-y	+= interrupts.o
board/enbw/enbw_cmc/enbw_cmc.c +0 -29
index 6c0d931..3616df0 100644
@@ -517,35 +517,6 @@ void arch_memory_failure_handle(void)
 }
 #endif
 
-#if defined(CONFIG_BOOTCOUNT_LIMIT)
-void bootcount_store(ulong a)
-{
-	struct davinci_rtc *reg =
-		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
-
-	/*
-	 * write RTC kick register to enable write
-	 * for RTC Scratch registers. Scratch0 and 1 are
-	 * used for bootcount values.
-	 */
-	writel(RTC_KICK0R_WE, &reg->kick0r);
-	writel(RTC_KICK1R_WE, &reg->kick1r);
-	out_be32(&reg->scratch0, a);
-	out_be32(&reg->scratch1, BOOTCOUNT_MAGIC);
-}
-
-ulong bootcount_load(void)
-{
-	struct davinci_rtc *reg =
-		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
-
-	if (in_be32(&reg->scratch1) != BOOTCOUNT_MAGIC)
-		return 0;
-	else
-		return in_be32(&reg->scratch0);
-}
-#endif
-
 void board_gpio_init(void)
 {
 	struct davinci_gpio *gpio = davinci_gpio_bank01;
board/keymile/km_arm/km_arm.c +0 -51

57 lines not on this page · raw message

board/omicron/calimain/calimain.c +0 -29
index 54415ce..1060a1f 100644
@@ -157,32 +157,3 @@ void hw_watchdog_reset(void)
 	davinci_hw_watchdog_reset();
 }
 #endif
-
-#if defined(CONFIG_BOOTCOUNT_LIMIT)
-void bootcount_store(ulong a)
-{
-	struct davinci_rtc *reg =
-		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
-
-	/*
-	 * write RTC kick register to enable write
-	 * for RTC Scratch registers. Scratch0 and 1 are
-	 * used for bootcount values.
-	 */
-	writel(RTC_KICK0R_WE, &reg->kick0r);
-	writel(RTC_KICK1R_WE, &reg->kick1r);
-	writel(a, &reg->scratch0);
-	writel(BOOTCOUNT_MAGIC, &reg->scratch1);
-}
-
-ulong bootcount_load(void)
-{
-	struct davinci_rtc *reg =
-		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
-
-	if (readl(&reg->scratch1) != BOOTCOUNT_MAGIC)
-		return 0;
-	else
-		return readl(&reg->scratch0);
-}
-#endif
drivers/bootcount/Makefile new file +47 -0

47 lines not on this page · raw message

drivers/bootcount/bootcount.c renamed from arch/powerpc/lib/bootcount.c +14 -11
similarity index 84%
rename from arch/powerpc/lib/bootcount.c
rename to drivers/bootcount/bootcount.c
index f9ce539..a470b62 100644
@@ -1,5 +1,5 @@
 /*
- * (C) Copyright 2010
+ * (C) Copyright 2010-2012
  * Stefan Roese, DENX Software Engineering, sr at denx.de.
  *
  * See file CREDITS for list of people who contributed to this
@@ -21,8 +21,8 @@
  * MA 02111-1307 USA
  */
 
-#include <common.h>
-#include <asm/io.h>
+#include <bootcount.h>
+#include <linux/compiler.h>
 
 /*
  * Only override CONFIG_SYS_BOOTCOUNT_ADDR if not already defined. This
@@ -65,33 +65,36 @@
 
 #endif /* !defined(CONFIG_SYS_BOOTCOUNT_ADDR) */
 
-void bootcount_store(ulong a)
+/* Now implement the generic default functions */
+#if defined(CONFIG_SYS_BOOTCOUNT_ADDR)
+__weak void bootcount_store(ulong a)
 {
 	void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
 
 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
-	out_be32(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
+	bc_out32(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
 #else
-	out_be32(reg, a);
-	out_be32(reg + 4, BOOTCOUNT_MAGIC);
+	bc_out32(reg, a);
+	bc_out32(reg + 4, BOOTCOUNT_MAGIC);
 #endif
 }
 
-ulong bootcount_load(void)
+__weak ulong bootcount_load(void)
 {
 	void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
 
 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
-	u32 tmp = in_be32(reg);
+	u32 tmp = bc_in32(reg);
 
 	if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
 		return 0;
 	else
 		return (tmp & 0x0000ffff);
 #else
-	if (in_be32(reg + 4) != BOOTCOUNT_MAGIC)
+	if (bc_in32(reg + 4) != BOOTCOUNT_MAGIC)
 		return 0;
 	else
-		return in_be32(reg);
+		return bc_in32(reg);
 #endif
 }
+#endif
drivers/bootcount/bootcount_at91.c new file +43 -0

43 lines not on this page · raw message

drivers/bootcount/bootcount_blackfin.c renamed from arch/blackfin/cpu/bootcount.c +0 -0
similarity index 100%
rename from arch/blackfin/cpu/bootcount.c
rename to drivers/bootcount/bootcount_blackfin.c
drivers/bootcount/bootcount_davinci.c new file +49 -0

49 lines not on this page · raw message

drivers/bootcount/bootcount_ram.c new file +72 -0

72 lines not on this page · raw message

include/bootcount.h new file +42 -0

42 lines not on this page · raw message

include/configs/calimain.h +1 -0
index 6b68f10..c89f276 100644
@@ -354,6 +354,7 @@
 #define CONFIG_SYS_INIT_SP_ADDR		(0x8001ff00)
 
 #define CONFIG_BOOTCOUNT_LIMIT
+#define CONFIG_SYS_BOOTCOUNT_LE		/* Use little-endian accessors */
 #define CONFIG_SYS_BOOTCOUNT_ADDR	DAVINCI_RTC_BASE
 
 #ifndef __ASSEMBLY__
include/configs/highbank.h +2 -0
index 520fa4c..a76cfc3 100644
@@ -42,6 +42,8 @@
 #define CONFIG_SYS_BAUDRATE_TABLE	{ 9600, 19200, 38400, 57600, 115200 }
 
 #define CONFIG_BOOTCOUNT_LIMIT
+#define CONFIG_SYS_BOOTCOUNT_SINGLEWORD
+#define CONFIG_SYS_BOOTCOUNT_LE		/* Use little-endian accessors */
 #define CONFIG_SYS_BOOTCOUNT_ADDR	0xfff3cf0c
 
 #define CONFIG_MISC_INIT_R
include/configs/km/km_arm.h +2 -0
index c73a10c..229745a 100644
@@ -274,6 +274,8 @@ int get_scl(void);
 #define CONFIG_KM_RESERVED_PRAM 0x801000
 /* address for the bootcount (taken from end of RAM) */
 #define BOOTCOUNT_ADDR          (CONFIG_KM_RESERVED_PRAM)
+/* Use generic bootcount RAM driver */
+#define CONFIG_BOOTCOUNT_RAM
 
 /* enable POST tests */
 #define CONFIG_POST	(CONFIG_SYS_POST_MEM_REGIONS)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v3 1/1 Consolidate bootcount code into drivers/bootcount

Quoted 4 lines · Stefan Roese

This patch moves all bootcount implementations into a common
directory: drivers/bootcount. The generic bootcount driver is now usable not only by powerpc platforms, but others as well.

Quoted 10 lines
Cc Heiko Schocher <[email protected]>
Cc Valentin Longchamp <[email protected]>
Cc Christian Riesch <[email protected]>
Cc Manfred Rudigier <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Rob Herring <[email protected]>
Cc Reinhard Meyer <[email protected]>

For highbank:

Quoted 723 lines

---
v3:
- Moved le-/be-accessors into header so that they now can be used by all bootcount drivers.
- Changed CONFIG_BOOTCOUNT_LE to CONFIG_SYS_BOOTCOUNT_LE
- Enabled CONFIG_SYS_BOOTCOUNT_LE in highbank
- Enabled CONFIG_SYS_BOOTCOUNT_SINGLEWORD in highbank

v2:
- Added CONFIG_BOOTCOUNT_LE to bootcount_davinci.c and enabled it in calimain.h to select little-endian accessors.

 Makefile                                           |    3 +
 arch/arm/cpu/arm926ejs/at91/cpu.c                  |   26 -------
 arch/arm/cpu/armv7/highbank/Makefile               |    2 +-
 arch/arm/cpu/armv7/highbank/bootcount.c            |   36 ----------
 arch/arm/cpu/ixp/cpu.c                             |   22 ------
 arch/powerpc/lib/Makefile                          |    1 -
 board/enbw/enbw_cmc/enbw_cmc.c                     |   29 --------
 board/keymile/km_arm/km_arm.c                      |   51 --------------
 board/omicron/calimain/calimain.c                  |   29 --------
 drivers/bootcount/Makefile                         |   47 +++++++++++++
 .../powerpc/lib => drivers/bootcount}/bootcount.c  |   25 ++++---
 drivers/bootcount/bootcount_at91.c                 |   43 ++++++++++++
 .../bootcount/bootcount_blackfin.c                 |    0
 drivers/bootcount/bootcount_davinci.c              |   49 +++++++++++++
 drivers/bootcount/bootcount_ram.c                  |   72 ++++++++++++++++++++
 include/bootcount.h                                |   42 ++++++++++++
 include/configs/calimain.h                         |    1 +
 include/configs/highbank.h                         |    2 +
 include/configs/km/km_arm.h                        |    2 +
 19 files changed, 276 insertions(+), 206 deletions(-)
 delete mode 100644 arch/arm/cpu/armv7/highbank/bootcount.c
 create mode 100644 drivers/bootcount/Makefile
 rename {arch/powerpc/lib => drivers/bootcount}/bootcount.c (84%)
 create mode 100644 drivers/bootcount/bootcount_at91.c
 rename arch/blackfin/cpu/bootcount.c => drivers/bootcount/bootcount_blackfin.c (100%)
 create mode 100644 drivers/bootcount/bootcount_davinci.c
 create mode 100644 drivers/bootcount/bootcount_ram.c
 create mode 100644 include/bootcount.h
Makefile +3 -0
index 659e8f2..8fd51b8 100644
@@ -249,6 +249,9 @@ LIBS += net/libnet.o
 LIBS += disk/libdisk.o
 LIBS += drivers/bios_emulator/libatibiosemu.o
 LIBS += drivers/block/libblock.o
+ifeq ($(CONFIG_BOOTCOUNT_LIMIT),y)
+LIBS += drivers/bootcount/libbootcount.o
+endif
 LIBS += drivers/dma/libdma.o
 LIBS += drivers/fpga/libfpga.o
 LIBS += drivers/gpio/libgpio.o
arch/arm/cpu/arm926ejs/at91/cpu.c +0 -26
index c47fb31..5cf4fad 100644
@@ -71,29 +71,3 @@ int print_cpuinfo(void)
 	return 0;
 }
 #endif
-
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-/*
- * We combine the BOOTCOUNT_MAGIC and bootcount in one 32-bit register.
- * This is done so we need to use only one of the four GPBR registers.
- */
-void bootcount_store (ulong a)
-{
-	at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
-
-	writel((BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
-		&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
-}
-
-ulong bootcount_load (void)
-{
-	at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
-
-	ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
-	if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
-		return 0;
-	else
-		return val & 0x0000ffff;
-}
-
-#endif /* CONFIG_BOOTCOUNT_LIMIT */
arch/arm/cpu/armv7/highbank/Makefile +1 -1
index 917c3a3..76faeb0 100644
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(SOC).o
 
-COBJS	:= timer.o bootcount.o
+COBJS	:= timer.o
 SOBJS	:=
 
 SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
arch/arm/cpu/armv7/highbank/bootcount.c deleted +0 -36
deleted file mode 100644
index 9ca0656..0000000
@@ -1,36 +0,0 @@
-/*
- * Copyright 2011 Calxeda, Inc.
- *
- * 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 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.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <common.h>
-#include <asm/io.h>
-
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-void bootcount_store(ulong a)
-{
-	writel((BOOTCOUNT_MAGIC & 0xffff0000) | a, CONFIG_SYS_BOOTCOUNT_ADDR);
-}
-
-ulong bootcount_load(void)
-{
-	u32 tmp = readl(CONFIG_SYS_BOOTCOUNT_ADDR);
-
-	if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
-		return 0;
-	else
-		return tmp & 0x0000ffff;
-}
-#endif
arch/arm/cpu/ixp/cpu.c +0 -22
index 942845d..f1864d6 100644
@@ -107,28 +107,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
arch/powerpc/lib/Makefile +0 -1
index cdd62a2..965f9ea 100644
@@ -46,7 +46,6 @@ SOBJS-y	+= reloc.o
 COBJS-$(CONFIG_BAT_RW) += bat_rw.o
 COBJS-y	+= board.o
 COBJS-y	+= bootm.o
-COBJS-$(CONFIG_BOOTCOUNT_LIMIT) += bootcount.o
 COBJS-y	+= cache.o
 COBJS-y	+= extable.o
 COBJS-y	+= interrupts.o
board/enbw/enbw_cmc/enbw_cmc.c +0 -29
index 6c0d931..3616df0 100644
@@ -517,35 +517,6 @@ void arch_memory_failure_handle(void)
 }
 #endif
 
-#if defined(CONFIG_BOOTCOUNT_LIMIT)
-void bootcount_store(ulong a)
-{
-	struct davinci_rtc *reg =
-		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
-
-	/*
-	 * write RTC kick register to enable write
-	 * for RTC Scratch registers. Scratch0 and 1 are
-	 * used for bootcount values.
-	 */
-	writel(RTC_KICK0R_WE, &reg->kick0r);
-	writel(RTC_KICK1R_WE, &reg->kick1r);
-	out_be32(&reg->scratch0, a);
-	out_be32(&reg->scratch1, BOOTCOUNT_MAGIC);
-}
-
-ulong bootcount_load(void)
-{
-	struct davinci_rtc *reg =
-		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
-
-	if (in_be32(&reg->scratch1) != BOOTCOUNT_MAGIC)
-		return 0;
-	else
-		return in_be32(&reg->scratch0);
-}
-#endif
-
 void board_gpio_init(void)
 {
 	struct davinci_gpio *gpio = davinci_gpio_bank01;
board/keymile/km_arm/km_arm.c +0 -51
index 9e9940c..667edbc 100644
@@ -404,57 +404,6 @@ int hush_init_var(void)
 }
 #endif
 
-#if defined(CONFIG_BOOTCOUNT_LIMIT)
-const ulong patterns[]      = {	0x00000000,
-				0xFFFFFFFF,
-				0xFF00FF00,
-				0x0F0F0F0F,
-				0xF0F0F0F0};
-const ulong NBR_OF_PATTERNS = sizeof(patterns)/sizeof(*patterns);
-const ulong OFFS_PATTERN    = 3;
-const ulong REPEAT_PATTERN  = 1000;
-
-void bootcount_store(ulong a)
-{
-	ulong *save_addr;
-	ulong size = 0;
-	int i;
-
-	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
-		size += gd->bd->bi_dram[i].size;
-	save_addr = (ulong *)(size - BOOTCOUNT_ADDR);
-	writel(a, save_addr);
-	writel(BOOTCOUNT_MAGIC, &save_addr[1]);
-
-	for (i = 0; i < REPEAT_PATTERN; i++)
-		writel(patterns[i % NBR_OF_PATTERNS],
-			&save_addr[i+OFFS_PATTERN]);
-
-}
-
-ulong bootcount_load(void)
-{
-	ulong *save_addr;
-	ulong size = 0;
-	ulong counter = 0;
-	int i, tmp;
-
-	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
-		size += gd->bd->bi_dram[i].size;
-	save_addr = (ulong *)(size - BOOTCOUNT_ADDR);
-
-	counter = readl(&save_addr[0]);
-
-	/* Is the counter reliable, check in the big pattern for bit errors */
-	for (i = 0; (i < REPEAT_PATTERN) && (counter != 0); i++) {
-		tmp = readl(&save_addr[i+OFFS_PATTERN]);
-		if (tmp != patterns[i % NBR_OF_PATTERNS])
-			counter = 0;
-	}
-	return counter;
-}
-#endif
-
 #if defined(CONFIG_SOFT_I2C)
 void set_sda(int state)
 {
board/omicron/calimain/calimain.c +0 -29
index 54415ce..1060a1f 100644
@@ -157,32 +157,3 @@ void hw_watchdog_reset(void)
 	davinci_hw_watchdog_reset();
 }
 #endif
-
-#if defined(CONFIG_BOOTCOUNT_LIMIT)
-void bootcount_store(ulong a)
-{
-	struct davinci_rtc *reg =
-		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
-
-	/*
-	 * write RTC kick register to enable write
-	 * for RTC Scratch registers. Scratch0 and 1 are
-	 * used for bootcount values.
-	 */
-	writel(RTC_KICK0R_WE, &reg->kick0r);
-	writel(RTC_KICK1R_WE, &reg->kick1r);
-	writel(a, &reg->scratch0);
-	writel(BOOTCOUNT_MAGIC, &reg->scratch1);
-}
-
-ulong bootcount_load(void)
-{
-	struct davinci_rtc *reg =
-		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
-
-	if (readl(&reg->scratch1) != BOOTCOUNT_MAGIC)
-		return 0;
-	else
-		return readl(&reg->scratch0);
-}
-#endif
drivers/bootcount/Makefile new file +47 -0
new file mode 100644
index 0000000..3d5ec13
@@ -0,0 +1,47 @@
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+include $(TOPDIR)/config.mk
+
+LIB 	:= $(obj)libbootcount.o
+
+COBJS-y				+= bootcount.o
+COBJS-$(CONFIG_AT91SAM9XE)	+= bootcount_at91.o
+COBJS-$(CONFIG_BFIN_CPU)	+= bootcount_blackfin.o
+COBJS-$(CONFIG_SOC_DA8XX)	+= bootcount_davinci.o
+COBJS-$(CONFIG_BOOTCOUNT_RAM)	+= bootcount_ram.o
+
+COBJS	:= $(COBJS-y)
+SRCS 	:= $(COBJS:.o=.c)
+OBJS 	:= $(addprefix $(obj),$(COBJS))
+
+all:	$(LIB)
+
+$(LIB):	$(obj).depend $(OBJS)
+	$(call cmd_link_o_target, $(OBJS))
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+########################################################################
drivers/bootcount/bootcount.c renamed from arch/powerpc/lib/bootcount.c +14 -11
similarity index 84%
rename from arch/powerpc/lib/bootcount.c
rename to drivers/bootcount/bootcount.c
index f9ce539..a470b62 100644
@@ -1,5 +1,5 @@
 /*
- * (C) Copyright 2010
+ * (C) Copyright 2010-2012
  * Stefan Roese, DENX Software Engineering, sr at denx.de.
  *
  * See file CREDITS for list of people who contributed to this
@@ -21,8 +21,8 @@
  * MA 02111-1307 USA
  */
 
-#include <common.h>
-#include <asm/io.h>
+#include <bootcount.h>
+#include <linux/compiler.h>
 
 /*
  * Only override CONFIG_SYS_BOOTCOUNT_ADDR if not already defined. This
@@ -65,33 +65,36 @@
 
 #endif /* !defined(CONFIG_SYS_BOOTCOUNT_ADDR) */
 
-void bootcount_store(ulong a)
+/* Now implement the generic default functions */
+#if defined(CONFIG_SYS_BOOTCOUNT_ADDR)
+__weak void bootcount_store(ulong a)
 {
 	void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
 
 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
-	out_be32(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
+	bc_out32(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
 #else
-	out_be32(reg, a);
-	out_be32(reg + 4, BOOTCOUNT_MAGIC);
+	bc_out32(reg, a);
+	bc_out32(reg + 4, BOOTCOUNT_MAGIC);
 #endif
 }
 
-ulong bootcount_load(void)
+__weak ulong bootcount_load(void)
 {
 	void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
 
 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
-	u32 tmp = in_be32(reg);
+	u32 tmp = bc_in32(reg);
 
 	if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
 		return 0;
 	else
 		return (tmp & 0x0000ffff);
 #else
-	if (in_be32(reg + 4) != BOOTCOUNT_MAGIC)
+	if (bc_in32(reg + 4) != BOOTCOUNT_MAGIC)
 		return 0;
 	else
-		return in_be32(reg);
+		return bc_in32(reg);
 #endif
 }
+#endif
drivers/bootcount/bootcount_at91.c new file +43 -0
new file mode 100644
index 0000000..7cfe14d
@@ -0,0 +1,43 @@
+/*
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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 <asm/io.h>
+#include <asm/arch/hardware.h>
+#include <asm/arch/at91_gpbr.h>
+
+/*
+ * We combine the BOOTCOUNT_MAGIC and bootcount in one 32-bit register.
+ * This is done so we need to use only one of the four GPBR registers.
+ */
+void bootcount_store(ulong a)
+{
+	at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
+
+	writel((BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
+		&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
+}
+
+ulong bootcount_load(void)
+{
+	at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
+
+	ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
+	if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
+		return 0;
+	else
+		return val & 0x0000ffff;
+}
drivers/bootcount/bootcount_blackfin.c renamed from arch/blackfin/cpu/bootcount.c +0 -0
similarity index 100%
rename from arch/blackfin/cpu/bootcount.c
rename to drivers/bootcount/bootcount_blackfin.c
drivers/bootcount/bootcount_davinci.c new file +49 -0
new file mode 100644
index 0000000..f560d72
@@ -0,0 +1,49 @@
+/*
+ * (C) Copyright 2011
+ * Heiko Schocher, DENX Software Engineering, hs at denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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 <bootcount.h>
+#include <asm/arch/da850_lowlevel.h>
+#include <asm/arch/davinci_misc.h>
+
+void bootcount_store(ulong a)
+{
+	struct davinci_rtc *reg =
+		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
+
+	/*
+	 * write RTC kick register to enable write
+	 * for RTC Scratch registers. Scratch0 and 1 are
+	 * used for bootcount values.
+	 */
+	writel(RTC_KICK0R_WE, &reg->kick0r);
+	writel(RTC_KICK1R_WE, &reg->kick1r);
+	bc_out32(&reg->scratch0, a);
+	bc_out32(&reg->scratch1, BOOTCOUNT_MAGIC);
+}
+
+ulong bootcount_load(void)
+{
+	struct davinci_rtc *reg =
+		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
+
+	if (bc_in32(&reg->scratch1) != BOOTCOUNT_MAGIC)
+		return 0;
+	else
+		return bc_in32(&reg->scratch0);
+}
drivers/bootcount/bootcount_ram.c new file +72 -0
new file mode 100644
index 0000000..8655af7
@@ -0,0 +1,72 @@
+/*
+ * (C) Copyright 2010
+ * Heiko Schocher, DENX Software Engineering, hs at denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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 <asm/io.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+const ulong patterns[]      = {	0x00000000,
+				0xFFFFFFFF,
+				0xFF00FF00,
+				0x0F0F0F0F,
+				0xF0F0F0F0};
+const ulong NBR_OF_PATTERNS = sizeof(patterns) / sizeof(*patterns);
+const ulong OFFS_PATTERN    = 3;
+const ulong REPEAT_PATTERN  = 1000;
+
+void bootcount_store(ulong a)
+{
+	ulong *save_addr;
+	ulong size = 0;
+	int i;
+
+	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
+		size += gd->bd->bi_dram[i].size;
+	save_addr = (ulong *)(size - BOOTCOUNT_ADDR);
+	writel(a, save_addr);
+	writel(BOOTCOUNT_MAGIC, &save_addr[1]);
+
+	for (i = 0; i < REPEAT_PATTERN; i++)
+		writel(patterns[i % NBR_OF_PATTERNS],
+			&save_addr[i + OFFS_PATTERN]);
+
+}
+
+ulong bootcount_load(void)
+{
+	ulong *save_addr;
+	ulong size = 0;
+	ulong counter = 0;
+	int i, tmp;
+
+	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
+		size += gd->bd->bi_dram[i].size;
+	save_addr = (ulong *)(size - BOOTCOUNT_ADDR);
+
+	counter = readl(&save_addr[0]);
+
+	/* Is the counter reliable, check in the big pattern for bit errors */
+	for (i = 0; (i < REPEAT_PATTERN) && (counter != 0); i++) {
+		tmp = readl(&save_addr[i + OFFS_PATTERN]);
+		if (tmp != patterns[i % NBR_OF_PATTERNS])
+			counter = 0;
+	}
+	return counter;
+}
include/bootcount.h new file +42 -0
new file mode 100644
index 0000000..1e60959
@@ -0,0 +1,42 @@
+/*
+ * (C) Copyright 2012
+ * Stefan Roese, DENX Software Engineering, sr at denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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 <asm/io.h>
+
+#ifdef CONFIG_SYS_BOOTCOUNT_LE
+static inline void bc_out32(volatile u32 *addr, u32 data)
+{
+	out_le32(addr, data);
+}
+
+static inline u32 bc_in32(volatile u32 *addr)
+{
+	return in_le32(addr);
+}
+#else
+static inline void bc_out32(volatile u32 *addr, u32 data)
+{
+	out_be32(addr, data);
+}
+
+static inline u32 bc_in32(volatile u32 *addr)
+{
+	return in_be32(addr);
+}
+#endif
include/configs/calimain.h +1 -0
index 6b68f10..c89f276 100644
@@ -354,6 +354,7 @@
 #define CONFIG_SYS_INIT_SP_ADDR		(0x8001ff00)
 
 #define CONFIG_BOOTCOUNT_LIMIT
+#define CONFIG_SYS_BOOTCOUNT_LE		/* Use little-endian accessors */
 #define CONFIG_SYS_BOOTCOUNT_ADDR	DAVINCI_RTC_BASE
 
 #ifndef __ASSEMBLY__
include/configs/highbank.h +2 -0
index 520fa4c..a76cfc3 100644
@@ -42,6 +42,8 @@
 #define CONFIG_SYS_BAUDRATE_TABLE	{ 9600, 19200, 38400, 57600, 115200 }
 
 #define CONFIG_BOOTCOUNT_LIMIT
+#define CONFIG_SYS_BOOTCOUNT_SINGLEWORD
+#define CONFIG_SYS_BOOTCOUNT_LE		/* Use little-endian accessors */
 #define CONFIG_SYS_BOOTCOUNT_ADDR	0xfff3cf0c
 
 #define CONFIG_MISC_INIT_R
include/configs/km/km_arm.h +2 -0
index c73a10c..229745a 100644
@@ -274,6 +274,8 @@ int get_scl(void);
 #define CONFIG_KM_RESERVED_PRAM 0x801000
 /* address for the bootcount (taken from end of RAM) */
 #define BOOTCOUNT_ADDR          (CONFIG_KM_RESERVED_PRAM)
+/* Use generic bootcount RAM driver */
+#define CONFIG_BOOTCOUNT_RAM
 
 /* enable POST tests */
 #define CONFIG_POST	(CONFIG_SYS_POST_MEM_REGIONS)
#2 lore raw

PATCH v3 1/1 Consolidate bootcount code into drivers/bootcount

In reply to Stefan Roese

Dear Stefan Roese,

Quoted 4 lines · In message <[email protected]> you wrote:

This patch moves all bootcount implementations into a common
directory: drivers/bootcount. The generic bootcount driver is now usable not only by powerpc platforms, but others as well.

Quoted 10 lines
Cc Heiko Schocher <[email protected]>
Cc Valentin Longchamp <[email protected]>
Cc Christian Riesch <[email protected]>
Cc Manfred Rudigier <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Rob Herring <[email protected]>
Cc Reinhard Meyer <[email protected]>

Sorry, this does not apply any more:

Applying patch #163024 to current directory
Description: [U-Boot,v3] Consolidate bootcount code into drivers/bootcount
Applying: Consolidate bootcount code into drivers/bootcount
fatal: sha1 information is lacking or useless (Makefile). Repository lacks necessary blobs to fall back on 3-way merge. Cannot fall back to three-way merge.
Patch failed at 0001 Consolidate bootcount code into drivers/bootcount

Can you please rebase? Thanks!

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
I perceive a possibility of an immediate  chronological  sequence  of
events which includes a violence.
                        - Terry Pratchett, _The Dark Side of the Sun_
#3 lore raw

PATCH v3 1/1 Consolidate bootcount code into drivers/bootcount

In reply to Stefan Roese

drivers/bootcount/Makefile

Quoted 4 lines · On Tuesday 05 June 2012 02:37:55 Stefan Roese wrote:
drivers/bootcount/Makefile new file +1 -0
 
+COBJS-$(CONFIG_BFIN_CPU)	+= bootcount_blackfin.o

needs to be CONFIG_BLACKFIN

Quoted 1 line

+all: $(LIB)

unused rule -> delete

include/bootcount.h line 23

Quoted 5 lines
include/bootcount.h new file +2 -0
 
+#ifdef CONFIG_SYS_BOOTCOUNT_LE
+static inline void bc_out32(volatile u32 *addr, u32 data)

the bc_xxx names are a little confusing since they overlap so much with the existing io.h api. how about "raw_bootcount_store" ?

Quoted 9 lines
include/bootcount.h new file +9 -0
+{
+	out_le32(addr, data);
+}
+
+static inline u32 bc_in32(volatile u32 *addr)
+{
+	return in_le32(addr);
+}
+#else

include/bootcount.h line 42

Quoted 10 lines
include/bootcount.h new file +10 -0
+static inline void bc_out32(volatile u32 *addr, u32 data)
+{
+	out_be32(addr, data);
+}
+
+static inline u32 bc_in32(volatile u32 *addr)
+{
+	return in_be32(addr);
+}
+#endif

i'm not a big fan of defaulting to an endian regardless of the host. in this case, it appears to benefit ppc only.

what about:
#include <asm/byteorder.h>
#if !defined(CONFIG_SYS_BOOTCOUNT_LE) && !defined(CONFIG_SYS_BOOTCOUNT_BE)

# if __BYTE_ORDER == __LITTLE_ENDIAN
#  define CONFIG_SYS_BOOTCOUNT_LE
# else
#  define CONFIG_SYS_BOOTCOUNT_BE
# endif
#endif

or if you're not a fan of that, then:
#if defined(CONFIG_SYS_BOOTCOUNT_LE)
... current in_le logic ...
#elif defined(CONFIG_SYS_BOOTCOUNT_BE)
... current in_be logic ...
#else

# error "please select one of CONFIG_SYS_BOOTCOUNT_{L,B}E"
#endif

and then add a default to arch/powerpc/include/asm/config.h
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120811/97d73248/attachment.pgp>

#4 lore raw

PATCH v3 1/1 Consolidate bootcount code into drivers/bootcount

Quoted 7 lines · Mike Frysinger

drivers/bootcount/Makefile

Quoted 4 lines · On Tuesday 05 June 2012 02:37:55 Stefan Roese wrote:
drivers/bootcount/Makefile new file +1 -0
 
+COBJS-$(CONFIG_BFIN_CPU)	+= bootcount_blackfin.o

needs to be CONFIG_BLACKFIN

Okay.

Quoted 3 lines
Quoted 1 line

+all: $(LIB)

unused rule -> delete

Okay.

Quoted 8 lines

include/bootcount.h line 23

Quoted 5 lines
include/bootcount.h new file +2 -0
 
+#ifdef CONFIG_SYS_BOOTCOUNT_LE
+static inline void bc_out32(volatile u32 *addr, u32 data)

the bc_xxx names are a little confusing since they overlap so much with the existing io.h api. how about "raw_bootcount_store" ?

Okay.

Quoted 39 lines
Quoted 9 lines
include/bootcount.h new file +9 -0
+{
+	out_le32(addr, data);
+}
+
+static inline u32 bc_in32(volatile u32 *addr)
+{
+	return in_le32(addr);
+}
+#else

include/bootcount.h line 42

Quoted 10 lines
include/bootcount.h new file +10 -0
+static inline void bc_out32(volatile u32 *addr, u32 data)
+{
+	out_be32(addr, bdata);
+}
+
+static inline u32 bc_in32(volatile u32 *addr)
+{
+	return in_be32(addr);
+}
+#endif

i'm not a big fan of defaulting to an endian regardless of the host. in this case, it appears to benefit ppc only.

what about:
#include <asm/byteorder.h>
#if !defined(CONFIG_SYS_BOOTCOUNT_LE) && !defined(CONFIG_SYS_BOOTCOUNT_BE)

# if __BYTE_ORDER == __LITTLE_ENDIAN
#  define CONFIG_SYS_BOOTCOUNT_LE
# else
#  define CONFIG_SYS_BOOTCOUNT_BE
# endif
#endif

or if you're not a fan of that, then:
#if defined(CONFIG_SYS_BOOTCOUNT_LE)
... current in_le logic ...
#elif defined(CONFIG_SYS_BOOTCOUNT_BE)
... current in_be logic ...
#else

Quoted 4 lines
# error "please select one of CONFIG_SYS_BOOTCOUNT_{L,B}E"
#endif

and then add a default to arch/powerpc/include/asm/config.h

Good idea. I'll send a new version with the 2nd approach later today.

Thanks,
Stefan

#5 lore raw

PATCH v3 1/1 Consolidate bootcount code into drivers/bootcount

In reply to Stefan Roese

Dear Stefan Roese,

Quoted 103 lines · Stefan Roese

This patch moves all bootcount implementations into a common
directory: drivers/bootcount. The generic bootcount driver is now usable not only by powerpc platforms, but others as well.

Cc Heiko Schocher <[email protected]>
Cc Valentin Longchamp <[email protected]>
Cc Christian Riesch <[email protected]>
Cc Manfred Rudigier <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Rob Herring <[email protected]>
Cc Reinhard Meyer <[email protected]>

---
v3:
- Moved le-/be-accessors into header so that they now can be used by all bootcount drivers.
- Changed CONFIG_BOOTCOUNT_LE to CONFIG_SYS_BOOTCOUNT_LE
- Enabled CONFIG_SYS_BOOTCOUNT_LE in highbank
- Enabled CONFIG_SYS_BOOTCOUNT_SINGLEWORD in highbank

v2:
- Added CONFIG_BOOTCOUNT_LE to bootcount_davinci.c and enabled it in calimain.h to select little-endian accessors.

 Makefile                                           |    3 +
 arch/arm/cpu/arm926ejs/at91/cpu.c                  |   26 -------
 arch/arm/cpu/armv7/highbank/Makefile               |    2 +-
 arch/arm/cpu/armv7/highbank/bootcount.c            |   36 ----------
 arch/arm/cpu/ixp/cpu.c                             |   22 ------
 arch/powerpc/lib/Makefile                          |    1 -
 board/enbw/enbw_cmc/enbw_cmc.c                     |   29 --------
 board/keymile/km_arm/km_arm.c                      |   51 --------------
 board/omicron/calimain/calimain.c                  |   29 --------
 drivers/bootcount/Makefile                         |   47 +++++++++++++
 .../powerpc/lib => drivers/bootcount}/bootcount.c  |   25 ++++---
 drivers/bootcount/bootcount_at91.c                 |   43 ++++++++++++
 .../bootcount/bootcount_blackfin.c                 |    0
 drivers/bootcount/bootcount_davinci.c              |   49 +++++++++++++
 drivers/bootcount/bootcount_ram.c                  |   72 ++++++++++++++++++++
 include/bootcount.h                                |   42 ++++++++++++
 include/configs/calimain.h                         |    1 +
 include/configs/highbank.h                         |    2 +
 include/configs/km/km_arm.h                        |    2 +
 19 files changed, 276 insertions(+), 206 deletions(-)
 delete mode 100644 arch/arm/cpu/armv7/highbank/bootcount.c
 create mode 100644 drivers/bootcount/Makefile
 rename {arch/powerpc/lib => drivers/bootcount}/bootcount.c (84%)
 create mode 100644 drivers/bootcount/bootcount_at91.c
 rename arch/blackfin/cpu/bootcount.c => drivers/bootcount/bootcount_blackfin.c (100%)
 create mode 100644 drivers/bootcount/bootcount_davinci.c
 create mode 100644 drivers/bootcount/bootcount_ram.c
 create mode 100644 include/bootcount.h
Makefile +3 -0
index 659e8f2..8fd51b8 100644
@@ -249,6 +249,9 @@ LIBS += net/libnet.o
 LIBS += disk/libdisk.o
 LIBS += drivers/bios_emulator/libatibiosemu.o
 LIBS += drivers/block/libblock.o
+ifeq ($(CONFIG_BOOTCOUNT_LIMIT),y)
+LIBS += drivers/bootcount/libbootcount.o
+endif
 LIBS += drivers/dma/libdma.o
 LIBS += drivers/fpga/libfpga.o
 LIBS += drivers/gpio/libgpio.o
arch/arm/cpu/arm926ejs/at91/cpu.c +0 -26
index c47fb31..5cf4fad 100644
@@ -71,29 +71,3 @@ int print_cpuinfo(void)
 	return 0;
 }
 #endif
-
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-/*
- * We combine the BOOTCOUNT_MAGIC and bootcount in one 32-bit register.
- * This is done so we need to use only one of the four GPBR registers.
- */
-void bootcount_store (ulong a)
-{
-	at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
-
-	writel((BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
-		&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
-}
-
-ulong bootcount_load (void)
-{
-	at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
-
-	ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
-	if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
-		return 0;
-	else
-		return val & 0x0000ffff;
-}
-
-#endif /* CONFIG_BOOTCOUNT_LIMIT */

<snip>

Quoted 22 lines
drivers/bootcount/Makefile new file +16 -0
new file mode 100644
index 0000000..3d5ec13
@@ -0,0 +1,47 @@
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software

drivers/bootcount/Makefile line 26

Quoted 10 lines
drivers/bootcount/Makefile new file +10 -0
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+include $(TOPDIR)/config.mk
+
+LIB 	:= $(obj)libbootcount.o
+
+COBJS-y				+= bootcount.o
+COBJS-$(CONFIG_AT91SAM9XE)	+= bootcount_at91.o

I tend to NAK this. Before it was available to all at91 processors (keep in mind nearly all at91 have this gpbr register). Now it is only available to AT91SAM9XE processor series which is the only user for bootcount in mainline. I fear we may break some not mainline boards here. I would prefer something that includes all different at91 SoC by default (except rm9200).

I have no solution yet but send this to prevent a v4. Will send a proposal for at91 later this day.

Best regards

Andreas Bie?mann

#6 lore raw

PATCH v3 1/1 Consolidate bootcount code into drivers/bootcount

Hi Andreas,

Quoted 9 lines · Andreas Bie?mann

drivers/bootcount/Makefile line 26

Quoted 4 lines
drivers/bootcount/Makefile new file +4 -0
+LIB 	:= $(obj)libbootcount.o
+
+COBJS-y				+= bootcount.o
+COBJS-$(CONFIG_AT91SAM9XE)	+= bootcount_at91.o

I tend to NAK this. Before it was available to all at91 processors (keep in mind nearly all at91 have this gpbr register). Now it is only available to AT91SAM9XE processor series which is the only user for bootcount in mainline.

Then we should choose a different CONFIG_ option here. One that selects all AT91 boards potentially supporting this feature. You are the expert here, please make a suggestion.

Quoted 2 lines

I fear we may break some not mainline boards
here.

Maybe. But we usually don't care about out-of-tree ports.

Quoted 5 lines

I would prefer something that includes all different at91 SoC by default (except rm9200).

I have no solution yet but send this to prevent a v4. Will send a proposal for at91 later this day.

Okay. But I would really like to see this patch go in soon. I still have a new board support patch waiting here for quite a long time depending on this bootcount stuff.

Best regards,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

#7 lore raw

PATCH v3 1/1 Consolidate bootcount code into drivers/bootcount

Hi Stefan,

Quoted 13 lines · Stefan Roese

Hi Andreas,

Quoted 9 lines · Andreas Bie?mann

drivers/bootcount/Makefile line 26

Quoted 4 lines
drivers/bootcount/Makefile new file +4 -0
+LIB 	:= $(obj)libbootcount.o
+
+COBJS-y				+= bootcount.o
+COBJS-$(CONFIG_AT91SAM9XE)	+= bootcount_at91.o

I tend to NAK this. Before it was available to all at91 processors (keep in mind nearly all at91 have this gpbr register). Now it is only available to AT91SAM9XE processor series which is the only user for bootcount in mainline.

Quoted 3 lines

Then we should choose a different CONFIG_ option here. One that selects all AT91 boards potentially supporting this feature. You are the expert here, please make a suggestion.

Unfortunately there is no such config option yet. We could add all the SoC explicitly like this:

---8<---

| +COBJS-$(CONFIG_AT91SAM9260)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9261)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9263)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9G10)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9G20)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9M10G45) += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9RL)     += bootcount_at91.o
|  COBJS-$(CONFIG_AT91SAM9XE)     += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9G20)    += bootcount_at91.o

--->8---

Maybe there is some make foo to get this easier?

Quoted 4 lines
Quoted 2 lines

I fear we may break some not mainline boards
here.

Maybe. But we usually don't care about out-of-tree ports.

That is true, we could just wait for patches adding this feature to other at91 SoC.

Quoted 9 lines
Quoted 5 lines

I would prefer something that includes all different at91 SoC by default (except rm9200).

I have no solution yet but send this to prevent a v4. Will send a proposal for at91 later this day.

Okay. But I would really like to see this patch go in soon. I still have a new board support patch waiting here for quite a long time depending on this bootcount stuff.

I'm with you, do you have a suggestion how to do the make foo nice?

Best regards

Andreas Bie?mann

#8 lore raw

PATCH v3 1/1 Consolidate bootcount code into drivers/bootcount

Hi Andreas,

Quoted 25 lines · Andreas Bie?mann
Quoted 11 lines
Quoted 7 lines

drivers/bootcount/Makefile line 26

Quoted 2 lines
drivers/bootcount/Makefile new file +2 -0
+COBJS-y				+= bootcount.o
+COBJS-$(CONFIG_AT91SAM9XE)	+= bootcount_at91.o

I tend to NAK this. Before it was available to all at91 processors (keep in mind nearly all at91 have this gpbr register). Now it is only available to AT91SAM9XE processor series which is the only user for bootcount in mainline.

Then we should choose a different CONFIG_ option here. One that selects all AT91 boards potentially supporting this feature. You are the expert here, please make a suggestion.

Unfortunately there is no such config option yet. We could add all the SoC explicitly like this:

---8<---

| +COBJS-$(CONFIG_AT91SAM9260)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9261)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9263)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9G10)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9G20)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9M10G45) += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9RL)     += bootcount_at91.o
|  COBJS-$(CONFIG_AT91SAM9XE)     += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9G20)    += bootcount_at91.o
Quoted 3 lines

--->8---

Maybe there is some make foo to get this easier?

Maybe. But nothing I can think of quickly. The better solution would be to add a new common CONFIG_AT91 (or similar) define, which is defined for all at91 platforms. Might be helpful in other places as well.

Not sure, how to best add this global AT91 define though. Easy wold be to add it to config header files.

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

I fear we may break some not mainline boards
here.

Maybe. But we usually don't care about out-of-tree ports.

That is true, we could just wait for patches adding this feature to other at91 SoC.

Quoted 3 lines
Quoted 3 lines

I would prefer something that includes all different at91 SoC by default (except rm9200).

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I have no solution yet but send this to prevent a v4. Will send a proposal for at91 later this day.

Okay. But I would really like to see this patch go in soon. I still have a new board support patch waiting here for quite a long time depending on this bootcount stuff.

I'm with you, do you have a suggestion how to do the make foo nice?

See above. Perhaps somebody else has other suggestions.

Nevertheless I think we can postpone this "AT91 bootcount tuning" to a follow-up patch.

Best regards,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

#9 lore raw

PATCH v3 1/1 Consolidate bootcount code into drivers/bootcount

Hi Stefan,

Quoted 30 lines · Stefan Roese

Hi Andreas,

Quoted 27 lines · Andreas Bie?mann
Quoted 11 lines
Quoted 7 lines

drivers/bootcount/Makefile line 26

Quoted 2 lines
drivers/bootcount/Makefile new file +2 -0
+COBJS-y				+= bootcount.o
+COBJS-$(CONFIG_AT91SAM9XE)	+= bootcount_at91.o

I tend to NAK this. Before it was available to all at91 processors (keep in mind nearly all at91 have this gpbr register). Now it is only available to AT91SAM9XE processor series which is the only user for bootcount in mainline.

Then we should choose a different CONFIG_ option here. One that selects all AT91 boards potentially supporting this feature. You are the expert here, please make a suggestion.

Unfortunately there is no such config option yet. We could add all the SoC explicitly like this:

---8<---

| +COBJS-$(CONFIG_AT91SAM9260)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9261)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9263)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9G10)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9G20)    += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9M10G45) += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9RL)     += bootcount_at91.o
|  COBJS-$(CONFIG_AT91SAM9XE)     += bootcount_at91.o
| +COBJS-$(CONFIG_AT91SAM9G20)    += bootcount_at91.o

--->8---

Quoted 8 lines
Quoted 1 line

Maybe there is some make foo to get this easier?

Maybe. But nothing I can think of quickly. The better solution would be to add a new common CONFIG_AT91 (or similar) define, which is defined for all at91 platforms. Might be helpful in other places as well.

Not sure, how to best add this global AT91 define though. Easy wold be to add it to config header files.

I think we put it in the asm/arch/hardware.h files, something like CONFIG_AT91_GPBR.

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines
Quoted 2 lines

I fear we may break some not mainline boards
here.

Maybe. But we usually don't care about out-of-tree ports.

That is true, we could just wait for patches adding this feature to other at91 SoC.

Quoted 9 lines
Quoted 5 lines

I would prefer something that includes all different at91 SoC by default (except rm9200).

I have no solution yet but send this to prevent a v4. Will send a proposal for at91 later this day.

Okay. But I would really like to see this patch go in soon. I still have a new board support patch waiting here for quite a long time depending on this bootcount stuff.

Quoted 6 lines
Quoted 1 line

I'm with you, do you have a suggestion how to do the make foo nice?

See above. Perhaps somebody else has other suggestions.

Nevertheless I think we can postpone this "AT91 bootcount tuning" to a follow-up patch.

This is ok for me. Just realized there is a v4 on patchwork (but did not hit my MUA ...).

Just add a

to v4.

Best regards

Andreas Bie?mann