From 1e62529aef56586f162b1922f8cd196a4c154175 Mon Sep 17 00:00:00 2001 From: Tom Van Braeckel Date: Tue, 8 May 2012 15:02:44 +0200 Subject: [PATCH 1/3] Added bootcount limit and RFS switcher logic --- arch/arm/lib/bootcount.c | 58 ++++++++++++++++++++++++++++++++++++++++++ common/main.c | 4 +++ include/configs/am335x_evm.h | 43 +++++++++++++++++++++++++------ 3 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 arch/arm/lib/bootcount.c diff --git a/arch/arm/lib/bootcount.c b/arch/arm/lib/bootcount.c new file mode 100644 index 0000000..07a95a9 --- /dev/null +++ b/arch/arm/lib/bootcount.c @@ -0,0 +1,58 @@ +/* + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH + * Marius Groeger + * + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH + * Alex Zuepke + * + * (C) Copyleft 2012 + * FifthPlay + * Tom Van Braeckel + * + * 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 + */ + +/* + * CPU specific code + */ + +#include +#include + +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]; +} + + diff --git a/common/main.c b/common/main.c index 3324d9d..7cd1c1b 100644 --- a/common/main.c +++ b/common/main.c @@ -55,6 +55,10 @@ void show_boot_progress (int val) __attribute__((weak, alias("__show_boot_progre int update_tftp (ulong addr); #endif /* CONFIG_UPDATE_TFTP */ +#ifdef CONFIG_BOOTCOUNT_LIMIT +#include <../arch/arm/lib/bootcount.c> +#endif + #define MAX_DELAY_STOP_STR 32 #undef DEBUG_PARSER diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h index dd7e1ba..92a90fd 100755 --- a/include/configs/am335x_evm.h +++ b/include/configs/am335x_evm.h @@ -18,6 +18,10 @@ #define CONFIG_SYS_NO_FLASH #define CONFIG_NAND_ENV +/* bootcounter */ +#define CONFIG_BOOTCOUNT_LIMIT +#define CONFIG_SYS_BOOTCOUNT_ADDR 0x4030B800 - 4 /* public stack in SRAM starts at 0x4030B800 so we use one right before it */ + #include /* get chip and board defs */ #include