From a99e435c8e24887ce80c322029ba23103e00d1c2 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 20 Jan 2023 00:13:04 +0000 Subject: [efi] Do not rely on ProcessorBind.h when building host binaries We cannot rely on the EDK2 ProcessorBind.h headers when compiling a binary for execution on the build host itself (e.g. elf2efi), since the host's CPU architecture may not even be supported by EDK2. Fix by skipping ProcessorBind.h when building a host binary, and defining the bare minimum required to allow other EDK2 headers to compile cleanly. Reported-by: Michal Suchánek Signed-off-by: Michael Brown --- src/util/elf2efi.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/util') diff --git a/src/util/elf2efi.c b/src/util/elf2efi.c index 08d790f1e..9523ccc31 100644 --- a/src/util/elf2efi.c +++ b/src/util/elf2efi.c @@ -33,6 +33,8 @@ #include #include #include + +#define EFI_HOSTONLY #include #include -- cgit v1.2.3-55-g7522 From 5bf8b115271fe7cfb45d0e83ef9f29fcf609068a Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sat, 28 Jan 2023 16:24:05 +0000 Subject: [efi] Build util/efirom as a host-only binary As with util/elf2efi32 and util/elf2efi64 in commit a99e435 ("[efi] Do not rely on ProcessorBind.h when building host binaries"), build util/efirom without using any architecture-specific EDK2 headers since the build host's CPU architecture may not be supported by EDK2. Signed-off-by: Michael Brown --- src/include/ipxe/efi/ProcessorBind.h | 3 +++ src/util/efirom.c | 2 ++ 2 files changed, 5 insertions(+) (limited to 'src/util') diff --git a/src/include/ipxe/efi/ProcessorBind.h b/src/include/ipxe/efi/ProcessorBind.h index eda609b94..8cc04e15b 100644 --- a/src/include/ipxe/efi/ProcessorBind.h +++ b/src/include/ipxe/efi/ProcessorBind.h @@ -40,6 +40,9 @@ typedef uint8_t BOOLEAN; /* Define an architecture-neutral MDE_CPU macro to prevent build errors */ #define MDE_CPU_EBC +/* Define MAX_BIT in terms of UINTN */ +#define MAX_BIT ( ( ( UINTN ) 1U ) << ( ( 8 * sizeof ( UINTN ) ) - 1 ) ) + #else /* EFI_HOSTONLY */ #ifdef __i386__ diff --git a/src/util/efirom.c b/src/util/efirom.c index 95feaf239..8ac7966ef 100644 --- a/src/util/efirom.c +++ b/src/util/efirom.c @@ -28,6 +28,8 @@ #include #include #include + +#define EFI_HOSTONLY #include #include #include -- cgit v1.2.3-55-g7522 From 38f54fb413a1c70f302f9b29ba9f1a87050d4066 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sat, 28 Jan 2023 15:30:11 +0000 Subject: [legal] Add support for the BSD-2-Clause-Patent licence Signed-off-by: Michael Brown --- src/include/compiler.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/util/licence.pl | 14 ++++++++++++++ 2 files changed, 61 insertions(+) (limited to 'src/util') diff --git a/src/include/compiler.h b/src/include/compiler.h index a936425de..5685ab154 100644 --- a/src/include/compiler.h +++ b/src/include/compiler.h @@ -755,6 +755,53 @@ char __debug_disable(OBJECT) = ( DBGLVL_MAX & ~DBGLVL_DFLT ); #define FILE_LICENCE_BSD2 \ PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__bsd2__ ) ) +/** Declare a file as being under the two-clause BSD plus patent licence + * + * This licence declaration is applicable when a file states itself to + * be licensed under terms allowing redistribution in source and + * binary forms (with or without modification) provided that: + * + * redistributions of source code retain the copyright notice, + * list of conditions and any attached disclaimers + * + * redistributions in binary form reproduce the copyright notice, + * list of conditions and any attached disclaimers in the + * documentation and/or other materials provided with the + * distribution + * + * and in addition states that + * + * Subject to the terms and conditions of this license, each + * copyright holder and contributor hereby grants to those + * receiving rights under this license a perpetual, worldwide, + * non-exclusive, no-charge, royalty-free, irrevocable (except for + * failure to satisfy the conditions of this license) patent + * license to make, have made, use, offer to sell, sell, import, + * and otherwise transfer this software, where such license + * applies only to those patent claims, already acquired or + * hereafter acquired, licensable by such copyright holder or + * contributor that are necessarily infringed by: + * + * their Contribution(s) (the licensed copyrights of copyright + * holders and non-copyrightable additions of contributors, in + * source or binary form) alone; or + * + * combination of their Contribution(s) with the work of + * authorship to which such Contribution(s) was added by such + * copyright holder or contributor, if, at the time the + * Contribution is added, such addition causes such combination + * to be necessarily infringed. The patent license shall not + * apply to any other combinations which include the + * Contribution. + * + * It is not necessary for the file to explicitly state that it is + * under a "BSD" licence; only that the licensing terms be + * functionally equivalent to the standard two-clause BSD licence with + * patent grant. + */ +#define FILE_LICENCE_BSD2_PATENT \ + PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__bsd2_patent__ ) ) + /** Declare a file as being under the one-clause MIT-style licence * * This licence declaration is applicable when a file states itself to diff --git a/src/util/licence.pl b/src/util/licence.pl index 79e70fd65..bb23c9524 100755 --- a/src/util/licence.pl +++ b/src/util/licence.pl @@ -29,6 +29,7 @@ my $known_licences = { public_domain => 1, bsd3 => 1, bsd2 => 1, + bsd2_patent => 1, mit => 1, isc => 1, }, @@ -41,6 +42,7 @@ my $known_licences = { public_domain => 1, bsd3 => 1, bsd2 => 1, + bsd2_patent => 1, mit => 1, isc => 1, }, @@ -54,6 +56,7 @@ my $known_licences = { public_domain => 1, bsd3 => 1, bsd2 => 1, + bsd2_patent => 1, mit => 1, isc => 1, }, @@ -65,6 +68,7 @@ my $known_licences = { public_domain => 1, bsd3 => 1, bsd2 => 1, + bsd2_patent => 1, mit => 1, isc => 1, }, @@ -100,6 +104,16 @@ my $known_licences = { isc => 1, }, }, + bsd2_patent => { + desc => ( "BSD Licence (without advertising or endorsement clauses, ". + "with patent clause)" ), + can_subsume => { + public_domain => 1, + bsd2 => 1, + mit => 1, + isc => 1, + }, + }, mit => { desc => "MIT/X11/Xorg Licence", can_subsume => { -- cgit v1.2.3-55-g7522 From d405a0bd84e34d5c549d71145657add506079fb4 Mon Sep 17 00:00:00 2001 From: Xiaotian Wu Date: Fri, 3 Feb 2023 12:44:11 +0000 Subject: [util] Add support for LoongArch64 binaries Signed-off-by: Xiaotian Wu Modified-by: Michael Brown Signed-off-by: Michael Brown --- src/util/efirom.c | 1 + src/util/elf2efi.c | 34 ++++++++++++++++++++++++++++++++++ src/util/genfsimg | 3 +++ 3 files changed, 38 insertions(+) (limited to 'src/util') diff --git a/src/util/efirom.c b/src/util/efirom.c index 8ac7966ef..b0334bdb1 100644 --- a/src/util/efirom.c +++ b/src/util/efirom.c @@ -95,6 +95,7 @@ static void read_pe_info ( void *pe, uint16_t *machine, break; case EFI_IMAGE_MACHINE_X64: case EFI_IMAGE_MACHINE_AARCH64: + case EFI_IMAGE_MACHINE_LOONGARCH64: *subsystem = nt->nt64.OptionalHeader.Subsystem; break; default: diff --git a/src/util/elf2efi.c b/src/util/elf2efi.c index 9523ccc31..cea9abf86 100644 --- a/src/util/elf2efi.c +++ b/src/util/elf2efi.c @@ -81,6 +81,9 @@ #ifndef EM_AARCH64 #define EM_AARCH64 183 #endif +#ifndef EM_LOONGARCH +#define EM_LOONGARCH 258 +#endif #ifndef R_AARCH64_NONE #define R_AARCH64_NONE 0 #endif @@ -126,6 +129,27 @@ #ifndef R_ARM_V4BX #define R_ARM_V4BX 40 #endif +#ifndef R_LARCH_NONE +#define R_LARCH_NONE 0 +#endif +#ifndef R_LARCH_64 +#define R_LARCH_64 2 +#endif +#ifndef R_LARCH_B26 +#define R_LARCH_B26 66 +#endif +#ifndef R_LARCH_PCALA_HI20 +#define R_LARCH_PCALA_HI20 71 +#endif +#ifndef R_LARCH_PCALA_LO12 +#define R_LARCH_PCALA_LO12 72 +#endif +#ifndef R_LARCH_GOT_PC_HI20 +#define R_LARCH_GOT_PC_HI20 75 +#endif +#ifndef R_LARCH_GOT_PC_LO12 +#define R_LARCH_GOT_PC_LO12 76 +#endif /** * Alignment of raw data of sections in the image file @@ -486,6 +510,9 @@ static void set_machine ( struct elf_file *elf, struct pe_header *pe_header ) { case EM_AARCH64: machine = EFI_IMAGE_MACHINE_AARCH64; break; + case EM_LOONGARCH: + machine = EFI_IMAGE_MACHINE_LOONGARCH64; + break; default: eprintf ( "Unknown ELF architecture %d\n", ehdr->e_machine ); exit ( 1 ); @@ -671,6 +698,7 @@ static void process_reloc ( struct elf_file *elf, const Elf_Shdr *shdr, case ELF_MREL ( EM_X86_64, R_X86_64_NONE ) : case ELF_MREL ( EM_AARCH64, R_AARCH64_NONE ) : case ELF_MREL ( EM_AARCH64, R_AARCH64_NULL ) : + case ELF_MREL ( EM_LOONGARCH, R_LARCH_NONE ) : /* Ignore dummy relocations used by REQUIRE_SYMBOL() */ break; case ELF_MREL ( EM_386, R_386_32 ) : @@ -680,6 +708,7 @@ static void process_reloc ( struct elf_file *elf, const Elf_Shdr *shdr, break; case ELF_MREL ( EM_X86_64, R_X86_64_64 ) : case ELF_MREL ( EM_AARCH64, R_AARCH64_ABS64 ) : + case ELF_MREL ( EM_LOONGARCH, R_LARCH_64 ) : /* Generate an 8-byte PE relocation */ generate_pe_reloc ( pe_reltab, offset, 8 ); break; @@ -700,6 +729,11 @@ static void process_reloc ( struct elf_file *elf, const Elf_Shdr *shdr, case ELF_MREL ( EM_AARCH64, R_AARCH64_LDST16_ABS_LO12_NC ) : case ELF_MREL ( EM_AARCH64, R_AARCH64_LDST32_ABS_LO12_NC ) : case ELF_MREL ( EM_AARCH64, R_AARCH64_LDST64_ABS_LO12_NC ) : + case ELF_MREL ( EM_LOONGARCH, R_LARCH_B26): + case ELF_MREL ( EM_LOONGARCH, R_LARCH_PCALA_HI20 ): + case ELF_MREL ( EM_LOONGARCH, R_LARCH_PCALA_LO12 ): + case ELF_MREL ( EM_LOONGARCH, R_LARCH_GOT_PC_HI20 ): + case ELF_MREL ( EM_LOONGARCH, R_LARCH_GOT_PC_LO12 ): /* Skip PC-relative relocations; all relative * offsets remain unaltered when the object is * loaded. diff --git a/src/util/genfsimg b/src/util/genfsimg index 731fa6ce0..0c0692793 100755 --- a/src/util/genfsimg +++ b/src/util/genfsimg @@ -72,6 +72,9 @@ efi_boot_name() { "c201" ) echo "BOOTARM.EFI" ;; + "6462" ) + echo "BOOTLOONGARCH64.EFI" + ;; "64aa" ) echo "BOOTAA64.EFI" ;; -- cgit v1.2.3-55-g7522