Skip to content

Commit a5aad0d

Browse files
[RFC] Two helper functions to allow easier validation of NVRAM table by OEMs (#538)
In the event that an OEM is using the RTC NVRAM table for something more complicated than a few flags, integrity validation becomes necessary. The `storage()` API in the `Nvram` trait returns a mutable reference and ensures we can't double borrow. Great for safety but makes it difficult to get the values for validation (and potential erasure if invalid) and then also deconstruct the NVRAM table, so that they can be passed off the values to whichever service needs them, as that would constitute a double borrow. This PR introduces two helper functions which 1) dumps the current u32 values of the registers, rather than allowing for another handle to the RTC peripheral. The OEM can then perform their validation logic and if something is iffy, they can 2) erase the contents of the table through the object that has the handle before splitting up the entries as the OEM desires. Related PRs: OpenDevicePartnership/embedded-mcu#11
1 parent e049318 commit a5aad0d

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rt633/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rt685s-evk/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rtc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,14 @@ impl<'r> Nvram<'r, RtcNvramStorage<'r>, u32, IMXRT_GPREG_COUNT> for RtcNvram<'r>
175175
// so we can safely access it as long as it's always from an object that has the handle-to-RTC.
176176
&mut self.storage
177177
}
178+
179+
fn clear_storage(&mut self) {
180+
for storage in self.storage.iter_mut() {
181+
storage.write(0);
182+
}
183+
}
184+
185+
fn dump_storage(&self) -> [u32; IMXRT_GPREG_COUNT] {
186+
self.storage.each_ref().map(|storage| storage.read())
187+
}
178188
}

0 commit comments

Comments
 (0)