Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add esp_custom_part_ota component #328

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hmalpani
Copy link
Collaborator

@hmalpani hmalpani commented May 16, 2024

Add new component to support OTA updates for non-app type partitions in ESP-IDF

Checklist

  • Component contains License
  • Component contains README.md
  • Component contains idf_component.yml file with url field defined
  • Add Example
  • Add Component Unit tests
  • Component was added to upload job
  • Component was added to build job
  • Optional: Component contains unit tests
  • CI passing

Change description

Please describe your change here

@hmalpani hmalpani marked this pull request as draft May 16, 2024 11:33
@hmalpani hmalpani force-pushed the feat/non_app_ota_update branch 2 times, most recently from a14c6c1 to 0bac912 Compare May 23, 2024 07:05
@hmalpani hmalpani changed the title feat: Add esp_non_app_ota component feat: Add esp_custom_part_ota component May 23, 2024
@hmalpani hmalpani force-pushed the feat/non_app_ota_update branch 2 times, most recently from 3551754 to a337719 Compare May 24, 2024 08:57
esp_custom_part_ota/include/esp_custom_part_ota.h Outdated Show resolved Hide resolved
esp_custom_part_ota/include/esp_custom_part_ota.h Outdated Show resolved Hide resolved
* - ESP_OK
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_custom_part_ota_set_backup_partition(esp_custom_part_ota_handle_t ctx, const esp_partition_t *backup_partition);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done in the begin API too, or this API has some special purpose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems redundant. I will remove this API


// Store backup data information in the default NVS partition.
nvs_handle_t backup_info_handle = 0;
ret = nvs_open(BACKUP_STORAGE_NAMESPACE, NVS_READWRITE, &backup_info_handle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the power goes at this moment then backup length is not yet stored and the primary partition is already erased. So this will result in data loss?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would have resulted in data loss. I have updated the code to first update the backup info in NVS and then erase the partition.


Custom Data Partition OTA aims at enabling Over-the-Air data update for custom data partitions in ESP-IDF.

## ESP Custom Partition OTA Abstraction Layer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example uses which scheme, should we mention about it here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a config option to enable/disable the backing-up of the data

esp_custom_part_ota/src/esp_custom_part_ota.c Outdated Show resolved Hide resolved
ESP_LOGI(TAG, "No backup present in the backup partition. Nothing to restore");
return ESP_OK;
}
if (handle->backup_len > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there be a scenario where this length is partial and not for full image? Do we need any image integrity checks (e.g., SHA sum) in the NVS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the user can set the length of the data to be backed-up. I don't think we need any image integrity checks. We store the size of data in NVS. Also in case of any error, the APIs will return relevant error code.

This component can be used for performing OTA upgrades for custom partitions in ESP-IDF
return ESP_ERR_NO_MEM;
}

esp_err_t ret = esp_partition_erase_range(ctx->backup_partition, 0, ctx->backup_len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we allow this API to be executed twice for 2 different partitions? If not, how can we detect if there exist a backup for any previous partition? Do we need some API to invalidate the previous backup here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right. I didn't think of this case. I think we can store some information in NVS regarding this and iterate over the data to check if some other backup is stored in the partition.

static const char *TAG = "esp_custom_part_ota";

#define BACKUP_STORAGE_NAMESPACE "esp_custom_ota"
#define BACKUP_STORAGE_DATA_LEN "backup_len"
Copy link
Member

@mahavirj mahavirj May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it help if we make this variable partition specific:

snprintf(str, size, "%s_backup_len", part_name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants