blob: a3162c97edd3d9a01a64645e91a1ba662c6bc537 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roesee4a95d12010-04-28 10:47:36 +02002/*
Stefan Roese0044c422012-08-16 17:55:41 +00003 * (C) Copyright 2010-2012
Stefan Roesee4a95d12010-04-28 10:47:36 +02004 * Stefan Roese, DENX Software Engineering, sr@denx.de.
Stefan Roesee4a95d12010-04-28 10:47:36 +02005 */
6
Stefan Roese0044c422012-08-16 17:55:41 +00007#include <bootcount.h>
8#include <linux/compiler.h>
Stefan Roesee4a95d12010-04-28 10:47:36 +02009
Stefan Roese0044c422012-08-16 17:55:41 +000010/* Now implement the generic default functions */
Stefan Roese0044c422012-08-16 17:55:41 +000011__weak void bootcount_store(ulong a)
Stefan Roesee4a95d12010-04-28 10:47:36 +020012{
13 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
14
15#if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
Stefan Roese0044c422012-08-16 17:55:41 +000016 raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
Stefan Roesee4a95d12010-04-28 10:47:36 +020017#else
Stefan Roese0044c422012-08-16 17:55:41 +000018 raw_bootcount_store(reg, a);
19 raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC);
Robert P. J. Day76765372015-12-22 07:15:14 -050020#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */
Stefano Babic1947c2d2018-02-22 12:30:41 +010021 flush_dcache_range(CONFIG_SYS_BOOTCOUNT_ADDR,
22 CONFIG_SYS_BOOTCOUNT_ADDR +
23 CONFIG_SYS_CACHELINE_SIZE);
Stefan Roesee4a95d12010-04-28 10:47:36 +020024}
25
Stefan Roese0044c422012-08-16 17:55:41 +000026__weak ulong bootcount_load(void)
Stefan Roesee4a95d12010-04-28 10:47:36 +020027{
28 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
29
30#if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
Stefan Roese0044c422012-08-16 17:55:41 +000031 u32 tmp = raw_bootcount_load(reg);
Michael Weiss59dde442010-05-20 16:09:35 +020032
33 if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
Stefan Roesee4a95d12010-04-28 10:47:36 +020034 return 0;
35 else
Michael Weiss59dde442010-05-20 16:09:35 +020036 return (tmp & 0x0000ffff);
Stefan Roesee4a95d12010-04-28 10:47:36 +020037#else
Stefan Roese0044c422012-08-16 17:55:41 +000038 if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC)
Stefan Roesee4a95d12010-04-28 10:47:36 +020039 return 0;
40 else
Stefan Roese0044c422012-08-16 17:55:41 +000041 return raw_bootcount_load(reg);
Robert P. J. Day76765372015-12-22 07:15:14 -050042#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */
Stefan Roesee4a95d12010-04-28 10:47:36 +020043}