blob: 426f276361a6020f424ab30c9095005e31495d25 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassfac4ced2016-11-07 08:47:08 -07002/*
3 * EFI hello world
4 *
5 * Copyright (c) 2016 Google, Inc
6 * Written by Simon Glass <sjg@chromium.org>
7 *
Heinrich Schuchardt08645802017-11-26 14:05:20 +01008 * This program demonstrates calling a boottime service.
9 * It writes a greeting and the load options to the console.
Simon Glassfac4ced2016-11-07 08:47:08 -070010 */
11
12#include <common.h>
Simon Glassfac4ced2016-11-07 08:47:08 -070013#include <efi_api.h>
14
Alexander Grafc28a9472017-12-11 09:40:47 +010015static const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
Heinrich Schuchardt5a771522018-01-19 20:24:42 +010016static const efi_guid_t fdt_guid = EFI_FDT_GUID;
Bin Meng8e943292018-06-27 20:38:04 -070017static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
Heinrich Schuchardt5a771522018-01-19 20:24:42 +010018static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
19
Heinrich Schuchardt5b669d82018-09-24 23:53:51 +020020/**
Heinrich Schuchardt5b669d82018-09-24 23:53:51 +020021 * efi_main() - entry point of the EFI application.
Heinrich Schuchardt08645802017-11-26 14:05:20 +010022 *
Heinrich Schuchardt5b669d82018-09-24 23:53:51 +020023 * @handle: handle of the loaded image
24 * @systable: system table
25 * @return: status code
Heinrich Schuchardt08645802017-11-26 14:05:20 +010026 */
Simon Glassfac4ced2016-11-07 08:47:08 -070027efi_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 Schuchardt08645802017-11-26 14:05:20 +010032 struct efi_loaded_image *loaded_image;
Heinrich Schuchardt08645802017-11-26 14:05:20 +010033 efi_status_t ret;
Heinrich Schuchardt5a771522018-01-19 20:24:42 +010034 efi_uintn_t i;
Heinrich Schuchardta0a61dd2018-02-05 18:24:26 +010035 u16 rev[] = L"0.0.0";
Simon Glassfac4ced2016-11-07 08:47:08 -070036
Heinrich Schuchardt5b669d82018-09-24 23:53:51 +020037 /* UEFI requires CR LF */
38 con_out->output_string(con_out, L"Hello, world!\r\n");
Heinrich Schuchardt08645802017-11-26 14:05:20 +010039
Heinrich Schuchardta0a61dd2018-02-05 18:24:26 +010040 /* 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 Schuchardt5b669d82018-09-24 23:53:51 +020055 con_out->output_string(con_out, L"\r\n");
Heinrich Schuchardta0a61dd2018-02-05 18:24:26 +010056
Heinrich Schuchardt08645802017-11-26 14:05:20 +010057 /* Get the loaded image protocol */
58 ret = boottime->handle_protocol(handle, &loaded_image_guid,
59 (void **)&loaded_image);
60 if (ret != EFI_SUCCESS) {
Heinrich Schuchardt5b669d82018-09-24 23:53:51 +020061 con_out->output_string
62 (con_out, L"Cannot open loaded image protocol\r\n");
Heinrich Schuchardt08645802017-11-26 14:05:20 +010063 goto out;
64 }
Heinrich Schuchardt5a771522018-01-19 20:24:42 +010065 /* Find configuration tables */
66 for (i = 0; i < systable->nr_tables; ++i) {
Heinrich Schuchardtb2b186c2019-01-20 08:20:32 +010067 if (!memcmp(&systable->tables[i].guid, &fdt_guid,
68 sizeof(efi_guid_t)))
Heinrich Schuchardt5b669d82018-09-24 23:53:51 +020069 con_out->output_string
70 (con_out, L"Have device tree\r\n");
Heinrich Schuchardtb2b186c2019-01-20 08:20:32 +010071 if (!memcmp(&systable->tables[i].guid, &acpi_guid,
72 sizeof(efi_guid_t)))
Heinrich Schuchardt5b669d82018-09-24 23:53:51 +020073 con_out->output_string
74 (con_out, L"Have ACPI 2.0 table\r\n");
Heinrich Schuchardtb2b186c2019-01-20 08:20:32 +010075 if (!memcmp(&systable->tables[i].guid, &smbios_guid,
76 sizeof(efi_guid_t)))
Heinrich Schuchardt5b669d82018-09-24 23:53:51 +020077 con_out->output_string
78 (con_out, L"Have SMBIOS table\r\n");
Heinrich Schuchardt5a771522018-01-19 20:24:42 +010079 }
Heinrich Schuchardt08645802017-11-26 14:05:20 +010080 /* 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 Schuchardt5b669d82018-09-24 23:53:51 +020087 con_out->output_string(con_out, L"\r\n");
Heinrich Schuchardt08645802017-11-26 14:05:20 +010088
89out:
90 boottime->exit(handle, ret, 0, NULL);
Simon Glassfac4ced2016-11-07 08:47:08 -070091
Heinrich Schuchardt08645802017-11-26 14:05:20 +010092 /* We should never arrive here */
93 return ret;
Simon Glassfac4ced2016-11-07 08:47:08 -070094}