Skip to content

Commit 42c81b8

Browse files
committed
[fuse_ctrl,dv] Tidy up tests for Caliptra secret addresses
The value in caliptra_ss_fuse_ctrl_manuf_prod_prov hadn't yet been updated for the change in 275521b. This change should make it so that test and also caliptra_ss_fuse_ctrl_init_fail get a magic number from a single (documented) place. Apply the same change to caliptra_ss_fuse_ctrl_test_unlocked0_prov.
1 parent 302ea24 commit 42c81b8

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

src/integration/test_suites/caliptra_ss_fuse_ctrl_init_fail/caliptra_ss_fuse_ctrl_init_fail.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ void init_fail() {
4242
CMD_FC_LCC_UNCORRECTABLE_FAULT
4343
};
4444

45-
const uint32_t partition_lower_addr_bound = partitions[SECRET_MANUF_PARTITION].address;
46-
const uint32_t partition_upper_addr_bound = partitions[SECRET_PROD_PARTITION_3].zer_address;
47-
4845
// Collect all buffered partitions with ECC enabled. Their content
4946
// will be read out after bringup which will trigger the ECC errors.
5047
partition_t part_sel[NUM_PARTITIONS];
@@ -59,7 +56,7 @@ void init_fail() {
5956
partition_t partition = part_sel[xorshift32() % count];
6057
uint32_t fault = faults[xorshift32() % 2];
6158

62-
if (partition.address > partition_lower_addr_bound && partition.address < partition_upper_addr_bound) {
59+
if (is_caliptra_secret_addr(partition.address)) {
6360
grant_caliptra_core_for_fc_writes();
6461
} else {
6562
grant_mcu_for_fc_writes();

src/integration/test_suites/caliptra_ss_fuse_ctrl_manuf_prod_prov/caliptra_ss_fuse_ctrl_manuf_prod_prov.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//********************************************************************************
22
// SPDX-License-Identifier: Apache-2.0
3-
//
3+
//
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ void manuf_prod_provision() {
6060
if (partitions[i].lc_phase == MANUF || partitions[i].lc_phase == PROD) {
6161
part_sel[count++] = partitions[i];
6262
}
63-
}
63+
}
6464

6565
// 0x2C88: CPTRA_SS_TEST_EXIT_TO_MANUF_TOKEN
6666
const uint32_t base_address = CPTRA_SS_TEST_UNLOCK_TOKEN_1;
@@ -90,10 +90,10 @@ void manuf_prod_provision() {
9090

9191
// Check that all the MANUF and PROD partitionss are writeable.
9292
for (uint32_t i = 0; i < count; i++) {
93-
if (part_sel[i].address > 0x40 && part_sel[i].address < 0xF8) {
93+
if (is_caliptra_secret_addr(part_sel[i].address)) {
9494
grant_caliptra_core_for_fc_writes();
9595
} else {
96-
grant_mcu_for_fc_writes();
96+
grant_mcu_for_fc_writes();
9797
}
9898
dai_wr(part_sel[i].address, i, 0, part_sel[i].granularity, 0);
9999
}
@@ -111,23 +111,23 @@ void manuf_prod_provision() {
111111

112112
// Check that only PROD partitions are writeable and writes to MANUF partitions are blocked.
113113
for (uint32_t i = 0; i < count; i++) {
114-
if (part_sel[i].address > 0x40 && part_sel[i].address < 0xF8) {
114+
if (is_caliptra_secret_addr(part_sel[i].address)) {
115115
grant_caliptra_core_for_fc_writes();
116116
} else {
117-
grant_mcu_for_fc_writes();
117+
grant_mcu_for_fc_writes();
118118
}
119119
dai_wr(part_sel[i].address, i, 0, part_sel[i].granularity, part_sel[i].lc_phase == MANUF ? OTP_CTRL_STATUS_DAI_ERROR_MASK : 0);
120120
}
121121
}
122122

123123
void main (void) {
124124
VPRINTF(LOW, "=================\nMCU Caliptra Boot Go\n=================\n\n")
125-
125+
126126
mcu_cptra_init_d();
127127
wait_dai_op_idle(0);
128-
128+
129129
lcc_initialization();
130-
grant_mcu_for_fc_writes();
130+
grant_mcu_for_fc_writes();
131131

132132
transition_state_check(TEST_UNLOCKED0, raw_unlock_token[0], raw_unlock_token[1], raw_unlock_token[2], raw_unlock_token[3], 1);
133133

src/integration/test_suites/caliptra_ss_fuse_ctrl_test_unlocked0_prov/caliptra_ss_fuse_ctrl_test_unlocked0_prov.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void test_unlocked0_provision() {
5151
uint32_t rnd_fuse_addresses[NUM_PARTITIONS-1];
5252

5353
for (uint32_t i = 0; i < (NUM_PARTITIONS-1); i++) {
54-
if (partitions[i].address > 0x40 && partitions[i].address < 0xD0) {
54+
if (is_caliptra_secret_addr(part_sel[i].address)) {
5555
grant_caliptra_core_for_fc_writes();
5656
} else {
5757
grant_mcu_for_fc_writes();
@@ -77,7 +77,7 @@ void test_unlocked0_provision() {
7777
wait_dai_op_idle(0);
7878

7979
for (uint32_t i = 0; i < (NUM_PARTITIONS-1); i++) {
80-
if (partitions[i].address > 0x40 && partitions[i].address < 0xD0) {
80+
if (is_caliptra_secret_addr(part_sel[i].address)) {
8181
grant_caliptra_core_for_fc_writes();
8282
} else {
8383
grant_mcu_for_fc_writes();

src/integration/test_suites/libs/fuse_ctrl/fuse_ctrl.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
#include <stdlib.h>
1818
#include <stdint.h>
19+
#include <stdbool.h>
1920

2021
#include "soc_address_map.h"
2122
#include "printf.h"
2223
#include "soc_ifc.h"
2324
#include "caliptra_ss_lc_ctrl_address_map.h"
2425
#include "riscv_hw_if.h"
26+
#include "fuse_ctrl_mmap.h"
2527
#include "fuse_ctrl.h"
2628

2729
void grant_mcu_for_fc_writes(void) {
@@ -330,4 +332,12 @@ void zeroize_without_addr(uint32_t exp_status) {
330332

331333
wait_dai_op_idle(exp_status);
332334
return;
333-
}
335+
}
336+
337+
bool is_caliptra_secret_addr(uint32_t addr) {
338+
// This mirrors CALIPTRA_SECRET_ACCESS_LOWER_ADDR and CALIPTRA_SECRET_ACCESS_UPPER_ADDR in
339+
// otp_ctrl_pkg. Here, we're using the fact that the secret partitions are a contiguous block,
340+
// starting with SECRET_MANUF_PARTITION and ending with SECRET_PROD_PARTITION_3.
341+
return ((addr >= partitions[SECRET_MANUF_PARTITION].address) &&
342+
(addr <= partitions[SECRET_PROD_PARTITION_3].zer_address));
343+
}

src/integration/test_suites/libs/fuse_ctrl/fuse_ctrl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ void shuffled_dai_rd(uint32_t addr, uint32_t* rdata0, uint32_t* rdata1, uint32_t
4141
void calculate_digest_without_addr(uint32_t exp_status);
4242
void zeroize_without_addr(uint32_t exp_status);
4343

44+
// Returns true if addr is in the range of addresses that are visible
45+
// to the Caliptra core but not the MCU.
46+
bool is_caliptra_secret_addr(uint32_t addr);
4447

45-
#endif // FUSE_CTRL_H
48+
#endif // FUSE_CTRL_H

0 commit comments

Comments
 (0)