From: Lukasz Majewski Date: Wed, 14 Mar 2018 18:24:45 +0100 Subject: [U-Boot] [PATCH v2 3/7] bootcount: Add function wrappers to handle bootcount increment and error checking In-Reply-To: <20180314172450.8385-1-lukma@denx.de> References: <20180314172450.8385-1-lukma@denx.de> Message-ID: <20180314172450.8385-4-lukma@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Those two functions can be used to provide easy bootcount management. Signed-off-by: Lukasz Majewski --- Changes in v2: - None include/bootcount.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/bootcount.h b/include/bootcount.h index e3b3f7028e..0ec9af6e2b 100644 --- a/include/bootcount.h +++ b/include/bootcount.h @@ -40,4 +40,29 @@ 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", bootlimit); + 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 */ #endif /* _BOOTCOUNT_H__ */ -- 2.11.0