Skip to main content

esp_partition_copy

Function esp_partition_copy 

Source
pub unsafe extern "C" fn esp_partition_copy(
    dest_part: *const esp_partition_t,
    dest_offset: u32,
    src_part: *const esp_partition_t,
    src_offset: u32,
    size: usize,
) -> i32
Expand description

@brief Copy data from a source partition at a specific offset to a destination partition at a specific offset.

The destination offset must be aligned to the flash sector size (SPI_FLASH_SEC_SIZE = 0x1000). If “size” is SIZE_MAX, the entire destination partition (from dest_offset onward) will be erased, and the function will copy all of the source partition starting from src_offset into the destination. The function ensures that the destination partition is erased on sector boundaries (erase size is aligned up SPI_FLASH_SEC_SIZE).

This function does the following:

  • erases the destination partition from dest_offset to the specified size (or the whole partition if “size” == SIZE_MAX),
  • maps data from the source partition in chunks,
  • writes the source data into the destination partition in corresponding chunks.

@param dest_part Pointer to a destination partition. @param dest_offset Offset in the destination partition where the data should be written (must be aligned to SPI_FLASH_SEC_SIZE = 0x1000). @param src_part Pointer to a source partition (must be located on internal flash). @param src_offset Offset in the source partition where the data should be read from. @param size Number of bytes to copy from the source partition to the destination partition. If “size” is SIZE_MAX, the function copies from src_offset to the end of the source partition and erases the entire destination partition (from dest_offset onward).

@return ESP_OK, if the source partition was copied successfully to the destination partition; ESP_ERR_INVALID_ARG, if src_part or dest_part are incorrect, or if dest_offset is not sector aligned; ESP_ERR_INVALID_SIZE, if the copy would go out of bounds of the source or destination partition; ESP_ERR_NOT_ALLOWED, if the destination partition is read-only; or one of the error codes from the lower-level flash driver.