1 /* 2 * (C) Copyright 2010-2012 3 * Stefan Roese, DENX Software Engineering, sr@denx.de. 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <bootcount.h> 9 #include <linux/compiler.h> 10 11 /* Now implement the generic default functions */ 12 __weak void bootcount_store(ulong a) 13 { 14 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; 15 16 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) 17 raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a); 18 #else 19 raw_bootcount_store(reg, a); 20 raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC); 21 #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ 22 } 23 24 __weak ulong bootcount_load(void) 25 { 26 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; 27 28 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) 29 u32 tmp = raw_bootcount_load(reg); 30 31 if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000)) 32 return 0; 33 else 34 return (tmp & 0x0000ffff); 35 #else 36 if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC) 37 return 0; 38 else 39 return raw_bootcount_load(reg); 40 #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */ 41 } 42