summaryrefslogtreecommitdiff
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-02-17 10:54:10 +0100
commit0617aea482414fda22051d66532817563b6e686a (patch)
tree61c9334e4045d2ce97c3d6349a30a99b5a889238
parent3a6e2d774c3f6d980dff9f616948a090ce154c30 (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>
-rw-r--r--lib/bch.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/bch.c b/lib/bch.c
index 7f4ca92708..b65753fefc 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);