Skip to content

Commit

Permalink
drivers/smmstore: add ability to write to whole flash
Browse files Browse the repository at this point in the history
With DRIVERS_EFI_UPDATE_CAPSULES enabled, SMMSTORE SMI handler can use
commands with highest bit (0x80) set to access whole flash instead of
just the SMMSTORE region. The rest of interface is identical to regular
SMMSTORE v2.

Change-Id: I7f3dbfa965b9dcbade8b2f06a5bd2ac1345c7972
Signed-off-by: Krystian Hebel <[email protected]>
  • Loading branch information
krystian-hebel committed Jun 27, 2024
1 parent 11de72c commit fd69fe4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/drivers/smmstore/smi.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ static uint32_t smmstorev2_exec(uint8_t command, void *param)
{
uint32_t ret = SMMSTORE_RET_FAILURE;

#if CONFIG(DRIVERS_EFI_UPDATE_CAPSULES)
smmstore_should_use_full_flash(&command);
#endif

switch (command) {
case SMMSTORE_CMD_INIT: {
printk(BIOS_DEBUG, "Init SMM store\n");
Expand Down
28 changes: 28 additions & 0 deletions src/drivers/smmstore/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,36 @@ _Static_assert(SMM_BLOCK_SIZE <= FMAP_SECTION_SMMSTORE_SIZE,
* crash/reboot could clear out all variables.
*/

#if CONFIG(DRIVERS_EFI_UPDATE_CAPSULES)
#define SMMSTORE_CMD_USE_FULL_FLASH 0x80

static int use_full_flash;

void smmstore_should_use_full_flash(uint8_t *cmd)
{
if ((*cmd & SMMSTORE_CMD_USE_FULL_FLASH) == SMMSTORE_CMD_USE_FULL_FLASH) {
use_full_flash = 1;
*cmd &= ~SMMSTORE_CMD_USE_FULL_FLASH;
} else {
use_full_flash = 0;
}

}
#endif

static enum cb_err lookup_store_region(struct region *region)
{
#if CONFIG(DRIVERS_EFI_UPDATE_CAPSULES)
if (use_full_flash) {
const struct region_device *rdev = boot_device_rw();
if (rdev == NULL)
return CB_ERR;

*region = *region_device_region(rdev);
return CB_SUCCESS;
}
#endif

if (fmap_locate_area(SMMSTORE_REGION, region)) {
printk(BIOS_WARNING,
"smm store: Unable to find SMM store FMAP region '%s'\n",
Expand Down
3 changes: 3 additions & 0 deletions src/include/smmstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ int smmstore_get_info(struct smmstore_params_info *info);
#endif
struct region_device;
int smmstore_lookup_region(struct region_device *rstore);
#if CONFIG(DRIVERS_EFI_UPDATE_CAPSULES)
void smmstore_should_use_full_flash(uint8_t *cmd);
#endif

/* Advertise SMMSTORE v2 support */
struct lb_header;
Expand Down

0 comments on commit fd69fe4

Please sign in to comment.