diff options
author | Heiko Schocher <hs@denx.de> | 2014-01-25 07:27:13 +0100 |
---|---|---|
committer | Heiko Schocher <hs@denx.de> | 2014-02-20 06:46:56 +0100 |
commit | 9e50c406c8eede1105bd8ad1c1b74e0ef64af233 (patch) | |
tree | 6d4acd03b5304cfcacd3a5adab6ed492288bfa45 /drivers | |
parent | 16c550274c2590ea20d32de9480365048e271aad (diff) | |
download | u-boot-9e50c406c8eede1105bd8ad1c1b74e0ef64af233.zip u-boot-9e50c406c8eede1105bd8ad1c1b74e0ef64af233.tar.gz u-boot-9e50c406c8eede1105bd8ad1c1b74e0ef64af233.tar.bz2 |
i2c, bootcount: add support for bootcounter on i2c devices
add support for bootcounter on an i2c device. And add a
README for all bootcounter options.
Signed-off-by: Heiko Schocher <hs@denx.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/bootcount/Makefile | 1 | ||||
-rw-r--r-- | drivers/bootcount/bootcount_i2c.c | 44 |
2 files changed, 45 insertions, 0 deletions
diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile index bed6971..6f1c419 100644 --- a/drivers/bootcount/Makefile +++ b/drivers/bootcount/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_SOC_DA8XX) += bootcount_davinci.o obj-$(CONFIG_BOOTCOUNT_AM33XX) += bootcount_davinci.o obj-$(CONFIG_BOOTCOUNT_RAM) += bootcount_ram.o obj-$(CONFIG_BOOTCOUNT_ENV) += bootcount_env.o +obj-$(CONFIG_BOOTCOUNT_I2C) += bootcount_i2c.o diff --git a/drivers/bootcount/bootcount_i2c.c b/drivers/bootcount/bootcount_i2c.c new file mode 100644 index 0000000..e27b168 --- /dev/null +++ b/drivers/bootcount/bootcount_i2c.c @@ -0,0 +1,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; +} |