]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
i2c, bootcount: add support for bootcounter on i2c devices
authorHeiko Schocher <hs@denx.de>
Sat, 25 Jan 2014 06:27:13 +0000 (07:27 +0100)
committerHeiko Schocher <hs@denx.de>
Thu, 20 Feb 2014 05:46:56 +0000 (06:46 +0100)
add support for bootcounter on an i2c device. And add a
README for all bootcounter options.

Signed-off-by: Heiko Schocher <hs@denx.de>
README
drivers/bootcount/Makefile
drivers/bootcount/bootcount_i2c.c [new file with mode: 0644]

diff --git a/README b/README
index bfd89b0bfb091259f091db5ff68f3f8f0b2be63f..f14364b5a56e2cb1ddb8510e171540fce5557b64 100644 (file)
--- a/README
+++ b/README
@@ -2855,6 +2855,26 @@ CBFS (Coreboot Filesystem) support
                The signing part is build into mkimage regardless of this
                option.
 
+- bootcount support:
+               CONFIG_BOOTCOUNT_LIMIT
+
+               This enables the bootcounter support, see:
+               http://www.denx.de/wiki/DULG/UBootBootCountLimit
+
+               CONFIG_AT91SAM9XE
+               enable special bootcounter support on at91sam9xe based boards.
+               CONFIG_BLACKFIN
+               enable special bootcounter support on blackfin based boards.
+               CONFIG_SOC_DA8XX
+               enable special bootcounter support on da850 based boards.
+               CONFIG_BOOTCOUNT_RAM
+               enable support for the bootcounter in RAM
+               CONFIG_BOOTCOUNT_I2C
+               enable support for the bootcounter on an i2c (like RTC) device.
+                       CONFIG_SYS_I2C_RTC_ADDR = i2c chip address
+                       CONFIG_SYS_BOOTCOUNT_ADDR = i2c addr which is used for
+                                                   the bootcounter.
+                       CONFIG_BOOTCOUNT_ALEN = address len
 
 - Show boot progress:
                CONFIG_SHOW_BOOT_PROGRESS
index bed6971aa55680dbea031f4ed60f3c453523687b..6f1c419c7a708e9976aa7cdc49dff6dffddf763d 100644 (file)
@@ -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 (file)
index 0000000..e27b168
--- /dev/null
@@ -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;
+}