Skip to content

Commit b9f23ba

Browse files
committed
update SPI NAND block device driver
1 parent 72f27ce commit b9f23ba

File tree

4 files changed

+1085
-40
lines changed

4 files changed

+1085
-40
lines changed

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

+42
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "drivers/QSPI.h"
2121
#include "blockdevice/BlockDevice.h"
2222
#include "platform/Callback.h"
23+
#include "bch.h"
2324

2425
#ifndef MBED_CONF_SPINAND_QSPI_IO0
2526
#define MBED_CONF_SPINAND_QSPI_IO0 NC
@@ -237,6 +238,10 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
237238
*/
238239
virtual const char *get_type() const;
239240

241+
virtual bool is_bad_block(uint16_t blk_idx);
242+
243+
virtual int mark_bad_block(uint16_t blk_idx);
244+
240245
private:
241246
/********************************/
242247
/* Different Device Csel Mgmt */
@@ -258,6 +263,9 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
258263
// Send Read command to Driver
259264
qspi_status_t _qspi_send_read_command(mbed::qspi_inst_t read_instruction, void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
260265

266+
// Send Continuous Read command to Driver
267+
qspi_status_t _qspi_send_continuous_read_command(mbed::qspi_inst_t read_instruction, void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
268+
261269
// Send Erase Instruction using command_transfer command to Driver
262270
qspi_status_t _qspi_send_erase_command(mbed::qspi_inst_t erase_instruction, mbed::bd_addr_t addr, mbed::bd_size_t size);
263271

@@ -272,6 +280,13 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
272280
/* Flash Configuration Functions */
273281
/*********************************/
274282

283+
// Read OTP ONFI parameters
284+
bool _read_otp_onfi();
285+
286+
int _read_oob(void *buffer, bd_addr_t addr, bd_size_t size);
287+
288+
int _program_oob(const void *buffer, bd_addr_t addr, bd_size_t size);
289+
275290
// Quad Enable in Security Register
276291
int _set_quad_enable();
277292

@@ -281,9 +296,19 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
281296
// Configure Write Enable in Status Register
282297
int _set_write_enable();
283298

299+
int _set_conti_read_enable();
300+
301+
int _set_conti_read_disable();
302+
303+
int _conti_read_exit();
304+
284305
// Wait on status register until write not-in-progress
285306
bool _is_mem_ready();
286307

308+
void _bch_init(uint8_t ecc_bits);
309+
void _bch_free();
310+
int _bch_calculate_ecc(unsigned char *buf, unsigned char *code);
311+
int _bch_correct_data(unsigned char *buf, unsigned char *read_ecc, unsigned char *calc_ecc);
287312
private:
288313

289314
// QSPI Driver Object
@@ -320,6 +345,23 @@ class SPINANDBlockDevice : public mbed::BlockDevice {
320345

321346
uint32_t _init_ref_count;
322347
bool _is_initialized;
348+
char _name[32];
349+
uint32_t _page_size, _block_size, _flash_size;
350+
uint8_t _page_shift, _block_shift;
351+
uint16_t _block_num, _page_num, _oob_size;
352+
uint8_t _ecc_bits, _ecc_bytes, _ecc_steps, _ecc_layout_pos;
353+
uint32_t _ecc_size;
354+
uint8_t *_ecc_calc;
355+
uint8_t *_ecc_code;
356+
uint8_t *_page_buf;
357+
uint8_t _continuous_read;
358+
359+
struct nand_bch_control {
360+
struct bch_code *bch;
361+
unsigned int *errloc;
362+
unsigned char *eccmask;
363+
};
364+
struct nand_bch_control _nbc;
323365
};
324366

325367
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2022 Macronix International Co., Ltd.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef _BCH_H
7+
#define _BCH_H
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
#include <stdint.h>
12+
13+
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
14+
15+
struct bch_code {
16+
unsigned int m;
17+
unsigned int n;
18+
unsigned int t;
19+
unsigned int ecc_bits;
20+
unsigned int ecc_words;
21+
unsigned int len;
22+
unsigned int *a_pow;
23+
unsigned int *a_log;
24+
unsigned int *mod_tab;
25+
unsigned int *ecc;
26+
unsigned int *syn;
27+
unsigned int *elp;
28+
unsigned int *buf;
29+
unsigned int *buf2;
30+
unsigned char *input_data;
31+
unsigned int endian;
32+
};
33+
34+
struct bch_code *bch_init(unsigned int m, unsigned int t);
35+
void bch_free(struct bch_code *bch);
36+
void bch_encode(struct bch_code *bch, unsigned char *data, unsigned int *ecc);
37+
int bch_decode(struct bch_code *bch, unsigned char *data, unsigned int *ecc);
38+
int fls(int x);
39+
40+
#ifdef __cplusplus
41+
}
42+
#endif
43+
#endif

0 commit comments

Comments
 (0)