diff mbox series

[19/19] hash: Plumb crc8 into the hash functions

Message ID 20240829145802.1827952-20-sjg@chromium.org
State Changes Requested
Delegated to: Tom Rini
Headers show
Series vbe: Series part E | expand

Commit Message

Simon Glass Aug. 29, 2024, 2:58 p.m. UTC
Add an entry for crc8, with watchdog handling.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/hash.c        | 8 ++++++++
 include/u-boot/crc.h | 3 +++
 lib/crc8.c           | 6 ++++++
 3 files changed, 17 insertions(+)

Comments

Peter Robinson Aug. 30, 2024, 12:17 p.m. UTC | #1
On Thu, 29 Aug 2024 at 16:02, Simon Glass <sjg@chromium.org> wrote:
>
> Add an entry for crc8, with watchdog handling.

What's the watchdog handling do? What's this used for?

Looking at the use of crc8 it's minimally used.

> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  common/hash.c        | 8 ++++++++
>  include/u-boot/crc.h | 3 +++
>  lib/crc8.c           | 6 ++++++
>  3 files changed, 17 insertions(+)
>
> diff --git a/common/hash.c b/common/hash.c
> index ac63803fed9..43c4e185750 100644
> --- a/common/hash.c
> +++ b/common/hash.c
> @@ -304,6 +304,14 @@ static struct hash_algo hash_algo[] = {
>                 .hash_update    = hash_update_crc16_ccitt,
>                 .hash_finish    = hash_finish_crc16_ccitt,
>         },
> +#if CONFIG_IS_ENABLED(CRC8)
> +       {
> +               .name           = "crc8",
> +               .digest_size    = 1,
> +               .chunk_size     = CHUNKSZ_CRC32,
> +               .hash_func_ws   = crc8_wd_buf,
> +       },
> +#endif
>  #if CONFIG_IS_ENABLED(CRC32)
>         {
>                 .name           = "crc32",
> diff --git a/include/u-boot/crc.h b/include/u-boot/crc.h
> index 5174bd7ac41..b2badaf6a97 100644
> --- a/include/u-boot/crc.h
> +++ b/include/u-boot/crc.h
> @@ -25,6 +25,9 @@
>   */
>  unsigned int crc8(unsigned int crc_start, const unsigned char *vptr, int len);
>
> +void crc8_wd_buf(const unsigned char *input, unsigned int len,
> +                unsigned char output[1], unsigned int chunk_sz);
> +
>  /* lib/crc16.c - 16 bit CRC with polynomial x^16 + x^15 + x^2 + 1 */
>  uint16_t crc16(uint16_t crc, const unsigned char *buffer, size_t len);
>
> diff --git a/lib/crc8.c b/lib/crc8.c
> index 20d46d16147..811e19917b4 100644
> --- a/lib/crc8.c
> +++ b/lib/crc8.c
> @@ -32,3 +32,9 @@ unsigned int crc8(unsigned int crc, const unsigned char *vptr, int len)
>
>         return crc;
>  }
> +
> +void crc8_wd_buf(const unsigned char *input, unsigned int len,
> +                unsigned char output[1], unsigned int chunk_sz)
> +{
> +       *output = crc8(0, input, len);
> +}
> --
> 2.34.1
>
Simon Glass Sept. 1, 2024, 8:09 p.m. UTC | #2
Hi Peter,

On Fri, 30 Aug 2024 at 06:17, Peter Robinson <pbrobinson@gmail.com> wrote:
>
> On Thu, 29 Aug 2024 at 16:02, Simon Glass <sjg@chromium.org> wrote:
> >
> > Add an entry for crc8, with watchdog handling.
>
> What's the watchdog handling do? What's this used for?

It does the hashing in chunks and touches the watchdog after every
chunk, to avoid the board resetting.

>
> Looking at the use of crc8 it's minimally used.

Yes, it's a cheap algorithm which provides some protection, so I am
using it in the VBE relocating loader (to come).

>
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> >  common/hash.c        | 8 ++++++++
> >  include/u-boot/crc.h | 3 +++
> >  lib/crc8.c           | 6 ++++++
> >  3 files changed, 17 insertions(+)
> >
> > diff --git a/common/hash.c b/common/hash.c
> > index ac63803fed9..43c4e185750 100644
> > --- a/common/hash.c
> > +++ b/common/hash.c
> > @@ -304,6 +304,14 @@ static struct hash_algo hash_algo[] = {
> >                 .hash_update    = hash_update_crc16_ccitt,
> >                 .hash_finish    = hash_finish_crc16_ccitt,
> >         },
> > +#if CONFIG_IS_ENABLED(CRC8)
> > +       {
> > +               .name           = "crc8",
> > +               .digest_size    = 1,
> > +               .chunk_size     = CHUNKSZ_CRC32,
> > +               .hash_func_ws   = crc8_wd_buf,
> > +       },
> > +#endif
> >  #if CONFIG_IS_ENABLED(CRC32)
> >         {
> >                 .name           = "crc32",
> > diff --git a/include/u-boot/crc.h b/include/u-boot/crc.h
> > index 5174bd7ac41..b2badaf6a97 100644
> > --- a/include/u-boot/crc.h
> > +++ b/include/u-boot/crc.h
> > @@ -25,6 +25,9 @@
> >   */
> >  unsigned int crc8(unsigned int crc_start, const unsigned char *vptr, int len);
> >
> > +void crc8_wd_buf(const unsigned char *input, unsigned int len,
> > +                unsigned char output[1], unsigned int chunk_sz);
> > +
> >  /* lib/crc16.c - 16 bit CRC with polynomial x^16 + x^15 + x^2 + 1 */
> >  uint16_t crc16(uint16_t crc, const unsigned char *buffer, size_t len);
> >
> > diff --git a/lib/crc8.c b/lib/crc8.c
> > index 20d46d16147..811e19917b4 100644
> > --- a/lib/crc8.c
> > +++ b/lib/crc8.c
> > @@ -32,3 +32,9 @@ unsigned int crc8(unsigned int crc, const unsigned char *vptr, int len)
> >
> >         return crc;
> >  }
> > +
> > +void crc8_wd_buf(const unsigned char *input, unsigned int len,
> > +                unsigned char output[1], unsigned int chunk_sz)
> > +{
> > +       *output = crc8(0, input, len);
> > +}
> > --
> > 2.34.1
> >

Regards,
Simon
diff mbox series

Patch

diff --git a/common/hash.c b/common/hash.c
index ac63803fed9..43c4e185750 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -304,6 +304,14 @@  static struct hash_algo hash_algo[] = {
 		.hash_update	= hash_update_crc16_ccitt,
 		.hash_finish	= hash_finish_crc16_ccitt,
 	},
+#if CONFIG_IS_ENABLED(CRC8)
+	{
+		.name		= "crc8",
+		.digest_size	= 1,
+		.chunk_size	= CHUNKSZ_CRC32,
+		.hash_func_ws	= crc8_wd_buf,
+	},
+#endif
 #if CONFIG_IS_ENABLED(CRC32)
 	{
 		.name		= "crc32",
diff --git a/include/u-boot/crc.h b/include/u-boot/crc.h
index 5174bd7ac41..b2badaf6a97 100644
--- a/include/u-boot/crc.h
+++ b/include/u-boot/crc.h
@@ -25,6 +25,9 @@ 
  */
 unsigned int crc8(unsigned int crc_start, const unsigned char *vptr, int len);
 
+void crc8_wd_buf(const unsigned char *input, unsigned int len,
+		 unsigned char output[1], unsigned int chunk_sz);
+
 /* lib/crc16.c - 16 bit CRC with polynomial x^16 + x^15 + x^2 + 1 */
 uint16_t crc16(uint16_t crc, const unsigned char *buffer, size_t len);
 
diff --git a/lib/crc8.c b/lib/crc8.c
index 20d46d16147..811e19917b4 100644
--- a/lib/crc8.c
+++ b/lib/crc8.c
@@ -32,3 +32,9 @@  unsigned int crc8(unsigned int crc, const unsigned char *vptr, int len)
 
 	return crc;
 }
+
+void crc8_wd_buf(const unsigned char *input, unsigned int len,
+		 unsigned char output[1], unsigned int chunk_sz)
+{
+	*output = crc8(0, input, len);
+}