efi_loader: move efi_init_obj_list() to a new efi_setup.c
The function, efi_init_obj_list(), can be shared in different pseudo efi
applications, like bootefi/bootmgr as well as my efishell. Moreover, it
will be utilized to extend efi initialization, for example, my "removable
disk support" patch and "capsule-on-disk support" patch in the future.
So with this patch, it will be moved to a new file, efi_setup.c, under
lib/efi_loader and exported, making no changes in functionality.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Remove lines deactivated by #if 1 #else
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2018-12-30 23:16:55 +09:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* EFI setup code
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016-2018 Alexander Graf et al.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-05-04 18:47:48 +09:00
|
|
|
#include <bootm.h>
|
efi_loader: move efi_init_obj_list() to a new efi_setup.c
The function, efi_init_obj_list(), can be shared in different pseudo efi
applications, like bootefi/bootmgr as well as my efishell. Moreover, it
will be utilized to extend efi initialization, for example, my "removable
disk support" patch and "capsule-on-disk support" patch in the future.
So with this patch, it will be moved to a new file, efi_setup.c, under
lib/efi_loader and exported, making no changes in functionality.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Remove lines deactivated by #if 1 #else
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2018-12-30 23:16:55 +09:00
|
|
|
#include <efi_loader.h>
|
|
|
|
|
|
|
|
#define OBJ_LIST_NOT_INITIALIZED 1
|
|
|
|
|
|
|
|
static efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED;
|
|
|
|
|
2019-05-04 18:47:48 +09:00
|
|
|
/*
|
|
|
|
* Allow unaligned memory access.
|
|
|
|
*
|
|
|
|
* This routine is overridden by architectures providing this feature.
|
|
|
|
*/
|
|
|
|
void __weak allow_unaligned(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-11 14:34:24 +09:00
|
|
|
/**
|
|
|
|
* efi_init_platform_lang() - define supported languages
|
|
|
|
*
|
|
|
|
* Set the PlatformLangCodes and PlatformLang variables.
|
|
|
|
*
|
|
|
|
* Return: status code
|
|
|
|
*/
|
|
|
|
static efi_status_t efi_init_platform_lang(void)
|
efi_loader: move efi_init_obj_list() to a new efi_setup.c
The function, efi_init_obj_list(), can be shared in different pseudo efi
applications, like bootefi/bootmgr as well as my efishell. Moreover, it
will be utilized to extend efi initialization, for example, my "removable
disk support" patch and "capsule-on-disk support" patch in the future.
So with this patch, it will be moved to a new file, efi_setup.c, under
lib/efi_loader and exported, making no changes in functionality.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Remove lines deactivated by #if 1 #else
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2018-12-30 23:16:55 +09:00
|
|
|
{
|
2019-04-11 14:34:24 +09:00
|
|
|
efi_status_t ret;
|
|
|
|
efi_uintn_t data_size = 0;
|
|
|
|
char *lang = CONFIG_EFI_PLATFORM_LANG_CODES;
|
|
|
|
char *pos;
|
efi_loader: move efi_init_obj_list() to a new efi_setup.c
The function, efi_init_obj_list(), can be shared in different pseudo efi
applications, like bootefi/bootmgr as well as my efishell. Moreover, it
will be utilized to extend efi initialization, for example, my "removable
disk support" patch and "capsule-on-disk support" patch in the future.
So with this patch, it will be moved to a new file, efi_setup.c, under
lib/efi_loader and exported, making no changes in functionality.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Remove lines deactivated by #if 1 #else
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2018-12-30 23:16:55 +09:00
|
|
|
|
2019-04-05 09:45:21 +09:00
|
|
|
/*
|
2019-04-11 14:34:24 +09:00
|
|
|
* Variable PlatformLangCodes defines the language codes that the
|
|
|
|
* machine can support.
|
2019-04-05 09:45:21 +09:00
|
|
|
*/
|
2019-04-11 14:34:24 +09:00
|
|
|
ret = EFI_CALL(efi_set_variable(L"PlatformLangCodes",
|
2019-04-05 09:45:21 +09:00
|
|
|
&efi_global_variable_guid,
|
|
|
|
EFI_VARIABLE_BOOTSERVICE_ACCESS |
|
|
|
|
EFI_VARIABLE_RUNTIME_ACCESS,
|
2019-04-11 14:34:24 +09:00
|
|
|
sizeof(CONFIG_EFI_PLATFORM_LANG_CODES),
|
|
|
|
CONFIG_EFI_PLATFORM_LANG_CODES));
|
2019-04-05 09:45:21 +09:00
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
2019-04-11 14:34:24 +09:00
|
|
|
* Variable PlatformLang defines the language that the machine has been
|
|
|
|
* configured for.
|
2019-04-05 09:45:21 +09:00
|
|
|
*/
|
2019-04-11 14:34:24 +09:00
|
|
|
ret = EFI_CALL(efi_get_variable(L"PlatformLang",
|
2019-04-05 09:45:21 +09:00
|
|
|
&efi_global_variable_guid,
|
2019-04-11 14:34:24 +09:00
|
|
|
NULL, &data_size, &pos));
|
|
|
|
if (ret == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
/* The variable is already set. Do not change it. */
|
|
|
|
ret = EFI_SUCCESS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The list of supported languages is semicolon separated. Use the first
|
|
|
|
* language to initialize PlatformLang.
|
|
|
|
*/
|
|
|
|
pos = strchr(lang, ';');
|
|
|
|
if (pos)
|
|
|
|
*pos = 0;
|
|
|
|
|
|
|
|
ret = EFI_CALL(efi_set_variable(L"PlatformLang",
|
|
|
|
&efi_global_variable_guid,
|
|
|
|
EFI_VARIABLE_NON_VOLATILE |
|
2019-04-05 09:45:21 +09:00
|
|
|
EFI_VARIABLE_BOOTSERVICE_ACCESS |
|
|
|
|
EFI_VARIABLE_RUNTIME_ACCESS,
|
2019-04-11 14:34:24 +09:00
|
|
|
1 + strlen(lang), lang));
|
|
|
|
out:
|
2019-04-05 09:45:21 +09:00
|
|
|
if (ret != EFI_SUCCESS)
|
2019-04-11 14:34:24 +09:00
|
|
|
printf("EFI: cannot initialize platform language settings\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-14 11:51:45 +09:00
|
|
|
#ifdef CONFIG_EFI_SECURE_BOOT
|
|
|
|
/**
|
|
|
|
* efi_init_secure_boot - initialize secure boot state
|
|
|
|
*
|
2020-05-03 23:29:00 +09:00
|
|
|
* Return: status code
|
2020-04-14 11:51:45 +09:00
|
|
|
*/
|
|
|
|
static efi_status_t efi_init_secure_boot(void)
|
|
|
|
{
|
|
|
|
efi_guid_t signature_types[] = {
|
|
|
|
EFI_CERT_SHA256_GUID,
|
|
|
|
EFI_CERT_X509_GUID,
|
|
|
|
};
|
|
|
|
efi_status_t ret;
|
|
|
|
|
|
|
|
/* TODO: read-only */
|
|
|
|
ret = EFI_CALL(efi_set_variable(L"SignatureSupport",
|
|
|
|
&efi_global_variable_guid,
|
|
|
|
EFI_VARIABLE_BOOTSERVICE_ACCESS
|
|
|
|
| EFI_VARIABLE_RUNTIME_ACCESS,
|
|
|
|
sizeof(signature_types),
|
|
|
|
&signature_types));
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
printf("EFI: cannot initialize SignatureSupport variable\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static efi_status_t efi_init_secure_boot(void)
|
|
|
|
{
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_EFI_SECURE_BOOT */
|
|
|
|
|
2019-04-11 14:34:24 +09:00
|
|
|
/**
|
|
|
|
* efi_init_obj_list() - Initialize and populate EFI object list
|
|
|
|
*
|
|
|
|
* Return: status code
|
|
|
|
*/
|
|
|
|
efi_status_t efi_init_obj_list(void)
|
|
|
|
{
|
2019-04-24 15:30:38 +09:00
|
|
|
u64 os_indications_supported = 0; /* None */
|
2019-04-11 14:34:24 +09:00
|
|
|
efi_status_t ret = EFI_SUCCESS;
|
2019-04-05 09:45:21 +09:00
|
|
|
|
efi_loader: move efi_init_obj_list() to a new efi_setup.c
The function, efi_init_obj_list(), can be shared in different pseudo efi
applications, like bootefi/bootmgr as well as my efishell. Moreover, it
will be utilized to extend efi initialization, for example, my "removable
disk support" patch and "capsule-on-disk support" patch in the future.
So with this patch, it will be moved to a new file, efi_setup.c, under
lib/efi_loader and exported, making no changes in functionality.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Remove lines deactivated by #if 1 #else
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2018-12-30 23:16:55 +09:00
|
|
|
/* Initialize once only */
|
|
|
|
if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED)
|
|
|
|
return efi_obj_list_initialized;
|
|
|
|
|
2019-05-04 18:47:48 +09:00
|
|
|
/* Allow unaligned memory access */
|
|
|
|
allow_unaligned();
|
|
|
|
|
|
|
|
/* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */
|
|
|
|
switch_to_non_secure_mode();
|
|
|
|
|
2020-05-21 04:27:29 +09:00
|
|
|
/* Initialize root node */
|
|
|
|
ret = efi_root_node_register();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
2020-03-20 03:21:58 +09:00
|
|
|
#ifdef CONFIG_PARTITIONS
|
|
|
|
ret = efi_disk_register();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
#endif
|
2019-06-20 20:52:16 +09:00
|
|
|
/* Initialize variable services */
|
|
|
|
ret = efi_init_variables();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
2019-04-11 14:34:24 +09:00
|
|
|
/* Define supported languages */
|
|
|
|
ret = efi_init_platform_lang();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
2019-04-24 15:30:38 +09:00
|
|
|
/* Indicate supported features */
|
|
|
|
ret = EFI_CALL(efi_set_variable(L"OsIndicationsSupported",
|
|
|
|
&efi_global_variable_guid,
|
|
|
|
EFI_VARIABLE_BOOTSERVICE_ACCESS |
|
|
|
|
EFI_VARIABLE_RUNTIME_ACCESS,
|
|
|
|
sizeof(os_indications_supported),
|
|
|
|
&os_indications_supported));
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
2020-02-20 04:48:49 +09:00
|
|
|
/* Initialize system table */
|
|
|
|
ret = efi_initialize_system_table();
|
2019-06-05 13:21:38 +09:00
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
2020-04-14 11:51:45 +09:00
|
|
|
/* Secure boot */
|
|
|
|
ret = efi_init_secure_boot();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
2020-02-20 04:48:49 +09:00
|
|
|
/* Indicate supported runtime services */
|
|
|
|
ret = efi_init_runtime_supported();
|
efi_loader: move efi_init_obj_list() to a new efi_setup.c
The function, efi_init_obj_list(), can be shared in different pseudo efi
applications, like bootefi/bootmgr as well as my efishell. Moreover, it
will be utilized to extend efi initialization, for example, my "removable
disk support" patch and "capsule-on-disk support" patch in the future.
So with this patch, it will be moved to a new file, efi_setup.c, under
lib/efi_loader and exported, making no changes in functionality.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Remove lines deactivated by #if 1 #else
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2018-12-30 23:16:55 +09:00
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Initialize EFI driver uclass */
|
|
|
|
ret = efi_driver_init();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = efi_console_register();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
#if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO)
|
|
|
|
ret = efi_gop_register();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
#endif
|
2020-02-21 16:55:45 +09:00
|
|
|
#ifdef CONFIG_EFI_LOAD_FILE2_INITRD
|
|
|
|
ret = efi_initrd_register();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
#endif
|
efi_loader: move efi_init_obj_list() to a new efi_setup.c
The function, efi_init_obj_list(), can be shared in different pseudo efi
applications, like bootefi/bootmgr as well as my efishell. Moreover, it
will be utilized to extend efi initialization, for example, my "removable
disk support" patch and "capsule-on-disk support" patch in the future.
So with this patch, it will be moved to a new file, efi_setup.c, under
lib/efi_loader and exported, making no changes in functionality.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Remove lines deactivated by #if 1 #else
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2018-12-30 23:16:55 +09:00
|
|
|
#ifdef CONFIG_NET
|
|
|
|
ret = efi_net_register();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_GENERATE_ACPI_TABLE
|
|
|
|
ret = efi_acpi_register();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_GENERATE_SMBIOS_TABLE
|
|
|
|
ret = efi_smbios_register();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
#endif
|
|
|
|
ret = efi_watchdog_register();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Initialize EFI runtime services */
|
|
|
|
ret = efi_reset_system_init();
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out:
|
|
|
|
efi_obj_list_initialized = ret;
|
|
|
|
return ret;
|
|
|
|
}
|