I have multiple app partitions (factory, ota_0 and ota_1).
Now when booting into factory I would like to read out the software version of for example ota_0.
My initial way was to utilize the esp_app_desc_t or esp_custom_app_desc_t struct as it has a fixed offset.
Use its offset from the .map file plus for example the partition offset of ota_0, but it looks like it does not contain the actual value.
How to read out software (project) version from another partition?
-
- Posts: 52
- Joined: Thu Jun 22, 2023 12:50 pm
Re: How to read out software (project) version from another partition?
Hello. If I understand you correctly, you should be able to use `esp_ota_get_partition_description` function.
- /**
- * @brief Returns esp_app_desc structure for app partition. This structure includes app version.
- *
- * Returns a description for the requested app partition.
- * @param[in] partition Pointer to app partition. (only app partition)
- * @param[out] app_desc Structure of info about app.
- * @return
- * - ESP_OK Successful.
- * - ESP_ERR_NOT_FOUND app_desc structure is not found. Magic word is incorrect.
- * - ESP_ERR_NOT_SUPPORTED Partition is not application.
- * - ESP_ERR_INVALID_ARG Arguments is NULL or if partition's offset exceeds partition size.
- * - ESP_ERR_INVALID_SIZE Read would go out of bounds of the partition.
- * - or one of error codes from lower-level flash driver.
- */
- esp_err_t esp_ota_get_partition_description(const esp_partition_t *partition, esp_app_desc_t *app_desc);
Re: How to read out software (project) version from another partition?
Thanks for the answer.
Does this also work with const __attribute__((section(".rodata_custom_desc"))) esp_custom_app_desc_t custom_app_desc = { ... } ?
Edit:
I guess I have to make my own:
with :
Offset for custom structure is sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t).
I suppose ESP_APP_DESC_MAGIC_WORD is just to check if the data was corrupted?
And can this be also used for the SSBL?
Does this also work with const __attribute__((section(".rodata_custom_desc"))) esp_custom_app_desc_t custom_app_desc = { ... } ?
Edit:
I guess I have to make my own:
Code: Select all
esp_err_t esp_ota_get_partition_description(const esp_partition_t *partition, esp_app_desc_t *app_desc)
{
if (partition == NULL || app_desc == NULL) {
return ESP_ERR_INVALID_ARG;
}
if(partition->type != ESP_PARTITION_TYPE_APP) {
return ESP_ERR_NOT_SUPPORTED;
}
esp_err_t err = esp_partition_read(partition, sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t), app_desc, sizeof(esp_app_desc_t));
if (err != ESP_OK) {
return err;
}
if (app_desc->magic_word != ESP_APP_DESC_MAGIC_WORD) {
return ESP_ERR_NOT_FOUND;
}
return ESP_OK;
}
Offset for custom structure is sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t).
I suppose ESP_APP_DESC_MAGIC_WORD is just to check if the data was corrupted?
And can this be also used for the SSBL?
Re: How to read out software (project) version from another partition?
Hi @leschge,
custom application versioning is not currently deployed in the IDF, though there is a support for generating .rodata_custom_desc section in the target binary.
Thus, if you need to add the custom versions to your application you ought to implement roughly the following (excerpts of my POC code):
Preferred runtime readout:
1. create custom application-version holder:
2. implement its getter API
Direct readout from required partition (app/factory in my case):
1. implement reading the partition data from a proper offset
note the offset in esp_err_t err = esp_partition_read(partition, sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t), app_desc, sizeof(esp_app_desc_t));
I assume you would like to maintain both standard app-version and the custom one in parallel. If you just like to replace one section with another, you can freely exchange .rodata_desc with .rodata_custom_desc and nothing changes for the versioning APIs, the offsets remain the same.
Regarding the bootloader usage - not sure, need to check the details first. However, the SSBL code uses own implementation for accessing the application's bin data.
Hope this helps
custom application versioning is not currently deployed in the IDF, though there is a support for generating .rodata_custom_desc section in the target binary.
Thus, if you need to add the custom versions to your application you ought to implement roughly the following (excerpts of my POC code):
Preferred runtime readout:
1. create custom application-version holder:
Code: Select all
const __attribute__((weak)) __attribute__((section(".rodata_custom_desc"))) esp_app_desc_t esp_app_desc_custom = {
.magic_word = ESP_APP_DESC_MAGIC_WORD,
.version = "app_version 1.2.3.4",
.project_name = PROJECT_NAME,
.time = "time",
.date = "date",
.idf_ver = IDF_VER
};
2. implement its getter API
Code: Select all
const esp_app_desc_t *esp_app_get_custom_description(void)
{
return &esp_app_desc_custom;
}
1. implement reading the partition data from a proper offset
Code: Select all
esp_err_t esp_ota_get_partition_custom_description(const esp_partition_t *partition, esp_app_desc_t *app_desc)
{
if (partition == NULL || app_desc == NULL) {
return ESP_ERR_INVALID_ARG;
}
if(partition->type != ESP_PARTITION_TYPE_APP) {
return ESP_ERR_NOT_SUPPORTED;
}
esp_err_t err = esp_partition_read(partition, sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t), app_desc, sizeof(esp_app_desc_t));
if (err != ESP_OK) {
return err;
}
if (app_desc->magic_word != ESP_APP_DESC_MAGIC_WORD) {
return ESP_ERR_NOT_FOUND;
}
return ESP_OK;
}
I assume you would like to maintain both standard app-version and the custom one in parallel. If you just like to replace one section with another, you can freely exchange .rodata_desc with .rodata_custom_desc and nothing changes for the versioning APIs, the offsets remain the same.
Regarding the bootloader usage - not sure, need to check the details first. However, the SSBL code uses own implementation for accessing the application's bin data.
Hope this helps
Re: How to read out software (project) version from another partition?
Hi @pacucha42 ,
thanks for the reply. For a (custom) app description about SSBL I saw, that they added it in master, but its not yet available in v5.0 or newer release of now.
thanks for the reply. For a (custom) app description about SSBL I saw, that they added it in master, but its not yet available in v5.0 or newer release of now.
Re: How to read out software (project) version from another partition?
If you are referring to the bootloader version info, it's a new feature coming in some future IDF release. I don't see a reason for this version being customisable (except for the parts given by Kconfig)...
If you need to access other partitions' info during the boot phase, you can use bootloader_common_get_partition_description() (and possibly slightly modify it according to the logic mentioned in my previous comment)
Regarding ESP_APP_DESC_MAGIC_WORD - yes, it is sort of anti-corruption precaution, a marker to confirm the structure contains proper values (or to distinguish between various app version types, if needed)
If you need to access other partitions' info during the boot phase, you can use bootloader_common_get_partition_description() (and possibly slightly modify it according to the logic mentioned in my previous comment)
Regarding ESP_APP_DESC_MAGIC_WORD - yes, it is sort of anti-corruption precaution, a marker to confirm the structure contains proper values (or to distinguish between various app version types, if needed)
Who is online
Users browsing this forum: MicroController and 139 guests