* write data to partition * * @param part partition * @param addr relative address for partition * @param buf write buffer * @param size write size * * @return >= 0: successful write data size * -1: error */
| 448 | * -1: error |
| 449 | */ |
| 450 | int fal_partition_write(const struct fal_partition *part, rt_uint32_t addr, const rt_uint8_t *buf, rt_size_t size) |
| 451 | { |
| 452 | int ret = 0; |
| 453 | const struct fal_flash_dev *flash_dev = NULL; |
| 454 | |
| 455 | RT_ASSERT(part); |
| 456 | RT_ASSERT(buf); |
| 457 | |
| 458 | if (addr + size > part->len) |
| 459 | { |
| 460 | LOG_E("Partition write error! Partition address out of bound."); |
| 461 | return -1; |
| 462 | } |
| 463 | |
| 464 | flash_dev = flash_device_find_by_part(part); |
| 465 | if (flash_dev == NULL) |
| 466 | { |
| 467 | LOG_E("Partition write error! Don't found flash device(%s) of the partition(%s).", part->flash_name, part->name); |
| 468 | return -1; |
| 469 | } |
| 470 | |
| 471 | ret = flash_dev->ops.write(part->offset + addr, buf, size); |
| 472 | if (ret < 0) |
| 473 | { |
| 474 | LOG_E("Partition write error! Flash device(%s) write error!", part->flash_name); |
| 475 | } |
| 476 | |
| 477 | return ret; |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * erase partition data |