[U-Boot] [PATCH V3 6/6] board: ge: Store bootcount in EEPROM on PPD and Bx50v3
Fabien Lahoudere
fabien.lahoudere at collabora.com
Wed Oct 17 08:33:31 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: Fabien Lahoudere <fabien.lahoudere at collabora.com>
---
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 12410d9..14507b4 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 8426279..6a052e0 100644
--- a/configs/ge_bx50v3_defconfig
+++ b/configs/ge_bx50v3_defconfig
@@ -17,6 +17,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
@@ -36,11 +50,7 @@ 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_BOOTCOUNT_BOOTLIMIT=10
-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 2953e01..3470faa 100644
--- a/configs/mx53ppd_defconfig
+++ b/configs/mx53ppd_defconfig
@@ -19,6 +19,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_MISC_INIT_R=y
CONFIG_HUSH_PARSER=y
@@ -35,11 +50,7 @@ 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_BOOTCOUNT_BOOTLIMIT=10
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART="0:5"
-CONFIG_SYS_BOOTCOUNT_ADDR=0x7000A000
CONFIG_FSL_ESDHC=y
CONFIG_MII=y
CONFIG_RTC_S35392A=y
diff --git a/include/configs/ge_bx50v3.h b/include/configs/ge_bx50v3.h
index fad840b..7212e7c 100644
--- a/include/configs/ge_bx50v3.h
+++ b/include/configs/ge_bx50v3.h
@@ -114,9 +114,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 bbd4cd7..1ecf604 100644
--- a/include/configs/mx53ppd.h
+++ b/include/configs/mx53ppd.h
@@ -126,9 +126,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; " \
--
1.8.3.1
More information about the U-Boot
mailing list