183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2c7ae3dfdSSimon Glass /*
3c7ae3dfdSSimon Glass * EFI hello world
4c7ae3dfdSSimon Glass *
5c7ae3dfdSSimon Glass * Copyright (c) 2016 Google, Inc
6c7ae3dfdSSimon Glass * Written by Simon Glass <sjg@chromium.org>
7c7ae3dfdSSimon Glass *
8bbf75dd9SHeinrich Schuchardt * This program demonstrates calling a boottime service.
9bbf75dd9SHeinrich Schuchardt * It writes a greeting and the load options to the console.
10c7ae3dfdSSimon Glass */
11c7ae3dfdSSimon Glass
12c7ae3dfdSSimon Glass #include <common.h>
13c7ae3dfdSSimon Glass #include <efi_api.h>
14c7ae3dfdSSimon Glass
15ae67dca5SAlexander Graf static const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
160aaabbb2SHeinrich Schuchardt static const efi_guid_t fdt_guid = EFI_FDT_GUID;
1747cae019SBin Meng static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
180aaabbb2SHeinrich Schuchardt static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
190aaabbb2SHeinrich Schuchardt
2087fc275cSHeinrich Schuchardt /**
2187fc275cSHeinrich Schuchardt * efi_main() - entry point of the EFI application.
22bbf75dd9SHeinrich Schuchardt *
2387fc275cSHeinrich Schuchardt * @handle: handle of the loaded image
2487fc275cSHeinrich Schuchardt * @systable: system table
2587fc275cSHeinrich Schuchardt * @return: status code
26bbf75dd9SHeinrich Schuchardt */
efi_main(efi_handle_t handle,struct efi_system_table * systable)27c7ae3dfdSSimon Glass efi_status_t EFIAPI efi_main(efi_handle_t handle,
28c7ae3dfdSSimon Glass struct efi_system_table *systable)
29c7ae3dfdSSimon Glass {
30c7ae3dfdSSimon Glass struct efi_simple_text_output_protocol *con_out = systable->con_out;
31c7ae3dfdSSimon Glass struct efi_boot_services *boottime = systable->boottime;
32bbf75dd9SHeinrich Schuchardt struct efi_loaded_image *loaded_image;
33bbf75dd9SHeinrich Schuchardt efi_status_t ret;
340aaabbb2SHeinrich Schuchardt efi_uintn_t i;
35f7c342f4SHeinrich Schuchardt u16 rev[] = L"0.0.0";
36c7ae3dfdSSimon Glass
3787fc275cSHeinrich Schuchardt /* UEFI requires CR LF */
3887fc275cSHeinrich Schuchardt con_out->output_string(con_out, L"Hello, world!\r\n");
39c7ae3dfdSSimon Glass
40f7c342f4SHeinrich Schuchardt /* Print the revision number */
41f7c342f4SHeinrich Schuchardt rev[0] = (systable->hdr.revision >> 16) + '0';
42f7c342f4SHeinrich Schuchardt rev[4] = systable->hdr.revision & 0xffff;
43f7c342f4SHeinrich Schuchardt for (; rev[4] >= 10;) {
44f7c342f4SHeinrich Schuchardt rev[4] -= 10;
45f7c342f4SHeinrich Schuchardt ++rev[2];
46f7c342f4SHeinrich Schuchardt }
47f7c342f4SHeinrich Schuchardt /* Third digit is only to be shown if non-zero */
48f7c342f4SHeinrich Schuchardt if (rev[4])
49f7c342f4SHeinrich Schuchardt rev[4] += '0';
50f7c342f4SHeinrich Schuchardt else
51f7c342f4SHeinrich Schuchardt rev[3] = 0;
52f7c342f4SHeinrich Schuchardt
53f7c342f4SHeinrich Schuchardt con_out->output_string(con_out, L"Running on UEFI ");
54f7c342f4SHeinrich Schuchardt con_out->output_string(con_out, rev);
5587fc275cSHeinrich Schuchardt con_out->output_string(con_out, L"\r\n");
56f7c342f4SHeinrich Schuchardt
57bbf75dd9SHeinrich Schuchardt /* Get the loaded image protocol */
58bbf75dd9SHeinrich Schuchardt ret = boottime->handle_protocol(handle, &loaded_image_guid,
59bbf75dd9SHeinrich Schuchardt (void **)&loaded_image);
60bbf75dd9SHeinrich Schuchardt if (ret != EFI_SUCCESS) {
6187fc275cSHeinrich Schuchardt con_out->output_string
6287fc275cSHeinrich Schuchardt (con_out, L"Cannot open loaded image protocol\r\n");
63bbf75dd9SHeinrich Schuchardt goto out;
64bbf75dd9SHeinrich Schuchardt }
650aaabbb2SHeinrich Schuchardt /* Find configuration tables */
660aaabbb2SHeinrich Schuchardt for (i = 0; i < systable->nr_tables; ++i) {
67*64463044SHeinrich Schuchardt if (!memcmp(&systable->tables[i].guid, &fdt_guid,
680aaabbb2SHeinrich Schuchardt sizeof(efi_guid_t)))
6987fc275cSHeinrich Schuchardt con_out->output_string
7087fc275cSHeinrich Schuchardt (con_out, L"Have device tree\r\n");
71*64463044SHeinrich Schuchardt if (!memcmp(&systable->tables[i].guid, &acpi_guid,
7247cae019SBin Meng sizeof(efi_guid_t)))
7387fc275cSHeinrich Schuchardt con_out->output_string
7487fc275cSHeinrich Schuchardt (con_out, L"Have ACPI 2.0 table\r\n");
75*64463044SHeinrich Schuchardt if (!memcmp(&systable->tables[i].guid, &smbios_guid,
760aaabbb2SHeinrich Schuchardt sizeof(efi_guid_t)))
7787fc275cSHeinrich Schuchardt con_out->output_string
7887fc275cSHeinrich Schuchardt (con_out, L"Have SMBIOS table\r\n");
790aaabbb2SHeinrich Schuchardt }
80bbf75dd9SHeinrich Schuchardt /* Output the load options */
81bbf75dd9SHeinrich Schuchardt con_out->output_string(con_out, L"Load options: ");
82bbf75dd9SHeinrich Schuchardt if (loaded_image->load_options_size && loaded_image->load_options)
83bbf75dd9SHeinrich Schuchardt con_out->output_string(con_out,
84bbf75dd9SHeinrich Schuchardt (u16 *)loaded_image->load_options);
85bbf75dd9SHeinrich Schuchardt else
86bbf75dd9SHeinrich Schuchardt con_out->output_string(con_out, L"<none>");
8787fc275cSHeinrich Schuchardt con_out->output_string(con_out, L"\r\n");
88bbf75dd9SHeinrich Schuchardt
89bbf75dd9SHeinrich Schuchardt out:
90bbf75dd9SHeinrich Schuchardt boottime->exit(handle, ret, 0, NULL);
91bbf75dd9SHeinrich Schuchardt
92bbf75dd9SHeinrich Schuchardt /* We should never arrive here */
93bbf75dd9SHeinrich Schuchardt return ret;
94c7ae3dfdSSimon Glass }
95