Skip to content
Snippets Groups Projects
Commit 37a34c9d authored by Carlo Ferriolo's avatar Carlo Ferriolo
Browse files

[RUST] add new function for validate slot


New validate slot function has been added to fix rauc updating process
which invalidated the slot to be updated but could not validate it back.

Signed-off-by: default avatarCarlo Ferriolo <carlo.ferriolo@seco.com>
parent a11bc89c
Branches main
No related tags found
1 merge request!22[RUST] add new function for validate slot
Pipeline #275661 passed with stages
in 46 seconds
......@@ -7,7 +7,7 @@
#include <malloc.h>
#include <errno.h>
#include <string.h>
#include <sysdata.h>
#include "sysdata.h"
#endif /* __GRUB__ */
......
......@@ -79,6 +79,13 @@ pub enum SwitchSlotSubcommand {
arg: String,
},
/// Validate a slot (add it to boot order list and puts its
/// fail boot counter to zero).
ValidateSlot {
/// slot ID (e.g. A or B)
arg: String,
},
/// Set current boot as ok (reset of fail boot counter for current slot).
SetBootOk,
......
......@@ -297,10 +297,15 @@ impl SwitchingTable {
let mut v: Vec<u8> = self.boot_slot_order.iter()
.copied()
.filter(|&id| id != slot_id)
.filter(|&id| id != slot_id && id != SLOT_NULL)
.collect();
v.insert(0, slot_id);
if v.len() < self.boot_slot_order.len(){
let diff = self.boot_slot_order.len()-v.len();
for _i in 0..diff {
v.push(SLOT_NULL);
}
}
self.boot_slot_order = v.try_into().unwrap();
Ok(())
}
......@@ -329,6 +334,32 @@ impl SwitchingTable {
Ok(())
}
/// Add slot from boot order
pub fn add_slot(&mut self, slot: &str) -> Result<(), SysdataError> {
let slot_id = slot_id_to_num(slot)?;
if ! self.boot_slot_order.iter().any(|&id| id == slot_id) {
let mut v: Vec<u8> = self.boot_slot_order.iter()
.copied()
.collect();
for n in v.iter_mut() {
if *n == SLOT_NULL {
*n = slot_id;
break;
}
}
self.boot_slot_order = v.try_into().unwrap();
}
Ok(())
}
/// Add slot to boot order and set its fail boot counter to zero
pub fn validate_slot(&mut self, slot: &str) -> Result<(), SysdataError> {
self.add_slot(slot)?;
self.reset_fail_boot_count(slot)?;
Ok(())
}
/// Set previous_boot_slot to current_boot_slot and reset boot fail counter
pub fn set_boot_ok(&mut self) {
self.previous_boot_slot = self.current_boot_slot;
......
......@@ -134,6 +134,12 @@ fn run() -> Result<(), SysdataError> {
Ok(())
}
// Validate slot (add to boot order + set fail boot counter = 0)
SwitchSlotSubcommand::ValidateSlot { arg } => {
table.data.switch_table.validate_slot(arg.as_str())?;
Ok(())
}
// Set current boot as ok (reset of fail boot counter for current slot).
SwitchSlotSubcommand::SetBootOk => {
if cli.verbose {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment