Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * EFI hello world |
| 3 | * |
| 4 | * Copyright (c) 2016 Google, Inc |
| 5 | * Written by Simon Glass <sjg@chromium.org> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
Heinrich Schuchardt | 0864580 | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 8 | * |
| 9 | * This program demonstrates calling a boottime service. |
| 10 | * It writes a greeting and the load options to the console. |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 14 | #include <efi_api.h> |
| 15 | |
Alexander Graf | c28a947 | 2017-12-11 09:40:47 +0100 | [diff] [blame] | 16 | static const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID; |
Heinrich Schuchardt | 5a77152 | 2018-01-19 20:24:42 +0100 | [diff] [blame] | 17 | static const efi_guid_t fdt_guid = EFI_FDT_GUID; |
| 18 | static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID; |
| 19 | |
| 20 | static int hw_memcmp(const void *buf1, const void *buf2, size_t length) |
| 21 | { |
| 22 | const u8 *pos1 = buf1; |
| 23 | const u8 *pos2 = buf2; |
| 24 | |
| 25 | for (; length; --length) { |
| 26 | if (*pos1 != *pos2) |
| 27 | return *pos1 - *pos2; |
| 28 | ++pos1; |
| 29 | ++pos2; |
| 30 | } |
| 31 | return 0; |
| 32 | } |
Alexander Graf | c28a947 | 2017-12-11 09:40:47 +0100 | [diff] [blame] | 33 | |
Heinrich Schuchardt | 0864580 | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 34 | /* |
| 35 | * Entry point of the EFI application. |
| 36 | * |
| 37 | * @handle handle of the loaded image |
| 38 | * @systable system table |
| 39 | * @return status code |
| 40 | */ |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 41 | efi_status_t EFIAPI efi_main(efi_handle_t handle, |
| 42 | struct efi_system_table *systable) |
| 43 | { |
| 44 | struct efi_simple_text_output_protocol *con_out = systable->con_out; |
| 45 | struct efi_boot_services *boottime = systable->boottime; |
Heinrich Schuchardt | 0864580 | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 46 | struct efi_loaded_image *loaded_image; |
Heinrich Schuchardt | 0864580 | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 47 | efi_status_t ret; |
Heinrich Schuchardt | 5a77152 | 2018-01-19 20:24:42 +0100 | [diff] [blame] | 48 | efi_uintn_t i; |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 49 | |
| 50 | con_out->output_string(con_out, L"Hello, world!\n"); |
Heinrich Schuchardt | 0864580 | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 51 | |
| 52 | /* Get the loaded image protocol */ |
| 53 | ret = boottime->handle_protocol(handle, &loaded_image_guid, |
| 54 | (void **)&loaded_image); |
| 55 | if (ret != EFI_SUCCESS) { |
| 56 | con_out->output_string(con_out, |
| 57 | L"Cannot open loaded image protocol\n"); |
| 58 | goto out; |
| 59 | } |
Heinrich Schuchardt | 5a77152 | 2018-01-19 20:24:42 +0100 | [diff] [blame] | 60 | /* Find configuration tables */ |
| 61 | for (i = 0; i < systable->nr_tables; ++i) { |
| 62 | if (!hw_memcmp(&systable->tables[i].guid, &fdt_guid, |
| 63 | sizeof(efi_guid_t))) |
| 64 | con_out->output_string(con_out, L"Have device tree\n"); |
| 65 | if (!hw_memcmp(&systable->tables[i].guid, &smbios_guid, |
| 66 | sizeof(efi_guid_t))) |
| 67 | con_out->output_string(con_out, L"Have SMBIOS table\n"); |
| 68 | } |
Heinrich Schuchardt | 0864580 | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 69 | /* Output the load options */ |
| 70 | con_out->output_string(con_out, L"Load options: "); |
| 71 | if (loaded_image->load_options_size && loaded_image->load_options) |
| 72 | con_out->output_string(con_out, |
| 73 | (u16 *)loaded_image->load_options); |
| 74 | else |
| 75 | con_out->output_string(con_out, L"<none>"); |
| 76 | con_out->output_string(con_out, L"\n"); |
| 77 | |
| 78 | out: |
| 79 | boottime->exit(handle, ret, 0, NULL); |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 80 | |
Heinrich Schuchardt | 0864580 | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 81 | /* We should never arrive here */ |
| 82 | return ret; |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 83 | } |