Simon Glass | c7ae3df | 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 | bbf75dd | 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 | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 14 | #include <efi_api.h> |
| 15 | |
Alexander Graf | ae67dca | 2017-12-11 09:40:47 +0100 | [diff] [blame^] | 16 | static const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID; |
| 17 | |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 18 | /* |
| 19 | * Entry point of the EFI application. |
| 20 | * |
| 21 | * @handle handle of the loaded image |
| 22 | * @systable system table |
| 23 | * @return status code |
| 24 | */ |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 25 | efi_status_t EFIAPI efi_main(efi_handle_t handle, |
| 26 | struct efi_system_table *systable) |
| 27 | { |
| 28 | struct efi_simple_text_output_protocol *con_out = systable->con_out; |
| 29 | struct efi_boot_services *boottime = systable->boottime; |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 30 | struct efi_loaded_image *loaded_image; |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 31 | efi_status_t ret; |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 32 | |
| 33 | con_out->output_string(con_out, L"Hello, world!\n"); |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 34 | |
Heinrich Schuchardt | bbf75dd | 2017-11-26 14:05:20 +0100 | [diff] [blame] | 35 | /* Get the loaded image protocol */ |
| 36 | ret = boottime->handle_protocol(handle, &loaded_image_guid, |
| 37 | (void **)&loaded_image); |
| 38 | if (ret != EFI_SUCCESS) { |
| 39 | con_out->output_string(con_out, |
| 40 | L"Cannot open loaded image protocol\n"); |
| 41 | goto out; |
| 42 | } |
| 43 | /* Output the load options */ |
| 44 | con_out->output_string(con_out, L"Load options: "); |
| 45 | if (loaded_image->load_options_size && loaded_image->load_options) |
| 46 | con_out->output_string(con_out, |
| 47 | (u16 *)loaded_image->load_options); |
| 48 | else |
| 49 | con_out->output_string(con_out, L"<none>"); |
| 50 | con_out->output_string(con_out, L"\n"); |
| 51 | |
| 52 | out: |
| 53 | boottime->exit(handle, ret, 0, NULL); |
| 54 | |
| 55 | /* We should never arrive here */ |
| 56 | return ret; |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 57 | } |