From patchwork Sun Sep 10 11:21:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 812110 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="YxnXTyvs"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xqpq166f1z9sDB for ; Sun, 10 Sep 2017 21:33:49 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 923B3C21E8C; Sun, 10 Sep 2017 11:30:39 +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 45D6BC21EBF; Sun, 10 Sep 2017 11:27:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6B78FC21DC3; Sun, 10 Sep 2017 11:23:44 +0000 (UTC) Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) by lists.denx.de (Postfix) with ESMTPS id 1FEC5C21F3A for ; Sun, 10 Sep 2017 11:23:39 +0000 (UTC) Received: by mail-qt0-f195.google.com with SMTP id q8so4090458qtb.1 for ; Sun, 10 Sep 2017 04:23:39 -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=YxnXTyvsyDqjMMCQ2u4FNsP3q6RZOSTjrZwG4TRV6I8YeKX1xfWeyMw99/geLPVbmT i/DyAjGLRspe4xjKt4ovsGmAwnJc/vTNaYHbFRWvJrz6tOALUVw6O4Wf6iPc9s6h4MFv mRQXAs1XvhF2MqzprzYiSpi56N0uZL0kSbxRC4u5jjH7UC/vy353YTQF4abKQI14Vpda jxvAIAwdNl76JmsixAOjU2WHutu94dNzgDstLUyl9tG4ZrouOE/WnauXm68R2J4w57mB 23zKmHAT3i60b/YICnYD/X0S1O3AfyLhoNwHohTZawtVpBZ2MsmXCWKGclFb0K62xCwj akHw== 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=Y2Wr0ZgVcBUUoMXQ8YUt5fNMvRX4gwzwSKO/2yLxnUKVVGXESRVZK3JC8VgIDDiod6 xdpEMFwt2SVe7Z6MrYWnMc25h8zmgFrVHhBNjBqNM8fEB40GsIjQAcjY3dP1O+ivyaHh 7L26PI6V8urN4lsDZXsSzEVK0ZIxSO6qe4rX3X28pQhjUGkWx2XPXgTC/g606bOSBWTa h/hvU1P+Ck3ojOVcDM5AGdB436kmEknYAA1cXEXudFOdEjPbB9wyF6/6UOnNOH8ukAhh zAg8k2d8wPzWaTontiz17usfpL90usngvpuuZkXvcFkB4qk6QuIqjdV986G5MSJnKxDm PbXA== X-Gm-Message-State: AHPjjUgoUcw5nGucTKcZIofg9PduFWQVdSqz/h71gcroR/3p8dM76ukP p+EeS+ekUbwENeeDurI= X-Google-Smtp-Source: AOwi7QBHiNxrzgWo9i/AVRifxdWDhl2BeZRhja2GMc8XdALeXxkY4Hk7wo6Ix37CjzG1fyk1q928DQ== X-Received: by 10.200.42.46 with SMTP id k43mr8546114qtk.273.1505042617870; Sun, 10 Sep 2017 04:23:37 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id x65sm4049637qke.48.2017.09.10.04.23.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Sep 2017 04:23:36 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Sun, 10 Sep 2017 07:21:38 -0400 Message-Id: <20170910112149.21358-22-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170910112149.21358-1-robdclark@gmail.com> References: <20170910112149.21358-1-robdclark@gmail.com> Cc: Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 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); }