-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: collab-emds-next
Are you sure you want to change the base?
Conversation
CI InformationTo view the history of this post, clich the 'edited' button above Inputs:Sources:sdk-nrf: PR head: 0136b4cab27b68b45a0b67681f720168fe7430a9 more detailssdk-nrf:
Github labels
List of changed files detected by CI (6)
Outputs:ToolchainVersion: 3ae5dc3c63 Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped;
|
} | ||
} | ||
|
||
return 0; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
17a71e7
to
f411e0a
Compare
github added @tejlmand and @nrfconnect/ncs-test-leads due to collaboration branch was rebased on top the latest main and there were some collisions. |
subsys/emds/emds_flash_new.c
Outdated
struct emds_snapshot_metadata *metadata) | ||
{ | ||
const struct flash_area *fa = partition->fa; | ||
uint8_t data_chunk[CHUNK_SIZE(partition->fp)]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
} | ||
} | ||
|
||
return 0; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
PR: