[U-Boot] [PATCH v1 0/5] Provide SPL support for bootcount (in the case of using falcon boot mode)

This patch series provides support for controlling bootcount limits in SPL. It also enables this feature on display5 board to present usage patterns.
"Green" travis CI build: https://travis-ci.org/lmajewski/u-boot-dfu
This patch has been applied on top of u-boot/master: SHA1: 1811a928c6c7604d6d05a84b4d552a7c31b4994e
This patch series shall be applied on top of: [U-Boot,1/2] Convert CONFIG_BOOTCOUNT_LIMIT to Kconfig http://patchwork.ozlabs.org/patch/871585/
[U-Boot,2/2] Convert CONFIG_SYS_BOOTCOUNT_SINGLEWORD to Kconfig http://patchwork.ozlabs.org/patch/871586/
Lukasz Majewski (5): bootcount: config: Make the SYS_BOOTCOUNT_ADDR available also for non EXT setups bootcount: Add function wrappers to handle bootcount increment and error checking spl: bootcount: Enable bootcount support in SPL config: display5: Enable boot count feature in the display5 board arm: display5: Extend SPL to support bootcount checking
board/liebherr/display5/spl.c | 4 +++- common/spl/Kconfig | 9 +++++++++ configs/display5_defconfig | 5 +++++ drivers/Makefile | 1 + drivers/bootcount/Kconfig | 13 ++++++------- include/bootcount.h | 25 +++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 8 deletions(-)

This commit gives the opportunity to reuse the CONFIG_SYS_BOOTCOUNT_ADDR Kconfig entry also for boards, which do not use EXT as a storage for bootcount (i.e. on flash ones).
Signed-off-by: Lukasz Majewski lukma@denx.de
---
drivers/bootcount/Kconfig | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig index d82289f57b..1254bb51ca 100644 --- a/drivers/bootcount/Kconfig +++ b/drivers/bootcount/Kconfig @@ -31,6 +31,12 @@ config BOOTCOUNT_EXT Add support for maintaining boot count in a file on an EXT filesystem.
+config SYS_BOOTCOUNT_ADDR + hex "RAM address used for reading and writing the boot counter" + default 0x7000A000 + help + Set the address used for reading and writing the boot counter. + if BOOTCOUNT_EXT
config SYS_BOOTCOUNT_EXT_INTERFACE @@ -56,13 +62,6 @@ config SYS_BOOTCOUNT_EXT_NAME help Set the filename and path of the file used to store the boot counter.
-config SYS_BOOTCOUNT_ADDR - hex "RAM address used for reading and writing the boot counter" - default 0x7000A000 - depends on BOOTCOUNT_EXT - help - Set the address used for reading and writing the boot counter. - endif
endif

On 10 Feb 2018, at 12.20, Lukasz Majewski lukma@denx.de wrote:
This commit gives the opportunity to reuse the CONFIG_SYS_BOOTCOUNT_ADDR Kconfig entry also for boards, which do not use EXT as a storage for bootcount (i.e. on flash ones).
Signed-off-by: Lukasz Majewski lukma@denx.de
Reviewed-by: Ian Ray ian.ray@ge.com
drivers/bootcount/Kconfig | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig index d82289f57b..1254bb51ca 100644 --- a/drivers/bootcount/Kconfig +++ b/drivers/bootcount/Kconfig @@ -31,6 +31,12 @@ config BOOTCOUNT_EXT Add support for maintaining boot count in a file on an EXT filesystem.
+config SYS_BOOTCOUNT_ADDR
- hex "RAM address used for reading and writing the boot counter"
- default 0x7000A000
- help
Set the address used for reading and writing the boot counter.
if BOOTCOUNT_EXT
config SYS_BOOTCOUNT_EXT_INTERFACE @@ -56,13 +62,6 @@ config SYS_BOOTCOUNT_EXT_NAME help Set the filename and path of the file used to store the boot counter.
-config SYS_BOOTCOUNT_ADDR
- hex "RAM address used for reading and writing the boot counter"
- default 0x7000A000
- depends on BOOTCOUNT_EXT
- help
Set the address used for reading and writing the boot counter.
endif
endif
2.11.0

Those two functions can be used in either SPL or U-boot proper to provide easy bootcount management.
Signed-off-by: Lukasz Majewski lukma@denx.de ---
include/bootcount.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
diff --git a/include/bootcount.h b/include/bootcount.h index 06fb4d3578..534875a5a5 100644 --- a/include/bootcount.h +++ b/include/bootcount.h @@ -38,3 +38,28 @@ static inline u32 raw_bootcount_load(volatile u32 *addr) return in_be32(addr); } #endif + +#ifdef CONFIG_SPL_BOOTCOUNT_LIMIT +static inline bool bootcount_error(void) +{ + unsigned long bootcount = bootcount_load(); + unsigned long bootlimit = env_get_ulong("bootlimit", 10, 0); + + if (bootlimit && (bootcount >= bootlimit)) { + printf("Warning: Bootlimit (%lu) exceeded.\n", bootcount); + return true; + } + + return false; +} + +static inline void bootcount_inc(void) +{ + unsigned long bootcount = bootcount_load(); + + bootcount_store(++bootcount); +} +#else +static inline bool bootcount_error(void) { return false; } +static inline void bootcount_inc(void) {} +#endif /* CONFIG_SPL_BOOTCOUNT_LIMIT */

