All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] efistub: convert into static library
@ 2014-06-26 14:23 ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: matt.fleming-ral2JQCrhuEAvxtiuMwx3w, x86-DgEjT+Ai2ygdnm+yROfE0A
  Cc: catalin.marinas-5wv7dgnIgG8, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, leif.lindholm-QSEj5FYQhm4dnm+yROfE0A,
	roy.franz-QSEj5FYQhm4dnm+yROfE0A, msalter-H+wXaHxf7aLQT0dZR+AlfA,
	Ard Biesheuvel

This is v2 of the series to change the #include "../../../../xxx.c" pattern
into a static library linked into either the kernel (arm64) or a separate boot
decompressor (x86, ARM).

Changes since v1:
- added patch #1 to change EFI_ERROR, it is not a result code defined by UEFI so
  it should only be returned by get_dram_base() and efi_entry()
- added a section to libstub Makefile to clean CFLAGS of stack protecter and 
  other options that are inappropriate for the stub
- rebased onto the UEFI Runtime Services NEON patches (re)posted earlier today

Ard Biesheuvel (5):
  efi/arm64: avoid EFI_ERROR as a generic return code
  efi/x86: efistub: move shared dependencies to <asm/efi.h>
  efi/arm64: efistub: move shared dependencies to <asm/efi.h>
  efi: efistub: refactor stub components
  efi: efistub: convert into static library

 arch/arm64/Kconfig                                 |  1 +
 arch/arm64/Makefile                                |  1 +
 arch/arm64/include/asm/efi.h                       | 12 ++++
 arch/arm64/kernel/efi-stub.c                       | 47 +++-----------
 arch/x86/boot/compressed/Makefile                  |  3 +-
 arch/x86/boot/compressed/eboot.c                   | 20 ++----
 arch/x86/boot/compressed/eboot.h                   | 16 -----
 arch/x86/include/asm/efi.h                         | 25 ++++++++
 drivers/firmware/efi/Kconfig                       |  3 +
 drivers/firmware/efi/Makefile                      |  2 +-
 drivers/firmware/efi/libstub/Makefile              | 26 ++++++++
 drivers/firmware/efi/{ => libstub}/arm-stub.c      | 32 ++++++----
 .../firmware/efi/{ => libstub}/efi-stub-helper.c   | 74 +++++++++++-----------
 drivers/firmware/efi/libstub/efistub.h             | 42 ++++++++++++
 drivers/firmware/efi/{ => libstub}/fdt.c           | 20 +++---
 include/linux/efi.h                                | 42 ++++++++++++
 16 files changed, 238 insertions(+), 128 deletions(-)
 create mode 100644 drivers/firmware/efi/libstub/Makefile
 rename drivers/firmware/efi/{ => libstub}/arm-stub.c (93%)
 rename drivers/firmware/efi/{ => libstub}/efi-stub-helper.c (88%)
 create mode 100644 drivers/firmware/efi/libstub/efistub.h
 rename drivers/firmware/efi/{ => libstub}/fdt.c (94%)

-- 
1.8.3.2

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 0/5] efistub: convert into static library
@ 2014-06-26 14:23 ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: linux-arm-kernel

This is v2 of the series to change the #include "../../../../xxx.c" pattern
into a static library linked into either the kernel (arm64) or a separate boot
decompressor (x86, ARM).

Changes since v1:
- added patch #1 to change EFI_ERROR, it is not a result code defined by UEFI so
  it should only be returned by get_dram_base() and efi_entry()
- added a section to libstub Makefile to clean CFLAGS of stack protecter and 
  other options that are inappropriate for the stub
- rebased onto the UEFI Runtime Services NEON patches (re)posted earlier today

Ard Biesheuvel (5):
  efi/arm64: avoid EFI_ERROR as a generic return code
  efi/x86: efistub: move shared dependencies to <asm/efi.h>
  efi/arm64: efistub: move shared dependencies to <asm/efi.h>
  efi: efistub: refactor stub components
  efi: efistub: convert into static library

 arch/arm64/Kconfig                                 |  1 +
 arch/arm64/Makefile                                |  1 +
 arch/arm64/include/asm/efi.h                       | 12 ++++
 arch/arm64/kernel/efi-stub.c                       | 47 +++-----------
 arch/x86/boot/compressed/Makefile                  |  3 +-
 arch/x86/boot/compressed/eboot.c                   | 20 ++----
 arch/x86/boot/compressed/eboot.h                   | 16 -----
 arch/x86/include/asm/efi.h                         | 25 ++++++++
 drivers/firmware/efi/Kconfig                       |  3 +
 drivers/firmware/efi/Makefile                      |  2 +-
 drivers/firmware/efi/libstub/Makefile              | 26 ++++++++
 drivers/firmware/efi/{ => libstub}/arm-stub.c      | 32 ++++++----
 .../firmware/efi/{ => libstub}/efi-stub-helper.c   | 74 +++++++++++-----------
 drivers/firmware/efi/libstub/efistub.h             | 42 ++++++++++++
 drivers/firmware/efi/{ => libstub}/fdt.c           | 20 +++---
 include/linux/efi.h                                | 42 ++++++++++++
 16 files changed, 238 insertions(+), 128 deletions(-)
 create mode 100644 drivers/firmware/efi/libstub/Makefile
 rename drivers/firmware/efi/{ => libstub}/arm-stub.c (93%)
 rename drivers/firmware/efi/{ => libstub}/efi-stub-helper.c (88%)
 create mode 100644 drivers/firmware/efi/libstub/efistub.h
 rename drivers/firmware/efi/{ => libstub}/fdt.c (94%)

-- 
1.8.3.2

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 1/5] efi/arm64: avoid EFI_ERROR as a generic return code
  2014-06-26 14:23 ` Ard Biesheuvel
@ 2014-06-26 14:23     ` Ard Biesheuvel
  -1 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: matt.fleming-ral2JQCrhuEAvxtiuMwx3w, x86-DgEjT+Ai2ygdnm+yROfE0A
  Cc: catalin.marinas-5wv7dgnIgG8, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, leif.lindholm-QSEj5FYQhm4dnm+yROfE0A,
	roy.franz-QSEj5FYQhm4dnm+yROfE0A, msalter-H+wXaHxf7aLQT0dZR+AlfA,
	Ard Biesheuvel

As EFI_ERROR is not a UEFI result code but a local invention only intended to
allow get_dram_base() to signal failure, we should not use it elsewhere.

Replace with EFI_LOAD_ERROR.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---
 arch/arm64/kernel/efi-stub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index e786e6cdc400..7aa7155a9740 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -69,7 +69,7 @@ static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
 		if (*image_addr != (dram_base + TEXT_OFFSET)) {
 			pr_efi_err(sys_table, "Failed to alloc kernel memory\n");
 			efi_free(sys_table, kernel_memsize, *image_addr);
-			return EFI_ERROR;
+			return EFI_LOAD_ERROR;
 		}
 		*image_size = kernel_memsize;
 	}
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 1/5] efi/arm64: avoid EFI_ERROR as a generic return code
@ 2014-06-26 14:23     ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: linux-arm-kernel

As EFI_ERROR is not a UEFI result code but a local invention only intended to
allow get_dram_base() to signal failure, we should not use it elsewhere.

Replace with EFI_LOAD_ERROR.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/arm64/kernel/efi-stub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index e786e6cdc400..7aa7155a9740 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -69,7 +69,7 @@ static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
 		if (*image_addr != (dram_base + TEXT_OFFSET)) {
 			pr_efi_err(sys_table, "Failed to alloc kernel memory\n");
 			efi_free(sys_table, kernel_memsize, *image_addr);
-			return EFI_ERROR;
+			return EFI_LOAD_ERROR;
 		}
 		*image_size = kernel_memsize;
 	}
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 2/5] efi/x86: efistub: move shared dependencies to <asm/efi.h>
  2014-06-26 14:23 ` Ard Biesheuvel
@ 2014-06-26 14:23     ` Ard Biesheuvel
  -1 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: matt.fleming-ral2JQCrhuEAvxtiuMwx3w, x86-DgEjT+Ai2ygdnm+yROfE0A
  Cc: catalin.marinas-5wv7dgnIgG8, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, leif.lindholm-QSEj5FYQhm4dnm+yROfE0A,
	roy.franz-QSEj5FYQhm4dnm+yROfE0A, msalter-H+wXaHxf7aLQT0dZR+AlfA,
	Ard Biesheuvel

This moves definitions depended upon both by code under arch/x86/boot and
under drivers/firmware/efi to <asm/efi.h>. This is in preparation of turning
the stub code under drivers/firmware/efi into a static library.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---
 arch/x86/boot/compressed/eboot.c |  5 +----
 arch/x86/boot/compressed/eboot.h | 16 ----------------
 arch/x86/include/asm/efi.h       | 25 +++++++++++++++++++++++++
 3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 0331d765c2bb..2fd5e2643623 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -19,10 +19,7 @@
 
 static efi_system_table_t *sys_table;
 
-static struct efi_config *efi_early;
-
-#define efi_call_early(f, ...)						\
-	efi_early->call(efi_early->f, __VA_ARGS__);
+struct efi_config *efi_early;
 
 #define BOOT_SERVICES(bits)						\
 static void setup_boot_services##bits(struct efi_config *c)		\
diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h
index c88c31ecad12..d487e727f1ec 100644
--- a/arch/x86/boot/compressed/eboot.h
+++ b/arch/x86/boot/compressed/eboot.h
@@ -103,20 +103,4 @@ struct efi_uga_draw_protocol {
 	void *blt;
 };
 
-struct efi_config {
-	u64 image_handle;
-	u64 table;
-	u64 allocate_pool;
-	u64 allocate_pages;
-	u64 get_memory_map;
-	u64 free_pool;
-	u64 free_pages;
-	u64 locate_handle;
-	u64 handle_protocol;
-	u64 exit_boot_services;
-	u64 text_output;
-	efi_status_t (*call)(unsigned long, ...);
-	bool is64;
-} __packed;
-
 #endif /* BOOT_COMPRESSED_EBOOT_H */
diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index 1eb5f6433ad8..55059a50a01f 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -156,6 +156,31 @@ static inline efi_status_t efi_thunk_set_virtual_address_map(
 	return EFI_SUCCESS;
 }
 #endif /* CONFIG_EFI_MIXED */
+
+
+/* arch specific definitions used by the stub code */
+
+struct efi_config {
+	u64 image_handle;
+	u64 table;
+	u64 allocate_pool;
+	u64 allocate_pages;
+	u64 get_memory_map;
+	u64 free_pool;
+	u64 free_pages;
+	u64 locate_handle;
+	u64 handle_protocol;
+	u64 exit_boot_services;
+	u64 text_output;
+	efi_status_t (*call)(unsigned long, ...);
+	bool is64;
+} __packed;
+
+extern struct efi_config *efi_early;
+
+#define efi_call_early(f, ...)						\
+	efi_early->call(efi_early->f, __VA_ARGS__);
+
 #else
 /*
  * IF EFI is not configured, have the EFI calls return -ENOSYS.
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 2/5] efi/x86: efistub: move shared dependencies to <asm/efi.h>
@ 2014-06-26 14:23     ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: linux-arm-kernel

This moves definitions depended upon both by code under arch/x86/boot and
under drivers/firmware/efi to <asm/efi.h>. This is in preparation of turning
the stub code under drivers/firmware/efi into a static library.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/x86/boot/compressed/eboot.c |  5 +----
 arch/x86/boot/compressed/eboot.h | 16 ----------------
 arch/x86/include/asm/efi.h       | 25 +++++++++++++++++++++++++
 3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 0331d765c2bb..2fd5e2643623 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -19,10 +19,7 @@
 
 static efi_system_table_t *sys_table;
 
-static struct efi_config *efi_early;
-
-#define efi_call_early(f, ...)						\
-	efi_early->call(efi_early->f, __VA_ARGS__);
+struct efi_config *efi_early;
 
 #define BOOT_SERVICES(bits)						\
 static void setup_boot_services##bits(struct efi_config *c)		\
diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h
index c88c31ecad12..d487e727f1ec 100644
--- a/arch/x86/boot/compressed/eboot.h
+++ b/arch/x86/boot/compressed/eboot.h
@@ -103,20 +103,4 @@ struct efi_uga_draw_protocol {
 	void *blt;
 };
 
-struct efi_config {
-	u64 image_handle;
-	u64 table;
-	u64 allocate_pool;
-	u64 allocate_pages;
-	u64 get_memory_map;
-	u64 free_pool;
-	u64 free_pages;
-	u64 locate_handle;
-	u64 handle_protocol;
-	u64 exit_boot_services;
-	u64 text_output;
-	efi_status_t (*call)(unsigned long, ...);
-	bool is64;
-} __packed;
-
 #endif /* BOOT_COMPRESSED_EBOOT_H */
diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index 1eb5f6433ad8..55059a50a01f 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -156,6 +156,31 @@ static inline efi_status_t efi_thunk_set_virtual_address_map(
 	return EFI_SUCCESS;
 }
 #endif /* CONFIG_EFI_MIXED */
+
+
+/* arch specific definitions used by the stub code */
+
+struct efi_config {
+	u64 image_handle;
+	u64 table;
+	u64 allocate_pool;
+	u64 allocate_pages;
+	u64 get_memory_map;
+	u64 free_pool;
+	u64 free_pages;
+	u64 locate_handle;
+	u64 handle_protocol;
+	u64 exit_boot_services;
+	u64 text_output;
+	efi_status_t (*call)(unsigned long, ...);
+	bool is64;
+} __packed;
+
+extern struct efi_config *efi_early;
+
+#define efi_call_early(f, ...)						\
+	efi_early->call(efi_early->f, __VA_ARGS__);
+
 #else
 /*
  * IF EFI is not configured, have the EFI calls return -ENOSYS.
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 3/5] efi/arm64: efistub: move shared dependencies to <asm/efi.h>
  2014-06-26 14:23 ` Ard Biesheuvel
@ 2014-06-26 14:23     ` Ard Biesheuvel
  -1 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: matt.fleming-ral2JQCrhuEAvxtiuMwx3w, x86-DgEjT+Ai2ygdnm+yROfE0A
  Cc: catalin.marinas-5wv7dgnIgG8, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, leif.lindholm-QSEj5FYQhm4dnm+yROfE0A,
	roy.franz-QSEj5FYQhm4dnm+yROfE0A, msalter-H+wXaHxf7aLQT0dZR+AlfA,
	Ard Biesheuvel

This moves definitions depended upon both by code under arch/arm64/boot and
under drivers/firmware/efi to <asm/efi.h>. This is in preparation of turning
the stub code under drivers/firmware/efi into a static library.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---
 arch/arm64/include/asm/efi.h | 12 ++++++++++++
 arch/arm64/kernel/efi-stub.c | 11 +----------
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h
index 375ba342dca6..a34fd3b12e2b 100644
--- a/arch/arm64/include/asm/efi.h
+++ b/arch/arm64/include/asm/efi.h
@@ -32,4 +32,16 @@ extern void efi_idmap_init(void);
 	kernel_neon_end();						\
 })
 
+/* arch specific definitions used by the stub code */
+
+/*
+ * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
+ * start of kernel and may not cross a 2MiB boundary. We set alignment to
+ * 2MiB so we know it won't cross a 2MiB boundary.
+ */
+#define EFI_FDT_ALIGN	SZ_2M   /* used by allocate_new_fdt_and_exit_boot() */
+#define MAX_FDT_OFFSET	SZ_512M
+
+#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
+
 #endif /* _ASM_EFI_H */
diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index 7aa7155a9740..23cbde4324b1 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -10,19 +10,10 @@
  *
  */
 #include <linux/efi.h>
+#include <asm/efi.h>
 #include <linux/libfdt.h>
 #include <asm/sections.h>
 
-/*
- * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
- * start of kernel and may not cross a 2MiB boundary. We set alignment to
- * 2MiB so we know it won't cross a 2MiB boundary.
- */
-#define EFI_FDT_ALIGN	SZ_2M   /* used by allocate_new_fdt_and_exit_boot() */
-#define MAX_FDT_OFFSET	SZ_512M
-
-#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
-
 static void efi_char16_printk(efi_system_table_t *sys_table_arg,
 			      efi_char16_t *str);
 
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 3/5] efi/arm64: efistub: move shared dependencies to <asm/efi.h>
@ 2014-06-26 14:23     ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: linux-arm-kernel

This moves definitions depended upon both by code under arch/arm64/boot and
under drivers/firmware/efi to <asm/efi.h>. This is in preparation of turning
the stub code under drivers/firmware/efi into a static library.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/arm64/include/asm/efi.h | 12 ++++++++++++
 arch/arm64/kernel/efi-stub.c | 11 +----------
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h
index 375ba342dca6..a34fd3b12e2b 100644
--- a/arch/arm64/include/asm/efi.h
+++ b/arch/arm64/include/asm/efi.h
@@ -32,4 +32,16 @@ extern void efi_idmap_init(void);
 	kernel_neon_end();						\
 })
 
+/* arch specific definitions used by the stub code */
+
+/*
+ * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
+ * start of kernel and may not cross a 2MiB boundary. We set alignment to
+ * 2MiB so we know it won't cross a 2MiB boundary.
+ */
+#define EFI_FDT_ALIGN	SZ_2M   /* used by allocate_new_fdt_and_exit_boot() */
+#define MAX_FDT_OFFSET	SZ_512M
+
+#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
+
 #endif /* _ASM_EFI_H */
diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index 7aa7155a9740..23cbde4324b1 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -10,19 +10,10 @@
  *
  */
 #include <linux/efi.h>
+#include <asm/efi.h>
 #include <linux/libfdt.h>
 #include <asm/sections.h>
 
-/*
- * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
- * start of kernel and may not cross a 2MiB boundary. We set alignment to
- * 2MiB so we know it won't cross a 2MiB boundary.
- */
-#define EFI_FDT_ALIGN	SZ_2M   /* used by allocate_new_fdt_and_exit_boot() */
-#define MAX_FDT_OFFSET	SZ_512M
-
-#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
-
 static void efi_char16_printk(efi_system_table_t *sys_table_arg,
 			      efi_char16_t *str);
 
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 4/5] efi: efistub: refactor stub components
  2014-06-26 14:23 ` Ard Biesheuvel
@ 2014-06-26 14:23     ` Ard Biesheuvel
  -1 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: matt.fleming-ral2JQCrhuEAvxtiuMwx3w, x86-DgEjT+Ai2ygdnm+yROfE0A
  Cc: catalin.marinas-5wv7dgnIgG8, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, leif.lindholm-QSEj5FYQhm4dnm+yROfE0A,
	roy.franz-QSEj5FYQhm4dnm+yROfE0A, msalter-H+wXaHxf7aLQT0dZR+AlfA,
	Ard Biesheuvel

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: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---
 arch/arm64/kernel/efi-stub.c           | 29 ++++---------
 arch/x86/boot/compressed/eboot.c       | 13 +++---
 drivers/firmware/efi/arm-stub.c        | 18 ++++++---
 drivers/firmware/efi/efi-stub-helper.c | 74 +++++++++++++++++-----------------
 drivers/firmware/efi/efistub.h         | 42 +++++++++++++++++++
 drivers/firmware/efi/fdt.c             | 20 +++++----
 include/linux/efi.h                    | 42 +++++++++++++++++++
 7 files changed, 157 insertions(+), 81 deletions(-)
 create mode 100644 drivers/firmware/efi/efistub.h

diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index 23cbde4324b1..e4999021b07d 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -11,36 +11,21 @@
  */
 #include <linux/efi.h>
 #include <asm/efi.h>
-#include <linux/libfdt.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 "../../../drivers/firmware/efi/efi-stub-helper.c"
 #include "../../../drivers/firmware/efi/fdt.c"
 #include "../../../drivers/firmware/efi/arm-stub.c"
 
 
-static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
-					unsigned long *image_addr,
-					unsigned long *image_size,
-					unsigned long *reserve_addr,
-					unsigned long *reserve_size,
-					unsigned long dram_base,
-					efi_loaded_image_t *image)
+efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
+				 unsigned long *image_addr,
+				 unsigned long *image_size,
+				 unsigned long *reserve_addr,
+				 unsigned long *reserve_size,
+				 unsigned long dram_base,
+				 efi_loaded_image_t *image)
 {
 	efi_status_t status;
 	unsigned long kernel_size, kernel_memsize = 0;
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 2fd5e2643623..d338c134c659 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -45,8 +45,7 @@ static void setup_boot_services##bits(struct efi_config *c)		\
 BOOT_SERVICES(32);
 BOOT_SERVICES(64);
 
-static void efi_printk(efi_system_table_t *, char *);
-static void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
+void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
 
 static efi_status_t
 __file_size32(void *__fh, efi_char16_t *filename_16,
@@ -153,7 +152,7 @@ grow:
 
 	return status;
 }
-static efi_status_t
+efi_status_t
 efi_file_size(efi_system_table_t *sys_table, void *__fh,
 	      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,
 	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)
 {
 	unsigned long func;
@@ -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) {
 		efi_file_handle_64_t *fh = handle;
@@ -246,7 +245,7 @@ static inline efi_status_t __open_volume64(void *__image, void **__fh)
 	return status;
 }
 
-static inline efi_status_t
+efi_status_t
 efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh)
 {
 	if (efi_early->is64)
@@ -255,7 +254,7 @@ efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__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;
 	size_t offset;
diff --git a/drivers/firmware/efi/arm-stub.c b/drivers/firmware/efi/arm-stub.c
index 41114ce03b01..34614d6f9698 100644
--- a/drivers/firmware/efi/arm-stub.c
+++ b/drivers/firmware/efi/arm-stub.c
@@ -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 efi_guid_t const var_guid __initconst = EFI_GLOBAL_VARIABLE_GUID;
@@ -36,8 +41,8 @@ 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,
-				    void *__image, void **__fh)
+efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
+			     void *__image, void **__fh)
 {
 	efi_file_io_interface_t *io;
 	efi_loaded_image_t *image = __image;
@@ -60,14 +65,15 @@ static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
 	*__fh = fh;
 	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;
 
 	return fh->close(handle);
 }
 
-static efi_status_t
+efi_status_t
 efi_file_read(void *handle, unsigned long *size, void *addr)
 {
 	efi_file_handle_t *fh = handle;
@@ -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_char16_t *filename_16, void **handle, u64 *file_sz)
 {
@@ -129,7 +135,7 @@ grow:
 
 
 
-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)
 {
 	struct efi_simple_text_output_protocol *out;
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c
index eb6d4be9e722..32d5cca30f49 100644
--- a/drivers/firmware/efi/efi-stub-helper.c
+++ b/drivers/firmware/efi/efi-stub-helper.c
@@ -9,18 +9,20 @@
  * 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 */
-#define EFI_ERROR	(~0UL)
+#include <linux/efi.h>
+#include <asm/efi.h>
+
+#include "efistub.h"
 
+#define EFI_READ_CHUNK_SIZE	(1024 * 1024)
 
 struct file_info {
 	efi_file_handle_t *handle;
 	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;
 
@@ -37,16 +39,12 @@ 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)
-#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,
-				       unsigned long *map_size,
-				       unsigned long *desc_size,
-				       u32 *desc_ver,
-				       unsigned long *key_ptr)
+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_memory_desc_t *m = NULL;
 	efi_status_t status;
@@ -88,7 +86,7 @@ fail:
 }
 
 
-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;
 	unsigned long map_size;
@@ -116,9 +114,9 @@ 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'.
  */
-static 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_high_alloc(efi_system_table_t *sys_table_arg,
+			    unsigned long size, unsigned long align,
+			    unsigned long *addr, unsigned long max)
 {
 	unsigned long map_size, desc_size;
 	efi_memory_desc_t *map;
@@ -202,9 +200,9 @@ fail:
 /*
  * Allocate at the lowest possible address.
  */
-static 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_low_alloc(efi_system_table_t *sys_table_arg,
+			   unsigned long size, unsigned long align,
+			   unsigned long *addr)
 {
 	unsigned long map_size, desc_size;
 	efi_memory_desc_t *map;
@@ -271,8 +269,8 @@ fail:
 	return status;
 }
 
-static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
-		     unsigned long addr)
+void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
+	      unsigned long addr)
 {
 	unsigned long nr_pages;
 
@@ -290,12 +288,12 @@ 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
  * the kernel image.
  */
-static 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)
+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)
 {
 	struct file_info *files;
 	unsigned long file_addr;
@@ -477,12 +475,12 @@ fail:
  * address is not available the lowest available address will
  * be used.
  */
-static 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 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)
 {
 	unsigned long cur_image_addr;
 	unsigned long new_addr = 0;
@@ -589,9 +587,9 @@ static u8 *efi_utf16_to_utf8(u8 *dst, const u16 *src, int n)
  * Size of memory allocated return in *cmd_line_len.
  * Returns NULL on error.
  */
-static char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
-				 efi_loaded_image_t *image,
-				 int *cmd_line_len)
+char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
+			  efi_loaded_image_t *image,
+			  int *cmd_line_len)
 {
 	const u16 *s2;
 	u8 *s1 = NULL;
diff --git a/drivers/firmware/efi/efistub.h b/drivers/firmware/efi/efistub.h
new file mode 100644
index 000000000000..304ab295ca1a
--- /dev/null
+++ b/drivers/firmware/efi/efistub.h
@@ -0,0 +1,42 @@
+
+#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
diff --git a/drivers/firmware/efi/fdt.c b/drivers/firmware/efi/fdt.c
index 507a3df46a5d..a56bb3528755 100644
--- a/drivers/firmware/efi/fdt.c
+++ b/drivers/firmware/efi/fdt.c
@@ -10,13 +10,17 @@
  *
  */
 
-static 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)
+#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,
+			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)
 {
 	int node, prev;
 	int status;
@@ -255,7 +259,7 @@ fail:
 	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_config_table_t *tables;
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 0ceb816bdfc2..3a64f2f85821 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -1163,4 +1163,46 @@ static inline void
 efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
 #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 */
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 4/5] efi: efistub: refactor stub components
@ 2014-06-26 14:23     ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: linux-arm-kernel

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: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/arm64/kernel/efi-stub.c           | 29 ++++---------
 arch/x86/boot/compressed/eboot.c       | 13 +++---
 drivers/firmware/efi/arm-stub.c        | 18 ++++++---
 drivers/firmware/efi/efi-stub-helper.c | 74 +++++++++++++++++-----------------
 drivers/firmware/efi/efistub.h         | 42 +++++++++++++++++++
 drivers/firmware/efi/fdt.c             | 20 +++++----
 include/linux/efi.h                    | 42 +++++++++++++++++++
 7 files changed, 157 insertions(+), 81 deletions(-)
 create mode 100644 drivers/firmware/efi/efistub.h

diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index 23cbde4324b1..e4999021b07d 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -11,36 +11,21 @@
  */
 #include <linux/efi.h>
 #include <asm/efi.h>
-#include <linux/libfdt.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 "../../../drivers/firmware/efi/efi-stub-helper.c"
 #include "../../../drivers/firmware/efi/fdt.c"
 #include "../../../drivers/firmware/efi/arm-stub.c"
 
 
-static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
-					unsigned long *image_addr,
-					unsigned long *image_size,
-					unsigned long *reserve_addr,
-					unsigned long *reserve_size,
-					unsigned long dram_base,
-					efi_loaded_image_t *image)
+efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
+				 unsigned long *image_addr,
+				 unsigned long *image_size,
+				 unsigned long *reserve_addr,
+				 unsigned long *reserve_size,
+				 unsigned long dram_base,
+				 efi_loaded_image_t *image)
 {
 	efi_status_t status;
 	unsigned long kernel_size, kernel_memsize = 0;
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 2fd5e2643623..d338c134c659 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -45,8 +45,7 @@ static void setup_boot_services##bits(struct efi_config *c)		\
 BOOT_SERVICES(32);
 BOOT_SERVICES(64);
 
-static void efi_printk(efi_system_table_t *, char *);
-static void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
+void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
 
 static efi_status_t
 __file_size32(void *__fh, efi_char16_t *filename_16,
@@ -153,7 +152,7 @@ grow:
 
 	return status;
 }
-static efi_status_t
+efi_status_t
 efi_file_size(efi_system_table_t *sys_table, void *__fh,
 	      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,
 	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)
 {
 	unsigned long func;
@@ -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) {
 		efi_file_handle_64_t *fh = handle;
@@ -246,7 +245,7 @@ static inline efi_status_t __open_volume64(void *__image, void **__fh)
 	return status;
 }
 
-static inline efi_status_t
+efi_status_t
 efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh)
 {
 	if (efi_early->is64)
@@ -255,7 +254,7 @@ efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__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;
 	size_t offset;
diff --git a/drivers/firmware/efi/arm-stub.c b/drivers/firmware/efi/arm-stub.c
index 41114ce03b01..34614d6f9698 100644
--- a/drivers/firmware/efi/arm-stub.c
+++ b/drivers/firmware/efi/arm-stub.c
@@ -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 efi_guid_t const var_guid __initconst = EFI_GLOBAL_VARIABLE_GUID;
@@ -36,8 +41,8 @@ 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,
-				    void *__image, void **__fh)
+efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
+			     void *__image, void **__fh)
 {
 	efi_file_io_interface_t *io;
 	efi_loaded_image_t *image = __image;
@@ -60,14 +65,15 @@ static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
 	*__fh = fh;
 	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;
 
 	return fh->close(handle);
 }
 
-static efi_status_t
+efi_status_t
 efi_file_read(void *handle, unsigned long *size, void *addr)
 {
 	efi_file_handle_t *fh = handle;
@@ -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_char16_t *filename_16, void **handle, u64 *file_sz)
 {
@@ -129,7 +135,7 @@ grow:
 
 
 
-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)
 {
 	struct efi_simple_text_output_protocol *out;
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c
index eb6d4be9e722..32d5cca30f49 100644
--- a/drivers/firmware/efi/efi-stub-helper.c
+++ b/drivers/firmware/efi/efi-stub-helper.c
@@ -9,18 +9,20 @@
  * 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 */
-#define EFI_ERROR	(~0UL)
+#include <linux/efi.h>
+#include <asm/efi.h>
+
+#include "efistub.h"
 
+#define EFI_READ_CHUNK_SIZE	(1024 * 1024)
 
 struct file_info {
 	efi_file_handle_t *handle;
 	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;
 
@@ -37,16 +39,12 @@ 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)
-#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,
-				       unsigned long *map_size,
-				       unsigned long *desc_size,
-				       u32 *desc_ver,
-				       unsigned long *key_ptr)
+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_memory_desc_t *m = NULL;
 	efi_status_t status;
@@ -88,7 +86,7 @@ fail:
 }
 
 
-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;
 	unsigned long map_size;
@@ -116,9 +114,9 @@ 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'.
  */
-static 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_high_alloc(efi_system_table_t *sys_table_arg,
+			    unsigned long size, unsigned long align,
+			    unsigned long *addr, unsigned long max)
 {
 	unsigned long map_size, desc_size;
 	efi_memory_desc_t *map;
@@ -202,9 +200,9 @@ fail:
 /*
  * Allocate at the lowest possible address.
  */
-static 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_low_alloc(efi_system_table_t *sys_table_arg,
+			   unsigned long size, unsigned long align,
+			   unsigned long *addr)
 {
 	unsigned long map_size, desc_size;
 	efi_memory_desc_t *map;
@@ -271,8 +269,8 @@ fail:
 	return status;
 }
 
-static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
-		     unsigned long addr)
+void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
+	      unsigned long addr)
 {
 	unsigned long nr_pages;
 
@@ -290,12 +288,12 @@ 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
  * the kernel image.
  */
-static 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)
+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)
 {
 	struct file_info *files;
 	unsigned long file_addr;
@@ -477,12 +475,12 @@ fail:
  * address is not available the lowest available address will
  * be used.
  */
-static 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 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)
 {
 	unsigned long cur_image_addr;
 	unsigned long new_addr = 0;
@@ -589,9 +587,9 @@ static u8 *efi_utf16_to_utf8(u8 *dst, const u16 *src, int n)
  * Size of memory allocated return in *cmd_line_len.
  * Returns NULL on error.
  */
-static char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
-				 efi_loaded_image_t *image,
-				 int *cmd_line_len)
+char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
+			  efi_loaded_image_t *image,
+			  int *cmd_line_len)
 {
 	const u16 *s2;
 	u8 *s1 = NULL;
diff --git a/drivers/firmware/efi/efistub.h b/drivers/firmware/efi/efistub.h
new file mode 100644
index 000000000000..304ab295ca1a
--- /dev/null
+++ b/drivers/firmware/efi/efistub.h
@@ -0,0 +1,42 @@
+
+#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
diff --git a/drivers/firmware/efi/fdt.c b/drivers/firmware/efi/fdt.c
index 507a3df46a5d..a56bb3528755 100644
--- a/drivers/firmware/efi/fdt.c
+++ b/drivers/firmware/efi/fdt.c
@@ -10,13 +10,17 @@
  *
  */
 
-static 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)
+#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,
+			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)
 {
 	int node, prev;
 	int status;
@@ -255,7 +259,7 @@ fail:
 	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_config_table_t *tables;
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 0ceb816bdfc2..3a64f2f85821 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -1163,4 +1163,46 @@ static inline void
 efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
 #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 */
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 5/5] efi: efistub: convert into static library
  2014-06-26 14:23 ` Ard Biesheuvel
@ 2014-06-26 14:23     ` Ard Biesheuvel
  -1 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: matt.fleming-ral2JQCrhuEAvxtiuMwx3w, x86-DgEjT+Ai2ygdnm+yROfE0A
  Cc: catalin.marinas-5wv7dgnIgG8, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, leif.lindholm-QSEj5FYQhm4dnm+yROfE0A,
	roy.franz-QSEj5FYQhm4dnm+yROfE0A, msalter-H+wXaHxf7aLQT0dZR+AlfA,
	Ard Biesheuvel

This patch changes both x86 and arm64 efistub implementations from #including
shared .c files under drivers/firmware/efi to building the shared code as a
static library.

The x86 code uses a stub built into the boot executable which uncompresses the
kernel at boot time. In this case, the library is linked into the decompressor.

In the arm64 case, the stub is part of the kernel proper so the library is
linked into the kernel proper as well.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---
 arch/arm64/Kconfig                                 |  1 +
 arch/arm64/Makefile                                |  1 +
 arch/arm64/kernel/efi-stub.c                       |  5 -----
 arch/x86/boot/compressed/Makefile                  |  3 ++-
 arch/x86/boot/compressed/eboot.c                   |  2 --
 drivers/firmware/efi/Kconfig                       |  3 +++
 drivers/firmware/efi/Makefile                      |  2 +-
 drivers/firmware/efi/libstub/Makefile              | 26 ++++++++++++++++++++++
 drivers/firmware/efi/{ => libstub}/arm-stub.c      | 14 ++++++------
 .../firmware/efi/{ => libstub}/efi-stub-helper.c   |  0
 drivers/firmware/efi/{ => libstub}/efistub.h       |  0
 drivers/firmware/efi/{ => libstub}/fdt.c           |  0
 12 files changed, 41 insertions(+), 16 deletions(-)
 create mode 100644 drivers/firmware/efi/libstub/Makefile
 rename drivers/firmware/efi/{ => libstub}/arm-stub.c (96%)
 rename drivers/firmware/efi/{ => libstub}/efi-stub-helper.c (100%)
 rename drivers/firmware/efi/{ => libstub}/efistub.h (100%)
 rename drivers/firmware/efi/{ => libstub}/fdt.c (100%)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 93e11f4d9513..f766f346022d 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -300,6 +300,7 @@ config EFI
 	select UCS2_STRING
 	select EFI_PARAMS_FROM_FDT
 	select EFI_RUNTIME_WRAPPERS
+	select EFI_ARMSTUB
 	default y
 	help
 	  This option provides support for runtime services provided
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 8185a913c5ed..bb8f21a626c0 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -48,6 +48,7 @@ core-$(CONFIG_XEN) += arch/arm64/xen/
 core-$(CONFIG_CRYPTO) += arch/arm64/crypto/
 libs-y		:= arch/arm64/lib/ $(libs-y)
 libs-y		+= $(LIBGCC)
+libs-$(CONFIG_EFI) += drivers/firmware/efi/libstub/
 
 # Default target when executing plain make
 KBUILD_IMAGE	:= Image.gz
diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index e4999021b07d..12456a7d3fa2 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -13,11 +13,6 @@
 #include <asm/efi.h>
 #include <asm/sections.h>
 
-/* Include shared EFI stub code */
-#include "../../../drivers/firmware/efi/efi-stub-helper.c"
-#include "../../../drivers/firmware/efi/fdt.c"
-#include "../../../drivers/firmware/efi/arm-stub.c"
-
 
 efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
 				 unsigned long *image_addr,
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 0fcd9133790c..7a801a310e37 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -33,7 +33,8 @@ VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
 $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
 
 ifeq ($(CONFIG_EFI_STUB), y)
-	VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o
+	VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \
+				$(objtree)/drivers/firmware/efi/libstub/lib.a
 endif
 
 $(obj)/vmlinux: $(VMLINUX_OBJS) FORCE
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index d338c134c659..d4d865438a0c 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -280,8 +280,6 @@ void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str)
 	}
 }
 
