helloworld.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * EFI hello world
  3. *
  4. * Copyright (c) 2016 Google, Inc
  5. * Written by Simon Glass <sjg@chromium.org>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. *
  9. * This program demonstrates calling a boottime service.
  10. * It writes a greeting and the load options to the console.
  11. */
  12. #include <common.h>
  13. #include <efi_api.h>
  14. /*
  15. * Entry point of the EFI application.
  16. *
  17. * @handle handle of the loaded image
  18. * @systable system table
  19. * @return status code
  20. */
  21. efi_status_t EFIAPI efi_main(efi_handle_t handle,
  22. struct efi_system_table *systable)
  23. {
  24. struct efi_simple_text_output_protocol *con_out = systable->con_out;
  25. struct efi_boot_services *boottime = systable->boottime;
  26. struct efi_loaded_image *loaded_image;
  27. const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
  28. efi_status_t ret;
  29. con_out->output_string(con_out, L"Hello, world!\n");
  30. /* Get the loaded image protocol */
  31. ret = boottime->handle_protocol(handle, &loaded_image_guid,
  32. (void **)&loaded_image);
  33. if (ret != EFI_SUCCESS) {
  34. con_out->output_string(con_out,
  35. L"Cannot open loaded image protocol\n");
  36. goto out;
  37. }
  38. /* Output the load options */
  39. con_out->output_string(con_out, L"Load options: ");
  40. if (loaded_image->load_options_size && loaded_image->load_options)
  41. con_out->output_string(con_out,
  42. (u16 *)loaded_image->load_options);
  43. else
  44. con_out->output_string(con_out, L"<none>");
  45. con_out->output_string(con_out, L"\n");
  46. out:
  47. boottime->exit(handle, ret, 0, NULL);
  48. /* We should never arrive here */
  49. return ret;
  50. }