[U-Boot] [PATCH] spl: Add bootcount/bootlimit support
Stefan Roese
sr at denx.de
Mon Sep 30 08:39:05 CEST 2013
This patch adds bootcount/bootlimit support to SPL. Right now with
SPL-NOR support only. But it should be easy to ad this feature to
other SPL implementations as well.
When the bootcounter exceeds the "bootlimit" environment variable
SPL will boot into the full-blown U-Boot to handle the bootcmd switch
via the altbootcmd variable.
Signed-off-by: Stefan Roese <sr at denx.de>
---
README | 3 +++
common/main.c | 7 +++++++
common/spl/spl.c | 23 +++++++++++++++++++++++
common/spl/spl_nor.c | 7 ++++++-
include/spl.h | 6 ++++++
spl/Makefile | 1 +
6 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/README b/README
index bcfffc3..6a4e56b 100644
--- a/README
+++ b/README
@@ -2998,6 +2998,9 @@ FIT uImage format:
parameters from when MMC is being used in raw mode
(for falcon mode)
+ CONFIG_SPL_BOOTCOUNT_SUPPORT
+ Support for drivers/bootcount/libbootcount.o in SPL binary
+
CONFIG_SPL_FAT_SUPPORT
Support for fs/fat/libfat.o in SPL binary
diff --git a/common/main.c b/common/main.c
index 56da214..2407569 100644
--- a/common/main.c
+++ b/common/main.c
@@ -349,8 +349,15 @@ static void process_boot_delay(void)
#ifdef CONFIG_BOOTCOUNT_LIMIT
bootcount = bootcount_load();
+#if !defined(CONFIG_SPL_BOOTCOUNT_SUPPORT)
+ /*
+ * Don't increment bootcount when SPL has bootcount suport included.
+ * Otherwise SPL and U-Boot would increment the counter adding a
+ * total of 2 each bootup.
+ */
bootcount++;
bootcount_store (bootcount);
+#endif
setenv_ulong("bootcount", bootcount);
bootlimit = getenv_ulong("bootlimit", 10, 0);
#endif /* CONFIG_BOOTCOUNT_LIMIT */
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 628c399..84f3fdf 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -144,6 +144,29 @@ static void spl_ram_load_image(void)
}
#endif
+#ifdef CONFIG_BOOTCOUNT_LIMIT
+int spl_bootlimit_exceeded(void)
+{
+ u32 bootcount, bootlimit;
+
+ /* Increment bootcounter */
+ bootcount = bootcount_load();
+ bootcount++;
+ bootcount_store(bootcount);
+
+ /* Check if limit is exceeeded */
+ env_init();
+ bootlimit = getenv_ulong("bootlimit", 10, 0);
+ if (bootlimit && (bootcount > bootlimit)) {
+ printf ("Warning: Bootlimit (%u) exceeded, booting into U-Boot!\n",
+ bootlimit);
+ return 1;
+ }
+
+ return 0;
+}
+#endif
+
void board_init_r(gd_t *dummy1, ulong dummy2)
{
u32 boot_device;
diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c
index 976e865..d3ffe67 100644
--- a/common/spl/spl_nor.c
+++ b/common/spl/spl_nor.c
@@ -26,7 +26,12 @@ void spl_nor_load_image(void)
*/
spl_image.flags |= SPL_COPY_PAYLOAD_ONLY;
- if (spl_start_uboot()) {
+ /*
+ * Check spl_bootlimit_exceeded() first, otherwise it may not
+ * be executed (when spl_start_uboot returns 1). And it needs
+ * the be run each boot to increment the bootcounter.
+ */
+ if (spl_bootlimit_exceeded() || spl_start_uboot()) {
/*
* Load real U-Boot from its location in NOR flash to its
* defined location in SDRAM
diff --git a/include/spl.h b/include/spl.h
index 4bc1dd1..dd6ffe4 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -79,4 +79,10 @@ void spl_net_load_image(const char *device);
#ifdef CONFIG_SPL_BOARD_INIT
void spl_board_init(void);
#endif
+
+#ifdef CONFIG_BOOTCOUNT_LIMIT
+int spl_bootlimit_exceeded(void);
+#else
+#define spl_bootlimit_exceeded() 0
+#endif
#endif
diff --git a/spl/Makefile b/spl/Makefile
index 01873de..1ae3b30 100644
--- a/spl/Makefile
+++ b/spl/Makefile
@@ -83,6 +83,7 @@ LIBS-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/libnet.o
LIBS-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/phy/libphy.o
LIBS-$(CONFIG_SPL_MUSB_NEW_SUPPORT) += drivers/usb/musb-new/libusb_musb-new.o
LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/usb/gadget/libusb_gadget.o
+LIBS-$(CONFIG_SPL_BOOTCOUNT_SUPPORT) += drivers/bootcount/libbootcount.o
ifneq ($(CONFIG_AM33XX)$(CONFIG_OMAP34XX)$(CONFIG_OMAP44XX)$(CONFIG_OMAP54XX)$(CONFIG_TI814X),)
LIBS-y += $(CPUDIR)/omap-common/libomap-common.o
--
1.8.4
More information about the U-Boot
mailing list