Skip to content

emds: loading flow implementation #22895

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

Open
wants to merge 2 commits into
base: collab-emds-next
Choose a base branch
from

Conversation

alxelax
Copy link
Contributor

@alxelax alxelax commented Jun 19, 2025

PR:

  • adds new loading flow implementation
  • adapts mesh light control sample to the new API statuses

@alxelax alxelax requested review from a team and Balaklaka as code owners June 19, 2025 14:47
@github-actions github-actions bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Jun 19, 2025
@NordicBuilder
Copy link
Contributor

NordicBuilder commented Jun 19, 2025

CI Information

To view the history of this post, clich the 'edited' button above
Build number: 7

Inputs:

Sources:

sdk-nrf: PR head: 0136b4cab27b68b45a0b67681f720168fe7430a9

more details

sdk-nrf:

PR head: 0136b4cab27b68b45a0b67681f720168fe7430a9
merge base: f411e0a82d678cf283a1df48bcd721f5a6cae3c1
target head (collab-emds-next): f411e0a82d678cf283a1df48bcd721f5a6cae3c1
Diff

Github labels

Enabled Name Description
ci-disabled Disable the ci execution
ci-all-test Run all of ci, no test spec filtering will be done
ci-force-downstream Force execution of downstream even if twister fails
ci-run-twister Force run twister
ci-run-zephyr-twister Force run zephyr twister
List of changed files detected by CI (6)
include
│  ├── emds
│  │  │ emds.h
samples
│  ├── bluetooth
│  │  ├── mesh
│  │  │  ├── light_ctrl
│  │  │  │  ├── src
│  │  │  │  │  │ main.c
subsys
│  ├── emds
│  │  ├── Kconfig
│  │  ├── emds_flash_new.c
│  │  ├── emds_flash_new.h
│  │  │ emds_new.c

Outputs:

Toolchain

Version: 3ae5dc3c63
Build docker image: docker-dtr.nordicsemi.no/sw-production/ncs-build:3ae5dc3c63_776d264d2e

Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped; ⚠️ Quarantine

  • ◻️ Toolchain - Skipped: existing toolchain is used
  • ✅ Build twister
    • sdk-nrf test count: 12
  • 🟠 Integration tests
    • 🟠 test-fw-nrfconnect-ble_mesh
Disabled integration tests
    • test-fw-nrfconnect-nrf_lrcs_mosh
    • test-fw-nrfconnect-nrf_lrcs_positioning
    • desktop52_verification
    • doc-internal
    • test_ble_nrf_config
    • test-fw-nrfconnect-apps
    • test-fw-nrfconnect-ble_samples
    • test-fw-nrfconnect-boot
    • test-fw-nrfconnect-chip
    • test-fw-nrfconnect-fem
    • test-fw-nrfconnect-nfc
    • test-fw-nrfconnect-nrf-iot_cloud
    • test-fw-nrfconnect-nrf-iot_libmodem-nrf
    • test-fw-nrfconnect-nrf-iot_lwm2m
    • test-fw-nrfconnect-nrf-iot_samples
    • test-fw-nrfconnect-nrf-iot_serial_lte_modem
    • test-fw-nrfconnect-nrf-iot_thingy91
    • test-fw-nrfconnect-nrf-iot_zephyr_lwm2m
    • test-fw-nrfconnect-nrf_crypto
    • test-fw-nrfconnect-ps-main
    • test-fw-nrfconnect-rpc
    • test-fw-nrfconnect-rs
    • test-fw-nrfconnect-tfm
    • test-fw-nrfconnect-thread-main
    • test-low-level
    • test-sdk-audio
    • test-sdk-find-my
    • test-sdk-mcuboot
    • test-sdk-pmic-samples
    • test-sdk-wifi
    • test-secdom-samples-public

Note: This message is automatically posted and updated by the CI

}
}

return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This function will return 0 if failures reach CONFIG_EMDS_SCANNING_FAILURES number. Is that correct? So it is success if all crc are wrong. First time run is maybe success.

Copy link
Contributor Author

@alxelax alxelax Jun 23, 2025

Choose a reason for hiding this comment

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

Yep, this is correct.
Having snapshot with wrong CRC or not having anything in emds at all are valid scenarios.
The function works with partitions.
There might be another partition has correct snapshot.
The final decision about fail or success should be done by user of emds_flash_scan_partition.
This function just scans partition and returns result.
It fails only if scanning fails itself (e.g. flash driver failure etc).

