From patchwork Tue May 30 18:36:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 100726 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp352679qge; Tue, 30 May 2017 11:37:22 -0700 (PDT) X-Received: by 10.84.238.199 with SMTP id l7mr86128914pln.153.1496169442218; Tue, 30 May 2017 11:37:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496169442; cv=none; d=google.com; s=arc-20160816; b=i4b1TD/tQa+dxeMeT8ju5eJVerergXKRvKfD0ydo862227DKg4wG634Z2ZFFg4536V ZtxRsmRPQ8p6S3VV7DmCC7SBpOVZr2qDsy5jkcmdLlOgSB+8Jfr7g6oCYr55gEoZi8DK CP72QDE2QfHHbTsbqraAnOopYUiAN5ihQhOWQbwKYXKAu+5HCj5Hp0M688yjVrJoOhWS 95yR8tIzl/hsZOAM4C4y85P8tAJCuutdlMQEacGveMWxbX4VLtS6BpgHb/vZ56aS7cHJ vhd1qJ3BX8VLEFJxzLQ0Tu6xnaNwDfx0E0IAbKA47UHJZsj+f0D3auJN8hb+j+aCojvE aneQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=YVDb5y57tC6NtjLJqxbVx9QgwuXhbNYapctseOSoUDQ=; b=cRfQubv+DGbvT569OjEyjP8p/SCV1K8h/fTOfx1NffdUGFlmPsVbr9kShWuJ1bhK40 x0H1xIFvOq7I4e797u3HBsrIpnd7DuF7BpsPKqTRFFamAwmO6GZL2cs6X1lFvmFOTrEK /2E6HzPN12euZjLyIvq9NUtuqThemla9jt1Wh7c5/TRvFWJYRpdnQviRBolXeFIJFYp9 9auNBcu3TMQqHrQ+k6KEYVm5dxvTp3wCbPLBMANLs0EEQW1FKp4qRt37uc+fvNojh+3n xtzFE/yXAl3spN5po8Rt5Qg4Sih8dFishdgZcpEJ+OreObYIn9M36CeLRT+4wwQd3q/j q7pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si44904691plf.190.2017.05.30.11.37.22; Tue, 30 May 2017 11:37:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750938AbdE3ShF (ORCPT + 2 others); Tue, 30 May 2017 14:37:05 -0400 Received: from mail-wr0-f173.google.com ([209.85.128.173]:34588 "EHLO mail-wr0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750951AbdE3ShE (ORCPT ); Tue, 30 May 2017 14:37:04 -0400 Received: by mail-wr0-f173.google.com with SMTP id g76so5640818wrd.1 for ; Tue, 30 May 2017 11:37:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dta/JGct3yUIcFxu+bS532loXs0K0cd71RxDbBatIyo=; b=RmHqiixoYwj5u8THfXkbDNMqTh0/IBKA7TheYDp0VrD8sFeJ2v5FD4GdZlBuDZ/uNo JjVR5LJ3L+0m3mXiBaRZcM8UK5sfnf23gLL08tNSLTxR6kxyqles47HyC0n6BObyYDRL lzUZ6cXM5NprRMqYo7x1gOfpuo0QpKXKqNZPs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dta/JGct3yUIcFxu+bS532loXs0K0cd71RxDbBatIyo=; b=mHiSVtSTDkU9mjwgme6DknMrHGMRZG6pwaT6vzl0PxfkeUKtC1QfVuTKG5X3WsuNP2 EtxhziO5m/TtGhLlJ/Eezc2sek4kjZ2JJHjl7FZ6C81/JbjBc4HCvQ5+RBGUEQVzF5GM IHsKd2fzKr5/DepwRPqis33yyoqr6fmxAF20ePoOhs9LEj/dykZncR0wkUCQ1wR90FDN +Q+KI/MTXJoNpSud09/ndqxhTeeKNJkkvWGiinSSGBfGbJFAXhPsFOsxoBrmDA9LMeco lIdzzAbQZsmEqCSdRCl5YSzng/IbK+nkClU8R3iRHDE+B2ql8H+yQRX5RdMFRDGCHzZS xg7w== X-Gm-Message-State: AODbwcDv6IO7GYgA/faLdWBIUoX5TieaSTB+VAR7eOS9I/vQRxnkGJm6 Ips0dQSqdx6hH8JD95F0CA== X-Received: by 10.223.183.30 with SMTP id l30mr9835526wre.115.1496169422349; Tue, 30 May 2017 11:37:02 -0700 (PDT) Received: from localhost.localdomain ([154.144.49.177]) by smtp.gmail.com with ESMTPSA id b8sm15935997wrb.7.2017.05.30.11.36.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 May 2017 11:37:01 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, linux@armlinux.org.uk Cc: linux-arm-kernel@lists.infradead.org, matt@codeblueprint.co.uk, leif.lindholm@linaro.org, Ard Biesheuvel Subject: [PATCH 3/7] arm: efi: replace open coded constants with symbolic ones Date: Tue, 30 May 2017 18:36:43 +0000 Message-Id: <20170530183647.28557-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170530183647.28557-1-ard.biesheuvel@linaro.org> References: <20170530183647.28557-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Replace the various open coded constants in the EFI PE/COFF header with definitions from pe.h, or expressions based on local symbols. Note that this patch also changes the indentation to make room for the symbolic constant names. Signed-off-by: Ard Biesheuvel --- arch/arm/boot/compressed/efi-header.S | 172 ++++++++++---------- 1 file changed, 89 insertions(+), 83 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm/boot/compressed/efi-header.S b/arch/arm/boot/compressed/efi-header.S index 97f595970916..4699c432a2e2 100644 --- a/arch/arm/boot/compressed/efi-header.S +++ b/arch/arm/boot/compressed/efi-header.S @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 Linaro Ltd + * Copyright (C) 2013-2017 Linaro Ltd * Authors: Roy Franz * Ard Biesheuvel * @@ -8,105 +8,111 @@ * published by the Free Software Foundation. */ - .macro __nop +#include +#include + + .macro __nop #ifdef CONFIG_EFI_STUB - @ This is almost but not quite a NOP, since it does clobber the - @ condition flags. But it is the best we can do for EFI, since - @ PE/COFF expects the magic string "MZ" at offset 0, while the - @ ARM/Linux boot protocol expects an executable instruction - @ there. - .inst 'M' | ('Z' << 8) | (0x1310 << 16) @ tstne r0, #0x4d000 + @ This is almost but not quite a NOP, since it does clobber the + @ condition flags. But it is the best we can do for EFI, since + @ PE/COFF expects the magic string "MZ" at offset 0, while the + @ ARM/Linux boot protocol expects an executable instruction + @ there. + .inst MZ_MAGIC | (0x1310 << 16) @ tstne r0, #0x4d000 #else - W(mov) r0, r0 + W(mov) r0, r0 #endif - .endm + .endm - .macro __EFI_HEADER + .macro __EFI_HEADER #ifdef CONFIG_EFI_STUB - .set start_offset, __efi_start - start - .org start + 0x3c - @ - @ The PE header can be anywhere in the file, but for - @ simplicity we keep it together with the MSDOS header - @ The offset to the PE/COFF header needs to be at offset - @ 0x3C in the MSDOS header. - @ The only 2 fields of the MSDOS header that are used are this - @ PE/COFF offset, and the "MZ" bytes at offset 0x0. - @ - .long pe_header - start @ Offset to the PE header. + .set start_offset, __efi_start - start + .org start + 0x3c + @ + @ The PE header can be anywhere in the file, but for + @ simplicity we keep it together with the MSDOS header + @ The offset to the PE/COFF header needs to be at offset + @ 0x3C in the MSDOS header. + @ The only 2 fields of the MSDOS header that are used are this + @ PE/COFF offset, and the "MZ" bytes at offset 0x0. + @ + .long pe_header - start @ Offset to the PE header. pe_header: - .ascii "PE\0\0" + .long PE_MAGIC coff_header: - .short 0x01c2 @ ARM or Thumb - .short 1 @ nr_sections - .long 0 @ TimeDateStamp - .long 0 @ PointerToSymbolTable - .long 0 @ NumberOfSymbols - .short section_table - optional_header - @ SizeOfOptionalHeader - .short 0x306 @ Characteristics. - @ IMAGE_FILE_32BIT_MACHINE | - @ IMAGE_FILE_DEBUG_STRIPPED | - @ IMAGE_FILE_EXECUTABLE_IMAGE | - @ IMAGE_FILE_LINE_NUMS_STRIPPED + .short IMAGE_FILE_MACHINE_THUMB @ Machine + .short section_count @ NumberOfSections + .long 0 @ TimeDateStamp + .long 0 @ PointerToSymbolTable + .long 0 @ NumberOfSymbols + .short section_table - optional_header @ SizeOfOptionalHeader + .short IMAGE_FILE_32BIT_MACHINE | \ + IMAGE_FILE_DEBUG_STRIPPED | \ + IMAGE_FILE_EXECUTABLE_IMAGE | \ + IMAGE_FILE_LINE_NUMS_STRIPPED @ Characteristics optional_header: - .short 0x10b @ PE32 format - .byte 0x02 @ MajorLinkerVersion - .byte 0x14 @ MinorLinkerVersion - .long _end - __efi_start @ SizeOfCode - .long 0 @ SizeOfInitializedData - .long 0 @ SizeOfUninitializedData - .long efi_stub_entry - start @ AddressOfEntryPoint - .long start_offset @ BaseOfCode - .long 0 @ data + .short PE_OPT_MAGIC_PE32 @ PE32 format + .byte 0x02 @ MajorLinkerVersion + .byte 0x14 @ MinorLinkerVersion + .long _end - __efi_start @ SizeOfCode + .long 0 @ SizeOfInitializedData + .long 0 @ SizeOfUninitializedData + .long efi_stub_entry - start @ AddressOfEntryPoint + .long start_offset @ BaseOfCode + .long 0 @ BaseOfData extra_header_fields: - .long 0 @ ImageBase - .long 0x200 @ SectionAlignment - .long 0x200 @ FileAlignment - .short 0 @ MajorOperatingSystemVersion - .short 0 @ MinorOperatingSystemVersion - .short 0 @ MajorImageVersion - .short 0 @ MinorImageVersion - .short 0 @ MajorSubsystemVersion - .short 0 @ MinorSubsystemVersion - .long 0 @ Win32VersionValue + .long 0 @ ImageBase + .long SZ_512 @ SectionAlignment + .long SZ_512 @ FileAlignment + .short 0 @ MajorOsVersion + .short 0 @ MinorOsVersion + .short 0 @ MajorImageVersion + .short 0 @ MinorImageVersion + .short 0 @ MajorSubsystemVersion + .short 0 @ MinorSubsystemVersion + .long 0 @ Win32VersionValue - .long _end - start @ SizeOfImage - .long start_offset @ SizeOfHeaders - .long 0 @ CheckSum - .short 0xa @ Subsystem (EFI application) - .short 0 @ DllCharacteristics - .long 0 @ SizeOfStackReserve - .long 0 @ SizeOfStackCommit - .long 0 @ SizeOfHeapReserve - .long 0 @ SizeOfHeapCommit - .long 0 @ LoaderFlags - .long 0x6 @ NumberOfRvaAndSizes + .long _end - start @ SizeOfImage + .long start_offset @ SizeOfHeaders + .long 0 @ CheckSum + .short IMAGE_SUBSYSTEM_EFI_APPLICATION @ Subsystem + .short 0 @ DllCharacteristics + .long 0 @ SizeOfStackReserve + .long 0 @ SizeOfStackCommit + .long 0 @ SizeOfHeapReserve + .long 0 @ SizeOfHeapCommit + .long 0 @ LoaderFlags + .long (section_table - .) / 8 @ NumberOfRvaAndSizes - .quad 0 @ ExportTable - .quad 0 @ ImportTable - .quad 0 @ ResourceTable - .quad 0 @ ExceptionTable - .quad 0 @ CertificationTable - .quad 0 @ BaseRelocationTable + .quad 0 @ ExportTable + .quad 0 @ ImportTable + .quad 0 @ ResourceTable + .quad 0 @ ExceptionTable + .quad 0 @ CertificationTable + .quad 0 @ BaseRelocationTable section_table: - .ascii ".text\0\0\0" - .long _end - __efi_start @ VirtualSize - .long __efi_start @ VirtualAddress - .long _edata - __efi_start @ SizeOfRawData - .long __efi_start @ PointerToRawData - .long 0 @ PointerToRelocations - .long 0 @ PointerToLineNumbers - .short 0 @ NumberOfRelocations - .short 0 @ NumberOfLineNumbers - .long 0xe0000020 @ Characteristics + .ascii ".text\0\0\0" + .long _end - __efi_start @ VirtualSize + .long __efi_start @ VirtualAddress + .long _edata - __efi_start @ SizeOfRawData + .long __efi_start @ PointerToRawData + .long 0 @ PointerToRelocations + .long 0 @ PointerToLineNumbers + .short 0 @ NumberOfRelocations + .short 0 @ NumberOfLineNumbers + .long IMAGE_SCN_CNT_CODE | \ + IMAGE_SCN_MEM_READ | \ + IMAGE_SCN_MEM_WRITE | \ + IMAGE_SCN_MEM_EXECUTE @ Characteristics + + .set section_count, (. - section_table) / 40 - .align 9 + .align 9 __efi_start: #endif - .endm + .endm