Skip to content

Commit 0fef805

Browse files
committed
add ondie and software ECC code
1 parent c37cd51 commit 0fef805

File tree

4 files changed

+1489
-2
lines changed

4 files changed

+1489
-2
lines changed

storage/blockdevice/COMPONENT_SPINAND/include/SPINAND/SPINANDBlockDevice.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
272272
/* Flash Configuration Functions */
273273
/*********************************/
274274

275+
// Read OTP ONFI parameters
276+
bool _read_otp_onfi();
277+
275278
// Quad Enable in Security Register
276279
int _set_quad_enable();
277280

@@ -283,7 +286,10 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
283286

284287
// Wait on status register until write not-in-progress
285288
bool _is_mem_ready();
286-
289+
void _bch_init(uint8_t ecc_bits);
290+
void _bch_free();
291+
int _bch_calculate_ecc(unsigned char* buf, unsigned char* code);
292+
int _bch_correct_data(unsigned char* buf, unsigned char* read_ecc, unsigned char* calc_ecc);
287293
private:
288294

289295
// QSPI Driver Object
@@ -320,6 +326,22 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
320326

321327
uint32_t _init_ref_count;
322328
bool _is_initialized;
329+
char _name[32];
330+
uint32_t _page_size, _block_size, _flash_size;
331+
uint8_t _page_shift, _block_shift;
332+
uint16_t _block_num, _page_num, _oob_size;
333+
uint8_t _ecc_bits, _ecc_bytes, _ecc_steps, _ecc_layout_pos;
334+
uint32_t _ecc_size;
335+
uint8_t *_ecc_calc;
336+
uint8_t *_ecc_code;
337+
uint8_t *_page_buf;
338+
339+
struct nand_bch_control {
340+
struct bch_control *bch;
341+
unsigned int *errloc;
342+
unsigned char *eccmask;
343+
};
344+
struct nand_bch_control _nbc;
323345
};
324346

325347
#endif
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Generic binary BCH encoding/decoding library
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License version 2 as published by
6+
* the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program; if not, write to the Free Software Foundation, Inc., 51
15+
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16+
*
17+
* Copyright © 2011 Parrot S.A.
18+
*
19+
* Author: Ivan Djelic <[email protected]>
20+
*
21+
* Description:
22+
*
23+
* This library provides runtime configurable encoding/decoding of binary
24+
* Bose-Chaudhuri-Hocquenghem (BCH) codes.
25+
*/
26+
#ifndef _BCH_H
27+
#define _BCH_H
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
#include <stdint.h>
32+
//typedef unsigned char uint8_t;
33+
//typedef unsigned short uint16_t;
34+
//typedef unsigned int uint32_t;
35+
36+
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
37+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
38+
/**
39+
* struct bch_control - BCH control structure
40+
* @m: Galois field order
41+
* @n: maximum codeword size in bits (= 2^m-1)
42+
* @t: error correction capability in bits
43+
* @ecc_bits: ecc exact size in bits, i.e. generator polynomial degree (<=m*t)
44+
* @ecc_bytes: ecc max size (m*t bits) in bytes
45+
* @a_pow_tab: Galois field GF(2^m) exponentiation lookup table
46+
* @a_log_tab: Galois field GF(2^m) log lookup table
47+
* @mod8_tab: remainder generator polynomial lookup tables
48+
* @ecc_buf: ecc parity words buffer
49+
* @ecc_buf2: ecc parity words buffer
50+
* @xi_tab: GF(2^m) base for solving degree 2 polynomial roots
51+
* @syn: syndrome buffer
52+
* @cache: log-based polynomial representation buffer
53+
* @elp: error locator polynomial
54+
* @poly_2t: temporary polynomials of degree 2t
55+
*/
56+
struct bch_control {
57+
unsigned int m;
58+
unsigned int n;
59+
unsigned int t;
60+
unsigned int ecc_bits;
61+
unsigned int ecc_bytes;
62+
/* private: */
63+
uint16_t *a_pow_tab;
64+
uint16_t *a_log_tab;
65+
uint32_t *mod8_tab;
66+
uint32_t *ecc_buf;
67+
uint32_t *ecc_buf2;
68+
unsigned int *xi_tab;
69+
unsigned int *syn;
70+
int *cache;
71+
struct gf_poly *elp;
72+
struct gf_poly *poly_2t[4];
73+
};
74+
75+
struct bch_control *init_bch(int m, int t, unsigned int prim_poly);
76+
77+
void free_bch(struct bch_control *bch);
78+
79+
void encode_bch(struct bch_control *bch, const uint8_t *data,
80+
unsigned int len, uint8_t *ecc);
81+
82+
int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,
83+
const uint8_t *recv_ecc, const uint8_t *calc_ecc,
84+
const unsigned int *syn, unsigned int *errloc);
85+
int fls(int x);
86+
#ifdef _X86_
87+
#define cpu_to_be32(x) ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | (((x)>>8)&0xff00) | (((x)>>24)&0xff))
88+
#else
89+
#define cpu_to_be32(x) x
90+
#endif
91+
#ifdef __cplusplus
92+
}
93+
#endif
94+
#endif /* _BCH_H */

0 commit comments

Comments
 (0)