diff mbox series

[U-Boot,v3,4/7] bootcount: Rewrite autoboot to use wrapper functions from bootcount.h

Message ID 20180429133633.29509-5-lukma@denx.de
State Superseded
Delegated to: Tom Rini
Headers show
Series Provide SPL support for bootcount (in the case of using falcon boot mode) | expand

Commit Message

Lukasz Majewski April 29, 2018, 1:36 p.m. UTC
The code has been refactored to use common wrappers from bootcount.h
header.

Signed-off-by: Lukasz Majewski <lukma@denx.de>

---

Changes in v3:
- New patch

Changes in v2:
- None

 common/autoboot.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

Comments

Stefan Roese April 30, 2018, 8:08 a.m. UTC | #1
Hi Lukasz,

On 29.04.2018 15:36, Lukasz Majewski wrote:
> The code has been refactored to use common wrappers from bootcount.h
> header.
> 
> Signed-off-by: Lukasz Majewski <lukma@denx.de>
> 
> ---
> 
> Changes in v3:
> - New patch
> 
> Changes in v2:
> - None
> 
>   common/autoboot.c | 23 +++++------------------
>   1 file changed, 5 insertions(+), 18 deletions(-)
> 
> diff --git a/common/autoboot.c b/common/autoboot.c
> index 2eef7a04cc..bfe4bdcf50 100644
> --- a/common/autoboot.c
> +++ b/common/autoboot.c
> @@ -14,6 +14,7 @@
>   #include <menu.h>
>   #include <post.h>
>   #include <u-boot/sha256.h>
> +#include <bootcount.h>
>   
>   DECLARE_GLOBAL_DATA_PTR;
>   
> @@ -291,18 +292,8 @@ const char *bootdelay_process(void)
>   {
>   	char *s;
>   	int bootdelay;
> -#ifdef CONFIG_BOOTCOUNT_LIMIT
> -	unsigned long bootcount = 0;
> -	unsigned long bootlimit = 0;
> -#endif /* CONFIG_BOOTCOUNT_LIMIT */
> -
> -#ifdef CONFIG_BOOTCOUNT_LIMIT
> -	bootcount = bootcount_load();
> -	bootcount++;
> -	bootcount_store(bootcount);
> -	env_set_ulong("bootcount", bootcount);
> -	bootlimit = env_get_ulong("bootlimit", 10, 0);
> -#endif /* CONFIG_BOOTCOUNT_LIMIT */
> +
> +	bootcount_inc(UBOOT);
>   
>   	s = env_get("bootdelay");
>   	bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
> @@ -324,13 +315,9 @@ const char *bootdelay_process(void)
>   		s = env_get("failbootcmd");
>   	} else
>   #endif /* CONFIG_POST */
> -#ifdef CONFIG_BOOTCOUNT_LIMIT
> -	if (bootlimit && (bootcount > bootlimit)) {
> -		printf("Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n",
> -		       (unsigned)bootlimit);
> +	if (bootcount_error(UBOOT))
>   		s = env_get("altbootcmd");
> -	} else
> -#endif /* CONFIG_BOOTCOUNT_LIMIT */
> +	else
>   		s = env_get("bootcmd");
>   
>   	process_fdt_options(gd->fdt_blob);

Now that look much simpler / cleaner. Thanks for working on this.

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan
Tom Rini April 30, 2018, 2:17 p.m. UTC | #2
On Sun, Apr 29, 2018 at 03:36:30PM +0200, Lukasz Majewski wrote:

> The code has been refactored to use common wrappers from bootcount.h
> header.
> 
> Signed-off-by: Lukasz Majewski <lukma@denx.de>
> 

Reviewed-by: Tom Rini <trini@konsulko.com>
diff mbox series

Patch

diff --git a/common/autoboot.c b/common/autoboot.c
index 2eef7a04cc..bfe4bdcf50 100644
--- a/common/autoboot.c
+++ b/common/autoboot.c
@@ -14,6 +14,7 @@ 
 #include <menu.h>
 #include <post.h>
 #include <u-boot/sha256.h>
+#include <bootcount.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -291,18 +292,8 @@  const char *bootdelay_process(void)
 {
 	char *s;
 	int bootdelay;
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-	unsigned long bootcount = 0;
-	unsigned long bootlimit = 0;
-#endif /* CONFIG_BOOTCOUNT_LIMIT */
-
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-	bootcount = bootcount_load();
-	bootcount++;
-	bootcount_store(bootcount);
-	env_set_ulong("bootcount", bootcount);
-	bootlimit = env_get_ulong("bootlimit", 10, 0);
-#endif /* CONFIG_BOOTCOUNT_LIMIT */
+
+	bootcount_inc(UBOOT);
 
 	s = env_get("bootdelay");
 	bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
@@ -324,13 +315,9 @@  const char *bootdelay_process(void)
 		s = env_get("failbootcmd");
 	} else
 #endif /* CONFIG_POST */
-#ifdef CONFIG_BOOTCOUNT_LIMIT
-	if (bootlimit && (bootcount > bootlimit)) {
-		printf("Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n",
-		       (unsigned)bootlimit);
+	if (bootcount_error(UBOOT))
 		s = env_get("altbootcmd");
-	} else
-#endif /* CONFIG_BOOTCOUNT_LIMIT */
+	else
 		s = env_get("bootcmd");
 
 	process_fdt_options(gd->fdt_blob);