-#include "../../../../drivers/firmware/efi/efi-stub-helper.c"
-
 static void find_bits(unsigned long mask, u8 *pos, u8 *size)
 {
 	u8 first, len;
diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig
index 04a7af46736a..395e76d9a1b5 100644
--- a/drivers/firmware/efi/Kconfig
+++ b/drivers/firmware/efi/Kconfig
@@ -61,6 +61,9 @@ config EFI_RUNTIME_WRAPPERS
 	  in which case it needs to provide #definitions of efi_call_virt and
 	  __efi_call_virt in <asm/efi.h>
 
+config EFI_ARMSTUB
+	bool
+
 endmenu
 
 config UEFI_CPER
diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
index e1096539eedb..d9abdbc962f1 100644
--- a/drivers/firmware/efi/Makefile
+++ b/drivers/firmware/efi/Makefile
@@ -1,7 +1,7 @@
 #
 # Makefile for linux kernel
 #
-obj-$(CONFIG_EFI)			+= efi.o vars.o
+obj-$(CONFIG_EFI)			+= efi.o vars.o libstub/
 obj-$(CONFIG_EFI_VARS)			+= efivars.o
 obj-$(CONFIG_EFI_VARS_PSTORE)		+= efi-pstore.o
 obj-$(CONFIG_UEFI_CPER)			+= cper.o
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
new file mode 100644
index 000000000000..b14bc2b9fb4d
--- /dev/null
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -0,0 +1,26 @@
+#
+# The stub may be linked into the kernel proper or into a separate boot binary,
+# but in either case, it executes before the kernel does (with MMU disabled) so
+# things like ftrace and stack-protector are likely to cause trouble if left
+# enabled, even if doing so doesn't break the build.
+#
+cflags-$(CONFIG_X86_32)		:= -march=i386
+cflags-$(CONFIG_X86_64)		:= -mcmodel=small
+cflags-$(CONFIG_X86)		+= -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 \
+				   -fPIC -fno-strict-aliasing -mno-red-zone \
+				   -mno-mmx -mno-sse -DDISABLE_BRANCH_PROFILING
+
+cflags-$(CONFIG_ARM64)		:= $(subst -pg,,$(KBUILD_CFLAGS))
+cflags-$(CONFIG_ARM)		:= $(subst -pg,,$(KBUILD_CFLAGS)) \
+				   -fno-builtin -fpic -mno-single-pic-base
+
+KBUILD_CFLAGS			:= $(cflags-y) \
+				   $(call cc-option,-ffreestanding) \
+				   $(call cc-option,-fno-stack-protector)
+
+GCOV_PROFILE			:= n
+
+lib-y				:= efi-stub-helper.o
+lib-$(CONFIG_EFI_ARMSTUB)	+= arm-stub.o fdt.o
+
+CFLAGS_fdt.o			+= -I$(srctree)/scripts/dtc/libfdt/
diff --git a/drivers/firmware/efi/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c
similarity index 96%
rename from drivers/firmware/efi/arm-stub.c
rename to drivers/firmware/efi/libstub/arm-stub.c
index 34614d6f9698..480339b6b110 100644
--- a/drivers/firmware/efi/arm-stub.c
+++ b/drivers/firmware/efi/libstub/arm-stub.c
@@ -151,13 +151,13 @@ void efi_char16_printk(efi_system_table_t *sys_table_arg,
  * must be reserved. On failure it is required to free all
  * all allocations it has made.
  */
-static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
-					unsigned long *image_addr,
-					unsigned long *image_size,
-					unsigned long *reserve_addr,
-					unsigned long *reserve_size,
-					unsigned long dram_base,
-					efi_loaded_image_t *image);
+efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
+				 unsigned long *image_addr,
+				 unsigned long *image_size,
+				 unsigned long *reserve_addr,
+				 unsigned long *reserve_size,
+				 unsigned long dram_base,
+				 efi_loaded_image_t *image);
 /*
  * EFI entry point for the arm/arm64 EFI stubs.  This is the entrypoint
  * that is described in the PE/COFF header.  Most of the code is the same
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
similarity index 100%
rename from drivers/firmware/efi/efi-stub-helper.c
rename to drivers/firmware/efi/libstub/efi-stub-helper.c
diff --git a/drivers/firmware/efi/efistub.h b/drivers/firmware/efi/libstub/efistub.h
similarity index 100%
rename from drivers/firmware/efi/efistub.h
rename to drivers/firmware/efi/libstub/efistub.h
diff --git a/drivers/firmware/efi/fdt.c b/drivers/firmware/efi/libstub/fdt.c
similarity index 100%
rename from drivers/firmware/efi/fdt.c
rename to drivers/firmware/efi/libstub/fdt.c
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 5/5] efi: efistub: convert into static library
@ 2014-06-26 14:23     ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-06-26 14:23 UTC (permalink / raw)
  To: linux-arm-kernel

This patch changes both x86 and arm64 efistub implementations from #including
shared .c files under drivers/firmware/efi to building the shared code as a
static library.

The x86 code uses a stub built into the boot executable which uncompresses the
kernel at boot time. In this case, the library is linked into the decompressor.

In the arm64 case, the stub is part of the kernel proper so the library is
linked into the kernel proper as well.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/arm64/Kconfig                                 |  1 +
 arch/arm64/Makefile                                |  1 +
 arch/arm64/kernel/efi-stub.c                       |  5 -----
 arch/x86/boot/compressed/Makefile                  |  3 ++-
 arch/x86/boot/compressed/eboot.c                   |  2 --
 drivers/firmware/efi/Kconfig                       |  3 +++
 drivers/firmware/efi/Makefile                      |  2 +-
 drivers/firmware/efi/libstub/Makefile              | 26 ++++++++++++++++++++++
 drivers/firmware/efi/{ => libstub}/arm-stub.c      | 14 ++++++------
 .../firmware/efi/{ => libstub}/efi-stub-helper.c   |  0
 drivers/firmware/efi/{ => libstub}/efistub.h       |  0
 drivers/firmware/efi/{ => libstub}/fdt.c           |  0
 12 files changed, 41 insertions(+), 16 deletions(-)
 create mode 100644 drivers/firmware/efi/libstub/Makefile
 rename drivers/firmware/efi/{ => libstub}/arm-stub.c (96%)
 rename drivers/firmware/efi/{ => libstub}/efi-stub-helper.c (100%)
 rename drivers/firmware/efi/{ => libstub}/efistub.h (100%)
 rename drivers/firmware/efi/{ => libstub}/fdt.c (100%)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 93e11f4d9513..f766f346022d 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -300,6 +300,7 @@ config EFI
 	select UCS2_STRING
 	select EFI_PARAMS_FROM_FDT
 	select EFI_RUNTIME_WRAPPERS
+	select EFI_ARMSTUB
 	default y
 	help
 	  This option provides support for runtime services provided
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 8185a913c5ed..bb8f21a626c0 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -48,6 +48,7 @@ core-$(CONFIG_XEN) += arch/arm64/xen/
 core-$(CONFIG_CRYPTO) += arch/arm64/crypto/
 libs-y		:= arch/arm64/lib/ $(libs-y)
 libs-y		+= $(LIBGCC)
+libs-$(CONFIG_EFI) += drivers/firmware/efi/libstub/
 
 # Default target when executing plain make
 KBUILD_IMAGE	:= Image.gz
diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index e4999021b07d..12456a7d3fa2 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -13,11 +13,6 @@
 #include <asm/efi.h>
 #include <asm/sections.h>
 
-/* Include shared EFI stub code */
-#include "../../../drivers/firmware/efi/efi-stub-helper.c"
-#include "../../../drivers/firmware/efi/fdt.c"
-#include "../../../drivers/firmware/efi/arm-stub.c"
-
 
 efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
 				 unsigned long *image_addr,
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 0fcd9133790c..7a801a310e37 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -33,7 +33,8 @@ VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
 $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
 
 ifeq ($(CONFIG_EFI_STUB), y)
-	VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o
+	VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \
+				$(objtree)/drivers/firmware/efi/libstub/lib.a
 endif
 
 $(obj)/vmlinux: $(VMLINUX_OBJS) FORCE
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index d338c134c659..d4d865438a0c 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -280,8 +280,6 @@ void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str)
 	}
 }
 
