From patchwork Wed Sep 13 22:05:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 813656 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hK8snWTQ"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xsx114Q97z9sxR for ; Thu, 14 Sep 2017 08:19:49 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5CC2AC226F5; Wed, 13 Sep 2017 22:10:17 +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=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, 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 1F01AC225FA; Wed, 13 Sep 2017 22:08:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id ED6FBC2260B; Wed, 13 Sep 2017 22:06:33 +0000 (UTC) Received: from mail-qk0-f194.google.com (mail-qk0-f194.google.com [209.85.220.194]) by lists.denx.de (Postfix) with ESMTPS id D13F4C2249C for ; Wed, 13 Sep 2017 22:06:29 +0000 (UTC) Received: by mail-qk0-f194.google.com with SMTP id g128so957177qke.0 for ; Wed, 13 Sep 2017 15:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DKsVzCsw32z5Rh0dgOU0MOQ8zk25bcDzhP7cBWZSGfE=; b=hK8snWTQ6Oq22BXpaDq1Rb8Qa54S6PkYPwJQngcJh0HNCuqEbXbV5uk2ixJXY2D466 JeD9Jk8wM33oPPEw+Aci8/a+gMG8bDAE8hfJbhEXv8wJNB82Zwy9qrofQXtWc6mLsvuB +Fjl/DczCysZgAamaZMsvpKIlE2AMjqWiFYvP3PhUvAkGuRG0x4XRzzahH4fIOXDwgBO diZNEi+iaglcRUn8RQymKxOkKVhZC2EOnKfywLk1oln+O9q1ny/9DQwOhOhJqUl9rV2U cwJgW/Vs2Ks0QC3aWXrXB8Xe7+7ci7ydAZ344e70GLXzmXFsm1YixasCBLLQCbG1UKsL BGhg== 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=DKsVzCsw32z5Rh0dgOU0MOQ8zk25bcDzhP7cBWZSGfE=; b=XeqrwZRPbfFurrq3AquDq4yvbOv9Nr9+z04lk50e/K7glV0qM8uXKzy4aR8syDyPt2 D1daQna/IAfxvKAYPDHcfwbMwBk2G/0AdiYMI0qem6+gvt12JiNfmj7TX+josQjZMTWB XwufRoky9Y5P4QtDdnpAyVgWtDM86coX05NGuw2WzRJzfPAzfjl/9f1ZYUO7XzzHJ7y7 c/psiXMSfdP43v31y3HsMt3HbKMcHRTZJJRqmaG4PYBPr8/LDWNUZLlCUgS/k799jkn+ QX+IuHnvSVbNefqKQA/lNBFNnYvejVMsQTry5cM2u/aiVkATMnMGqetCo1/kmGx7HIai Lt0Q== X-Gm-Message-State: AHPjjUhXSYqhNH22h0HmW7kEfjymxBNxsEqKqbaKVbcfXh6pXgAOTgSm f9fFpXWrX2kZSWqn3Kc= X-Google-Smtp-Source: AOwi7QAXyA9uFecgFbXq8WmQ3UV0RcGPf/h3dCPI4OS+vmVHsIEjZ3IWYy4f9SCmSTcpI9n6PiOcMw== X-Received: by 10.55.12.16 with SMTP id 16mr25384238qkm.213.1505340388536; Wed, 13 Sep 2017 15:06:28 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id e18sm10524005qtc.59.2017.09.13.15.06.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Sep 2017 15:06:27 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Wed, 13 Sep 2017 18:05:35 -0400 Message-Id: <20170913220546.19560-13-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170913220546.19560-1-robdclark@gmail.com> References: <20170913220546.19560-1-robdclark@gmail.com> Cc: Heinrich Schuchardt Subject: [U-Boot] [PATCH v3 12/21] efi_loader: support load_image() from a file-path 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" Previously we only supported the case when the EFI application loaded the image into memory for us. But fallback.efi does not do this. Signed-off-by: Rob Clark --- lib/efi_loader/efi_boottime.c | 85 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 15 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 837e61d8fe..ec40f41bcb 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -762,6 +762,47 @@ void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *ob list_add_tail(&obj->link, &efi_obj_list); } +static efi_status_t load_image_from_path(struct efi_device_path *file_path, + void **buffer) +{ + struct efi_file_info *info = NULL; + struct efi_file_handle *f; + static efi_status_t ret; + uint64_t bs; + + f = efi_file_from_path(file_path); + if (!f) + return EFI_DEVICE_ERROR; + + bs = 0; + EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid, + &bs, info)); + if (ret == EFI_BUFFER_TOO_SMALL) { + info = malloc(bs); + EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid, + &bs, info)); + } + if (ret != EFI_SUCCESS) + goto error; + + ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer); + if (ret) + goto error; + + EFI_CALL(ret = f->read(f, &info->file_size, *buffer)); + +error: + free(info); + EFI_CALL(f->close(f)); + + if (ret != EFI_SUCCESS) { + efi_free_pool(*buffer); + *buffer = NULL; + } + + return ret; +} + static efi_status_t EFIAPI efi_load_image(bool boot_policy, efi_handle_t parent_image, struct efi_device_path *file_path, @@ -769,25 +810,40 @@ static efi_status_t EFIAPI efi_load_image(bool boot_policy, unsigned long source_size, efi_handle_t *image_handle) { - static struct efi_object loaded_image_info_obj = { - .protocols = { - { - .guid = &efi_guid_loaded_image, - }, - }, - }; struct efi_loaded_image *info; struct efi_object *obj; EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image, file_path, source_buffer, source_size, image_handle); - info = malloc(sizeof(*info)); - loaded_image_info_obj.protocols[0].protocol_interface = info; - obj = malloc(sizeof(loaded_image_info_obj)); - memset(info, 0, sizeof(*info)); - memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj)); - obj->handle = info; - info->file_path = file_path; + + info = calloc(1, sizeof(*info)); + obj = calloc(1, sizeof(*obj)); + + if (!source_buffer) { + struct efi_device_path *dp, *fp; + efi_status_t ret; + + ret = load_image_from_path(file_path, &source_buffer); + if (ret != EFI_SUCCESS) { + free(info); + free(obj); + return EFI_EXIT(ret); + } + + /* + * split file_path which contains both the device and + * file parts: + */ + efi_dp_split_file_path(file_path, &dp, &fp); + + efi_setup_loaded_image(info, obj, dp, fp); + } else { + /* In this case, file_path is the "device" path, ie. + * something like a HARDWARE_DEVICE:MEMORY_MAPPED + */ + efi_setup_loaded_image(info, obj, file_path, NULL); + } + info->reserved = efi_load_pe(source_buffer, info); if (!info->reserved) { free(info); @@ -796,7 +852,6 @@ static efi_status_t EFIAPI efi_load_image(bool boot_policy, } *image_handle = info; - list_add_tail(&obj->link, &efi_obj_list); return EFI_EXIT(EFI_SUCCESS); }