From 529e20cacc69e917707b1c5e05dd3c21d76060f9 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 | 23 +++++++++++++++++++++++ libcaliptra/inc/caliptra_api.h | 3 +++ libcaliptra/inc/caliptra_types.h | 10 ++++++++++ libcaliptra/src/caliptra_api.c | 15 +++++++++++++++ libcaliptra/src/caliptra_mbox.h | 1 + 5 files changed, 52 insertions(+) diff --git a/libcaliptra/examples/generic/test.c b/libcaliptra/examples/generic/test.c index 7f7daeeffa..a8c74a748f 100644 --- a/libcaliptra/examples/generic/test.c +++ b/libcaliptra/examples/generic/test.c @@ -664,6 +664,29 @@ 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_req csr_req = {0}; + struct caliptra_get_idev_csr_resp csr_resp = {0}; + + status = caliptra_get_idev_csr(&csr_req, &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..3db91d0a2e 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_req *req, 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..f6a3134823 100644 --- a/libcaliptra/inc/caliptra_types.h +++ b/libcaliptra/inc/caliptra_types.h @@ -218,6 +218,16 @@ struct caliptra_capabilities_resp { uint8_t capabilities[16]; }; +struct caliptra_get_idev_csr_req { + struct caliptra_req_header hdr; +}; + +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..e184285a9a 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_req *req, 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 {