drivers/uart: Replace 'unsigned long int' by 'unsigned long'
[coreboot2.git] / src / ec / google / chromeec / vboot_storage.c
blob63e131448a0b7347748444649d649f6822915efe
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <assert.h>
4 #include <console/console.h>
5 #include <ec/google/chromeec/ec.h>
6 #include <security/vboot/vboot_common.h>
8 #define VBOOT_HASH_VSLOT 0
9 #define VBOOT_HASH_VSLOT_MASK (1 << (VBOOT_HASH_VSLOT))
11 int vboot_save_hash(void *digest, size_t digest_size)
13 const int slot = VBOOT_HASH_VSLOT;
14 uint32_t lock_status;
15 int num_slots;
17 /* Ensure the digests being saved does not exceed the EC's slot size. */
18 assert(digest_size > 0 && digest_size <= EC_VSTORE_SLOT_SIZE);
20 if (google_chromeec_vstore_write(slot, digest, digest_size))
21 return -1;
23 /* Assert the slot is locked on successful write. */
24 num_slots = google_chromeec_vstore_info(&lock_status);
26 /* Normalize to be 0 based. If num_slots returned 0 then it'll be -1. */
27 num_slots--;
29 if (num_slots < slot) {
30 printk(BIOS_ERR, "Not enough vstore slots for vboot hash: %d\n",
31 num_slots + 1);
32 return -1;
35 if ((lock_status & VBOOT_HASH_VSLOT_MASK) == 0) {
36 printk(BIOS_ERR, "Vstore slot not locked after write.\n");
37 return -1;
40 return 0;
43 int vboot_retrieve_hash(void *digest, size_t digest_size)
45 /* Ensure the digests being saved match the EC's slot size. */
46 assert(digest_size == EC_VSTORE_SLOT_SIZE);
48 return google_chromeec_vstore_read(VBOOT_HASH_VSLOT, digest);