New, SPL related config option - CONFIG_SPL_BOOTCOUNT_LIMIT has been added to allow drivers/bootcount code re-usage in SPL.
This code is necessary to use and setup bootcount in SPL in the case of falcon boot mode.
Signed-off-by: Lukasz Majewski lukma@denx.de ---
common/spl/Kconfig | 9 +++++++++ drivers/Makefile | 1 + 2 files changed, 10 insertions(+)
diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 65b3aff244..37354e262e 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -46,6 +46,15 @@ config SPL_BOOTROM_SUPPORT BOOT_DEVICE_BOOTROM (or fall-through to the next boot device in the boot device list, if not implemented for a given board)
+config SPL_BOOTCOUNT_LIMIT + bool "Support bootcount in SPL" + depends on SPL_ENV_SUPPORT + help + On some boards, which use 'falcon' mode, it is necessary to check + and increment the number of boot attempts. Such boards do not + use proper U-Boot for normal boot flow and hence needs those + adjustments to be done in the SPL. + config SPL_RAW_IMAGE_SUPPORT bool "Support SPL loading and booting of RAW images" default n if (ARCH_MX6 && (SPL_MMC_SUPPORT || SPL_SATA_SUPPORT)) diff --git a/drivers/Makefile b/drivers/Makefile index e6062a5683..2a988360a0 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -20,6 +20,7 @@ obj-$(CONFIG_$(SPL_TPL_)TIMER) += timer/ ifndef CONFIG_TPL_BUILD ifdef CONFIG_SPL_BUILD
+obj-$(CONFIG_SPL_BOOTCOUNT_LIMIT) += bootcount/ obj-$(CONFIG_SPL_CPU_SUPPORT) += cpu/ obj-$(CONFIG_SPL_CRYPTO_SUPPORT) += crypto/ obj-$(CONFIG_SPL_GPIO_SUPPORT) += gpio/

The boot count is enabled in both SPL and u-boot proper.
Signed-off-by: Lukasz Majewski lukma@denx.de ---
configs/display5_defconfig | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/configs/display5_defconfig b/configs/display5_defconfig index 1502b77fea..97c3b6a60c 100644 --- a/configs/display5_defconfig +++ b/configs/display5_defconfig @@ -14,6 +14,7 @@ CONFIG_SPL_LOAD_FIT=y CONFIG_OF_BOARD_SETUP=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/mach-imx/spl_sd.cfg,MX6Q" CONFIG_SPL=y +CONFIG_SPL_BOOTCOUNT_LIMIT=y # CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR is not set CONFIG_SPL_DMA_SUPPORT=y CONFIG_SPL_ENV_SUPPORT=y @@ -49,6 +50,10 @@ CONFIG_EFI_PARTITION=y # CONFIG_SPL_EFI_PARTITION is not set CONFIG_OF_CONTROL=y CONFIG_ENV_IS_IN_SPI_FLASH=y +CONFIG_BOOTCOUNT=y +CONFIG_BOOTCOUNT_LIMIT=y +CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y +CONFIG_SYS_BOOTCOUNT_ADDR=0x020CC068 CONFIG_SPI_FLASH=y CONFIG_SPI_FLASH_BAR=y CONFIG_SPI_FLASH_SPANSION=y

This patch is necessary for providing basic bootcount checking in the case of using "falcon" boot mode.
It forces u-boot proper boot, when we exceed the number of errors.
Signed-off-by: Lukasz Majewski lukma@denx.de ---
board/liebherr/display5/spl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/board/liebherr/display5/spl.c b/board/liebherr/display5/spl.c index 0a36e656c0..e21b4bee75 100644 --- a/board/liebherr/display5/spl.c +++ b/board/liebherr/display5/spl.c @@ -20,6 +20,7 @@ #include <environment.h> #include <fsl_esdhc.h> #include <netdev.h> +#include <bootcount.h> #include "common.h"
DECLARE_GLOBAL_DATA_PTR; @@ -214,7 +215,7 @@ void board_boot_order(u32 *spl_boot_list) env_load();
s = env_get("BOOT_FROM"); - if (s && strcmp(s, "ACTIVE") == 0) { + if (s && !bootcount_error() && strcmp(s, "ACTIVE") == 0) { spl_boot_list[0] = BOOT_DEVICE_MMC1; spl_boot_list[1] = spl_boot_device(); } @@ -242,6 +243,7 @@ int spl_start_uboot(void) if (env_get_yesno("boot_os") != 1) return 1; #endif + bootcount_inc(); return 0; } #endif
participants (2)
-
Lukasz Majewski
-
Ray, Ian (GE Healthcare)