[U-Boot] [PATCHv2 6/6] board: ge: Store bootcount in EEPROM on PPD and Bx50v3
Sebastian Reichel
sebastian.reichel at collabora.co.uk
Fri Jul 20 15:31:14 UTC 2018
From: Denis Zalevskiy <denis.zalevskiy at ge.com>
u-boot's ext3/4 write/modify functionality sometimes corrupts filesystem in the
case if it requires recovery (e.g. after unexpected shutdown) and we want to
avoid the only filesystem modification we have - bootcounter writing. So,
bootcounter will be stored in the EEPROM where VPD is stored.
Signed-off-by: Denis Zalevskiy <denis.zalevskiy at ge.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel at collabora.co.uk>
---
board/ge/common/vpd_reader.c | 20 ++++++++++++++++++++
configs/ge_bx50v3_defconfig | 18 ++++++++++++++----
configs/mx53ppd_defconfig | 19 +++++++++++++++----
include/configs/ge_bx50v3.h | 6 +++---
include/configs/mx53ppd.h | 6 +++---
5 files changed, 55 insertions(+), 14 deletions(-)
diff --git a/board/ge/common/vpd_reader.c b/board/ge/common/vpd_reader.c
index 12410d9b715b..14507b45e485 100644
--- a/board/ge/common/vpd_reader.c
+++ b/board/ge/common/vpd_reader.c
@@ -5,6 +5,7 @@
#include "vpd_reader.h"
+#include <linux/bug.h>
#include <i2c.h>
#include <linux/bch.h>
#include <stdlib.h>
@@ -200,7 +201,26 @@ int read_vpd(struct vpd_cache *cache,
int (*process_block)(struct vpd_cache *, u8 id, u8 version,
u8 type, size_t size, u8 const *data))
{
+#if defined(CONFIG_BOOTCOUNT_I2C) && \
+ (CONFIG_SYS_BOOTCOUNT_I2C_BUS == CONFIG_SYS_VPD_EEPROM_I2C_BUS) && \
+ ((CONFIG_SYS_BOOTCOUNT_I2C_ADDR & 0xf0) == CONFIG_SYS_VPD_EEPROM_I2C_ADDR)
+ /*
+ * bootcount is expected to reside at the end of EEPROM
+ *
+ * check is hard-wired to the logic of the 24C08 EEPROM 256-bytes
+ * page-wise (4 pages) i2c_address/bootcount_address structure combined
+ * with raw I2C access, so the I2C address and offset are combined into:
+ *
+ * i2c_addr = (device_i2c_addr | page),
+ * offset = (offset - (page * 256)))
+ */
+ BUILD_BUG_ON((CONFIG_SYS_BOOTCOUNT_I2C_ADDR & 0x0f) * 256 +
+ CONFIG_SYS_BOOTCOUNT_ADDR + CONFIG_BOOTCOUNT_I2C_LEN !=
+ CONFIG_SYS_VPD_EEPROM_SIZE);
+ static const size_t size = CONFIG_SYS_BOOTCOUNT_ADDR;
+#else
static const size_t size = CONFIG_SYS_VPD_EEPROM_SIZE;
+#endif
int res;
u8 *data;
diff --git a/configs/ge_bx50v3_defconfig b/configs/ge_bx50v3_defconfig
index 0c2d033ad8e1..952e87d62d84 100644
--- a/configs/ge_bx50v3_defconfig
+++ b/configs/ge_bx50v3_defconfig
@@ -16,6 +16,20 @@ CONFIG_SYS_VPD_EEPROM_I2C_ADDR=0x50
CONFIG_SYS_VPD_EEPROM_I2C_ADDR_LEN=1
CONFIG_SYS_VPD_EEPROM_SIZE=1024
+CONFIG_BOOTCOUNT_I2C=y
+CONFIG_BOOTCOUNT_LIMIT=y
+CONFIG_SYS_BOOTCOUNT_I2C_BUS=4
+# bootcount is stored in VPD EEPROM
+# we are using generic driver instead of EEPROM one (while should use it)
+# at the end of VPD EEPROM: (SYS_VPD_EEPROM_SIZE - CONFIG_BOOTCOUNT_I2C_LEN)
+# so, the address is 0x3FE:
+# ("VPD EEPROM chip address" | "3rd 256-byte page"):
+CONFIG_SYS_BOOTCOUNT_I2C_ADDR=0x53
+# (+ "offset in the page"):
+CONFIG_SYS_BOOTCOUNT_ADDR=0xfe
+CONFIG_BOOTCOUNT_I2C_LEN=2
+CONFIG_BOOTCOUNT_ALEN=1
+
CONFIG_SUPPORT_RAW_INITRD=y
CONFIG_BOARD_EARLY_INIT_F=y
CONFIG_LAST_STAGE_INIT=y
@@ -35,10 +49,6 @@ CONFIG_CMD_EXT4_WRITE=y
CONFIG_CMD_FS_GENERIC=y
CONFIG_DOS_PARTITION=y
CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_BOOTCOUNT_LIMIT=y
-CONFIG_BOOTCOUNT_EXT=y
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART="1:5"
-CONFIG_SYS_BOOTCOUNT_ADDR=0x7000A000
CONFIG_FSL_ESDHC=y
CONFIG_SPI_FLASH=y
CONFIG_SPI_FLASH_STMICRO=y
diff --git a/configs/mx53ppd_defconfig b/configs/mx53ppd_defconfig
index 4a7e8eee0df1..43672d88e202 100644
--- a/configs/mx53ppd_defconfig
+++ b/configs/mx53ppd_defconfig
@@ -18,6 +18,21 @@ CONFIG_SYS_VPD_EEPROM_I2C_ADDR=0x50
CONFIG_SYS_VPD_EEPROM_I2C_ADDR_LEN=1
CONFIG_SYS_VPD_EEPROM_SIZE=1024
+CONFIG_BOOTCOUNT_LIMIT=y
+CONFIG_BOOTCOUNT_I2C=y
+# using bus where monitor's EEPROM is connected to
+CONFIG_SYS_BOOTCOUNT_I2C_BUS=2
+# bootcount is stored in Monitor's VPD EEPROM
+# we are using generic driver instead of EEPROM one (while should use it)
+# at the end of VPD EEPROM: (SYS_VPD_EEPROM_SIZE - CONFIG_BOOTCOUNT_I2C_LEN)
+# so, the address is 0x3FE:
+# ("VPD EEPROM chip address" | "3rd 256-byte page"):
+CONFIG_SYS_BOOTCOUNT_I2C_ADDR=0x53
+# (+ "offset in the page"):
+CONFIG_SYS_BOOTCOUNT_ADDR=0xfe
+CONFIG_BOOTCOUNT_I2C_LEN=2
+CONFIG_BOOTCOUNT_ALEN=1
+
CONFIG_SUPPORT_RAW_INITRD=y
CONFIG_HUSH_PARSER=y
CONFIG_CMD_BOOTZ=y
@@ -33,10 +48,6 @@ CONFIG_CMD_EXT4_WRITE=y
CONFIG_CMD_FAT=y
CONFIG_CMD_FS_GENERIC=y
CONFIG_ENV_IS_IN_MMC=y
-CONFIG_BOOTCOUNT_LIMIT=y
-CONFIG_BOOTCOUNT_EXT=y
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART="0:5"
-CONFIG_SYS_BOOTCOUNT_ADDR=0x7000A000
CONFIG_FSL_ESDHC=y
CONFIG_NETDEVICES=y
CONFIG_RTC_S35392A=y
diff --git a/include/configs/ge_bx50v3.h b/include/configs/ge_bx50v3.h
index fef41a8a1887..a6e31f7e91a9 100644
--- a/include/configs/ge_bx50v3.h
+++ b/include/configs/ge_bx50v3.h
@@ -116,9 +116,9 @@
"setenv stdout vga; " \
"echo \"\n\n\n\n \" $msg; " \
"setenv stdout serial; " \
- "mw.b 0x7000A000 0xbc; " \
- "mw.b 0x7000A001 0x00; " \
- "ext4write ${dev} ${devnum}:5 0x7000A000 /boot/failures 2\0" \
+ "i2c dev 4; " \
+ "i2c mw.b 53 fe bc; " \
+ "i2c mw.b 53 ff 00; \0" \
"altbootcmd=" \
"run doquiet; " \
"setenv partnum 1; run hasfirstboot || setenv partnum 2; " \
diff --git a/include/configs/mx53ppd.h b/include/configs/mx53ppd.h
index e08e83151fbf..0e353e270f91 100644
--- a/include/configs/mx53ppd.h
+++ b/include/configs/mx53ppd.h
@@ -129,9 +129,9 @@
"setenv stdout vga; " \
"echo \"\n\n\n\n \" $msg; " \
"setenv stdout serial; " \
- "mw.b 0x7000A000 0xbc; " \
- "mw.b 0x7000A001 0x00; " \
- "ext4write ${dev} ${devnum}:5 0x7000A000 /boot/failures 2\0" \
+ "i2c dev 2; " \
+ "i2c mw.b 53 fe bc; " \
+ "i2c mw.b 53 ff 00; \0" \
"altbootcmd=" \
"run doquiet; " \
"setenv partnum 1; run hasfirstboot || setenv partnum 2; " \
--
2.18.0
More information about the U-Boot
mailing list