From patchwork Fri Jul 20 15:31:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 947074 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=collabora.co.uk Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41XFLZ5hgsz9s55 for ; Sat, 21 Jul 2018 01:34:46 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 82516C21EC9; Fri, 20 Jul 2018 15:33:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_PASS, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id B0D48C21F1D; Fri, 20 Jul 2018 15:32:06 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9F911C21F1C; Fri, 20 Jul 2018 15:31:40 +0000 (UTC) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lists.denx.de (Postfix) with ESMTPS id 00812C21EC8 for ; Fri, 20 Jul 2018 15:31:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 1283927E14E From: Sebastian Reichel To: Sebastian Reichel , u-boot@lists.denx.de Date: Fri, 20 Jul 2018 17:31:14 +0200 Message-Id: <20180720153114.15610-7-sebastian.reichel@collabora.co.uk> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180720153114.15610-1-sebastian.reichel@collabora.co.uk> References: <20180720153114.15610-1-sebastian.reichel@collabora.co.uk> Cc: Tom Rini Subject: [U-Boot] [PATCHv2 6/6] board: ge: Store bootcount in EEPROM on PPD and Bx50v3 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Denis Zalevskiy 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 Signed-off-by: Sebastian Reichel --- 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 #include #include #include @@ -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; " \