From patchwork Wed Mar 27 04:40: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: 1066451 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="zwKThRi7"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44TZzJ4XW0z9sNk for ; Wed, 27 Mar 2019 15:39:40 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 5511EC21E3B; Wed, 27 Mar 2019 04:39:37 +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=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 5300FC21E68; Wed, 27 Mar 2019 04:39:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2EE5BC21DE8; Wed, 27 Mar 2019 04:39:24 +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 813AEC21E3E for ; Wed, 27 Mar 2019 04:39:20 +0000 (UTC) Received: by mail-yw1-f66.google.com with SMTP id m207so2468731ywd.5 for ; Tue, 26 Mar 2019 21:39:20 -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 :mime-version:content-transfer-encoding; bh=9hSuHe5Q0lKolgD7eviV68VbqRawBApBdhWAATQDdIM=; b=zwKThRi7w+2DWEt478Bg2+aSVAKRYNM3OoRw/ViH7YlIrSFOIzLD722wfnxXyrewWC XIsXtOchPfuvQD1tyKJpciBAjBa1YCRGlr6i6ia+L0+wdPB26EFopRfHYxlGTGy7bF0a 4XCB7TJsKIDBTcFpmQ2N34HYdsDfFd+UTzyUs5dH7wMrfq6UmefWzAwbvsjWVVyle5Aa DvBPE3l0EIEKRqMsGGbmITNaQnsK1umd/PW19bfmYy3plMP5lom8tA5VLTcRvEz5XXXj k4aOhX2vxahQG423U7uf6pRSH9MzxZ+Ml5LnuNBsxYeLqY4WsnEqj/gRxj/h5y5ro8oQ CR/g== 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=9hSuHe5Q0lKolgD7eviV68VbqRawBApBdhWAATQDdIM=; b=nZDxjBpXvP+yGZVpqjogY6y8h+DbLTlCAbMBMYi05Q6Zk+T3feS7wMmlxROWM1Svra 4ruxUhy9sHKKLzdiO8F1ScisWxOCMYHfrX3gjzss1xmdeT2NXfl1P3Wb/CSSLGk/HaB0 0AI/dUM6g0HpEKolqOkEnD5GwWGtAlAkYExojzCJOVg6VMw3ePm8aPkpwwgcZw5Qp8ih +ustKm0vWJq1M7Ky1onV+P2NZerrUKMP0X8l1VAn/Ui6p4MeinrM6PRC59KsSXlDX4I6 /mGH/hy5gw/75FlcKCsbIehkwi5geI9xuiCHi92B1Vdf23mEiSC49ruGXv2B4k+qtG+2 KgGQ== X-Gm-Message-State: APjAAAUJagw/zPsnmfQgnt+pyViJBfrPWjqbhHwjRX/ora2S1khEDCP2 pGGadERHng0gtyyZ27N7q86hXw== X-Google-Smtp-Source: APXvYqx6mtM/ZaRWq11wsYMS2H/4StaBRC0h+B0mqYr8roSgzYZhBpr5NeJ1ntgpRHvq+7IXeqW7eA== X-Received: by 2002:a81:33ce:: with SMTP id z197mr28936400ywz.172.1553661559486; Tue, 26 Mar 2019 21:39:19 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 205sm7795719ywd.15.2019.03.26.21.39.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:39:19 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 27 Mar 2019 13:40:32 +0900 Message-Id: <20190327044042.13707-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327044042.13707-1-takahiro.akashi@linaro.org> References: <20190327044042.13707-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC v2 01/11] efi_loader: boottime: add loaded image 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" To meet UEFI spec v2.7a section 9.2, we should add EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL to image handle, instead of EFI_DEVICE_PATH_PROTOCOL. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt Reviewed-by: Heinrich Schuchardt --- include/efi_api.h | 4 ++++ include/efi_loader.h | 1 + lib/efi_loader/efi_boottime.c | 19 ++++++++++++------- lib/efi_loader/efi_image_loader.c | 2 ++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index ccf608653d4a..63b703c951a7 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -333,6 +333,10 @@ struct efi_system_table { EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, \ 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) +#define LOADED_IMAGE_DEVICE_PATH_GUID \ + EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, \ + 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf) + #define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000 struct efi_loaded_image { diff --git a/include/efi_loader.h b/include/efi_loader.h index 512880ab8fbf..3f54e354bdcd 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -135,6 +135,7 @@ extern const efi_guid_t efi_guid_event_group_reset_system; /* GUID of the device tree table */ extern const efi_guid_t efi_guid_fdt; extern const efi_guid_t efi_guid_loaded_image; +extern const efi_guid_t efi_guid_loaded_image_device_path; extern const efi_guid_t efi_guid_device_path_to_text_protocol; extern const efi_guid_t efi_simple_file_system_protocol_guid; extern const efi_guid_t efi_file_info_guid; diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 391681260c27..578b32a05ffd 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1519,6 +1519,7 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path, efi_status_t ret; struct efi_loaded_image *info = NULL; struct efi_loaded_image_obj *obj = NULL; + struct efi_device_path *dp; /* In case of EFI_OUT_OF_RESOURCES avoid illegal free by caller. */ *handle_ptr = NULL; @@ -1542,15 +1543,19 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *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) + + dp = efi_dp_append(device_path, file_path); + if (!dp) { + ret = EFI_OUT_OF_RESOURCES; goto failure; + } + } else { + dp = NULL; } + ret = efi_add_protocol(&obj->header, + &efi_guid_loaded_image_device_path, dp); + if (ret != EFI_SUCCESS) + goto failure; /* * When asking for the loaded_image interface, just diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index fe66e7b9ffe1..c6177b9ff832 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -14,6 +14,8 @@ const efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID; const efi_guid_t efi_guid_device_path = DEVICE_PATH_GUID; const efi_guid_t efi_guid_loaded_image = LOADED_IMAGE_GUID; +const efi_guid_t efi_guid_loaded_image_device_path + = LOADED_IMAGE_DEVICE_PATH_GUID; const efi_guid_t efi_simple_file_system_protocol_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID; const efi_guid_t efi_file_info_guid = EFI_FILE_INFO_GUID; From patchwork Wed Mar 27 04:40: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: 1066453 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="PX20gHqB"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Tb1D2Sqlz9sNk for ; Wed, 27 Mar 2019 15:41:20 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id C6E83C21DFB; Wed, 27 Mar 2019 04:40:07 +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=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 54C83C21E50; Wed, 27 Mar 2019 04:39:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9F875C21E34; Wed, 27 Mar 2019 04:39:26 +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 ABC68C21E50 for ; Wed, 27 Mar 2019 04:39:22 +0000 (UTC) Received: by mail-yw1-f66.google.com with SMTP id j128so11543264ywg.12 for ; Tue, 26 Mar 2019 21:39:22 -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 :mime-version:content-transfer-encoding; bh=UadYXf+fYjPAyxYVrydlV6RLBFyXvBE+TbGog072Yb0=; b=PX20gHqBQWwZxpM98GyHmhHA/pWP4+83DFn18fsRpoTvYFVlpyXF3upN3Bg0BfKy+H g0/F5/7M6/7yKaMJR2qTO8MKmbqCTdKBEpfelBPvRUUvqEiNZc9D+3UP7g88eIujFYAG 8SyMVNLzx1zSF4yjh4eP3zdxUcUl5pcr2O2SDydnjvKs19AyeBqJF5uDA6bqhRyeqQRW OjG5k/i1vTNsi7PcYpLgDWOC2JQLHtcaXw702l6colbllLTAZAQw4c6ezLxN3cXMSFPy eQCIKzm+330BGoc9vymguaguupPZtU8d6Vf5abJJqv8Vhxpro6CIknpAbRyOerzGVlRp ux1w== 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=UadYXf+fYjPAyxYVrydlV6RLBFyXvBE+TbGog072Yb0=; b=jHNd9FdAQJtx/4lr6iK+/p5S6SoOKM7BsBe5yLHdiTuAHiIi/de9h0uc/UK63s2exc idCPkgsRDyHC/Mnhaono3HWP29i/poC8VAFaLchCi8kMil6y/N2yckfITMh5CW37JqdC AsB+Q/Bx57mHYrFbTqRS1CpBqohnpxLVBV7HVSXCPZaOOtNHjlezQkxG3OAcpT1eXcBH Kk8yn1CgY+PM/QE+Gg7m40xnFDA9dRETHul17CXieOEoOm3eVxmiGfyVcxGXQg5V0yU+ 3+IwJ3FZrKXTliAqG+PxZtYkfP+nVaDXvzNVA9RmoYw/e48fUdaxaQ3C6hfRmmKBFWOv AtwA== X-Gm-Message-State: APjAAAU8A3IOW0yFHM/skvoaIFAQVUfytH8pcB4kc2cbaqox7hO37opq F6LKJmvsp3wwQ3N+0u1RrKR24A== X-Google-Smtp-Source: APXvYqzVil6ylxlPFIVwgwJhJ6gvB64t9JIWMEiZ1v0kOmFJuxCXTndwgqUQSjClKyE6lcJIGrC2jg== X-Received: by 2002:a25:c382:: with SMTP id t124mr28491428ybf.157.1553661561691; Tue, 26 Mar 2019 21:39:21 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a4sm880535ywa.7.2019.03.26.21.39.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:39:21 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 27 Mar 2019 13:40:33 +0900 Message-Id: <20190327044042.13707-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327044042.13707-1-takahiro.akashi@linaro.org> References: <20190327044042.13707-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC v2 02/11] 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" This is a preparatory patch. Those two functions will be used later for reworking do_bootefi(). 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 3f54e354bdcd..6dfa2fef3cf0 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -321,10 +321,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 578b32a05ffd..74da6b01054a 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1686,12 +1686,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 Wed Mar 27 04:40: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: 1066452 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="IksIaTip"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Tb153vHXz9sPR for ; Wed, 27 Mar 2019 15:41:13 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 1F831C21E3E; Wed, 27 Mar 2019 04:39:51 +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=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 C9C84C21E62; Wed, 27 Mar 2019 04:39:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AEFC5C21E5B; Wed, 27 Mar 2019 04:39:26 +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 C6CB1C21E35 for ; Wed, 27 Mar 2019 04:39:24 +0000 (UTC) Received: by mail-yw1-f66.google.com with SMTP id w66so11583749ywd.4 for ; Tue, 26 Mar 2019 21:39:24 -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 :mime-version:content-transfer-encoding; bh=wto0VLwbm2BnvYT7sDe71i/FYULGakGD+10bQqBLM4c=; b=IksIaTipiWK5zzYdVbGGWQWEw9i+xg3bEWM6Q8aJnNbkQsQzjQKl6gfh0FdI4FKEqt LaPc5cxcFQfGyw/8djjh8BWiZ7qqFSnWfW7Phf2BsQZaV79JrTPQjooYtlQk5zXuAJw8 uduOAqKafLtVzi9r4Qf1Kg+oK+zW5UEvNbHCusxpjwN9Bl8hsQJSRnkkSTWCX/8D24q3 B2RzK+vL3rL5XR/2C5mTgdgpy8Z/dzUrPDV1yH5OgpT4bITME1kfj1WI9bu9c5wuRRT2 L1pIXrYjiekbGIVlR4Np/eIuFo9HUneXBND7gitHKUbO5VfFqcMV45vIJ/Qw/mE+0Br/ 8MKQ== 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=wto0VLwbm2BnvYT7sDe71i/FYULGakGD+10bQqBLM4c=; b=hJtPfw+2j3kegF2iBdMmBmqE0HkTzQN7Y01/cEtNCDDlLV0siTg0YRg35mB/CoVUFC N7N9CqxpeBr1iERPwEwEQGwkHrTCfxEeYYpSDDPfUkurUAYyzdA31ccHvSVWDUOkW8Wd mjtQSeU9W1vtBEs+d8+MuzaR4tBl8KLB6w9SOVJo06q905u868YkZPNEH2p7ibZ32VG1 nYlAGrH97XRPSDxikZJ9hGzelsI4MuTtVMsS5PkmUKzdCW68jeB610D4X0bSiyZbNmrh jeF1qbqn6sIJaMAl59354jnIKpPZeludadh2aMPd3DaKnvflztgu5Hh399roKTaDJGNq sOHg== X-Gm-Message-State: APjAAAV8wkeoJ72JZuz0a5AEHGOipNDpPXEkow4z0xn4K1+khO6qkXwu 6ZHXX6Q/dT5fcZW8fVRxFSVRoQ== X-Google-Smtp-Source: APXvYqyyBDkbRofOkH3LKOt0pkH5phP3C0QmwjH6hhCge8jYBJInEBz1ubgK3ioemaGnqaVhWDBd1Q== X-Received: by 2002:a25:1488:: with SMTP id 130mr5226966ybu.468.1553661563810; Tue, 26 Mar 2019 21:39:23 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g1sm7152170ywf.0.2019.03.26.21.39.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:39:23 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 27 Mar 2019 13:40:34 +0900 Message-Id: <20190327044042.13707-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327044042.13707-1-takahiro.akashi@linaro.org> References: <20190327044042.13707-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC v2 03/11] efi_loader: device_path: handle special case of 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" This is a preparatory patch. efi_dp_split_file_path() is used to create device_path and file_path from file_path for efi_setup_loaded_image(). In a special case, however, of HARDWARE_DEVICE/MEMORY, it doesn't work expectedly since this path doesn't contain any FILE_PATH sub-type. This patch makes a workaround. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_device_path.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 53b40c8c3c2d..e283fad767ed 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -933,6 +933,14 @@ efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path, dp = efi_dp_dup(full_path); if (!dp) return EFI_OUT_OF_RESOURCES; + + if (EFI_DP_TYPE(dp, HARDWARE_DEVICE, MEMORY)) { + /* no FILE_PATH */ + *device_path = dp; + + return EFI_SUCCESS; + } + p = dp; while (!EFI_DP_TYPE(p, MEDIA_DEVICE, FILE_PATH)) { p = efi_dp_next(p); From patchwork Wed Mar 27 04:40: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: 1066454 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="rTi+egoS"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Tb1f43s3z9sNk for ; Wed, 27 Mar 2019 15:41:42 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 00B2CC21E02; Wed, 27 Mar 2019 04:40: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=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 4687EC21E60; Wed, 27 Mar 2019 04:39:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9E477C21DFA; Wed, 27 Mar 2019 04:39:27 +0000 (UTC) Received: from mail-yw1-f42.google.com (mail-yw1-f42.google.com [209.85.161.42]) by lists.denx.de (Postfix) with ESMTPS id 1C113C21E39 for ; Wed, 27 Mar 2019 04:39:27 +0000 (UTC) Received: by mail-yw1-f42.google.com with SMTP id m207so2468846ywd.5 for ; Tue, 26 Mar 2019 21:39:27 -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 :mime-version:content-transfer-encoding; bh=CPR61fg5a/XqzH/GiwTZaPLWezVncFwakP0WbRvq3ko=; b=rTi+egoSGDbl9F8BNRJxCZGWMX+IEbIMXl8HbSP2Y1tBObOE5J63tFrQrPNvqqHtvL ZfVpyddAzutF6WTxOb9O9M6+lcHQ/AAmk4gdooP+4xPLHuv9ArKq9fjIQPP+rrqpsCoj Kw1uPoAT9jaUf66FD+hVlc9LJ0JwD/7saZ/er0dFBOvyBIN7nEmiC+1jQQUEYTxhAoYJ a/aMIHqMBaO41NGWOv8b85IsEEC87K8g8ag5l5qY4gplyAXwZWVzOOsP8OLOPGfPKp/m tB35oCzaslraN1gnc0oR554v+VBTg/8f6Vj0l6B11ii2EZE77JVlglNOvY/8MlirWGqF 9IZQ== 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=CPR61fg5a/XqzH/GiwTZaPLWezVncFwakP0WbRvq3ko=; b=dpvJ8z63ocu0O7+MwflB02yCQsjM338aCLYO2GgibX3Hy/aKrX2dVMFU5uXdZUQyYm 6Nt5vnXE/JmfB7fFHxDFcDlCZR7+Br0ToZYM1yth+8NJygHMGUCIp0V5U3xuvlWoYOZ9 yHRXRDWKbzo/eyZSNSJQilX8bTM4nm3nChBPTocHDwpWTp8XCB3HsRezRZI76JZJwJTD A9oOj9BrvZiztM6VoIdkpwTobji0wJltHA998jp2t6+lrElLlHym0G1mmFbg5Xhmk4BJ i4lrTY2mKWicCEa0dtVVCX3mEGe8P0rNH44uDhrsZ44Xc+IPkbDWFKs/g3vmYNSKbzIL FmdQ== X-Gm-Message-State: APjAAAXggnLFvk2CS1f1Tlh5kwfStGD5ctukyD+vwwDuBEtD0UCrHeVJ EDZp/OsgytlaTRMVzzxEW67asA== X-Google-Smtp-Source: APXvYqyaxKnCiOqUuqnUL7DhO2VDJwIcuV/PqdYqmUB4Yx8Kvli0Qnnp8meUxrOFE5xczOgyIyyd4Q== X-Received: by 2002:a81:2997:: with SMTP id p145mr27998687ywp.112.1553661566064; Tue, 26 Mar 2019 21:39:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 12sm86504yww.88.2019.03.26.21.39.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:39:25 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 27 Mar 2019 13:40:35 +0900 Message-Id: <20190327044042.13707-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327044042.13707-1-takahiro.akashi@linaro.org> References: <20190327044042.13707-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC v2 04/11] cmd: bootefi: carve out fdt handling 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 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 3619a20e6433..aba8b203d419 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 efi_status_t efi_process_fdt(const char *fdt_opt) +{ + unsigned long fdt_addr; + efi_status_t ret; + + if (fdt_opt) { + fdt_addr = simple_strtoul(fdt_opt, NULL, 16); + if (!fdt_addr && *fdt_opt != '0') + return EFI_INVALID_PARAMETER; + + /* Install device tree */ + ret = efi_install_fdt(fdt_addr); + if (ret != EFI_SUCCESS) { + printf("ERROR: failed to install device tree\n"); + return ret; + } + } 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 EFI_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"); - } + r = fdt_process_fdt(argc > 2 ? argv[2] : NULL); + if (r != EFI_SUCCESS) + return r; + #ifdef CONFIG_CMD_BOOTEFI_HELLO if (!strcmp(argv[1], "hello")) { ulong size = __efi_helloworld_end - __efi_helloworld_begin; From patchwork Wed Mar 27 04:40: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: 1066455 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="YNLrQst2"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Tb1n4v9Sz9sNk for ; Wed, 27 Mar 2019 15:41:49 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 3EBADC21E0D; Wed, 27 Mar 2019 04:40:48 +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=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 CE227C21E56; Wed, 27 Mar 2019 04:39:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2DC10C21E44; Wed, 27 Mar 2019 04:39:29 +0000 (UTC) Received: from mail-yw1-f53.google.com (mail-yw1-f53.google.com [209.85.161.53]) by lists.denx.de (Postfix) with ESMTPS id 3EC23C21E36 for ; Wed, 27 Mar 2019 04:39:29 +0000 (UTC) Received: by mail-yw1-f53.google.com with SMTP id j66so11551254ywc.10 for ; Tue, 26 Mar 2019 21:39:29 -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 :mime-version:content-transfer-encoding; bh=odtR592PRCyvVU0BnbLiXb6ERsjOauChB1u7LJvxHhg=; b=YNLrQst2RKGBiqyEJLkZCmV553p0qH5VLGLCyQuTN/pucQT/k88C1YoxkjWOm7+O5C JPtZ15aucInFe8db84n44BgmW3jYrXaLzXJ+AhQoeiBio0tF2aYsVNkhJw22y9ub0ltF e0KKQmiKBKOccSOT2c1nHpZgzOsensmQwvbbvqXUMtMjTHQNZ4Mmvap5El5YRti3Lh8c IIXaBXN/Y2lSybkDbwlF2eBFl/kmi9xWtg0xrIEOQySoxL4omC+RecqqAjfInQOWTfGU J4y10wI0PoFCL25hOjDgPYkbcw3KLSUuWD4HXj0u943zMtDv99pCk7ACNCY2JrhpZUra wBmA== 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=odtR592PRCyvVU0BnbLiXb6ERsjOauChB1u7LJvxHhg=; b=ViTIL7K5uNuQtlnRr8dVl0jsFfjfe14wNqFh6Hjqposr302TYe5fL7SVN/6sy25eaO CGvT3kTTYJaFafVJDxrucS8+yFVFxBCqhvZxW6dU8FKAlZ7oewF0iXbbeq6oxyPW9zqz N67PrlemIsOS5KhSk30tQW3uiNe8ZgRYiLadLPb3mKTvADvbUNDCz02B/WgH8yuoJWLm mzi+ENbTVCjlAT+dfWj8YRiRv4b5jm6dq233Yqa22mMV654v9lcm+eZXGYBuKQV0EdFH c9xGAPtzWchDwCLtus7Yz2HJchK5QBwfhqcgamz+ipCcQwat1Ewi8f1ZECylmiAFrfbZ GkZw== X-Gm-Message-State: APjAAAXfvbRpYYrgWcARq85H8y0m66y7xhX58PP0BQVpROJoZPUax5qA hMsQgbHmLyU2XgNB/m3Oeb3+uA== X-Google-Smtp-Source: APXvYqxzcU+JPuv6blbEnOwsJ//J3BXCaROo+y4FC9dW48WrWJZ894Wj2XH5taEpuJWywfDucTqTVw== X-Received: by 2002:a25:16d7:: with SMTP id 206mr28916926ybw.335.1553661568189; Tue, 26 Mar 2019 21:39:28 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g1sm7152225ywf.0.2019.03.26.21.39.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:39:27 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 27 Mar 2019 13:40:36 +0900 Message-Id: <20190327044042.13707-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327044042.13707-1-takahiro.akashi@linaro.org> References: <20190327044042.13707-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC v2 05/11] cmd: bootefi: merge efi_install_fdt() and efi_process_fdt() 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. For simplicity, merge two functions. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 67 +++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index aba8b203d419..ce0db07f8633 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -165,41 +165,8 @@ static void efi_carve_out_dt_rsv(void *fdt) } } -static efi_status_t efi_install_fdt(ulong fdt_addr) -{ - bootm_headers_t img = { 0 }; - efi_status_t ret; - void *fdt; - - fdt = map_sysmem(fdt_addr, 0); - if (fdt_check_header(fdt)) { - printf("ERROR: invalid device tree\n"); - return EFI_INVALID_PARAMETER; - } - - /* Create memory reservation as indicated by the device tree */ - efi_carve_out_dt_rsv(fdt); - - /* Prepare fdt for payload */ - ret = copy_fdt(&fdt); - if (ret) - return ret; - - if (image_setup_libfdt(&img, fdt, 0, NULL)) { - printf("ERROR: failed to process device tree\n"); - return EFI_LOAD_ERROR; - } - - /* Link to it in the efi tables */ - ret = efi_install_configuration_table(&efi_guid_fdt, fdt); - if (ret != EFI_SUCCESS) - return EFI_OUT_OF_RESOURCES; - - return ret; -} - /** - * efi_process_fdt() - process fdt passed by a command argument + * efi_install_fdt() - install 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 @@ -207,21 +174,43 @@ static efi_status_t efi_install_fdt(ulong fdt_addr) * If specified, fdt will be installed as configuration table, * otherwise no fdt will be passed. */ -static efi_status_t efi_process_fdt(const char *fdt_opt) +static efi_status_t efi_install_fdt(const char *fdt_opt) { unsigned long fdt_addr; + void *fdt; + bootm_headers_t img = { 0 }; efi_status_t ret; if (fdt_opt) { + /* Install device tree */ fdt_addr = simple_strtoul(fdt_opt, NULL, 16); if (!fdt_addr && *fdt_opt != '0') return EFI_INVALID_PARAMETER; - /* Install device tree */ - ret = efi_install_fdt(fdt_addr); + fdt = map_sysmem(fdt_addr, 0); + if (fdt_check_header(fdt)) { + printf("ERROR: invalid device tree\n"); + return EFI_INVALID_PARAMETER; + } + + /* Create memory reservation as indicated by the device tree */ + efi_carve_out_dt_rsv(fdt); + + /* Prepare fdt for payload */ + ret = copy_fdt(&fdt); + if (ret) + return ret; + + if (image_setup_libfdt(&img, fdt, 0, NULL)) { + printf("ERROR: failed to process device tree\n"); + return EFI_LOAD_ERROR; + } + + /* Link to it in the efi tables */ + ret = efi_install_configuration_table(&efi_guid_fdt, fdt); if (ret != EFI_SUCCESS) { printf("ERROR: failed to install device tree\n"); - return ret; + return EFI_OUT_OF_RESOURCES; } } else { /* Remove device tree. EFI_NOT_FOUND can be ignored here */ @@ -441,7 +430,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc < 2) return CMD_RET_USAGE; - r = fdt_process_fdt(argc > 2 ? argv[2] : NULL); + r = fdt_install_fdt(argc > 2 ? argv[2] : NULL); if (r != EFI_SUCCESS) return r; From patchwork Wed Mar 27 04:40: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: 1066459 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="vYSP8P5f"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Tb4c5p2gz9sNk for ; Wed, 27 Mar 2019 15:44:16 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 4BCB2C21E75; Wed, 27 Mar 2019 04:40:20 +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 CCAA8C21E18; Wed, 27 Mar 2019 04:39:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B30F3C21E52; Wed, 27 Mar 2019 04:39:32 +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 8DD3EC21E88 for ; Wed, 27 Mar 2019 04:39:31 +0000 (UTC) Received: by mail-yw1-f67.google.com with SMTP id m207so2468911ywd.5 for ; Tue, 26 Mar 2019 21:39:31 -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 :mime-version:content-transfer-encoding; bh=sZWsochRLHuLn0zZ10/0rSELkaEFApFfrW4ttZTOhZE=; b=vYSP8P5fPtfnzgAFl5YX5lsJrZyauW5TLTGiWAoym63jBs0hgzej8zs4NY5cPZ/ikH 5IPa1nGudVrJzQDgXmnr/OVIwgMqkRpK6JkcylhXBkDWtyjZKMhuoRAF/9VwR3xXShB7 p10s4c1zEafVS6XiFUQ2R95TBUoiqXvvspLqmfwE+ep497xuRFtLZ+G5m0P1gh5rrlzQ 7X0dQDWQYJ3JK1/RoydKOC2LhXK6OAnN/vPs0Q/QkiKrRgqO7KZVbyG0XO9llxxVPMX8 u3PYi6czd0RZL16zTlUC+dzKEaB75d5v2t9HwUD5CYqVI1qQcg/uO4g64LNVHNOiHDeO tXgA== 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=sZWsochRLHuLn0zZ10/0rSELkaEFApFfrW4ttZTOhZE=; b=GmqpFtyADaqukdORTeSPbVaMnAyTbouV0kgH0PU2Yj9REfCOjd9ua2yPh1CngbSzMw H3ELZnFwj1fwV8ufOuPNKgnq+ozui7515F1TGmdVhppoD3ctuWP0ZylBtr0eCcxzWWib RggllxvCUohOpkzWvBjDiCPEAlyaqin3TAdhiNmWst0PtCzjr+R5v+J8skrRyCJgNKuo kkJmMvltarRjQepjhaih+Uhexz+u0gGA+x/uLeIRLv0YCb1QjZOCc/k0ingTiqdvjjSZ yqZNmRY6edBbuhYipDJEQul9hMvBENHONZSFkyMeztRHJjcmidktgWNb55evW3TkBRuf 6MPg== X-Gm-Message-State: APjAAAUjVeGLt8FSa4g/BIi8SsgTPLwL67ayufN1vxYNOoRP3Lzv2Tgw dtyVvPyatpTLtCX2kPT0JL4Zsg== X-Google-Smtp-Source: APXvYqwC9PMiSZyE3TUrg6fnNwZFq/MEznwVphcm3toGfQhiFPCIsTkRgwWPRHOqoA7BxvT2kHD6Tw== X-Received: by 2002:a5b:60f:: with SMTP id d15mr28520081ybq.183.1553661570502; Tue, 26 Mar 2019 21:39:30 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 206sm6980432yws.95.2019.03.26.21.39.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:39:30 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 27 Mar 2019 13:40:37 +0900 Message-Id: <20190327044042.13707-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327044042.13707-1-takahiro.akashi@linaro.org> References: <20190327044042.13707-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC v2 06/11] 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 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 | 145 +++++++++++++++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 55 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index ce0db07f8633..1267d895472c 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -221,39 +221,6 @@ static efi_status_t efi_install_fdt(const char *fdt_opt) return EFI_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 * @@ -300,11 +267,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) @@ -328,7 +298,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) @@ -338,6 +310,25 @@ err_add_protocol: } #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 * @@ -383,6 +374,62 @@ 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 ret; + + /* Allow unaligned memory access */ + allow_unaligned(); + + switch_to_non_secure_mode(); + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + printf("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_install_fdt(fdt_opt); + if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + + ret = bootefi_test_prepare(&image_obj, &loaded_image_info, + "\\selftest", "efi_selftest"); + if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + + /* Execute the test */ + ret = EFI_CALL(efi_selftest(&image_obj->header, &systab)); + bootefi_run_finish(image_obj, loaded_image_info); + + return ret != EFI_SUCCESS; +} #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ static int do_bootefi_bootmgr_exec(void) @@ -414,6 +461,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(); @@ -427,9 +481,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; - r = fdt_install_fdt(argc > 2 ? argv[2] : NULL); if (r != EFI_SUCCESS) return r; @@ -445,22 +496,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 Wed Mar 27 04:40:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1066458 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="SMj09bRR"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Tb3w0XT5z9sNk for ; Wed, 27 Mar 2019 15:43:39 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 9FD62C21E38; Wed, 27 Mar 2019 04:41:02 +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=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 6AD1DC21E1E; Wed, 27 Mar 2019 04:39:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EF084C21E6A; Wed, 27 Mar 2019 04:39:34 +0000 (UTC) Received: from mail-yw1-f46.google.com (mail-yw1-f46.google.com [209.85.161.46]) by lists.denx.de (Postfix) with ESMTPS id ABB54C21E56 for ; Wed, 27 Mar 2019 04:39:33 +0000 (UTC) Received: by mail-yw1-f46.google.com with SMTP id l5so11437197ywa.0 for ; Tue, 26 Mar 2019 21:39:33 -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 :mime-version:content-transfer-encoding; bh=4CNjyckN27JParpPQ4yJU3GiL7jee+DWks4CN0Sqkv0=; b=SMj09bRRzU+5cmWpIVTvB5XawHYowA2HjKpD3+N/ueeVVSyWksOumaJgx9DzhVapJ/ 7Vqh83WZ+I5uMAkCjJDExxERDs/iaBIIkBnTGRUORzm6FLlevNqBTOez9ZK5AkBM/E4g uB3StHJV/zibyidKEyPNmQxUcbolhwx4fXiu3S6kyWBNUFthe1z57mH5NQlEh10PJebN VU+qJVETT4KwCauSf6J572xzUuZV3x2IP4mdkW9IDfnqBycgBnY+ijNbj4XQ5ivqD0gu 7ihbm4JLRcaACpPciVx8RKwtQINoASeV0haCSvp/5qxrU+0W31m0fuMS1S77Ethz/KMn BtQA== 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=4CNjyckN27JParpPQ4yJU3GiL7jee+DWks4CN0Sqkv0=; b=CuCQHvQx7pkkhE8haaVBwCQW21Q0muj+0IiaETXyNi43vPC3FuiR4C0a/MllfaP8iy 5z4jC3TX+9SaifGPefn6nfp6K8mcgdWNJIRcDrJV1zv9crZBMrozMZ1whG0yjFgNjvHx 5d76lt8tm24DhBXR5pYyzMGPwQXzMC+0ADjWUsHnfbpfbFttDhWuLulUYG6mCSb1+sBz pfRL3Hh1ngXdGDNaNAXZg7+/6sUsUSTdZS/3JfJp30X/u/GHMI4OYk4x4/EYAqSjtAIv tnLqOmsGztyBWRIJ/Ogcm7OtMP91JivpFyXkwKkGgO+nzVcTQP76TKmWMJf9obSZZuBG MnUw== X-Gm-Message-State: APjAAAVNSbWG/dvBIZnJRUvK6Yy/q+x4pAgBvrY+BYHKf+6JRIO4m8bD Z7NY4TSAmT+umKvpltXrLQprF0KZV6c= X-Google-Smtp-Source: APXvYqyXmpCiNoNeFkBnPVmrrNwEMtN0zxJwWHwNNQLuESNuTvoK5cbZBlmc7GfNb87upaPeAALfqQ== X-Received: by 2002:a81:7a94:: with SMTP id v142mr28962384ywc.221.1553661572673; Tue, 26 Mar 2019 21:39:32 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f190sm19638778ywb.98.2019.03.26.21.39.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:39:32 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 27 Mar 2019 13:40:38 +0900 Message-Id: <20190327044042.13707-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327044042.13707-1-takahiro.akashi@linaro.org> References: <20190327044042.13707-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC v2 07/11] 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 for reworking do_bootefi() in later patch. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 1267d895472c..e9d4881997a1 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -309,6 +309,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 static efi_status_t bootefi_run_prepare(const char *load_options_path, struct efi_device_path *device_path, @@ -432,27 +453,6 @@ static int do_efi_selftest(const char *fdt_opt) } #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 Wed Mar 27 04:40:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1066470 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="ImhIQg1m"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Tb5J4WcSz9sRf for ; Wed, 27 Mar 2019 15:44:52 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 47689C21E49; Wed, 27 Mar 2019 04:41:29 +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=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 C234BC21DFA; Wed, 27 Mar 2019 04:39:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DDCBFC21DFA; Wed, 27 Mar 2019 04:39:39 +0000 (UTC) Received: from mail-yw1-f46.google.com (mail-yw1-f46.google.com [209.85.161.46]) by lists.denx.de (Postfix) with ESMTPS id D5F71C21E57 for ; Wed, 27 Mar 2019 04:39:35 +0000 (UTC) Received: by mail-yw1-f46.google.com with SMTP id j128so11543486ywg.12 for ; Tue, 26 Mar 2019 21:39:35 -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 :mime-version:content-transfer-encoding; bh=/hPELRTp4wXMJeh+yK/JmbE4Yealtpkn91ut3BCgoL8=; b=ImhIQg1m2lfwX93pukvqQvBCUPQrZe2guVc29N9gAmx+lQJpeXrt5GIdZpFdbMBn6U L5ayvSICbPC3DdYAH1AlKuUvp4y2tLpPPgJpmELcZqxkMwEd5CszhqG6YcVi61mxqYl+ fOJOUijaZfcIAsFrsgeg9P7isirKFI2m4qune1V9BNU2TT+kq/wKDin893o2YHdzLJjs XdIL2QFWwfTLffVcI4+gmAT2mdsW4m3P0I5svYyofn/5S/dy/FQtBZIMc4SMNSj6yHms pO+2pgBf0pQ8qkXFRHZgn6+h1Uxz8BnnsGXTht1U++SOYMScfR4hVXsXvrU2FxdTOGCp gkrQ== 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=/hPELRTp4wXMJeh+yK/JmbE4Yealtpkn91ut3BCgoL8=; b=TKGZrN8Jx5lzBKOc9XSEmI200n1L2Bh2J7D9xswPqP0RpmegSRmlA+45YZa5F0w9Xx PM1I2MgEZLO3nJ475oVHgraYLcnOoH3IYakU5pneY5hpASL3VK1ePxiWNYKm+d78gtVN T+Bs1fTzRUFVolLKxVtpZBaJxXl2tIbOv8QqgCdK7MV+OQNlf2hCw2JVPAU+gXdIMUvW 1QEgaDeX8r35UqIUORaZGEAcSdzzcTF61nelnyHzl2MI2BDVco8O9hkBlbLKsZGztUMI SEKMtRUY88MBEzmFaw8g14aLiut8RanFM4BARoEdTvERtaXSo/pdGDN1sVeDX9jyPtKN FT5g== X-Gm-Message-State: APjAAAUMTey53lrOAtSD68dwpNO9EIgXmaUA05N5UYRc1YdluO1RT0s7 nMeXXZYtHKW51XCOUSrsFIpTiJ7Lhic= X-Google-Smtp-Source: APXvYqwnKkLNf2PP/RggcCdGuwly/Ha54wYuoymqro1D8j/5jfEJcKyX2NiudZP6P2IwYIx8DmMLRg== X-Received: by 2002:a81:3b58:: with SMTP id i85mr30433394ywa.357.1553661574825; Tue, 26 Mar 2019 21:39:34 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z203sm156762ywd.42.2019.03.26.21.39.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:39:34 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 27 Mar 2019 13:40:39 +0900 Message-Id: <20190327044042.13707-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327044042.13707-1-takahiro.akashi@linaro.org> References: <20190327044042.13707-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC v2 08/11] cmd: bootefi: carve out bootmgr 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 later patch. do_bootmgr_exec() is renamed to do_efibootmgr() as we put all the necessary code into this function. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index e9d4881997a1..94b5bdeed3f1 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -309,22 +309,47 @@ err_add_protocol: 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) { struct efi_device_path *device_path, *file_path; void *addr; - efi_status_t r; + efi_status_t ret; + + /* Allow unaligned memory access */ + allow_unaligned(); + + switch_to_non_secure_mode(); + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + printf("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_install_fdt(fdt_opt); + if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; 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); + ret = do_bootefi_exec(addr, device_path, file_path); printf("## Application terminated, r = %lu\n", - r & ~EFI_ERROR_MASK); + ret & ~EFI_ERROR_MASK); - if (r != EFI_SUCCESS) + if (ret != EFI_SUCCESS) return 1; return 0; @@ -463,6 +488,9 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 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); @@ -497,9 +525,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 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); From patchwork Wed Mar 27 04:40:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1066456 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="nrKqH/Bu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Tb2T5620z9sNk for ; Wed, 27 Mar 2019 15:42:25 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 63B06C21E45; Wed, 27 Mar 2019 04:41: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_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 006C4C21DFB; Wed, 27 Mar 2019 04:39:50 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 45CDEC21E57; Wed, 27 Mar 2019 04:39:41 +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 03C16C21E1A for ; Wed, 27 Mar 2019 04:39:38 +0000 (UTC) Received: by mail-yw1-f67.google.com with SMTP id c4so11544093ywa.11 for ; Tue, 26 Mar 2019 21:39:37 -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 :mime-version:content-transfer-encoding; bh=/vq7t5iK4cZOgMMxqY7yUByF6yew7zMWGt6r7Yjmw9U=; b=nrKqH/BuClUJ0v/iRCnXQ+uU8RSgcLIIi5/saffxfX1KnYVr3jUwPf13uHhvun2XeB SFKoBpQ8gcP33HsWhbyILh7itf7VzUZCWZQ1UX5jDKeqaK2Hopxkfk8RFtpJ8v5cP9OC nSzvNnwZiRDA/TaJWetodlF93lyk8PaAHKllARFASq2bOcnBlzPhURdder/pmk/GQC8D vnTfu+8pQCSEh2Fd1wg8TMS7/VLH0sDpuYEZdf/pIolOLc/lhD5jmn26W/NF0nhKO70o o6QV8AvISm+I94QvGumoUZByo/Bm4OjXwMXFSxAzZ0dDSe8w+1QyEIeBz1rFFqJ7eGSY GR0A== 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=/vq7t5iK4cZOgMMxqY7yUByF6yew7zMWGt6r7Yjmw9U=; b=fJFFe0hwPLvA/Q0xUYj4AEy5iWyAgmJKP79pgx2M9UZkp/RvL9Cbk0Cj2LqBmiZC6m fXCjYZOsrlu4DoJy5tfXNL9kvYiOPl6qv1MQ6eYCc62lbjoCT36hAjeYDQuBTU6WQts3 nvR7sSPhOC8/tJynCatBBUyfGrkq9i22S9aZcJZD8Q73NYcHHBKYC55B1UQrKiwXEEqD EAHL2shqRsAv/6K75MIDPEWpzLOTmKbJKqdu+4mJx3A5XOb4BZtEFTxNFjukPB6pvQLw 4RFlbqYXIkU6HYSa9LHb8uJpCIb3YItr20haYu7v+icda522KegPaacW9FB/qYD4ELJB 9pPg== X-Gm-Message-State: APjAAAVu8mgousGcdpQ7/smnyknExQS4VhN7Q9QwhQjD4Sq+T+fyT4Np IUyRQFwsq/WLeS3GPA3IWIjZlw== X-Google-Smtp-Source: APXvYqztnjOtxSWhoHaifTUdoQ8/qVdnlXI56hognMd0lwNwQdwb6FFDkjW6PpmV5r9F5/XtpvYJ+Q== X-Received: by 2002:a81:3204:: with SMTP id y4mr30387338ywy.142.1553661576978; Tue, 26 Mar 2019 21:39:36 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v204sm4053062ywc.54.2019.03.26.21.39.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:39:36 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 27 Mar 2019 13:40:40 +0900 Message-Id: <20190327044042.13707-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327044042.13707-1-takahiro.akashi@linaro.org> References: <20190327044042.13707-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC v2 09/11] cmd: bootefi: carve out do_boot_efi() 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 later patch. All the non-boot-manager-based (that is, bootefi ) code is put into one function, do_boot_efi(). Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 122 ++++++++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 54 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 94b5bdeed3f1..39a0712af6ad 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -355,6 +355,73 @@ static int do_efibootmgr(const char *fdt_opt) return 0; } +/* + * 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) +{ + unsigned long addr; + char *saddr; + efi_status_t ret; + unsigned long fdt_addr; + + /* Allow unaligned memory access */ + allow_unaligned(); + + switch_to_non_secure_mode(); + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + printf("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_install_fdt(fdt_opt); + if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + +#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 + { + 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); + ret = do_bootefi_exec(map_sysmem(addr, 0), bootefi_device_path, + bootefi_image_path); + printf("## Application terminated, r = %lu\n", + ret & ~EFI_ERROR_MASK); + + if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + else + return CMD_RET_SUCCESS; +} + #ifdef CONFIG_CMD_BOOTEFI_SELFTEST static efi_status_t bootefi_run_prepare(const char *load_options_path, struct efi_device_path *device_path, @@ -481,11 +548,6 @@ 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; @@ -496,55 +558,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 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; - } - - r = fdt_install_fdt(argc > 2 ? argv[2] : NULL); - if (r != EFI_SUCCESS) - return r; - -#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 - { - 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 From patchwork Wed Mar 27 04:40:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1066457 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="QD8LITCy"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Tb380KVPz9sNk for ; Wed, 27 Mar 2019 15:42:59 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 84F27C21E0B; Wed, 27 Mar 2019 04:41:43 +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 8265DC21DB6; Wed, 27 Mar 2019 04:39:57 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7F838C21E0F; Wed, 27 Mar 2019 04:39:44 +0000 (UTC) Received: from mail-yw1-f49.google.com (mail-yw1-f49.google.com [209.85.161.49]) by lists.denx.de (Postfix) with ESMTPS id DAE00C21E16 for ; Wed, 27 Mar 2019 04:39:40 +0000 (UTC) Received: by mail-yw1-f49.google.com with SMTP id m207so2469074ywd.5 for ; Tue, 26 Mar 2019 21:39:40 -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 :mime-version:content-transfer-encoding; bh=s2V2mdzzubZ/+vUnb784K7sAwxkRwDn0D0oIyV6qcCw=; b=QD8LITCyYfZ3p+zFNc6I7p7hKaHseC+9arDFkGJWMycaMhbnLsjBlpzwaq3CHnJV12 3xOzmN+qUEqoejN+6Dlz+XOyatLTLJRowJEPduryLUtb7Yx+twXNCVgkCw4MnHx2HMAL INMciBO+qQ/YU78o19NqHtvkAuA7YKO62GEA2ovQmxFhmH6gujnMAUjcsMVXSfK1YTaW abOdhJJWOebLNHvSGSSUM5z1hgwNG/8I3DUa/Tz9KhW8cqQq72l+NfQMzZYBgw9uZdxz oxMj1VYrH+vyWFR55XJqICpCf9U35vjfKUxTE2LvGuuekLg26ADqyOtCVq98Y8KrKFnG xdIA== 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=s2V2mdzzubZ/+vUnb784K7sAwxkRwDn0D0oIyV6qcCw=; b=EwlFASeay/ztP/Ok936licJlT4H9+e5oz1MgILx01YZTT9nV/hifqoBHfbnWI+Pxjv eEVtkoC4rP7zG5a6V2y+sIMr6FVwHNVx3mXsQpEoxZ0AYd1+orSCOaXTHxIZC/Jdz8q5 iBjCtoZ4uUKjVwLSdgHMbBCafI3f1g9buHelqBpQjvpfVNquIbQwIdzmMNY/bH3sf7vO ujqVeLjbFBSbPaqMToLPMN3M7cmZIiezvu5ouRY4uRY8VKywk1+xtFEj0ojsa6Y9qSrx SWna9jxqb4/1sUbejyy8aJF8iSbSto8s0mJyrTUPhG2x00qxBg9Aflk8CmPlon7R0GeD y7Pw== X-Gm-Message-State: APjAAAUm7as17XGGvtqBd2KK9qWK+MOOslqEYi8YFYbVa9wKnpZjA69Y qlHUflCkncsiuzXAJOWHiI49tA== X-Google-Smtp-Source: APXvYqzp1O1nEsWTpRPkpQAM+T+AJuEBtUyANu/icXiK8lEFr28vGhOofzX/ZE7ajdfBFS+NGVNzLw== X-Received: by 2002:a0d:d581:: with SMTP id x123mr29042945ywd.244.1553661579589; Tue, 26 Mar 2019 21:39:39 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t145sm7226363ywc.58.2019.03.26.21.39.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:39:39 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 27 Mar 2019 13:40:41 +0900 Message-Id: <20190327044042.13707-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327044042.13707-1-takahiro.akashi@linaro.org> References: <20190327044042.13707-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC v2 10/11] efi_loader: rework bootmgr/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 the current implementation, bootefi command and EFI boot manager don't use load_image API, instead, use more primitive and internal functions. This will introduce duplicated code and potentially unknown bugs as well as inconsistent behaviours. With this patch, do_efibootmgr() and do_boot_efi() are completely overhauled and re-implemented using load_image API. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 199 +++++++++++++++++++--------------- include/efi_loader.h | 5 +- lib/efi_loader/efi_bootmgr.c | 43 ++++---- lib/efi_loader/efi_boottime.c | 1 + 4 files changed, 138 insertions(+), 110 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 39a0712af6ad..17dccd718008 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -224,88 +224,43 @@ static efi_status_t efi_install_fdt(const char *fdt_opt) /** * do_bootefi_exec() - execute EFI binary * - * @efi: address of the binary - * @device_path: path of the device from which the binary was loaded - * @image_path: device path of the binary + * @handle: handle of loaded image * Return: status code * * 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, - struct efi_device_path *device_path, - struct efi_device_path *image_path) +static efi_status_t do_bootefi_exec(efi_handle_t handle) { - efi_handle_t mem_handle = NULL; - struct efi_device_path *memdp = NULL; - efi_status_t ret; struct efi_loaded_image_obj *image_obj = NULL; struct efi_loaded_image *loaded_image_info = NULL; - - /* - * Special case for efi payload not loaded from disk, such as - * 'bootefi hello' or for example payload loaded directly into - * memory via JTAG, etc: - */ - 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() */ - memdp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, 0, 0); - device_path = image_path = memdp; - /* - * Grub expects that the device path of the loaded image is - * installed on a handle. - */ - ret = efi_create_handle(&mem_handle); - if (ret != EFI_SUCCESS) - return ret; /* TODO: leaks device_path */ - ret = efi_add_protocol(mem_handle, &efi_guid_device_path, - device_path); - if (ret != EFI_SUCCESS) - goto err_add_protocol; - } else { - assert(device_path && image_path); - } - - ret = efi_setup_loaded_image(device_path, image_path, &image_obj, - &loaded_image_info); - if (ret) - goto err_prepare; + efi_status_t ret; /* 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; - - if (memdp) { - struct efi_device_path_memory *mdp = (void *)memdp; - mdp->memory_type = loaded_image_info->image_code_type; - mdp->start_address = (uintptr_t)loaded_image_info->image_base; - mdp->end_address = mdp->start_address + - loaded_image_info->image_size; - } + goto err; + set_load_options(loaded_image_info, "bootargs"); /* we don't support much: */ env_set("efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_OsIndicationsSupported", "{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); - -err_add_protocol: - if (mem_handle) - efi_delete_handle(mem_handle); + efi_free_pool(loaded_image_info); +err: return ret; } @@ -319,8 +274,7 @@ err_add_protocol: */ static int do_efibootmgr(const char *fdt_opt) { - struct efi_device_path *device_path, *file_path; - void *addr; + efi_handle_t handle; efi_status_t ret; /* Allow unaligned memory access */ @@ -340,19 +294,21 @@ static int do_efibootmgr(const char *fdt_opt) if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; - addr = efi_bootmgr_load(&device_path, &file_path); - if (!addr) - return 1; + ret = efi_bootmgr_load(&handle); + if (ret != EFI_SUCCESS) { + printf("EFI boot manager: Cannot load any image\n"); + return CMD_RET_FAILURE; + } - printf("## Starting EFI application at %p ...\n", addr); - ret = do_bootefi_exec(addr, device_path, file_path); - printf("## Application terminated, r = %lu\n", - ret & ~EFI_ERROR_MASK); + ret = do_bootefi_exec(handle); + printf("## Application terminated, r = %lu\n", ret & ~EFI_ERROR_MASK); + + EFI_CALL(efi_unload_image(handle)); if (ret != EFI_SUCCESS) - return 1; + return CMD_RET_FAILURE; - return 0; + return CMD_RET_SUCCESS; } /* @@ -367,10 +323,14 @@ static int do_efibootmgr(const char *fdt_opt) */ static int do_boot_efi(const char *image_opt, const char *fdt_opt) { - unsigned long addr; - char *saddr; + void *image_buf; + struct efi_device_path *device_path, *image_path; + struct efi_device_path *memdp = NULL, *file_path = NULL; + const char *saddr; + unsigned long addr, size; + const char *size_str; + efi_handle_t mem_handle = NULL, handle; efi_status_t ret; - unsigned long fdt_addr; /* Allow unaligned memory access */ allow_unaligned(); @@ -390,36 +350,96 @@ static int do_boot_efi(const char *image_opt, const char *fdt_opt) return CMD_RET_FAILURE; #ifdef CONFIG_CMD_BOOTEFI_HELLO - if (!strcmp(argv[1], "hello")) { - ulong size = __efi_helloworld_end - __efi_helloworld_begin; - + 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; - memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size); + + image_buf = map_sysmem(addr, size); + memcpy(image_buf, __efi_helloworld_begin, size); + + device_path = NULL; + image_path = NULL; } else #endif { - saddr = argv[1]; + 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; + } + + if (!device_path && !image_path) { + /* + * Special case for efi payload not loaded from disk, + * such as 'bootefi hello' or for example payload + * loaded directly into memory via JTAG, etc: + */ + printf("WARNING: using memory device/image path, this may confuse some payloads!\n"); + + /* actual addresses filled in after efi_load_image() */ + memdp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + (uint64_t)image_buf, size); + file_path = memdp; /* append(memdp, NULL) */ + + /* + * 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) + /* TODO: leaks device_path */ + goto err_add_protocol; + + ret = efi_add_protocol(mem_handle, &efi_guid_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_CALL(efi_load_image(false, (void *)0x1 /* FIXME */, + file_path, image_buf, size, &handle)); + if (ret != EFI_SUCCESS) + goto err_prepare; + printf("## Starting EFI application at %08lx ...\n", addr); - ret = do_bootefi_exec(map_sysmem(addr, 0), bootefi_device_path, - bootefi_image_path); - printf("## Application terminated, r = %lu\n", - ret & ~EFI_ERROR_MASK); + ret = do_bootefi_exec(handle); + printf("## Application terminated, r = %lu\n", ret & ~EFI_ERROR_MASK); + + EFI_CALL(efi_unload_image(handle)); +err_prepare: + if (device_path) + efi_free_pool(file_path); + +err_add_protocol: + if (mem_handle) + efi_delete_handle(mem_handle); + if (memdp) + efi_free_pool(memdp); if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; - else - return CMD_RET_SUCCESS; + + return CMD_RET_SUCCESS; } #ifdef CONFIG_CMD_BOOTEFI_SELFTEST @@ -577,7 +597,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" @@ -602,6 +622,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/include/efi_loader.h b/include/efi_loader.h index 6dfa2fef3cf0..6c09a7f40d02 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -410,8 +410,6 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path, struct efi_device_path *file_path, struct efi_loaded_image_obj **handle_ptr, struct efi_loaded_image **info_ptr); -efi_status_t efi_load_image_from_path(struct efi_device_path *file_path, - void **buffer, efi_uintn_t *size); /* Print information about all loaded images */ void efi_print_image_infos(void *pc); @@ -565,8 +563,7 @@ 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(efi_handle_t *handle); #else /* CONFIG_IS_ENABLED(EFI_LOADER) */ diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 4fccadc5483d..13ec79b2098b 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -120,14 +120,14 @@ 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, efi_handle_t *handle) { 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,19 +136,19 @@ 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_CALL(efi_load_image(false, (void *)0x1 /* FIXME */, + lo.file_path, NULL, 0, + handle)); if (ret != EFI_SUCCESS) goto error; @@ -159,17 +159,22 @@ static void *try_load_entry(uint16_t n, struct efi_device_path **device_path, L"BootCurrent", (efi_guid_t *)&efi_global_variable_guid, attributes, size, &n)); - if (ret != EFI_SUCCESS) + if (ret != EFI_SUCCESS) { + if (EFI_CALL(efi_unload_image(*handle)) + != EFI_SUCCESS) + printf("Unloading image failed\n"); goto error; + } 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 +182,10 @@ 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(efi_handle_t *handle) { u16 bootnext, *bootorder; efi_uintn_t size; - void *image = NULL; int i, num; efi_status_t ret; @@ -209,10 +212,9 @@ void *efi_bootmgr_load(struct efi_device_path **device_path, /* load BootNext */ if (ret == EFI_SUCCESS) { if (size == sizeof(u16)) { - image = try_load_entry(bootnext, device_path, - file_path); - if (image) - return image; + ret = try_load_entry(bootnext, handle); + if (ret == EFI_SUCCESS) + return ret; } } else { printf("Deleting BootNext failed\n"); @@ -223,19 +225,20 @@ 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) + ret = try_load_entry(bootorder[i], handle); + if (ret == EFI_SUCCESS) break; } free(bootorder); error: - return image; + return ret; } diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 74da6b01054a..8e2fa0111591 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1610,6 +1610,7 @@ failure: * @size: size of the loaded image * Return: status code */ +static efi_status_t efi_load_image_from_path(struct efi_device_path *file_path, void **buffer, efi_uintn_t *size) { From patchwork Wed Mar 27 04:40:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1066469 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="aFzWtXJt"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44Tb5G6gl7z9sR9 for ; Wed, 27 Mar 2019 15:44:50 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 85357C21E15; Wed, 27 Mar 2019 04:42:10 +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 5D0D1C21E38; Wed, 27 Mar 2019 04:40:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7A81FC21E36; Wed, 27 Mar 2019 04:39:46 +0000 (UTC) Received: from mail-yw1-f68.google.com (mail-yw1-f68.google.com [209.85.161.68]) by lists.denx.de (Postfix) with ESMTPS id B8740C21DFB for ; Wed, 27 Mar 2019 04:39:42 +0000 (UTC) Received: by mail-yw1-f68.google.com with SMTP id z9so7997545ywd.6 for ; Tue, 26 Mar 2019 21:39:42 -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 :mime-version:content-transfer-encoding; bh=Y38BbfBZ2Khxmj9ROhCNtb+AIVBveBgZcfNqnkHbMyw=; b=aFzWtXJtJERxV3xYtzZnQZ34zZE/doyxo5ThWRtAnjyHdiNG3Tu+QKYXwTLvSMt+Ug rlhcHoXdNZny8c75SI5koB9MD5ZGyyaK0uK2J0NS6i6JsDlMcw1Aig55w/dxHQpuko7A 1iBMr9qQD+wUa0hgJsU/ws+NXvwJP9G8EFVd6IBjftUxUTTHHLwyyII0NEh8lmEGXPdq ngQxViH2OAyOax4K0QUrCLs0eEHQAVWskXOMl9hINj9WNUOdH52izK+dBo5mDxrc/39v 16Ke68evGgjpodqUfLI/tDiin1CbjV7osGOD13Facud6UyBeQ3fwa+urd608mki803L0 aiUw== 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=Y38BbfBZ2Khxmj9ROhCNtb+AIVBveBgZcfNqnkHbMyw=; b=VTzeKHy/9a99KwmEI0hkICFbbvZCiO3JRxSO/JgstNkfD41bslz+UJndBeo2r84JJe 0aYpz+b5d2sh+/xYcLwI+zjQosbvHADn9UU4Llysi0YZ+SxnsG3B2iod/XVvHrZp7I/J sTJGUmnrCj2A+UW/wS8qRsnoyG7D25Du0I4q3P+wceUaqr2nPdpEZTgGGh2wHw5w63Rp lJ+/hRCu2tTP8NH7rIDvWpi/Bie7rMQfGsD9/dt74p4q3g84fkL3WvwiJ8V+PW6YKD6v 1tF0D2mVr0TUITe9nteEingte8bdqHrxLqcQQpYShDNQmB9rsaxggiQPstLUjSgZTgz5 64CQ== X-Gm-Message-State: APjAAAWOYrbSn6ZzueE+nNuZBtkUze5cciZB8ZkuCPQuE8WKCwtrNNev u/P2gQAgE475aepMu9GwekSV3LdrAIc= X-Google-Smtp-Source: APXvYqxmTKWXqQ5w0k4xJerp6lGfk8QnArTWhipHUtftzVJW5kQfU+8xmcPEhJbvziCd21ONAmqv8w== X-Received: by 2002:a25:582:: with SMTP id 124mr28365969ybf.374.1553661581710; Tue, 26 Mar 2019 21:39:41 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l82sm5703322ywl.6.2019.03.26.21.39.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:39:41 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 27 Mar 2019 13:40:42 +0900 Message-Id: <20190327044042.13707-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327044042.13707-1-takahiro.akashi@linaro.org> References: <20190327044042.13707-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC v2 11/11] 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. With this patch, EFI boot manager can be kicked in by a standalone command, 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 17dccd718008..2a2ff4034831 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -635,3 +635,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 */