How to read out software (project) version from another partition?

leschge
Posts: 37
Joined: Fri May 06, 2022 1:38 pm

How to read out software (project) version from another partition?

Postby leschge » Wed Jul 26, 2023 7:00 am

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.

ESP_adokitkat
Posts: 52
Joined: Thu Jun 22, 2023 12:50 pm

Re: How to read out software (project) version from another partition?

Postby ESP_adokitkat » Thu Jul 27, 2023 1:04 am

Hello. If I understand you correctly, you should be able to use `esp_ota_get_partition_description` function.
  1. /**
  2.  * @brief Returns esp_app_desc structure for app partition. This structure includes app version.
  3.  *
  4.  * Returns a description for the requested app partition.
  5.  * @param[in] partition     Pointer to app partition. (only app partition)
  6.  * @param[out] app_desc     Structure of info about app.
  7.  * @return
  8.  *  - ESP_OK                Successful.
  9.  *  - ESP_ERR_NOT_FOUND     app_desc structure is not found. Magic word is incorrect.
  10.  *  - ESP_ERR_NOT_SUPPORTED Partition is not application.
  11.  *  - ESP_ERR_INVALID_ARG   Arguments is NULL or if partition's offset exceeds partition size.
  12.  *  - ESP_ERR_INVALID_SIZE  Read would go out of bounds of the partition.
  13.  *  - or one of error codes from lower-level flash driver.
  14.  */
  15. esp_err_t esp_ota_get_partition_description(const esp_partition_t *partition, esp_app_desc_t *app_desc);

leschge
Posts: 37
Joined: Fri May 06, 2022 1:38 pm

Re: How to read out software (project) version from another partition?

Postby leschge » Thu Jul 27, 2023 7:30 am

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:

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;
}
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?

pacucha42
Posts: 31
Joined: Fri Mar 29, 2019 12:56 pm

Re: How to read out software (project) version from another partition?

Postby pacucha42 » Tue Aug 01, 2023 8:05 pm

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:

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;
}
Direct readout from required partition (app/factory in my case):

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;
}
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

leschge
Posts: 37
Joined: Fri May 06, 2022 1:38 pm

Re: How to read out software (project) version from another partition?

Postby leschge » Wed Aug 02, 2023 7:44 am

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.

pacucha42
Posts: 31
Joined: Fri Mar 29, 2019 12:56 pm

Re: How to read out software (project) version from another partition?

Postby pacucha42 » Wed Aug 02, 2023 9:38 am

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)

Who is online

Users browsing this forum: No registered users and 80 guests