From 73bdc9672c79d078785c8d2df41d97e7bec30936 Mon Sep 17 00:00:00 2001 From: Carl Lundin Date: Wed, 13 Nov 2024 10:21:29 -0800 Subject: [PATCH] Add GetIdevCsr to libcaliptra. --- libcaliptra/examples/generic/test.c | 22 ++++++++++++++++++++++ libcaliptra/inc/caliptra_api.h | 3 +++ libcaliptra/inc/caliptra_types.h | 6 ++++++ libcaliptra/src/caliptra_api.c | 15 +++++++++++++++ libcaliptra/src/caliptra_mbox.h | 1 + 5 files changed, 47 insertions(+) diff --git a/libcaliptra/examples/generic/test.c b/libcaliptra/examples/generic/test.c index 7f7daeeffa..bdd421e7e2 100644 --- a/libcaliptra/examples/generic/test.c +++ b/libcaliptra/examples/generic/test.c @@ -664,6 +664,28 @@ int rom_test_devid_csr(const test_info* info) printf("IDEV CSR matches\n"); } + caliptra_req_idev_csr_complete(); + caliptra_ready_for_firmware(); + + // Test Get Idev CSR now that a CSR is provisioned. + // GET IDEV CSR + struct caliptra_get_idev_csr_resp csr_resp = {0}; + + status = caliptra_get_idev_csr(&csr_resp, false); + + if (status) { + printf("Get IDev CSR failed: 0x%x\n", status); + dump_caliptra_error_codes(); + failure = 1; + } else { + if (memcmp(csr_resp.data, idev_csr_bytes, csr_resp.data_size) != 0) { + printf("IDEV CSR does not match\n"); + failure = 1; + } else { + printf("Get IDev CSR: OK\n"); + } + } + free((void*)caliptra_idevid_csr_buf.data); return failure; } diff --git a/libcaliptra/inc/caliptra_api.h b/libcaliptra/inc/caliptra_api.h index a5fbeefd68..8992dad882 100644 --- a/libcaliptra/inc/caliptra_api.h +++ b/libcaliptra/inc/caliptra_api.h @@ -180,6 +180,9 @@ int caliptra_certify_key_extended(struct caliptra_certify_key_extended_req *req, // FIPS version int caliptra_fips_version(struct caliptra_fips_version_resp *resp, bool async); +// Get IDev CSR +int caliptra_get_idev_csr(struct caliptra_get_idev_csr_resp *resp, bool async); + // Self test start int caliptra_self_test_start(bool async); diff --git a/libcaliptra/inc/caliptra_types.h b/libcaliptra/inc/caliptra_types.h index 165b27348a..9058f50bd7 100644 --- a/libcaliptra/inc/caliptra_types.h +++ b/libcaliptra/inc/caliptra_types.h @@ -218,6 +218,12 @@ struct caliptra_capabilities_resp { uint8_t capabilities[16]; }; +struct caliptra_get_idev_csr_resp { + struct caliptra_resp_header hdr; + uint32_t data_size; + uint8_t data[512]; +}; + // DPE commands #define DPE_MAGIC 0x44504543 // "DPEC" diff --git a/libcaliptra/src/caliptra_api.c b/libcaliptra/src/caliptra_api.c index 5bac11a39e..cf8d4b9924 100644 --- a/libcaliptra/src/caliptra_api.c +++ b/libcaliptra/src/caliptra_api.c @@ -1170,6 +1170,21 @@ int caliptra_fips_version(struct caliptra_fips_version_resp *resp, bool async) return pack_and_execute_command(&p, async); } +// Get IDev CSR +int caliptra_get_idev_csr(struct caliptra_get_idev_csr_resp *resp, bool async) +{ + if (!resp) + { + return INVALID_PARAMS; + } + + caliptra_checksum checksum = 0; + + CREATE_PARCEL(p, OP_GET_IDEV_CSR, &checksum, resp); + + return pack_and_execute_command(&p, async); +} + // Self test start int caliptra_self_test_start(bool async) { diff --git a/libcaliptra/src/caliptra_mbox.h b/libcaliptra/src/caliptra_mbox.h index f62ce0b765..2b5d77b5df 100644 --- a/libcaliptra/src/caliptra_mbox.h +++ b/libcaliptra/src/caliptra_mbox.h @@ -51,6 +51,7 @@ enum mailbox_command { OP_SELF_TEST_GET_RESULTS = 0x46504C67, // "FPGR" OP_SHUTDOWN = 0x46505344, // "FPSD" OP_CAPABILITIES = 0x43415053, // "CAPS" + OP_GET_IDEV_CSR = 0x49444352, // "IDCR" }; struct parcel {