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