blob: 9ae2ee33898758bf02ac665bfbdbe8a5179cc774 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassc7ae3df2016-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 Schuchardtbbf75dd2017-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 Glassc7ae3df2016-11-07 08:47:08 -070010 */
11
12#include <common.h>
Simon Glassc7ae3df2016-11-07 08:47:08 -070013#include <efi_api.h>
14
Heinrich Schuchardtdec88e42019-04-20 07:39:11 +020015static const efi_guid_t loaded_image_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
Heinrich Schuchardt0aaabbb2018-01-19 20:24:42 +010016static const efi_guid_t fdt_guid = EFI_FDT_GUID;
Bin Meng47cae012018-06-27 20:38:04 -070017static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
Heinrich Schuchardt0aaabbb2018-01-19 20:24:42 +010018static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
19
Heinrich Schuchardt87fc2752018-09-24 23:53:51 +020020/**
Heinrich Schuchardt87fc2752018-09-24 23:53:51 +020021 * efi_main() - entry point of the EFI application.
Heinrich Schuchardtbbf75dd2017-11-26 14:05:20 +010022 *
Heinrich Schuchardt87fc2752018-09-24 23:53:51 +020023 * @handle: handle of the loaded image
24 * @systable: system table
25 * @return: status code
Heinrich Schuchardtbbf75dd2017-11-26 14:05:20 +010026 */
Simon Glassc7ae3df2016-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 Schuchardtbbf75dd2017-11-26 14:05:20 +010032 struct efi_loaded_image *loaded_image;
Heinrich Schuchardtbbf75dd2017-11-26 14:05:20 +010033 efi_status_t ret;
Heinrich Schuchardt0aaabbb2018-01-19 20:24:42 +010034 efi_uintn_t i;
Heinrich Schuchardtf7c342f2018-02-05 18:24:26 +010035 u16 rev[] = L"0.0.0";
Simon Glassc7ae3df2016-11-07 08:47:08 -070036
Heinrich Schuchardt87fc2752018-09-24 23:53:51 +020037 /* UEFI requires CR LF */
38 con_out->output_string(con_out, L"Hello, world!\r\n");
Simon Glassc7ae3df2016-11-07 08:47:08 -070039
Heinrich Schuchardtf7c342f2018-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 Schuchardt87fc2752018-09-24 23:53:51 +020055 con_out->output_string(con_out, L"\r\n");
Heinrich Schuchardtf7c342f2018-02-05 18:24:26 +010056
Heinrich Schuchardtbbf75dd2017-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 Schuchardt87fc2752018-09-24 23:53:51 +020061 con_out->output_string
62 (con_out, L"Cannot open loaded image protocol\r\n");
Heinrich Schuchardtbbf75dd2017-11-26 14:05:20 +010063 goto out;
64 }
Heinrich Schuchardt0aaabbb2018-01-19 20:24:42 +010065 /* Find configuration tables */
66 for (i = 0; i < systable->nr_tables; ++i) {
Heinrich Schuchardt64463042019-01-20 08:20:32 +010067 if (!memcmp(&systable->tables[i].guid, &fdt_guid,
68 sizeof(efi_guid_t)))
Heinrich Schuchardt87fc2752018-09-24 23:53:51 +020069 con_out->output_string
70 (con_out, L"Have device tree\r\n");
Heinrich Schuchardt64463042019-01-20 08:20:32 +010071 if (!memcmp(&systable->tables[i].guid, &acpi_guid,
72 sizeof(efi_guid_t)))
Heinrich Schuchardt87fc2752018-09-24 23:53:51 +020073 con_out->output_string
74 (con_out, L"Have ACPI 2.0 table\r\n");
Heinrich Schuchardt64463042019-01-20 08:20:32 +010075 if (!memcmp(&systable->tables[i].guid, &smbios_guid,
76 sizeof(efi_guid_t)))
Heinrich Schuchardt87fc2752018-09-24 23:53:51 +020077 con_out->output_string
78 (con_out, L"Have SMBIOS table\r\n");
Heinrich Schuchardt0aaabbb2018-01-19 20:24:42 +010079 }
Heinrich Schuchardtbbf75dd2017-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 Schuchardt87fc2752018-09-24 23:53:51 +020087 con_out->output_string(con_out, L"\r\n");
Heinrich Schuchardtbbf75dd2017-11-26 14:05:20 +010088
89out:
90 boottime->exit(handle, ret, 0, NULL);
91
92 /* We should never arrive here */
93 return ret;
Simon Glassc7ae3df2016-11-07 08:47:08 -070094}