Copy link
Contributor

Choose a reason for hiding this comment

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

I find it a little strange that failing crc is not reported as error. But I having a hard time arguing why that is really important, so I will just leave it for now.

@alxelax alxelax requested a review from Balaklaka June 23, 2025 09:10
@alxelax alxelax force-pushed the collab-emds-next branch from 17a71e7 to f411e0a Compare June 23, 2025 09:55
@alxelax alxelax requested review from tejlmand and a team as code owners June 23, 2025 09:55
@alxelax alxelax removed request for a team and tejlmand June 23, 2025 09:59
@alxelax
Copy link
Contributor Author

alxelax commented Jun 23, 2025

github added @tejlmand and @nrfconnect/ncs-test-leads due to collaboration branch was rebased on top the latest main and there were some collisions.
Actually, nothing to review for them after collisions were solved. I removed them from PR as reviewers.

@alxelax alxelax removed the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Jun 23, 2025
struct emds_snapshot_metadata *metadata)
{
const struct flash_area *fa = partition->fa;
uint8_t data_chunk[CHUNK_SIZE(partition->fp)];
Copy link
Contributor

Choose a reason for hiding this comment

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

This creates VLA at runtime. We should not be using dynamic memory allocation. I think it is safer to simply freeze the data chunk size at compile time in multiples of 16.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm... Why is VLA under obstruction?
Heap and VLA are already in use in many components. For example, in old emds here:
https://github.com/nrfconnect/sdk-nrf/blob/main/subsys/emds/emds_flash.c#L343
https://github.com/nrfconnect/sdk-nrf/blob/main/subsys/emds/emds_flash.c#L428

Copy link
Contributor

@omkar3141 omkar3141 Jun 24, 2025

Choose a reason for hiding this comment

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

In 2018, we removed all usage of VLAs in nRF5 Mesh. I don't know how this got into existing emds. Even zephyr guidelines prevent VLAs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm... but this is not nrf5 and not Zephyr. Does Nordic concern about MISRA rules?
Seems using VLA wasn't a problem before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot from 2025-06-24 16-10-11
FYI

Copy link
Contributor

@omkar3141 omkar3141 Jun 24, 2025

Choose a reason for hiding this comment

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

  1. is wrong. Because dev_uuid is already declared as array. Example in one is not VLA declaration, it is pointer access.
    2,3, 4: this is not vla. this will be treated as pointer.

A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’, where the type qualifiers (if any) are those specified within the [ and ] of the
array type derivation. If the keyword static also appears within the [ and ] of the
array type derivation, then for each call to the function, the value of the corresponding
actual argument shall provide access to the first element of an array with at least as many
elements as specified by the size expression.

So we don't have VLAs in NCS mesh so far. Probably copilot is getting confused by array like syntax and confidently stating that this is a VLA.

Copy link
Contributor

Choose a reason for hiding this comment

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

btw, I decided to ask same question like you to cursor, and it seems, it is able to provide correct answer:
bilde

@github-actions github-actions bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Jun 24, 2025
@alxelax alxelax requested a review from omkar3141 June 24, 2025 13:08
@alxelax alxelax removed the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Jun 24, 2025
alxelax added 2 commits June 24, 2025 17:02
Commit adds new loading flow implementation
with searching the freshest data on two partitions.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
Commit adapts light control sample to the new
emds API statuses.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
@github-actions github-actions bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Jun 24, 2025
}
}

return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it a little strange that failing crc is not reported as error. But I having a hard time arguing why that is really important, so I will just leave it for now.

@@ -144,7 +144,9 @@ int emds_store(void);
* previously stored data.
*
* @retval 0 Success
* @retval -ERRNO errno code if error
* @retval -ECANCELED errno code if it was called before @ref emds_init
* @retval -ENOENT errno code if no valid snapshot was found in any partition
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should write in documentation that first time run will give this error, as snapshot is empty.

return 0;
for (int i = 0; i < PARTITIONS_NUM_MAX; i++) {
if (emds_flash_scan_partition(&partition[i], &metadata)) {
LOG_ERR("Failed to scan partition %d:", i);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a LOG_DBG (LOG_WRN) as possible no error code will be supplied?

Copy link
Contributor

@omkar3141 omkar3141 left a comment

Choose a reason for hiding this comment

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

Looks good. Lots of interesting discussions during this PR. Thanks for clarifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants