![]() |
coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
|
#include <string.h>
#include <boot_device.h>
#include <bootstate.h>
#include <bootmode.h>
#include <console/console.h>
#include <cbmem.h>
#include <elog.h>
#include <fmap.h>
#include <ip_checksum.h>
#include <region_file.h>
#include <security/vboot/antirollback.h>
#include <security/vboot/mrc_cache_hash_tpm.h>
#include <security/vboot/vboot_common.h>
#include <spi_flash.h>
#include "mrc_cache.h"
Go to the source code of this file.
Data Structures | |
struct | mrc_metadata |
struct | cache_region |
Macros | |
#define | DEFAULT_MRC_CACHE "RW_MRC_CACHE" |
#define | VARIABLE_MRC_CACHE "RW_VAR_MRC_CACHE" |
#define | RECOVERY_MRC_CACHE "RECOVERY_MRC_CACHE" |
#define | UNIFIED_MRC_CACHE "UNIFIED_MRC_CACHE" |
#define | MRC_DATA_SIGNATURE (('M'<<0)|('R'<<8)|('C'<<16)|('D'<<24)) |
#define | NORMAL_FLAG (1 << 0) |
#define | RECOVERY_FLAG (1 << 1) |
Enumerations | |
enum | result { UPDATE_FAILURE = -1 , UPDATE_SUCCESS = 0 , ALREADY_UPTODATE = 1 } |
Functions | |
_Static_assert (!CONFIG(MRC_SAVE_HASH_IN_TPM)||CONFIG(VBOOT_STARTS_IN_BOOTBLOCK), "for TPM MRC hash functionality, vboot must start in bootblock") | |
static int | lookup_region_by_name (const char *name, struct region *r) |
static const struct cache_region * | lookup_region_type (int type) |
static const struct cache_region * | lookup_region (struct region *r, int type) |
static int | mrc_header_valid (struct region_device *rdev, struct mrc_metadata *md) |
static int | mrc_data_valid (int type, const struct mrc_metadata *md, void *data, size_t data_size) |
static int | mrc_cache_get_latest_slot_info (const char *name, const struct region_device *backing_rdev, struct mrc_metadata *md, struct region_file *cache_file, struct region_device *rdev, bool fail_bad_data) |
static int | mrc_cache_find_current (int type, uint32_t version, struct region_device *rdev, struct mrc_metadata *md) |
ssize_t | mrc_cache_load_current (int type, uint32_t version, void *buffer, size_t buffer_size) |
mrc_cache_load_current More... | |
void * | mrc_cache_current_mmap_leak (int type, uint32_t version, size_t *data_size) |
mrc_cache_mmap_leak More... | |
static bool | mrc_cache_needs_update (const struct region_device *rdev, const struct mrc_metadata *new_md, const void *new_data, size_t new_data_size) |
static void | log_event_cache_update (uint8_t slot, enum result res) |
static void | update_mrc_cache_by_type (int type, struct mrc_metadata *new_md, const void *new_data, size_t new_data_size) |
static int | nvm_is_write_protected (void) |
static int | nvm_protect (const struct region *r) |
static int | protect_mrc_cache (const char *name) |
static void | protect_mrc_region (void) |
static void | invalidate_normal_cache (void) |
static void | update_mrc_cache_from_cbmem (int type) |
static void | finalize_mrc_cache (void *unused) |
int | mrc_cache_stash_data (int type, uint32_t version, const void *data, size_t size) |
Returns < 0 on error, 0 on success. More... | |
BOOT_STATE_INIT_ENTRY (BS_DEV_ENUMERATE, BS_ON_EXIT, finalize_mrc_cache, NULL) | |
Variables | |
struct mrc_metadata | __packed |
static const struct cache_region | recovery_training |
static const struct cache_region | normal_training |
static const struct cache_region | variable_data |
static const struct cache_region * | cache_regions [] |
#define DEFAULT_MRC_CACHE "RW_MRC_CACHE" |
Definition at line 20 of file mrc_cache.c.
#define MRC_DATA_SIGNATURE (('M'<<0)|('R'<<8)|('C'<<16)|('D'<<24)) |
Definition at line 25 of file mrc_cache.c.
#define NORMAL_FLAG (1 << 0) |
Definition at line 41 of file mrc_cache.c.
#define RECOVERY_FLAG (1 << 1) |
Definition at line 42 of file mrc_cache.c.
#define RECOVERY_MRC_CACHE "RECOVERY_MRC_CACHE" |
Definition at line 22 of file mrc_cache.c.
#define UNIFIED_MRC_CACHE "UNIFIED_MRC_CACHE" |
Definition at line 23 of file mrc_cache.c.
#define VARIABLE_MRC_CACHE "RW_VAR_MRC_CACHE" |
Definition at line 21 of file mrc_cache.c.
enum result |
Enumerator | |
---|---|
UPDATE_FAILURE | |
UPDATE_SUCCESS | |
ALREADY_UPTODATE |
Definition at line 35 of file mrc_cache.c.
_Static_assert | ( | ! | CONFIGMRC_SAVE_HASH_IN_TPM)||CONFIG(VBOOT_STARTS_IN_BOOTBLOCK, |
"for TPM MRC hash | functionality, | ||
vboot must start in bootblock" | |||
) |
BOOT_STATE_INIT_ENTRY | ( | BS_DEV_ENUMERATE | , |
BS_ON_EXIT | , | ||
finalize_mrc_cache | , | ||
NULL | |||
) |
Definition at line 673 of file mrc_cache.c.
References CONFIG, invalidate_normal_cache(), MRC_TRAINING_DATA, MRC_VARIABLE_DATA, protect_mrc_region(), and update_mrc_cache_from_cbmem().
Definition at line 596 of file mrc_cache.c.
References BIOS_ERR, CONFIG, DEFAULT_MRC_CACHE, fmap_locate_area_as_rdev_rw(), get_recovery_mode_retrain_switch(), MRC_DATA_SIGNATURE, name, printk, rdev, region_file_init(), region_file_update_data(), and vboot_recovery_mode_enabled().
Referenced by finalize_mrc_cache().
Definition at line 401 of file mrc_cache.c.
References BIOS_ERR, elog_add_event_raw(), ELOG_MEM_CACHE_UPDATE_STATUS_FAIL, ELOG_MEM_CACHE_UPDATE_STATUS_SUCCESS, ELOG_TYPE_MEM_CACHE_UPDATE, printk, elog_event_mem_cache_update::slot, type, UPDATE_FAILURE, and UPDATE_SUCCESS.
Referenced by update_mrc_cache_by_type().
|
static |
Definition at line 149 of file mrc_cache.c.
References BIOS_ERR, lookup_region_by_name(), lookup_region_type(), cache_region::name, NULL, printk, and type.
Referenced by mrc_cache_find_current(), update_mrc_cache_by_type(), and update_mrc_cache_from_cbmem().
|
static |
Definition at line 122 of file mrc_cache.c.
References fmap_locate_area(), and name.
Referenced by lookup_region(), and protect_mrc_cache().
|
static |
Definition at line 129 of file mrc_cache.c.
References ARRAY_SIZE, cache_regions, CONFIG, cache_region::flags, NORMAL_FLAG, NULL, RECOVERY_FLAG, type, and vboot_recovery_mode_enabled().
Referenced by lookup_region(), mrc_cache_stash_data(), and mrc_data_valid().
mrc_cache_mmap_leak
Return a pointer to a buffer with the latest slot data. An mmap will be executed (without a matching unmap). This will be a common entry point for platforms where mmap is considered a noop, like x86
Definition at line 342 of file mrc_cache.c.
References BIOS_INFO, mrc_metadata::data_size, mrc_cache_find_current(), mrc_data_valid(), NULL, printk, rdev, rdev_mmap_full(), region_device_sz(), type, and version.
Referenced by check_region_overlap(), get_cached_training(), init_dram_ddr3(), OemInitResume(), platform_fsp_memory_init_params_cb(), prepare_mrc_cache(), raminit(), raminit_common(), and sdram_initialize().
|
static |
Definition at line 272 of file mrc_cache.c.
References BIOS_INFO, boot_device_ro_subregion(), CONFIG, mrc_metadata::data_size, get_recovery_mode_retrain_switch(), lookup_region(), mrc_cache_get_latest_slot_info(), cache_region::name, NULL, printk, rdev, rdev_chain(), type, vboot_recovery_mode_enabled(), mrc_metadata::version, and version.
Referenced by mrc_cache_current_mmap_leak(), and mrc_cache_load_current().
|
static |
Definition at line 239 of file mrc_cache.c.
References BIOS_ERR, BIOS_NOTICE, mrc_header_valid(), name, printk, rdev, rdev_chain(), region_file_data(), and region_file_init().
Referenced by mrc_cache_find_current(), and update_mrc_cache_by_type().
mrc_cache_load_current
Fill in the buffer with the latest slot data. This will be a common entry point for ARM platforms. Returns < 0 on error, size of the returned data on success.
Definition at line 319 of file mrc_cache.c.
References buffer, mrc_metadata::data_size, mrc_cache_find_current(), mrc_data_valid(), rdev, rdev_readat(), region_device_sz(), type, and version.
Referenced by mt_mem_init_run(), and qclib_load_and_run().
|
static |
Definition at line 369 of file mrc_cache.c.
References BIOS_ERR, memcmp(), NULL, printk, rdev, rdev_mmap_full(), rdev_munmap(), and region_device_sz().
Referenced by update_mrc_cache_by_type().
Returns < 0 on error, 0 on success.
Definition at line 687 of file mrc_cache.c.
References BIOS_ERR, BIOS_INFO, cbmem_add(), cache_region::cbmem_id, compute_ip_checksum(), CONFIG, mrc_metadata::header_checksum, lookup_region_type(), memcpy(), MRC_DATA_SIGNATURE, cache_region::name, NULL, printk, mrc_metadata::signature, type, update_mrc_cache_by_type(), and version.
Referenced by mainboard_romstage_entry(), mt_mem_init_run(), OemS3Save(), raminit(), raminit_common(), save_memory_training_data(), save_mrc_data(), save_timings(), sdram_initialize(), and write_table_entry().
|
static |
Definition at line 209 of file mrc_cache.c.
References BIOS_ERR, checksum(), compute_ip_checksum(), CONFIG, mrc_metadata::data_checksum, mrc_metadata::data_size, lookup_region_type(), mrc_cache_verify_hash(), NULL, printk, cache_region::tpm_hash_index, and type.
Referenced by mrc_cache_current_mmap_leak(), and mrc_cache_load_current().
|
static |
Definition at line 167 of file mrc_cache.c.
References BIOS_ERR, checksum(), compute_ip_checksum(), mrc_metadata::data_size, mrc_metadata::header_checksum, MRC_DATA_SIGNATURE, printk, rdev, rdev_chain(), rdev_readat(), region_device_sz(), and mrc_metadata::signature.
Referenced by mrc_cache_get_latest_slot_info().
|
static |
Definition at line 510 of file mrc_cache.c.
References BIOS_DEBUG, BIOS_ERR, boot_device_spi_flash(), CONFIG, get_write_protect_state(), printk, and spi_flash_status().
Referenced by protect_mrc_cache().
|
static |
Definition at line 539 of file mrc_cache.c.
References boot_device_spi_flash(), CONFIG, spi_flash_ctrlr_protect_region(), and WRITE_PROTECT.
Referenced by protect_mrc_cache().
|
static |
Definition at line 551 of file mrc_cache.c.
References BIOS_ERR, BIOS_INFO, CONFIG, lookup_region_by_name(), name, nvm_is_write_protected(), nvm_protect(), and printk.
Referenced by protect_mrc_region().
Definition at line 577 of file mrc_cache.c.
References CONFIG, DEFAULT_MRC_CACHE, protect_mrc_cache(), RECOVERY_MRC_CACHE, and UNIFIED_MRC_CACHE.
Referenced by finalize_mrc_cache().
|
static |
Definition at line 428 of file mrc_cache.c.
References ALREADY_UPTODATE, ARRAY_SIZE, BIOS_DEBUG, BIOS_ERR, boot_device_ro_subregion(), boot_device_rw_subregion(), CONFIG, cache_region::elog_slot, incoherent_rdev_init(), log_event_cache_update(), lookup_region(), mrc_cache_get_latest_slot_info(), mrc_cache_needs_update(), mrc_cache_update_hash(), cache_region::name, NULL, printk, region_file_update_data_arr(), update_region_file_entry::size, cache_region::tpm_hash_index, type, UPDATE_FAILURE, and UPDATE_SUCCESS.
Referenced by mrc_cache_stash_data(), and update_mrc_cache_from_cbmem().
|
static |
Definition at line 641 of file mrc_cache.c.
References BIOS_INFO, cbmem_entry_find(), cbmem_entry_size(), cbmem_entry_start(), cache_region::cbmem_id, lookup_region(), cache_region::name, NULL, printk, type, and update_mrc_cache_by_type().
Referenced by finalize_mrc_cache().
struct mrc_metadata __packed |
|
static |
|
static |
Definition at line 1 of file mrc_cache.c.
|
static |
Definition at line 1 of file mrc_cache.c.
|
static |
Definition at line 1 of file mrc_cache.c.