10044c42eSStefan Roese /* 20044c42eSStefan Roese * (C) Copyright 2010-2012 30044c42eSStefan Roese * Stefan Roese, DENX Software Engineering, sr@denx.de. 40044c42eSStefan Roese * 51a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 60044c42eSStefan Roese */ 70044c42eSStefan Roese 80044c42eSStefan Roese #include <bootcount.h> 90044c42eSStefan Roese #include <linux/compiler.h> 100044c42eSStefan Roese 110044c42eSStefan Roese /* 120044c42eSStefan Roese * Only override CONFIG_SYS_BOOTCOUNT_ADDR if not already defined. This 130044c42eSStefan Roese * way, some boards can define it directly in their config header. 140044c42eSStefan Roese */ 150044c42eSStefan Roese #if !defined(CONFIG_SYS_BOOTCOUNT_ADDR) 160044c42eSStefan Roese 170044c42eSStefan Roese #if defined(CONFIG_QE) 1838d67a4eSZhao Qiang #include <linux/immap_qe.h> 190044c42eSStefan Roese #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + 0x110000 + \ 200044c42eSStefan Roese QE_MURAM_SIZE - 2 * sizeof(u32)) 21*76765375SRobert P. J. Day #endif /* defined(CONFIG_QE) */ 220044c42eSStefan Roese 230044c42eSStefan Roese #endif /* !defined(CONFIG_SYS_BOOTCOUNT_ADDR) */ 240044c42eSStefan Roese 250044c42eSStefan Roese /* Now implement the generic default functions */ 260044c42eSStefan Roese #if defined(CONFIG_SYS_BOOTCOUNT_ADDR) bootcount_store(ulong a)270044c42eSStefan Roese__weak void bootcount_store(ulong a) 280044c42eSStefan Roese { 290044c42eSStefan Roese void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; 300044c42eSStefan Roese 310044c42eSStefan Roese #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) 320044c42eSStefan Roese raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a); 330044c42eSStefan Roese #else 340044c42eSStefan Roese raw_bootcount_store(reg, a); 350044c42eSStefan Roese raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC); 36*76765375SRobert P. J. Day #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ 370044c42eSStefan Roese } 380044c42eSStefan Roese bootcount_load(void)390044c42eSStefan Roese__weak ulong bootcount_load(void) 400044c42eSStefan Roese { 410044c42eSStefan Roese void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; 420044c42eSStefan Roese 430044c42eSStefan Roese #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) 440044c42eSStefan Roese u32 tmp = raw_bootcount_load(reg); 450044c42eSStefan Roese 460044c42eSStefan Roese if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000)) 470044c42eSStefan Roese return 0; 480044c42eSStefan Roese else 490044c42eSStefan Roese return (tmp & 0x0000ffff); 500044c42eSStefan Roese #else 510044c42eSStefan Roese if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC) 520044c42eSStefan Roese return 0; 530044c42eSStefan Roese else 540044c42eSStefan Roese return raw_bootcount_load(reg); 55*76765375SRobert P. J. Day #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */ 560044c42eSStefan Roese } 57*76765375SRobert P. J. Day #endif /* defined(CONFIG_SYS_BOOTCOUNT_ADDR) */ 58