-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: efivar: Copy VarToFile to RTStorageVolatile file at ESP #267
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,16 @@ | |
|
||
#include "efivar.h" | ||
|
||
#define EFI_VARTOFILE "b2ac5fc9-92b7-4acd-aeac-11e818c3130c-VarToFile" | ||
#define EFI_RTSTORAGEVOLATILE "b2ac5fc9-92b7-4acd-aeac-11e818c3130c-RTStorageVolatile" | ||
#define PATH_SIZE 4096 | ||
|
||
static const char *esp_paths[] = { | ||
"/boot", | ||
"/boot/efi", | ||
"/efi" | ||
}; | ||
|
||
static int default_probe(void) | ||
{ | ||
return 1; | ||
|
@@ -65,7 +75,7 @@ _efi_set_variable_variadic(efi_guid_t guid, const char *name, const uint8_t *dat | |
VERSION(_efi_set_variable_mode,efi_set_variable@@LIBEFIVAR_0.24) | ||
int NONNULL(2, 3) PUBLIC | ||
_efi_set_variable_mode(efi_guid_t guid, const char *name, const uint8_t *data, | ||
size_t data_size, uint32_t attributes, mode_t mode) | ||
size_t data_size, uint32_t attributes, mode_t mode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldnt change tabbing on this patch |
||
{ | ||
int rc; | ||
if (!ops->set_variable) { | ||
|
@@ -93,7 +103,7 @@ efi_append_variable(efi_guid_t guid, const char *name, const uint8_t *data, | |
int rc; | ||
if (!ops->append_variable) { | ||
rc = generic_append_variable(guid, name, data, data_size, | ||
attributes); | ||
attributes); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is irrelevant |
||
if (rc < 0) | ||
efi_error("generic_append_variable() failed"); | ||
else | ||
|
@@ -145,7 +155,7 @@ efi_get_variable(efi_guid_t guid, const char *name, uint8_t **data, | |
|
||
int NONNULL(2, 3) PUBLIC | ||
efi_get_variable_attributes(efi_guid_t guid, const char *name, | ||
uint32_t *attributes) | ||
uint32_t *attributes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so is this |
||
{ | ||
int rc; | ||
if (!ops->get_variable_attributes) { | ||
|
@@ -227,6 +237,76 @@ efi_variables_supported(void) | |
return 1; | ||
} | ||
|
||
static int | ||
get_esp_filename(char **esp_filename) | ||
{ | ||
char *dst_name = NULL; | ||
efi_guid_t dst_guid = efi_guid_empty; | ||
size_t filename_size; | ||
uint32_t filename_attr; | ||
uint8_t *filename = NULL; | ||
int rc = 0; | ||
|
||
efi_parse_name(EFI_RTSTORAGEVOLATILE, &dst_name, &dst_guid); | ||
|
||
if (dst_name && !efi_guid_is_empty(&dst_guid)) { | ||
rc = efi_get_variable(dst_guid, dst_name, &filename, &filename_size, &filename_attr); | ||
if (rc < 0) { | ||
fprintf(stderr, "efivar: Error %d getting filename from RTStorageVolatile\n", rc); | ||
return rc; | ||
} | ||
|
||
printf("efivar: RSTStorageVolatile found with %s\n", (char *)filename); | ||
} | ||
|
||
*esp_filename = (char *)filename; | ||
|
||
free(dst_name); | ||
|
||
return 0; | ||
} | ||
|
||
static void | ||
search_esp_filename(const char *filename, char *esp_filename) | ||
{ | ||
size_t num_paths = sizeof(esp_paths) / sizeof(esp_paths[0]); | ||
|
||
for (size_t i = 0; i < num_paths; ++i) { | ||
snprintf(esp_filename, PATH_SIZE, "%s/%s", esp_paths[i], filename); | ||
|
||
struct stat buffer; | ||
if (stat(esp_filename, &buffer) == 0) { | ||
return; | ||
} | ||
} | ||
|
||
esp_filename[0] = '\0'; | ||
} | ||
|
||
void PUBLIC | ||
efi_save_esp_filename(void) | ||
{ | ||
char esp_filename_path[PATH_SIZE]; | ||
char *esp_filename = NULL; | ||
int rc = 0; | ||
|
||
rc = get_esp_filename(&esp_filename); | ||
if (rc < 0 || !esp_filename) { | ||
goto cleanup; | ||
} | ||
|
||
search_esp_filename(esp_filename, esp_filename_path); | ||
if (esp_filename_path[0] != '\0') { | ||
printf("efivar: VarToFile content saved at %s\n", esp_filename_path); | ||
} | ||
else { | ||
fprintf(stderr, "efivar: no found file in ESP part to save VarToFile\n"); | ||
} | ||
|
||
cleanup: | ||
free(esp_filename); | ||
} | ||
|
||
static void CONSTRUCTOR libefivar_init(void); | ||
|
||
static void CONSTRUCTOR | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message needs to be clearer. It's usually not required to write a file.
Please use the u-boot commit message for guidance and write a proper one here.
Explain what u-boot is doing with these variables and why you need help from efivar & userspace tools to make the change permanent