diff options
author | Max Krummenacher <max.krummenacher@toradex.com> | 2016-02-09 13:29:16 +0100 |
---|---|---|
committer | Marcel Ziswiler <marcel.ziswiler@toradex.com> | 2017-01-11 21:25:09 +0100 |
commit | 785aff3c959b03e835941bdad5602216f2368dd9 (patch) | |
tree | dd75fa5a044bdca7bc2c4125e559044b7c4baeeb /lib | |
parent | b89000425a0352f92a240e704c6aea9294bc525b (diff) |
lib/bch.c: modify algorithm to conform to iMX7 FCB needs
Modification taken from imx-kobs-5.3.
Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bch.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/bch.c b/lib/bch.c index 147715afd06..bb4e15a377d 100644 --- a/lib/bch.c +++ b/lib/bch.c @@ -154,6 +154,40 @@ static void store_ecc8(struct bch_control *bch, uint8_t *dst, memcpy(dst, pad, BCH_ECC_BYTES(bch)-4*nwords); } +#ifdef CONFIG_TARGET_COLIBRI_IMX7 +/* + * reverse bit for byte + */ +static uint8_t reverse_bit(uint8_t in_byte) +{ + int i; + uint8_t out_byte = 0; + + for (i = 0; i < 8; i++) { + if (in_byte & ((0x80) >> i)) { + out_byte |= 1 << i; + } + } + + return out_byte; +} + + /* + * swap 32-bit data, including bit reverse and swap to big endian + */ +static uint32_t swap_data(uint32_t data) +{ + uint32_t r = 0; + + r = reverse_bit(data & 0xFF) << 24; + r |= reverse_bit((data >> 8) & 0xFF) << 16; + r |= reverse_bit((data >> 16) & 0xFF) << 8; + r |= reverse_bit((data >> 24) & 0xFF); + + return r; +} +#endif + /** * encode_bch - calculate BCH ecc parity of data * @bch: BCH control structure @@ -217,7 +251,14 @@ void encode_bch(struct bch_control *bch, const uint8_t *data, */ while (mlen--) { /* input data is read in big-endian format */ +#if CONFIG_TARGET_COLIBRI_IMX7 + /*TODO: big little endian*/ + /*w = r[0]^cpu_to_be32(*pdata++);*/ + /*w = r[0]^(uint32_t)(*pdata++);*/ + w = r[0]^swap_data(*pdata++); +#else w = r[0]^cpu_to_be32(*pdata++); +#endif p0 = tab0 + (l+1)*((w >> 0) & 0xff); p1 = tab1 + (l+1)*((w >> 8) & 0xff); p2 = tab2 + (l+1)*((w >> 16) & 0xff); |