efi-stub.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2013, 2014 Linaro Ltd; <roy.franz@linaro.org>
  3. *
  4. * This file implements the EFI boot stub for the arm64 kernel.
  5. * Adapted from ARM version by Mark Salter <msalter@redhat.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. */
  12. #include <linux/efi.h>
  13. #include <linux/libfdt.h>
  14. #include <asm/sections.h>
  15. /*
  16. * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
  17. * start of kernel and may not cross a 2MiB boundary. We set alignment to
  18. * 2MiB so we know it won't cross a 2MiB boundary.
  19. */
  20. #define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */
  21. #define MAX_FDT_OFFSET SZ_512M
  22. #define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
  23. static void efi_char16_printk(efi_system_table_t *sys_table_arg,
  24. efi_char16_t *str);
  25. static efi_status_t efi_open_volume(efi_system_table_t *sys_table,
  26. void *__image, void **__fh);
  27. static efi_status_t efi_file_close(void *handle);
  28. static efi_status_t
  29. efi_file_read(void *handle, unsigned long *size, void *addr);
  30. static efi_status_t
  31. efi_file_size(efi_system_table_t *sys_table, void *__fh,
  32. efi_char16_t *filename_16, void **handle, u64 *file_sz);
  33. /* Include shared EFI stub code */
  34. #include "../../../drivers/firmware/efi/efi-stub-helper.c"
  35. #include "../../../drivers/firmware/efi/fdt.c"
  36. #include "../../../drivers/firmware/efi/arm-stub.c"
  37. static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
  38. unsigned long *image_addr,
  39. unsigned long *image_size,
  40. unsigned long *reserve_addr,
  41. unsigned long *reserve_size,
  42. unsigned long dram_base,
  43. efi_loaded_image_t *image)
  44. {
  45. efi_status_t status;
  46. unsigned long kernel_size, kernel_memsize = 0;
  47. /* Relocate the image, if required. */
  48. kernel_size = _edata - _text;
  49. if (*image_addr != (dram_base + TEXT_OFFSET)) {
  50. kernel_memsize = kernel_size + (_end - _edata);
  51. status = efi_relocate_kernel(sys_table, image_addr,
  52. kernel_size, kernel_memsize,
  53. dram_base + TEXT_OFFSET,
  54. PAGE_SIZE);
  55. if (status != EFI_SUCCESS) {
  56. pr_efi_err(sys_table, "Failed to relocate kernel\n");
  57. return status;
  58. }
  59. if (*image_addr != (dram_base + TEXT_OFFSET)) {
  60. pr_efi_err(sys_table, "Failed to alloc kernel memory\n");
  61. efi_free(sys_table, kernel_memsize, *image_addr);
  62. return EFI_ERROR;
  63. }
  64. *image_size = kernel_memsize;
  65. }
  66. return EFI_SUCCESS;
  67. }