4 * Copyright (c) 2016 Google, Inc
5 * Written by Simon Glass <sjg@chromium.org>
7 * SPDX-License-Identifier: GPL-2.0+
9 * This program demonstrates calling a boottime service.
10 * It writes a greeting and the load options to the console.
16 static const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
17 static const efi_guid_t fdt_guid = EFI_FDT_GUID;
18 static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
20 static int hw_memcmp(const void *buf1, const void *buf2, size_t length)
22 const u8 *pos1 = buf1;
23 const u8 *pos2 = buf2;
25 for (; length; --length) {
35 * Entry point of the EFI application.
37 * @handle handle of the loaded image
38 * @systable system table
41 efi_status_t EFIAPI efi_main(efi_handle_t handle,
42 struct efi_system_table *systable)
44 struct efi_simple_text_output_protocol *con_out = systable->con_out;
45 struct efi_boot_services *boottime = systable->boottime;
46 struct efi_loaded_image *loaded_image;
50 con_out->output_string(con_out, L"Hello, world!\n");
52 /* Get the loaded image protocol */
53 ret = boottime->handle_protocol(handle, &loaded_image_guid,
54 (void **)&loaded_image);
55 if (ret != EFI_SUCCESS) {
56 con_out->output_string(con_out,
57 L"Cannot open loaded image protocol\n");
60 /* Find configuration tables */
61 for (i = 0; i < systable->nr_tables; ++i) {
62 if (!hw_memcmp(&systable->tables[i].guid, &fdt_guid,
64 con_out->output_string(con_out, L"Have device tree\n");
65 if (!hw_memcmp(&systable->tables[i].guid, &smbios_guid,
67 con_out->output_string(con_out, L"Have SMBIOS table\n");
69 /* Output the load options */
70 con_out->output_string(con_out, L"Load options: ");
71 if (loaded_image->load_options_size && loaded_image->load_options)
72 con_out->output_string(con_out,
73 (u16 *)loaded_image->load_options);
75 con_out->output_string(con_out, L"<none>");
76 con_out->output_string(con_out, L"\n");
79 boottime->exit(handle, ret, 0, NULL);
81 /* We should never arrive here */