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

Allow to find any partition type (app and data) with iterator (IDFGH-4783) #6586

Closed

Conversation

0xFEEDC0DE64
Copy link
Contributor

I tried to build an remove partition browser tool which lists all types and subtypes of partitions and I was missing the partition type "ANY".

Example usage:

    JsonDocument doc;
    auto iter = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, nullptr);

    while (iter)
    {
        auto part = esp_partition_get(iter);
        if (!part)
            break;

        auto obj = doc.createNestedObject();
        obj["type"] = part->type;
        obj["subtype"] = part->subtype;
        obj["address"] = part->address;
        obj["size"] = part->size;
        obj["label"] = std::string{part->label};
        obj["encrypted"] = part->encrypted;

        iter = esp_partition_next(iter);
    }

    if (iter)
        esp_partition_iterator_release(iter);

@github-actions github-actions bot changed the title Allow to find any partition type (app and data) with iterator Allow to find any partition type (app and data) with iterator (IDFGH-4783) Feb 21, 2021
@Alvin1Zhang
Copy link
Collaborator

Thanks for your contribution.

@0xFEEDC0DE64
Copy link
Contributor Author

Ok is this PR already in consideration? Are any questions open? Can I help somehow to get this merged?

@igrr
Copy link
Member

igrr commented May 5, 2021

Hi @0xFEEDC0DE64, thank you for the PR, and sorry that it took a long time for us to take a look.

Would you be okay with 2 changes being added to your commit?

  1. Return NULL from esp_partition_find if type == ESP_PARTITION_TYPE_ANY and subtype != ESP_PARTITION_SUBTYPE_ANY, as such combination of arguments doesn't make sense:
     if (type == ESP_PARTITION_TYPE_ANY && subtype != ESP_PARTITION_SUBTYPE_ANY) {
         return NULL;
     }
  2. In test_partition.c, extend the existing test case to exercise the newly added logic:
     it = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL);
     TEST_ASSERT_NOT_NULL(it);
     count = 0;
     for (; it != NULL; it = esp_partition_next(it)) {
         ++count;
     }
     esp_partition_iterator_release(it);
     TEST_ASSERT_EQUAL(8, count);

If this looks okay to you, I'll submit this internally.

(Edit: fixed a mistake in the first part, returning NULL instead of ESP_ERR_INVALID_ARG).

@espressif-bot espressif-bot added the Status: In Progress Work is in progress label May 5, 2021
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress labels May 17, 2021
@igrr
Copy link
Member

igrr commented May 18, 2021

@0xFEEDC0DE64 the PR has been cherry-picked as 1f419bd, thanks again!

@igrr igrr closed this May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants