* [U-Boot] [PATCH 1/3] efi_loader: provide freestanding library
2019-01-20 7:20 [U-Boot] [PATCH 0/3] efi_loader: provide library for freestanding binaries Heinrich Schuchardt
@ 2019-01-20 7:20 ` Heinrich Schuchardt
2019-01-20 7:20 ` [U-Boot] [PATCH 2/3] efi_loader: use freestanding library for efi apps Heinrich Schuchardt
2019-01-20 7:20 ` [U-Boot] [PATCH 3/3] efi_loader: use library memcpy() in helloworld.efi Heinrich Schuchardt
2 siblings, 0 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2019-01-20 7:20 UTC (permalink / raw)
To: u-boot
GCC requires that freestanding programs provide memcpy(), memmove(),
memset(), and memcmp().
Provide the required library functions.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
lib/efi_loader/efi_freestanding.c | 90 +++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
create mode 100644 lib/efi_loader/efi_freestanding.c
diff --git a/lib/efi_loader/efi_freestanding.c b/lib/efi_loader/efi_freestanding.c
new file mode 100644
index 0000000000..bd9da5bbc8
--- /dev/null
+++ b/lib/efi_loader/efi_freestanding.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Library for freestanding binary
+ *
+ * Copyright 2019, Heinrich Schuchardt <xypron.glpk@gmx.de>
+ *
+ * GCC requires that freestanding programs provide memcpy(), memmove(),
+ * memset(), and memcmp().
+ */
+
+#include <common.h>
+
+/**
+ * memcmp() - compare memory areas
+ *
+ * @s1: pointer to first area
+ * @s2: pointer to second area
+ * @n: number of bytes to compare
+ * Return: 0 if both memory areas are the same, otherwise the sign of the
+ * result value is the same as the sign of the difference between
+ * the first differing pair of bytes taken as u8.
+ */
+int memcmp(const void *s1, const void *s2, size_t n)
+{
+ const u8 *pos1 = s1;
+ const u8 *pos2 = s2;
+
+ for (; n; --n) {
+ if (*pos1 != *pos2)
+ return *pos1 - *pos2;
+ ++pos1;
+ ++pos2;
+ }
+ return 0;
+}
+
+/**
+ * memcpy() - copy memory area
+ *
+ * @dest: destination buffer
+ * @src: source buffer
+ * @n: number of bytes to copy
+ * Return: pointer to destination buffer
+ */
+void *memmove(void *dest, const void *src, size_t n)
+{
+ u8 *d = dest;
+ const u8 *s = src;
+
+ if (d >= s) {
+ for (; n; --n)
+ *d++ = *s++;
+ } else {
+ d += n;
+ s += n;
+ for (; n; --n)
+ *--d = *--s;
+ }
+ return dest;
+}
+
+/**
+ * memcpy() - copy memory area
+ *
+ * @dest: destination buffer
+ * @src: source buffer
+ * @n: number of bytes to copy
+ * Return: pointer to destination buffer
+ */
+void *memcpy(void *dest, const void *src, size_t n)
+{
+ return memmove(dest, src, n);
+}
+
+/**
+ * memset() - fill memory with a constant byte
+ *
+ * @s: destination buffer
+ * @c: byte value
+ * @n: number of bytes to set
+ * Return: pointer to destination buffer
+ */
+void *memset(void *s, int c, size_t n)
+{
+ u8 *d = s;
+
+ for (; n; --n)
+ *d++ = c;
+ return s;
+}
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH 2/3] efi_loader: use freestanding library for efi apps
2019-01-20 7:20 [U-Boot] [PATCH 0/3] efi_loader: provide library for freestanding binaries Heinrich Schuchardt
2019-01-20 7:20 ` [U-Boot] [PATCH 1/3] efi_loader: provide freestanding library Heinrich Schuchardt
@ 2019-01-20 7:20 ` Heinrich Schuchardt
2019-01-21 13:52 ` Alexander Graf
2019-01-20 7:20 ` [U-Boot] [PATCH 3/3] efi_loader: use library memcpy() in helloworld.efi Heinrich Schuchardt
2 siblings, 1 reply; 5+ messages in thread
From: Heinrich Schuchardt @ 2019-01-20 7:20 UTC (permalink / raw)
To: u-boot
GCC requires that freestanding programs provide memcpy(), memmove(),
memset(), and memcmp().
Add the library functions when building a *.efi files.
The EFI selftests might use other compilation flags. So use a symbolic
link to provide lib/efi_selftest/efi_freestanding.c and compile it
separately.
Reported-by: Alexander Graf <agraf@suse.de>
Fixes: 5be444d14b38 ("efi_loader: consistent build flags for EFI applications")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
lib/efi_selftest/efi_freestanding.c | 1 +
scripts/Makefile.lib | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
create mode 120000 lib/efi_selftest/efi_freestanding.c
diff --git a/lib/efi_selftest/efi_freestanding.c b/lib/efi_selftest/efi_freestanding.c
new file mode 120000
index 0000000000..4b7edd52bd
--- /dev/null
+++ b/lib/efi_selftest/efi_freestanding.c
@@ -0,0 +1 @@
+../efi_loader/efi_freestanding.c
\ No newline at end of file
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index a5b57fc6b9..4facb76ace 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -389,7 +389,7 @@ $(obj)/efi_reloc.o: $(srctree)/arch/$(ARCH)/lib/$(EFI_RELOC:.o=.c) $(recordmcoun
$(call cmd,force_checksrc)
$(call if_changed_rule,cc_o_c)
-$(obj)/%_efi.so: $(obj)/%.o $(obj)/efi_crt0.o $(obj)/efi_reloc.o
+$(obj)/%_efi.so: $(obj)/%.o $(obj)/efi_crt0.o $(obj)/efi_reloc.o $(obj)/efi_freestanding.o
$(call cmd,efi_ld)
# ACPI
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH 2/3] efi_loader: use freestanding library for efi apps
2019-01-20 7:20 ` [U-Boot] [PATCH 2/3] efi_loader: use freestanding library for efi apps Heinrich Schuchardt
@ 2019-01-21 13:52 ` Alexander Graf
0 siblings, 0 replies; 5+ messages in thread
From: Alexander Graf @ 2019-01-21 13:52 UTC (permalink / raw)
To: u-boot
On 01/20/2019 08:20 AM, Heinrich Schuchardt wrote:
> GCC requires that freestanding programs provide memcpy(), memmove(),
> memset(), and memcmp().
>
> Add the library functions when building a *.efi files.
>
> The EFI selftests might use other compilation flags. So use a symbolic
> link to provide lib/efi_selftest/efi_freestanding.c and compile it
> separately.
>
> Reported-by: Alexander Graf <agraf@suse.de>
> Fixes: 5be444d14b38 ("efi_loader: consistent build flags for EFI applications")
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> lib/efi_selftest/efi_freestanding.c | 1 +
> scripts/Makefile.lib | 2 +-
> 2 files changed, 2 insertions(+), 1 deletion(-)
> create mode 120000 lib/efi_selftest/efi_freestanding.c
>
> diff --git a/lib/efi_selftest/efi_freestanding.c b/lib/efi_selftest/efi_freestanding.c
> new file mode 120000
> index 0000000000..4b7edd52bd
> --- /dev/null
> +++ b/lib/efi_selftest/efi_freestanding.c
> @@ -0,0 +1 @@
> +../efi_loader/efi_freestanding.c
> \ No newline at end of file
Please try to refrain from using symlinks. I will apply the patch
regardless, but if you can think of a better way to model this, I'm all
for it.
Thanks,
Alex
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH 3/3] efi_loader: use library memcpy() in helloworld.efi
2019-01-20 7:20 [U-Boot] [PATCH 0/3] efi_loader: provide library for freestanding binaries Heinrich Schuchardt
2019-01-20 7:20 ` [U-Boot] [PATCH 1/3] efi_loader: provide freestanding library Heinrich Schuchardt
2019-01-20 7:20 ` [U-Boot] [PATCH 2/3] efi_loader: use freestanding library for efi apps Heinrich Schuchardt
@ 2019-01-20 7:20 ` Heinrich Schuchardt
2 siblings, 0 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2019-01-20 7:20 UTC (permalink / raw)
To: u-boot
Helloworld does not need its own memcpy() implementation anymore. Use the
one provided in efi_freestanding.c.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
lib/efi_loader/helloworld.c | 36 ++++++------------------------------
1 file changed, 6 insertions(+), 30 deletions(-)
diff --git a/lib/efi_loader/helloworld.c b/lib/efi_loader/helloworld.c
index 2905479e65..426f276361 100644
--- a/lib/efi_loader/helloworld.c
+++ b/lib/efi_loader/helloworld.c
@@ -17,30 +17,6 @@ static const efi_guid_t fdt_guid = EFI_FDT_GUID;
static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
-/**
- * hw_memcmp() - compare memory areas
- *
- * @buf1: pointer to first area
- * @buf2: pointer to second area
- * @length: number of bytes to compare
- * Return: 0 if both memory areas are the same, otherwise the sign of the
- * result value is the same as the sign of ghe difference between
- * the first differing pair of bytes taken as u8.
- */
-static int hw_memcmp(const void *buf1, const void *buf2, size_t length)
-{
- const u8 *pos1 = buf1;
- const u8 *pos2 = buf2;
-
- for (; length; --length) {
- if (*pos1 != *pos2)
- return *pos1 - *pos2;
- ++pos1;
- ++pos2;
- }
- return 0;
-}
-
/**
* efi_main() - entry point of the EFI application.
*
@@ -88,16 +64,16 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
}
/* Find configuration tables */
for (i = 0; i < systable->nr_tables; ++i) {
- if (!hw_memcmp(&systable->tables[i].guid, &fdt_guid,
- sizeof(efi_guid_t)))
+ if (!memcmp(&systable->tables[i].guid, &fdt_guid,
+ sizeof(efi_guid_t)))
con_out->output_string
(con_out, L"Have device tree\r\n");
- if (!hw_memcmp(&systable->tables[i].guid, &acpi_guid,
- sizeof(efi_guid_t)))
+ if (!memcmp(&systable->tables[i].guid, &acpi_guid,
+ sizeof(efi_guid_t)))
con_out->output_string
(con_out, L"Have ACPI 2.0 table\r\n");
- if (!hw_memcmp(&systable->tables[i].guid, &smbios_guid,
- sizeof(efi_guid_t)))
+ if (!memcmp(&systable->tables[i].guid, &smbios_guid,
+ sizeof(efi_guid_t)))
con_out->output_string
(con_out, L"Have SMBIOS table\r\n");
}
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread