diff mbox

[U-Boot,v2,3/14] bch: Allow to build for the host

Message ID 3367aba903accff9a9a11f5fabce4eebf348a99d.1479817585.git-series.maxime.ripard@free-electrons.com
State Accepted
Commit 71d2c07028ce87d3aeca4e1220fb6dcbfd7bb22f
Delegated to: Jagannadha Sutradharudu Teki
Headers show

Commit Message

Maxime Ripard Nov. 22, 2016, 12:38 p.m. UTC
We will need the bch functions in the tool to generate the SPL images for
the Allwinner SoCs.

Do the needed adjustments so that we can use it on the host.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 lib/bch.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+), 0 deletions(-)

Comments

Tom Rini Nov. 22, 2016, 3:12 p.m. UTC | #1
On Tue, Nov 22, 2016 at 01:38:33PM +0100, Maxime Ripard wrote:

> We will need the bch functions in the tool to generate the SPL images for
> the Allwinner SoCs.
> 
> Do the needed adjustments so that we can use it on the host.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Jagan Teki Nov. 25, 2016, 5:05 p.m. UTC | #2
On Tue, Nov 22, 2016 at 6:08 PM, Maxime Ripard
<maxime.ripard@free-electrons.com> wrote:
> We will need the bch functions in the tool to generate the SPL images for
> the Allwinner SoCs.
>
> Do the needed adjustments so that we can use it on the host.
>
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> ---
>  lib/bch.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 48 insertions(+), 0 deletions(-)
>
> diff --git a/lib/bch.c b/lib/bch.c
> index 147715afd06a..ec53483774b5 100644
> --- a/lib/bch.c
> +++ b/lib/bch.c
> @@ -54,10 +54,27 @@
>   * finite fields GF(2^q). In Rapport de recherche INRIA no 2829, 1996.
>   */
>
> +#ifndef USE_HOSTCC
>  #include <common.h>
>  #include <ubi_uboot.h>
>
>  #include <linux/bitops.h>
> +#else
> +#include <errno.h>
> +#include <endian.h>
> +#include <stdint.h>
> +#include <stdlib.h>
> +#include <string.h>
> +
> +#undef cpu_to_be32
> +#define cpu_to_be32 htobe32
> +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
> +#define kmalloc(size, flags)   malloc(size)
> +#define kzalloc(size, flags)   calloc(1, size)
> +#define kfree free
> +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
> +#endif
> +
>  #include <asm/byteorder.h>
>  #include <linux/bch.h>
>
> @@ -95,6 +112,37 @@ struct gf_poly_deg1 {
>         unsigned int   c[2];
>  };
>
> +#ifdef USE_HOSTCC
> +static int fls(int x)
> +{

This look redundant definition to me,  can't we use this from
include/linux/bitops.h ?

thanks!
Maxime Ripard Nov. 29, 2016, 8:49 a.m. UTC | #3
On Fri, Nov 25, 2016 at 10:35:15PM +0530, Jagan Teki wrote:
> On Tue, Nov 22, 2016 at 6:08 PM, Maxime Ripard
> <maxime.ripard@free-electrons.com> wrote:
> > We will need the bch functions in the tool to generate the SPL images for
> > the Allwinner SoCs.
> >
> > Do the needed adjustments so that we can use it on the host.
> >
> > Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> > ---
> >  lib/bch.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 48 insertions(+), 0 deletions(-)
> >
> > diff --git a/lib/bch.c b/lib/bch.c
> > index 147715afd06a..ec53483774b5 100644
> > --- a/lib/bch.c
> > +++ b/lib/bch.c
> > @@ -54,10 +54,27 @@
> >   * finite fields GF(2^q). In Rapport de recherche INRIA no 2829, 1996.
> >   */
> >
> > +#ifndef USE_HOSTCC
> >  #include <common.h>
> >  #include <ubi_uboot.h>
> >
> >  #include <linux/bitops.h>
> > +#else
> > +#include <errno.h>
> > +#include <endian.h>
> > +#include <stdint.h>
> > +#include <stdlib.h>
> > +#include <string.h>
> > +
> > +#undef cpu_to_be32
> > +#define cpu_to_be32 htobe32
> > +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
> > +#define kmalloc(size, flags)   malloc(size)
> > +#define kzalloc(size, flags)   calloc(1, size)
> > +#define kfree free
> > +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
> > +#endif
> > +
> >  #include <asm/byteorder.h>
> >  #include <linux/bch.h>
> >
> > @@ -95,6 +112,37 @@ struct gf_poly_deg1 {
> >         unsigned int   c[2];
> >  };
> >
> > +#ifdef USE_HOSTCC
> > +static int fls(int x)
> > +{
> 
> This look redundant definition to me,  can't we use this from
> include/linux/bitops.h ?

This is compiled to run in userspace, linux/bitops.h isn't available
there.

Maxime
diff mbox

Patch

diff --git a/lib/bch.c b/lib/bch.c
index 147715afd06a..ec53483774b5 100644
--- a/lib/bch.c
+++ b/lib/bch.c
@@ -54,10 +54,27 @@ 
  * finite fields GF(2^q). In Rapport de recherche INRIA no 2829, 1996.
  */
 
+#ifndef USE_HOSTCC
 #include <common.h>
 #include <ubi_uboot.h>
 
 #include <linux/bitops.h>
+#else
+#include <errno.h>
+#include <endian.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#undef cpu_to_be32
+#define cpu_to_be32 htobe32
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#define kmalloc(size, flags)	malloc(size)
+#define kzalloc(size, flags)	calloc(1, size)
+#define kfree free
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
 #include <asm/byteorder.h>
 #include <linux/bch.h>
 
@@ -95,6 +112,37 @@  struct gf_poly_deg1 {
 	unsigned int   c[2];
 };
 
+#ifdef USE_HOSTCC
+static int fls(int x)
+{
+	int r = 32;
+
+	if (!x)
+		return 0;
+	if (!(x & 0xffff0000u)) {
+		x <<= 16;
+		r -= 16;
+	}
+	if (!(x & 0xff000000u)) {
+		x <<= 8;
+		r -= 8;
+	}
+	if (!(x & 0xf0000000u)) {
+		x <<= 4;
+		r -= 4;
+	}
+	if (!(x & 0xc0000000u)) {
+		x <<= 2;
+		r -= 2;
+	}
+	if (!(x & 0x80000000u)) {
+		x <<= 1;
+		r -= 1;
+	}
+	return r;
+}
+#endif
+
 /*
  * same as encode_bch(), but process input data one byte at a time
  */