Consolidate bootcount code into drivers/bootcount
Subsystems (4)
PATCH 1/1 Consolidate bootcount code into drivers/bootcount
This patch moves all bootcount implementations into a common
directory: drivers/bootcount. The generic bootcount driver (bootcount.c) is now usable not only by powerpc platforms, but others as well. Highbank is already moved to this "generic" code. For all other non-generic implementations, SoC specific drivers have been created (e.g. bootcount_at91.c).
---
Mike, the blackfin implementation is not compile-tested yet. Could you please give it a try?
Thanks,
Stefan
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 | 10 ++-
drivers/bootcount/bootcount_at91.c | 43 ++++++++++++
.../bootcount/bootcount_blackfin.c | 0
drivers/bootcount/bootcount_davinci.c | 50 ++++++++++++++
drivers/bootcount/bootcount_ram.c | 72 ++++++++++++++++++++
include/configs/km/km_arm.h | 2 +
16 files changed, 225 insertions(+), 198 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 (92%)
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.cMakefile +3 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 , ®->kick0r); -writel (RTC_KICK1R_WE , ®->kick1r); -out_be32 (®->scratch0, a); -out_be32 (®->scratch1,BOOTCOUNT_MAGIC ); -} - -ulong bootcount_load (void ) -{ -struct davinci_rtc *reg = - (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR ; - -if (in_be32 (®->scratch1) !=BOOTCOUNT_MAGIC ) -return 0 ; -else -return in_be32 (®->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
@@ -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 , ®->kick0r); -writel (RTC_KICK1R_WE , ®->kick1r); -writel (a, ®->scratch0); -writel (BOOTCOUNT_MAGIC , ®->scratch1); -} - -ulong bootcount_load (void ) -{ -struct davinci_rtc *reg = - (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR ; - -if (readl (®->scratch1) !=BOOTCOUNT_MAGIC ) -return 0 ; -else -return readl (®->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 +7 -3
@@ -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
@@ -22,6 +22,7 @@*/ #include <common.h> +#include <linux/compiler.h> #include <asm/io.h> /*
@@ -65,7 +66,9 @@#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 ;
@@ -77,7 +80,7 @@ void bootcount_store(ulong a)#endif } -ulong bootcount_load (void ) +__weak ulong bootcount_load (void ) {void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR ;
@@ -95,3 +98,4 @@ ulong bootcount_load(void)return in_be32 (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
drivers/bootcount/bootcount_davinci.c new file +50 -0
50 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/configs/km/km_arm.h +2 -0
@@ -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.3
PATCH 1/1 Consolidate bootcount code into drivers/bootcount
Hi Stefan,
Quoted 6 lines · Stefan Roese
This patch moves all bootcount implementations into a common
directory:drivers/bootcount. The generic bootcount driver (bootcount.c) is now usable not only by powerpc platforms, but others as well. Highbank is already moved to this "generic" code. For all other non-generic implementations, SoC specific drivers have been created (e.g.bootcount_at91.c).
Thank you for this patch! I have reviewed and tested the davinci/calimain parts of it, please see below.
[...]
Quoted 34 lines
drivers/bootcount/bootcount_davinci.c new file +28
-0@@ -0,0 +1,50 @@ +/* +* (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 <common.h> +#include <asm/io.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;
drivers/bootcount/bootcount_davinci.c line 38
Quoted 10 lines
drivers/bootcount/bootcount_davinci.c new file +10
-0+ + ? ? ? /* + ? ? ? ?* write RTC kick register to enable write + ? ? ? ?* for RTC Scratch registers. Scratch0 and 1 are + ? ? ? ?* used for bootcount values. + ? ? ? ?*/ + ? ? ? writel(RTC_KICK0R_WE, ®->kick0r); + ? ? ? writel(RTC_KICK1R_WE, ®->kick1r); + ? ? ? out_be32(®->scratch0, a); + ? ? ? out_be32(®->scratch1, BOOTCOUNT_MAGIC);
This code here seems to be copied from the enbw_cmc board. The calimain board uses writel instead of out_be32 for the scratch registers (because I didn't understand why we should use big endian on a little endian machine). So your patch changes the byte order here for the calimain board and thus breaks our boot counter support.
What's the reason for using out_be32 here?
drivers/bootcount/bootcount_davinci.c line 49
Quoted 11 lines
drivers/bootcount/bootcount_davinci.c new file +11
-0+} + +ulong bootcount_load (void ) +{ + ? ? ? struct davinci_rtc *reg = + ? ? ? ? ? ? ? (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR; + + ? ? ? if (in_be32(®->scratch1) != BOOTCOUNT_MAGIC) + ? ? ? ? ? ? ? return 0; + ? ? ? else + ? ? ? ? ? ? ? return in_be32(®->scratch0);
Same as above, the calimain board uses readl instead of in_be32.
I replaced out_be32 by writel and in_be32 by readl and tested it on the calimain board, it works fine :-)
Regards, Christian
PATCH 1/1 Consolidate bootcount code into drivers/bootcount
Hi Christian,
Quoted 12 lines · On Friday 01 June 2012 14:51:32 Christian Riesch wrote:
Quoted 12 lines
drivers/bootcount/bootcount_davinci.c new file +12
-0+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 , ®->kick0r); +writel (RTC_KICK1R_WE , ®->kick1r);
Quoted 8 lines
drivers/bootcount/bootcount_davinci.c line 38
Quoted 2 lines
drivers/bootcount/bootcount_davinci.c new file +2
-0+out_be32 (®->scratch0, a); +out_be32 (®->scratch1,BOOTCOUNT_MAGIC );This code here seems to be copied from the
enbw_cmcboard. The calimain board uses writel instead ofout_be32for the scratch registers (because I didn't understand why we should use big endian on a little endian machine). So your patch changes the byte order here for the calimain board and thus breaks our boot counter support.
I missed this difference. Thanks for spotting.
Quoted 1 line
What's the reason for using
out_be32here?
I assume historical reasons, as all this bootcounter code is originated from powerpc specific code. Heiko, is this correct?
Quoted 14 lines
drivers/bootcount/bootcount_davinci.c line 49
Quoted 11 lines
drivers/bootcount/bootcount_davinci.c new file +11
-0+} + +ulong bootcount_load (void ) +{ +struct davinci_rtc *reg = + (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR ; + +if (in_be32 (®->scratch1) !=BOOTCOUNT_MAGIC ) +return 0 ; +else +return in_be32 (®->scratch0);Same as above, the calimain board uses readl instead of
in_be32.
Quoted 2 lines
I replaced
out_be32by writel andin_be32by readl and tested it on the calimain board, it works fine :-)
I see. Too bad, now we have two Davince boards using nearly the same driver, one little endian and one big endian. If none of both boards can be changed, then we need to add an configuration switch to select the endianess.
Heiko? Any comments?
Thanks,
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