1/* 2 * functions for handling bootcount support 3 * 4 * Copyright (c) 2010 Analog Devices Inc. 5 * 6 * Licensed under the 2-clause BSD. 7 */ 8 9/* This version uses one 32bit storage and combines the magic/count */ 10 11#include <common.h> 12 13/* We abuse the EVT0 MMR for bootcount storage by default */ 14#ifndef CONFIG_SYS_BOOTCOUNT_ADDR 15# define CONFIG_SYS_BOOTCOUNT_ADDR EVT0 16#endif 17 18#define MAGIC_MASK 0xffff0000 19#define COUNT_MASK 0x0000ffff 20 21void bootcount_store(ulong cnt) 22{ 23 ulong magic = (BOOTCOUNT_MAGIC & MAGIC_MASK) | (cnt & COUNT_MASK); 24 bfin_write32(CONFIG_SYS_BOOTCOUNT_ADDR, magic); 25} 26 27ulong bootcount_load(void) 28{ 29 ulong magic = bfin_read32(CONFIG_SYS_BOOTCOUNT_ADDR); 30 if ((magic & MAGIC_MASK) == (BOOTCOUNT_MAGIC & MAGIC_MASK)) 31 return magic & COUNT_MASK; 32 else 33 return 0; 34} 35