Skip to content

Commit

Permalink
[ownership] Rename protect_when_primary
Browse files Browse the repository at this point in the history
Rename `protect_when_primary` to `protect_when_active`, as this feature
is supposed to protect flash pages in whichever side is the active side
regardless of which side is the primary side.

Signed-off-by: Chris Frantz <[email protected]>
(cherry picked from commit 5de39b8)
  • Loading branch information
cfrantz committed Nov 13, 2024
1 parent 8838c81 commit 73e897e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
20 changes: 10 additions & 10 deletions sw/device/silicon_creator/lib/ownership/testdata/basic_owner.json5
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
scramble: false,
ecc: false,
high_endurance: false,
protect_when_primary: true
protect_when_active: true
},
{
start: 32,
Expand All @@ -74,7 +74,7 @@
scramble: true,
ecc: true,
high_endurance: false,
protect_when_primary: true
protect_when_active: true
},
{
start: 224,
Expand All @@ -85,7 +85,7 @@
scramble: false,
ecc: false,
high_endurance: true,
protect_when_primary: false
protect_when_active: false
},
{
start: 256,
Expand All @@ -96,7 +96,7 @@
scramble: false,
ecc: false,
high_endurance: false,
protect_when_primary: true
protect_when_active: true
},
{
start: 288,
Expand All @@ -107,7 +107,7 @@
scramble: true,
ecc: true,
high_endurance: false,
protect_when_primary: true
protect_when_active: true
},
{
start: 480,
Expand All @@ -118,7 +118,7 @@
scramble: false,
ecc: false,
high_endurance: true,
protect_when_primary: false
protect_when_active: false
}
]
}
Expand All @@ -136,7 +136,7 @@
scramble: true,
ecc: true,
high_endurance: false,
protect_when_primary: false
protect_when_active: false
},
{
bank: 0,
Expand All @@ -148,7 +148,7 @@
scramble: true,
ecc: true,
high_endurance: false,
protect_when_primary: false
protect_when_active: false
},
{
bank: 0,
Expand All @@ -160,7 +160,7 @@
scramble: true,
ecc: true,
high_endurance: false,
protect_when_primary: false
protect_when_active: false
},
{
bank: 0,
Expand All @@ -172,7 +172,7 @@
scramble: true,
ecc: true,
high_endurance: false,
protect_when_primary: false
protect_when_active: false
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,10 @@
The new flash configuration should have a different scrambling or ECC configuration than the current configuration.
- Boot owner firmware and examine the flash controller's region configuration registers.
- Confirm that in the intermediate "dual-owner" state, the primary half of the flash is configured for the previous owner and the secondary half is configured for the next owner.
Confirm that the `protect_when_primary` condition does not apply during the dual-owner state.
Confirm that the `protect_when_active` condition does not apply during the dual-owner state.
- Activate ownership with the `dummy` activate key.
- Use the rescue protocol to upload owner firmware into the newly-configured flash regions.
- Confirm that in the owned state, the entire flash is configured for the new owner and that the `protect_when_primary` condition removes erase/program permissions appropriately.
- Confirm that in the owned state, the entire flash is configured for the new owner and that the `protect_when_active` condition removes erase/program permissions appropriately.
'''
tags:
[
Expand Down
18 changes: 9 additions & 9 deletions sw/host/opentitanlib/src/ownership/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pub struct FlashFlags {
/// The high endurance feature is enabled in this region.
#[serde(default)]
pub high_endurance: bool,
/// Forbid program and erase operations when in the primary flash side.
/// Forbid program and erase operations when in the active flash side.
#[serde(default)]
pub protect_when_primary: bool,
pub protect_when_active: bool,
/// Lock the configuration of this region.
#[serde(default)]
pub lock: bool,
Expand Down Expand Up @@ -64,7 +64,7 @@ impl FlashFlags {
read: true,
program: true,
erase: true,
protect_when_primary: true,
protect_when_active: true,
..Default::default()
}
}
Expand All @@ -77,7 +77,7 @@ impl FlashFlags {
erase: true,
scramble: true,
ecc: true,
protect_when_primary: true,
protect_when_active: true,
..Default::default()
}
}
Expand Down Expand Up @@ -114,7 +114,7 @@ impl From<u64> for FlashFlags {
read: flags & 0xF == Self::TRUE,
program: (flags >> 4) & 0xF == Self::TRUE,
erase: (flags >> 8) & 0xF == Self::TRUE,
protect_when_primary: (flags >> 24) & 0xF == Self::TRUE,
protect_when_active: (flags >> 24) & 0xF == Self::TRUE,
lock: (flags >> 28) & 0xF == Self::TRUE,

// Second 32-bit word: flash properties.
Expand All @@ -134,7 +134,7 @@ impl From<FlashFlags> for u64 {
if flags.read { FlashFlags::TRUE } else { FlashFlags::FALSE } |
if flags.program { FlashFlags::TRUE } else { FlashFlags::FALSE } << 4 |
if flags.erase { FlashFlags::TRUE } else { FlashFlags::FALSE } << 8 |
if flags.protect_when_primary { FlashFlags::TRUE } else { FlashFlags::FALSE } << 24 |
if flags.protect_when_active { FlashFlags::TRUE } else { FlashFlags::FALSE } << 24 |
if flags.lock { FlashFlags::TRUE } else { FlashFlags::FALSE } << 28 |

// Second 32-bit word: flash properties.
Expand Down Expand Up @@ -263,7 +263,7 @@ r#"00000000: 46 4c 53 48 2c 00 00 00 00 00 00 00 96 09 00 99 FLSH,...........
scramble: false,
ecc: true,
high_endurance: false,
protect_when_primary: false,
protect_when_active: false,
lock: false
},
{
Expand All @@ -275,7 +275,7 @@ r#"00000000: 46 4c 53 48 2c 00 00 00 00 00 00 00 96 09 00 99 FLSH,...........
scramble: false,
ecc: false,
high_endurance: false,
protect_when_primary: false,
protect_when_active: false,
lock: false
},
{
Expand All @@ -287,7 +287,7 @@ r#"00000000: 46 4c 53 48 2c 00 00 00 00 00 00 00 96 09 00 99 FLSH,...........
scramble: true,
ecc: true,
high_endurance: true,
protect_when_primary: false,
protect_when_active: false,
lock: false
}
]
Expand Down
6 changes: 3 additions & 3 deletions sw/host/opentitanlib/src/ownership/flash_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ r#"00000000: 49 4e 46 4f 2c 00 00 00 00 00 00 00 96 09 00 99 INFO,...........
scramble: false,
ecc: true,
high_endurance: false,
protect_when_primary: false,
protect_when_active: false,
lock: false
},
{
Expand All @@ -158,7 +158,7 @@ r#"00000000: 49 4e 46 4f 2c 00 00 00 00 00 00 00 96 09 00 99 INFO,...........
scramble: false,
ecc: false,
high_endurance: false,
protect_when_primary: false,
protect_when_active: false,
lock: false
},
{
Expand All @@ -171,7 +171,7 @@ r#"00000000: 49 4e 46 4f 2c 00 00 00 00 00 00 00 96 09 00 99 INFO,...........
scramble: true,
ecc: true,
high_endurance: true,
protect_when_primary: false,
protect_when_active: false,
lock: false
}
]
Expand Down
8 changes: 4 additions & 4 deletions sw/host/opentitanlib/src/ownership/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ r#"00000000: 4f 57 4e 52 00 08 00 00 00 00 00 00 4c 4e 45 58 OWNR........LNEX
scramble: true,
ecc: true,
high_endurance: true,
protect_when_primary: false,
protect_when_active: false,
lock: false
},
{
Expand All @@ -505,7 +505,7 @@ r#"00000000: 4f 57 4e 52 00 08 00 00 00 00 00 00 4c 4e 45 58 OWNR........LNEX
scramble: true,
ecc: true,
high_endurance: true,
protect_when_primary: false,
protect_when_active: false,
lock: false
}
]
Expand All @@ -524,7 +524,7 @@ r#"00000000: 4f 57 4e 52 00 08 00 00 00 00 00 00 4c 4e 45 58 OWNR........LNEX
scramble: true,
ecc: true,
high_endurance: true,
protect_when_primary: false,
protect_when_active: false,
lock: false
},
{
Expand All @@ -537,7 +537,7 @@ r#"00000000: 4f 57 4e 52 00 08 00 00 00 00 00 00 4c 4e 45 58 OWNR........LNEX
scramble: true,
ecc: true,
high_endurance: true,
protect_when_primary: false,
protect_when_active: false,
lock: false
}
]
Expand Down
8 changes: 4 additions & 4 deletions sw/host/tests/ownership/flash_permission_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn flash_permission_test(opts: &Opts, transport: &TransportWrapper) -> Result<()
// Earlgrey-specific.
//
// Note: when in an unlocked state, flash lockdown doesn't apply, so neither
// the `protect_when_primary` nor `lock` bits for individual regions will
// the `protect_when_active` nor `lock` bits for individual regions will
// affect the region config.
assert_eq!(
region[0],
Expand Down Expand Up @@ -241,10 +241,10 @@ fn flash_permission_test(opts: &Opts, transport: &TransportWrapper) -> Result<()
return RomError(u32::from_str_radix(&capture[2], 16)?).into();
}
let region = FlashRegion::find_all(&capture[1])?;
// Flash SideA is the primary side and has protect_when_primary = true.
// Flash SideA is the primary side and has protect_when_active = true.
//
// Since we are in a locked ownership state, we expect the region configuration
// to reflect both the `protect_when_primary` and `lock` properties of the
// to reflect both the `protect_when_active` and `lock` properties of the
// owner's flash configuration.
let locked = if opts.config_kind.is_flash_locked() {
"LK"
Expand All @@ -263,7 +263,7 @@ fn flash_permission_test(opts: &Opts, transport: &TransportWrapper) -> Result<()
region[2],
FlashRegion("data", 2, 224, 32, "RD-WR-ER-xx-xx-HE", locked)
);
// Flash SideB is the secondary side, so protect_when_primary doesn't apply.
// Flash SideB is the secondary side, so protect_when_active doesn't apply.
assert_eq!(
region[3],
FlashRegion("data", 3, 256, 32, "RD-WR-ER-xx-xx-xx", locked)
Expand Down
6 changes: 3 additions & 3 deletions sw/host/tests/ownership/transfer_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl OwnerConfigKind {
scramble: self as u32 & CFG_FLASH_ERROR != 0,
ecc: self as u32 & CFG_FLASH_ERROR != 0,
high_endurance: false,
protect_when_primary: true,
protect_when_active: true,
lock: self.is_flash_locked(),
}
}
Expand All @@ -166,7 +166,7 @@ impl OwnerConfigKind {
scramble: true,
ecc: true,
high_endurance: false,
protect_when_primary: true,
protect_when_active: true,
lock: self.is_flash_locked(),
}
}
Expand All @@ -179,7 +179,7 @@ impl OwnerConfigKind {
scramble: false,
ecc: false,
high_endurance: true,
protect_when_primary: false,
protect_when_active: false,
lock: self.is_flash_locked(),
}
}
Expand Down

0 comments on commit 73e897e

Please sign in to comment.