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 28, 2024
1 parent 628cce5 commit 623abec
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/drivers/smmstore/smi.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ static uint32_t smmstorev2_exec(uint8_t command, void *param)

uint32_t smmstore_exec(uint8_t command, void *param)
{
if (smmstore_preprocess_cmd(&command))
return SMMSTORE_RET_SUCCESS;

if (command != SMMSTORE_CMD_CLEAR && !param)
return SMMSTORE_RET_FAILURE;

Expand Down
26 changes: 26 additions & 0 deletions src/drivers/smmstore/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,34 @@ _Static_assert(SMM_BLOCK_SIZE <= FMAP_SECTION_SMMSTORE_SIZE,
* crash/reboot could clear out all variables.
*/

static int use_full_flash;

int smmstore_preprocess_cmd(uint8_t *cmd)
{
if (CONFIG(DRIVERS_EFI_UPDATE_CAPSULES)) {
if (*cmd & SMMSTORE_CMD_USE_FULL_FLASH) {
use_full_flash = 1;
*cmd &= ~SMMSTORE_CMD_USE_FULL_FLASH;
} else {
use_full_flash = 0;
}
}

return 0;
}

static enum cb_err lookup_store_region(struct region *region)
{
if (CONFIG(DRIVERS_EFI_UPDATE_CAPSULES) && 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;
}

if (fmap_locate_area(SMMSTORE_REGION, region)) {
printk(BIOS_WARNING,
"smm store: Unable to find SMM store FMAP region '%s'\n",
Expand Down
5 changes: 5 additions & 0 deletions src/include/smmstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#define SMMSTORE_CMD_RAW_WRITE 6
#define SMMSTORE_CMD_RAW_CLEAR 7

/* Used by capsule updates */
#define SMMSTORE_CMD_USE_FULL_FLASH 0x80

/* Version 1 */
struct smmstore_params_read {
void *buf;
Expand Down Expand Up @@ -117,6 +120,8 @@ int smmstore_get_info(struct smmstore_params_info *info);
#endif
struct region_device;
int smmstore_lookup_region(struct region_device *rstore);
/* Returns 0 if normal parsing should continue, 1 otherwise */
int smmstore_preprocess_cmd(uint8_t *cmd);

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

0 comments on commit 623abec

Please sign in to comment.