From: Alexander Graf Date: Fri, 6 Apr 2018 01:23:44 +0200 Subject: [U-Boot] [PATCH v2] efi_loader: Check machine type in the image header In-Reply-To: <89abdc6e-6690-a5c4-5806-96cfcdb9dadc@gmx.de> References: <20180405212830.GA5872@intel.com> <40666517-ea08-6cb6-6d1b-75f38e0be3f0@suse.de> <89abdc6e-6690-a5c4-5806-96cfcdb9dadc@gmx.de> Message-ID: <67deef2c-c187-eb99-1f6b-2d557ee29cb4@suse.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 06.04.18 01:03, Heinrich Schuchardt wrote: > On 04/06/2018 12:43 AM, Alexander Graf wrote: >> >> >> On 05.04.18 23:28, Ivan Gorinov wrote: >>> Check FileHeader.Machine to make sure the EFI executable image is built >>> for the same architecture. For example, 32-bit U-Boot on x86 will print >>> an error message instead of loading an x86_64 image and crashing. >>> >>> Signed-off-by: Ivan Gorinov >>> --- >>> include/pe.h | 24 ++++++++++++++++++++++++ >>> lib/efi_loader/efi_image_loader.c | 24 ++++++++++++------------ >>> 2 files changed, 36 insertions(+), 12 deletions(-) >>> >>> diff --git a/include/pe.h b/include/pe.h >>> index c3a19ce..0dc33f0 100644 >>> --- a/include/pe.h >>> +++ b/include/pe.h >>> @@ -38,11 +38,35 @@ typedef struct _IMAGE_DOS_HEADER { >>> #define IMAGE_DOS_SIGNATURE 0x5A4D /* MZ */ >>> #define IMAGE_NT_SIGNATURE 0x00004550 /* PE00 */ >>> >>> +#define IMAGE_FILE_MACHINE_I386 0x014c >>> #define IMAGE_FILE_MACHINE_ARM 0x01c0 >>> #define IMAGE_FILE_MACHINE_THUMB 0x01c2 >>> #define IMAGE_FILE_MACHINE_ARMNT 0x01c4 >>> #define IMAGE_FILE_MACHINE_AMD64 0x8664 >>> #define IMAGE_FILE_MACHINE_ARM64 0xaa64 >>> +#define IMAGE_FILE_MACHINE_RISCV32 0x5032 >>> +#define IMAGE_FILE_MACHINE_RISCV64 0x5064 >>> + >>> +#if defined(CONFIG_ARM64) >>> +#define TARGET_PE_MACHINE_TYPE IMAGE_FILE_MACHINE_ARM64 >>> +#elif defined(CONFIG_ARM) >>> +#define TARGET_PE_MACHINE_TYPE IMAGE_FILE_MACHINE_THUMB >> >> Are you sure we always have thumb as machine type here? Aren't we >> compatible with either ARM or THUMB? > > The value 0x01c2 means ARM or THUMB > It is used by Linux, GRUB, iPXE. I'm not sure that's fully accurate. ARM means some old legacy one, but ARMNT and THUMB can both be used, no? https://www.npmjs.com/package/binarycpu What I'm trying to say is that a 1:1 matching might not be the only thing we want. Alex