All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 3/7] bootcount: Add function wrappers to handle bootcount increment and error checking
Date: Wed, 21 Mar 2018 11:07:18 +0100	[thread overview]
Message-ID: <20180321110718.326a2034@jawa> (raw)
In-Reply-To: <857eafd0-a089-50e2-f4f7-df69fb07def6@denx.de>

Hi Stefan,

> On 14.03.2018 18:24, Lukasz Majewski wrote:
> > Those two functions can be used to provide easy bootcount
> > management.
> > 
> > Signed-off-by: Lukasz Majewski <lukma@denx.de>
> > 
> > ---
> > 
> > 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);
> > +}  
> 
> Why not:
> 
> static inline void bootcount_inc(void)
> {
> 	bootcount_store(bootcount_load() + 1);
> }
> 
> instead ?

+1

> 
> > +#else
> > +static inline bool bootcount_error(void) { return false; }
> > +static inline void bootcount_inc(void) {}
> > +#endif /* CONFIG_SPL_BOOTCOUNT_LIMIT */
> >   #endif /* _BOOTCOUNT_H__ */  
> 
> And can't you use these helper functions in proper U-Boot as well
> (common/autoboot.c). Looking at this old code there, there is also
> room for improvement
> - perhaps as a new patch in this series. ;)

It would be best to have it on top of this series - as other patches
depends on it....

But, OK I will check if this can be done.

Thanks for hint.

> 
> 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/20180321/45cce358/attachment.sig>

  reply	other threads:[~2018-03-21 10:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-14 17:24 [U-Boot] [PATCH v2 0/7] Provide SPL support for bootcount (in the case of using falcon boot mode) Lukasz Majewski
2018-03-14 17:24 ` [U-Boot] [PATCH v2 1/7] bootcount: spl: Enable bootcount support in SPL Lukasz Majewski
2018-03-21 10:19   ` Stefan Roese
2018-03-14 17:24 ` [U-Boot] [PATCH v2 2/7] bootcount: Add include guards into bootcount.h file Lukasz Majewski
2018-03-21 10:01   ` Stefan Roese
2018-03-14 17:24 ` [U-Boot] [PATCH v2 3/7] bootcount: Add function wrappers to handle bootcount increment and error checking Lukasz Majewski
2018-03-21 10:00   ` Stefan Roese
2018-03-21 10:07     ` Lukasz Majewski [this message]
2018-03-14 17:24 ` [U-Boot] [PATCH v2 4/7] bootcount: u-boot: Do not increment bootcount if already done in SPL Lukasz Majewski
2018-03-21 10:06   ` Stefan Roese
2018-03-14 17:24 ` [U-Boot] [PATCH v2 5/7] bootcount: spl: Extend SPL to support bootcount incrementation Lukasz Majewski
2018-03-21 10:20   ` Stefan Roese
2018-03-21 11:31     ` Lukasz Majewski
2018-03-14 17:24 ` [U-Boot] [PATCH v2 6/7] bootcount: display5: spl: Extend DISPLAY5 board SPL to support bootcount checking Lukasz Majewski
2018-03-21 10:10   ` Stefan Roese
2018-03-14 17:24 ` [U-Boot] [PATCH v2 7/7] bootcount: display5: config: Enable boot count feature in the display5 board Lukasz Majewski
2018-03-21 10:11   ` Stefan Roese

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=20180321110718.326a2034@jawa \
    --to=lukma@denx.de \
    --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.