Skip to content

Commit

Permalink
Add libcaliptra APIs to check if ready for certain boot milestones.
Browse files Browse the repository at this point in the history
Previously the only APIs blocked until it reached those milestones. Now they can be checked asynchronously. This is also how `caliptra_is_csr_ready` works.
  • Loading branch information
zhalvorsen authored and jhand2 committed Feb 19, 2025
1 parent 09bc0ca commit 69304ec
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
20 changes: 19 additions & 1 deletion libcaliptra/inc/caliptra_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,34 @@ 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);

/**
* caliptra_is_ready_for_firmware
*
* Checks if Caliptra hardware is ready for firmware upload
*
* @return bool True if ready, false otherwise
*/
uint32_t caliptra_is_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
* @return int 0 if ready, Caliptra error otherwise
*/
uint32_t caliptra_ready_for_firmware(void);

/**
* caliptra_is_ready_for_runtime
*
* Checks if Caliptra hardware is ready for runtime commands
*
* @return bool True if ready, false otherwise
*/
uint32_t caliptra_is_ready_for_runtime(void);

/**
* caliptra_ready_for_runtime
*
Expand Down
36 changes: 29 additions & 7 deletions libcaliptra/src/caliptra_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,30 +324,41 @@ uint32_t caliptra_read_fw_fatal_error()
return caliptra_read_fw_error_fatal();
}

/**
* caliptra_is_ready_for_firmware
*
* Checks if Caliptra hardware is ready for firmware upload
*
* @return bool True if ready, false otherwise
*/
uint32_t caliptra_is_ready_for_firmware(void)
{
uint32_t status = caliptra_read_status();
return (status & GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_FW_MASK) == GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_FW_MASK;
}

/**
* 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
* @return int 0 if ready, Caliptra error otherwise
*/
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 (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)
else if (caliptra_is_ready_for_firmware())
{
ready = true;
}
Expand All @@ -360,6 +371,19 @@ uint32_t caliptra_ready_for_firmware(void)
return 0;
}

/**
* caliptra_is_ready_for_runtime
*
* Checks if Caliptra hardware is ready for runtime commands
*
* @return bool True if ready, false otherwise
*/
uint32_t caliptra_is_ready_for_runtime(void)
{
uint32_t status = caliptra_read_status();
return (status & GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_RUNTIME_MASK) == GENERIC_AND_FUSE_REG_CPTRA_FLOW_STATUS_READY_FOR_RUNTIME_MASK;
}

/**
* caliptra_ready_for_runtime
*
Expand All @@ -370,20 +394,18 @@ uint32_t 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 (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)
else if (caliptra_is_ready_for_runtime())
{
ready = true;
}
Expand Down

0 comments on commit 69304ec

Please sign in to comment.