Skip to content

Commit

Permalink
arm/tlsr82: bugfix, tlsr82_flash_ioctl() return wrong value.
Browse files Browse the repository at this point in the history
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
  • Loading branch information
CV-Bowen committed Jun 13, 2022
1 parent 53c6789 commit 3bad2da
Showing 1 changed file with 55 additions and 11 deletions.
66 changes: 55 additions & 11 deletions arch/arm/src/tlsr82/tlsr82_flash_mtd.c
Expand Up @@ -320,13 +320,12 @@ static void tlsr82_flash_print(const char *msg, const uint8_t *buf,
#ifdef CONFIG_TLSR82_FLASH_TEST
static int tlsr82_flash_test(struct tlsr82_flash_dev_s *priv)
{
struct mtd_geometry_s geo;
int ret = OK;
int npages = 0;
int i = 0;
int j = 0;

npages = priv->nsectors * (TLSR82_SECTOR_SIZE / TLSR82_PAGE_SIZE);

ferr("======== Flash test start ========\n");

/* 1. print the manufacture id and unique id */
Expand All @@ -342,10 +341,21 @@ static int tlsr82_flash_test(struct tlsr82_flash_dev_s *priv)

ferr("%s\n", print_buf);

ret = tlsr82_flash_ioctl(&priv->mtd, MTDIOC_GEOMETRY, (unsigned long)&geo);
if (ret != OK)
{
ferr(" Flash geometry get failed, ret=%d\n", ret);
goto errout;
}

npages = priv->nsectors * (TLSR82_SECTOR_SIZE / TLSR82_PAGE_SIZE);

ferr(" Flash Start Address: 0x%08lx\n", priv->baseaddr);
ferr(" Flash Size : 0x%08lx\n", priv->size);
ferr(" Flash Sector: %d\n", priv->nsectors);
ferr(" Flash Page : %d\n", npages);
ferr(" Flash Size : 0x%08lx\n", priv->size);
ferr(" Flash Sector Size : %ld\n", geo.erasesize);
ferr(" Flash Page Size : %ld\n", geo.blocksize);
ferr(" Flash Sector : %ld\n", geo.neraseblocks);
ferr(" Flash Page : %d\n", npages);

/* 2. erase chip and check all the erased sector, all the bit in erased
* sector should be 1.
Expand All @@ -354,7 +364,13 @@ static int tlsr82_flash_test(struct tlsr82_flash_dev_s *priv)
ferr("Flash chip erase test start:\n");

FLASH_ERASE_TRACE_START();
tlsr82_flash_chip_erase(priv);
ret = tlsr82_flash_ioctl(&priv->mtd, MTDIOC_BULKERASE, 0);
if (ret != OK)
{
ferr(" Flash erase failed, ret=%d\n", ret);
goto errout;
}

FLASH_ERASE_TRACE_END();

for (i = 0; i < npages; i++)
Expand Down Expand Up @@ -429,7 +445,13 @@ static int tlsr82_flash_test(struct tlsr82_flash_dev_s *priv)
int k;

ferr("Erase chip for byte write test\n");
tlsr82_flash_chip_erase(priv);
ret = tlsr82_flash_ioctl(&priv->mtd, MTDIOC_BULKERASE, 0);
if (ret != OK)
{
ferr(" Flash erase failed, ret=%d\n", ret);
goto errout;
}

ferr("Erase chip finished\n");

ferr("Flash byte read/write test start\n");
Expand Down Expand Up @@ -504,7 +526,13 @@ static int tlsr82_flash_test(struct tlsr82_flash_dev_s *priv)
/* 1) erase the chip */

ferr("Erase chip for protect/unprotect test\n");
tlsr82_flash_chip_erase(priv);
ret = tlsr82_flash_ioctl(&priv->mtd, MTDIOC_BULKERASE, 0);
if (ret != OK)
{
ferr(" Flash erase failed, ret=%d\n", ret);
goto errout;
}

ferr("Erase chip finished\n");

/* 2) write data into chip */
Expand All @@ -523,7 +551,13 @@ static int tlsr82_flash_test(struct tlsr82_flash_dev_s *priv)
/* 3) protect the flash, read the flash status register */

FLASH_PROT_TRACE_START();
tlsr82_flash_protect();
ret = tlsr82_flash_ioctl(&priv->mtd, MTDIOC_PROTECT, 0);
if (ret != OK)
{
ferr(" Flash protect failed, ret=%d\n", ret);
goto errout;
}

FLASH_PROT_TRACE_END();

status = tlsr82_flash_read_status(5);
Expand All @@ -539,7 +573,13 @@ static int tlsr82_flash_test(struct tlsr82_flash_dev_s *priv)
}

FLASH_UNPROT_TRACE_START();
tlsr82_flash_unprotect();
ret = tlsr82_flash_ioctl(&priv->mtd, MTDIOC_UNPROTECT, 0);
if (ret != OK)
{
ferr(" Flash unprotect failed, ret=%d\n", ret);
goto errout;
}

FLASH_UNPROT_TRACE_END();

/* 5) read the chip, the data should be same as the data written in 2) */
Expand Down Expand Up @@ -729,7 +769,7 @@ static int tlsr82_flash_ioctl(struct mtd_dev_s *dev, int cmd,
unsigned long arg)
{
struct tlsr82_flash_dev_s *priv = (struct tlsr82_flash_dev_s *)dev;
int ret = -EINVAL; /* Assume good command with bad parameters */
int ret = OK; /* Assume good command with good parameters */

finfo("cmd: %d\n", cmd);

Expand Down Expand Up @@ -761,6 +801,10 @@ static int tlsr82_flash_ioctl(struct mtd_dev_s *dev, int cmd,
" neraseblocks: %" PRId32 "\n",
geo->blocksize, geo->erasesize, geo->neraseblocks);
}
else
{
ret = -EINVAL;
}
}
break;

Expand Down

0 comments on commit 3bad2da

Please sign in to comment.