Commit bd669475 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Matt Fleming

efi: efistub: Refactor stub components

In order to move from the #include "../../../xxxxx.c" anti-pattern used
by both the x86 and arm64 versions of the stub to a static library
linked into either the kernel proper (arm64) or a separate boot
executable (x86), there is some prepatory work required.

This patch does the following:
- move forward declarations of functions shared between the arch
  specific and the generic parts of the stub to include/linux/efi.h
- move forward declarations of functions shared between various .c files
  of the generic stub code to a new local header file called "efistub.h"
- add #includes to all .c files which were formerly relying on the
  #includor to include the correct header files
- remove all static modifiers from functions which will need to be
  externally visible once we move to a static library
Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarMatt Fleming <matt.fleming@intel.com>
parent a13b0077
...@@ -11,30 +11,15 @@ ...@@ -11,30 +11,15 @@
*/ */
#include <linux/efi.h> #include <linux/efi.h>
#include <asm/efi.h> #include <asm/efi.h>
#include <linux/libfdt.h>
#include <asm/sections.h> #include <asm/sections.h>
static void efi_char16_printk(efi_system_table_t *sys_table_arg,
efi_char16_t *str);
static efi_status_t efi_open_volume(efi_system_table_t *sys_table,
void *__image, void **__fh);
static efi_status_t efi_file_close(void *handle);
static efi_status_t
efi_file_read(void *handle, unsigned long *size, void *addr);
static efi_status_t
efi_file_size(efi_system_table_t *sys_table, void *__fh,
efi_char16_t *filename_16, void **handle, u64 *file_sz);
/* Include shared EFI stub code */ /* Include shared EFI stub code */
#include "../../../drivers/firmware/efi/efi-stub-helper.c" #include "../../../drivers/firmware/efi/efi-stub-helper.c"
#include "../../../drivers/firmware/efi/fdt.c" #include "../../../drivers/firmware/efi/fdt.c"
#include "../../../drivers/firmware/efi/arm-stub.c" #include "../../../drivers/firmware/efi/arm-stub.c"
static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
unsigned long *image_addr, unsigned long *image_addr,
unsigned long *image_size, unsigned long *image_size,
unsigned long *reserve_addr, unsigned long *reserve_addr,
......
...@@ -45,8 +45,7 @@ static void setup_boot_services##bits(struct efi_config *c) \ ...@@ -45,8 +45,7 @@ static void setup_boot_services##bits(struct efi_config *c) \
BOOT_SERVICES(32); BOOT_SERVICES(32);
BOOT_SERVICES(64); BOOT_SERVICES(64);
static void efi_printk(efi_system_table_t *, char *); void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
static void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
static efi_status_t static efi_status_t
__file_size32(void *__fh, efi_char16_t *filename_16, __file_size32(void *__fh, efi_char16_t *filename_16,
...@@ -153,7 +152,7 @@ __file_size64(void *__fh, efi_char16_t *filename_16, ...@@ -153,7 +152,7 @@ __file_size64(void *__fh, efi_char16_t *filename_16,
return status; return status;
} }
static efi_status_t efi_status_t
efi_file_size(efi_system_table_t *sys_table, void *__fh, efi_file_size(efi_system_table_t *sys_table, void *__fh,
efi_char16_t *filename_16, void **handle, u64 *file_sz) efi_char16_t *filename_16, void **handle, u64 *file_sz)
{ {
...@@ -163,7 +162,7 @@ efi_file_size(efi_system_table_t *sys_table, void *__fh, ...@@ -163,7 +162,7 @@ efi_file_size(efi_system_table_t *sys_table, void *__fh,
return __file_size32(__fh, filename_16, handle, file_sz); return __file_size32(__fh, filename_16, handle, file_sz);
} }
static inline efi_status_t efi_status_t
efi_file_read(void *handle, unsigned long *size, void *addr) efi_file_read(void *handle, unsigned long *size, void *addr)
{ {
unsigned long func; unsigned long func;
...@@ -181,7 +180,7 @@ efi_file_read(void *handle, unsigned long *size, void *addr) ...@@ -181,7 +180,7 @@ efi_file_read(void *handle, unsigned long *size, void *addr)
} }
} }
static inline efi_status_t efi_file_close(void *handle) efi_status_t efi_file_close(void *handle)
{ {
if (efi_early->is64) { if (efi_early->is64) {
efi_file_handle_64_t *fh = handle; efi_file_handle_64_t *fh = handle;
...@@ -246,7 +245,7 @@ static inline efi_status_t __open_volume64(void *__image, void **__fh) ...@@ -246,7 +245,7 @@ static inline efi_status_t __open_volume64(void *__image, void **__fh)
return status; return status;
} }
static inline efi_status_t efi_status_t
efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh) efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh)
{ {
if (efi_early->is64) if (efi_early->is64)
...@@ -255,7 +254,7 @@ efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh) ...@@ -255,7 +254,7 @@ efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh)
return __open_volume32(__image, __fh); return __open_volume32(__image, __fh);
} }
static void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str)
{ {
unsigned long output_string; unsigned long output_string;
size_t offset; size_t offset;
......
...@@ -12,6 +12,11 @@ ...@@ -12,6 +12,11 @@
* *
*/ */
#include <linux/efi.h>
#include <asm/efi.h>
#include "efistub.h"
static int __init efi_secureboot_enabled(efi_system_table_t *sys_table_arg) static int __init efi_secureboot_enabled(efi_system_table_t *sys_table_arg)
{ {
static efi_guid_t const var_guid __initconst = EFI_GLOBAL_VARIABLE_GUID; static efi_guid_t const var_guid __initconst = EFI_GLOBAL_VARIABLE_GUID;
...@@ -36,7 +41,7 @@ static int __init efi_secureboot_enabled(efi_system_table_t *sys_table_arg) ...@@ -36,7 +41,7 @@ static int __init efi_secureboot_enabled(efi_system_table_t *sys_table_arg)
} }
} }
static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
void *__image, void **__fh) void *__image, void **__fh)
{ {
efi_file_io_interface_t *io; efi_file_io_interface_t *io;
...@@ -60,14 +65,15 @@ static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, ...@@ -60,14 +65,15 @@ static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
*__fh = fh; *__fh = fh;
return status; return status;
} }
static efi_status_t efi_file_close(void *handle)
efi_status_t efi_file_close(void *handle)
{ {
efi_file_handle_t *fh = handle; efi_file_handle_t *fh = handle;
return fh->close(handle); return fh->close(handle);
} }
static efi_status_t efi_status_t
efi_file_read(void *handle, unsigned long *size, void *addr) efi_file_read(void *handle, unsigned long *size, void *addr)
{ {
efi_file_handle_t *fh = handle; efi_file_handle_t *fh = handle;
...@@ -76,7 +82,7 @@ efi_file_read(void *handle, unsigned long *size, void *addr) ...@@ -76,7 +82,7 @@ efi_file_read(void *handle, unsigned long *size, void *addr)
} }
static efi_status_t efi_status_t
efi_file_size(efi_system_table_t *sys_table_arg, void *__fh, efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
efi_char16_t *filename_16, void **handle, u64 *file_sz) efi_char16_t *filename_16, void **handle, u64 *file_sz)
{ {
...@@ -129,7 +135,7 @@ efi_file_size(efi_system_table_t *sys_table_arg, void *__fh, ...@@ -129,7 +135,7 @@ efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
static void efi_char16_printk(efi_system_table_t *sys_table_arg, void efi_char16_printk(efi_system_table_t *sys_table_arg,
efi_char16_t *str) efi_char16_t *str)
{ {
struct efi_simple_text_output_protocol *out; struct efi_simple_text_output_protocol *out;
...@@ -145,7 +151,7 @@ static void efi_char16_printk(efi_system_table_t *sys_table_arg, ...@@ -145,7 +151,7 @@ static void efi_char16_printk(efi_system_table_t *sys_table_arg,
* must be reserved. On failure it is required to free all * must be reserved. On failure it is required to free all
* all allocations it has made. * all allocations it has made.
*/ */
static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
unsigned long *image_addr, unsigned long *image_addr,
unsigned long *image_size, unsigned long *image_size,
unsigned long *reserve_addr, unsigned long *reserve_addr,
......
...@@ -9,18 +9,20 @@ ...@@ -9,18 +9,20 @@
* under the terms of the GNU General Public License version 2. * under the terms of the GNU General Public License version 2.
* *
*/ */
#define EFI_READ_CHUNK_SIZE (1024 * 1024)
/* error code which can't be mistaken for valid address */ #include <linux/efi.h>
#define EFI_ERROR (~0UL) #include <asm/efi.h>
#include "efistub.h"
#define EFI_READ_CHUNK_SIZE (1024 * 1024)
struct file_info { struct file_info {
efi_file_handle_t *handle; efi_file_handle_t *handle;
u64 size; u64 size;
}; };
static void efi_printk(efi_system_table_t *sys_table_arg, char *str) void efi_printk(efi_system_table_t *sys_table_arg, char *str)
{ {
char *s8; char *s8;
...@@ -37,11 +39,7 @@ static void efi_printk(efi_system_table_t *sys_table_arg, char *str) ...@@ -37,11 +39,7 @@ static void efi_printk(efi_system_table_t *sys_table_arg, char *str)
} }
} }
#define pr_efi(sys_table, msg) efi_printk(sys_table, "EFI stub: "msg) efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
#define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg)
static efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
efi_memory_desc_t **map, efi_memory_desc_t **map,
unsigned long *map_size, unsigned long *map_size,
unsigned long *desc_size, unsigned long *desc_size,
...@@ -88,7 +86,7 @@ static efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg, ...@@ -88,7 +86,7 @@ static efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
} }
static unsigned long __init get_dram_base(efi_system_table_t *sys_table_arg) unsigned long __init get_dram_base(efi_system_table_t *sys_table_arg)
{ {
efi_status_t status; efi_status_t status;
unsigned long map_size; unsigned long map_size;
...@@ -116,7 +114,7 @@ static unsigned long __init get_dram_base(efi_system_table_t *sys_table_arg) ...@@ -116,7 +114,7 @@ static unsigned long __init get_dram_base(efi_system_table_t *sys_table_arg)
/* /*
* Allocate at the highest possible address that is not above 'max'. * Allocate at the highest possible address that is not above 'max'.
*/ */
static efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg, efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
unsigned long size, unsigned long align, unsigned long size, unsigned long align,
unsigned long *addr, unsigned long max) unsigned long *addr, unsigned long max)
{ {
...@@ -202,7 +200,7 @@ static efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg, ...@@ -202,7 +200,7 @@ static efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
/* /*
* Allocate at the lowest possible address. * Allocate at the lowest possible address.
*/ */
static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
unsigned long size, unsigned long align, unsigned long size, unsigned long align,
unsigned long *addr) unsigned long *addr)
{ {
...@@ -271,7 +269,7 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, ...@@ -271,7 +269,7 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
return status; return status;
} }
static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
unsigned long addr) unsigned long addr)
{ {
unsigned long nr_pages; unsigned long nr_pages;
...@@ -290,7 +288,7 @@ static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, ...@@ -290,7 +288,7 @@ static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
* We only support loading a file from the same filesystem as * We only support loading a file from the same filesystem as
* the kernel image. * the kernel image.
*/ */
static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
efi_loaded_image_t *image, efi_loaded_image_t *image,
char *cmd_line, char *option_string, char *cmd_line, char *option_string,
unsigned long max_addr, unsigned long max_addr,
...@@ -477,7 +475,7 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, ...@@ -477,7 +475,7 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
* address is not available the lowest available address will * address is not available the lowest available address will
* be used. * be used.
*/ */
static efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg, efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
unsigned long *image_addr, unsigned long *image_addr,
unsigned long image_size, unsigned long image_size,
unsigned long alloc_size, unsigned long alloc_size,
...@@ -589,7 +587,7 @@ static u8 *efi_utf16_to_utf8(u8 *dst, const u16 *src, int n) ...@@ -589,7 +587,7 @@ static u8 *efi_utf16_to_utf8(u8 *dst, const u16 *src, int n)
* Size of memory allocated return in *cmd_line_len. * Size of memory allocated return in *cmd_line_len.
* Returns NULL on error. * Returns NULL on error.
*/ */
static char *efi_convert_cmdline(efi_system_table_t *sys_table_arg, char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
efi_loaded_image_t *image, efi_loaded_image_t *image,
int *cmd_line_len) int *cmd_line_len)
{ {
......
#ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H
#define _DRIVERS_FIRMWARE_EFI_EFISTUB_H
/* error code which can't be mistaken for valid address */
#define EFI_ERROR (~0UL)
void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image,
void **__fh);
efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
efi_char16_t *filename_16, void **handle,
u64 *file_sz);
efi_status_t efi_file_read(void *handle, unsigned long *size, void *addr);
efi_status_t efi_file_close(void *handle);
unsigned long get_dram_base(efi_system_table_t *sys_table_arg);
efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
unsigned long orig_fdt_size,
void *fdt, int new_fdt_size, char *cmdline_ptr,
u64 initrd_addr, u64 initrd_size,
efi_memory_desc_t *memory_map,
unsigned long map_size, unsigned long desc_size,
u32 desc_ver);
efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table,
void *handle,
unsigned long *new_fdt_addr,
unsigned long max_addr,
u64 initrd_addr, u64 initrd_size,
char *cmdline_ptr,
unsigned long fdt_addr,
unsigned long fdt_size);
void *get_fdt(efi_system_table_t *sys_table);
#endif
...@@ -10,7 +10,11 @@ ...@@ -10,7 +10,11 @@
* *
*/ */
static efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, #include <linux/efi.h>
#include <linux/libfdt.h>
#include <asm/efi.h>
efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
unsigned long orig_fdt_size, unsigned long orig_fdt_size,
void *fdt, int new_fdt_size, char *cmdline_ptr, void *fdt, int new_fdt_size, char *cmdline_ptr,
u64 initrd_addr, u64 initrd_size, u64 initrd_addr, u64 initrd_size,
...@@ -255,7 +259,7 @@ efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, ...@@ -255,7 +259,7 @@ efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table,
return EFI_LOAD_ERROR; return EFI_LOAD_ERROR;
} }
static void *get_fdt(efi_system_table_t *sys_table) void *get_fdt(efi_system_table_t *sys_table)
{ {
efi_guid_t fdt_guid = DEVICE_TREE_GUID; efi_guid_t fdt_guid = DEVICE_TREE_GUID;
efi_config_table_t *tables; efi_config_table_t *tables;
......
...@@ -1163,4 +1163,46 @@ static inline void ...@@ -1163,4 +1163,46 @@ static inline void
efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {} efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
#endif #endif
/* prototypes shared between arch specific and generic stub code */
#define pr_efi(sys_table, msg) efi_printk(sys_table, "EFI stub: "msg)
#define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg)
void efi_printk(efi_system_table_t *sys_table_arg, char *str);
void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
unsigned long addr);
char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
efi_loaded_image_t *image, int *cmd_line_len);
efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
efi_memory_desc_t **map,
unsigned long *map_size,
unsigned long *desc_size,
u32 *desc_ver,
unsigned long *key_ptr);
efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
unsigned long size, unsigned long align,
unsigned long *addr);
efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
unsigned long size, unsigned long align,
unsigned long *addr, unsigned long max);
efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
unsigned long *image_addr,
unsigned long image_size,
unsigned long alloc_size,
unsigned long preferred_addr,
unsigned long alignment);
efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
efi_loaded_image_t *image,
char *cmd_line, char *option_string,
unsigned long max_addr,
unsigned long *load_addr,
unsigned long *load_size);
#endif /* _LINUX_EFI_H */ #endif /* _LINUX_EFI_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment