From patchwork Thu Aug 9 06:51:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143814 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1723626ljj; Wed, 8 Aug 2018 23:51:49 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxWV7WTMwEhwbwX1LBg+dZh7erIldy0AmyS/cpHJL7geM/kiqNuSiIqy8WerJ24mZXpBUne X-Received: by 2002:a50:da01:: with SMTP id z1-v6mr1575861edj.62.1533797509369; Wed, 08 Aug 2018 23:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533797509; cv=none; d=google.com; s=arc-20160816; b=DkHxMpUSlqAAzX63QufkhGioQtAN58W5GEFZ2I+UZimVlBLzB1FPuLEUyVkh3xmLxm C3g4AJTROjTos8Gl7GXE4syC9ytDFjyPga6wFGJNDwAJskTF/w7tBdo6iNLnEUevbFNu 3VcjhFfbUYMFdmm4S2U14sk5QkjHUBnngrhsKF0S8Yp2F+iHGCq1GYZY1tvA+oGwLTBq hefpNb6Ytw7/udtpWaQjXqZv73v1mYiGFVJ/JUj2eDDSHvlc7ZLNI4Wxi3N8/Mv2qs+l 2v2H5Y9of05rBxLl/prftbxUwmVRYFgDLGef4/Glz0ilwuwOTggQ3PMbM6//rLIni9Sz RZFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=ivf9FuEa/I2W/yWsKRtNnbB/mRPf2x4IgRQOkWKYqaU=; b=NSgTgQnJ3sv3yk4SZ/C4QGirtca6/7ItZyB7hiUmEL8YD1h6aXholStwI9MucAhws0 m7Rf4qh4+p6NIaEQZdDh6yfzs9jVA8cpMSXUbAUl8K6lzy/K6zNQJ+jeIGHbU+eQGs4t /UTqcl+FxzXDdZeMb6F9I7ggOQBCJdY9rnHuv6WTZ0EQlmdjMsmij4BVVRWH8lBVCnuH 8n9kVJrvlw/apbj+FcR6CAWTtJsnRpCyj/8RIhyEE6O0/w3B22qBagy5fYnB31JwOohb nEZQPU42PANFiyyRq4PbZNelyFXV+lscE6O1j3u5T582L4U8kYLQcvCHJ714T1zBcufZ q0tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UCvIwTa1; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id u24-v6si5724467edi.415.2018.08.08.23.51.49; Wed, 08 Aug 2018 23:51:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UCvIwTa1; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 03883C21D9A; Thu, 9 Aug 2018 06:51:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 063D1C21C4A; Thu, 9 Aug 2018 06:51:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 20A37C21C4A; Thu, 9 Aug 2018 06:51:40 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by lists.denx.de (Postfix) with ESMTPS id 8757BC21C27 for ; Thu, 9 Aug 2018 06:51:39 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id n7-v6so2288215pgq.4 for ; Wed, 08 Aug 2018 23:51:39 -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; bh=wM6Up4DPFUa8WfSaoOl2UpQP3HvqalUTRlpYbVRxOjI=; b=UCvIwTa1QK0+5/7Gy79XnAhhYefQPo+Kyq2yosKF4l5DFzes9VaUg0qPPpFaqsXM0G cD6lusLOpiBgztDDJZhWfANM7XMk+x7uCQmhghsV81MSvDzhGJ8bQE1TN6f9Yu+14k2Z QtuRTnwLe3ipqnyROa7yhHgL3yxisLwt/zfVA= 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; bh=wM6Up4DPFUa8WfSaoOl2UpQP3HvqalUTRlpYbVRxOjI=; b=a7M4upFUBdUfqotQvF4TqC/CN22R2PIn/qNBYoXqMFvQ95BVZ5qBN9aN0v1EfxbeKy EdGyHl5wppZVjJbzJq72jkBpwD69Fjuo/6dMYOBus16YMQIeckIwJV9TLEoZ0Qa7AhvA tFykEKBcei6sd/kNphFSa0hI2CIr2e7WaKoeUndtVYUhzN4IkLoFaUkdQJNgbwHn+w8Z pjc/mxCLbZlK5UPnkk4gCJFtGlD43NX9HBtzaA8hp8vQ2MFufqG1Vk5q7PP4wN+WDvzI QDTud+jyJyTODJne1iQHFZVDKzLVq1dCwnc3BVN8CxKy2UdshcrpWu29dNQr+mP3kqdg W2hw== X-Gm-Message-State: AOUpUlEzl8cq4x/F3r9+a3NHvHhem1hnRhqivni4qchh8wcEsV2e9Rkl HDrUr2SHqNSdZKq5McEgY4EEcuOEexU= X-Received: by 2002:a65:6086:: with SMTP id t6-v6mr912476pgu.424.1533797498173; Wed, 08 Aug 2018 23:51:38 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t15-v6sm10010228pfa.158.2018.08.08.23.51.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 23:51:37 -0700 (PDT) From: AKASHI Takahiro To: agraf@suse.de Date: Thu, 9 Aug 2018 15:51:22 +0900 Message-Id: <20180809065122.9034-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH] efi_loader: set image_base and image_size to correct values X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Currently, image's image_base points to an address where the image was temporarily uploaded for further loading. Since efi_loader relocates the image to final destination, image_base and image_size should reflect that. This bug was detected in UEFI SCT, "Loaded Image Protocol Test - test 2," which shows that 'Unload' function doesn't fit into a range suggested by image_base and image_size. TestCase/UEFI/EFI/Protocol/LoadedImage/BlackBoxTest/ LoadedImageBBTestMain.c:1002 This patch also reverts a patch, "efi_loader: save image relocation address and size" since newly added fields are no longer needed. Signed-off-by: AKASHI Takahiro --- include/efi_api.h | 2 -- lib/efi_loader/efi_image_loader.c | 17 ++++++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index b2806fba3b8..882a734c198 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -345,8 +345,6 @@ struct efi_loaded_image { /* Below are efi loader private fields */ #ifdef CONFIG_EFI_LOADER - void *reloc_base; - aligned_u64 reloc_size; efi_status_t exit_status; struct jmp_buf_data exit_jmp; #endif diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index fdf40a62c8e..df244deeac5 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -58,10 +58,10 @@ efi_status_t efi_print_image_info(struct efi_loaded_image *image, void *pc) return EFI_INVALID_PARAMETER; printf("UEFI image"); printf(" [0x%p:0x%p]", - image->reloc_base, image->reloc_base + image->reloc_size - 1); - if (pc && pc >= image->reloc_base && - pc < image->reloc_base + image->reloc_size) - printf(" pc=0x%zx", pc - image->reloc_base); + image->image_base, image->image_base + image->image_size - 1); + if (pc && pc >= image->image_base && + pc < image->image_base + image->image_size) + printf(" pc=0x%zx", pc - image->image_base); if (image->file_path) printf(" '%pD'", image->file_path); printf("\n"); @@ -209,7 +209,6 @@ void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info) int rel_idx = IMAGE_DIRECTORY_ENTRY_BASERELOC; void *entry; uint64_t image_base; - uint64_t image_size; unsigned long virt_size = 0; int supported = 0; @@ -253,7 +252,6 @@ void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info) IMAGE_NT_HEADERS64 *nt64 = (void *)nt; IMAGE_OPTIONAL_HEADER64 *opt = &nt64->OptionalHeader; image_base = opt->ImageBase; - image_size = opt->SizeOfImage; efi_set_code_and_data_type(loaded_image_info, opt->Subsystem); efi_reloc = efi_alloc(virt_size, loaded_image_info->image_code_type); @@ -269,7 +267,6 @@ void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info) } else if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { IMAGE_OPTIONAL_HEADER32 *opt = &nt->OptionalHeader; image_base = opt->ImageBase; - image_size = opt->SizeOfImage; efi_set_code_and_data_type(loaded_image_info, opt->Subsystem); efi_reloc = efi_alloc(virt_size, loaded_image_info->image_code_type); @@ -312,10 +309,8 @@ void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info) invalidate_icache_all(); /* Populate the loaded image interface bits */ - loaded_image_info->image_base = efi; - loaded_image_info->image_size = image_size; - loaded_image_info->reloc_base = efi_reloc; - loaded_image_info->reloc_size = virt_size; + loaded_image_info->image_base = efi_reloc; + loaded_image_info->image_size = virt_size; return entry; }