efi_loader: reduce noisiness if ESP is missing

EFI variables can be stored in a file on the EFI system partition. If that
partition is missing we are writing two error messages per variable. This
is too noisy.

Just warn once about the missing ESP.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
This commit is contained in:
Heinrich Schuchardt
2024-10-18 03:18:36 +02:00
parent 3d23dedd92
commit bc4fe5666d

View File

@@ -37,18 +37,16 @@ static efi_status_t __maybe_unused efi_set_blk_dev_to_system_partition(void)
char part_str[PART_STR_LEN]; char part_str[PART_STR_LEN];
int r; int r;
if (efi_system_partition.uclass_id == UCLASS_INVALID) { if (efi_system_partition.uclass_id == UCLASS_INVALID)
log_err("No EFI system partition\n");
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
}
snprintf(part_str, PART_STR_LEN, "%x:%x", snprintf(part_str, PART_STR_LEN, "%x:%x",
efi_system_partition.devnum, efi_system_partition.part); efi_system_partition.devnum, efi_system_partition.part);
r = fs_set_blk_dev(blk_get_uclass_name(efi_system_partition.uclass_id), r = fs_set_blk_dev(blk_get_uclass_name(efi_system_partition.uclass_id),
part_str, FS_TYPE_ANY); part_str, FS_TYPE_ANY);
if (r) { if (r)
log_err("Cannot read EFI system partition\n");
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@@ -67,14 +65,21 @@ efi_status_t efi_var_to_file(void)
loff_t len; loff_t len;
loff_t actlen; loff_t actlen;
int r; int r;
static bool once;
ret = efi_var_collect(&buf, &len, EFI_VARIABLE_NON_VOLATILE); ret = efi_var_collect(&buf, &len, EFI_VARIABLE_NON_VOLATILE);
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
goto error; goto error;
ret = efi_set_blk_dev_to_system_partition(); ret = efi_set_blk_dev_to_system_partition();
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS) {
goto error; if (!once) {
log_warning("Cannot persist EFI variables without system partition\n");
once = true;
}
goto out;
}
once = false;
r = fs_write(EFI_VAR_FILE_NAME, map_to_sysmem(buf), 0, len, &actlen); r = fs_write(EFI_VAR_FILE_NAME, map_to_sysmem(buf), 0, len, &actlen);
if (r || len != actlen) if (r || len != actlen)
@@ -83,6 +88,7 @@ efi_status_t efi_var_to_file(void)
error: error:
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
log_err("Failed to persist EFI variables\n"); log_err("Failed to persist EFI variables\n");
out:
free(buf); free(buf);
return ret; return ret;
#else #else