-#include "../../../../drivers/firmware/efi/efi-stub-helper.c"
-
 static void find_bits(unsigned long mask, u8 *pos, u8 *size)
 {
 	u8 first, len;
diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig
index 04a7af46736a..395e76d9a1b5 100644
--- a/drivers/firmware/efi/Kconfig
+++ b/drivers/firmware/efi/Kconfig
@@ -61,6 +61,9 @@ config EFI_RUNTIME_WRAPPERS
 	  in which case it needs to provide #definitions of efi_call_virt and
 	  __efi_call_virt in <asm/efi.h>
 
+config EFI_ARMSTUB
+	bool
+
 endmenu
 
 config UEFI_CPER
diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
index e1096539eedb..d9abdbc962f1 100644
--- a/drivers/firmware/efi/Makefile
+++ b/drivers/firmware/efi/Makefile
@@ -1,7 +1,7 @@
 #
 # Makefile for linux kernel
 #
-obj-$(CONFIG_EFI)			+= efi.o vars.o
+obj-$(CONFIG_EFI)			+= efi.o vars.o libstub/
 obj-$(CONFIG_EFI_VARS)			+= efivars.o
 obj-$(CONFIG_EFI_VARS_PSTORE)		+= efi-pstore.o
 obj-$(CONFIG_UEFI_CPER)			+= cper.o
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
new file mode 100644
index 000000000000..b14bc2b9fb4d
--- /dev/null
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -0,0 +1,26 @@
+#
+# The stub may be linked into the kernel proper or into a separate boot binary,
+# but in either case, it executes before the kernel does (with MMU disabled) so
+# things like ftrace and stack-protector are likely to cause trouble if left
+# enabled, even if doing so doesn't break the build.
+#
+cflags-$(CONFIG_X86_32)		:= -march=i386
+cflags-$(CONFIG_X86_64)		:= -mcmodel=small
+cflags-$(CONFIG_X86)		+= -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 \
+				   -fPIC -fno-strict-aliasing -mno-red-zone \
+				   -mno-mmx -mno-sse -DDISABLE_BRANCH_PROFILING
+
+cflags-$(CONFIG_ARM64)		:= $(subst -pg,,$(KBUILD_CFLAGS))
+cflags-$(CONFIG_ARM)		:= $(subst -pg,,$(KBUILD_CFLAGS)) \
+				   -fno-builtin -fpic -mno-single-pic-base
+
+KBUILD_CFLAGS			:= $(cflags-y) \
+				   $(call cc-option,-ffreestanding) \
+				   $(call cc-option,-fno-stack-protector)
+
+GCOV_PROFILE			:= n
+
+lib-y				:= efi-stub-helper.o
+lib-$(CONFIG_EFI_ARMSTUB)	+= arm-stub.o fdt.o
+
+CFLAGS_fdt.o			+= -I$(srctree)/scripts/dtc/libfdt/
diff --git a/drivers/firmware/efi/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c
similarity index 96%
rename from drivers/firmware/efi/arm-stub.c
rename to drivers/firmware/efi/libstub/arm-stub.c
index 34614d6f9698..480339b6b110 100644
--- a/drivers/firmware/efi/arm-stub.c
+++ b/drivers/firmware/efi/libstub/arm-stub.c
@@ -151,13 +151,13 @@ void efi_char16_printk(efi_system_table_t *sys_table_arg,
  * must be reserved. On failure it is required to free all
  * all allocations it has made.
  */
-static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
-					unsigned long *image_addr,
-					unsigned long *image_size,
-					unsigned long *reserve_addr,
-					unsigned long *reserve_size,
-					unsigned long dram_base,
-					efi_loaded_image_t *image);
+efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
+				 unsigned long *image_addr,
+				 unsigned long *image_size,
+				 unsigned long *reserve_addr,
+				 unsigned long *reserve_size,
+				 unsigned long dram_base,
+				 efi_loaded_image_t *image);
 /*
  * EFI entry point for the arm/arm64 EFI stubs.  This is the entrypoint
  * that is described in the PE/COFF header.  Most of the code is the same
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
similarity index 100%
rename from drivers/firmware/efi/efi-stub-helper.c
rename to drivers/firmware/efi/libstub/efi-stub-helper.c
diff --git a/drivers/firmware/efi/efistub.h b/drivers/firmware/efi/libstub/efistub.h
similarity index 100%
rename from drivers/firmware/efi/efistub.h
rename to drivers/firmware/efi/libstub/efistub.h
diff --git a/drivers/firmware/efi/fdt.c b/drivers/firmware/efi/libstub/fdt.c
similarity index 100%
rename from drivers/firmware/efi/fdt.c
rename to drivers/firmware/efi/libstub/fdt.c
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 4/5] efi: efistub: refactor stub components
  2014-06-26 14:23     ` Ard Biesheuvel
@ 2014-07-01 15:11         ` Matt Fleming
  -1 siblings, 0 replies; 36+ messages in thread
From: Matt Fleming @ 2014-07-01 15:11 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: matt.fleming-ral2JQCrhuEAvxtiuMwx3w, x86-DgEjT+Ai2ygdnm+yROfE0A,
	catalin.marinas-5wv7dgnIgG8, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, leif.lindholm-QSEj5FYQhm4dnm+yROfE0A,
	roy.franz-QSEj5FYQhm4dnm+yROfE0A, msalter-H+wXaHxf7aLQT0dZR+AlfA

On Thu, 26 Jun, at 04:23:36PM, Ard Biesheuvel wrote:
> 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: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

[...]

> diff --git a/include/linux/efi.h b/include/linux/efi.h
> index 0ceb816bdfc2..3a64f2f85821 100644
> --- a/include/linux/efi.h
> +++ b/include/linux/efi.h
> @@ -1163,4 +1163,46 @@ static inline void
>  efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
>  #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);
> +

We've been very good so far at not splattering include/linux/efi.h with
any of the EFI boot stub prototypes, and it would be awesome if we
didn't have to start now.

Is there any way we could avoid doing this? Arguably everything should
be in the new efistub.h, no?

-- 
Matt Fleming, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 4/5] efi: efistub: refactor stub components
@ 2014-07-01 15:11         ` Matt Fleming
  0 siblings, 0 replies; 36+ messages in thread
From: Matt Fleming @ 2014-07-01 15:11 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 26 Jun, at 04:23:36PM, Ard Biesheuvel wrote:
> 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: Ard Biesheuvel <ard.biesheuvel@linaro.org>

[...]

> diff --git a/include/linux/efi.h b/include/linux/efi.h
> index 0ceb816bdfc2..3a64f2f85821 100644
> --- a/include/linux/efi.h
> +++ b/include/linux/efi.h
> @@ -1163,4 +1163,46 @@ static inline void
>  efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
>  #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);
> +

We've been very good so far at not splattering include/linux/efi.h with
any of the EFI boot stub prototypes, and it would be awesome if we
didn't have to start now.

Is there any way we could avoid doing this? Arguably everything should
be in the new efistub.h, no?

-- 
Matt Fleming, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 4/5] efi: efistub: refactor stub components
  2014-07-01 15:11         ` Matt Fleming
@ 2014-07-01 15:18             ` Ard Biesheuvel
  -1 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-01 15:18 UTC (permalink / raw)
  To: Matt Fleming
  Cc: Matt Fleming, x86-DgEjT+Ai2ygdnm+yROfE0A, Catalin Marinas,
	linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, Leif Lindholm, Roy Franz,
	Mark Salter

On 1 July 2014 17:11, Matt Fleming <matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org> wrote:
> On Thu, 26 Jun, at 04:23:36PM, Ard Biesheuvel wrote:
>> 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: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>
> [...]
>
>> diff --git a/include/linux/efi.h b/include/linux/efi.h
>> index 0ceb816bdfc2..3a64f2f85821 100644
>> --- a/include/linux/efi.h
>> +++ b/include/linux/efi.h
>> @@ -1163,4 +1163,46 @@ static inline void
>>  efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
>>  #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);
>> +
>
> We've been very good so far at not splattering include/linux/efi.h with
> any of the EFI boot stub prototypes, and it would be awesome if we
> didn't have to start now.
>
> Is there any way we could avoid doing this? Arguably everything should
> be in the new efistub.h, no?
>

There are bits that are shared between code under arch/xxx and
drivers/firmware/efi, and what those bits are is different between the
archs. I used <asm/efi.h> just for convenience, but perhaps we could
add <asm/efistub.h> for each arch, and #include it in both "efistub.h"
under drivers/firmware/efi and the stub bits that live under arch/xxx?
Then any other users of <asm/efi.h> won't have to see it.

-- 
Ard.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 4/5] efi: efistub: refactor stub components
@ 2014-07-01 15:18             ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-01 15:18 UTC (permalink / raw)
  To: linux-arm-kernel

On 1 July 2014 17:11, Matt Fleming <matt@console-pimps.org> wrote:
> On Thu, 26 Jun, at 04:23:36PM, Ard Biesheuvel wrote:
>> 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: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>
> [...]
>
>> diff --git a/include/linux/efi.h b/include/linux/efi.h
>> index 0ceb816bdfc2..3a64f2f85821 100644
>> --- a/include/linux/efi.h
>> +++ b/include/linux/efi.h
>> @@ -1163,4 +1163,46 @@ static inline void
>>  efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
>>  #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);
>> +
>
> We've been very good so far at not splattering include/linux/efi.h with
> any of the EFI boot stub prototypes, and it would be awesome if we
> didn't have to start now.
>
> Is there any way we could avoid doing this? Arguably everything should
> be in the new efistub.h, no?
>

There are bits that are shared between code under arch/xxx and
drivers/firmware/efi, and what those bits are is different between the
archs. I used <asm/efi.h> just for convenience, but perhaps we could
add <asm/efistub.h> for each arch, and #include it in both "efistub.h"
under drivers/firmware/efi and the stub bits that live under arch/xxx?
Then any other users of <asm/efi.h> won't have to see it.

-- 
Ard.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 4/5] efi: efistub: refactor stub components
  2014-07-01 15:18             ` Ard Biesheuvel
@ 2014-07-01 15:20                 ` Ard Biesheuvel
  -1 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-01 15:20 UTC (permalink / raw)
  To: Matt Fleming
  Cc: Matt Fleming, x86-DgEjT+Ai2ygdnm+yROfE0A, Catalin Marinas,
	linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, Leif Lindholm, Roy Franz,
	Mark Salter

On 1 July 2014 17:18, Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> wrote:
> On 1 July 2014 17:11, Matt Fleming <matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org> wrote:
>> On Thu, 26 Jun, at 04:23:36PM, Ard Biesheuvel wrote:
>>> 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: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>>
>> [...]
>>
>>> diff --git a/include/linux/efi.h b/include/linux/efi.h
>>> index 0ceb816bdfc2..3a64f2f85821 100644
>>> --- a/include/linux/efi.h
>>> +++ b/include/linux/efi.h
>>> @@ -1163,4 +1163,46 @@ static inline void
>>>  efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
>>>  #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);
>>> +
>>
>> We've been very good so far at not splattering include/linux/efi.h with
>> any of the EFI boot stub prototypes, and it would be awesome if we
>> didn't have to start now.
>>
>> Is there any way we could avoid doing this? Arguably everything should
>> be in the new efistub.h, no?
>>
>
> There are bits that are shared between code under arch/xxx and
> drivers/firmware/efi, and what those bits are is different between the
> archs. I used <asm/efi.h> just for convenience, but perhaps we could
> add <asm/efistub.h> for each arch, and #include it in both "efistub.h"
> under drivers/firmware/efi and the stub bits that live under arch/xxx?
> Then any other users of <asm/efi.h> won't have to see it.
>

... but that wasn't your question ....

The reason this can't live in "efistub.h" is that it gets included by
bits under arch/xxx
So perhaps moving the local "efistub.h" to <linux/efistub.h> would be
appropriate, yes.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 4/5] efi: efistub: refactor stub components
@ 2014-07-01 15:20                 ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-01 15:20 UTC (permalink / raw)
  To: linux-arm-kernel

On 1 July 2014 17:18, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> On 1 July 2014 17:11, Matt Fleming <matt@console-pimps.org> wrote:
>> On Thu, 26 Jun, at 04:23:36PM, Ard Biesheuvel wrote:
>>> 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: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>>
>> [...]
>>
>>> diff --git a/include/linux/efi.h b/include/linux/efi.h
>>> index 0ceb816bdfc2..3a64f2f85821 100644
>>> --- a/include/linux/efi.h
>>> +++ b/include/linux/efi.h
>>> @@ -1163,4 +1163,46 @@ static inline void
>>>  efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
>>>  #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);
>>> +
>>
>> We've been very good so far at not splattering include/linux/efi.h with
>> any of the EFI boot stub prototypes, and it would be awesome if we
>> didn't have to start now.
>>
>> Is there any way we could avoid doing this? Arguably everything should
>> be in the new efistub.h, no?
>>
>
> There are bits that are shared between code under arch/xxx and
> drivers/firmware/efi, and what those bits are is different between the
> archs. I used <asm/efi.h> just for convenience, but perhaps we could
> add <asm/efistub.h> for each arch, and #include it in both "efistub.h"
> under drivers/firmware/efi and the stub bits that live under arch/xxx?
> Then any other users of <asm/efi.h> won't have to see it.
>

... but that wasn't your question ....

The reason this can't live in "efistub.h" is that it gets included by
bits under arch/xxx
So perhaps moving the local "efistub.h" to <linux/efistub.h> would be
appropriate, yes.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 4/5] efi: efistub: refactor stub components
  2014-07-01 15:20                 ` Ard Biesheuvel
@ 2014-07-01 16:22                     ` Matt Fleming
  -1 siblings, 0 replies; 36+ messages in thread
From: Matt Fleming @ 2014-07-01 16:22 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Matt Fleming, x86-DgEjT+Ai2ygdnm+yROfE0A, Catalin Marinas,
	linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, Leif Lindholm, Roy Franz,
	Mark Salter

On Tue, 01 Jul, at 05:20:21PM, Ard Biesheuvel wrote:
> 
> ... but that wasn't your question ....
> 
> The reason this can't live in "efistub.h" is that it gets included by
> bits under arch/xxx
> So perhaps moving the local "efistub.h" to <linux/efistub.h> would be
> appropriate, yes.

I didn't mean that we should add include/linux/efistub.h, rather that we
should try adding them to efistub.h or asm/efi.h.

But I see that isn't going to work too well and there's no easy fix.
Let's just leave things as they are for now.

Long term, I've been thinking of splitting up include/linux/efi.h. It's
currently weighing in at 1208 lines and contains pieces for all sorts of
different chunks of EFI code, 32-bit and 64-bit versions of data
structures, etc.

-- 
Matt Fleming, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 4/5] efi: efistub: refactor stub components
@ 2014-07-01 16:22                     ` Matt Fleming
  0 siblings, 0 replies; 36+ messages in thread
From: Matt Fleming @ 2014-07-01 16:22 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 01 Jul, at 05:20:21PM, Ard Biesheuvel wrote:
> 
> ... but that wasn't your question ....
> 
> The reason this can't live in "efistub.h" is that it gets included by
> bits under arch/xxx
> So perhaps moving the local "efistub.h" to <linux/efistub.h> would be
> appropriate, yes.

I didn't mean that we should add include/linux/efistub.h, rather that we
should try adding them to efistub.h or asm/efi.h.

But I see that isn't going to work too well and there's no easy fix.
Let's just leave things as they are for now.

Long term, I've been thinking of splitting up include/linux/efi.h. It's
currently weighing in at 1208 lines and contains pieces for all sorts of
different chunks of EFI code, 32-bit and 64-bit versions of data
structures, etc.

-- 
Matt Fleming, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 0/5] efistub: convert into static library
  2014-06-26 14:23 ` Ard Biesheuvel
@ 2014-07-01 18:39     ` Matt Fleming
  -1 siblings, 0 replies; 36+ messages in thread
From: Matt Fleming @ 2014-07-01 18:39 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: matt.fleming-ral2JQCrhuEAvxtiuMwx3w, x86-DgEjT+Ai2ygdnm+yROfE0A,
	catalin.marinas-5wv7dgnIgG8, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, leif.lindholm-QSEj5FYQhm4dnm+yROfE0A,
	roy.franz-QSEj5FYQhm4dnm+yROfE0A, msalter-H+wXaHxf7aLQT0dZR+AlfA

On Thu, 26 Jun, at 04:23:32PM, Ard Biesheuvel wrote:
> This is v2 of the series to change the #include "../../../../xxx.c" pattern
> into a static library linked into either the kernel (arm64) or a separate boot
> decompressor (x86, ARM).
> 
> Changes since v1:
> - added patch #1 to change EFI_ERROR, it is not a result code defined by UEFI so
>   it should only be returned by get_dram_base() and efi_entry()
> - added a section to libstub Makefile to clean CFLAGS of stack protecter and 
>   other options that are inappropriate for the stub
> - rebased onto the UEFI Runtime Services NEON patches (re)posted earlier today
> 
> Ard Biesheuvel (5):
>   efi/arm64: avoid EFI_ERROR as a generic return code
>   efi/x86: efistub: move shared dependencies to <asm/efi.h>
>   efi/arm64: efistub: move shared dependencies to <asm/efi.h>
>   efi: efistub: refactor stub components
>   efi: efistub: convert into static library

Thanks Ard. I've picked these up.

-- 
Matt Fleming, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 0/5] efistub: convert into static library
@ 2014-07-01 18:39     ` Matt Fleming
  0 siblings, 0 replies; 36+ messages in thread
From: Matt Fleming @ 2014-07-01 18:39 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 26 Jun, at 04:23:32PM, Ard Biesheuvel wrote:
> This is v2 of the series to change the #include "../../../../xxx.c" pattern
> into a static library linked into either the kernel (arm64) or a separate boot
> decompressor (x86, ARM).
> 
> Changes since v1:
> - added patch #1 to change EFI_ERROR, it is not a result code defined by UEFI so
>   it should only be returned by get_dram_base() and efi_entry()
> - added a section to libstub Makefile to clean CFLAGS of stack protecter and 
>   other options that are inappropriate for the stub
> - rebased onto the UEFI Runtime Services NEON patches (re)posted earlier today
> 
> Ard Biesheuvel (5):
>   efi/arm64: avoid EFI_ERROR as a generic return code
>   efi/x86: efistub: move shared dependencies to <asm/efi.h>
>   efi/arm64: efistub: move shared dependencies to <asm/efi.h>
>   efi: efistub: refactor stub components
>   efi: efistub: convert into static library

Thanks Ard. I've picked these up.

-- 
Matt Fleming, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 0/5] efistub: convert into static library
  2014-07-01 18:39     ` Matt Fleming
@ 2014-07-01 18:55         ` Ard Biesheuvel
  -1 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-01 18:55 UTC (permalink / raw)
  To: Matt Fleming
  Cc: Matt Fleming, x86-DgEjT+Ai2ygdnm+yROfE0A, Catalin Marinas,
	linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, Leif Lindholm, Roy Franz,
	Mark Salter

On 1 July 2014 20:39, Matt Fleming <matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org> wrote:
> On Thu, 26 Jun, at 04:23:32PM, Ard Biesheuvel wrote:
>> This is v2 of the series to change the #include "../../../../xxx.c" pattern
>> into a static library linked into either the kernel (arm64) or a separate boot
>> decompressor (x86, ARM).
>>
>> Changes since v1:
>> - added patch #1 to change EFI_ERROR, it is not a result code defined by UEFI so
>>   it should only be returned by get_dram_base() and efi_entry()
>> - added a section to libstub Makefile to clean CFLAGS of stack protecter and
>>   other options that are inappropriate for the stub
>> - rebased onto the UEFI Runtime Services NEON patches (re)posted earlier today
>>
>> Ard Biesheuvel (5):
>>   efi/arm64: avoid EFI_ERROR as a generic return code
>>   efi/x86: efistub: move shared dependencies to <asm/efi.h>
>>   efi/arm64: efistub: move shared dependencies to <asm/efi.h>
>>   efi: efistub: refactor stub components
>>   efi: efistub: convert into static library
>
> Thanks Ard. I've picked these up.
>

OK, thanks. One tiny snag that I would like to fix up once we have
some Acks to add: I just noticed that i removed the 'static' from
handle_kernel_image()'s definition from arm64 in 4/5, but removed it
from the forward declaration in 5/5, which likely breaks bisect for
arm64 if you happen to end up right in the middle.

Regards,
Ard.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 0/5] efistub: convert into static library
@ 2014-07-01 18:55         ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-01 18:55 UTC (permalink / raw)
  To: linux-arm-kernel

On 1 July 2014 20:39, Matt Fleming <matt@console-pimps.org> wrote:
> On Thu, 26 Jun, at 04:23:32PM, Ard Biesheuvel wrote:
>> This is v2 of the series to change the #include "../../../../xxx.c" pattern
>> into a static library linked into either the kernel (arm64) or a separate boot
>> decompressor (x86, ARM).
>>
>> Changes since v1:
>> - added patch #1 to change EFI_ERROR, it is not a result code defined by UEFI so
>>   it should only be returned by get_dram_base() and efi_entry()
>> - added a section to libstub Makefile to clean CFLAGS of stack protecter and
>>   other options that are inappropriate for the stub
>> - rebased onto the UEFI Runtime Services NEON patches (re)posted earlier today
>>
>> Ard Biesheuvel (5):
>>   efi/arm64: avoid EFI_ERROR as a generic return code
>>   efi/x86: efistub: move shared dependencies to <asm/efi.h>
>>   efi/arm64: efistub: move shared dependencies to <asm/efi.h>
>>   efi: efistub: refactor stub components
>>   efi: efistub: convert into static library
>
> Thanks Ard. I've picked these up.
>

OK, thanks. One tiny snag that I would like to fix up once we have
some Acks to add: I just noticed that i removed the 'static' from
handle_kernel_image()'s definition from arm64 in 4/5, but removed it
from the forward declaration in 5/5, which likely breaks bisect for
arm64 if you happen to end up right in the middle.

Regards,
Ard.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 0/5] efistub: convert into static library
  2014-07-01 18:55         ` Ard Biesheuvel
@ 2014-07-01 19:01             ` Matt Fleming
  -1 siblings, 0 replies; 36+ messages in thread
From: Matt Fleming @ 2014-07-01 19:01 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Matt Fleming, x86-DgEjT+Ai2ygdnm+yROfE0A, Catalin Marinas,
	linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, Leif Lindholm, Roy Franz,
	Mark Salter

On Tue, 01 Jul, at 08:55:20PM, Ard Biesheuvel wrote:
> 
> OK, thanks. One tiny snag that I would like to fix up once we have
> some Acks to add: I just noticed that i removed the 'static' from
> handle_kernel_image()'s definition from arm64 in 4/5, but removed it
> from the forward declaration in 5/5, which likely breaks bisect for
> arm64 if you happen to end up right in the middle.

Good catch.

I rebase 'next' pretty feely, so just remind me at some point in the
future and we can fix this up.

-- 
Matt Fleming, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 0/5] efistub: convert into static library
@ 2014-07-01 19:01             ` Matt Fleming
  0 siblings, 0 replies; 36+ messages in thread
From: Matt Fleming @ 2014-07-01 19:01 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 01 Jul, at 08:55:20PM, Ard Biesheuvel wrote:
> 
> OK, thanks. One tiny snag that I would like to fix up once we have
> some Acks to add: I just noticed that i removed the 'static' from
> handle_kernel_image()'s definition from arm64 in 4/5, but removed it
> from the forward declaration in 5/5, which likely breaks bisect for
> arm64 if you happen to end up right in the middle.

Good catch.

I rebase 'next' pretty feely, so just remind me at some point in the
future and we can fix this up.

-- 
Matt Fleming, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 5/5] efi: efistub: convert into static library
  2014-06-26 14:23     ` Ard Biesheuvel
@ 2014-07-02 11:15         ` Matt Fleming
  -1 siblings, 0 replies; 36+ messages in thread
From: Matt Fleming @ 2014-07-02 11:15 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: matt.fleming-ral2JQCrhuEAvxtiuMwx3w, x86-DgEjT+Ai2ygdnm+yROfE0A,
	catalin.marinas-5wv7dgnIgG8, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, leif.lindholm-QSEj5FYQhm4dnm+yROfE0A,
	roy.franz-QSEj5FYQhm4dnm+yROfE0A, msalter-H+wXaHxf7aLQT0dZR+AlfA

On Thu, 26 Jun, at 04:23:37PM, Ard Biesheuvel wrote:
> This patch changes both x86 and arm64 efistub implementations from #including
> shared .c files under drivers/firmware/efi to building the shared code as a
> static library.
> 
> The x86 code uses a stub built into the boot executable which uncompresses the
> kernel at boot time. In this case, the library is linked into the decompressor.
> 
> In the arm64 case, the stub is part of the kernel proper so the library is
> linked into the kernel proper as well.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

OK, this breaks the ia64 build because of the following...

/drivers/firmware/efi/libstub/efi-stub-helper.c:14:21: fatal error: asm/efi.h: No such file or directory

> diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
> index e1096539eedb..d9abdbc962f1 100644
> --- a/drivers/firmware/efi/Makefile
> +++ b/drivers/firmware/efi/Makefile
> @@ -1,7 +1,7 @@
>  #
>  # Makefile for linux kernel
>  #
> -obj-$(CONFIG_EFI)			+= efi.o vars.o
> +obj-$(CONFIG_EFI)			+= efi.o vars.o libstub/
>  obj-$(CONFIG_EFI_VARS)			+= efivars.o
>  obj-$(CONFIG_EFI_VARS_PSTORE)		+= efi-pstore.o
>  obj-$(CONFIG_UEFI_CPER)			+= cper.o

I guess what we need is CONFIG_EFI_LIBSTUB selected by both
CONFIG_EFI_STUB (for x86) and CONFIG_EFI_ARMSTUB (for arm64)? e.g.

obj-$(CONFIG_EFI_LIBSTUB)		libstub/

-- 
Matt Fleming, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 5/5] efi: efistub: convert into static library
@ 2014-07-02 11:15         ` Matt Fleming
  0 siblings, 0 replies; 36+ messages in thread
From: Matt Fleming @ 2014-07-02 11:15 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 26 Jun, at 04:23:37PM, Ard Biesheuvel wrote:
> This patch changes both x86 and arm64 efistub implementations from #including
> shared .c files under drivers/firmware/efi to building the shared code as a
> static library.
> 
> The x86 code uses a stub built into the boot executable which uncompresses the
> kernel at boot time. In this case, the library is linked into the decompressor.
> 
> In the arm64 case, the stub is part of the kernel proper so the library is
> linked into the kernel proper as well.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

OK, this breaks the ia64 build because of the following...

/drivers/firmware/efi/libstub/efi-stub-helper.c:14:21: fatal error: asm/efi.h: No such file or directory

> diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
> index e1096539eedb..d9abdbc962f1 100644
> --- a/drivers/firmware/efi/Makefile
> +++ b/drivers/firmware/efi/Makefile
> @@ -1,7 +1,7 @@
>  #
>  # Makefile for linux kernel
>  #
> -obj-$(CONFIG_EFI)			+= efi.o vars.o
> +obj-$(CONFIG_EFI)			+= efi.o vars.o libstub/
>  obj-$(CONFIG_EFI_VARS)			+= efivars.o
>  obj-$(CONFIG_EFI_VARS_PSTORE)		+= efi-pstore.o
>  obj-$(CONFIG_UEFI_CPER)			+= cper.o

I guess what we need is CONFIG_EFI_LIBSTUB selected by both
CONFIG_EFI_STUB (for x86) and CONFIG_EFI_ARMSTUB (for arm64)? e.g.

obj-$(CONFIG_EFI_LIBSTUB)		libstub/

-- 
Matt Fleming, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 5/5] efi: efistub: convert into static library
  2014-07-02 11:15         ` Matt Fleming
@ 2014-07-02 11:23             ` Ard Biesheuvel
  -1 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-02 11:23 UTC (permalink / raw)
  To: Matt Fleming
  Cc: Matt Fleming, x86-DgEjT+Ai2ygdnm+yROfE0A, Catalin Marinas,
	linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, Leif Lindholm, Roy Franz,
	Mark Salter

On 2 July 2014 13:15, Matt Fleming <matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org> wrote:
> On Thu, 26 Jun, at 04:23:37PM, Ard Biesheuvel wrote:
>> This patch changes both x86 and arm64 efistub implementations from #including
>> shared .c files under drivers/firmware/efi to building the shared code as a
>> static library.
>>
>> The x86 code uses a stub built into the boot executable which uncompresses the
>> kernel at boot time. In this case, the library is linked into the decompressor.
>>
>> In the arm64 case, the stub is part of the kernel proper so the library is
>> linked into the kernel proper as well.
>>
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>
> OK, this breaks the ia64 build because of the following...
>
> /drivers/firmware/efi/libstub/efi-stub-helper.c:14:21: fatal error: asm/efi.h: No such file or directory
>
>> diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
>> index e1096539eedb..d9abdbc962f1 100644
>> --- a/drivers/firmware/efi/Makefile
>> +++ b/drivers/firmware/efi/Makefile
>> @@ -1,7 +1,7 @@
>>  #
>>  # Makefile for linux kernel
>>  #
>> -obj-$(CONFIG_EFI)                    += efi.o vars.o
>> +obj-$(CONFIG_EFI)                    += efi.o vars.o libstub/
>>  obj-$(CONFIG_EFI_VARS)                       += efivars.o
>>  obj-$(CONFIG_EFI_VARS_PSTORE)                += efi-pstore.o
>>  obj-$(CONFIG_UEFI_CPER)                      += cper.o
>
> I guess what we need is CONFIG_EFI_LIBSTUB selected by both
> CONFIG_EFI_STUB (for x86) and CONFIG_EFI_ARMSTUB (for arm64)? e.g.
>
> obj-$(CONFIG_EFI_LIBSTUB)               libstub/
>

Yes, that seems the appropriate way to deal with this.
Let me respin so I can fix the other thing I mentioned yesterday as well.

-- 
Ard.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 5/5] efi: efistub: convert into static library
@ 2014-07-02 11:23             ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-02 11:23 UTC (permalink / raw)
  To: linux-arm-kernel

On 2 July 2014 13:15, Matt Fleming <matt@console-pimps.org> wrote:
> On Thu, 26 Jun, at 04:23:37PM, Ard Biesheuvel wrote:
>> This patch changes both x86 and arm64 efistub implementations from #including
>> shared .c files under drivers/firmware/efi to building the shared code as a
>> static library.
>>
>> The x86 code uses a stub built into the boot executable which uncompresses the
>> kernel at boot time. In this case, the library is linked into the decompressor.
>>
>> In the arm64 case, the stub is part of the kernel proper so the library is
>> linked into the kernel proper as well.
>>
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>
> OK, this breaks the ia64 build because of the following...
>
> /drivers/firmware/efi/libstub/efi-stub-helper.c:14:21: fatal error: asm/efi.h: No such file or directory
>
>> diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
>> index e1096539eedb..d9abdbc962f1 100644
>> --- a/drivers/firmware/efi/Makefile
>> +++ b/drivers/firmware/efi/Makefile
>> @@ -1,7 +1,7 @@
>>  #
>>  # Makefile for linux kernel
>>  #
>> -obj-$(CONFIG_EFI)                    += efi.o vars.o
>> +obj-$(CONFIG_EFI)                    += efi.o vars.o libstub/
>>  obj-$(CONFIG_EFI_VARS)                       += efivars.o
>>  obj-$(CONFIG_EFI_VARS_PSTORE)                += efi-pstore.o
>>  obj-$(CONFIG_UEFI_CPER)                      += cper.o
>
> I guess what we need is CONFIG_EFI_LIBSTUB selected by both
> CONFIG_EFI_STUB (for x86) and CONFIG_EFI_ARMSTUB (for arm64)? e.g.
>
> obj-$(CONFIG_EFI_LIBSTUB)               libstub/
>

Yes, that seems the appropriate way to deal with this.
Let me respin so I can fix the other thing I mentioned yesterday as well.

-- 
Ard.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 5/5] efi: efistub: convert into static library
  2014-07-02 11:23             ` Ard Biesheuvel
@ 2014-07-02 11:49                 ` Ard Biesheuvel
  -1 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-02 11:49 UTC (permalink / raw)
  To: Matt Fleming
  Cc: Matt Fleming, x86-DgEjT+Ai2ygdnm+yROfE0A, Catalin Marinas,
	linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, Leif Lindholm, Roy Franz,
	Mark Salter

Would something like this

ifneq ($(CONFIG_EFI_STUB)$(CONFIG_EFI_ARMSTUB),nn)
obj-y += libstub/
endif

be too hideous?



On 2 July 2014 13:23, Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> wrote:
> On 2 July 2014 13:15, Matt Fleming <matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org> wrote:
>> On Thu, 26 Jun, at 04:23:37PM, Ard Biesheuvel wrote:
>>> This patch changes both x86 and arm64 efistub implementations from #including
>>> shared .c files under drivers/firmware/efi to building the shared code as a
>>> static library.
>>>
>>> The x86 code uses a stub built into the boot executable which uncompresses the
>>> kernel at boot time. In this case, the library is linked into the decompressor.
>>>
>>> In the arm64 case, the stub is part of the kernel proper so the library is
>>> linked into the kernel proper as well.
>>>
>>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>>
>> OK, this breaks the ia64 build because of the following...
>>
>> /drivers/firmware/efi/libstub/efi-stub-helper.c:14:21: fatal error: asm/efi.h: No such file or directory
>>
>>> diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
>>> index e1096539eedb..d9abdbc962f1 100644
>>> --- a/drivers/firmware/efi/Makefile
>>> +++ b/drivers/firmware/efi/Makefile
>>> @@ -1,7 +1,7 @@
>>>  #
>>>  # Makefile for linux kernel
>>>  #
>>> -obj-$(CONFIG_EFI)                    += efi.o vars.o
>>> +obj-$(CONFIG_EFI)                    += efi.o vars.o libstub/
>>>  obj-$(CONFIG_EFI_VARS)                       += efivars.o
>>>  obj-$(CONFIG_EFI_VARS_PSTORE)                += efi-pstore.o
>>>  obj-$(CONFIG_UEFI_CPER)                      += cper.o
>>
>> I guess what we need is CONFIG_EFI_LIBSTUB selected by both
>> CONFIG_EFI_STUB (for x86) and CONFIG_EFI_ARMSTUB (for arm64)? e.g.
>>
>> obj-$(CONFIG_EFI_LIBSTUB)               libstub/
>>
>
> Yes, that seems the appropriate way to deal with this.
> Let me respin so I can fix the other thing I mentioned yesterday as well.
>
> --
> Ard.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 5/5] efi: efistub: convert into static library
@ 2014-07-02 11:49                 ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-02 11:49 UTC (permalink / raw)
  To: linux-arm-kernel

Would something like this

ifneq ($(CONFIG_EFI_STUB)$(CONFIG_EFI_ARMSTUB),nn)
obj-y += libstub/
endif

be too hideous?



On 2 July 2014 13:23, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> On 2 July 2014 13:15, Matt Fleming <matt@console-pimps.org> wrote:
>> On Thu, 26 Jun, at 04:23:37PM, Ard Biesheuvel wrote:
>>> This patch changes both x86 and arm64 efistub implementations from #including
>>> shared .c files under drivers/firmware/efi to building the shared code as a
>>> static library.
>>>
>>> The x86 code uses a stub built into the boot executable which uncompresses the
>>> kernel at boot time. In this case, the library is linked into the decompressor.
>>>
>>> In the arm64 case, the stub is part of the kernel proper so the library is
>>> linked into the kernel proper as well.
>>>
>>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>>
>> OK, this breaks the ia64 build because of the following...
>>
>> /drivers/firmware/efi/libstub/efi-stub-helper.c:14:21: fatal error: asm/efi.h: No such file or directory
>>
>>> diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
>>> index e1096539eedb..d9abdbc962f1 100644
>>> --- a/drivers/firmware/efi/Makefile
>>> +++ b/drivers/firmware/efi/Makefile
>>> @@ -1,7 +1,7 @@
>>>  #
>>>  # Makefile for linux kernel
>>>  #
>>> -obj-$(CONFIG_EFI)                    += efi.o vars.o
>>> +obj-$(CONFIG_EFI)                    += efi.o vars.o libstub/
>>>  obj-$(CONFIG_EFI_VARS)                       += efivars.o
>>>  obj-$(CONFIG_EFI_VARS_PSTORE)                += efi-pstore.o
>>>  obj-$(CONFIG_UEFI_CPER)                      += cper.o
>>
>> I guess what we need is CONFIG_EFI_LIBSTUB selected by both
>> CONFIG_EFI_STUB (for x86) and CONFIG_EFI_ARMSTUB (for arm64)? e.g.
>>
>> obj-$(CONFIG_EFI_LIBSTUB)               libstub/
>>
>
> Yes, that seems the appropriate way to deal with this.
> Let me respin so I can fix the other thing I mentioned yesterday as well.
>
> --
> Ard.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 2/5] efi/x86: efistub: move shared dependencies to <asm/efi.h>
  2014-06-26 14:23     ` Ard Biesheuvel
@ 2014-07-02 12:59         ` Mark Salter
  -1 siblings, 0 replies; 36+ messages in thread
From: Mark Salter @ 2014-07-02 12:59 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: matt.fleming-ral2JQCrhuEAvxtiuMwx3w, x86-DgEjT+Ai2ygdnm+yROfE0A,
	catalin.marinas-5wv7dgnIgG8, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, leif.lindholm-QSEj5FYQhm4dnm+yROfE0A,
	roy.franz-QSEj5FYQhm4dnm+yROfE0A

On Thu, 2014-06-26 at 16:23 +0200, Ard Biesheuvel wrote:
> This moves definitions depended upon both by code under arch/x86/boot and
> under drivers/firmware/efi to <asm/efi.h>. This is in preparation of turning
> the stub code under drivers/firmware/efi into a static library.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
>  arch/x86/boot/compressed/eboot.c |  5 +----
>  arch/x86/boot/compressed/eboot.h | 16 ----------------
>  arch/x86/include/asm/efi.h       | 25 +++++++++++++++++++++++++
>  3 files changed, 26 insertions(+), 20 deletions(-)
> 
> diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
> index 0331d765c2bb..2fd5e2643623 100644
> --- a/arch/x86/boot/compressed/eboot.c
> +++ b/arch/x86/boot/compressed/eboot.c
> @@ -19,10 +19,7 @@
>  
>  static efi_system_table_t *sys_table;
>  
> -static struct efi_config *efi_early;
> -
> -#define efi_call_early(f, ...)						\
> -	efi_early->call(efi_early->f, __VA_ARGS__);
> +struct efi_config *efi_early;
>  
>  #define BOOT_SERVICES(bits)						\
>  static void setup_boot_services##bits(struct efi_config *c)		\
> diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h
> index c88c31ecad12..d487e727f1ec 100644
> --- a/arch/x86/boot/compressed/eboot.h
> +++ b/arch/x86/boot/compressed/eboot.h
> @@ -103,20 +103,4 @@ struct efi_uga_draw_protocol {
>  	void *blt;
>  };
>  
> -struct efi_config {
> -	u64 image_handle;
> -	u64 table;
> -	u64 allocate_pool;
> -	u64 allocate_pages;
> -	u64 get_memory_map;
> -	u64 free_pool;
> -	u64 free_pages;
> -	u64 locate_handle;
> -	u64 handle_protocol;
> -	u64 exit_boot_services;
> -	u64 text_output;
> -	efi_status_t (*call)(unsigned long, ...);
> -	bool is64;
> -} __packed;
> -
>  #endif /* BOOT_COMPRESSED_EBOOT_H */
> diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
> index 1eb5f6433ad8..55059a50a01f 100644
> --- a/arch/x86/include/asm/efi.h
> +++ b/arch/x86/include/asm/efi.h
> @@ -156,6 +156,31 @@ static inline efi_status_t efi_thunk_set_virtual_address_map(
>  	return EFI_SUCCESS;
>  }
>  #endif /* CONFIG_EFI_MIXED */
> +
> +
> +/* arch specific definitions used by the stub code */
> +
> +struct efi_config {
> +	u64 image_handle;
> +	u64 table;
> +	u64 allocate_pool;
> +	u64 allocate_pages;
> +	u64 get_memory_map;
> +	u64 free_pool;
> +	u64 free_pages;
> +	u64 locate_handle;
> +	u64 handle_protocol;
> +	u64 exit_boot_services;
> +	u64 text_output;
> +	efi_status_t (*call)(unsigned long, ...);
> +	bool is64;
> +} __packed;
> +
> +extern struct efi_config *efi_early;
> +
> +#define efi_call_early(f, ...)						\
> +	efi_early->call(efi_early->f, __VA_ARGS__);

