stm32/storage: Change storage_read/write_blocks to return int type.
And return -MP_EIO if calling storage_read_block/storage_write_block fails. This lines up with the return type and value (negative for error) of the calls to MICROPY_HW_BDEV_READBLOCKS (and WRITEBLOCKS, and BDEV2 versions).
This commit is contained in:
parent
120368ba1a
commit
d8057c325a
|
@ -185,7 +185,7 @@ bool storage_write_block(const uint8_t *src, uint32_t block) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t storage_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) {
|
int storage_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) {
|
||||||
#if defined(MICROPY_HW_BDEV_READBLOCKS)
|
#if defined(MICROPY_HW_BDEV_READBLOCKS)
|
||||||
if (FLASH_PART1_START_BLOCK <= block_num && block_num + num_blocks <= FLASH_PART1_START_BLOCK + MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0)) {
|
if (FLASH_PART1_START_BLOCK <= block_num && block_num + num_blocks <= FLASH_PART1_START_BLOCK + MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0)) {
|
||||||
return MICROPY_HW_BDEV_READBLOCKS(dest, block_num - FLASH_PART1_START_BLOCK, num_blocks);
|
return MICROPY_HW_BDEV_READBLOCKS(dest, block_num - FLASH_PART1_START_BLOCK, num_blocks);
|
||||||
|
@ -200,13 +200,13 @@ mp_uint_t storage_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_bl
|
||||||
|
|
||||||
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 -MP_EIO; // error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0; // success
|
return 0; // success
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t storage_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) {
|
int storage_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) {
|
||||||
#if defined(MICROPY_HW_BDEV_WRITEBLOCKS)
|
#if defined(MICROPY_HW_BDEV_WRITEBLOCKS)
|
||||||
if (FLASH_PART1_START_BLOCK <= block_num && block_num + num_blocks <= FLASH_PART1_START_BLOCK + MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0)) {
|
if (FLASH_PART1_START_BLOCK <= block_num && block_num + num_blocks <= FLASH_PART1_START_BLOCK + MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_NUM_BLOCKS, 0)) {
|
||||||
return MICROPY_HW_BDEV_WRITEBLOCKS(src, block_num - FLASH_PART1_START_BLOCK, num_blocks);
|
return MICROPY_HW_BDEV_WRITEBLOCKS(src, block_num - FLASH_PART1_START_BLOCK, num_blocks);
|
||||||
|
@ -221,7 +221,7 @@ mp_uint_t storage_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t
|
||||||
|
|
||||||
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 -MP_EIO; // error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0; // success
|
return 0; // success
|
||||||
|
|
|
@ -47,9 +47,9 @@ void storage_flush(void);
|
||||||
bool storage_read_block(uint8_t *dest, uint32_t block);
|
bool storage_read_block(uint8_t *dest, uint32_t block);
|
||||||
bool storage_write_block(const uint8_t *src, uint32_t block);
|
bool storage_write_block(const uint8_t *src, uint32_t block);
|
||||||
|
|
||||||
// these return 0 on success, non-zero on error
|
// these return 0 on success, negative errno on error
|
||||||
mp_uint_t storage_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks);
|
int storage_read_blocks(uint8_t *dest, 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);
|
int storage_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks);
|
||||||
|
|
||||||
int32_t flash_bdev_ioctl(uint32_t op, uint32_t arg);
|
int32_t flash_bdev_ioctl(uint32_t op, uint32_t arg);
|
||||||
bool flash_bdev_readblock(uint8_t *dest, uint32_t block);
|
bool flash_bdev_readblock(uint8_t *dest, uint32_t block);
|
||||||
|
|
Loading…
Reference in New Issue