drivers/spi: add RPMC support

Add functions to send the RPMC-related commands to a RPMC-capable SPI
flash to provision the root key, update the HMAC key, increment the
monotonic counter, and request the monotonic counter data. To talk to
the flash chip, the command bytes and polling mechanism described in the
SFDP data structure of the flash are used.

The JESD260 specification was used as a reference.

Some of inspiration was taken from
github.com/teslamotors/coreboot/tree/tesla-4.12-amd

TEST=When used with the later patch that calls some of the functions
added in this patch, sending the RPMC increment monotonic counter
command to the RPMC-capable SPI flash, in this case W74M12JW, is
successful.

Change-Id: Ia9bd69d0105c66bf5ecb6c90e8c782a81912bd40
Signed-off-by: Felix Held <felix-coreboot@felixheld.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/84837
Reviewed-by: Matt DeVillier <matt.devillier@gmail.com>
Reviewed-by: Marshall Dawson <marshalldawson3rd@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Felix Held 2024-11-06 01:58:28 +01:00
commit ce01117aa5
2 changed files with 357 additions and 0 deletions

View file

@ -15,6 +15,10 @@
/* SPI RPMC field lengths in bytes */
#define SPI_RPMC_TAG_LEN 12
#define SPI_RPMC_SIG_LEN 32
#define SPI_RPMC_ROOT_KEY_LEN 32
#define SPI_RPMC_TRUNCTAED_SIG_LEN 28 /* only used in write RPMC root key command */
#define SPI_RPMC_KEY_DATA_LEN 4
#define SPI_RPMC_COUNTER_DATA_LEN 4
struct spi_flash;
@ -261,4 +265,52 @@ uint32_t spi_flash_get_mmap_windows(struct flash_mmap_window *table);
/* Print the SFDP headers read from the SPI flash */
void spi_flash_print_sfdp_headers(const struct spi_flash *flash);
/*
* Write RPMC root key
*
* root_key: pointer to 32 bytes long buffer with root key
* truncated_signature: pointer to 28 bytes long buffer with truncated signature
*
* The buffers have the bytes in the order in which they will be sent to the SPI flash
*/
enum cb_err spi_flash_rpmc_write_root_key(const struct spi_flash *flash, uint8_t counter_addr,
const uint8_t *root_key,
const uint8_t *truncated_signature);
/*
* Update HMAC key
*
* key_data: pointer to 4 bytes long buffer with key data
* signature: pointer to 32 bytes long buffer with signature
*
* The buffers have the bytes in the order in which they will be sent to the SPI flash
*/
enum cb_err spi_flash_rpmc_update_hmac_key(const struct spi_flash *flash, uint8_t counter_addr,
uint8_t *key_data, const uint8_t *signature);
/*
* Increment monotonic counter
*
* counter_data: pointer to 4 bytes long buffer with counter data
* signature: pointer to 32 bytes long buffer with signature
*
* The buffers have the bytes in the order in which they will be sent to the SPI flash
*/
enum cb_err spi_flash_rpmc_increment(const struct spi_flash *flash, uint8_t counter_addr,
const uint8_t *counter_data, const uint8_t *signature);
/*
* Request monotonic counter
*
* tag: pointer to 12 bytes long buffer with tag
* signature: pointer to 32 bytes long buffer with signature
* counter_data: pointer to 4 bytes long buffer with counter data
* signature_out: pointer to 32 bytes long buffer with signature
*
* The buffers have the bytes in the order in which they will be sent to the SPI flash
*/
enum cb_err spi_flash_rpmc_request(const struct spi_flash *flash, uint8_t counter_addr,
const uint8_t *tag, const uint8_t *signature,
uint8_t *counter_data, uint8_t *signature_out);
#endif /* _SPI_FLASH_H_ */