Provide SPL support for bootcount (in the case of using falcon boot mode)
v5 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. Moreover, the common code has been identified and reused in the common/autoboot.c file.
It also enables this feature on display5 board to present usage patterns.
This patch has been applied on top of u-boot/master:
SHA1 : v2018.05-rc3
Test HW: Beagle Bone Black (am335x) , Display5 (imx6q)
Travis-Ci: https://travis-ci.org/lmajewski/u-boot-dfu/builds/373639971
Lukasz Majewski (7):
bootcount: spl: Enable bootcount support in SPL
bootcount: Add include guards into bootcount.h file
bootcount: Add function wrappers to handle bootcount increment and
error checking
bootcount: Rewrite autoboot to use wrapper functions from bootcount.h
bootcount: spl: Extend SPL to support bootcount incrementation
bootcount: display5: spl: Extend DISPLAY5 board SPL to support
bootcount checking
bootcount: display5: config: Enable boot count feature in the display5
board
board/liebherr/display5/spl.c | 3 ++- common/autoboot.c | 23 +++++--------------- common/spl/Kconfig | 9 ++++++++ common/spl/spl.c | 3 +++ configs/display5_defconfig | 4 ++++ drivers/Makefile | 1 + include/bootcount.h | 50 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 74 insertions(+), 19 deletions(-)
Signature · 1 line
2.11.0
PATCH v5 1/7 bootcount: spl: Enable bootcount support in SPL
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.
---
Changes in v5:
- None
Changes in v4:
- None
Changes in v3:
- None
Changes in v2:
- None
common/spl/Kconfig | 9 +++++++++ drivers/Makefile | 1 + 2 files changed, 10 insertions(+)
common/spl/Kconfig +9 -0
@@ -54,6 +54,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
@@ -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
PATCH v5 1/7 bootcount: spl: Enable bootcount support in SPL
Quoted 9 lines · Lukasz Majewski
New, SPL related config option -
CONFIG_SPL_BOOTCOUNT_LIMIThas been added to allowdrivers/bootcountcode 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 <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Tom Rini <[email protected]>
Quoted 23 lines
---
Changes in v5:
- NoneChanges in v4:
- NoneChanges in v3:
- NoneChanges in v2:
- Nonecommon/spl/Kconfig | 9 +++++++++ drivers/Makefile | 1 + 2 files changed, 10 insertions(+)common/spl/Kconfig +0
-0
common/spl/Kconfig config SPL_BOOTROM_SUPPORT · line 54
Quoted 1 line
common/spl/Kconfig +0
-0@@ -54,6 +54,15 @@ config SPL_BOOTROM_SUPPORT BOOT_DEVICE_BOOTROM (or fall-through to the next boot device in
the
common/spl/Kconfig config SPL_BOOTROM_SUPPORT
Quoted 7 lines
common/spl/Kconfig +5
-0boot 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
Quoted 21 lines
common/spl/Kconfig +4
-0+ 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
-1@@ -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/ --2.11.0
Signature · 1 line
Alex Kiernan
PATCH v5 1/7 bootcount: spl: Enable bootcount support in SPL
In reply to Lukasz MajewskiQuoted 10 lines · Lukasz Majewski
New, SPL related config option -
CONFIG_SPL_BOOTCOUNT_LIMIThas been added to allowdrivers/bootcountcode 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 <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Tom Rini <[email protected]>Reviewed-by Alex Kiernan <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180511/d02f8c4f/attachment.sig>
PATCH v5 2/7 bootcount: Add include guards into bootcount.h file
In reply to Lukasz MajewskiThis patch adds missing include guards for bootcount.h file.
---
Changes in v5:
- None
Changes in v4:
- None
Changes in v3:
- None
Changes in v2:
- New patch
include/bootcount.h | 3 +++ 1 file changed, 3 insertions(+)
include/bootcount.h +3 -0
@@ -4,6 +4,8 @@* * SPDX-License-Identifier: GPL-2.0+ */ +#ifndef _BOOTCOUNT_H__ +#define _BOOTCOUNT_H__#include <common.h> #include <asm/io.h>
@@ -38,3 +40,4 @@ static inline u32 raw_bootcount_load(volatile u32 *addr)return in_be32 (addr); }#endif +#endif /* _BOOTCOUNT_H__ */
Signature · 1 line
2.11.0
PATCH v5 2/7 bootcount: Add include guards into bootcount.h file
Quoted 5 lines · Lukasz Majewski
This patch adds missing include guards for
bootcount.hfile.Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Tom Rini <[email protected]>
Quoted 37 lines
---
Changes in v5:
- NoneChanges in v4:
- NoneChanges in v3:
- NoneChanges in v2:
- New patchinclude/bootcount.h | 3 +++ 1 file changed, 3 insertions(+)include/bootcount.h +3
-1@@ -4,6 +4,8 @@* * SPDX-License-Identifier: GPL-2.0+ */ +#ifndef _BOOTCOUNT_H__ +#define _BOOTCOUNT_H__#include <common.h> #include <asm/io.h> @@ -38,3 +40,4 @@ static inline u32 raw_bootcount_load(volatile u32 *addr)return in_be32 (addr); }#endif +#endif /* _BOOTCOUNT_H__ */ --2.11.0
Signature · 1 line
Alex Kiernan
PATCH v5 2/7 bootcount: Add include guards into bootcount.h file
In reply to Lukasz MajewskiQuoted 6 lines · Lukasz Majewski
This patch adds missing include guards for
bootcount.hfile.Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Tom Rini <[email protected]>Reviewed-by Alex Kiernan <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180511/29b34604/attachment.sig>
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
In reply to Lukasz MajewskiThose two functions can be used to provide easy bootcount management.
---
Changes in v5:
- Provide parenthesis for #if defined(FOO) && ...
Changes in v4:
- Remove enum bootcount_context and replace it with checking gd_t->flags (The GD_FLG_SPL_INIT is only set in SPL, it is cleared in u-boot proper, so can be used as indication if we are in u-boot or SPL).
- Do not call bootcount_store() twice when it is not needed.
- Call env_set_ulong("bootcount", bootcount); only in NON SPL context - Boards with TINY_PRINTF (in newest mainline) will build break as this function requires simple_itoa() from vsprintf.c (now not always build in SPL).
Changes in v3:
- Unify those functions to also work with common/autoboot.c code
- Add enum bootcount_context to distinguish between u-boot proper and SPL
Changes in v2:
- None
include/bootcount.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
include/bootcount.h +47 -0
@@ -11,6 +11,8 @@#include <asm/io.h> #include <asm/byteorder.h> +#if defined(CONFIG_SPL_BOOTCOUNT_LIMIT ) || defined(CONFIG_BOOTCOUNT_LIMIT ) +#if !defined(CONFIG_SYS_BOOTCOUNT_LE ) && !defined(CONFIG_SYS_BOOTCOUNT_BE )# if __BYTE_ORDER == __LITTLE_ENDIAN# define CONFIG_SYS_BOOTCOUNT_LE
@@ -40,4 +42,49 @@ static inline u32 raw_bootcount_load(volatile u32 *addr)return in_be32 (addr); }#endif + +DECLARE_GLOBAL_DATA_PTR ; +static inline int 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." , bootlimit); +if (!(gd->flags &GD_FLG_SPL_INIT )) +printf (" Using altbootcmd." ); +printf ("\n" ); + +return 1 ; + } + +return 0 ; +} + +static inline void bootcount_inc (void ) +{ +unsigned long bootcount =bootcount_load (); + +if (gd->flags &GD_FLG_SPL_INIT ) { +bootcount_store (++bootcount); +return ; + } + +#ifndef CONFIG_SPL_BUILD +/* Only increment bootcount when no bootcount support in SPL */ +#ifndef CONFIG_SPL_BOOTCOUNT_LIMIT +bootcount_store (++bootcount); +#endif +env_set_ulong ("bootcount" , bootcount); +#endif /* !CONFIG_SPL_BUILD */ +} + +#if defined(CONFIG_SPL_BUILD ) && !defined(CONFIG_SPL_BOOTCOUNT_LIMIT ) +void bootcount_store (ulong a) {}; +ulong bootcount_load (void ) {return 0 ; } +#endif /* CONFIG_SPL_BUILD && !CONFIG_SPL_BOOTCOUNT_LIMIT */ +#else +static inline int bootcount_error (void ) {return 0 ; } +static inline void bootcount_inc (void ) {} +#endif /* CONFIG_SPL_BOOTCOUNT_LIMIT || CONFIG_BOOTCOUNT_LIMIT */ #endif /* _BOOTCOUNT_H__ */
Signature · 1 line
2.11.0
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
Quoted 11 lines · Lukasz Majewski
Those two functions can be used to provide easy bootcount management.
Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Tom Rini <[email protected]>Reviewed-by Stefan Roese <[email protected]>---
Changes in v5:
- Provide parenthesis for #if defined(FOO) && ...
Quoted 7 lines
Changes in v4:
- Remove enumbootcount_contextand replace it with checkinggd_t->flags(TheGD_FLG_SPL_INITis only set in SPL, it is cleared in u-boot proper, so can be used as indication if we are in u-boot or SPL).
- Do not callbootcount_store()twice when it is not needed.
- Callenv_set_ulong("bootcount", bootcount); only in NON SPL context - Boards withTINY_PRINTF(in newest mainline) will build break as this
function
Quoted 17 lines
requires
simple_itoa()fromvsprintf.c(now not always build in SPL).Changes in v3:
- Unify those functions to also work withcommon/autoboot.ccode
- Add enumbootcount_contextto distinguish between u-boot proper and SPLChanges in v2:
- Noneinclude/bootcount.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)include/bootcount.h +0
-0
include/bootcount.h line 14
Quoted 4 lines
include/bootcount.h +1
-0@@ -11,6 +11,8 @@#include <asm/io.h> #include <asm/byteorder.h> +#if defined(CONFIG_SPL_BOOTCOUNT_LIMIT) ||
defined(CONFIG_BOOTCOUNT_LIMIT)
include/bootcount.h line 16
Quoted 2 lines
include/bootcount.h +1
-0+ #if !defined(CONFIG_SYS_BOOTCOUNT_LE) &&
!defined(CONFIG_SYS_BOOTCOUNT_BE)
include/bootcount.h static inline u32 raw_bootcount_load(volatile u32
Quoted 3 lines
include/bootcount.h +0
-0# if __BYTE_ORDER == __LITTLE_ENDIAN# define CONFIG_SYS_BOOTCOUNT_LE @@ -40,4 +42,49 @@ static inline u32 raw_bootcount_load(volatile u32
*addr)
Quoted 30 lines
include/bootcount.h +27
-0return in_be32(addr); }#endif + +DECLARE_GLOBAL_DATA_PTR ; +static inline int 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." , bootlimit); +if (!(gd->flags &GD_FLG_SPL_INIT )) +printf (" Using altbootcmd." ); +printf ("\n" ); + +return 1 ; + } + +return 0 ; +} + +static inline void bootcount_inc (void ) +{ +unsigned long bootcount =bootcount_load (); + +if (gd->flags &GD_FLG_SPL_INIT ) { +bootcount_store (++bootcount); +return ; + }
include/bootcount.h static inline u32 raw_bootcount_load(volatile u32 *addr) · line 81
Quoted 10 lines
include/bootcount.h +10
-0+ +#ifndef CONFIG_SPL_BUILD +/* Only increment bootcount when no bootcount support in SPL */ +#ifndef CONFIG_SPL_BOOTCOUNT_LIMIT +bootcount_store (++bootcount); +#endif +env_set_ulong ("bootcount" , bootcount); +#endif /* !CONFIG_SPL_BUILD */ +} +
I'm kinda confused by this code... isn't this equivalent.?
static inline void bootcount_inc(void)
{
unsigned long bootcount = bootcount_load(); bootcount_store(++bootcount);
#ifndef CONFIG_SPL_BUILD
env_set_ulong("bootcount", bootcount); #endif /* !CONFIG_SPL_BUILD */
}
Also I suspect bootcount_store() will fail at link time on boards where the bootcount is stored in ext4?
Quoted 11 lines
include/bootcount.h +8
-1+#if defined(CONFIG_SPL_BUILD ) && !defined(CONFIG_SPL_BOOTCOUNT_LIMIT ) +void bootcount_store (ulong a) {}; +ulong bootcount_load (void ) {return 0 ; } +#endif /* CONFIG_SPL_BUILD && !CONFIG_SPL_BOOTCOUNT_LIMIT */ +#else +static inline int bootcount_error (void ) {return 0 ; } +static inline void bootcount_inc (void ) {} +#endif /* CONFIG_SPL_BOOTCOUNT_LIMIT || CONFIG_BOOTCOUNT_LIMIT */ #endif /* _BOOTCOUNT_H__ */ --2.11.0
Signature · 1 line
Alex Kiernan
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
Quoted 10 lines · Alex Kiernan
Quoted 7 lines · Lukasz Majewski
Those two functions can be used to provide easy bootcount management.
Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Tom Rini <[email protected]>Reviewed-by Stefan Roese <[email protected]>---
Quoted 6 lines
Quoted 6 lines
Changes in v5:
- Provide parenthesis for #if defined(FOO) && ...Changes in v4:
- Remove enumbootcount_contextand replace it with checkinggd_t->flags(TheGD_FLG_SPL_INITis only set in SPL, it is cleared in u-boot
proper,
Quoted 10 lines
Quoted 4 lines
so can be used as indication if we are in u-boot or SPL).
- Do not callbootcount_store()twice when it is not needed.
- Callenv_set_ulong("bootcount", bootcount); only in NON SPL context - Boards withTINY_PRINTF(in newest mainline) will build break as thisfunction
Quoted 5 lines
requires
simple_itoa()fromvsprintf.c(now not always build in SPL).Changes in v3:
- Unify those functions to also work withcommon/autoboot.ccode
- Add enumbootcount_contextto distinguish between u-boot proper and
SPL
Quoted 4 lines
Quoted 4 lines
Changes in v2:
- Noneinclude/bootcount.h | 47
+++++++++++++++++++++++++++++++++++++++++++++++
Quoted 62 lines
include/bootcount.h line 14
Quoted 11 lines
1 file changed, 47 insertions(+)include/bootcount.h +1
-0@@ -11,6 +11,8 @@#include <asm/io.h> #include <asm/byteorder.h> +#if defined(CONFIG_SPL_BOOTCOUNT_LIMIT) ||
defined(CONFIG_BOOTCOUNT_LIMIT)include/bootcount.h line 16
Quoted 2 lines
include/bootcount.h +1
-0+ #if !defined(CONFIG_SYS_BOOTCOUNT_LE) &&!defined(CONFIG_SYS_BOOTCOUNT_BE)
include/bootcount.h static inline u32 raw_bootcount_load(volatile u32
Quoted 3 lines
include/bootcount.h +0
-0# if __BYTE_ORDER == __LITTLE_ENDIAN# define CONFIG_SYS_BOOTCOUNT_LE @@ -40,4 +42,49 @@ static inline u32 raw_bootcount_load(volatile u32*addr)
Quoted 30 lines
include/bootcount.h +27
-0return in_be32(addr); }#endif + +DECLARE_GLOBAL_DATA_PTR ; +static inline int 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." , bootlimit); +if (!(gd->flags &GD_FLG_SPL_INIT )) +printf (" Using altbootcmd." ); +printf ("\n" ); + +return 1 ; + } + +return 0 ; +} + +static inline void bootcount_inc (void ) +{ +unsigned long bootcount =bootcount_load (); + +if (gd->flags &GD_FLG_SPL_INIT ) { +bootcount_store (++bootcount); +return ; + }include/bootcount.h static inline u32 raw_bootcount_load(volatile u32 *addr) · line 81
Quoted 10 lines
include/bootcount.h +10
-0+ +#ifndef CONFIG_SPL_BUILD +/* Only increment bootcount when no bootcount support in SPL */ +#ifndef CONFIG_SPL_BOOTCOUNT_LIMIT +bootcount_store (++bootcount); +#endif +env_set_ulong ("bootcount" , bootcount); +#endif /* !CONFIG_SPL_BUILD */ +} +I'm kinda confused by this code... isn't this equivalent.?
Quoted 9 lines
static inline void bootcount_inc(void)
{
unsigned long bootcount = bootcount_load();
bootcount_store(++bootcount);
#ifndef CONFIG_SPL_BUILD
env_set_ulong("bootcount", bootcount);
#endif /* !CONFIG_SPL_BUILD */
}I should've included my reasoning as I've got to be missing something... if GD_FLG_SPL_INIT is always set when we get here in SPL, then it's equivalent to the compile time guard. Which I think says I don't understand the flow to how we get here, otherwise we wouldn't need the runtime guard.
Quoted 8 lines
Quoted 8 lines
include/bootcount.h +8
-0+#if defined(CONFIG_SPL_BUILD ) && !defined(CONFIG_SPL_BOOTCOUNT_LIMIT ) +void bootcount_store (ulong a) {}; +ulong bootcount_load (void ) {return 0 ; } +#endif /* CONFIG_SPL_BUILD && !CONFIG_SPL_BOOTCOUNT_LIMIT */ +#else +static inline int bootcount_error (void ) {return 0 ; } +static inline void bootcount_inc (void ) {} +#endif /* CONFIG_SPL_BOOTCOUNT_LIMIT || CONFIG_BOOTCOUNT_LIMIT */
Quoted 8 lines
Quoted 3 lines
include/bootcount.h +0
-1#endif /* _BOOTCOUNT_H__ */ --2.11.0
--
Alex Kiernan
--
Alex Kiernan
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
On 08.05.2018 08:58, Alex Kiernan wrote:
<snip>
Quoted 31 lines
Quoted 21 lines
Quoted 8 lines
include/bootcount.h +8
-0+static inline void bootcount_inc (void ) +{ +unsigned long bootcount =bootcount_load (); + +if (gd->flags &GD_FLG_SPL_INIT ) { +bootcount_store (++bootcount); +return ; + }include/bootcount.h static inline u32 raw_bootcount_load(volatile u32 *addr) · line 81
Quoted 10 lines
include/bootcount.h +10
-0+ +#ifndef CONFIG_SPL_BUILD +/* Only increment bootcount when no bootcount support in SPL */ +#ifndef CONFIG_SPL_BOOTCOUNT_LIMIT +bootcount_store (++bootcount); +#endif +env_set_ulong ("bootcount" , bootcount); +#endif /* !CONFIG_SPL_BUILD */ +} +I'm kinda confused by this code... isn't this equivalent.?
Quoted 9 lines
static inline void bootcount_inc(void) { unsigned long bootcount = bootcount_load(); bootcount_store(++bootcount); #ifndef CONFIG_SPL_BUILD env_set_ulong("bootcount", bootcount); #endif /* !CONFIG_SPL_BUILD */ }
Quoted 4 lines
I should've included my reasoning as I've got to be missing something... if
GD_FLG_SPL_INITis always set when we get here in SPL, then it's equivalent to the compile time guard. Which I think says I don't understand the flow to how we get here, otherwise we wouldn't need the runtime guard.
When using with SPL and bootcounter support, this code will get called twice, first from the SPL, where the counter will get incremented. And second from main U-Boot, where we need to make sure, that the counter does not get incremented again, if SPL has already done so.
With your patch version, the bootcounter would get incremented twice in this case.
Thanks,
Stefan
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
Hi Alex, Stefan,
Quoted 41 lines · Alex Kiernan
<snip>
Quoted 31 lines
Quoted 21 lines
Quoted 12 lines
include/bootcount.h +11
-0+static inline void bootcount_inc (void ) +{ +unsigned long bootcount =bootcount_load (); + +if (gd->flags &GD_FLG_SPL_INIT ) { +bootcount_store (++bootcount); +return ; + } + +#ifndef CONFIG_SPL_BUILD +/* Only increment bootcount when no bootcount support in SPL */ +#ifndef
CONFIG_SPL_BOOTCOUNT_LIMITinclude/bootcount.h static inline u32 raw_bootcount_load(volatile u32 *addr) · line 81
Quoted 6 lines
include/bootcount.h +6
-0+bootcount_store (++bootcount); +#endif +env_set_ulong ("bootcount" , bootcount); +#endif /* !CONFIG_SPL_BUILD */ +} +I'm kinda confused by this code... isn't this equivalent.?
Quoted 9 lines
static inline void bootcount_inc(void) { unsigned long bootcount = bootcount_load(); bootcount_store(++bootcount); #ifndef CONFIG_SPL_BUILD env_set_ulong("bootcount", bootcount); #endif /* !CONFIG_SPL_BUILD */ }Quoted 5 lines
I should've included my reasoning as I've got to be missing something... if
GD_FLG_SPL_INITis always set when we get here in SPL, then it's equivalent to the compile time guard. Which I think says I don't understand the flow to how we get here, otherwise we wouldn't need the runtime guard.
Quoted 5 lines
When using with SPL and bootcounter support, this code will get called twice, first from the SPL, where the counter will get incremented. And second from main U-Boot, where we need to make sure, that the counter does not get incremented again, if SPL has already done so.
+1
Quoted 6 lines
With your patch version, the bootcounter would get incremented twice in this case.
Thanks,
Stefan
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180508/f0450882/attachment.sig>
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
In reply to Stefan RoeseQuoted 4 lines · Stefan Roese
On 08.05.2018 08:58, Alex Kiernan wrote:
<snip>
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
include/bootcount.h static inline u32 raw_bootcount_load(volatile u32 *addr)
Quoted 11 lines
include/bootcount.h +11
-0+static inline void bootcount_inc (void ) +{ +unsigned long bootcount =bootcount_load (); + +if (gd->flags &GD_FLG_SPL_INIT ) { +bootcount_store (++bootcount); +return ; + } + +#ifndef CONFIG_SPL_BUILD +/* Only increment bootcount when no bootcount support in SPL
*/
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
include/bootcount.h static inline u32 raw_bootcount_load(volatile u32 *addr) · line 81
Quoted 7 lines
include/bootcount.h +7
-0+#ifndef CONFIG_SPL_BOOTCOUNT_LIMIT +bootcount_store (++bootcount); +#endif +env_set_ulong ("bootcount" , bootcount); +#endif /* !CONFIG_SPL_BUILD */ +} +I'm kinda confused by this code... isn't this equivalent.?
static inline void bootcount_inc(void) { unsigned long bootcount = bootcount_load();
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
bootcount_store(++bootcount); #ifndef CONFIG_SPL_BUILD env_set_ulong("bootcount", bootcount); #endif /* !CONFIG_SPL_BUILD */ }I should've included my reasoning as I've got to be missing
something... if
Quoted 1 line
Quoted 1 line
GD_FLG_SPL_INITis always set when we get here in SPL, then it's
equivalent
Quoted 1 line
Quoted 1 line
to the compile time guard. Which I think says I don't understand the
flow
Quoted 10 lines
Quoted 1 line
to how we get here, otherwise we wouldn't need the runtime guard.
When using with SPL and bootcounter support, this code will get called twice, first from the SPL, where the counter will get incremented. And second from main U-Boot, where we need to make sure, that the counter does not get incremented again, if SPL has already done so.
With your patch version, the bootcounter would get incremented twice in this case.
Ahh... thank you. That was the important piece!
Signature · 1 line
Alex Kiernan
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
In reply to Alex KiernanQuoted 105 lines · On Tue, 08 May 2018 05:15:13 +0000 Alex Kiernan <[email protected]> wrote:
Quoted 12 lines · Lukasz Majewski
Those two functions can be used to provide easy bootcount management.
Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Tom Rini <[email protected]>Reviewed-by Stefan Roese <[email protected]>---
Changes in v5:
- Provide parenthesis for #if defined(FOO) && ...Quoted 9 lines
Changes in v4:
- Remove enumbootcount_contextand replace it with checkinggd_t->flags(TheGD_FLG_SPL_INITis only set in SPL, it is cleared in u-boot proper, so can be used as indication if we are in u-boot or SPL).
- Do not callbootcount_store()twice when it is not needed.
- Callenv_set_ulong("bootcount", bootcount); only in NON SPL context - Boards withTINY_PRINTF(in newest mainline) will build break as thisfunction
Quoted 20 lines
requires
simple_itoa()fromvsprintf.c(now not always build in
SPL).Changes in v3:
- Unify those functions to also work withcommon/autoboot.ccode
- Add enumbootcount_contextto distinguish between u-boot proper and SPLChanges in v2:
- Noneinclude/bootcount.h | 47+++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
include/bootcount.h +0
-0include/bootcount.h line 14
Quoted 4 lines
include/bootcount.h +1
-0@@ -11,6 +11,8 @@#include <asm/io.h> #include <asm/byteorder.h> +#if defined(CONFIG_SPL_BOOTCOUNT_LIMIT) ||
defined(CONFIG_BOOTCOUNT_LIMIT)include/bootcount.h line 16
Quoted 2 lines
include/bootcount.h +1
-0+ #if !defined(CONFIG_SYS_BOOTCOUNT_LE) &&!defined(CONFIG_SYS_BOOTCOUNT_BE)
Quoted 4 lines
include/bootcount.h +0
-0# if __BYTE_ORDER == __LITTLE_ENDIAN# define CONFIG_SYS_BOOTCOUNT_LE @@ -40,4 +42,49 @@ static inline u32 raw_bootcount_load(volatileu32
*addr)
Quoted 35 lines
return in_be32(addr);}
#endifinclude/bootcount.h +9
-0+ +DECLARE_GLOBAL_DATA_PTR ; +static inline int 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.",bootlimit);
include/bootcount.h +21
-0+if (!(gd->flags &GD_FLG_SPL_INIT )) +printf (" Using altbootcmd." ); +printf ("\n" ); + +return 1 ; + } + +return 0 ; +} + +static inline void bootcount_inc (void ) +{ +unsigned long bootcount =bootcount_load (); + +if (gd->flags &GD_FLG_SPL_INIT ) { +bootcount_store (++bootcount); +return ; + } + +#ifndef CONFIG_SPL_BUILD +/* Only increment bootcount when no bootcount support in SPL */ +#ifndef
CONFIG_SPL_BOOTCOUNT_LIMITinclude/bootcount.h static inline u32 raw_bootcount_load(volatile u32 *addr) · line 81
Quoted 6 lines
include/bootcount.h +6
-0+bootcount_store (++bootcount); +#endif +env_set_ulong ("bootcount" , bootcount); +#endif /* !CONFIG_SPL_BUILD */ +} +I'm kinda confused by this code... isn't this equivalent.?
static inline void bootcount_inc(void) { unsigned long bootcount = bootcount_load();
Quoted 8 lines
bootcount_store(++bootcount); #ifndef CONFIG_SPL_BUILD env_set_ulong("bootcount", bootcount); #endif /* !CONFIG_SPL_BUILD */ }Also I suspect
bootcount_store()will fail at link time on boards where the bootcount is stored in ext4?
I've run this patch set several times with travis-CI. No errors were present (the travis-ci link is in the cover letter).
Maybe there are some out of tree boards, which use the bootcount in some "odd" way....
Quoted 15 lines
Quoted 11 lines
+#if
defined(CONFIG_SPL_BUILD)
&& !defined(CONFIG_SPL_BOOTCOUNT_LIMIT) +void bootcount_store(ulong
a) {}; +ulongbootcount_load(void){ return 0; }include/bootcount.h +5
-1+#endif /* CONFIG_SPL_BUILD && !CONFIG_SPL_BOOTCOUNT_LIMIT */ +#else +static inline int bootcount_error (void ) {return 0 ; } +static inline void bootcount_inc (void ) {} +#endif /* CONFIG_SPL_BOOTCOUNT_LIMIT || CONFIG_BOOTCOUNT_LIMIT */ #endif /* _BOOTCOUNT_H__ */ --Quoted 1 line
2.11.0
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180508/1ac80274/attachment.sig>
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
Quoted 114 lines · Lukasz Majewski
Quoted 111 lines · On Tue, 08 May 2018 05:15:13 +0000 Alex Kiernan <[email protected]> wrote:
Quoted 12 lines · Lukasz Majewski
Those two functions can be used to provide easy bootcount management.
Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Tom Rini <[email protected]>Reviewed-by Stefan Roese <[email protected]>---
Changes in v5:
- Provide parenthesis for #if defined(FOO) && ...Quoted 9 lines
Changes in v4:
- Remove enumbootcount_contextand replace it with checkinggd_t->flags(TheGD_FLG_SPL_INITis only set in SPL, it is cleared in u-boot proper, so can be used as indication if we are in u-boot or SPL).
- Do not callbootcount_store()twice when it is not needed.
- Callenv_set_ulong("bootcount", bootcount); only in NON SPL context - Boards withTINY_PRINTF(in newest mainline) will build break as thisfunction
Quoted 20 lines
requires
simple_itoa()fromvsprintf.c(now not always build in
SPL).Changes in v3:
- Unify those functions to also work withcommon/autoboot.ccode
- Add enumbootcount_contextto distinguish between u-boot proper and SPLChanges in v2:
- Noneinclude/bootcount.h | 47+++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
include/bootcount.h +0
-0include/bootcount.h line 14
Quoted 4 lines
include/bootcount.h +1
-0@@ -11,6 +11,8 @@#include <asm/io.h> #include <asm/byteorder.h> +#if defined(CONFIG_SPL_BOOTCOUNT_LIMIT) ||
defined(CONFIG_BOOTCOUNT_LIMIT)include/bootcount.h line 16
Quoted 2 lines
include/bootcount.h +1
-0+ #if !defined(CONFIG_SYS_BOOTCOUNT_LE) &&!defined(CONFIG_SYS_BOOTCOUNT_BE)
Quoted 4 lines
include/bootcount.h +0
-0# if __BYTE_ORDER == __LITTLE_ENDIAN# define CONFIG_SYS_BOOTCOUNT_LE @@ -40,4 +42,49 @@ static inline u32 raw_bootcount_load(volatileu32
*addr)
Quoted 35 lines
return in_be32(addr);}
#endifinclude/bootcount.h +9
-0+ +DECLARE_GLOBAL_DATA_PTR ; +static inline int 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.",bootlimit);
include/bootcount.h +21
-0+if (!(gd->flags &GD_FLG_SPL_INIT )) +printf (" Using altbootcmd." ); +printf ("\n" ); + +return 1 ; + } + +return 0 ; +} + +static inline void bootcount_inc (void ) +{ +unsigned long bootcount =bootcount_load (); + +if (gd->flags &GD_FLG_SPL_INIT ) { +bootcount_store (++bootcount); +return ; + } + +#ifndef CONFIG_SPL_BUILD +/* Only increment bootcount when no bootcount support in SPL */ +#ifndef
CONFIG_SPL_BOOTCOUNT_LIMITinclude/bootcount.h static inline u32 raw_bootcount_load(volatile u32 *addr) · line 81
Quoted 6 lines
include/bootcount.h +6
-0+bootcount_store (++bootcount); +#endif +env_set_ulong ("bootcount" , bootcount); +#endif /* !CONFIG_SPL_BUILD */ +} +I'm kinda confused by this code... isn't this equivalent.?
static inline void bootcount_inc(void) { unsigned long bootcount = bootcount_load();bootcount_store(++bootcount); #ifndef CONFIG_SPL_BUILD env_set_ulong("bootcount", bootcount); #endif /* !CONFIG_SPL_BUILD */ }
Quoted 8 lines
Quoted 2 lines
Also I suspect
bootcount_store()will fail at link time on boards where the bootcount is stored in ext4?I've run this patch set several times with travis-CI. No errors were present (the travis-ci link is in the cover letter).
Maybe there are some out of tree boards, which use the bootcount in some "odd" way....
I'm only really aware of the ext4 stuff from when I picked through it to consolidate the bootcount into Kconfig. I don't think there would be any Travis failures for this case as you need to have bootcount in SPL which you can't have before this series. If I try building a board like this (choose ext4 for the bootcount) and it fails to link:
drivers/built-in.o: In function `bootcount_store':u-boot/drivers/bootcount/bootcount_ext.c:18: undefined reference to fs_set_blk_dev' u-boot/drivers/bootcount/bootcount_ext.c:29: undefined reference to fs_write'drivers/built-in.o: In function `bootcount_load':u-boot/drivers/bootcount/bootcount_ext.c:41: undefined reference to fs_set_blk_dev' u-boot/drivers/bootcount/bootcount_ext.c:47: undefined reference to fs_read'
But having just played around with Kconfig a bit for this case, I'm not sure there's anything that's actually any better than a link time error; anything we did in Kconfig would just end up modelling out that link error.
Signature · 1 line
Alex Kiernan
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
Hi Alex,
Quoted 122 lines · Lukasz Majewski
Quoted 120 lines
Quoted 105 lines · On Tue, 08 May 2018 05:15:13 +0000 Alex Kiernan <[email protected]> wrote:
Quoted 12 lines · Lukasz Majewski
Those two functions can be used to provide easy bootcount management.
Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Tom Rini <[email protected]>Reviewed-by Stefan Roese <[email protected]>---
Changes in v5:
- Provide parenthesis for #if defined(FOO) && ...Quoted 9 lines
Changes in v4:
- Remove enumbootcount_contextand replace it with checkinggd_t->flags(TheGD_FLG_SPL_INITis only set in SPL, it is cleared in u-boot proper, so can be used as indication if we are in u-boot or SPL).
- Do not callbootcount_store()twice when it is not needed.
- Callenv_set_ulong("bootcount", bootcount); only in NON SPL context - Boards withTINY_PRINTF(in newest mainline) will build break as thisfunction
Quoted 20 lines
requires
simple_itoa()fromvsprintf.c(now not always build
in SPL).Changes in v3:
- Unify those functions to also work withcommon/autoboot.ccode
- Add enumbootcount_contextto distinguish between u-boot proper and SPLChanges in v2:
- Noneinclude/bootcount.h | 47+++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
include/bootcount.h +0
-0include/bootcount.h line 14
Quoted 4 lines
include/bootcount.h +1
-0@@ -11,6 +11,8 @@#include <asm/io.h> #include <asm/byteorder.h> +#if defined(CONFIG_SPL_BOOTCOUNT_LIMIT) ||
defined(CONFIG_BOOTCOUNT_LIMIT)include/bootcount.h line 16
Quoted 2 lines
include/bootcount.h +1
-0+ #if !defined(CONFIG_SYS_BOOTCOUNT_LE) &&!defined(CONFIG_SYS_BOOTCOUNT_BE)
Quoted 4 lines
include/bootcount.h +0
-0# if __BYTE_ORDER == __LITTLE_ENDIAN# define CONFIG_SYS_BOOTCOUNT_LE @@ -40,4 +42,49 @@ static inline u32 raw_bootcount_load(volatileu32
*addr)
Quoted 35 lines
return in_be32(addr);}
#endifinclude/bootcount.h +6
-0+ +DECLARE_GLOBAL_DATA_PTR ; +static inline int bootcount_error (void ) +{ +unsigned long bootcount =bootcount_load (); + unsigned long bootlimit = env_get_ulong("bootlimit",10, 0); +
include/bootcount.h +2
-0+if (bootlimit && bootcount > bootlimit) { + printf("Warning: Bootlimit (%lu) exceeded.",bootlimit);
include/bootcount.h +21
-0+if (!(gd->flags &GD_FLG_SPL_INIT )) +printf (" Using altbootcmd." ); +printf ("\n" ); + +return 1 ; + } + +return 0 ; +} + +static inline void bootcount_inc (void ) +{ +unsigned long bootcount =bootcount_load (); + +if (gd->flags &GD_FLG_SPL_INIT ) { +bootcount_store (++bootcount); +return ; + } + +#ifndef CONFIG_SPL_BUILD +/* Only increment bootcount when no bootcount support in SPL */ +#ifndef
CONFIG_SPL_BOOTCOUNT_LIMITinclude/bootcount.h static inline u32 raw_bootcount_load(volatile u32 *addr) · line 81
Quoted 6 lines
include/bootcount.h +6
-0+bootcount_store (++bootcount); +#endif +env_set_ulong ("bootcount" , bootcount); +#endif /* !CONFIG_SPL_BUILD */ +} +I'm kinda confused by this code... isn't this equivalent.?
static inline void bootcount_inc(void) { unsigned long bootcount = bootcount_load();Quoted 8 lines
bootcount_store(++bootcount); #ifndef CONFIG_SPL_BUILD env_set_ulong("bootcount", bootcount); #endif /* !CONFIG_SPL_BUILD */ }Also I suspect
bootcount_store()will fail at link time on boards where the bootcount is stored in ext4?I've run this patch set several times with travis-CI. No errors were present (the travis-ci link is in the cover letter).
Quoted 8 lines
Quoted 2 lines
Maybe there are some out of tree boards, which use the bootcount in some "odd" way....
I'm only really aware of the ext4 stuff from when I picked through it to consolidate the bootcount into
Kconfig. I don't think there would be any Travis failures for this case as you need to have bootcount in SPL which you can't have before this series.
Could you be more specific here?
This series adds support for bootcount in SPL. The travis-CI tests which I've performed were correct for the all boards which use it:
https://travis-ci.org/lmajewski/u-boot-dfu/builds/373639971
The bootcount_inc() is added in generic SPL code - this seems to work on all boards - boards which don't define CONFIG_SPL_BOOTCOUNT will just return from it.
However, I don't know how the code will behave if one would like to add ext4 support to it (including ext4 support to SPL).
I suppose that those boards will not enable SPL BOOTCOUNT in SPL and use the code as it is now - just in u-boot.
This patch series was designed with one main use case in mind - the "falcon" boot of Linux from SPL with bootcount support.
Quoted 14 lines
If I try building a
board like this (choose ext4 for the bootcount) and it fails to link:
drivers/built-in.o: In function `bootcount_store':u-boot/drivers/bootcount/bootcount_ext.c:18: undefined reference tofs_set_blk_dev' u-boot/drivers/bootcount/bootcount_ext.c:29: undefined reference tofs_write'drivers/built-in.o: In function `bootcount_load':u-boot/drivers/bootcount/bootcount_ext.c:41: undefined reference tofs_set_blk_dev' u-boot/drivers/bootcount/bootcount_ext.c:47: undefined reference tofs_read'
Quoted 5 lines
But having just played around with
Kconfiga bit for this case, I'm not sure there's anything that's actually any better than a link time error; anything we did inKconfigwould just end up modelling out that link error.
Could you share which particular board this breaks? I've tested it on Beagle Bone Black (and display5).
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180508/23d18e25/attachment.sig>
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
Quoted 167 lines · Lukasz Majewski
Hi Alex,
Quoted 122 lines · Lukasz Majewski
Quoted 120 lines
Quoted 105 lines · On Tue, 08 May 2018 05:15:13 +0000 Alex Kiernan <[email protected]> wrote:
Quoted 12 lines · Lukasz Majewski
Those two functions can be used to provide easy bootcount management.
Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Tom Rini <[email protected]>Reviewed-by Stefan Roese <[email protected]>---
Changes in v5:
- Provide parenthesis for #if defined(FOO) && ...Quoted 9 lines
Changes in v4:
- Remove enumbootcount_contextand replace it with checkinggd_t->flags(TheGD_FLG_SPL_INITis only set in SPL, it is cleared in u-boot proper, so can be used as indication if we are in u-boot or SPL).
- Do not callbootcount_store()twice when it is not needed.
- Callenv_set_ulong("bootcount", bootcount); only in NON SPL context - Boards withTINY_PRINTF(in newest mainline) will build break as thisfunction
Quoted 20 lines
requires
simple_itoa()fromvsprintf.c(now not always build
in SPL).Changes in v3:
- Unify those functions to also work withcommon/autoboot.ccode
- Add enumbootcount_contextto distinguish between u-boot proper and SPLChanges in v2:
- Noneinclude/bootcount.h | 47+++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
include/bootcount.h +0
-0include/bootcount.h line 14
Quoted 4 lines
include/bootcount.h +1
-0@@ -11,6 +11,8 @@#include <asm/io.h> #include <asm/byteorder.h> +#if defined(CONFIG_SPL_BOOTCOUNT_LIMIT) ||
defined(CONFIG_BOOTCOUNT_LIMIT)include/bootcount.h line 16
Quoted 2 lines
include/bootcount.h +1
-0+ #if !defined(CONFIG_SYS_BOOTCOUNT_LE) &&!defined(CONFIG_SYS_BOOTCOUNT_BE)
Quoted 4 lines
include/bootcount.h +0
-0# if __BYTE_ORDER == __LITTLE_ENDIAN# define CONFIG_SYS_BOOTCOUNT_LE @@ -40,4 +42,49 @@ static inline u32 raw_bootcount_load(volatileu32
*addr)
Quoted 35 lines
return in_be32(addr);}
#endifinclude/bootcount.h +6
-0+ +DECLARE_GLOBAL_DATA_PTR ; +static inline int bootcount_error (void ) +{ +unsigned long bootcount =bootcount_load (); + unsigned long bootlimit = env_get_ulong("bootlimit",10, 0); +
include/bootcount.h +2
-0+if (bootlimit && bootcount > bootlimit) { + printf("Warning: Bootlimit (%lu) exceeded.",bootlimit);
include/bootcount.h +21
-0+if (!(gd->flags &GD_FLG_SPL_INIT )) +printf (" Using altbootcmd." ); +printf ("\n" ); + +return 1 ; + } + +return 0 ; +} + +static inline void bootcount_inc (void ) +{ +unsigned long bootcount =bootcount_load (); + +if (gd->flags &GD_FLG_SPL_INIT ) { +bootcount_store (++bootcount); +return ; + } + +#ifndef CONFIG_SPL_BUILD +/* Only increment bootcount when no bootcount support in SPL */ +#ifndef
CONFIG_SPL_BOOTCOUNT_LIMITinclude/bootcount.h static inline u32 raw_bootcount_load(volatile u32 *addr) · line 81
Quoted 6 lines
include/bootcount.h +6
-0+bootcount_store (++bootcount); +#endif +env_set_ulong ("bootcount" , bootcount); +#endif /* !CONFIG_SPL_BUILD */ +} +I'm kinda confused by this code... isn't this equivalent.?
static inline void bootcount_inc(void) { unsigned long bootcount = bootcount_load();Quoted 8 lines
bootcount_store(++bootcount); #ifndef CONFIG_SPL_BUILD env_set_ulong("bootcount", bootcount); #endif /* !CONFIG_SPL_BUILD */ }Also I suspect
bootcount_store()will fail at link time on boards where the bootcount is stored in ext4?I've run this patch set several times with travis-CI. No errors were present (the travis-ci link is in the cover letter).
Quoted 8 lines
Quoted 2 lines
Maybe there are some out of tree boards, which use the bootcount in some "odd" way....
I'm only really aware of the ext4 stuff from when I picked through it to consolidate the bootcount into
Kconfig. I don't think there would be any Travis failures for this case as you need to have bootcount in SPL which you can't have before this series.Could you be more specific here?
This series adds support for bootcount in SPL. The travis-CI tests which I've performed were correct for the all boards which use it:
https://travis-ci.org/lmajewski/u-boot-dfu/builds/373639971
The
bootcount_inc()is added in generic SPL code - this seems to work on all boards - boards which don't defineCONFIG_SPL_BOOTCOUNTwill just return from it.However, I don't know how the code will behave if one would like to add ext4 support to it (including ext4 support to SPL).
I suppose that those boards will not enable SPL BOOTCOUNT in SPL and use the code as it is now - just in u-boot.
This patch series was designed with one main use case in mind - the "falcon" boot of Linux from SPL with bootcount support.
Quoted 14 lines
If I try building a
board like this (choose ext4 for the bootcount) and it fails to link:
drivers/built-in.o: In function `bootcount_store':u-boot/drivers/bootcount/bootcount_ext.c:18: undefined reference tofs_set_blk_dev' u-boot/drivers/bootcount/bootcount_ext.c:29: undefined reference tofs_write'drivers/built-in.o: In function `bootcount_load':u-boot/drivers/bootcount/bootcount_ext.c:41: undefined reference tofs_set_blk_dev' u-boot/drivers/bootcount/bootcount_ext.c:47: undefined reference tofs_read'
Quoted 8 lines
Quoted 5 lines
But having just played around with
Kconfiga bit for this case, I'm not sure there's anything that's actually any better than a link time error; anything we did inKconfigwould just end up modelling out that link error.Could you share which particular board this breaks? I've tested it on Beagle Bone Black (and display5).
There isn't one (at least not one I'm aware of), but this gives another impossible combination which you can select, of which we've lots already.
I should've played around some more before commenting as I think what you've got is everything that's needed.
--
Alex Kiernan
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
Hi Alex,
Quoted 182 lines · Lukasz Majewski
Quoted 171 lines
Hi Alex,
Quoted 127 lines
Quoted 115 lines · Lukasz Majewski
Quoted 112 lines · On Tue, 08 May 2018 05:15:13 +0000 Alex Kiernan <[email protected]> wrote:
Quoted 12 lines · Lukasz Majewski
Those two functions can be used to provide easy bootcount management.
Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Tom Rini <[email protected]>Reviewed-by Stefan Roese <[email protected]>---
Changes in v5:
- Provide parenthesis for #if defined(FOO) && ...Quoted 9 lines
Changes in v4:
- Remove enumbootcount_contextand replace it with checkinggd_t->flags(TheGD_FLG_SPL_INITis only set in SPL, it is cleared in u-boot proper, so can be used as indication if we are in u-boot or SPL).
- Do not callbootcount_store()twice when it is not needed.
- Callenv_set_ulong("bootcount", bootcount); only in NON SPL context - Boards withTINY_PRINTF(in newest mainline) will build break as thisfunction
Quoted 21 lines
requires
simple_itoa()fromvsprintf.c(now not always
build in SPL).Changes in v3:
- Unify those functions to also work withcommon/autoboot.ccode
- Add enumbootcount_contextto distinguish between u-boot proper and SPLChanges in v2:
- Noneinclude/bootcount.h | 47+++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
include/bootcount.h +0
-0include/bootcount.h line 14
Quoted 4 lines
include/bootcount.h +1
-0@@ -11,6 +11,8 @@#include <asm/io.h> #include <asm/byteorder.h> +#if defined(CONFIG_SPL_BOOTCOUNT_LIMIT) ||
defined(CONFIG_BOOTCOUNT_LIMIT)include/bootcount.h line 16
Quoted 2 lines
include/bootcount.h +1
-0+ #if !defined(CONFIG_SYS_BOOTCOUNT_LE) &&!defined(CONFIG_SYS_BOOTCOUNT_BE)
Quoted 4 lines
include/bootcount.h +0
-0# if __BYTE_ORDER == __LITTLE_ENDIAN# define CONFIG_SYS_BOOTCOUNT_LE @@ -40,4 +42,49 @@ static inline u32raw_bootcount_load(volatile u32
*addr)
Quoted 35 lines
return in_be32(addr);}
#endifinclude/bootcount.h +6
-0+ +DECLARE_GLOBAL_DATA_PTR ; +static inline int bootcount_error (void ) +{ +unsigned long bootcount =bootcount_load (); + unsigned long bootlimit = env_get_ulong("bootlimit",10, 0); +
include/bootcount.h +2
-0+if (bootlimit && bootcount > bootlimit) { + printf("Warning: Bootlimit (%lu) exceeded.",bootlimit);
include/bootcount.h +21
-0+if (!(gd->flags &GD_FLG_SPL_INIT )) +printf (" Using altbootcmd." ); +printf ("\n" ); + +return 1 ; + } + +return 0 ; +} + +static inline void bootcount_inc (void ) +{ +unsigned long bootcount =bootcount_load (); + +if (gd->flags &GD_FLG_SPL_INIT ) { +bootcount_store (++bootcount); +return ; + } + +#ifndef CONFIG_SPL_BUILD +/* Only increment bootcount when no bootcount support in SPL */ +#ifndef
CONFIG_SPL_BOOTCOUNT_LIMITinclude/bootcount.h static inline u32 raw_bootcount_load(volatile u32 *addr) · line 81
Quoted 6 lines
include/bootcount.h +6
-0+bootcount_store (++bootcount); +#endif +env_set_ulong ("bootcount" , bootcount); +#endif /* !CONFIG_SPL_BUILD */ +} +I'm kinda confused by this code... isn't this equivalent.?
static inline void bootcount_inc(void) { unsigned long bootcount = bootcount_load();bootcount_store(++bootcount); #ifndef CONFIG_SPL_BUILD env_set_ulong("bootcount", bootcount); #endif /* !CONFIG_SPL_BUILD */ }Quoted 8 lines
Quoted 2 lines
Also I suspect
bootcount_store()will fail at link time on boards where the bootcount is stored in ext4?I've run this patch set several times with travis-CI. No errors were present (the travis-ci link is in the cover letter).
Maybe there are some out of tree boards, which use the bootcount in some "odd" way....
Quoted 5 lines
I'm only really aware of the ext4 stuff from when I picked through it to consolidate the bootcount into
Kconfig. I don't think there would be any Travis failures for this case as you need to have bootcount in SPL which you can't have before this series.Could you be more specific here?
This series adds support for bootcount in SPL. The travis-CI tests which I've performed were correct for the all boards which use it:
https://travis-ci.org/lmajewski/u-boot-dfu/builds/373639971
The
bootcount_inc()is added in generic SPL code - this seems to work on all boards - boards which don't defineCONFIG_SPL_BOOTCOUNTwill just return from it.However, I don't know how the code will behave if one would like to add ext4 support to it (including ext4 support to SPL).
I suppose that those boards will not enable SPL BOOTCOUNT in SPL and use the code as it is now - just in u-boot.
This patch series was designed with one main use case in mind - the "falcon" boot of Linux from SPL with bootcount support.
Quoted 15 lines
If I try building a
board like this (choose ext4 for the bootcount) and it fails to link:
drivers/built-in.o: In function `bootcount_store':u-boot/drivers/bootcount/bootcount_ext.c:18: undefined reference tofs_set_blk_dev' u-boot/drivers/bootcount/bootcount_ext.c:29: undefined reference tofs_write'drivers/built-in.o: In function `bootcount_load':u-boot/drivers/bootcount/bootcount_ext.c:41: undefined reference tofs_set_blk_dev' u-boot/drivers/bootcount/bootcount_ext.c:47: undefined reference tofs_read'Quoted 8 lines
Quoted 5 lines
But having just played around with
Kconfiga bit for this case, I'm not sure there's anything that's actually any better than a link time error; anything we did inKconfigwould just end up modelling out that link error.Could you share which particular board this breaks? I've tested it on Beagle Bone Black (and display5).
Quoted 6 lines
There isn't one (at least not one I'm aware of), but this gives another impossible combination which you can select, of which we've lots already.
I should've played around some more before commenting as I think what you've got is everything that's needed.
It is all the matter of use-case.
For SPL I've assumed that we will use IRAM or some RTC special register (as it is with display5) to store the bootcount (all info - magic number with boot count in 32 bits).
This seems logical and optimal - since we "assume" that SPL shall be possible small.
To avoid coincidence one needs to define CONFIG_SPL_BOOTCOUNT. Without it we shall have the same behaviour as previously on all supported boards (in theory at least :-) ).
Quoted 3 lines
--
Alex Kiernan
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180508/70302480/attachment.sig>
PATCH v5 3/7 bootcount: Add function wrappers to handle bootcount increment and error checking
In reply to Lukasz MajewskiQuoted 6 lines · Lukasz Majewski
Those two functions can be used to provide easy bootcount management.
Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Tom Rini <[email protected]>Reviewed-by Stefan Roese <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180511/a02ae71e/attachment.sig>
PATCH v5 4/7 bootcount: Rewrite autoboot to use wrapper functions from bootcount.h
In reply to Lukasz MajewskiThe code has been refactored to use common wrappers from bootcount.h header.
---
Changes in v5:
- None
Changes in v4:
- Use global data pointer (gd_t *) instead of bootcount specific enum
Changes in v3:
- New patch
Changes in v2: None
common/autoboot.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-)
common/autoboot.c +5 -18
@@ -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 (); 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 ()) s =env_get ("altbootcmd" ); - } else -#endif /* CONFIG_BOOTCOUNT_LIMIT */ +else s =env_get ("bootcmd" );process_fdt_options (gd->fdt_blob);
Signature · 1 line
2.11.0
PATCH v5 4/7 bootcount: Rewrite autoboot to use wrapper functions from bootcount.h
Quoted 6 lines · Lukasz Majewski
The code has been refactored to use common wrappers from
bootcount.hheader.Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Tom Rini <[email protected]>
Quoted 39 lines
---
Changes in v5:
- NoneChanges in v4:
- Use global data pointer (gd_t*) instead of bootcount specific enumChanges in v3:
- New patchChanges in v2: None
common/autoboot.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-)common/autoboot.c +1
-7@@ -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 ();
common/autoboot.c const char *bootdelay_process(void) · line 299
Quoted 10 lines
common/autoboot.c +2
-5- bootcount++; -bootcount_store (bootcount); -env_set_ulong ("bootcount" , bootcount); - bootlimit =env_get_ulong ("bootlimit" ,10 ,0 ); -#endif /* CONFIG_BOOTCOUNT_LIMIT */ + +bootcount_inc (); s =env_get ("bootdelay" ); bootdelay = s ? (int)simple_strtol(s, NULL, 10) :
CONFIG_BOOTDELAY;
common/autoboot.c const char *bootdelay_process(void) · line 329
Quoted 7 lines
common/autoboot.c +0
-3@@ -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",
Quoted 11 lines
common/autoboot.c +2
-4- (unsigned)bootlimit); +if (bootcount_error ()) s =env_get ("altbootcmd" ); - } else -#endif /* CONFIG_BOOTCOUNT_LIMIT */ +else s =env_get ("bootcmd" );process_fdt_options (gd->fdt_blob); --2.11.0
Signature · 1 line
Alex Kiernan
PATCH v5 4/7 bootcount: Rewrite autoboot to use wrapper functions from bootcount.h
In reply to Lukasz MajewskiQuoted 7 lines · Lukasz Majewski
The code has been refactored to use common wrappers from
bootcount.hheader.Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Tom Rini <[email protected]>Reviewed-by Alex Kiernan <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180511/a58093c1/attachment.sig>
PATCH v5 5/7 bootcount: spl: Extend SPL to support bootcount incrementation
In reply to Lukasz MajewskiThis patch adds support for incrementation of the bootcount in SPL. Such feature is necessary when we do want to use this feature with 'falcon' boot mode (which loads OS directly in SPL).
---
Changes in v5:
- None
Changes in v4:
- Use gd_t global data pointer instead of bootcount specific enum
Changes in v3:
- Remove not needed #ifdefs
- Add enum bootcount_context parameter to bootcount_inc() function
Changes in v2:
- New patch - as suggested by Stefan Roese - bootcount_inc() is called in common SPL code (./common/spl/spl.c), so other boards can also reuse it without modification
common/spl/spl.c | 3 +++ 1 file changed, 3 insertions(+)
common/spl/spl.c +3 -0
@@ -20,6 +20,7 @@#include <dm/root.h> #include <linux/compiler.h> #include <fdt_support.h> +#include <bootcount.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -417,6 +418,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)spl_board_init ();#endif +bootcount_inc (); +memset (&spl_image,'\0' ,sizeof (spl_image));#ifdef CONFIG_SYS_SPL_ARGS_ADDR spl_image.arg = (void *)CONFIG_SYS_SPL_ARGS_ADDR ;
Signature · 1 line
2.11.0
PATCH v5 5/7 bootcount: spl: Extend SPL to support bootcount incrementation
Quoted 7 lines · Lukasz Majewski
This patch adds support for incrementation of the bootcount in SPL. Such feature is necessary when we do want to use this feature with 'falcon' boot mode (which loads OS directly in SPL).
Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180511/08703d99/attachment.sig>
PATCH v5 6/7 bootcount: display5: spl: Extend DISPLAY5 board SPL to support bootcount checking
In reply to Lukasz MajewskiThis patch is necessary for providing basic bootcount checking in the case of using "falcon" boot mode in that board.
It forces u-boot proper boot, when we exceed the number of errors.
---
Changes in v5:
- None
Changes in v4:
- Use global data pointer (gd) instead of bootcount specific enum (SPL)
Changes in v3:
- The bootcount_error now accepts enum bootcount_error input parameter
Changes in v2:
- Remove bootcount_init() from SPL specific board code
board/liebherr/display5/spl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
board/liebherr/display5/spl.c +2 -1
@@ -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 (); }
Signature · 1 line
2.11.0
PATCH v5 6/7 bootcount: display5: spl: Extend DISPLAY5 board SPL to support bootcount checking
Quoted 7 lines · Lukasz Majewski
This patch is necessary for providing basic bootcount checking in the case of using "falcon" boot mode in that board.
It forces u-boot proper boot, when we exceed the number of errors.
Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Stefan Roese <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180511/c2902733/attachment.sig>
PATCH v5 7/7 bootcount: display5: config: Enable boot count feature in the display5 board
In reply to Lukasz MajewskiThe boot count is enabled in both SPL and proper u-boot.
---
Changes in v5:
- None
Changes in v4:
- None
Changes in v3:
- None
Changes in v2:
- None
configs/display5_defconfig | 4 ++++ 1 file changed, 4 insertions(+)
configs/display5_defconfig +4 -0
@@ -16,6 +16,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_SUPPORT_RAW_INITRD=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
@@ -53,6 +54,9 @@ CONFIG_EFI_PARTITION=y CONFIG_OF_CONTROL=y CONFIG_ENV_IS_IN_SPI_FLASH=y CONFIG_FSL_ESDHC=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
PATCH v5 7/7 bootcount: display5: config: Enable boot count feature in the display5 board
Quoted 4 lines · Lukasz Majewski
The boot count is enabled in both SPL and proper u-boot.
Signed-off-by Lukasz Majewski <[email protected]>Reviewed-by Stefan Roese <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180511/7c741185/attachment.sig>