blob: 3b8de5b4ea76b1d39eaaaad2d7d8ded30d0972bc [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
20static 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 Grafc28a9472017-12-11 09:40:47 +010033
Heinrich Schuchardt08645802017-11-26 14:05:20 +010034/*
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 Glassfac4ced2016-11-07 08:47:08 -070041efi_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 Schuchardt08645802017-11-26 14:05:20 +010046 struct efi_loaded_image *loaded_image;
Heinrich Schuchardt08645802017-11-26 14:05:20 +010047 efi_status_t ret;
Heinrich Schuchardt5a771522018-01-19 20:24:42 +010048 efi_uintn_t i;
Heinrich Schuchardta0a61dd2018-02-05 18:24:26 +010049 u16 rev[] = L"0.0.0";
Simon Glassfac4ced2016-11-07 08:47:08 -070050
51 con_out->output_string(con_out, L"Hello, world!\n");
Heinrich Schuchardt08645802017-11-26 14:05:20 +010052
Heinrich Schuchardta0a61dd2018-02-05 18:24:26 +010053 /* Print the revision number */
54 rev[0] = (systable->hdr.revision >> 16) + '0';
55 rev[4] = systable->hdr.revision & 0xffff;
56 for (; rev[4] >= 10;) {
57 rev[4] -= 10;
58 ++rev[2];
59 }
60 /* Third digit is only to be shown if non-zero */
61 if (rev[4])
62 rev[4] += '0';
63 else
64 rev[3] = 0;
65
66 con_out->output_string(con_out, L"Running on UEFI ");
67 con_out->output_string(con_out, rev);
68 con_out->output_string(con_out, L"\n");
69
Heinrich Schuchardt08645802017-11-26 14:05:20 +010070 /* Get the loaded image protocol */
71 ret = boottime->handle_protocol(handle, &loaded_image_guid,
72 (void **)&loaded_image);
73 if (ret != EFI_SUCCESS) {
74 con_out->output_string(con_out,
75 L"Cannot open loaded image protocol\n");
76 goto out;
77 }
Heinrich Schuchardt5a771522018-01-19 20:24:42 +010078 /* Find configuration tables */
79 for (i = 0; i < systable->nr_tables; ++i) {
80 if (!hw_memcmp(&systable->tables[i].guid, &fdt_guid,
81 sizeof(efi_guid_t)))
82 con_out->output_string(con_out, L"Have device tree\n");
Bin Meng8e943292018-06-27 20:38:04 -070083 if (!hw_memcmp(&systable->tables[i].guid, &acpi_guid,
84 sizeof(efi_guid_t)))
85 con_out->output_string(con_out, L"Have ACPI 2.0 table\n");
Heinrich Schuchardt5a771522018-01-19 20:24:42 +010086 if (!hw_memcmp(&systable->tables[i].guid, &smbios_guid,
87 sizeof(efi_guid_t)))
88 con_out->output_string(con_out, L"Have SMBIOS table\n");
89 }
Heinrich Schuchardt08645802017-11-26 14:05:20 +010090 /* Output the load options */
91 con_out->output_string(con_out, L"Load options: ");
92 if (loaded_image->load_options_size && loaded_image->load_options)
93 con_out->output_string(con_out,
94 (u16 *)loaded_image->load_options);
95 else
96 con_out->output_string(con_out, L"<none>");
97 con_out->output_string(con_out, L"\n");
98
99out:
100 boottime->exit(handle, ret, 0, NULL);
Simon Glassfac4ced2016-11-07 08:47:08 -0700101
Heinrich Schuchardt08645802017-11-26 14:05:20 +0100102 /* We should never arrive here */
103 return ret;
Simon Glassfac4ced2016-11-07 08:47:08 -0700104}