Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 2 | /* |
| 3 | * EFI hello world |
| 4 | * |
| 5 | * Copyright (c) 2016 Google, Inc |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | * |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 8 | * This program demonstrates calling a boottime service. |
| 9 | * It writes a greeting and the load options to the console. |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 13 | #include <efi_api.h> |
| 14 | |
Alexander Graf | ae67dca | 2017-12-11 09:40:47 +0100 | [diff] [blame] | 15 | static const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID; |
Heinrich Schuchardt | 0aaabbb | 2018-01-19 20:24:42 +0100 | [diff] [blame] | 16 | static const efi_guid_t fdt_guid = EFI_FDT_GUID; |
Bin Meng | 47cae01 | 2018-06-27 20:38:04 -0700 | [diff] [blame] | 17 | static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID; |
Heinrich Schuchardt | 0aaabbb | 2018-01-19 20:24:42 +0100 | [diff] [blame] | 18 | static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID; |
| 19 | |
Heinrich Schuchardt | 87fc275 | 2018-09-24 23:53:51 +0200 | [diff] [blame] | 20 | /** |
Heinrich Schuchardt | 87fc275 | 2018-09-24 23:53:51 +0200 | [diff] [blame] | 21 | * efi_main() - entry point of the EFI application. |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 22 | * |
Heinrich Schuchardt | 87fc275 | 2018-09-24 23:53:51 +0200 | [diff] [blame] | 23 | * @handle: handle of the loaded image |
| 24 | * @systable: system table |
| 25 | * @return: status code |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 26 | */ |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 27 | efi_status_t EFIAPI efi_main(efi_handle_t handle, |
| 28 | struct efi_system_table *systable) |
| 29 | { |
| 30 | struct efi_simple_text_output_protocol *con_out = systable->con_out; |
| 31 | struct efi_boot_services *boottime = systable->boottime; |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 32 | struct efi_loaded_image *loaded_image; |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 33 | efi_status_t ret; |
Heinrich Schuchardt | 0aaabbb | 2018-01-19 20:24:42 +0100 | [diff] [blame] | 34 | efi_uintn_t i; |
Heinrich Schuchardt | f7c342f | 2018-02-05 18:24:26 +0100 | [diff] [blame] | 35 | u16 rev[] = L"0.0.0"; |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 36 | |
Heinrich Schuchardt | 87fc275 | 2018-09-24 23:53:51 +0200 | [diff] [blame] | 37 | /* UEFI requires CR LF */ |
| 38 | con_out->output_string(con_out, L"Hello, world!\r\n"); |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 39 | |
Heinrich Schuchardt | f7c342f | 2018-02-05 18:24:26 +0100 | [diff] [blame] | 40 | /* Print the revision number */ |
| 41 | rev[0] = (systable->hdr.revision >> 16) + '0'; |
| 42 | rev[4] = systable->hdr.revision & 0xffff; |
| 43 | for (; rev[4] >= 10;) { |
| 44 | rev[4] -= 10; |
| 45 | ++rev[2]; |
| 46 | } |
| 47 | /* Third digit is only to be shown if non-zero */ |
| 48 | if (rev[4]) |
| 49 | rev[4] += '0'; |
| 50 | else |
| 51 | rev[3] = 0; |
| 52 | |
| 53 | con_out->output_string(con_out, L"Running on UEFI "); |
| 54 | con_out->output_string(con_out, rev); |
Heinrich Schuchardt | 87fc275 | 2018-09-24 23:53:51 +0200 | [diff] [blame] | 55 | con_out->output_string(con_out, L"\r\n"); |
Heinrich Schuchardt | f7c342f | 2018-02-05 18:24:26 +0100 | [diff] [blame] | 56 | |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 57 | /* Get the loaded image protocol */ |
| 58 | ret = boottime->handle_protocol(handle, &loaded_image_guid, |
| 59 | (void **)&loaded_image); |
| 60 | if (ret != EFI_SUCCESS) { |
Heinrich Schuchardt | 87fc275 | 2018-09-24 23:53:51 +0200 | [diff] [blame] | 61 | con_out->output_string |
| 62 | (con_out, L"Cannot open loaded image protocol\r\n"); |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 63 | goto out; |
| 64 | } |
Heinrich Schuchardt | 0aaabbb | 2018-01-19 20:24:42 +0100 | [diff] [blame] | 65 | /* Find configuration tables */ |
| 66 | for (i = 0; i < systable->nr_tables; ++i) { |
Heinrich Schuchardt | 6446304 | 2019-01-20 08:20:32 +0100 | [diff] [blame] | 67 | if (!memcmp(&systable->tables[i].guid, &fdt_guid, |
| 68 | sizeof(efi_guid_t))) |
Heinrich Schuchardt | 87fc275 | 2018-09-24 23:53:51 +0200 | [diff] [blame] | 69 | con_out->output_string |
| 70 | (con_out, L"Have device tree\r\n"); |
Heinrich Schuchardt | 6446304 | 2019-01-20 08:20:32 +0100 | [diff] [blame] | 71 | if (!memcmp(&systable->tables[i].guid, &acpi_guid, |
| 72 | sizeof(efi_guid_t))) |
Heinrich Schuchardt | 87fc275 | 2018-09-24 23:53:51 +0200 | [diff] [blame] | 73 | con_out->output_string |
| 74 | (con_out, L"Have ACPI 2.0 table\r\n"); |
Heinrich Schuchardt | 6446304 | 2019-01-20 08:20:32 +0100 | [diff] [blame] | 75 | if (!memcmp(&systable->tables[i].guid, &smbios_guid, |
| 76 | sizeof(efi_guid_t))) |
Heinrich Schuchardt | 87fc275 | 2018-09-24 23:53:51 +0200 | [diff] [blame] | 77 | con_out->output_string |
| 78 | (con_out, L"Have SMBIOS table\r\n"); |
Heinrich Schuchardt | 0aaabbb | 2018-01-19 20:24:42 +0100 | [diff] [blame] | 79 | } |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 80 | /* Output the load options */ |
| 81 | con_out->output_string(con_out, L"Load options: "); |
| 82 | if (loaded_image->load_options_size && loaded_image->load_options) |
| 83 | con_out->output_string(con_out, |
| 84 | (u16 *)loaded_image->load_options); |
| 85 | else |
| 86 | con_out->output_string(con_out, L"<none>"); |
Heinrich Schuchardt | 87fc275 | 2018-09-24 23:53:51 +0200 | [diff] [blame] | 87 | con_out->output_string(con_out, L"\r\n"); |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 88 | |
| 89 | out: |
| 90 | boottime->exit(handle, ret, 0, NULL); |
| 91 | |
| 92 | /* We should never arrive here */ |
| 93 | return ret; |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 94 | } |