That shouldn't have the trailing ;

> +
>  #else
>  /*
>   * IF EFI is not configured, have the EFI calls return -ENOSYS.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 2/5] efi/x86: efistub: move shared dependencies to <asm/efi.h>
@ 2014-07-02 12:59         ` Mark Salter
  0 siblings, 0 replies; 36+ messages in thread
From: Mark Salter @ 2014-07-02 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 2014-06-26 at 16:23 +0200, Ard Biesheuvel wrote:
> This moves definitions depended upon both by code under arch/x86/boot and
> under drivers/firmware/efi to <asm/efi.h>. This is in preparation of turning
> the stub code under drivers/firmware/efi into a static library.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  arch/x86/boot/compressed/eboot.c |  5 +----
>  arch/x86/boot/compressed/eboot.h | 16 ----------------
>  arch/x86/include/asm/efi.h       | 25 +++++++++++++++++++++++++
>  3 files changed, 26 insertions(+), 20 deletions(-)
> 
> diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
> index 0331d765c2bb..2fd5e2643623 100644
> --- a/arch/x86/boot/compressed/eboot.c
> +++ b/arch/x86/boot/compressed/eboot.c
> @@ -19,10 +19,7 @@
>  
>  static efi_system_table_t *sys_table;
>  
> -static struct efi_config *efi_early;
> -
> -#define efi_call_early(f, ...)						\
> -	efi_early->call(efi_early->f, __VA_ARGS__);
> +struct efi_config *efi_early;
>  
>  #define BOOT_SERVICES(bits)						\
>  static void setup_boot_services##bits(struct efi_config *c)		\
> diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h
> index c88c31ecad12..d487e727f1ec 100644
> --- a/arch/x86/boot/compressed/eboot.h
> +++ b/arch/x86/boot/compressed/eboot.h
> @@ -103,20 +103,4 @@ struct efi_uga_draw_protocol {
>  	void *blt;
>  };
>  
> -struct efi_config {
> -	u64 image_handle;
> -	u64 table;
> -	u64 allocate_pool;
> -	u64 allocate_pages;
> -	u64 get_memory_map;
> -	u64 free_pool;
> -	u64 free_pages;
> -	u64 locate_handle;
> -	u64 handle_protocol;
> -	u64 exit_boot_services;
> -	u64 text_output;
> -	efi_status_t (*call)(unsigned long, ...);
> -	bool is64;
> -} __packed;
> -
>  #endif /* BOOT_COMPRESSED_EBOOT_H */
> diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
> index 1eb5f6433ad8..55059a50a01f 100644
> --- a/arch/x86/include/asm/efi.h
> +++ b/arch/x86/include/asm/efi.h
> @@ -156,6 +156,31 @@ static inline efi_status_t efi_thunk_set_virtual_address_map(
>  	return EFI_SUCCESS;
>  }
>  #endif /* CONFIG_EFI_MIXED */
> +
> +
> +/* arch specific definitions used by the stub code */
> +
> +struct efi_config {
> +	u64 image_handle;
> +	u64 table;
> +	u64 allocate_pool;
> +	u64 allocate_pages;
> +	u64 get_memory_map;
> +	u64 free_pool;
> +	u64 free_pages;
> +	u64 locate_handle;
> +	u64 handle_protocol;
> +	u64 exit_boot_services;
> +	u64 text_output;
> +	efi_status_t (*call)(unsigned long, ...);
> +	bool is64;
> +} __packed;
> +
> +extern struct efi_config *efi_early;
> +
> +#define efi_call_early(f, ...)						\
> +	efi_early->call(efi_early->f, __VA_ARGS__);

