mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #11081 from OTAkeys/pr/fix_mtd_spi_nor_read
drivers/mtd_spi_nor: fix read spanning pages
This commit is contained in:
commit
c7b15f4abe
@ -420,17 +420,9 @@ static int mtd_spi_nor_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t
|
|||||||
if (addr > chipsize) {
|
if (addr > chipsize) {
|
||||||
return -EOVERFLOW;
|
return -EOVERFLOW;
|
||||||
}
|
}
|
||||||
if (size > mtd->page_size) {
|
|
||||||
size = mtd->page_size;
|
|
||||||
}
|
|
||||||
if ((addr + size) > chipsize) {
|
if ((addr + size) > chipsize) {
|
||||||
size = chipsize - addr;
|
size = chipsize - addr;
|
||||||
}
|
}
|
||||||
uint32_t page_addr_mask = dev->page_addr_mask;
|
|
||||||
if ((addr & page_addr_mask) != ((addr + size - 1) & page_addr_mask)) {
|
|
||||||
/* Reads across page boundaries must be split */
|
|
||||||
size = mtd->page_size - (addr & ~(page_addr_mask));
|
|
||||||
}
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -215,10 +215,24 @@ static void test_mtd_write_read(void)
|
|||||||
|
|
||||||
/* out of bounds write (more than page size) */
|
/* out of bounds write (more than page size) */
|
||||||
const size_t page_size = dev->page_size;
|
const size_t page_size = dev->page_size;
|
||||||
const uint8_t buf_page[page_size + 1];
|
uint8_t buf_page[page_size + 1];
|
||||||
|
memset(buf_page, 1, sizeof(buf_page));
|
||||||
ret = mtd_write(dev, buf_page, 0, sizeof(buf_page));
|
ret = mtd_write(dev, buf_page, 0, sizeof(buf_page));
|
||||||
TEST_ASSERT_EQUAL_INT(-EOVERFLOW, ret);
|
TEST_ASSERT_EQUAL_INT(-EOVERFLOW, ret);
|
||||||
|
|
||||||
|
/* Read more than one page */
|
||||||
|
ret = mtd_erase(dev, 0, dev->page_size * dev->pages_per_sector);
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, ret);
|
||||||
|
ret = mtd_write(dev, buf_page, 0, dev->page_size);
|
||||||
|
TEST_ASSERT_EQUAL_INT(dev->page_size, ret);
|
||||||
|
ret = mtd_write(dev, buf_page, dev->page_size, dev->page_size);
|
||||||
|
TEST_ASSERT_EQUAL_INT(dev->page_size, ret);
|
||||||
|
memset(buf_page, 0, sizeof(buf_page));
|
||||||
|
ret = mtd_read(dev, buf_page, 0, sizeof(buf_page));
|
||||||
|
TEST_ASSERT_EQUAL_INT(sizeof(buf_page), ret);
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, buf_page[0]);
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, buf_page[sizeof(buf_page) - 1]);
|
||||||
|
|
||||||
/* pages overlap write */
|
/* pages overlap write */
|
||||||
ret = mtd_write(dev, buf, dev->page_size - (sizeof(buf) / 2), sizeof(buf));
|
ret = mtd_write(dev, buf, dev->page_size - (sizeof(buf) / 2), sizeof(buf));
|
||||||
TEST_ASSERT_EQUAL_INT(-EOVERFLOW, ret);
|
TEST_ASSERT_EQUAL_INT(-EOVERFLOW, ret);
|
||||||
|
Loading…
Reference in New Issue
Block a user