blob: 67554fa4a9b80ce9c3486d86c92183ea552574db [file] [log] [blame]
Stefan Roesee4a95d12010-04-28 10:47:36 +02001/*
Stefan Roese0044c422012-08-16 17:55:41 +00002 * (C) Copyright 2010-2012
Stefan Roesee4a95d12010-04-28 10:47:36 +02003 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Roesee4a95d12010-04-28 10:47:36 +02006 */
7
Stefan Roese0044c422012-08-16 17:55:41 +00008#include <bootcount.h>
9#include <linux/compiler.h>
Stefan Roesee4a95d12010-04-28 10:47:36 +020010
Stefan Roese0044c422012-08-16 17:55:41 +000011/* Now implement the generic default functions */
Stefan Roese0044c422012-08-16 17:55:41 +000012__weak void bootcount_store(ulong a)
Stefan Roesee4a95d12010-04-28 10:47:36 +020013{
14 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
15
16#if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
Stefan Roese0044c422012-08-16 17:55:41 +000017 raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
Stefan Roesee4a95d12010-04-28 10:47:36 +020018#else
Stefan Roese0044c422012-08-16 17:55:41 +000019 raw_bootcount_store(reg, a);
20 raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC);
Robert P. J. Day76765372015-12-22 07:15:14 -050021#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */
Stefan Roesee4a95d12010-04-28 10:47:36 +020022}
23
Stefan Roese0044c422012-08-16 17:55:41 +000024__weak ulong bootcount_load(void)
Stefan Roesee4a95d12010-04-28 10:47:36 +020025{
26 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
27
28#if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
Stefan Roese0044c422012-08-16 17:55:41 +000029 u32 tmp = raw_bootcount_load(reg);
Michael Weiss59dde442010-05-20 16:09:35 +020030
31 if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
Stefan Roesee4a95d12010-04-28 10:47:36 +020032 return 0;
33 else
Michael Weiss59dde442010-05-20 16:09:35 +020034 return (tmp & 0x0000ffff);
Stefan Roesee4a95d12010-04-28 10:47:36 +020035#else
Stefan Roese0044c422012-08-16 17:55:41 +000036 if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC)
Stefan Roesee4a95d12010-04-28 10:47:36 +020037 return 0;
38 else
Stefan Roese0044c422012-08-16 17:55:41 +000039 return raw_bootcount_load(reg);
Robert P. J. Day76765372015-12-22 07:15:14 -050040#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */
Stefan Roesee4a95d12010-04-28 10:47:36 +020041}