summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMax Krummenacher <max.krummenacher@toradex.com>2016-02-09 13:29:16 +0100
committerMax Krummenacher <max.krummenacher@toradex.com>2016-03-09 15:03:32 +0100
commit3748a005c7df2647dc78f286267d3c28b9b2c732 (patch)
tree6ab9b296e0b8478b0d74837ab0d7d86be71a31f8 /lib
parent204c3595d33883a3e495f6ed89317bee291d3ceb (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.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/bch.c b/lib/bch.c
index 7f4ca927085..b65753fefc7 100644
--- a/lib/bch.c
+++ b/lib/bch.c
@@ -165,6 +165,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
@@ -228,7 +262,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);