Re: [U-Boot] [PATCH 4/7] tools: sunxi: Add spl image builder
On Mon, Nov 14, 2016 at 07:58:03PM +0100, Maxime Ripard wrote: > Hi, > > On Mon, Nov 14, 2016 at 10:25:27AM -0500, Tom Rini wrote: > > On Mon, Nov 14, 2016 at 04:20:49PM +0100, Maxime Ripard wrote: > > > On Fri, Nov 11, 2016 at 11:20:47AM -0500, Tom Rini wrote: > > > > On Tue, Nov 08, 2016 at 05:21:14PM +0100, Maxime Ripard wrote: > > > > > > > > > This program generates raw SPL images that can be flashed on the NAND > > > > > with > > > > > the ECC and randomizer properly set up. > > > > > > > > > > Signed-off-by: Maxime Ripard> > > > [snip] > > > > > +++ b/tools/sunxi-spl-image-builder.c > > > > > @@ -0,0 +1,1113 @@ > > > > > +/* > > > > > + * Generic binary BCH encoding/decoding library > > > > > > > > OK, but this is also lib/bch.c and re-using lib/ code for tools is a > > > > normal best practice. I'd suggest re-factoring this code in sunxi-tools > > > > sot that it too borrows lib/bch.c from the kernel (and can re-sync > > > > bugfixes if needed). Thanks! > > > > > > I finally figured that out. > > > > > > It turns out that the driver was doing a modulo by 0. I guess gcc's > > > and our libgcc don't have the same behaviour in this case, but in > > > U-boot's case, the function was simply returning (which is kind of > > > odd). > > > > > > I'll send a fix for the driver. > > > > So it's something in how lib/bch.c and lib1funcs.S interact? Please CC > > me on these when fixing whatever side of this it is in the kernel, > > thanks! > > Hmm, no, sorry, I meant to reply on the cover letter. The issue isn't > in lib/bch.c, it was really in our NAND driver. No changes required in > the kernel, just an extra patch in this serie :) Ah-ah! OK, thanks for clarifying. -- Tom signature.asc Description: Digital signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/7] tools: sunxi: Add spl image builder
Hi, On Mon, Nov 14, 2016 at 10:25:27AM -0500, Tom Rini wrote: > On Mon, Nov 14, 2016 at 04:20:49PM +0100, Maxime Ripard wrote: > > On Fri, Nov 11, 2016 at 11:20:47AM -0500, Tom Rini wrote: > > > On Tue, Nov 08, 2016 at 05:21:14PM +0100, Maxime Ripard wrote: > > > > > > > This program generates raw SPL images that can be flashed on the NAND > > > > with > > > > the ECC and randomizer properly set up. > > > > > > > > Signed-off-by: Maxime Ripard> > > [snip] > > > > +++ b/tools/sunxi-spl-image-builder.c > > > > @@ -0,0 +1,1113 @@ > > > > +/* > > > > + * Generic binary BCH encoding/decoding library > > > > > > OK, but this is also lib/bch.c and re-using lib/ code for tools is a > > > normal best practice. I'd suggest re-factoring this code in sunxi-tools > > > sot that it too borrows lib/bch.c from the kernel (and can re-sync > > > bugfixes if needed). Thanks! > > > > I finally figured that out. > > > > It turns out that the driver was doing a modulo by 0. I guess gcc's > > and our libgcc don't have the same behaviour in this case, but in > > U-boot's case, the function was simply returning (which is kind of > > odd). > > > > I'll send a fix for the driver. > > So it's something in how lib/bch.c and lib1funcs.S interact? Please CC > me on these when fixing whatever side of this it is in the kernel, > thanks! Hmm, no, sorry, I meant to reply on the cover letter. The issue isn't in lib/bch.c, it was really in our NAND driver. No changes required in the kernel, just an extra patch in this serie :) Maxime -- Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com signature.asc Description: PGP signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/7] tools: sunxi: Add spl image builder
On Mon, Nov 14, 2016 at 04:20:49PM +0100, Maxime Ripard wrote: > On Fri, Nov 11, 2016 at 11:20:47AM -0500, Tom Rini wrote: > > On Tue, Nov 08, 2016 at 05:21:14PM +0100, Maxime Ripard wrote: > > > > > This program generates raw SPL images that can be flashed on the NAND with > > > the ECC and randomizer properly set up. > > > > > > Signed-off-by: Maxime Ripard> > [snip] > > > +++ b/tools/sunxi-spl-image-builder.c > > > @@ -0,0 +1,1113 @@ > > > +/* > > > + * Generic binary BCH encoding/decoding library > > > > OK, but this is also lib/bch.c and re-using lib/ code for tools is a > > normal best practice. I'd suggest re-factoring this code in sunxi-tools > > sot that it too borrows lib/bch.c from the kernel (and can re-sync > > bugfixes if needed). Thanks! > > I finally figured that out. > > It turns out that the driver was doing a modulo by 0. I guess gcc's > and our libgcc don't have the same behaviour in this case, but in > U-boot's case, the function was simply returning (which is kind of > odd). > > I'll send a fix for the driver. So it's something in how lib/bch.c and lib1funcs.S interact? Please CC me on these when fixing whatever side of this it is in the kernel, thanks! -- Tom signature.asc Description: Digital signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/7] tools: sunxi: Add spl image builder
On Fri, Nov 11, 2016 at 11:20:47AM -0500, Tom Rini wrote: > On Tue, Nov 08, 2016 at 05:21:14PM +0100, Maxime Ripard wrote: > > > This program generates raw SPL images that can be flashed on the NAND with > > the ECC and randomizer properly set up. > > > > Signed-off-by: Maxime Ripard> [snip] > > +++ b/tools/sunxi-spl-image-builder.c > > @@ -0,0 +1,1113 @@ > > +/* > > + * Generic binary BCH encoding/decoding library > > OK, but this is also lib/bch.c and re-using lib/ code for tools is a > normal best practice. I'd suggest re-factoring this code in sunxi-tools > sot that it too borrows lib/bch.c from the kernel (and can re-sync > bugfixes if needed). Thanks! I finally figured that out. It turns out that the driver was doing a modulo by 0. I guess gcc's and our libgcc don't have the same behaviour in this case, but in U-boot's case, the function was simply returning (which is kind of odd). I'll send a fix for the driver. Maxime -- Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com signature.asc Description: PGP signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/7] tools: sunxi: Add spl image builder
Hi, On 14-11-16 14:53, Maxime Ripard wrote: On Mon, Nov 14, 2016 at 12:29:25PM +0100, Hans de Goede wrote: Hi, On 14-11-16 12:18, Hans de Goede wrote: Hi, On 08-11-16 17:21, Maxime Ripard wrote: This program generates raw SPL images that can be flashed on the NAND with the ECC and randomizer properly set up. Signed-off-by: Maxime RipardLooks good to me: Reviewed-by: Hans de Goede Note this causes a cpu_to_be32 redefine compiler warning I've fixed this up locally. I'll have to send a v2 based on Tom's comments. How did you fix this? I added an undef above the define, if you use the pre-existing macro you get problems later because it gets called as cpu_to_be32(*addr++) and the pre-existing macro references its argument multiple times. Regards, Hans ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/7] tools: sunxi: Add spl image builder
On Mon, Nov 14, 2016 at 12:29:25PM +0100, Hans de Goede wrote: > Hi, > > On 14-11-16 12:18, Hans de Goede wrote: > > Hi, > > > > On 08-11-16 17:21, Maxime Ripard wrote: > > > This program generates raw SPL images that can be flashed on the NAND with > > > the ECC and randomizer properly set up. > > > > > > Signed-off-by: Maxime Ripard> > > > Looks good to me: > > > > Reviewed-by: Hans de Goede > > Note this causes a cpu_to_be32 redefine compiler warning > I've fixed this up locally. I'll have to send a v2 based on Tom's comments. How did you fix this? Thanks, Maxime -- Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com signature.asc Description: PGP signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/7] tools: sunxi: Add spl image builder
Hi, On 14-11-16 12:18, Hans de Goede wrote: Hi, On 08-11-16 17:21, Maxime Ripard wrote: This program generates raw SPL images that can be flashed on the NAND with the ECC and randomizer properly set up. Signed-off-by: Maxime RipardLooks good to me: Reviewed-by: Hans de Goede Note this causes a cpu_to_be32 redefine compiler warning I've fixed this up locally. Regards, Hans Regards, Hans --- tools/.gitignore|1 +- tools/Makefile |1 +- tools/sunxi-spl-image-builder.c | 1113 - 3 files changed, 1115 insertions(+), 0 deletions(-) create mode 100644 tools/sunxi-spl-image-builder.c diff --git a/tools/.gitignore b/tools/.gitignore index cb1e722d4575..16574467544c 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -15,6 +15,7 @@ /mkexynosspl /mxsboot /mksunxiboot +/sunxi-spl-image-builder /ncb /proftool /relocate-rela diff --git a/tools/Makefile b/tools/Makefile index 400588cf0f5c..dfeeb23484ce 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -171,6 +171,7 @@ hostprogs-$(CONFIG_MX28) += mxsboot HOSTCFLAGS_mxsboot.o := -pedantic hostprogs-$(CONFIG_ARCH_SUNXI) += mksunxiboot +hostprogs-$(CONFIG_ARCH_SUNXI) += sunxi-spl-image-builder hostprogs-$(CONFIG_NETCONSOLE) += ncb hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1 diff --git a/tools/sunxi-spl-image-builder.c b/tools/sunxi-spl-image-builder.c new file mode 100644 index ..0f915eb2bdf5 --- /dev/null +++ b/tools/sunxi-spl-image-builder.c @@ -0,0 +1,1113 @@ +/* + * Generic binary BCH encoding/decoding library + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * For the BCH implementation: + * + * Copyright © 2011 Parrot S.A. + * + * Author: Ivan Djelic + * + * See also: + * http://lxr.free-electrons.com/source/lib/bch.c + * + * For the randomizer and image builder implementation: + * + * Copyright © 2016 NextThing Co. + * Copyright © 2016 Free Electrons + * + * Author: Boris Brezillon + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(CONFIG_BCH_CONST_PARAMS) +#define GF_M(_p) (CONFIG_BCH_CONST_M) +#define GF_T(_p) (CONFIG_BCH_CONST_T) +#define GF_N(_p) ((1 << (CONFIG_BCH_CONST_M))-1) +#else +#define GF_M(_p) ((_p)->m) +#define GF_T(_p) ((_p)->t) +#define GF_N(_p) ((_p)->n) +#endif + +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) + +#define BCH_ECC_WORDS(_p) DIV_ROUND_UP(GF_M(_p)*GF_T(_p), 32) +#define BCH_ECC_BYTES(_p) DIV_ROUND_UP(GF_M(_p)*GF_T(_p), 8) + +#ifndef dbg +#define dbg(_fmt, args...) do {} while (0) +#endif + +#define cpu_to_be32 htobe32 +#define kfree free +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +#define BCH_PRIMITIVE_POLY0x5803 + +struct image_info { +int ecc_strength; +int ecc_step_size; +int page_size; +int oob_size; +int usable_page_size; +int eraseblock_size; +int scramble; +int boot0; +off_t offset; +const char *source; +const char *dest; +}; + +/** + * struct bch_control - BCH control structure + * @m: Galois field order + * @n: maximum codeword size in bits (= 2^m-1) + * @t: error correction capability in bits + * @ecc_bits: ecc exact size in bits, i.e. generator polynomial degree (<=m*t) + * @ecc_bytes: ecc max size (m*t bits) in bytes + * @a_pow_tab: Galois field GF(2^m) exponentiation lookup table + * @a_log_tab: Galois field GF(2^m) log lookup table + * @mod8_tab: remainder generator polynomial lookup tables + * @ecc_buf:ecc parity words buffer + * @ecc_buf2: ecc parity words buffer + * @xi_tab: GF(2^m) base for solving degree 2 polynomial roots + * @syn:syndrome buffer + * @cache: log-based polynomial representation buffer + * @elp:error locator polynomial + * @poly_2t:temporary polynomials of degree 2t + */ +struct bch_control { +unsigned intm; +unsigned intn; +unsigned intt; +unsigned intecc_bits; +unsigned intecc_bytes; +/* private: */ +uint16_t *a_pow_tab; +uint16_t *a_log_tab; +uint32_t
Re: [U-Boot] [PATCH 4/7] tools: sunxi: Add spl image builder
Hi, On 08-11-16 17:21, Maxime Ripard wrote: This program generates raw SPL images that can be flashed on the NAND with the ECC and randomizer properly set up. Signed-off-by: Maxime RipardLooks good to me: Reviewed-by: Hans de Goede Regards, Hans --- tools/.gitignore|1 +- tools/Makefile |1 +- tools/sunxi-spl-image-builder.c | 1113 - 3 files changed, 1115 insertions(+), 0 deletions(-) create mode 100644 tools/sunxi-spl-image-builder.c diff --git a/tools/.gitignore b/tools/.gitignore index cb1e722d4575..16574467544c 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -15,6 +15,7 @@ /mkexynosspl /mxsboot /mksunxiboot +/sunxi-spl-image-builder /ncb /proftool /relocate-rela diff --git a/tools/Makefile b/tools/Makefile index 400588cf0f5c..dfeeb23484ce 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -171,6 +171,7 @@ hostprogs-$(CONFIG_MX28) += mxsboot HOSTCFLAGS_mxsboot.o := -pedantic hostprogs-$(CONFIG_ARCH_SUNXI) += mksunxiboot +hostprogs-$(CONFIG_ARCH_SUNXI) += sunxi-spl-image-builder hostprogs-$(CONFIG_NETCONSOLE) += ncb hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1 diff --git a/tools/sunxi-spl-image-builder.c b/tools/sunxi-spl-image-builder.c new file mode 100644 index ..0f915eb2bdf5 --- /dev/null +++ b/tools/sunxi-spl-image-builder.c @@ -0,0 +1,1113 @@ +/* + * Generic binary BCH encoding/decoding library + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * For the BCH implementation: + * + * Copyright © 2011 Parrot S.A. + * + * Author: Ivan Djelic + * + * See also: + * http://lxr.free-electrons.com/source/lib/bch.c + * + * For the randomizer and image builder implementation: + * + * Copyright © 2016 NextThing Co. + * Copyright © 2016 Free Electrons + * + * Author: Boris Brezillon + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(CONFIG_BCH_CONST_PARAMS) +#define GF_M(_p) (CONFIG_BCH_CONST_M) +#define GF_T(_p) (CONFIG_BCH_CONST_T) +#define GF_N(_p) ((1 << (CONFIG_BCH_CONST_M))-1) +#else +#define GF_M(_p) ((_p)->m) +#define GF_T(_p) ((_p)->t) +#define GF_N(_p) ((_p)->n) +#endif + +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) + +#define BCH_ECC_WORDS(_p) DIV_ROUND_UP(GF_M(_p)*GF_T(_p), 32) +#define BCH_ECC_BYTES(_p) DIV_ROUND_UP(GF_M(_p)*GF_T(_p), 8) + +#ifndef dbg +#define dbg(_fmt, args...) do {} while (0) +#endif + +#define cpu_to_be32 htobe32 +#define kfree free +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +#define BCH_PRIMITIVE_POLY 0x5803 + +struct image_info { + int ecc_strength; + int ecc_step_size; + int page_size; + int oob_size; + int usable_page_size; + int eraseblock_size; + int scramble; + int boot0; + off_t offset; + const char *source; + const char *dest; +}; + +/** + * struct bch_control - BCH control structure + * @m: Galois field order + * @n: maximum codeword size in bits (= 2^m-1) + * @t: error correction capability in bits + * @ecc_bits: ecc exact size in bits, i.e. generator polynomial degree (<=m*t) + * @ecc_bytes: ecc max size (m*t bits) in bytes + * @a_pow_tab: Galois field GF(2^m) exponentiation lookup table + * @a_log_tab: Galois field GF(2^m) log lookup table + * @mod8_tab: remainder generator polynomial lookup tables + * @ecc_buf:ecc parity words buffer + * @ecc_buf2: ecc parity words buffer + * @xi_tab: GF(2^m) base for solving degree 2 polynomial roots + * @syn:syndrome buffer + * @cache: log-based polynomial representation buffer + * @elp:error locator polynomial + * @poly_2t:temporary polynomials of degree 2t + */ +struct bch_control { + unsigned intm; + unsigned intn; + unsigned intt; + unsigned intecc_bits; + unsigned intecc_bytes; +/* private: */ + uint16_t *a_pow_tab; + uint16_t *a_log_tab; + uint32_t *mod8_tab; + uint32_t *ecc_buf; + uint32_t *ecc_buf2; + unsigned int
Re: [U-Boot] [PATCH 4/7] tools: sunxi: Add spl image builder
On Tue, Nov 08, 2016 at 05:21:14PM +0100, Maxime Ripard wrote: > This program generates raw SPL images that can be flashed on the NAND with > the ECC and randomizer properly set up. > > Signed-off-by: Maxime Ripard[snip] > +++ b/tools/sunxi-spl-image-builder.c > @@ -0,0 +1,1113 @@ > +/* > + * Generic binary BCH encoding/decoding library OK, but this is also lib/bch.c and re-using lib/ code for tools is a normal best practice. I'd suggest re-factoring this code in sunxi-tools sot that it too borrows lib/bch.c from the kernel (and can re-sync bugfixes if needed). Thanks! -- Tom signature.asc Description: Digital signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/7] tools: sunxi: Add spl image builder
On Tue, Nov 08, 2016 at 05:29:47PM +0100, Boris Brezillon wrote: > On Tue, 8 Nov 2016 17:21:14 +0100 > Maxime Ripardwrote: > > > This program generates raw SPL images that can be flashed on the NAND with > > the ECC and randomizer properly set up. > > > > Maybe you should mention that this file has been copied from the > sunxi-tools project. Definitely, I've amended my commit log. > Otherwise, > > Acked-by: Boris Brezillon Thanks! Maxime -- Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com signature.asc Description: PGP signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/7] tools: sunxi: Add spl image builder
On Tue, 8 Nov 2016 17:21:14 +0100 Maxime Ripardwrote: > This program generates raw SPL images that can be flashed on the NAND with > the ECC and randomizer properly set up. > Maybe you should mention that this file has been copied from the sunxi-tools project. Otherwise, Acked-by: Boris Brezillon > Signed-off-by: Maxime Ripard > --- > tools/.gitignore|1 +- > tools/Makefile |1 +- > tools/sunxi-spl-image-builder.c | 1113 - > 3 files changed, 1115 insertions(+), 0 deletions(-) > create mode 100644 tools/sunxi-spl-image-builder.c > > diff --git a/tools/.gitignore b/tools/.gitignore > index cb1e722d4575..16574467544c 100644 > --- a/tools/.gitignore > +++ b/tools/.gitignore > @@ -15,6 +15,7 @@ > /mkexynosspl > /mxsboot > /mksunxiboot > +/sunxi-spl-image-builder > /ncb > /proftool > /relocate-rela > diff --git a/tools/Makefile b/tools/Makefile > index 400588cf0f5c..dfeeb23484ce 100644 > --- a/tools/Makefile > +++ b/tools/Makefile > @@ -171,6 +171,7 @@ hostprogs-$(CONFIG_MX28) += mxsboot > HOSTCFLAGS_mxsboot.o := -pedantic > > hostprogs-$(CONFIG_ARCH_SUNXI) += mksunxiboot > +hostprogs-$(CONFIG_ARCH_SUNXI) += sunxi-spl-image-builder > > hostprogs-$(CONFIG_NETCONSOLE) += ncb > hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1 > diff --git a/tools/sunxi-spl-image-builder.c b/tools/sunxi-spl-image-builder.c > new file mode 100644 > index ..0f915eb2bdf5 > --- /dev/null > +++ b/tools/sunxi-spl-image-builder.c > @@ -0,0 +1,1113 @@ > +/* > + * Generic binary BCH encoding/decoding library > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms of the GNU General Public License version 2 as published > by > + * the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, but > WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for > + * more details. > + * > + * You should have received a copy of the GNU General Public License along > with > + * this program; if not, write to the Free Software Foundation, Inc., 51 > + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. > + * > + * For the BCH implementation: > + * > + * Copyright © 2011 Parrot S.A. > + * > + * Author: Ivan Djelic > + * > + * See also: > + * http://lxr.free-electrons.com/source/lib/bch.c > + * > + * For the randomizer and image builder implementation: > + * > + * Copyright © 2016 NextThing Co. > + * Copyright © 2016 Free Electrons > + * > + * Author: Boris Brezillon > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#if defined(CONFIG_BCH_CONST_PARAMS) > +#define GF_M(_p) (CONFIG_BCH_CONST_M) > +#define GF_T(_p) (CONFIG_BCH_CONST_T) > +#define GF_N(_p) ((1 << (CONFIG_BCH_CONST_M))-1) > +#else > +#define GF_M(_p) ((_p)->m) > +#define GF_T(_p) ((_p)->t) > +#define GF_N(_p) ((_p)->n) > +#endif > + > +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) > + > +#define BCH_ECC_WORDS(_p) DIV_ROUND_UP(GF_M(_p)*GF_T(_p), 32) > +#define BCH_ECC_BYTES(_p) DIV_ROUND_UP(GF_M(_p)*GF_T(_p), 8) > + > +#ifndef dbg > +#define dbg(_fmt, args...) do {} while (0) > +#endif > + > +#define cpu_to_be32 htobe32 > +#define kfree free > +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) > + > +#define BCH_PRIMITIVE_POLY 0x5803 > + > +struct image_info { > + int ecc_strength; > + int ecc_step_size; > + int page_size; > + int oob_size; > + int usable_page_size; > + int eraseblock_size; > + int scramble; > + int boot0; > + off_t offset; > + const char *source; > + const char *dest; > +}; > + > +/** > + * struct bch_control - BCH control structure > + * @m: Galois field order > + * @n: maximum codeword size in bits (= 2^m-1) > + * @t: error correction capability in bits > + * @ecc_bits: ecc exact size in bits, i.e. generator polynomial degree > (<=m*t) > + * @ecc_bytes: ecc max size (m*t bits) in bytes > + * @a_pow_tab: Galois field GF(2^m) exponentiation lookup table > + * @a_log_tab: Galois field GF(2^m) log lookup table > + * @mod8_tab: remainder generator polynomial lookup tables > + * @ecc_buf:ecc parity words buffer > + * @ecc_buf2: ecc parity words buffer > + * @xi_tab: GF(2^m) base for solving degree 2 polynomial roots > + * @syn:syndrome buffer > + * @cache: log-based polynomial representation buffer > + * @elp:error locator polynomial > + * @poly_2t:temporary polynomials of degree