From: Lukasz Majewski Date: Tue, 8 May 2018 09:38:45 +0200 Subject: [U-Boot] [PATCH v5 3/7] bootcount: Add function wrappers to handle bootcount increment and error checking In-Reply-To: <694bc944-3453-1305-ff70-564c3670c07c@denx.de> References: <20180502141056.23937-1-lukma@denx.de> <20180502141056.23937-4-lukma@denx.de> <694bc944-3453-1305-ff70-564c3670c07c@denx.de> Message-ID: <20180508093845.003332de@jawa> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Alex, Stefan, > On 08.05.2018 08:58, Alex Kiernan wrote: > > > > >>> +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 */ > >>> +} > >>> + > > > >> 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 */ > >> } > > > > 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. > > 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 > > 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: