Skip to content

Commit 38f6bdc

Browse files
[fuse_ctrl, rtl] Make pk hash vendor lock more generic
Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
1 parent d4e2131 commit 38f6bdc

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/fuse_ctrl/rtl/otp_ctrl.sv

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,16 @@ module otp_ctrl
397397
// Intercept write requests to the `VENDOR_HASHES_PROD` partition and verify
398398
// the write is allowed by the volatile lock of the `VENDOR_PK_HASH_VOLATILE LOCK` register.
399399
if (NumVendorPkFuses > 1) begin
400+
401+
localparam int prod_vendor_hash_num = NumVendorPkFuses-1;
402+
localparam int prod_vendor_hash_size = CptraCoreVendorPkHash1Size + CptraCorePqcKeyType1Size;
403+
localparam int prod_vendor_hash_start = CptraCoreVendorPkHash1Offset;
404+
localparam int prod_vendor_hash_end = CptraCoreVendorPkHash1Offset + (prod_vendor_hash_size * prod_vendor_hash_num);
405+
400406
if (dai_cmd == DaiWrite && reg2hw.vendor_pk_hash_volatile_lock != '0 &&
401-
dai_addr >= VendorHashesProdPartitionOffset &&
402-
dai_addr < VendorHashesProdPartitionDigestOffset) begin
403-
if (32'(dai_addr) >= (VendorHashesProdPartitionOffset + (reg2hw.vendor_pk_hash_volatile_lock * (CptraCoreVendorPkHash1Size + CptraCorePqcKeyType1Size)))) begin
407+
dai_addr >= prod_vendor_hash_start &&
408+
dai_addr < prod_vendor_hash_end) begin
409+
if (32'(dai_addr) >= (prod_vendor_hash_start + ((reg2hw.vendor_pk_hash_volatile_lock-1) * prod_vendor_hash_size))) begin
404410
part_access_pre[VendorHashesProdPartitionIdx].write_lock = MuBi8True;
405411
end
406412
end

src/integration/test_suites/smoke_test_fc_pk_volatile_lock/smoke_test_fc_pk_volatile_lock.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,22 @@ volatile char* stdout = (char *)SOC_MCI_TOP_MCI_REG_DEBUG_OUT;
4141
* the volatile lock works as intended. The test proceeds in the following steps:
4242
*
4343
* 1. Write a value to first fuse.
44-
* 2. Write a value to second fuse.
45-
* 3. Activate the volatile lock such that the fuse from step 2 is now in the
44+
* 2. Activate the volatile lock such that the fuse from step 2 is now in the
4645
* locked region.
47-
* 4. Verify that writing to the second fuse now results in an error.
46+
* 3. Verify that writing to the second fuse now results in an error.
4847
*/
4948
void program_vendor_hashes_prod_partition(void) {
50-
const uint32_t addresses[2] = {CPTRA_CORE_VENDOR_PK_HASH_3, CPTRA_CORE_VENDOR_PK_HASH_5};
49+
const uint32_t addresses[2] = {CPTRA_CORE_VENDOR_PK_HASH_3, CPTRA_CORE_VENDOR_PK_HASH_4};
5150

5251
const uint32_t data = 0xdeadbeef;
5352

5453
// Step 1
5554
dai_wr(addresses[0], data, 0, 32, 0);
5655

5756
// Step 2
58-
//dai_wr(addresses[1], data+1, 0, 32, 0);
57+
lsu_write_32(SOC_OTP_CTRL_VENDOR_PK_HASH_VOLATILE_LOCK, 4); // Lock all hashes starting from index 4.
5958

6059
// Step 3
61-
lsu_write_32(SOC_OTP_CTRL_VENDOR_PK_HASH_VOLATILE_LOCK, 4); // Lock all hashes starting from index 5.
62-
63-
// Step 4
6460
dai_wr(addresses[1], data+2, 0, 32, OTP_CTRL_STATUS_DAI_ERROR_MASK);
6561
}
6662

0 commit comments

Comments
 (0)