Skip to contentSkip to conversation

Provide SPL support for bootcount (in the case of using falcon boot mode)

PATCH In review Lukasz Majewski 2 participants 7 messages Feb 10, 2018 – Feb 12, 2018

lore
Share & tools
lore
#0 lore raw

cover 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(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/5 bootcount: config: Make the SYS_BOOTCOUNT_ADDR available also for non EXT setups

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).

---

 drivers/bootcount/Kconfig | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/bootcount/Kconfig +6 -7
index d82289f57b..1254bb51ca 100644
@@ -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
Signature · 1 line
2.11.0
Reviewed-by Ian Ray on v1 1/5
#2 lore raw

[U-Boot] EXT: [PATCH v1 1/5] bootcount: config: Make the SYS_BOOTCOUNT_ADDR available also for non EXT setups

Quoted 9 lines · Lukasz Majewski

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).

Quoted 39 lines

---

drivers/bootcount/Kconfig | 13 ++++++-------

1 file changed, 6 insertions(+), 7 deletions(-)
drivers/bootcount/Kconfig +6 -0
index d82289f57b..1254bb51ca 100644
@@ -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

drivers/bootcount/Kconfig +0 -7
@@ -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

Signature · 1 line
2.11.0
#3 lore raw

PATCH 2/5 bootcount: Add function wrappers to handle bootcount increment and error checking

In reply to Lukasz Majewski

Those two functions can be used in either SPL or U-boot proper to provide easy bootcount management.

---

 include/bootcount.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
include/bootcount.h +25 -0
index 06fb4d3578..534875a5a5 100644
@@ -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 */
Signature · 1 line
2.11.0
#4 lore raw

PATCH 3/5 spl: bootcount: Enable bootcount support in SPL

In reply to Lukasz Majewski

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.

---

 common/spl/Kconfig | 9 +++++++++
 drivers/Makefile   | 1 +
 2 files changed, 10 insertions(+)
common/spl/Kconfig +9 -0
index 65b3aff244..37354e262e 100644
@@ -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))
drivers/Makefile +1 -0
index e6062a5683..2a988360a0 100644
@@ -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/
Signature · 1 line
2.11.0
#5 lore raw

PATCH 4/5 config: display5: Enable boot count feature in the display5 board

In reply to Lukasz Majewski

The boot count is enabled in both SPL and u-boot proper.

---

 configs/display5_defconfig | 5 +++++
 1 file changed, 5 insertions(+)
configs/display5_defconfig +5 -0
index 1502b77fea..97c3b6a60c 100644
@@ -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
Signature · 1 line
2.11.0
#6 lore raw

PATCH 5/5 arm: display5: Extend SPL to support bootcount checking

In reply to Lukasz Majewski

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.

---

 board/liebherr/display5/spl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
board/liebherr/display5/spl.c +3 -1
index 0a36e656c0..e21b4bee75 100644
@@ -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
Signature · 1 line
2.11.0