Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ready_for_runtime API #1934

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libcaliptra/examples/generic/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ int rt_test_all_commands(const test_info* info)
printf("FW Load: OK\n");
}

status = caliptra_ready_for_runtime();
if (status) {
printf("Firmware Boot Failed: 0x%x\n", status);
dump_caliptra_error_codes();
failure = 1;
}

// GET_IDEV_CERT
struct caliptra_get_idev_cert_req idev_cert_req = {};
struct caliptra_get_idev_cert_resp idev_cert_resp;
Expand Down
21 changes: 19 additions & 2 deletions libcaliptra/inc/caliptra_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,25 @@ bool caliptra_ready_for_fuses(void);
// STILL_READY_FOR_FUSES - Flow status still indicates ready for fuses after writing fuse done
int caliptra_init_fuses(const struct caliptra_fuses *fuses);

// Query if ROM is ready for firmware
bool caliptra_ready_for_firmware(void);
/**
* caliptra_ready_for_firmware
*
* Waits until Caliptra hardware is ready for firmware upload or until
* Caliptra reports an error
*
* @return bool True if ready, false otherwise
*/
uint32_t caliptra_ready_for_firmware(void);

/**
* caliptra_ready_for_runtime
*
* Waits until Caliptra hardware is ready for runtime commands or until
* Caliptra reports an error
*
* @return int 0 if ready, Caliptra error otherwise
*/
uint32_t caliptra_ready_for_runtime(void);

// Read the value of the caliptra FW non-fatal error code
// returns: Caliptra error code (see error/src/lib.rs)
Expand Down
25 changes: 19 additions & 6 deletions libcaliptra/src/caliptra_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,27 @@ uint32_t caliptra_read_fw_fatal_error()
/**
* caliptra_ready_for_firmware
*
* Reports if the Caliptra hardware is ready for firmware upload
* Waits until Caliptra hardware is ready for firmware upload or until
* Caliptra reports an error
*
* @return bool True if ready, false otherwise
*/
bool caliptra_ready_for_firmware(void)
uint32_t caliptra_ready_for_firmware(void)
{
uint32_t status;
uint32_t fatal_error;
bool ready = false;

do
{
status = caliptra_read_status();
fatal_error = caliptra_read_fw_fatal_error();

if ((status & GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_FW_MASK) == GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_FW_MASK)
if (fatal_error != 0)
{
return fatal_error;
}
else if ((status & GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_FW_MASK) == GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_FW_MASK)
{
ready = true;
}
Expand All @@ -350,7 +357,7 @@ bool caliptra_ready_for_firmware(void)
}
} while (ready == false);

return true;
return 0;
}

/**
Expand All @@ -364,13 +371,19 @@ bool caliptra_ready_for_firmware(void)
uint32_t caliptra_ready_for_runtime(void)
{
uint32_t status;
uint32_t fatal_error;
bool ready = false;

do
{
status = caliptra_read_status();
fatal_error = caliptra_read_fw_fatal_error();

if ((status & GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_FW_MASK) == GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_FW_MASK)
if (fatal_error != 0)
{
return fatal_error;
}
else if ((status & GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_RUNTIME_MASK) == GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_RUNTIME_MASK)
{
ready = true;
}
Expand All @@ -380,7 +393,7 @@ uint32_t caliptra_ready_for_runtime(void)
}
} while (ready == false);

return true;
return 0;
}

/*
Expand Down
Loading