rockchip: rkflash: adjust vendor part design for rkflash

1.Using internal vendor strategy for slc nand and spi nand storage;
2.Using outernal vendor strategy for spi nor;
3.Rejust rkflash_debug design.
4.Remove gcc -g

Change-Id: Ib5eca61a7a600f99d438448e4b7f03dd3dddb5f2
Signed-off-by: Dingqiang Lin <jon.lin@rock-chips.com>
This commit is contained in:
Dingqiang Lin 2018-07-18 21:48:51 +08:00 committed by Tao Huang
parent c5e0b1b35a
commit f091fa7c6f
20 changed files with 13951 additions and 96306 deletions

View File

@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_RK_NANDC_NAND) += rksftl.o rkflash_blk.o rknandc_base.o rkflash_debug.o nand_boot.o flash.o nandc.o ftl_flash_plat.o
obj-$(CONFIG_RK_SFC_NAND) += rksftl.o rkflash_blk.o rksfc_base.o rkflash_debug.o sfc_nand_boot.o sfc_nand.o sfc.o ftl_flash_plat.o
obj-$(CONFIG_RK_NANDC_NAND) += rksftl.o rkflash_blk.o rknandc_base.o rkflash_debug.o nand_boot.o flash.o nandc.o
obj-$(CONFIG_RK_SFC_NAND) += rksftl.o rkflash_blk.o rksfc_base.o rkflash_debug.o sfc_nand_boot.o sfc_nand.o sfc.o
obj-$(CONFIG_RK_SFC_NOR) += rkflash_blk.o rksfc_base.o rkflash_debug.o sfc_nor_boot.o sfc_nor.o sfc.o
obj-$(CONFIG_RK_SFC_NOR_MTD) += sfc_nor_mtd.o

View File

@ -5,8 +5,6 @@
#ifndef __FLASH_H
#define __FLASH_H
#include "typedef.h"
#ifndef BIT
#define BIT(nr) (1 << (nr))
#endif

View File

@ -1,132 +0,0 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2018 Rockchip Electronics Co. Ltd. */
#include <linux/kernel.h>
#include <linux/slab.h>
#include "flash_com.h"
struct nand_phy_info g_nand_phy_info;
struct nand_ops g_nand_ops;
static u32 check_buf[MAX_FLASH_PAGE_SIZE / 4];
static u32 check_spare_buf[MAX_FLASH_PAGE_SIZE / 8 / 4];
static u32 pg_buf0[MAX_FLASH_PAGE_SIZE / 4];
void *ftl_malloc(int size)
{
return kmalloc(size, GFP_KERNEL | GFP_DMA);
}
void ftl_free(void *buf)
{
kfree(buf);
}
static u32 l2p_addr_tran(struct nand_req *req, u32 *addr, u32 *p_die)
{
u16 block_index, page_index;
u16 blk_per_die = g_nand_phy_info.blk_per_die;
u32 die_index;
block_index = (u16)((req[0].page_addr >> BLOCK_ADDR_BITS) &
BLOCK_ADDR_MASK);
page_index = (u16)(req[0].page_addr & PAGE_ADDR_MASK);
die_index = (u16)((req[0].page_addr >> DIE_ADDR_BITS) &
DIE_ADDR_MASK);
*p_die = die_index;
*addr = (block_index + blk_per_die * die_index) *
g_nand_phy_info.page_per_blk + page_index;
return 0;
}
s32 ftl_flash_prog_pages(void *request, u32 num_req, u32 flash_type, u32 check)
{
u32 i, cs, status, addr;
struct nand_req *req = (struct nand_req *)request;
for (i = 0; i < num_req; i++) {
l2p_addr_tran(&req[i], &addr, &cs);
status = g_nand_ops.prog_page(cs,
addr,
req[i].p_data,
req[i].p_spare);
req[i].status = status;
if (status != NAND_STS_OK)
req[i].status = NAND_STS_ECC_ERR;
}
if (check == 0)
return 0;
for (i = 0; i < num_req; i++) {
l2p_addr_tran(&req[i], &addr, &cs);
status = g_nand_ops.read_page(cs,
addr,
check_buf,
check_spare_buf);
if (status != NAND_STS_ECC_ERR)
req[i].status = NAND_STS_OK;
if (check_buf[0] != req[i].p_data[0])
req[i].status = NAND_STS_ECC_ERR;
}
return 0;
}
s32 ftl_flash_read_pages(void *request, u32 num_req, u32 flash_type)
{
u32 i, cs, status, addr;
struct nand_req *req = (struct nand_req *)request;
for (i = 0; i < num_req; i++) {
l2p_addr_tran(&req[i], &addr, &cs);
status = g_nand_ops.read_page(cs,
addr,
req[i].p_data,
req[i].p_spare);
req[i].status = status;
}
return OK;
}
s32 ftl_flash_erase_blocks(void *request, u32 num_req)
{
u32 i, cs, status, addr;
struct nand_req *req = (struct nand_req *)request;
for (i = 0; i < num_req; i++) {
l2p_addr_tran(&req[i], &addr, &cs);
status = g_nand_ops.erase_blk(cs, addr);
req[i].status = status;
if (status != NAND_STS_OK)
req[i].status = NAND_STS_ECC_ERR;
}
return OK;
}
s32 ftl_flash_get_bad_blk_list(u16 *table, u32 die)
{
return g_nand_ops.get_bad_blk_list(table, die);
}
s32 ftl_flash_test_blk(u16 phy_block)
{
s32 sts = 0;
u32 spare[16];
struct nand_req req;
req.p_data = pg_buf0;
req.p_spare = spare;
memset(spare, 0xA5, 32);
memset(pg_buf0, 0x5A, 8);
req.page_addr = phy_block << BLOCK_ADDR_BITS;
ftl_flash_erase_blocks((void *)&req, 1);
ftl_flash_prog_pages((void *)&req, 1, SLC, 1);
if (req.status == NAND_STS_ECC_ERR) {
PRINT_E("%s %x is bad block\n", __func__, phy_block);
sts = -1;
}
ftl_flash_erase_blocks((void *)&req, 1);
return sts;
}

