All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Rini <trini@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] SPL: Add CONFIG_SPL_BOOTCOUNT_SUPPORT
Date: Fri, 27 Sep 2013 15:26:08 -0400	[thread overview]
Message-ID: <1380309969-5618-2-git-send-email-trini@ti.com> (raw)
In-Reply-To: <1380309969-5618-1-git-send-email-trini@ti.com>

Add a new symbol, CONFIG_SPL_BOOTCOUNT_SUPPORT, to make use of the
existing BOOTCOUNT_SUPPORT within SPL.  It is strongly discouraged to
use bootcount in both SPL and full U-Boot, as they use the same counter.

Signed-off-by: Tom Rini <trini@ti.com>
---
 README            |    6 ++++++
 common/spl/spl.c  |   27 +++++++++++++++++++++++++++
 doc/README.falcon |    8 +++++++-
 include/spl.h     |    1 +
 spl/Makefile      |    1 +
 5 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/README b/README
index de17f59..5351d24 100644
--- a/README
+++ b/README
@@ -3035,6 +3035,12 @@ FIT uImage format:
 		Enable booting directly to an OS from SPL.
 		See also: doc/README.falcon
 
+		CONFIG_SPL_BOOTCOUNT_LIMIT
+		Optional part of CONFIG_SPL_OS_BOOT and requires
+		CONFIG_SPL_ENV_SUPPORT.  Adds the bootcount facility to
+		SPL.  It is strongly encouraged to not use bootcount in
+		both SPL and full U-Boot.
+
 		CONFIG_SPL_DISPLAY_PRINT
 		For ARM, enable an optional function to print more information
 		about the running system.
diff --git a/common/spl/spl.c b/common/spl/spl.c
index da31457..ffa49d9 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -38,6 +38,10 @@ static bd_t bdata __attribute__ ((section(".data")));
  *
  * Please implement your own board specific funcion to do this.
  *
+ * If both CONFIG_SPL_BOOTCOUNT_LIMIT and CONFIG_SPL_ENV_SUPPORT are
+ * set this function is responsible for calling
+ * spl_bootcount_limit_exceeded();
+ *
  * RETURN
  * 0 to not start u-boot
  * positive if u-boot should start
@@ -49,6 +53,29 @@ __weak int spl_start_uboot(void)
 	puts("SPL: Direct Linux boot not active!\n");
 	return 1;
 }
+
+#if defined(CONFIG_SPL_BOOTCOUNT_LIMIT) && defined(CONFIG_SPL_ENV_SUPPORT)
+/*
+ * Determine if we have exceeded our bootlimit.
+ *
+ * @return 1 if we have exceeded our limit, 0 otherwise.
+ */
+int spl_bootcount_limit_exceeded(void)
+{
+	unsigned long bootcount = 0;
+	unsigned long bootlimit = 0;
+
+	bootcount = bootcount_load();
+	bootcount++;
+	bootcount_store (bootcount);
+	setenv_ulong("bootcount", bootcount);
+	bootlimit = getenv_ulong("bootlimit", 10, 0);
+	printf("bootcount: %ld\nbootlimit: %ld\n", bootcount, bootlimit);
+	if (bootlimit)
+		return bootcount > bootlimit;
+	return 0;
+}
+#endif /* CONFIG_BOOTCOUNT_LIMIT && CONFIG_SPL_ENV_SUPPORT */
 #endif
 
 /*
diff --git a/doc/README.falcon b/doc/README.falcon
index 82a254b..c34c171 100644
--- a/doc/README.falcon
+++ b/doc/README.falcon
@@ -70,6 +70,8 @@ CONFIG_CMD_SPL_WRITE_SIZE 	Size of the parameters area to be copied
 
 CONFIG_SPL_OS_BOOT	Activate Falcon Mode.
 
+CONFIG_SPL_BOOTCOUNT_LIMIT	Use bootcount support to fall back to U-Boot
+
 Function that a board must implement
 ------------------------------------
 
@@ -78,7 +80,8 @@ void spl_board_prepare_for_linux(void) : optional
 
 spl_start_uboot() : required
 		Returns "0" if SPL should start the kernel, "1" if U-Boot
-		must be started.
+		must be started.  Must call spl_bootcount_limit_exceeded if
+		CONFIG_SPL_BOOTCOUNT_LIMIT is to be supported
 
 Environment variables
 ---------------------
@@ -89,6 +92,9 @@ mode.  In this case the following variables may be supported:
 boot_os : 		Set to yes/Yes/true/True/1 to enable booting to OS,
 			any other value to fall back to U-Boot (including
 			unset)
+bootlimit :		As part of CONFIG_SPL_BOOTCOUNT_LIMIT used to set the
+			maximum number of times to try and boot the OS before
+			falling back to U-Boot.
 falcon_args_file :	Filename to load as the 'args' portion of falcon mode
 			rather than the hard-coded value.
 falcon_image_file :	Filename to load as the OS image portion of falcon
diff --git a/include/spl.h b/include/spl.h
index 2bd6e16..ca654b3 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -37,6 +37,7 @@ void spl_parse_image_header(const struct image_header *header);
 void spl_board_prepare_for_linux(void);
 void __noreturn jump_to_image_linux(void *arg);
 int spl_start_uboot(void);
+int spl_bootcount_limit_exceeded(void);
 void spl_display_print(void);
 
 /* NAND SPL functions */
diff --git a/spl/Makefile b/spl/Makefile
index fa642ec..2a34df8 100644
--- a/spl/Makefile
+++ b/spl/Makefile
@@ -99,6 +99,7 @@ LIBS-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/phy/libphy.o
 LIBS-$(CONFIG_SPL_USBETH_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_LIMIT) += drivers/bootcount/libbootcount.o
 LIBS-$(CONFIG_SPL_WATCHDOG_SUPPORT) += drivers/watchdog/libwatchdog.o
 
 ifneq ($(CONFIG_OMAP_COMMON),)
-- 
1.7.9.5

  reply	other threads:[~2013-09-27 19:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-27 19:26 [U-Boot] [PATCH 0/2] Add bootcount support to SPL Tom Rini
2013-09-27 19:26 ` Tom Rini [this message]
2013-09-30  6:37   ` [U-Boot] [PATCH 1/2] SPL: Add CONFIG_SPL_BOOTCOUNT_SUPPORT Stefan Roese
2013-10-02 13:14     ` Tom Rini
2013-09-27 19:26 ` [U-Boot] [PATCH 2/2] am335x: Switch to CONFIG_SPL_BOOTCOUNT_SUPPORT Tom Rini
2013-09-28  1:20 ` [U-Boot] [PATCH 0/2] Add bootcount support to SPL Otavio Salvador
2013-10-02 15:07   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1380309969-5618-2-git-send-email-trini@ti.com \
    --to=trini@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.