That shouldn't have the trailing ;

> +
>  #else
>  /*
>   * IF EFI is not configured, have the EFI calls return -ENOSYS.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 2/5] efi/x86: efistub: move shared dependencies to <asm/efi.h>
  2014-07-02 12:59         ` Mark Salter
@ 2014-07-02 13:02             ` Ard Biesheuvel
  -1 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-02 13:02 UTC (permalink / raw)
  To: Mark Salter
  Cc: Matt Fleming, x86-DgEjT+Ai2ygdnm+yROfE0A, Catalin Marinas,
	linux-efi-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, Leif Lindholm, Roy Franz

On 2 July 2014 14:59, Mark Salter <msalter-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
> On Thu, 2014-06-26 at 16:23 +0200, Ard Biesheuvel wrote:
>> This moves definitions depended upon both by code under arch/x86/boot and
>> under drivers/firmware/efi to <asm/efi.h>. This is in preparation of turning
>> the stub code under drivers/firmware/efi into a static library.
>>
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>> ---
>>  arch/x86/boot/compressed/eboot.c |  5 +----
>>  arch/x86/boot/compressed/eboot.h | 16 ----------------
>>  arch/x86/include/asm/efi.h       | 25 +++++++++++++++++++++++++
>>  3 files changed, 26 insertions(+), 20 deletions(-)
>>
>> diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
>> index 0331d765c2bb..2fd5e2643623 100644
>> --- a/arch/x86/boot/compressed/eboot.c
>> +++ b/arch/x86/boot/compressed/eboot.c
>> @@ -19,10 +19,7 @@
>>
>>  static efi_system_table_t *sys_table;
>>
>> -static struct efi_config *efi_early;
>> -
>> -#define efi_call_early(f, ...)                                               \
>> -     efi_early->call(efi_early->f, __VA_ARGS__);
>> +struct efi_config *efi_early;
>>
>>  #define BOOT_SERVICES(bits)                                          \
>>  static void setup_boot_services##bits(struct efi_config *c)          \
>> diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h
>> index c88c31ecad12..d487e727f1ec 100644
>> --- a/arch/x86/boot/compressed/eboot.h
>> +++ b/arch/x86/boot/compressed/eboot.h
>> @@ -103,20 +103,4 @@ struct efi_uga_draw_protocol {
>>       void *blt;
>>  };
>>
>> -struct efi_config {
>> -     u64 image_handle;
>> -     u64 table;
>> -     u64 allocate_pool;
>> -     u64 allocate_pages;
>> -     u64 get_memory_map;
>> -     u64 free_pool;
>> -     u64 free_pages;
>> -     u64 locate_handle;
>> -     u64 handle_protocol;
>> -     u64 exit_boot_services;
>> -     u64 text_output;
>> -     efi_status_t (*call)(unsigned long, ...);
>> -     bool is64;
>> -} __packed;
>> -
>>  #endif /* BOOT_COMPRESSED_EBOOT_H */
>> diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
>> index 1eb5f6433ad8..55059a50a01f 100644
>> --- a/arch/x86/include/asm/efi.h
>> +++ b/arch/x86/include/asm/efi.h
>> @@ -156,6 +156,31 @@ static inline efi_status_t efi_thunk_set_virtual_address_map(
>>       return EFI_SUCCESS;
>>  }
>>  #endif /* CONFIG_EFI_MIXED */
>> +
>> +
>> +/* arch specific definitions used by the stub code */
>> +
>> +struct efi_config {
>> +     u64 image_handle;
>> +     u64 table;
>> +     u64 allocate_pool;
>> +     u64 allocate_pages;
>> +     u64 get_memory_map;
>> +     u64 free_pool;
>> +     u64 free_pages;
>> +     u64 locate_handle;
>> +     u64 handle_protocol;
>> +     u64 exit_boot_services;
>> +     u64 text_output;
>> +     efi_status_t (*call)(unsigned long, ...);
>> +     bool is64;
>> +} __packed;
>> +
>> +extern struct efi_config *efi_early;
>> +
>> +#define efi_call_early(f, ...)                                               \
>> +     efi_early->call(efi_early->f, __VA_ARGS__);
>
> That shouldn't have the trailing ;
>

