stm32/storage: Add option for bdev to supply readblock/writeblocks.
If the underlying block device supports it, it's more efficient to read/write multiple blocks at once.
This commit is contained in:
parent
0210383da5
commit
861080aa3d
@ -151,8 +151,10 @@ bool storage_read_block(uint8_t *dest, uint32_t block) {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
#if defined(BDEV_READBLOCK)
|
||||||
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + BDEV_NUM_BLOCKS) {
|
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + BDEV_NUM_BLOCKS) {
|
||||||
return BDEV_READBLOCK(dest, block - FLASH_PART1_START_BLOCK);
|
return BDEV_READBLOCK(dest, block - FLASH_PART1_START_BLOCK);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -163,14 +165,22 @@ bool storage_write_block(const uint8_t *src, uint32_t block) {
|
|||||||
if (block == 0) {
|
if (block == 0) {
|
||||||
// can't write MBR, but pretend we did
|
// can't write MBR, but pretend we did
|
||||||
return true;
|
return true;
|
||||||
|
#if defined(BDEV_WRITEBLOCK)
|
||||||
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + BDEV_NUM_BLOCKS) {
|
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + BDEV_NUM_BLOCKS) {
|
||||||
return BDEV_WRITEBLOCK(src, block - FLASH_PART1_START_BLOCK);
|
return BDEV_WRITEBLOCK(src, block - FLASH_PART1_START_BLOCK);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t storage_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) {
|
mp_uint_t storage_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) {
|
||||||
|
#if defined(BDEV_READBLOCKS)
|
||||||
|
if (FLASH_PART1_START_BLOCK <= block_num && block_num + num_blocks <= FLASH_PART1_START_BLOCK + BDEV_NUM_BLOCKS) {
|
||||||
|
return BDEV_READBLOCKS(dest, block_num - FLASH_PART1_START_BLOCK, num_blocks);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
for (size_t i = 0; i < num_blocks; i++) {
|
for (size_t i = 0; i < num_blocks; i++) {
|
||||||
if (!storage_read_block(dest + i * FLASH_BLOCK_SIZE, block_num + i)) {
|
if (!storage_read_block(dest + i * FLASH_BLOCK_SIZE, block_num + i)) {
|
||||||
return 1; // error
|
return 1; // error
|
||||||
@ -180,6 +190,12 @@ mp_uint_t storage_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_bl
|
|||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t storage_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) {
|
mp_uint_t storage_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) {
|
||||||
|
#if defined(BDEV_WRITEBLOCKS)
|
||||||
|
if (FLASH_PART1_START_BLOCK <= block_num && block_num + num_blocks <= FLASH_PART1_START_BLOCK + BDEV_NUM_BLOCKS) {
|
||||||
|
return BDEV_WRITEBLOCKS(src, block_num - FLASH_PART1_START_BLOCK, num_blocks);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
for (size_t i = 0; i < num_blocks; i++) {
|
for (size_t i = 0; i < num_blocks; i++) {
|
||||||
if (!storage_write_block(src + i * FLASH_BLOCK_SIZE, block_num + i)) {
|
if (!storage_write_block(src + i * FLASH_BLOCK_SIZE, block_num + i)) {
|
||||||
return 1; // error
|
return 1; // error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user