1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2016 Google, Inc
6 * Written by Simon Glass <sjg@chromium.org>
8 * This program demonstrates calling a boottime service.
9 * It writes a greeting and the load options to the console.
15 static const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
16 static const efi_guid_t fdt_guid = EFI_FDT_GUID;
17 static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
18 static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
21 * hw_memcmp() - compare memory areas
23 * @buf1: pointer to first area
24 * @buf2: pointer to second area
25 * @length: number of bytes to compare
26 * Return: 0 if both memory areas are the same, otherwise the sign of the
27 * result value is the same as the sign of ghe difference between
28 * the first differing pair of bytes taken as u8.
30 static int hw_memcmp(const void *buf1, const void *buf2, size_t length)
32 const u8 *pos1 = buf1;
33 const u8 *pos2 = buf2;
35 for (; length; --length) {
45 * efi_main() - entry point of the EFI application.
47 * @handle: handle of the loaded image
48 * @systable: system table
49 * @return: status code
51 efi_status_t EFIAPI efi_main(efi_handle_t handle,
52 struct efi_system_table *systable)
54 struct efi_simple_text_output_protocol *con_out = systable->con_out;
55 struct efi_boot_services *boottime = systable->boottime;
56 struct efi_loaded_image *loaded_image;
61 /* UEFI requires CR LF */
62 con_out->output_string(con_out, L"Hello, world!\r\n");
64 /* Print the revision number */
65 rev[0] = (systable->hdr.revision >> 16) + '0';
66 rev[4] = systable->hdr.revision & 0xffff;
67 for (; rev[4] >= 10;) {
71 /* Third digit is only to be shown if non-zero */
77 con_out->output_string(con_out, L"Running on UEFI ");
78 con_out->output_string(con_out, rev);
79 con_out->output_string(con_out, L"\r\n");
81 /* Get the loaded image protocol */
82 ret = boottime->handle_protocol(handle, &loaded_image_guid,
83 (void **)&loaded_image);
84 if (ret != EFI_SUCCESS) {
85 con_out->output_string
86 (con_out, L"Cannot open loaded image protocol\r\n");
89 /* Find configuration tables */
90 for (i = 0; i < systable->nr_tables; ++i) {
91 if (!hw_memcmp(&systable->tables[i].guid, &fdt_guid,
93 con_out->output_string
94 (con_out, L"Have device tree\r\n");
95 if (!hw_memcmp(&systable->tables[i].guid, &acpi_guid,
97 con_out->output_string
98 (con_out, L"Have ACPI 2.0 table\r\n");
99 if (!hw_memcmp(&systable->tables[i].guid, &smbios_guid,
101 con_out->output_string
102 (con_out, L"Have SMBIOS table\r\n");
104 /* Output the load options */
105 con_out->output_string(con_out, L"Load options: ");
106 if (loaded_image->load_options_size && loaded_image->load_options)
107 con_out->output_string(con_out,
108 (u16 *)loaded_image->load_options);
110 con_out->output_string(con_out, L"<none>");
111 con_out->output_string(con_out, L"\r\n");
114 boottime->exit(handle, ret, 0, NULL);
116 /* We should never arrive here */