Skip to content

Commit 8d524f6

Browse files
cfrantzpamaury
authored andcommitted
[rom_ext] Update INFO page lockdown for earlgrey_a1
The INFO page layout has changed between the ES and PROD chips. Update the lockdown and ownership functions relating to INFO configuration. Update the `flash_permission_test` to verify the configuration. Signed-off-by: Chris Frantz <cfrantz@google.com>
1 parent 02b176a commit 8d524f6

File tree

6 files changed

+61
-36
lines changed

6 files changed

+61
-36
lines changed

sw/device/silicon_creator/lib/drivers/flash_ctrl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ static const flash_ctrl_info_page_t *kInfoPagesNoOwnerAccess[] = {
760760
// Bank 1
761761
&kFlashCtrlInfoPageBootData0,
762762
&kFlashCtrlInfoPageBootData1,
763+
&kFlashCtrlInfoPageCreatorReserved0,
763764
};
764765

765766
enum {
@@ -805,6 +806,7 @@ void flash_ctrl_cert_info_page_creator_cfg(
805806
void flash_ctrl_cert_info_page_owner_restrict(
806807
const flash_ctrl_info_page_t *info_page) {
807808
SEC_MMIO_ASSERT_WRITE_INCREMENT(kFlashCtrlSecMmioCertInfoPageOwnerRestrict,
808-
1);
809+
2);
809810
flash_ctrl_info_perms_set(info_page, kCertificateInfoPageOwnerAccess);
811+
sec_mmio_write32(flash_ctrl_core_base() + info_page->cfg_wen_offset, 0);
810812
}

sw/device/silicon_creator/lib/drivers/flash_ctrl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ FLASH_CTRL_INFO_PAGES_DEFINE(INFO_PAGE_STRUCT_DECL_);
166166
*/
167167
enum {
168168
kFlashCtrlSecMmioCertInfoPageCreatorCfg = 2,
169-
kFlashCtrlSecMmioCertInfoPageOwnerRestrict = 1,
169+
kFlashCtrlSecMmioCertInfoPageOwnerRestrict = 2,
170170
kFlashCtrlSecMmioCertInfoPagesOwnerRestrict = 5,
171-
kFlashCtrlSecMmioCreatorInfoPagesLockdown = 12,
171+
kFlashCtrlSecMmioCreatorInfoPagesLockdown = 14,
172172
kFlashCtrlSecMmioDataDefaultCfgSet = 1,
173173
kFlashCtrlSecMmioDataDefaultPermsSet = 1,
174174
kFlashCtrlSecMmioExecSet = 1,

sw/device/silicon_creator/lib/drivers/flash_ctrl_unittest.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,11 @@ INSTANTIATE_TEST_SUITE_P(AllCases, FlashCtrlCfgSetTest,
682682
}));
683683

684684
TEST_F(FlashCtrlTest, CreatorInfoLockdown) {
685-
std::array<const flash_ctrl_info_page_t *, 6> no_owner_access = {
686-
&kFlashCtrlInfoPageFactoryId, &kFlashCtrlInfoPageCreatorSecret,
687-
&kFlashCtrlInfoPageOwnerSecret, &kFlashCtrlInfoPageWaferAuthSecret,
688-
&kFlashCtrlInfoPageBootData0, &kFlashCtrlInfoPageBootData1,
685+
std::array<const flash_ctrl_info_page_t *, 7> no_owner_access = {
686+
&kFlashCtrlInfoPageFactoryId, &kFlashCtrlInfoPageCreatorSecret,
687+
&kFlashCtrlInfoPageOwnerSecret, &kFlashCtrlInfoPageWaferAuthSecret,
688+
&kFlashCtrlInfoPageBootData0, &kFlashCtrlInfoPageBootData1,
689+
&kFlashCtrlInfoPageCreatorReserved0,
689690
};
690691
for (auto page : no_owner_access) {
691692
auto info_page = InfoPages().at(page);
@@ -737,6 +738,7 @@ TEST_F(FlashCtrlTest, CertInfoOwnerRestrict) {
737738
auto info_page = InfoPages().at(page);
738739
EXPECT_SEC_READ32(base_ + info_page.cfg_offset, 0x9666666);
739740
EXPECT_SEC_WRITE32(base_ + info_page.cfg_offset, 0x9669966);
741+
EXPECT_SEC_WRITE32(base_ + info_page.cfg_wen_offset, 0);
740742
}
741743

742744
flash_ctrl_cert_info_page_owner_restrict(

sw/device/silicon_creator/lib/ownership/owner_block.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,10 @@ rom_error_t owner_block_flash_apply(const owner_flash_config_t *flash,
251251
}
252252

253253
static inline hardened_bool_t is_owner_page(const owner_info_page_t *config) {
254-
if (config->bank == 0) {
255-
if (config->page >= 6 && config->page <= 9) {
256-
// Currently, bank0, pages 6-9 (inclusive) are the pages reserved
257-
// for the owner's use.
258-
return kHardenedBoolTrue;
259-
}
254+
// On earlgrey_a1, in banks 0 and 1, pages 5-8 (inclusive) are reserved
255+
// for the owner.
256+
if (config->page >= 5 && config->page <= 8) {
257+
return kHardenedBoolTrue;
260258
}
261259
return kHardenedBoolFalse;
262260
}

sw/device/silicon_creator/lib/ownership/owner_block_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ const owner_flash_info_config_t info_config = {
219219
{
220220
// Disallowed page
221221
.bank = 0,
222-
.page = 5,
222+
.page = 9,
223223
.access = FLASH_ACCESS(
224224
/*index=*/1,
225225
/*read=*/true,

sw/host/tests/ownership/flash_permission_test.rs

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,49 @@ impl FlashRegion<'_> {
105105
}
106106
}
107107

108+
fn flash_info_check(info: &[FlashRegion<'_>], unlocked: bool) -> Result<()> {
109+
// Flash info regions when no OwnerReserved pages are configured:
110+
let config = [
111+
FlashRegion("info", 0, 0, 0, "uu-uu-uu-uu-uu-uu", "LK"), // factory ID
112+
FlashRegion("info", 0, 0, 1, "uu-uu-uu-uu-uu-uu", "LK"), // creator secret
113+
FlashRegion("info", 0, 0, 2, "uu-uu-uu-uu-uu-uu", "LK"), // owner secret
114+
FlashRegion("info", 0, 0, 3, "uu-uu-uu-uu-uu-uu", "LK"), // wafer auth secret
115+
FlashRegion("info", 0, 0, 4, "RD-xx-xx-SC-EC-xx", "LK"), // attestation key seeds
116+
FlashRegion("info", 0, 0, 5, "xx-xx-xx-xx-xx-xx", "UN"), // owner reserved
117+
FlashRegion("info", 0, 0, 6, "xx-xx-xx-xx-xx-xx", "UN"), // owner reserved
118+
FlashRegion("info", 0, 0, 7, "xx-xx-xx-xx-xx-xx", "UN"), // owner reserved
119+
FlashRegion("info", 0, 0, 8, "xx-xx-xx-xx-xx-xx", "UN"), // owner reserved
120+
FlashRegion("info", 0, 0, 9, "RD-xx-xx-SC-EC-xx", "LK"), // factory certs
121+
FlashRegion("info", 1, 0, 0, "uu-uu-uu-uu-uu-uu", "LK"), // boot data 0
122+
FlashRegion("info", 1, 0, 1, "uu-uu-uu-uu-uu-uu", "LK"), // boot data 1
123+
FlashRegion("info", 1, 0, 2, "RD-xx-xx-SC-EC-xx", "LK"), // owner config 0
124+
if unlocked {
125+
FlashRegion("info", 1, 0, 3, "RD-WR-ER-SC-EC-xx", "LK") // owner config 1
126+
} else {
127+
FlashRegion("info", 1, 0, 3, "RD-xx-xx-SC-EC-xx", "LK") // owner config 1
128+
},
129+
FlashRegion("info", 1, 0, 4, "uu-uu-uu-uu-uu-uu", "LK"), // creator reserved
130+
FlashRegion("info", 1, 0, 5, "xx-xx-xx-xx-xx-xx", "UN"), // owner reserved
131+
FlashRegion("info", 1, 0, 6, "xx-xx-xx-xx-xx-xx", "UN"), // owner reserved
132+
FlashRegion("info", 1, 0, 7, "xx-xx-xx-xx-xx-xx", "UN"), // owner reserved
133+
FlashRegion("info", 1, 0, 8, "xx-xx-xx-xx-xx-xx", "UN"), // owner reserved
134+
FlashRegion("info", 1, 0, 9, "RD-xx-xx-SC-EC-xx", "LK"), // dice certs
135+
];
136+
assert_eq!(info.len(), config.len());
137+
let mut err = 0;
138+
for i in 0..config.len() {
139+
if info[i] != config[i] {
140+
log::error!("INFO entry {i}: {:?} != {:?}", info[i], config[i]);
141+
err += 1;
142+
}
143+
}
144+
if err != 0 {
145+
Err(anyhow!("INFO lockdown mismatch"))
146+
} else {
147+
Ok(())
148+
}
149+
}
150+
108151
fn flash_permission_test(opts: &Opts, transport: &TransportWrapper) -> Result<()> {
109152
let uart = transport.uart("console")?;
110153
let rescue = RescueSerial::new(Rc::clone(&uart));
@@ -198,17 +241,7 @@ fn flash_permission_test(opts: &Opts, transport: &TransportWrapper) -> Result<()
198241
FlashRegion("data", 7, 0, 0, "xx-xx-xx-xx-xx-xx", "UN")
199242
);
200243

201-
// Bank 1, pages 2-3 are the ownership pages. In an ownership unlocked
202-
// state, OwnerPage0 (bank 1 page 2) should be read-only and OwnerPage1
203-
// (bank1 page 3) should be read/write.
204-
assert_eq!(
205-
region[20],
206-
FlashRegion("info", 1, 0, 2, "RD-xx-xx-SC-EC-xx", "LK")
207-
);
208-
assert_eq!(
209-
region[21],
210-
FlashRegion("info", 1, 0, 3, "RD-WR-ER-SC-EC-xx", "LK")
211-
);
244+
flash_info_check(&region[8..], /*unlocked=*/ true)?;
212245
}
213246

214247
log::info!("###### Get Boot Log (2/2) ######");
@@ -306,17 +339,7 @@ fn flash_permission_test(opts: &Opts, transport: &TransportWrapper) -> Result<()
306339
FlashRegion("data", 7, 0, 0, "xx-xx-xx-xx-xx-xx", "UN")
307340
);
308341

309-
// Bank 1, pages 2-3 are the ownership pages. In an ownership locked
310-
// state, both pages should be read-only.
311-
assert_eq!(
312-
region[20],
313-
FlashRegion("info", 1, 0, 2, "RD-xx-xx-SC-EC-xx", "LK")
314-
);
315-
assert_eq!(
316-
region[21],
317-
FlashRegion("info", 1, 0, 3, "RD-xx-xx-SC-EC-xx", "LK")
318-
);
319-
342+
flash_info_check(&region[8..], /*unlocked=*/ false)?;
320343
Ok(())
321344
}
322345

0 commit comments

Comments
 (0)