[U-Boot] [PATCH 4/6] bootcount: Configure length limit for I2C bootcount
Sebastian Reichel
sebastian.reichel at collabora.co.uk
Tue Jun 26 17:43:02 UTC 2018
From: Denis Zalevskiy <denis.zalevskiy at ge.com>
Bootcount driver should verify size against the maximum available space. New
configuration parameter adds this capability and keeps backward compatibility by
providing default value.
Signed-off-by: Denis Zalevskiy <denis.zalevskiy at ge.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel at collabora.co.uk>
---
drivers/bootcount/Kconfig | 6 ++++++
drivers/bootcount/bootcount_i2c.c | 10 ++++++----
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig
index a5349a62fdc3..e7f2e1ef65e0 100644
--- a/drivers/bootcount/Kconfig
+++ b/drivers/bootcount/Kconfig
@@ -132,4 +132,10 @@ config SYS_BOOTCOUNT_I2C_ADDR
depends on BOOTCOUNT_I2C
help
I2C address of the device used to store bootcounter
+
+config BOOTCOUNT_I2C_LEN
+ int "Maximum length of bootcounter in bytes"
+ default 2
+ depends on BOOTCOUNT_I2C
+
endif
diff --git a/drivers/bootcount/bootcount_i2c.c b/drivers/bootcount/bootcount_i2c.c
index 79d82ad451f3..a8bb611eea9e 100644
--- a/drivers/bootcount/bootcount_i2c.c
+++ b/drivers/bootcount/bootcount_i2c.c
@@ -54,14 +54,15 @@ void bootcount_store(ulong a)
if (prev_i2c_bus < 0)
return;
- unsigned char buf[3];
+ unsigned char buf[2];
int ret;
+ BUILD_BUG_ON(CONFIG_BOOTCOUNT_I2C_LEN < sizeof(buf));
buf[0] = BC_MAGIC;
buf[1] = (a & 0xff);
ret = i2c_write(CONFIG_SYS_BOOTCOUNT_I2C_ADDR,
CONFIG_SYS_BOOTCOUNT_ADDR,
- CONFIG_BOOTCOUNT_ALEN, buf, 2);
+ CONFIG_BOOTCOUNT_ALEN, buf, sizeof(buf));
if (ret != 0)
puts("Error writing bootcount\n");
@@ -77,12 +78,13 @@ ulong bootcount_load(void)
if (prev_i2c_bus < 0)
return count;
- unsigned char buf[3];
+ unsigned char buf[2];
int ret;
+ BUILD_BUG_ON(CONFIG_BOOTCOUNT_I2C_LEN < sizeof(buf));
ret = i2c_read(CONFIG_SYS_BOOTCOUNT_I2C_ADDR,
CONFIG_SYS_BOOTCOUNT_ADDR,
- CONFIG_BOOTCOUNT_ALEN, buf, 2);
+ CONFIG_BOOTCOUNT_ALEN, buf, sizeof(buf));
if (ret != 0) {
puts("Error loading bootcount\n");
goto out;
--
2.18.0
More information about the U-Boot
mailing list