From patchwork Tue Mar 5 05:53:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1051622 X-Patchwork-Delegate: xypron.glpk@gmx.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; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Fxma2u5E"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44D5d74WQHz9s1B for ; Tue, 5 Mar 2019 16:52:11 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 4D8C0C21E16; Tue, 5 Mar 2019 05:52:04 +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_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 2577CC21DF3; Tue, 5 Mar 2019 05:52:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 247E4C21DC1; Tue, 5 Mar 2019 05:51:54 +0000 (UTC) Received: from mail-yw1-f67.google.com (mail-yw1-f67.google.com [209.85.161.67]) by lists.denx.de (Postfix) with ESMTPS id B0688C21E2B for ; Tue, 5 Mar 2019 05:51:50 +0000 (UTC) Received: by mail-yw1-f67.google.com with SMTP id s204so6075656ywg.2 for ; Mon, 04 Mar 2019 21:51:50 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=SKnktM/NKAgY6OOGTW+wiR8R0J7qw7EvrZpzKaPIgbM=; b=Fxma2u5E42XiWR+YzOJydKBYbUiUkyztp7M914P4QCP67OwHhf1EqmcwXE8zzI3Jks QyJJx966Xt541k8mQTaG5yBgIgKVbORbVWpRQ/aPyVia/nKEAVPQ/+r+5CKPdO0swMhF ePjYlfn2srM9A+Ob9Redwbyy9ifO0ByP+ye62hi+SPSH+DrlXaOLs53fNcf3Xw2H82y1 ZmQPGPNXzJgRQTp1ONupRX8BRrUSIpBjNoemcY12Zq2A5dsla4nk44NGuO0As+7AZiBA e18b14xCgcyRclGvOrpf759FHlqcHcbDNjpgdZ4pm8gQm3nwiLvehNTG2Ifk50X39Ye5 Ntdg== 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:mime-version:content-transfer-encoding; bh=SKnktM/NKAgY6OOGTW+wiR8R0J7qw7EvrZpzKaPIgbM=; b=aF0gEzKrAUvnrh0xHrkn0mV6KbQT32Y1SGcv5j2mV0NU35bx91r1X17Rj6iQV+SjlV 7pXARfDw1E8WTPJ9KDLIWG0Wl29rl6SWWzPjegq1rAuZZJEF9C+cLr2229aD4CydC5ba ItARjbJ5FmEScfee7FYfqwoP+CE8Fhs3C218mS+KrliTk03NGqGFhx7szNujoc8iZOsV GrT1Qu2I9z0z4kvpqGn8hI0YqOI+XAOF8Qiubre6KPSYV5k9U/SvlmOvjDCrT4CbyHxl wNy5G5/mT+2UTPE/tNvXlUfgHfc5P1NQGDjp+CR2i0z3vasnvLqhKJeoSEP+MFGQkqji U4fw== X-Gm-Message-State: APjAAAXb2lNSfOnCKwgjJ2PTkI0Q7Rd6/6QMW+s7sUiK/EbLBpLgJ/yP k9X4Sq3M0aQGYTKmxx+WElnGxm1nXlw= X-Google-Smtp-Source: APXvYqy4EfqkBM9mZlnocxRa6Q2tXj/UPb6qO8xrCJLBg3kB7bnWi0kg81RAfcS0xTWzoh5O7zPESQ== X-Received: by 2002:a5b:78b:: with SMTP id b11mr753800ybq.185.1551765109725; Mon, 04 Mar 2019 21:51:49 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h204sm3309414ywh.52.2019.03.04.21.51.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2019 21:51:49 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@suse.de Date: Tue, 5 Mar 2019 14:53:30 +0900 Message-Id: <20190305055337.3793-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305055337.3793-1-takahiro.akashi@linaro.org> References: <20190305055337.3793-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC 1/8] efi_loader: boottime: don't add device path protocol to image handle 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" It is just wrong to add devcie path protocol to image handle. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_boottime.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index bd8b8a17ae71..7bd9c0a952d4 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1540,17 +1540,8 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path, info->file_path = file_path; info->system_table = &systab; - if (device_path) { + if (device_path) info->device_handle = efi_dp_find_obj(device_path, NULL); - /* - * When asking for the device path interface, return - * bootefi_device_path - */ - ret = efi_add_protocol(&obj->header, - &efi_guid_device_path, device_path); - if (ret != EFI_SUCCESS) - goto failure; - } /* * When asking for the loaded_image interface, just From patchwork Tue Mar 5 05:53:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1051623 X-Patchwork-Delegate: xypron.glpk@gmx.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; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="FZ2+OAzh"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44D5dX1t3Sz9s3q for ; Tue, 5 Mar 2019 16:52:32 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id BAB56C21DCA; Tue, 5 Mar 2019 05:52:18 +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_DNSWL_NONE, 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 AC17EC21DE8; Tue, 5 Mar 2019 05:52:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 764A0C21DD4; Tue, 5 Mar 2019 05:51:56 +0000 (UTC) Received: from mail-yw1-f66.google.com (mail-yw1-f66.google.com [209.85.161.66]) by lists.denx.de (Postfix) with ESMTPS id D607AC21E26 for ; Tue, 5 Mar 2019 05:51:52 +0000 (UTC) Received: by mail-yw1-f66.google.com with SMTP id x21so6057003ywx.11 for ; Mon, 04 Mar 2019 21:51:52 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=xYiPgxSrNHNTHRrBP8ONZ8gMKJIb1jwuyLJUSyRjVLU=; b=FZ2+OAzh0K20tESdi9jkqknlE1bWaX2TVJHagHdfIkBUouGb04l4C0/tbaU88CBbr3 cv/IWny56xZ233Ari5VULsNC8pnqCzw0i8ld8e3AXgV9Bdemkdeu1zT0S8W7L4GsLyRs EWbodRgaYrM2AeSZ4iPGKm4QujH3O8JIa5/3DVe7v9GSsHYrc1K0V+3A8Ldr0uI/Rr1A o8GZLAPaASwjApG9QeutYuAAi0j8M/X2+zb7+UD+D149mPLbDMOF3SkHbhHbSoZEONmM ESebP6VdpYfgUUTg3/bvTcZBPLjrVVpY1tr8ld92xS0JVFHmw9uRNgwV9qlkTWCCEH9m ubUw== 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:mime-version:content-transfer-encoding; bh=xYiPgxSrNHNTHRrBP8ONZ8gMKJIb1jwuyLJUSyRjVLU=; b=HjWRHnQNi0+idp1/7EVXCIM9fE5LpB4zfRbKCmj4CUUEcUpGXoxFzG/MXMc4cMAx2r IAAHpk/cPjvl+fXDzQll5nYXi3hGhl3UltMvKcqE4DCOwJjGaAjkhP7pazLLVB8+egzX GfpfPVqqat/hrx3VNoSQ1WracA6ASdtTfXwVdmn9P6K2Ypr+WPxXfieuNBndf5VcuymO RrCT0EHRkvl8WBrorGNp2cPxkz9ek3v3DE8dHDTlABJ8NDBrXTukazAMqH/cFd9wEBLi nOu5D5iM7Y94li9Q/z1ig5Ztg2icT8UJvIXEwGFpa+lqW8qg73n1scxLWCxGxAfBhdy5 KS9w== X-Gm-Message-State: APjAAAUlqVjRwEdx0wfoBnCJc820Dd4kxE/5ej6huTWzNFgnz/g9X5cV Vrh/3EROWRdaiTaYutAg2RT8nA== X-Google-Smtp-Source: APXvYqx7yZJ2LdLoSLJ0f0oCIzyYQ17lLIAknm/5vBTviXTVTvdVXodA3FIMxLnXbXiFmUs3y242Vw== X-Received: by 2002:a81:3a81:: with SMTP id h123mr17672174ywa.412.1551765111862; Mon, 04 Mar 2019 21:51:51 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g39sm3546145ywk.50.2019.03.04.21.51.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2019 21:51:51 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@suse.de Date: Tue, 5 Mar 2019 14:53:31 +0900 Message-Id: <20190305055337.3793-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305055337.3793-1-takahiro.akashi@linaro.org> References: <20190305055337.3793-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC 2/8] efi_loader: boottime: export efi_[un]load_image() 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Those two functions will be used later to re-implement do_bootefi_exec(). Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- include/efi_loader.h | 9 +++++++++ lib/efi_loader/efi_boottime.c | 14 +++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 512880ab8fbf..47a51ddc9406 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -320,10 +320,19 @@ efi_status_t efi_create_handle(efi_handle_t *handle); void efi_delete_handle(efi_handle_t obj); /* Call this to validate a handle and find the EFI object for it */ struct efi_object *efi_search_obj(const efi_handle_t handle); +/* Load image */ +efi_status_t EFIAPI efi_load_image(bool boot_policy, + efi_handle_t parent_image, + struct efi_device_path *file_path, + void *source_buffer, + efi_uintn_t source_size, + efi_handle_t *image_handle); /* Start image */ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, efi_uintn_t *exit_data_size, u16 **exit_data); +/* Unload image */ +efi_status_t EFIAPI efi_unload_image(efi_handle_t image_handle); /* Find a protocol on a handle */ efi_status_t efi_search_protocol(const efi_handle_t handle, const efi_guid_t *protocol_guid, diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 7bd9c0a952d4..c6991d353497 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1672,12 +1672,12 @@ error: * * Return: status code */ -static efi_status_t EFIAPI efi_load_image(bool boot_policy, - efi_handle_t parent_image, - struct efi_device_path *file_path, - void *source_buffer, - efi_uintn_t source_size, - efi_handle_t *image_handle) +efi_status_t EFIAPI efi_load_image(bool boot_policy, + efi_handle_t parent_image, + struct efi_device_path *file_path, + void *source_buffer, + efi_uintn_t source_size, + efi_handle_t *image_handle) { struct efi_device_path *dp, *fp; struct efi_loaded_image *info = NULL; @@ -1871,7 +1871,7 @@ static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle, * * Return: status code */ -static efi_status_t EFIAPI efi_unload_image(efi_handle_t image_handle) +efi_status_t EFIAPI efi_unload_image(efi_handle_t image_handle) { struct efi_object *efiobj; From patchwork Tue Mar 5 05:53:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1051626 X-Patchwork-Delegate: xypron.glpk@gmx.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; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="VSmpGF6O"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44D5gX2CDDz9s47 for ; Tue, 5 Mar 2019 16:54:16 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 0FADFC21E13; Tue, 5 Mar 2019 05:53:00 +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_DNSWL_BLOCKED, 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 691CCC21E1B; Tue, 5 Mar 2019 05:52:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 85A7EC21E15; Tue, 5 Mar 2019 05:52:00 +0000 (UTC) Received: from mail-yw1-f54.google.com (mail-yw1-f54.google.com [209.85.161.54]) by lists.denx.de (Postfix) with ESMTPS id 27E44C21D8E for ; Tue, 5 Mar 2019 05:51:55 +0000 (UTC) Received: by mail-yw1-f54.google.com with SMTP id 189so6072445ywi.3 for ; Mon, 04 Mar 2019 21:51:55 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=xP/nc3FbfoZl2hnzcLcPj/UK18AZmP8c5obatayjf9Y=; b=VSmpGF6OjpnCywciHh5z5YGvW3adR0CAsVAX9vakxPMcou2V8V0J7EC0HB+iQhq3Eo jjmAVXeYSQbtySGYXm3zaOakX9viYnscBGy1wQpaGM9HzFkv+lqZmxZvLPtgz8tl77vc l9rkVrwtkUjMzKGmN2W6HwcF4DP7YuM4WK8kbcdtryI3EpN1LxU1R6YZ9MbexxotB0PW Oxl4OkDkqcK9CpJziEJZSGtMOfSV7X5TjKpha4ZQP+8lsYySeOUUJS6udUkJqtIwfQka gYeqqCA11A5PU+yZyQViqIK2gqwUVeIemfGfil8rWbm+316a7JmcY5nMQPXPn26v3+Jo Huig== 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:mime-version:content-transfer-encoding; bh=xP/nc3FbfoZl2hnzcLcPj/UK18AZmP8c5obatayjf9Y=; b=OjlsDuR855UtEc1SkJMoMY3DFkWEgjHxlQ74n2y7yiAFNyqNaQY6GudVF4UvqbTiuS FX++xCSVMnh6p6xbEZf2eq9E9SuMpATyNE7VHbnVHgBOcA/gYuGQLfg3r6G7s0/BI3GQ b1sphseUGLJVXwLTCqnyVjHqcMX4jRPWI30dmLdIynx8RmTJiFTKvCRB5Vr3zcXndDBx 7Kb9HQmpDdeKvSsseT5j+1PYU2TxO1TfYnt64IOafNHWqGux1n6cTEwdku3XXPuuAUet EozEhO5L0Pd2oNRaaES2xKMKv1rvLZnzIA2fqYnk6neXm2HaQDq8sSo5IKeuHI+Pumxk zkpw== X-Gm-Message-State: APjAAAXWJqDH5K2tEn0e3EVRNsubHI8dy7hqvxjJ6QmpmGQBDe8R4Fu3 nXyiBuHpztr1Htf3UEaMExHZo4Xx/YY= X-Google-Smtp-Source: APXvYqxERJzGLLAWxw08zS1FH0OL7kVTLm4Pht70lM95ooUMPz1xL945yFJmqofLdtpmlEVwclmGtw== X-Received: by 2002:a25:f810:: with SMTP id u16mr801129ybd.290.1551765114109; Mon, 04 Mar 2019 21:51:54 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id q190sm3301362ywd.6.2019.03.04.21.51.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2019 21:51:53 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@suse.de Date: Tue, 5 Mar 2019 14:53:32 +0900 Message-Id: <20190305055337.3793-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305055337.3793-1-takahiro.akashi@linaro.org> References: <20190305055337.3793-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC 3/8] efi_loader: bootmgr: return pointer and size of buffer in loading 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" We need to know the size of image loaded so as to be able to use load_image() API at do_bootefi_exec() in a later patch. So change the interface of efi_bootmgr_load(). Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 5 +++-- lib/efi_loader/efi_bootmgr.c | 41 +++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 47a51ddc9406..3f51116155ad 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -564,8 +564,9 @@ struct efi_load_option { void efi_deserialize_load_option(struct efi_load_option *lo, u8 *data); unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data); -void *efi_bootmgr_load(struct efi_device_path **device_path, - struct efi_device_path **file_path); +efi_status_t efi_bootmgr_load(struct efi_device_path **device_path, + struct efi_device_path **file_path, + void **image, efi_uintn_t *size); #else /* CONFIG_IS_ENABLED(EFI_LOADER) */ diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 1575c5c09e46..38f3fa15f6ef 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -120,14 +120,17 @@ static void *get_var(u16 *name, const efi_guid_t *vendor, * if successful. This checks that the EFI_LOAD_OPTION is active (enabled) * and that the specified file to boot exists. */ -static void *try_load_entry(uint16_t n, struct efi_device_path **device_path, - struct efi_device_path **file_path) +static efi_status_t try_load_entry(u16 n, + struct efi_device_path **device_path, + struct efi_device_path **file_path, + void **image, efi_uintn_t *image_size) { struct efi_load_option lo; u16 varname[] = L"Boot0000"; u16 hexmap[] = L"0123456789ABCDEF"; - void *load_option, *image = NULL; + void *load_option; efi_uintn_t size; + efi_status_t ret; varname[4] = hexmap[(n & 0xf000) >> 12]; varname[5] = hexmap[(n & 0x0f00) >> 8]; @@ -136,18 +139,17 @@ static void *try_load_entry(uint16_t n, struct efi_device_path **device_path, load_option = get_var(varname, &efi_global_variable_guid, &size); if (!load_option) - return NULL; + return EFI_LOAD_ERROR; efi_deserialize_load_option(&lo, load_option); if (lo.attributes & LOAD_OPTION_ACTIVE) { u32 attributes; - efi_status_t ret; debug("%s: trying to load \"%ls\" from %pD\n", __func__, lo.label, lo.file_path); - ret = efi_load_image_from_path(lo.file_path, &image, &size); + ret = efi_load_image_from_path(lo.file_path, image, image_size); if (ret != EFI_SUCCESS) goto error; @@ -164,12 +166,14 @@ static void *try_load_entry(uint16_t n, struct efi_device_path **device_path, printf("Booting: %ls\n", lo.label); efi_dp_split_file_path(lo.file_path, device_path, file_path); + } else { + ret = EFI_LOAD_ERROR; } error: free(load_option); - return image; + return ret; } /* @@ -177,12 +181,12 @@ error: * EFI variable, the available load-options, finding and returning * the first one that can be loaded successfully. */ -void *efi_bootmgr_load(struct efi_device_path **device_path, - struct efi_device_path **file_path) +efi_status_t efi_bootmgr_load(struct efi_device_path **device_path, + struct efi_device_path **file_path, + void **image, efi_uintn_t *image_size) { u16 bootnext, *bootorder; efi_uintn_t size; - void *image = NULL; int i, num; efi_status_t ret; @@ -201,9 +205,9 @@ void *efi_bootmgr_load(struct efi_device_path **device_path, (efi_guid_t *)&efi_global_variable_guid, 0, 0, &bootnext)); if (ret == EFI_SUCCESS) { - image = try_load_entry(bootnext, - device_path, file_path); - if (image) + ret = try_load_entry(bootnext, device_path, file_path, + image, image_size); + if (ret == EFI_SUCCESS) goto error; } } @@ -212,19 +216,22 @@ void *efi_bootmgr_load(struct efi_device_path **device_path, bootorder = get_var(L"BootOrder", &efi_global_variable_guid, &size); if (!bootorder) { printf("BootOrder not defined\n"); + ret = EFI_NOT_FOUND; goto error; } num = size / sizeof(uint16_t); for (i = 0; i < num; i++) { - debug("%s: trying to load Boot%04X\n", __func__, bootorder[i]); - image = try_load_entry(bootorder[i], device_path, file_path); - if (image) + debug("%s: trying to load Boot%04X\n", __func__, + bootorder[i]); + ret = try_load_entry(bootorder[i], device_path, file_path, + image, image_size); + if (ret == EFI_SUCCESS) break; } free(bootorder); error: - return image; + return ret; } From patchwork Tue Mar 5 05:53:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1051625 X-Patchwork-Delegate: xypron.glpk@gmx.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; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="xE3C3AnG"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44D5gW1vqkz9s1B for ; Tue, 5 Mar 2019 16:54:15 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id E740DC21E16; Tue, 5 Mar 2019 05:52:31 +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_DNSWL_NONE, 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 650EBC21DFB; Tue, 5 Mar 2019 05:52:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 23062C21E29; Tue, 5 Mar 2019 05:52:01 +0000 (UTC) Received: from mail-yw1-f51.google.com (mail-yw1-f51.google.com [209.85.161.51]) by lists.denx.de (Postfix) with ESMTPS id 7D4BEC21DD3 for ; Tue, 5 Mar 2019 05:51:57 +0000 (UTC) Received: by mail-yw1-f51.google.com with SMTP id x21so6057089ywx.11 for ; Mon, 04 Mar 2019 21:51:57 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=T6zyIAh74lqOi0hLc+bw6oqcFQhizFsJ2kZYrCi9UHE=; b=xE3C3AnGm2n4RfF+KICidVLYgAuxWpurUDvo1H9PcyreWUq3QuMIG1yd/TfBh1Bkqs ziRd3I2wugkru2VCQ0K9COOoRW6W+PLpaWDW7oIi0bafVvhvIkuYcyTbEdeFyFXvYsI2 /BsSXYukRESk1ZEl/sLT8c2/rpE1aXaI3djPnAlY/ZBum5rk53+H/tgWUytdHMnli0hb aGtxZneKidD84u6FP2QdM1qIs+Mz7NYzP8sYxKVLXB8HfJM96TwJsCuiSo6vYMFMcXKW fDKCO/QdJCriJlxnqHmuE3TXFsI9NBQWrpaZgSbnyiuh4vgkRatqUevXCcIxivbbtnpZ sV0g== 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:mime-version:content-transfer-encoding; bh=T6zyIAh74lqOi0hLc+bw6oqcFQhizFsJ2kZYrCi9UHE=; b=kygGC2HqGYvAAHWqsHPk7yFrmPOHyp2HxU9T5F1kwhE70U8E08QZj7Tjw6ATxDI786 kj0e7fDDgKRUUeLAGJXHfpqkN7lohai0yokH3/ZuoYp9B0J1HgO4f1d0d/rcfaF5jMW5 ipmRP+WNHlNR26cSlPcsuGTuFWlhtj/G7PG+zbU+o0MuX+vK2LIncuvq5dqw0cqqSIdr b/tQkF9EzX222o8OKbtCsAk88RYoCpsnVs5ghZk/5VjonmuZBallMzGY0Dt0OjdpZpxg YTJ4NB+W7W9QEYJqWyfknxQOdwlPjBtPv35muxM8+YODY3J8fFmK1gLEdEmu4IO6R5UA 4ZOg== X-Gm-Message-State: APjAAAXayXhsZmxgcpCV+Iwu6Cfw8qi0adFGD91+h4Rn4bGpA2Ti4aHy CalHW89bGCHl1u32clPrDgAsBw== X-Google-Smtp-Source: APXvYqzOGd+oHcPOcgungONjBR/OAbUXZQ/28ApTxnY9wszMScER0VPjHe8ltOYYrs5b0auf33nFJw== X-Received: by 2002:a5b:b8b:: with SMTP id l11mr744771ybq.373.1551765116506; Mon, 04 Mar 2019 21:51:56 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id n128sm2690388ywf.74.2019.03.04.21.51.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2019 21:51:56 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@suse.de Date: Tue, 5 Mar 2019 14:53:33 +0900 Message-Id: <20190305055337.3793-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305055337.3793-1-takahiro.akashi@linaro.org> References: <20190305055337.3793-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC 4/8] cmd: bootefi: move do_bootefi_bootmgr_exec() forward 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This is a preparatory patch. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 3619a20e6433..1d90e7b4b575 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -314,6 +314,27 @@ err_add_protocol: return ret; } +static int do_bootefi_bootmgr_exec(void) +{ + struct efi_device_path *device_path, *file_path; + void *addr; + efi_status_t r; + + addr = efi_bootmgr_load(&device_path, &file_path); + if (!addr) + return 1; + + printf("## Starting EFI application at %p ...\n", addr); + r = do_bootefi_exec(addr, device_path, file_path); + printf("## Application terminated, r = %lu\n", + r & ~EFI_ERROR_MASK); + + if (r != EFI_SUCCESS) + return 1; + + return 0; +} + #ifdef CONFIG_CMD_BOOTEFI_SELFTEST /** * bootefi_test_prepare() - prepare to run an EFI test @@ -362,27 +383,6 @@ failure: #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ -static int do_bootefi_bootmgr_exec(void) -{ - struct efi_device_path *device_path, *file_path; - void *addr; - efi_status_t r; - - addr = efi_bootmgr_load(&device_path, &file_path); - if (!addr) - return 1; - - printf("## Starting EFI application at %p ...\n", addr); - r = do_bootefi_exec(addr, device_path, file_path); - printf("## Application terminated, r = %lu\n", - r & ~EFI_ERROR_MASK); - - if (r != EFI_SUCCESS) - return 1; - - return 0; -} - /* Interpreter command to boot an arbitrary EFI image from memory */ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { From patchwork Tue Mar 5 05:53:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1051624 X-Patchwork-Delegate: xypron.glpk@gmx.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; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="h+MX7zNF"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44D5ft6ftLz9s1B for ; Tue, 5 Mar 2019 16:53:42 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 73674C21DA1; Tue, 5 Mar 2019 05:52:46 +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_DNSWL_NONE, 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 D215DC21C38; Tue, 5 Mar 2019 05:52:11 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AEE5CC21DA2; Tue, 5 Mar 2019 05:52:04 +0000 (UTC) Received: from mail-yw1-f44.google.com (mail-yw1-f44.google.com [209.85.161.44]) by lists.denx.de (Postfix) with ESMTPS id 1FDA3C21E30 for ; Tue, 5 Mar 2019 05:52:01 +0000 (UTC) Received: by mail-yw1-f44.google.com with SMTP id 189so6072560ywi.3 for ; Mon, 04 Mar 2019 21:52:01 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=tqJj1MifuuAMKX7ZTJwBmZ0a62lNmha/+Gs3R0OjvAM=; b=h+MX7zNF/02z8xa0T+q/goLdkmvJWcM6aijabbgc61pSmtyunEt3XAaYwQSkx4ud8t oedKXXEVnAGkouxtM2hKomfQKrIdytuCDWI01O8U+2jc45XEyEOIDEa49MMJRIGFxdMK SswEx83C9/HvbHWPlvz61GiEa9aeuWVG/npLnCAyh3JphB1uPjVq9wpkHLck6mF7rCZ1 QOjL2hHHjXzojdIRJxEzc0dKhm3MOnazewxUNiNt9QCOfodRP48YbmLYH/qiUrX+aaaD p5nDFYbkpBpKGRoIidNq+BCsFxYsEMA7R5jr/PkogAQs1iktGd9ww/lDO5AHyXiRNzKD UtwA== 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:mime-version:content-transfer-encoding; bh=tqJj1MifuuAMKX7ZTJwBmZ0a62lNmha/+Gs3R0OjvAM=; b=K4srIW0RMTctqbV09TGv6uX4Pb3zInzjIFx92ntLK5vwZYZe9zPwY8/nQU8ZuccTwK W3gvjdpHrVLtgkIqXcWwUpVhFYZaviuXygEZHWmER4RUJFouLLVBUn7RxuDP5LbIm4zE rym7By6W+rEskYQMwSn+vZLLEdHOX7vSW01oXVENuvNMSfqa0mpP3uTavpNXha7yCNUJ gnhsArewFVI8eBfDPgA4e1W4ojtyy13bviwXGQ6iAnbJY4xhonifjDaVtnGKt04I9LFm lPnieaUQetO/0qr6C64I25gUuZ27rEOTRdpFc364IxLN5LuJNuF4v9PX0txJGiCk/eOa Es1g== X-Gm-Message-State: APjAAAVSUYAP2M/tCBdalOTVMt1Uvcd3QU5jgC7EwPJcfi9REbL0Yy1X uCj4PAz3e9bSidh6COcxKrdMag== X-Google-Smtp-Source: APXvYqx7ZY2ZqG0MzW2vxi/kaIfQeLQaiGO2bdfqz2s7XZ/zLds8kdVBr0DIdqKEQHNk2S7k2xhS0Q== X-Received: by 2002:a0d:dc83:: with SMTP id f125mr17519332ywe.67.1551765118658; Mon, 04 Mar 2019 21:51:58 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p13sm803142ywe.80.2019.03.04.21.51.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2019 21:51:58 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@suse.de Date: Tue, 5 Mar 2019 14:53:34 +0900 Message-Id: <20190305055337.3793-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305055337.3793-1-takahiro.akashi@linaro.org> References: <20190305055337.3793-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC 5/8] cmd: bootefi: carve out fdt handling 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This is a preparatory patch for reworking do_bootefi() in later patch. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 53 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 1d90e7b4b575..8915cdbfd5f5 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -198,6 +198,40 @@ static efi_status_t efi_install_fdt(ulong fdt_addr) return ret; } +/** + * efi_process_fdt() - process fdt passed by a command argument + * @fdt_opt: pointer to argument + * Return: CMD_RET_SUCCESS on success, + CMD_RET_USAGE or CMD_RET_FAILURE otherwise + * + * If specified, fdt will be installed as configuration table, + * otherwise no fdt will be passed. + */ +static int efi_process_fdt(const char *fdt_opt) +{ + unsigned long fdt_addr; + efi_status_t r; + + if (fdt_opt) { + fdt_addr = simple_strtoul(fdt_opt, NULL, 16); + if (!fdt_addr && *fdt_opt != '0') + return CMD_RET_USAGE; + + /* Install device tree */ + r = efi_install_fdt(fdt_addr); + if (r != EFI_SUCCESS) { + printf("ERROR: failed to install device tree\n"); + return CMD_RET_FAILURE; + } + } else { + /* Remove device tree. EFI_NOT_FOUND can be ignored here */ + efi_install_configuration_table(&efi_guid_fdt, NULL); + printf("WARNING: booting without device tree\n"); + } + + return CMD_RET_SUCCESS; +} + static efi_status_t bootefi_run_prepare(const char *load_options_path, struct efi_device_path *device_path, struct efi_device_path *image_path, @@ -407,21 +441,10 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc < 2) return CMD_RET_USAGE; - if (argc > 2) { - fdt_addr = simple_strtoul(argv[2], NULL, 16); - if (!fdt_addr && *argv[2] != '0') - return CMD_RET_USAGE; - /* Install device tree */ - r = efi_install_fdt(fdt_addr); - if (r != EFI_SUCCESS) { - printf("ERROR: failed to install device tree\n"); - return CMD_RET_FAILURE; - } - } else { - /* Remove device tree. EFI_NOT_FOUND can be ignored here */ - efi_install_configuration_table(&efi_guid_fdt, NULL); - printf("WARNING: booting without device tree\n"); - } + ret = fdt_process_fdt(argc > 2 ? argv[2] : NULL); + if (ret != EFI_SUCCESS) + return ret; + #ifdef CONFIG_CMD_BOOTEFI_HELLO if (!strcmp(argv[1], "hello")) { ulong size = __efi_helloworld_end - __efi_helloworld_begin; From patchwork Tue Mar 5 05:53:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1051629 X-Patchwork-Delegate: xypron.glpk@gmx.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; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="HTfWwupK"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44D5jY4kbpz9s1B for ; Tue, 5 Mar 2019 16:56:01 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 2E88EC21E29; Tue, 5 Mar 2019 05:53:35 +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_DNSWL_NONE, 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 AB9C2C21E26; Tue, 5 Mar 2019 05:52:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2572BC21E26; Tue, 5 Mar 2019 05:52:05 +0000 (UTC) Received: from mail-yw1-f65.google.com (mail-yw1-f65.google.com [209.85.161.65]) by lists.denx.de (Postfix) with ESMTPS id F1C66C21DB3 for ; Tue, 5 Mar 2019 05:52:01 +0000 (UTC) Received: by mail-yw1-f65.google.com with SMTP id v201so6062985ywa.9 for ; Mon, 04 Mar 2019 21:52:01 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=0AxDcKreaizb07ZEoDNQxiLyrBckspg4LwBbaPafkPk=; b=HTfWwupKGfL8y8OcPMTLk+OGsDFIXlQaL2HFmTWVGcZwQ70CmQwMghqDjrAtcqcj2z GyAGsmBo2Lcb6LMMWY7zdHsydYGa7QP74MKVcMfVoRwm9TbX775OZXVMFUSbN/AQVGuP Z1sM5Y4Ma1PX4EHoTSPZFmavWQc8RwWx/wneOL8qRS04BmqybMzgv+ow+axZ/Urh+0j7 Qu8kaIwwl1E9Q2p1RVRDQA6QzgJznGGMZuRYeeC0yx7qkj4pbMEy/Qj+IvHvyS4hE7NV ZksSM6p7Lx/bfOsKZlikfWVZgRwxVJxhgN9ruyWCb/KOuIEawjQDqVSW040/50IQN7lU J5WQ== 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:mime-version:content-transfer-encoding; bh=0AxDcKreaizb07ZEoDNQxiLyrBckspg4LwBbaPafkPk=; b=qvAmDH7hsurk6dBUX0g58HxVivW6gMH6R5+HYhcw0RH0Q6q6R/Ii83+gYJbudBrKK9 w7C2eF3x9U7QOkJ4X1mh+8LU5LCByzSsOvnOjLolL2cIiQ8O+BYDjN1zlV+zvrirgxeR AEGoPJ6w2Sg8yJme/2c7gUlVU3E+csYEXiqbHKR1hGL7JkvrAB34fFk7j6D1Q54oncp1 NpKD7GTR0HqRv091kpUFuRnrXZ1SrFMZyQyaIcXalNfJiBlvbOg5vEc526xn30jxfBh0 J0adzcjDF0HfAH8Hr6hJTJN1KerWPGIP8ue6szqD32WiTzLMz078RjDKtEi8F177NWEc PEww== X-Gm-Message-State: APjAAAWb7SG11lylzK7wKvblwom2ct1nMbWLfud6Gy/Wmfb/+uY8OqJQ CuCIwCTI61BYrDlPOSFNHPQNMA== X-Google-Smtp-Source: APXvYqzopWH4h0z+brexnp5efMakBUj+SkiqAFMALnhDXpiJ5GEXKgWPk0SQSU2UdPwG0Xs+9eDKYw== X-Received: by 2002:a25:13c5:: with SMTP id 188mr723875ybt.473.1551765120943; Mon, 04 Mar 2019 21:52:00 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 205sm2720224ywd.15.2019.03.04.21.52.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2019 21:52:00 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@suse.de Date: Tue, 5 Mar 2019 14:53:35 +0900 Message-Id: <20190305055337.3793-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305055337.3793-1-takahiro.akashi@linaro.org> References: <20190305055337.3793-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC 6/8] cmd: bootefi: carve out efi_selftest code from do_bootefi() 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This is a preparatory patch for reworking do_bootefi() in a later patch. Efi_selftest code is unusual in terms of execution path in do_bootefi(), which make that function complicated and hard to understand. With this patch, all efi_selftest related code will be put in a separate function. The change also includes expanding efi_run_prepare() and efi_run_finish() in do_bootefi_exec(). Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 146 +++++++++++++++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 55 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 8915cdbfd5f5..1470122af266 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -232,39 +232,6 @@ static int efi_process_fdt(const char *fdt_opt) return CMD_RET_SUCCESS; } -static efi_status_t bootefi_run_prepare(const char *load_options_path, - struct efi_device_path *device_path, - struct efi_device_path *image_path, - struct efi_loaded_image_obj **image_objp, - struct efi_loaded_image **loaded_image_infop) -{ - efi_status_t ret; - - ret = efi_setup_loaded_image(device_path, image_path, image_objp, - loaded_image_infop); - if (ret != EFI_SUCCESS) - return ret; - - /* Transfer environment variable as load options */ - set_load_options(*loaded_image_infop, load_options_path); - - return 0; -} - -/** - * bootefi_run_finish() - finish up after running an EFI test - * - * @loaded_image_info: Pointer to a struct which holds the loaded image info - * @image_objj: Pointer to a struct which holds the loaded image object - */ -static void bootefi_run_finish(struct efi_loaded_image_obj *image_obj, - struct efi_loaded_image *loaded_image_info) -{ - efi_restore_gd(); - free(loaded_image_info->load_options); - efi_delete_handle(&image_obj->header); -} - /** * do_bootefi_exec() - execute EFI binary * @@ -311,11 +278,14 @@ static efi_status_t do_bootefi_exec(void *efi, assert(device_path && image_path); } - ret = bootefi_run_prepare("bootargs", device_path, image_path, - &image_obj, &loaded_image_info); + ret = efi_setup_loaded_image(device_path, image_path, &image_obj, + &loaded_image_info); if (ret) goto err_prepare; + /* Transfer environment variable as load options */ + set_load_options(loaded_image_info, "bootargs"); + /* Load the EFI payload */ ret = efi_load_pe(image_obj, efi, loaded_image_info); if (ret != EFI_SUCCESS) @@ -339,7 +309,9 @@ static efi_status_t do_bootefi_exec(void *efi, err_prepare: /* image has returned, loaded-image obj goes *poof*: */ - bootefi_run_finish(image_obj, loaded_image_info); + efi_restore_gd(); + free(loaded_image_info->load_options); + efi_delete_handle(&image_obj->header); err_add_protocol: if (mem_handle) @@ -370,6 +342,25 @@ static int do_bootefi_bootmgr_exec(void) } #ifdef CONFIG_CMD_BOOTEFI_SELFTEST +static efi_status_t bootefi_run_prepare(const char *load_options_path, + struct efi_device_path *device_path, + struct efi_device_path *image_path, + struct efi_loaded_image_obj **image_objp, + struct efi_loaded_image **loaded_image_infop) +{ + efi_status_t ret; + + ret = efi_setup_loaded_image(device_path, image_path, image_objp, + loaded_image_infop); + if (ret != EFI_SUCCESS) + return ret; + + /* Transfer environment variable as load options */ + set_load_options(*loaded_image_infop, load_options_path); + + return 0; +} + /** * bootefi_test_prepare() - prepare to run an EFI test * @@ -415,6 +406,63 @@ failure: return ret; } +/** + * bootefi_run_finish() - finish up after running an EFI test + * + * @loaded_image_info: Pointer to a struct which holds the loaded image info + * @image_objj: Pointer to a struct which holds the loaded image object + */ +static void bootefi_run_finish(struct efi_loaded_image_obj *image_obj, + struct efi_loaded_image *loaded_image_info) +{ + efi_restore_gd(); + free(loaded_image_info->load_options); + efi_delete_handle(&image_obj->header); +} + +/** + * do_efi_selftest() - execute EFI Selftest + * + * @fdt_opt: string of fdt start address + * Return: status code + * + * Execute EFI Selftest + */ +static int do_efi_selftest(const char *fdt_opt) +{ + struct efi_loaded_image_obj *image_obj; + struct efi_loaded_image *loaded_image_info; + efi_status_t r; + int ret; + + /* Allow unaligned memory access */ + allow_unaligned(); + + switch_to_non_secure_mode(); + + /* Initialize EFI drivers */ + r = efi_init_obj_list(); + if (r != EFI_SUCCESS) { + printf("Error: Cannot set up EFI drivers, r = %lu\n", + r & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_process_fdt(fdt_opt); + if (ret != EFI_SUCCESS) + return ret; + + r = bootefi_test_prepare(&image_obj, &loaded_image_info, + "\\selftest", "efi_selftest"); + if (r != EFI_SUCCESS) + return CMD_RET_FAILURE; + + /* Execute the test */ + r = EFI_CALL(efi_selftest(&image_obj->header, &systab)); + bootefi_run_finish(image_obj, loaded_image_info); + + return r != EFI_SUCCESS; +} #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ /* Interpreter command to boot an arbitrary EFI image from memory */ @@ -425,6 +473,13 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) efi_status_t r; unsigned long fdt_addr; + if (argc < 2) + return CMD_RET_USAGE; +#ifdef CONFIG_CMD_BOOTEFI_SELFTEST + else if (!strcmp(argv[1], "selftest")) + return do_efi_selftest(argc > 2 ? argv[2] : NULL); +#endif + /* Allow unaligned memory access */ allow_unaligned(); @@ -438,9 +493,6 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_FAILURE; } - if (argc < 2) - return CMD_RET_USAGE; - ret = fdt_process_fdt(argc > 2 ? argv[2] : NULL); if (ret != EFI_SUCCESS) return ret; @@ -456,22 +508,6 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) addr = CONFIG_SYS_LOAD_ADDR; memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size); } else -#endif -#ifdef CONFIG_CMD_BOOTEFI_SELFTEST - if (!strcmp(argv[1], "selftest")) { - struct efi_loaded_image_obj *image_obj; - struct efi_loaded_image *loaded_image_info; - - r = bootefi_test_prepare(&image_obj, &loaded_image_info, - "\\selftest", "efi_selftest"); - if (r != EFI_SUCCESS) - return CMD_RET_FAILURE; - - /* Execute the test */ - r = EFI_CALL(efi_selftest(&image_obj->header, &systab)); - bootefi_run_finish(image_obj, loaded_image_info); - return r != EFI_SUCCESS; - } else #endif if (!strcmp(argv[1], "bootmgr")) { return do_bootefi_bootmgr_exec(); From patchwork Tue Mar 5 05:53:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1051627 X-Patchwork-Delegate: xypron.glpk@gmx.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; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="pBzQsGLW"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44D5h21944z9s47 for ; Tue, 5 Mar 2019 16:54:42 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id C470AC21E16; Tue, 5 Mar 2019 05:53:15 +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_DNSWL_NONE, 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 35632C21E2F; Tue, 5 Mar 2019 05:52:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 11286C21DDC; Tue, 5 Mar 2019 05:52:08 +0000 (UTC) Received: from mail-yw1-f65.google.com (mail-yw1-f65.google.com [209.85.161.65]) by lists.denx.de (Postfix) with ESMTPS id 886B5C21E38 for ; Tue, 5 Mar 2019 05:52:04 +0000 (UTC) Received: by mail-yw1-f65.google.com with SMTP id u200so6062214ywu.10 for ; Mon, 04 Mar 2019 21:52:04 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=SF9YjGy5qiNWgIYIMepqar37qWZGmQ2LaxbgUqBVFik=; b=pBzQsGLWpgaWbobb1HYqLuSrFwTGLR+i4ABcluBpxpbfBXbEPo+0OXm+cwEU+yvonw xmBs8mpmepv2Kp97JyVAPR6IqDVL8oCtsJzIo6WQQt81BCHC+aUGKLArwhfGZ1TBALqn d2cUHMMklZHRwDnrPgIfGdF0add9kssmc67jyxJxRWWQOA6+OoPwAvlT4XBhC+q8kl7s KR4IEI9n4SBHJ8zuEBqV7T0t43Xu5RO1R386/qqRrk42VekvVz9MPab6Bl9CSHsaAQUt 0C/0ELK8rE552zCF2TzRA6swoKiMf5scaWvSYHlr78qC4yZvOdelwsFA/OQXSEwMr64e KqfQ== 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:mime-version:content-transfer-encoding; bh=SF9YjGy5qiNWgIYIMepqar37qWZGmQ2LaxbgUqBVFik=; b=UAj+8lV80uGPzUGStJo0r+5k/T5mVMsKgZMjfsD/sAY+9AlmPwDZch3D1k0pztvWkf 8LQ931pD303FKpTREZGE9fGhb6fN/e9mKETGIWDbH72ZT3WobiFSKCcQ+ZkerPzvPCM1 D14CtEl9IYYdPJwf2Zr/JE7cTdRP7IeRwsi+XCaP7FYSwJPIMvn2sOfRHrZMgqc2zYo9 PyNC126zRdjASBmzrds8mhnRdiGizLyZZybzajCnvdAGiyy2T7GoypMVllr2N8QC621w R2im9LEXQwcLSCmrz03krflppGFgwGbOcZN7PwIVTribTVmzGKD/6U4onq8FOlVoOZ5h qYxA== X-Gm-Message-State: APjAAAVJB0np/ICLI+n83lk31G16n17uEJbmxupej9c7A2Xd9oE4tN6m 2UzUjQ0tWXgPjYLQI3w2PtO1zA== X-Google-Smtp-Source: APXvYqwO9TO+9QCohHViJdDmPC2HP5cuR10nVuggiGTVkqFw+Y+ZNKr7cLJ7FNXwbTG7o3zkDER7tg== X-Received: by 2002:a25:8241:: with SMTP id d1mr738355ybn.345.1551765123372; Mon, 04 Mar 2019 21:52:03 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id q190sm3301473ywd.6.2019.03.04.21.52.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2019 21:52:03 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@suse.de Date: Tue, 5 Mar 2019 14:53:36 +0900 Message-Id: <20190305055337.3793-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305055337.3793-1-takahiro.akashi@linaro.org> References: <20190305055337.3793-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC 7/8] cmd: bootefi: rework do_bootefi(), using load_image API 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" In this patch, do_bootefi() and do_bootefi_exec() will be reworked, without any functional change so that load_image() API as well as start_image() are used in the implementation. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 252 ++++++++++++++++++++++------------ lib/efi_loader/efi_boottime.c | 14 +- 2 files changed, 170 insertions(+), 96 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 1470122af266..00cacbdd4231 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -236,6 +236,7 @@ static int efi_process_fdt(const char *fdt_opt) * do_bootefi_exec() - execute EFI binary * * @efi: address of the binary + * @efi_size: size of the binary * @device_path: path of the device from which the binary was loaded * @image_path: device path of the binary * Return: status code @@ -243,15 +244,16 @@ static int efi_process_fdt(const char *fdt_opt) * Load the EFI binary into a newly assigned memory unwinding the relocation * information, install the loaded image protocol, and call the binary. */ -static efi_status_t do_bootefi_exec(void *efi, +static efi_status_t do_bootefi_exec(void *efi, efi_uintn_t efi_size, struct efi_device_path *device_path, struct efi_device_path *image_path) { - efi_handle_t mem_handle = NULL; + efi_handle_t mem_handle = NULL, handle; struct efi_device_path *memdp = NULL; - efi_status_t ret; + struct efi_device_path *file_path = NULL; struct efi_loaded_image_obj *image_obj = NULL; struct efi_loaded_image *loaded_image_info = NULL; + efi_status_t ret; /* * Special case for efi payload not loaded from disk, such as @@ -260,36 +262,42 @@ static efi_status_t do_bootefi_exec(void *efi, */ if (!device_path && !image_path) { printf("WARNING: using memory device/image path, this may confuse some payloads!\n"); - /* actual addresses filled in after efi_load_pe() */ + /* actual addresses filled in after efi_load_image() */ memdp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, 0, 0); - device_path = image_path = memdp; + file_path = memdp; /* append(memdp, NULL) */ /* - * Grub expects that the device path of the loaded image is - * installed on a handle. + * Make sure that device for device_path exist + * in load_image(). Otherwise, shell and grub will fail. */ ret = efi_create_handle(&mem_handle); - if (ret != EFI_SUCCESS) + if (ret != EFI_SUCCESS) { + efi_free_pool(memdp); return ret; /* TODO: leaks device_path */ + } ret = efi_add_protocol(mem_handle, &efi_guid_device_path, - device_path); + memdp); if (ret != EFI_SUCCESS) goto err_add_protocol; } else { assert(device_path && image_path); + file_path = efi_dp_append(device_path, image_path); } - ret = efi_setup_loaded_image(device_path, image_path, &image_obj, - &loaded_image_info); - if (ret) + ret = EFI_CALL(efi_load_image(false, (void *)0x1 /* FIXME */, file_path, + efi, efi_size, &handle)); + if (ret != EFI_SUCCESS) goto err_prepare; /* Transfer environment variable as load options */ - set_load_options(loaded_image_info, "bootargs"); - - /* Load the EFI payload */ - ret = efi_load_pe(image_obj, efi, loaded_image_info); + ret = EFI_CALL(systab.boottime->open_protocol( + handle, + &efi_guid_loaded_image, + (void **)&loaded_image_info, + NULL, NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)); if (ret != EFI_SUCCESS) goto err_prepare; + set_load_options(loaded_image_info, "bootargs"); if (memdp) { struct efi_device_path_memory *mdp = (void *)memdp; @@ -304,41 +312,154 @@ static efi_status_t do_bootefi_exec(void *efi, "{ro,boot}(blob)0000000000000000"); /* Call our payload! */ + image_obj = container_of(handle, struct efi_loaded_image_obj, header); debug("%s: Jumping to 0x%p\n", __func__, image_obj->entry); - ret = EFI_CALL(efi_start_image(&image_obj->header, NULL, NULL)); + ret = EFI_CALL(efi_start_image(handle, NULL, NULL)); err_prepare: - /* image has returned, loaded-image obj goes *poof*: */ efi_restore_gd(); free(loaded_image_info->load_options); - efi_delete_handle(&image_obj->header); + ret = EFI_CALL(efi_unload_image(handle)); err_add_protocol: if (mem_handle) efi_delete_handle(mem_handle); + if (device_path) + efi_free_pool(file_path); return ret; } -static int do_bootefi_bootmgr_exec(void) +/** + * do_efibootmgr() - execute EFI Boot Manager + * + * @fdt_opt: string of fdt start address + * Return: status code + * + * Execute EFI Boot Manager + */ +static int do_efibootmgr(const char *fdt_opt) +{ + void *image_buf; + efi_uintn_t buf_size; + struct efi_device_path *device_path, *image_path; + unsigned long addr; + efi_status_t r; + int ret; + + /* Allow unaligned memory access */ + allow_unaligned(); + + switch_to_non_secure_mode(); + + /* Initialize EFI drivers */ + r = efi_init_obj_list(); + if (r != EFI_SUCCESS) { + printf("Error: Cannot set up EFI drivers, r = %lu\n", + r & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_process_fdt(fdt_opt); + if (ret != EFI_SUCCESS) + return ret; + + r = efi_bootmgr_load(&device_path, &image_path, &image_buf, &buf_size); + if (r != EFI_SUCCESS) + return CMD_RET_FAILURE; + + addr = map_to_sysmem(image_buf); + + printf("## Starting EFI application at %08lx ...\n", addr); + r = do_bootefi_exec(image_buf, buf_size, device_path, image_path); + printf("## Application terminated, r = %lu\n", r & ~EFI_ERROR_MASK); + + if (r != EFI_SUCCESS) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; +} + +/* + * do_boot_efi() - execute EFI binary from command line + * + * @image_opt: string of image start address + * @fdt_opt: string of fdt start address + * Return: status code + * + * Set up memory image for the binary to be loaded, prepare + * device path and then call do_bootefi_exec() to execute it. + */ +static int do_boot_efi(const char *image_opt, const char *fdt_opt) { - struct efi_device_path *device_path, *file_path; - void *addr; + void *image_buf; + struct efi_device_path *device_path, *image_path; + const char *saddr; + unsigned long addr, size; + const char *size_str; efi_status_t r; - addr = efi_bootmgr_load(&device_path, &file_path); - if (!addr) - return 1; + /* Allow unaligned memory access */ + allow_unaligned(); - printf("## Starting EFI application at %p ...\n", addr); - r = do_bootefi_exec(addr, device_path, file_path); - printf("## Application terminated, r = %lu\n", - r & ~EFI_ERROR_MASK); + switch_to_non_secure_mode(); + /* Initialize EFI drivers */ + r = efi_init_obj_list(); + if (r != EFI_SUCCESS) { + printf("Error: Cannot set up EFI drivers, r = %lu\n", + r & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + r = efi_process_fdt(fdt_opt); if (r != EFI_SUCCESS) - return 1; + return r; - return 0; +#ifdef CONFIG_CMD_BOOTEFI_HELLO + if (!strcmp(image_opt, "hello")) { + saddr = env_get("loadaddr"); + size = __efi_helloworld_end - __efi_helloworld_begin; + + if (saddr) + addr = simple_strtoul(saddr, NULL, 16); + else + addr = CONFIG_SYS_LOAD_ADDR; + + image_buf = map_sysmem(addr, size); + memcpy(image_buf, __efi_helloworld_begin, size); + + device_path = NULL; + image_path = NULL; + } else +#endif + { + saddr = image_opt; + size_str = env_get("filesize"); + if (size_str) + size = simple_strtoul(size_str, NULL, 16); + else + size = 0; + + addr = simple_strtoul(saddr, NULL, 16); + /* Check that a numeric value was passed */ + if (!addr && *saddr != '0') + return CMD_RET_USAGE; + + image_buf = map_sysmem(addr, size); + + device_path = bootefi_device_path; + image_path = bootefi_image_path; + } + + printf("## Starting EFI application at %08lx ...\n", addr); + r = do_bootefi_exec(image_buf, size, device_path, image_path); + printf("## Application terminated, r = %lu\n", r & ~EFI_ERROR_MASK); + + if (r != EFI_SUCCESS) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; } #ifdef CONFIG_CMD_BOOTEFI_SELFTEST @@ -468,69 +589,17 @@ static int do_efi_selftest(const char *fdt_opt) /* Interpreter command to boot an arbitrary EFI image from memory */ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - unsigned long addr; - char *saddr; - efi_status_t r; - unsigned long fdt_addr; - if (argc < 2) return CMD_RET_USAGE; + + if (!strcmp(argv[1], "bootmgr")) + return do_efibootmgr(argc > 2 ? argv[2] : NULL); #ifdef CONFIG_CMD_BOOTEFI_SELFTEST else if (!strcmp(argv[1], "selftest")) return do_efi_selftest(argc > 2 ? argv[2] : NULL); #endif - /* Allow unaligned memory access */ - allow_unaligned(); - - switch_to_non_secure_mode(); - - /* Initialize EFI drivers */ - r = efi_init_obj_list(); - if (r != EFI_SUCCESS) { - printf("Error: Cannot set up EFI drivers, r = %lu\n", - r & ~EFI_ERROR_MASK); - return CMD_RET_FAILURE; - } - - ret = fdt_process_fdt(argc > 2 ? argv[2] : NULL); - if (ret != EFI_SUCCESS) - return ret; - -#ifdef CONFIG_CMD_BOOTEFI_HELLO - if (!strcmp(argv[1], "hello")) { - ulong size = __efi_helloworld_end - __efi_helloworld_begin; - - saddr = env_get("loadaddr"); - if (saddr) - addr = simple_strtoul(saddr, NULL, 16); - else - addr = CONFIG_SYS_LOAD_ADDR; - memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size); - } else -#endif - if (!strcmp(argv[1], "bootmgr")) { - return do_bootefi_bootmgr_exec(); - } else { - saddr = argv[1]; - - addr = simple_strtoul(saddr, NULL, 16); - /* Check that a numeric value was passed */ - if (!addr && *saddr != '0') - return CMD_RET_USAGE; - - } - - printf("## Starting EFI application at %08lx ...\n", addr); - r = do_bootefi_exec(map_sysmem(addr, 0), bootefi_device_path, - bootefi_image_path); - printf("## Application terminated, r = %lu\n", - r & ~EFI_ERROR_MASK); - - if (r != EFI_SUCCESS) - return 1; - else - return 0; + return do_boot_efi(argv[1], argc > 2 ? argv[2] : NULL); } #ifdef CONFIG_SYS_LONGHELP @@ -549,7 +618,7 @@ static char bootefi_help_text[] = " Use environment variable efi_selftest to select a single test.\n" " Use 'setenv efi_selftest list' to enumerate all tests.\n" #endif - "bootefi bootmgr [fdt addr]\n" + "bootefi bootmgr [fdt address]\n" " - load and boot EFI payload based on BootOrder/BootXXXX variables.\n" "\n" " If specified, the device tree located at gets\n" @@ -574,6 +643,13 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path) ret = efi_dp_from_name(dev, devnr, path, &device, &image); if (ret == EFI_SUCCESS) { bootefi_device_path = device; + if (image) { + /* FIXME: image should not contain device */ + struct efi_device_path *image_tmp = image; + + efi_dp_split_file_path(image, &device, &image); + efi_free_pool(image_tmp); + } bootefi_image_path = image; } else { bootefi_device_path = NULL; diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index c6991d353497..0011a226a3be 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1703,11 +1703,6 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy, &source_size); if (ret != EFI_SUCCESS) goto error; - /* - * split file_path which contains both the device and - * file parts: - */ - efi_dp_split_file_path(file_path, &dp, &fp); } else { /* In this case, file_path is the "device" path, i.e. * something like a HARDWARE_DEVICE:MEMORY_MAPPED @@ -1723,10 +1718,13 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy, dest_buffer = (void *)(uintptr_t)addr; memcpy(dest_buffer, source_buffer, source_size); source_buffer = dest_buffer; - - dp = file_path; - fp = NULL; } + /* + * split file_path which contains both the device and + * file parts: + */ + efi_dp_split_file_path(file_path, &dp, &fp); + ret = efi_setup_loaded_image(dp, fp, image_obj, &info); if (ret != EFI_SUCCESS) goto error_invalid_image; From patchwork Tue Mar 5 05:53:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1051628 X-Patchwork-Delegate: xypron.glpk@gmx.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; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="wVUWQ8x8"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44D5jB4qDtz9s1B for ; Tue, 5 Mar 2019 16:55:42 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 62AF6C21DE8; Tue, 5 Mar 2019 05:53:50 +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_DNSWL_NONE, 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 350BDC21DAF; Tue, 5 Mar 2019 05:52:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A0E51C21DAF; Tue, 5 Mar 2019 05:52:11 +0000 (UTC) Received: from mail-yw1-f66.google.com (mail-yw1-f66.google.com [209.85.161.66]) by lists.denx.de (Postfix) with ESMTPS id EAE19C21DDC for ; Tue, 5 Mar 2019 05:52:07 +0000 (UTC) Received: by mail-yw1-f66.google.com with SMTP id z191so6070256ywa.6 for ; Mon, 04 Mar 2019 21:52:07 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=11uxoS1SYssL5t6pJBHd4NPmAUfNd7ZZuqRL28HiTMo=; b=wVUWQ8x8WASkGGhGDxEbUoCUi5t96wiQKi2DwIFGVkr+z7Evnk/yrEdgvL4i+kZ2aQ bGEWgx6xLwwtk4ymEhy4aQK/jeasj0BlnaEDl7huw5qkFI3Gef2If80PPsqK/L2syLKN 8wD2SVguIQbXohGY6AEqPHFyM73H43xNRzEfuZ+UlNh/6cJ9RViZDemdsMsu+vfIJX0s bfV1LKWvAl5ezYWjJhkaEjuUB2m9Qf3DT9ayBWlXiXahJtSUyu4d3r9lGI31SBwO6uZ1 GdDlik48RphsKztEf8zsSq0s9xnrXsNtrI0UzILFWaGXwib/LmH95U761ukM9r3rPq9v jVRw== 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:mime-version:content-transfer-encoding; bh=11uxoS1SYssL5t6pJBHd4NPmAUfNd7ZZuqRL28HiTMo=; b=XdzxjsKfDU1EmK6zALVHcFWEK12ocFR0yST24SebwuPNI9gHrpLxRBle3wWby4za4X fVW/DPyPSd/aZPlbCFn4tDsfj16XCtgwCEKtQqvxXVktD4RomqwcgFmympveDCBfLgMW w8ZC+EHZvO14ct2+ZuIhJYkcxtQ7GCTjLPHZq4yzcUK5EmyRXl78TO6zBpr/A29JqGRa UcTOT9S/qVyhbbuUb9WrKxI5xKEyXjKP5jd7IaytLBzjOWmyrv9VDA4Nu90lb/ZEXQU1 lvdvSsglEwkvAnXqZyqhxDeNUK/4/Ph3olgpBpISici7hOJMR9zpJJ+CmZ6y2cFPU9KZ ku0Q== X-Gm-Message-State: APjAAAVbmmCF61+O6YpfBwehFJBL165iQGqlYTHSOeLfHgWlCelWEdoc fbrTD/DA50J5o4SFKF1lxpPX6w== X-Google-Smtp-Source: APXvYqwhP6J0IFCvexOpV3XMJzDknOy9I7OMzH7EysKyKbD/OFmCzDxa500I609XQMAL3XcKhlp78A== X-Received: by 2002:a0d:c544:: with SMTP id h65mr17153813ywd.35.1551765125519; Mon, 04 Mar 2019 21:52:05 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j132sm3122756ywa.35.2019.03.04.21.52.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2019 21:52:05 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@suse.de Date: Tue, 5 Mar 2019 14:53:37 +0900 Message-Id: <20190305055337.3793-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305055337.3793-1-takahiro.akashi@linaro.org> References: <20190305055337.3793-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC 8/8] cmd: add efibootmgr command 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add CONFIG_CMD_STANDALONE_EFIBOOTMGR. Signed-off-by: AKASHI Takahiro --- cmd/Kconfig | 8 ++++++++ cmd/bootefi.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index 4bcc5c45579d..aa27b21956b3 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -224,6 +224,14 @@ config CMD_BOOTEFI help Boot an EFI image from memory. +config CMD_STANDALONE_EFIBOOTMGR + bool "Enable EFI Boot Manager as a standalone command" + depends on CMD_BOOTEFI + default n + help + With this option enabled, EFI Boot Manager can be invoked + as a standalone command. + config CMD_BOOTEFI_HELLO_COMPILE bool "Compile a standard EFI hello world binary for testing" depends on CMD_BOOTEFI && !CPU_V7M && !SANDBOX diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 00cacbdd4231..6becd37e17a4 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -656,3 +656,38 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path) bootefi_image_path = NULL; } } + +#ifdef CONFIG_CMD_STANDALONE_EFIBOOTMGR +static int do_efibootmgr_cmd(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + char *fdt_opt; + int ret; + + if (argc != 1) + return CMD_RET_USAGE; + + fdt_opt = env_get("fdtaddr"); + if (!fdt_opt) + fdt_opt = env_get("fdtcontroladdr"); + + ret = do_efibootmgr(fdt_opt); + + free(fdt_opt); + + return ret; +} + +#ifdef CONFIG_SYS_LONGHELP +static char efibootmgr_help_text[] = + "(no arguments)\n" + " - Launch EFI boot manager and execute EFI application\n" + " based on BootNext and BootOrder variables\n"; +#endif + +U_BOOT_CMD( + efibootmgr, 1, 0, do_efibootmgr_cmd, + "Launch EFI boot manager", + efibootmgr_help_text +); +#endif /* CONFIG_CMD_STANDALONE_EFIBOOTMGR */