flash: implement functions to check if pages are all zero or one

tags/0.1.0
S.J.R. van Schaik 8 years ago
parent fe1cd870c0
commit 756e5852cb
  1. 3
      include/flash.h
  2. 16
      source/core/flash.c
  3. 2
      source/drivers/spi_flash.c

@ -24,7 +24,8 @@ struct flash_dev {
uint8_t log2_block_size;
};
int default_flash_is_erased(struct flash_dev *dev, uint32_t addr);
int default_flash_is_zero(struct flash_dev *dev, uint32_t addr);
int default_flash_is_one(struct flash_dev *dev, uint32_t addr);
size_t default_flash_copy(struct flash_dev *dev, uint32_t dst, uint32_t src,
size_t len);

@ -5,9 +5,9 @@
#include <flash.h>
#include <macros.h>
int default_flash_is_erased(struct flash_dev *dev, uint32_t addr)
static int default_flash_is_val(struct flash_dev *dev, uint32_t addr, char val)
{
uint8_t data[32];
char data[32];
size_t i, nbytes, len = 1 << dev->log2_block_size;
addr <<= dev->log2_block_size;
@ -19,7 +19,7 @@ int default_flash_is_erased(struct flash_dev *dev, uint32_t addr)
return 0;
for (i = 0; i < sizeof(data); ++i) {
if (data[i] != 0xff)
if (data[i] != val)
return 0;
}
@ -30,6 +30,16 @@ int default_flash_is_erased(struct flash_dev *dev, uint32_t addr)
return 1;
}
int default_flash_is_zero(struct flash_dev *dev, uint32_t addr)
{
return default_flash_is_val(dev, addr, 0);
}
int default_flash_is_one(struct flash_dev *dev, uint32_t addr)
{
return default_flash_is_val(dev, addr, 0xff);
}
size_t default_flash_copy(struct flash_dev *dev, uint32_t dst, uint32_t src,
size_t len)
{

@ -24,7 +24,7 @@ static struct flash_ops spi_flash_ops = {
.read = spi_flash_read,
.write = spi_flash_write,
.copy = default_flash_copy,
.is_erased = default_flash_is_erased,
.is_erased = default_flash_is_one,
.erase = spi_flash_erase,
};

Loading…
Cancel
Save