AKASHI Takahiro | 7e0badb | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * EFI setup code |
| 4 | * |
| 5 | * Copyright (c) 2016-2018 Alexander Graf et al. |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <efi_loader.h> |
| 10 | |
| 11 | #define OBJ_LIST_NOT_INITIALIZED 1 |
| 12 | |
| 13 | static efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED; |
| 14 | |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 15 | /** |
| 16 | * efi_init_platform_lang() - define supported languages |
| 17 | * |
| 18 | * Set the PlatformLangCodes and PlatformLang variables. |
| 19 | * |
| 20 | * Return: status code |
| 21 | */ |
| 22 | static efi_status_t efi_init_platform_lang(void) |
AKASHI Takahiro | 7e0badb | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 23 | { |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 24 | efi_status_t ret; |
| 25 | efi_uintn_t data_size = 0; |
| 26 | char *lang = CONFIG_EFI_PLATFORM_LANG_CODES; |
| 27 | char *pos; |
AKASHI Takahiro | 7e0badb | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 28 | |
| 29 | /* |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 30 | * Variable PlatformLangCodes defines the language codes that the |
| 31 | * machine can support. |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 32 | */ |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 33 | ret = EFI_CALL(efi_set_variable(L"PlatformLangCodes", |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 34 | &efi_global_variable_guid, |
| 35 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 36 | EFI_VARIABLE_RUNTIME_ACCESS, |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 37 | sizeof(CONFIG_EFI_PLATFORM_LANG_CODES), |
| 38 | CONFIG_EFI_PLATFORM_LANG_CODES)); |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 39 | if (ret != EFI_SUCCESS) |
| 40 | goto out; |
| 41 | |
| 42 | /* |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 43 | * Variable PlatformLang defines the language that the machine has been |
| 44 | * configured for. |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 45 | */ |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 46 | ret = EFI_CALL(efi_get_variable(L"PlatformLang", |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 47 | &efi_global_variable_guid, |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 48 | NULL, &data_size, &pos)); |
| 49 | if (ret == EFI_BUFFER_TOO_SMALL) { |
| 50 | /* The variable is already set. Do not change it. */ |
| 51 | ret = EFI_SUCCESS; |
| 52 | goto out; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * The list of supported languages is semicolon separated. Use the first |
| 57 | * language to initialize PlatformLang. |
| 58 | */ |
| 59 | pos = strchr(lang, ';'); |
| 60 | if (pos) |
| 61 | *pos = 0; |
| 62 | |
| 63 | ret = EFI_CALL(efi_set_variable(L"PlatformLang", |
| 64 | &efi_global_variable_guid, |
| 65 | EFI_VARIABLE_NON_VOLATILE | |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 66 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 67 | EFI_VARIABLE_RUNTIME_ACCESS, |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 68 | 1 + strlen(lang), lang)); |
| 69 | out: |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 70 | if (ret != EFI_SUCCESS) |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 71 | printf("EFI: cannot initialize platform language settings\n"); |
| 72 | return ret; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * efi_init_obj_list() - Initialize and populate EFI object list |
| 77 | * |
| 78 | * Return: status code |
| 79 | */ |
| 80 | efi_status_t efi_init_obj_list(void) |
| 81 | { |
| 82 | efi_status_t ret = EFI_SUCCESS; |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 83 | |
AKASHI Takahiro | 7e0badb | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 84 | /* Initialize once only */ |
| 85 | if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) |
| 86 | return efi_obj_list_initialized; |
| 87 | |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 88 | /* Define supported languages */ |
| 89 | ret = efi_init_platform_lang(); |
| 90 | if (ret != EFI_SUCCESS) |
| 91 | goto out; |
| 92 | |
AKASHI Takahiro | 7e0badb | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 93 | /* Initialize system table */ |
| 94 | ret = efi_initialize_system_table(); |
| 95 | if (ret != EFI_SUCCESS) |
| 96 | goto out; |
| 97 | |
| 98 | /* Initialize root node */ |
| 99 | ret = efi_root_node_register(); |
| 100 | if (ret != EFI_SUCCESS) |
| 101 | goto out; |
| 102 | |
| 103 | /* Initialize EFI driver uclass */ |
| 104 | ret = efi_driver_init(); |
| 105 | if (ret != EFI_SUCCESS) |
| 106 | goto out; |
| 107 | |
| 108 | ret = efi_console_register(); |
| 109 | if (ret != EFI_SUCCESS) |
| 110 | goto out; |
| 111 | #ifdef CONFIG_PARTITIONS |
| 112 | ret = efi_disk_register(); |
| 113 | if (ret != EFI_SUCCESS) |
| 114 | goto out; |
| 115 | #endif |
| 116 | #if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO) |
| 117 | ret = efi_gop_register(); |
| 118 | if (ret != EFI_SUCCESS) |
| 119 | goto out; |
| 120 | #endif |
| 121 | #ifdef CONFIG_NET |
| 122 | ret = efi_net_register(); |
| 123 | if (ret != EFI_SUCCESS) |
| 124 | goto out; |
| 125 | #endif |
| 126 | #ifdef CONFIG_GENERATE_ACPI_TABLE |
| 127 | ret = efi_acpi_register(); |
| 128 | if (ret != EFI_SUCCESS) |
| 129 | goto out; |
| 130 | #endif |
| 131 | #ifdef CONFIG_GENERATE_SMBIOS_TABLE |
| 132 | ret = efi_smbios_register(); |
| 133 | if (ret != EFI_SUCCESS) |
| 134 | goto out; |
| 135 | #endif |
| 136 | ret = efi_watchdog_register(); |
| 137 | if (ret != EFI_SUCCESS) |
| 138 | goto out; |
| 139 | |
| 140 | /* Initialize EFI runtime services */ |
| 141 | ret = efi_reset_system_init(); |
| 142 | if (ret != EFI_SUCCESS) |
| 143 | goto out; |
| 144 | |
| 145 | out: |
| 146 | efi_obj_list_initialized = ret; |
| 147 | return ret; |
| 148 | } |