29 lines
475 B
C
29 lines
475 B
C
|
#include <stdint.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
#include <flash.h>
|
||
|
#include <macros.h>
|
||
|
|
||
|
#include <fs/block.h>
|
||
|
|
||
|
int block_is_erased(struct flash_dev *dev, uint32_t addr, uint32_t len)
|
||
|
{
|
||
|
char buf[32], cmp[32];
|
||
|
size_t count;
|
||
|
|
||
|
memset(cmp, 0xff, sizeof cmp);
|
||
|
|
||
|
for (; len; addr += count, len -= count) {
|
||
|
count = min(len, sizeof buf);
|
||
|
|
||
|
if (flash_read(dev, addr, buf, count) < 0)
|
||
|
return -1;
|
||
|
|
||
|
if (memcmp(buf, cmp, count) != 0)
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|