rkflash: support SPI Nor gpt update

Change-Id: I8469f7141f2b4e62340e8f8b7b25038ab7d19f44
Signed-off-by: Jon Lin <jon.lin@rock-chips.com>
This commit is contained in:
Jon Lin 2019-12-19 12:46:05 +08:00
parent 164b2567a2
commit 7edaca2270
3 changed files with 35 additions and 1 deletions

View File

@ -64,6 +64,30 @@ int rksfc_nor_read(struct udevice *udev, u32 sec, u32 n_sec, void *p_data)
return n_sec;
}
/* Workaround for GPT not aligned program */
int rksfc_nor_simply_over_write(struct udevice *udev,
u32 sec,
u32 n_sec,
const void *p_data)
{
struct rkflash_info *priv = dev_get_priv(udev);
struct SFNOR_DEV *p_dev = (struct SFNOR_DEV *)&priv->flash_dev_info;
u8 *pbuf_temp;
u32 addr_aligned, offset, remain;
addr_aligned = sec / NOR_SECS_PAGE * NOR_SECS_PAGE;
offset = sec - addr_aligned;
remain = (offset + n_sec + NOR_SECS_PAGE - 1) / NOR_SECS_PAGE * NOR_SECS_PAGE;
pbuf_temp = malloc(remain * 512);
snor_read(p_dev, addr_aligned, remain, pbuf_temp);
memcpy(pbuf_temp + offset * 512, p_data, n_sec * 512);
snor_write(p_dev, addr_aligned, remain, pbuf_temp);
free(pbuf_temp);
return n_sec;
}
int rksfc_nor_write(struct udevice *udev,
u32 sec,
u32 n_sec,
@ -74,6 +98,10 @@ int rksfc_nor_write(struct udevice *udev,
char *buf = (char *)p_data;
struct rkflash_info *priv = dev_get_priv(udev);
struct SFNOR_DEV *p_dev = (struct SFNOR_DEV *)&priv->flash_dev_info;
u32 sfc_nor_density = rksfc_nor_get_capacity(udev);
if (sec >= (sfc_nor_density - 33))
return rksfc_nor_simply_over_write(udev, sec, n_sec, p_data);
if (sec + n_sec - 1 < FLASH_VENDOR_PART_START ||
sec > FLASH_VENDOR_PART_END) {

View File

@ -242,6 +242,8 @@ int snor_erase(struct SFNOR_DEV *p_dev,
union SFCCMD_DATA sfcmd;
int timeout[] = {400, 2000, 40000}; /* ms */
rkflash_print_dio("%s %x\n", __func__, addr);
if (erase_type > ERASE_CHIP)
return SFC_PARAM_ERR;
@ -431,6 +433,8 @@ int snor_read(struct SFNOR_DEV *p_dev, u32 sec, u32 n_sec, void *p_data)
u32 addr, size, len;
u8 *p_buf = (u8 *)p_data;
rkflash_print_dio("%s %x %x\n", __func__, sec, n_sec);
if ((sec + n_sec) > p_dev->capacity)
return SFC_PARAM_ERR;
@ -463,6 +467,8 @@ int snor_write(struct SFNOR_DEV *p_dev, u32 sec, u32 n_sec, void *p_data)
u8 *p_buf = (u8 *)p_data;
u32 total_sec = n_sec;
rkflash_print_dio("%s %x %x %x\n", __func__, sec, n_sec, ((u32 *)p_data)[0]);
if ((sec + n_sec) > p_dev->capacity)
return SFC_PARAM_ERR;

View File

@ -12,7 +12,7 @@
#define NOR_PAGE_SIZE 256
#define NOR_BLOCK_SIZE (64 * 1024)
#define NOR_SECS_BLK (NOR_BLOCK_SIZE / 512)
#define NOR_SECS_PAGE 4
#define NOR_SECS_PAGE 8
#define FEA_READ_STATUE_MASK (0x3 << 0)
#define FEA_STATUE_MODE1 0