Hmm, perhaps not.
This patch just moves stuff around, so fixing this should probably be
done in a separate patch.

-- 
Ard.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 2/5] efi/x86: efistub: move shared dependencies to <asm/efi.h>
@ 2014-07-02 13:02             ` Ard Biesheuvel
  0 siblings, 0 replies; 36+ messages in thread
From: Ard Biesheuvel @ 2014-07-02 13:02 UTC (permalink / raw)
  To: linux-arm-kernel

On 2 July 2014 14:59, Mark Salter <msalter@redhat.com> wrote:
> On Thu, 2014-06-26 at 16:23 +0200, Ard Biesheuvel wrote:
>> This moves definitions depended upon both by code under arch/x86/boot and
>> under drivers/firmware/efi to <asm/efi.h>. This is in preparation of turning
>> the stub code under drivers/firmware/efi into a static library.
>>
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> ---
>>  arch/x86/boot/compressed/eboot.c |  5 +----
>>  arch/x86/boot/compressed/eboot.h | 16 ----------------
>>  arch/x86/include/asm/efi.h       | 25 +++++++++++++++++++++++++
>>  3 files changed, 26 insertions(+), 20 deletions(-)
>>
>> diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
>> index 0331d765c2bb..2fd5e2643623 100644
>> --- a/arch/x86/boot/compressed/eboot.c
>> +++ b/arch/x86/boot/compressed/eboot.c
>> @@ -19,10 +19,7 @@
>>
>>  static efi_system_table_t *sys_table;
>>
>> -static struct efi_config *efi_early;
>> -
>> -#define efi_call_early(f, ...)                                               \
>> -     efi_early->call(efi_early->f, __VA_ARGS__);
>> +struct efi_config *efi_early;
>>
>>  #define BOOT_SERVICES(bits)                                          \
>>  static void setup_boot_services##bits(struct efi_config *c)          \
>> diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h
>> index c88c31ecad12..d487e727f1ec 100644
>> --- a/arch/x86/boot/compressed/eboot.h
>> +++ b/arch/x86/boot/compressed/eboot.h
>> @@ -103,20 +103,4 @@ struct efi_uga_draw_protocol {
>>       void *blt;
>>  };
>>
>> -struct efi_config {
>> -     u64 image_handle;
>> -     u64 table;
>> -     u64 allocate_pool;
>> -     u64 allocate_pages;
>> -     u64 get_memory_map;
>> -     u64 free_pool;
>> -     u64 free_pages;
>> -     u64 locate_handle;
>> -     u64 handle_protocol;
>> -     u64 exit_boot_services;
>> -     u64 text_output;
>> -     efi_status_t (*call)(unsigned long, ...);
>> -     bool is64;
>> -} __packed;
>> -
>>  #endif /* BOOT_COMPRESSED_EBOOT_H */
>> diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
>> index 1eb5f6433ad8..55059a50a01f 100644
>> --- a/arch/x86/include/asm/efi.h
>> +++ b/arch/x86/include/asm/efi.h
>> @@ -156,6 +156,31 @@ static inline efi_status_t efi_thunk_set_virtual_address_map(
>>       return EFI_SUCCESS;
>>  }
>>  #endif /* CONFIG_EFI_MIXED */
>> +
>> +
>> +/* arch specific definitions used by the stub code */
>> +
>> +struct efi_config {
>> +     u64 image_handle;
>> +     u64 table;
>> +     u64 allocate_pool;
>> +     u64 allocate_pages;
>> +     u64 get_memory_map;
>> +     u64 free_pool;
>> +     u64 free_pages;
>> +     u64 locate_handle;
>> +     u64 handle_protocol;
>> +     u64 exit_boot_services;
>> +     u64 text_output;
>> +     efi_status_t (*call)(unsigned long, ...);
>> +     bool is64;
>> +} __packed;
>> +
>> +extern struct efi_config *efi_early;
>> +
>> +#define efi_call_early(f, ...)                                               \
>> +     efi_early->call(efi_early->f, __VA_ARGS__);
>
> That shouldn't have the trailing ;
>

Hmm, perhaps not.
This patch just moves stuff around, so fixing this should probably be
done in a separate patch.

-- 
Ard.

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2014-07-02 13:02 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-26 14:23 [PATCH v2 0/5] efistub: convert into static library Ard Biesheuvel
2014-06-26 14:23 ` Ard Biesheuvel
     [not found] ` <1403792617-25792-1-git-send-email-ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2014-06-26 14:23   ` [PATCH v2 1/5] efi/arm64: avoid EFI_ERROR as a generic return code Ard Biesheuvel
2014-06-26 14:23     ` Ard Biesheuvel
2014-06-26 14:23   ` [PATCH v2 2/5] efi/x86: efistub: move shared dependencies to <asm/efi.h> Ard Biesheuvel
2014-06-26 14:23     ` Ard Biesheuvel
     [not found]     ` <1403792617-25792-3-git-send-email-ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2014-07-02 12:59       ` Mark Salter
2014-07-02 12:59         ` Mark Salter
     [not found]         ` <1404305996.19665.7.camel-PDpCo7skNiwAicBL8TP8PQ@public.gmane.org>
2014-07-02 13:02           ` Ard Biesheuvel
2014-07-02 13:02             ` Ard Biesheuvel
2014-06-26 14:23   ` [PATCH v2 3/5] efi/arm64: " Ard Biesheuvel
2014-06-26 14:23     ` Ard Biesheuvel
2014-06-26 14:23   ` [PATCH v2 4/5] efi: efistub: refactor stub components Ard Biesheuvel
2014-06-26 14:23     ` Ard Biesheuvel
     [not found]     ` <1403792617-25792-5-git-send-email-ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2014-07-01 15:11       ` Matt Fleming
2014-07-01 15:11         ` Matt Fleming
     [not found]         ` <20140701151130.GF7539-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2014-07-01 15:18           ` Ard Biesheuvel
2014-07-01 15:18             ` Ard Biesheuvel
     [not found]             ` <CAKv+Gu9tY7RqVXdWejwOPnpBTX0S5M9QxBH2te71kpysOV3vWA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-01 15:20               ` Ard Biesheuvel
2014-07-01 15:20                 ` Ard Biesheuvel
     [not found]                 ` <CAKv+Gu8sHpHNEJhDrrJcN12rVrhRgprzmNeJ_BoMCbL+Gh2-NQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-01 16:22                   ` Matt Fleming
2014-07-01 16:22                     ` Matt Fleming
2014-06-26 14:23   ` [PATCH v2 5/5] efi: efistub: convert into static library Ard Biesheuvel
2014-06-26 14:23     ` Ard Biesheuvel
     [not found]     ` <1403792617-25792-6-git-send-email-ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2014-07-02 11:15       ` Matt Fleming
2014-07-02 11:15         ` Matt Fleming
     [not found]         ` <20140702111528.GL7539-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2014-07-02 11:23           ` Ard Biesheuvel
2014-07-02 11:23             ` Ard Biesheuvel
     [not found]             ` <CAKv+Gu9N_p49603oy0rKaq+G6sX+GS5ueSfJ2B=Yh7DrF301Cg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-02 11:49               ` Ard Biesheuvel
2014-07-02 11:49                 ` Ard Biesheuvel
2014-07-01 18:39   ` [PATCH v2 0/5] " Matt Fleming
2014-07-01 18:39     ` Matt Fleming
     [not found]     ` <20140701183906.GH7539-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2014-07-01 18:55       ` Ard Biesheuvel
2014-07-01 18:55         ` Ard Biesheuvel
     [not found]         ` <CAKv+Gu8eN4s9V6=mmQFpMDKuuMRE0y5T6pxk27=BLMFRX1O57w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-01 19:01           ` Matt Fleming
2014-07-01 19:01             ` Matt Fleming

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.