File: bootcount_i2c.c

package info (click to toggle)
u-boot 2016.11%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 104,408 kB
  • ctags: 428,706
  • sloc: ansic: 1,260,674; asm: 33,807; python: 10,106; perl: 8,014; makefile: 7,111; sh: 1,975; cpp: 1,829; yacc: 604; lex: 363; tcl: 28; sed: 24; awk: 6
file content (44 lines) | stat: -rw-r--r-- 807 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * (C) Copyright 2013
 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <bootcount.h>
#include <linux/compiler.h>
#include <i2c.h>

#define BC_MAGIC	0xbc

void bootcount_store(ulong a)
{
	unsigned char buf[3];
	int ret;

	buf[0] = BC_MAGIC;
	buf[1] = (a & 0xff);
	ret = i2c_write(CONFIG_SYS_I2C_RTC_ADDR, CONFIG_SYS_BOOTCOUNT_ADDR,
		  CONFIG_BOOTCOUNT_ALEN, buf, 2);
	if (ret != 0)
		puts("Error writing bootcount\n");
}

ulong bootcount_load(void)
{
	unsigned char buf[3];
	int ret;

	ret = i2c_read(CONFIG_SYS_I2C_RTC_ADDR, CONFIG_SYS_BOOTCOUNT_ADDR,
		       CONFIG_BOOTCOUNT_ALEN, buf, 2);
	if (ret != 0) {
		puts("Error loading bootcount\n");
		return 0;
	}
	if (buf[0] == BC_MAGIC)
		return buf[1];

	bootcount_store(0);

	return 0;
}