View File

@ -1,51 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (c) 2018 Rockchip Electronics Co. Ltd. */
#ifndef _FTL_INCLUDE_
#define _FTL_INCLUDE_
#include <linux/kernel.h>
#include "flash_com.h"
#include "typedef.h"
#define ENABLE_LOW_FORMAT
#define SYS_FTL_VERSION "ftl_ver 1.2.2"
/*
* debug
*/
#define FTL_DEBUG_LEVEL D_INF
#define FTL_DEBUG(level, format, arg...) \
do {\
if ((level) <= FTL_DEBUG_LEVEL) {\
pr_info(format, ##arg);\
} \
} while (0)
#define D_ERR 0
#define D_WAN 1
#define D_INF 2
#define D_DBG 3
/* For init, load, recovery, flush_all */
#define FTL_DBG_GLB D_DBG
/* For open_blk, erase_blk, write_trace_page, get_trace_list */
#define FTL_DBG_BLK (FTL_DBG_GLB + 1)
/* For flush 1 cache, write page */
#define FTL_DBG_PAGE (FTL_DBG_GLB + 2)
/* For lookup/update l2p */
#define FTL_DBG_MAP (FTL_DBG_GLB + 3)
#define FTL_DEBUG_BREAK(exp) \
do { \
if (exp) { \
FTL_DEBUG(0, "FILE: %s:%d:\n", __FILE__, __LINE__);\
dump_ftl_info();\
while (1)\
;\
} \
} while (0)
#endif

View File

@ -8,7 +8,6 @@
#include "flash.h"
#include "rkflash_api.h"
#include "rk_sftl.h"
#include "typedef.h"
int sftl_flash_init(void __iomem *reg_addr)
{
@ -33,14 +32,24 @@ unsigned int sftl_flash_get_capacity(void)
return sftl_get_density();
}
int sftl_flash_read(u32 sec, u32 n_sec, void *p_data)
{
return sftl_read(sec, n_sec, p_data);
}
int sftl_flash_write(u32 sec, u32 n_sec, void *p_data)
{
return sftl_write(sec, n_sec, p_data);
}
int sftl_flash_read(u32 sec, u32 n_sec, void *p_data)
int sftl_flash_vendor_read(u32 sec, u32 n_sec, void *p_data)
{
return sftl_read(sec, n_sec, p_data);
return sftl_vendor_read(sec, n_sec, p_data);
}
int sftl_flash_vendor_write(u32 sec, u32 n_sec, void *p_data)
{
return sftl_vendor_write(sec, n_sec, p_data);
}
void sftl_flash_deinit(void)

View File

@ -8,7 +8,7 @@
#include "flash.h"
#include "flash_com.h"
#include "nandc.h"
#include "typedef.h"
#include "rk_sftl.h"
#define CPU_DELAY_NS(n) ndelay(n)

View File

@ -12,5 +12,22 @@ int sftl_read(u32 index, u32 count, u8 *buf);
int sftl_write(u32 index, u32 count, u8 *buf);
u32 sftl_get_density(void);
s32 sftl_gc(void);
int sftl_vendor_read(u32 index, u32 count, u8 *buf);
int sftl_vendor_write(u32 index, u32 count, u8 *buf);
int rk_sftl_vendor_read(u32 index, u32 count, u8 *buf);
int rk_sftl_vendor_write(u32 index, u32 count, u8 *buf);
int rk_sftl_vendor_register(void);
int rk_sftl_vendor_storage_init(void);
int rk_sftl_vendor_dev_ops_register(int (*read)(u32 sec,
u32 n_sec,
void *p_data),
int (*write)(u32 sec,
u32 n_sec,
void *p_data));
void *ftl_malloc(int n_size);
void ftl_free(void *p);
void *ftl_memset(void *s, int c, unsigned int n);
void *ftl_memcpy(void *pv_to,
const void *pv_from,
unsigned int size);
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,8 @@ int sftl_flash_init(void __iomem *reg_addr);
void sftl_flash_read_id(u8 chip_sel, void *buf);
int sftl_flash_read(unsigned int sec, unsigned int n_sec, void *p_data);
int sftl_flash_write(unsigned int sec, unsigned int n_sec, void *p_data);
int sftl_flash_vendor_read(unsigned int sec, unsigned int n_sec, void *p_data);
int sftl_flash_vendor_write(unsigned int sec, unsigned int n_sec, void *p_data);
unsigned int sftl_flash_get_capacity(void);
void sftl_flash_deinit(void);
int sftl_flash_resume(void __iomem *reg_addr);
@ -32,6 +34,8 @@ int snor_vendor_write(unsigned int sec, unsigned int n_sec, void *p_data);
int snand_init(void __iomem *reg_addr);
int snand_read(unsigned int sec, unsigned int n_sec, void *p_data);
int snand_write(unsigned int sec, unsigned int n_sec, void *p_data);
int snand_vendor_read(unsigned int sec, unsigned int n_sec, void *p_data);
int snand_vendor_write(unsigned int sec, unsigned int n_sec, void *p_data);
unsigned int snand_get_capacity(void);
void snand_deinit(void);
int snand_resume(void __iomem *reg_addr);

View File

@ -25,9 +25,11 @@
#include <linux/timer.h>
#include <linux/wait.h>
#include <linux/version.h>
#include <linux/soc/rockchip/rk_vendor_storage.h>
#include "rkflash_api.h"
#include "rkflash_blk.h"
#include "rk_sftl.h"
#include "../soc/rockchip/flash_vendor_storage.h"
@ -40,8 +42,8 @@ static struct flash_boot_ops nandc_nand_ops = {
sftl_flash_get_capacity,
sftl_flash_deinit,
sftl_flash_resume,
sftl_flash_read,
sftl_flash_write,
sftl_flash_vendor_read,
sftl_flash_vendor_write,
#else
-1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
#endif
@ -72,8 +74,8 @@ static struct flash_boot_ops sfc_nand_ops = {
snand_get_capacity,
snand_deinit,
snand_resume,
snand_read,
snand_write,
snand_vendor_read,
snand_vendor_write,
#else
-1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
#endif
@ -106,7 +108,7 @@ static char *mtd_read_temp_buffer;
#define MTD_RW_SECTORS (512)
static DEFINE_MUTEX(g_flash_ops_mutex);
static int vendor_read(u32 sec, u32 n_sec, void *p_data)
int rkflash_vendor_read(u32 sec, u32 n_sec, void *p_data)
{
int ret;
@ -121,7 +123,7 @@ static int vendor_read(u32 sec, u32 n_sec, void *p_data)
return ret;
}
static int vendor_write(u32 sec, u32 n_sec, void *p_data)
int rkflash_vendor_write(u32 sec, u32 n_sec, void *p_data)
{
int ret;
@ -679,8 +681,23 @@ int rkflash_dev_init(void __iomem *reg_addr, enum flash_con_type con_type)
pr_info("rkflash[%d] init success\n", tmp_id);
g_flash_type = tmp_id;
mytr.quit = 1;
flash_vendor_dev_ops_register(&vendor_read,
&vendor_write);
if (g_flash_type == FLASH_TYPE_SFC_NOR) {
flash_vendor_dev_ops_register(rkflash_vendor_read,
rkflash_vendor_write);
} else {
#if defined(CONFIG_RK_NANDC_NAND) || defined(CONFIG_RK_SFC_NAND)
rk_sftl_vendor_dev_ops_register(rkflash_vendor_read,
rkflash_vendor_write);
ret = rk_sftl_vendor_storage_init();
if (!ret) {
rk_vendor_register(sftl_vendor_read, sftl_vendor_write);
rk_sftl_vendor_register();
pr_info("rkflashd vendor storage init ok !\n");
} else {
pr_info("rkflash vendor storage init failed !\n");
}
#endif
}
#ifdef CONFIG_RK_SFC_NOR_MTD
if (g_flash_type == FLASH_TYPE_SFC_NOR) {
pr_info("sfc_nor flash registered as a mtd device\n");

View File

@ -123,4 +123,7 @@ void rkflash_dev_shutdown(void);
void rkflash_dev_flush(void);
int rkflash_dev_init(void __iomem *reg_addr, enum flash_con_type type);
int rkflash_dev_exit(void);
int rkflash_vendor_read(u32 sec, u32 n_sec, void *p_data);
int rkflash_vendor_write(u32 sec, u32 n_sec, void *p_data);
#endif

View File

@ -2,15 +2,6 @@
/* Copyright (c) 2018 Rockchip Electronics Co. Ltd. */
#include <linux/kernel.h>
#include "rkflash_debug.h"
#include "sfc_nor.h"
#include "typedef.h"
void rknand_print_hex(char *s, void *buf, int width, int len)
{
print_hex_dump(KERN_WARNING, s, DUMP_PREFIX_OFFSET,
16, width, buf, len * width, 0);
}
unsigned int rkflash_debug = PRINT_BIT_SFC | PRINT_BIT_NANDC;

View File

@ -5,65 +5,91 @@
#ifndef _RKFLASH_DEBUG_H
#define _RKFLASH_DEBUG_H
/*
* Test switch
*/
#define BLK_STRESS_TEST_EN 0
#include <linux/kernel.h>
/*
* Print switch, set to 1 if needed
* Debug control center
* 1. Set Printing-adding-macro to 1 to allow print code being compiled in.
* 2. Set variable 'rkflash_debug' to control debug print to enable print.
*/
/*
* Printing-adding
*/
extern unsigned int rkflash_debug;
#define PRINT_SWI_SFC_I 1
#define PRINT_SWI_SFC_E 1
#define PRINT_SWI_SFC_HEX 1
#define PRINT_SWI_NANDC_I 1
#define PRINT_SWI_NANDC_E 1
#define PRINT_SWI_NANDC_HEX 1
/*
* Print switch, set var rkflash_debug corresponding bit to
* 1 if needed.
* I - info
* E - error
* HEX - multiline print
*/
#define PRINT_BIT_SFC_I BIT(0)
#define PRINT_BIT_SFC_E BIT(1)
#define PRINT_BIT_SFC_HEX BIT(2)
#define PRINT_BIT_SFC\
(PRINT_BIT_SFC_I | PRINT_BIT_SFC_E | PRINT_BIT_SFC_HEX)
#define PRINT_SWI_SFC_I 0
#define PRINT_SWI_SFC_E 1
#define PRINT_SWI_SFC_HEX 1
#define PRINT_SWI_NANDC_I 0
#define PRINT_SWI_NANDC_E 1
#define PRINT_SWI_NANDC_HEX 1
#define PRINT_BIT_NANDC_I BIT(4)
#define PRINT_BIT_NANDC_E BIT(5)
#define PRINT_BIT_NANDC_HEX BIT(5)
#define PRINT_BIT_NANDC\
(PRINT_BIT_NANDC_I | PRINT_BIT_NANDC_E | PRINT_BIT_NANDC_HEX)
#if (PRINT_SWI_SFC_I)
#define PRINT_SFC_I(...) pr_info(__VA_ARGS__)
#define PRINT_SFC_I(...) {if (rkflash_debug & PRINT_BIT_SFC_I)\
pr_info(__VA_ARGS__); }
#else
#define PRINT_SFC_I(...)
#endif
#if (PRINT_SWI_SFC_E)
#define PRINT_SFC_E(...) pr_info(__VA_ARGS__)
#define PRINT_SFC_E(...) {if (rkflash_debug & PRINT_BIT_SFC_E)\
pr_info(__VA_ARGS__); }
#else
#define PRINT_SFC_E(...)
#endif
#if (PRINT_SWI_SFC_HEX)
#define PRINT_SFC_HEX(s, buf, width, len)\
rknand_print_hex(s, buf, width, len)
rkflash_print_hex(s, buf, width, len)
#else
#define PRINT_SFC_HEX(s, buf, width, len)
#endif
#if (PRINT_SWI_NANDC_I)
#define PRINT_NANDC_I(...) pr_info(__VA_ARGS__)
#define PRINT_NANDC_I(...) {if (rkflash_debug & PRINT_BIT_NANDC_I)\
pr_info(__VA_ARGS__); }
#else
#define PRINT_NANDC_I(...)
#endif
#if (PRINT_SWI_NANDC_E)
#define PRINT_NANDC_E(...) pr_info(__VA_ARGS__)
#define PRINT_NANDC_E(...) {if (rkflash_debug & PRINT_BIT_NANDC_I)\
pr_info(__VA_ARGS__); }
#else
#define PRINT_NANDC_E(...)
#endif
#if (PRINT_SWI_NANDC_HEX)
#define PRINT_NANDC_HEX(s, buf, width, len)\
rknand_print_hex(s, buf, width, len)
(rkflash_print_hex(s, buf, width, len))
#else
#define PRINT_NANDC_HEX(s, buf, width, len)
#endif
void rkflash_print_hex(char *s, void *buf, u32 width, u32 len);
#define rkflash_print_hex(s, buf, w, len)\
print_hex_dump(KERN_WARNING, s, DUMP_PREFIX_OFFSET,\
4, w, buf, (len) * w, 0)
#endif

View File

@ -6,9 +6,9 @@
#include <linux/delay.h>
#include <linux/kernel.h>
#include "flash.h"
#include "flash_com.h"
#include "rkflash_debug.h"
#include "rk_sftl.h"
#include "sfc.h"
#include "sfc_nand.h"

View File

@ -115,6 +115,9 @@ struct nand_info {
u32 (*ecc_status)(void);
};
extern struct nand_phy_info g_nand_phy_info;
extern struct nand_ops g_nand_ops;
u32 sfc_nand_init(void);
void sfc_nand_deinit(void);
int sfc_nand_read_id(u8 *buf);

View File

@ -5,11 +5,10 @@
#include <linux/kernel.h>
#include <linux/mutex.h>
#include "rk_sftl.h"
#include "rkflash_api.h"
#include "rk_sftl.h"
#include "sfc.h"
#include "sfc_nand.h"
#include "typedef.h"
int snand_init(void __iomem *reg_addr)
{
@ -39,6 +38,16 @@ int snand_read(u32 sec, u32 n_sec, void *p_data)
return sftl_read(sec, n_sec, p_data);
}
int snand_vendor_read(u32 sec, u32 n_sec, void *p_data)
{
return sftl_vendor_read(sec, n_sec, p_data);
}
int snand_vendor_write(u32 sec, u32 n_sec, void *p_data)
{
return sftl_vendor_write(sec, n_sec, p_data);
}
void snand_deinit(void)
{
sftl_deinit();

View File

@ -8,7 +8,6 @@
#include "sfc.h"
#include "sfc_nor.h"
#include "rkflash_api.h"
#include "typedef.h"
#define VENDOR_PART_NUM 4

View File

@ -27,15 +27,4 @@
#define INVALID_UINT16 ((u16)0xFFFF)
#define INVALID_UINT32 ((u32)0xFFFFFFFFL)
#define PRINT_E pr_info
#define PRINT_I pr_info
void *ftl_malloc(int n_size);
void *ftl_memset(void *s, int c, unsigned int n);
void *ftl_memcpy(void *pv_to,
const void *pv_from,
unsigned int size);
void ftl_free(void *p);
void rknand_print_hex(char *s, void *buf, int width, int len);
#endif /*__TYPEDEF_H */