Skip to content

Commit

Permalink
bbm: Fix errors (PX4#25)
Browse files Browse the repository at this point in the history
* bbm: Fix errors

* bbm: remove unnecessary code
  • Loading branch information
Jun-Tao authored and haiyangyuneec committed Jan 7, 2019
1 parent 062f7c9 commit 30053f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
18 changes: 8 additions & 10 deletions drivers/mtd/smart.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ static bool inline smart_is_free(FAR struct smart_struct_s *dev, uint16_t sector

static void smart_save_meta(FAR struct smart_struct_s *dev)
{
/* save sMap at block 1 */

MTD_WRITE(dev->mtd, dev->mapphyssector * dev->sectorsize, (dev->neraseblocks << 1),
(FAR uint8_t *) dev->freecount);
Expand All @@ -344,7 +343,6 @@ static void smart_save_meta(FAR struct smart_struct_s *dev)

static void smart_load_meta(FAR struct smart_struct_s *dev)
{
/* load sMap at block 1 */

uint32_t readaddress = dev->mapphyssector * dev->sectorsize;
MTD_READ(dev->mtd, readaddress, (dev->neraseblocks << 1), (FAR uint8_t *) dev->freecount);
Expand All @@ -361,7 +359,7 @@ static void smart_clear_signature(FAR struct smart_struct_s *dev)
char headerbuf[SMART_SIGNATURE_SIZE];
memset(headerbuf, CONFIG_SMARTFS_ERASEDSTATE, SMART_SIGNATURE_SIZE);

wrcount = MTD_WRITE(dev->mtd, dev->rootphyssector, SMART_SIGNATURE_SIZE, headerbuf);
wrcount = MTD_WRITE(dev->mtd, dev->rootphyssector * dev->sectorsize, SMART_SIGNATURE_SIZE, headerbuf);
if (wrcount != SMART_SIGNATURE_SIZE)
{
ferr("ERROR: write signature failed: %d.\n",wrcount);
Expand Down Expand Up @@ -885,7 +883,7 @@ static int smart_scan(FAR struct smart_struct_s *dev, bool is_format)
/* Skip current bad block */
if (ret == -EIO)
{
smart_handle_badblock(dev, physsector);
smart_handle_badblock(dev, physsector / dev->sectorsPerBlk);
physsector++;
if (physsector >= (SMART_FIRST_ALLOC_SECTOR-1))
goto err_out;
Expand Down Expand Up @@ -1001,7 +999,7 @@ static int smart_scan(FAR struct smart_struct_s *dev, bool is_format)
ferr("Error: Read physical sector %d error, ret = %d\n", physsector, ret);
if (ret == -EIO)
{
smart_handle_badblock(dev, block);
smart_handle_badblock(dev, physsector / dev->sectorsPerBlk );
}
continue;
}
Expand Down Expand Up @@ -1231,13 +1229,13 @@ static inline int smart_llformat(FAR struct smart_struct_s *dev, unsigned long a

headerbuf[SMART_FMT_ROOTDIRS_POS] = (uint8_t) (arg & 0xff);

wrcount = MTD_WRITE(dev->mtd, dev->rootphyssector, SMART_SIGNATURE_SIZE, headerbuf);
wrcount = MTD_WRITE(dev->mtd, dev->rootphyssector * dev->sectorsize, SMART_SIGNATURE_SIZE, headerbuf);
if (wrcount != SMART_SIGNATURE_SIZE)
{
ferr("ERROR: write signature failed\n");
if (ret == -EIO)
if (wrcount == -EIO)
{
smart_handle_badblock(dev, dev->rootphyssector);
smart_handle_badblock(dev, dev->rootphyssector / dev->sectorsPerBlk);
}
if (wrcount < 0)
{
Expand Down Expand Up @@ -1359,7 +1357,7 @@ static uint16_t smart_findfreephyssector(FAR struct smart_struct_s *dev,
if (ret == -EIO)
{
/* Mark it as bad block */
smart_handle_badblock(dev, i / dev->sectorsPerBlk);
smart_handle_badblock(dev, sector / dev->sectorsPerBlk);
}

/* Try next sector */
Expand Down Expand Up @@ -1585,7 +1583,7 @@ static int smart_readsector(FAR struct smart_struct_s *dev,
if (ret == -EIO)
{
/* Mark it as bad block */
smart_handle_badblock(dev, readaddr / dev->sectorsPerBlk);
smart_handle_badblock(dev, physsector / dev->sectorsPerBlk);
}
goto errout;
}
Expand Down
13 changes: 8 additions & 5 deletions drivers/mtd/spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ int spi_mark_badblock(FAR struct spi_flash_dev_s *priv, size_t block)
/* Mark bad block */
memset(spare_buf, 0, priv->spare_size);

ssize_t nbytes = priv->pagewrite(priv, address, priv->spare_size, true, (FAR uint8_t *)spare_buf);
if (nbytes != priv->spare_size) {
ssize_t nbytes = priv->pagewrite(priv, address, 2, true, (FAR uint8_t *)spare_buf);
if (nbytes != 2) {
ret = -EFAULT;
goto errout;
}
Expand All @@ -130,14 +130,17 @@ int spi_mark_badblock(FAR struct spi_flash_dev_s *priv, size_t block)

bool spi_is_badblock(FAR struct spi_flash_dev_s *priv, size_t block)
{
bool ret;
bool ret = false;
off_t address = (block << priv->block_shift);
uint8_t *spare_buf = kmm_malloc(priv->spare_size);

ssize_t nbytes;

nbytes = priv->pageread(priv, address, priv->spare_size, true, (FAR uint8_t *)spare_buf);
if (nbytes != priv->spare_size) {
if (nbytes == -EIO) {
ret = true;
goto errout;
} else if (nbytes != priv->spare_size) {
//TODO: Check whether set block as good or bad when read spare data failed
ret = false;
goto errout;
Expand Down Expand Up @@ -297,7 +300,7 @@ static ssize_t spi_cacheread(struct spi_flash_dev_s *priv, size_t block, FAR uin
ssize_t ret;

#ifdef CONFIG_SPI_CACHE_DEBUG
ferr("block: %d shift=%d\n", block, shift);
ferr("block: %d\n", block);
#endif

/* Check if the requested erase block is already in the cache */
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/w25.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ static ssize_t w25_pageread(FAR struct spi_flash_dev_s *priv, off_t address, siz
w25_read_last_ecc_address(priv->spi, &ecc_page);
ferr("ecc error block = %08x, page = %04x, last ecc page = %04x, status = (%02x, %02x, %02x)\n", address>>priv->block_shift, page, ecc_page, status2, status3, status);
#else
ferr("ecc error block = %08x, status = %02x\n", address>>priv->block_shift, page, status);
ferr("ecc error block = %08x, page = %04x, status = %02x\n", address>>priv->block_shift, page, status);
#endif
return -EIO;
}
Expand Down

0 comments on commit 30053f2

Please sign in to comment.