From patchwork Thu May 12 02:29:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 571792 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:66c4:0:0:0:0 with SMTP id x4csp258469mal; Wed, 11 May 2022 19:29:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQf0CMDyn2a+fsrWV5D5tlw57PhVXKw0L1VqbBFxJGY1COQqrtAPFLb1/IR4Lr/bqODBbA X-Received: by 2002:a17:907:96a8:b0:6f4:45f1:6e76 with SMTP id hd40-20020a17090796a800b006f445f16e76mr28635904ejc.186.1652322597598; Wed, 11 May 2022 19:29:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652322597; cv=none; d=google.com; s=arc-20160816; b=g9e/dUHfZrjDyWmaL4qdaSwJdbuIaWOD80qFwGvZhktdUjpDVC6oWx53T3pTwT6Is8 uITlkfkjxF9cvukVe5xvu8e0JaAQBde6/CS2oIRllBRPNutGqu/DGNbQVpuYUhY52uc3 v59CYb/ZlR0HkdWOL6RV4j8uXZeubbrw5z7fcA3w994M6b/RtjYNLPTprJxiAy+rLsJh AWZ3Z2Rm2OIdJSvBGIhMOm1M1DjgLjT+1YrR9NVb/yYchOZSjUFDH4CYUkTBXAaQgTq1 4/OUg5UZMDbCp1IJ7960xt7AhWi2x1avEH1jQDETiA4yR2bLl+QsimPwmn3xjrlb2dc9 Hm6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=h6UUKFaHkOLSlGWXFN0CEMZtf9sWvPkPw+9EWwYGpCg=; b=wIW9HQLLYAQNDlD/v1/PJvCkdMi9glNfs+76QVTwIaxPQOHTd/XMbEq2EEJCRNsSXb jpgdfPNk/4EC1+4ir6en8yrmuhY7wbv8YRPh40/IUrjmQGGtvtFkm8ZyVOB4zkck4K0E iGk9GpJ6Q0xLnR1YimdU5OTlHLxtlW7jkA2M8kD1VRbx4QAvEF0E4AbQ0TaaKTpmacEO GRl3RapqCmXQa+1n6Vj4O3tc4dAYIMIgGj8N7C5DZwrhrDRtovKFLTQ78nhUX4S2WB6m 7UOg+ccTNDS5Fhrd6kvvR63vRDCnfbGk1SbPn8PPVwMIb2qrO3aq5aSYWLFgCtdxpqn+ U+Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xO6RPoSP; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id oz39-20020a1709077da700b006e8b1219735si4647048ejc.8.2022.05.11.19.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 19:29:57 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xO6RPoSP; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BC37684372; Thu, 12 May 2022 04:29:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="xO6RPoSP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B63A18435A; Thu, 12 May 2022 04:29:48 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 77A6E8432D for ; Thu, 12 May 2022 04:29:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pg1-x52e.google.com with SMTP id v10so3336359pgl.11 for ; Wed, 11 May 2022 19:29:45 -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=h6UUKFaHkOLSlGWXFN0CEMZtf9sWvPkPw+9EWwYGpCg=; b=xO6RPoSPvYlUhFbX0/+E+UGw3Nr8Yq4ww4z/u+SSg1z+gjWsI2impxphR188Rul2Ih /zZDTQJ/22luDiceJ1999Q+AaKk+dJO6ZdKQtCmyOTB45alSTv/+VmAUHYmtaqUpIqO5 4XSLFwDZ2byOzcbUA/k0gYSoygZyhQR/N0rqCG8QAR/NlwYhBRLxGxRfQBB+YDPLOieh dEyUB3isSYN8ZoGpE8adtsMDBBCTpSlzmxu6awmAdSa2h+Pm53EapLhW0lqZTnTjDT0G JcOy5oFRb1HQJVWkB4WUqgKeeKcXbRWiPVDO/GsavqJiH2pbfwogVPGDOlRL9oNN6DX9 2nmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h6UUKFaHkOLSlGWXFN0CEMZtf9sWvPkPw+9EWwYGpCg=; b=JuzkUvHXf+M8loPY+WJuNuVWa13pcfSDiVChGJJY9Iedpc5zXCPDbIRHoZk92D9TEQ ohjS5X1dRXW9VYDEiPGr0LhKXTmZbpA0ecdlTW/lmawVUlFNch/3sXoivWfHye6rrhkG zJ0FZ0/StCngLFglmbqX741ARrjT1g/J+kq+OB68hQm/CuMNe+ZjSAFIGsQssWKIxN50 5ktLclaeqJuSQrVcPAF979b0IXQX+LyBevwGMLrEdcer1W/rhhIqbJDTSTPUD4gpDfhO mFTNNqdqvN7XxfCAsBB4aTrF88/y9GkYufyB9gbOQJsTBICCDGfI34VBjve6USvheLfX vCeQ== X-Gm-Message-State: AOAM5320pGAtO+sCrqfdJsA8QztleX9uTh7qlCMBgB0mcKgPP2TX0aKF wmPygRm1JWR+SbfWS1yx08IooGQo0AFrqA== X-Received: by 2002:a63:82c7:0:b0:398:2d6d:848a with SMTP id w190-20020a6382c7000000b003982d6d848amr22110645pgd.343.1652322583903; Wed, 11 May 2022 19:29:43 -0700 (PDT) Received: from localhost.localdomain (p914133-ipoe.ipoe.ocn.ne.jp. [153.243.15.132]) by smtp.gmail.com with ESMTPSA id i4-20020aa78b44000000b0050dc7628190sm2445314pfd.106.2022.05.11.19.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 19:29:43 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de Cc: mark.kettenis@xs4all.nl, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 1/3] efi_loader: disk: add efi_disk_is_removable() Date: Thu, 12 May 2022 11:29:01 +0900 Message-Id: <20220512022903.65346-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220512022903.65346-1-takahiro.akashi@linaro.org> References: <20220512022903.65346-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean This helper function will be used to determine if the device is removable media, initially for handling a short-path loading. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- include/efi_loader.h | 3 +++ lib/efi_loader/efi_disk.c | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/efi_loader.h b/include/efi_loader.h index 40fbab816e2d..839184acb7ff 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -659,6 +659,9 @@ efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type, /* Call this to signal an event */ void efi_signal_event(struct efi_event *event); +/* return true if the device is removable */ +bool efi_disk_is_removable(efi_handle_t handle); + /* open file system: */ struct efi_simple_file_system_protocol *efi_simple_file_system( struct blk_desc *desc, int part, struct efi_device_path *dp); diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index f5b462fb164a..1e82f52dc070 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -73,6 +73,33 @@ static efi_status_t EFIAPI efi_disk_reset(struct efi_block_io *this, return EFI_EXIT(EFI_SUCCESS); } +/** + * efi_disk_is_removable() - check if the device is removable media + * @handle: efi object handle; + * + * Examine the device and determine if the device is a local block device + * and removable media. + * + * Return: true if removable, false otherwise + */ +bool efi_disk_is_removable(efi_handle_t handle) +{ + struct efi_handler *handler; + struct efi_block_io *io; + efi_status_t ret; + + ret = efi_search_protocol(handle, &efi_block_io_guid, &handler); + if (ret != EFI_SUCCESS) + return false; + + io = handler->protocol_interface; + + if (!io || !io->media) + return false; + + return (bool)io->media->removable_media; +} + enum efi_disk_direction { EFI_DISK_READ, EFI_DISK_WRITE, From patchwork Thu May 12 02:29:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 571793 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:66c4:0:0:0:0 with SMTP id x4csp258600mal; Wed, 11 May 2022 19:30:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaOjAtkdSXJZDi+huPNFiUsQLf5D+3nOacYL4TuXiSOAoFspY0hkpGZAUqG/UjrMU19GxY X-Received: by 2002:a17:907:7da3:b0:6f5:2d00:e069 with SMTP id oz35-20020a1709077da300b006f52d00e069mr25382239ejc.743.1652322611661; Wed, 11 May 2022 19:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652322611; cv=none; d=google.com; s=arc-20160816; b=hoS1NGcOokIt+EREPOaE9xYLK2plc/glHMuK0OYIwumd7ZhYYbBh/hKqc5lCnSIzFK Utj8epP0uFAQSfNY19CwdHxrHoP+scXINUTHU97JYb03eRZNjysRIurDvV63ObM7VL5g obs135wEtA8hgIUf9QI375gRiUz80X6pXvTEGjsic3j1qOo5xhq0AAejxsDEjy+96IwX YcRPKYg+Zrn7gYbwm5IEnMViKKmFDNiZHSwIG678JntcOVukqtvlWivRxYJg9mY2n8BE RoP30PN7PIMlfsx7sfGXW3UFJ/7NSMb1Jwq2jar3CUim9V+GLVGhNnmj4RdP/IIIjUjE 8Icw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=exTxoWac+E6AKTuBh7PTaqLLySWqDQS4GkpNUV0KF64=; b=daW1U/o3Qelu9LbZlr7U6+j7XofeAds19X7o78zciRbJiqzh9jXRCw7FbENW9LHnyM BIBvkZY9rRYREDkUmm18uJaRPfMbpj/mOMuCvsFbaeh7QypuQulKGHq/H9pfusGLLLTI m35tDu03JVTL/nrjQDQbm148h4WNev7wEI3t6jaQMcra8uJg80hHIyVWu6xxAgoBIl1x G2OpSHJnlq4ddAQ9avy+wV1K1z9Pd2ks0jDo1r/26/tYkx/R0c/rYs5ON6o7BByV7uBE wJ2Yl/KCarrYGJZo1xRzTSnuy40RrtY/rZqwu7IPIlrZEKYWVHYUP3PQR4TXBKLmNoDb 3zmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I64cbdyO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id z20-20020a05640235d400b004280d15fdb3si4485870edc.395.2022.05.11.19.30.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 19:30:11 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I64cbdyO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B990A8435B; Thu, 12 May 2022 04:29:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="I64cbdyO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CB3A284375; Thu, 12 May 2022 04:29:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EA18584356 for ; Thu, 12 May 2022 04:29:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x429.google.com with SMTP id p8so3536607pfh.8 for ; Wed, 11 May 2022 19:29:47 -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=exTxoWac+E6AKTuBh7PTaqLLySWqDQS4GkpNUV0KF64=; b=I64cbdyOOA00G/4wZHwzSLV4Pxl8dhqHFA5lnYJbPrDmfI7Z/RMoVDZvpsP3CiqsMI VS3VCF8XgjnRJTppx7HiUcD3XrLaTjg69u+wm25DL1Gyl59fPRyGuqWnvKJR9yTRirR8 a/BZmgSpXAzj4uNrXWK8GKXbm0ajC3f9fyhesITHWWmAXaHfDdYbb4c98ZiYPW5E/WJs C1BNE9YFboLyKCbNOAEPjMfNPgaGYAl5ijpEu1N9+f12HBoAdHus2+oyFEQn6RhU+1yn ZUa1sx92UcG9MPrvfsGLpbcka0Mu0bsPu2xvCKxGp/pwzNXVBU7mPagP9qAcHtDhHtWx v0aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=exTxoWac+E6AKTuBh7PTaqLLySWqDQS4GkpNUV0KF64=; b=E0BNx7tS6jnspAreW2eMkyQU5l5Ok65d3P5/LQk3jIyjav4OV+g9AoDasaJA/FN+iZ kUvHPs2D5cpWG+31Zh1S8aQvQ4oE+gKNvctpSthZiTlvqp2STOK54tNLLybScUly9716 UOEhdwugmbbfcAycqTyBCwmSSfIwx6Ay4ONPVLjmmbp0X5qdNHu5FIz+ra03C7iH73EM WBjG5pZfiwfNeQ6Be+BJIUt3cRoFyyNL+7LiRLWexW6fgauYUgtUbWphfQgm5XN79yNE nR3udNVzFtyi7oqIIr7nI2w2DcdcvbBnrE7Pz6IG2PenDBtQRFqbDtsBqJGFqFIoCtiA qnuQ== X-Gm-Message-State: AOAM532SgYIoKFEIrl+/lDsF0e7+agmpZmM7F8G2etd3vAaxjT4KnrRT gjyEMSz19KZo6RFXhU0WV6DBig== X-Received: by 2002:a63:5cb:0:b0:3da:fe5d:4448 with SMTP id 194-20020a6305cb000000b003dafe5d4448mr8033576pgf.583.1652322586010; Wed, 11 May 2022 19:29:46 -0700 (PDT) Received: from localhost.localdomain (p914133-ipoe.ipoe.ocn.ne.jp. [153.243.15.132]) by smtp.gmail.com with ESMTPSA id i4-20020aa78b44000000b0050dc7628190sm2445314pfd.106.2022.05.11.19.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 19:29:45 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de Cc: mark.kettenis@xs4all.nl, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 2/3] efi_loader: bootmgr: fix a problem in loading an image from a short-path Date: Thu, 12 May 2022 11:29:02 +0900 Message-Id: <20220512022903.65346-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220512022903.65346-1-takahiro.akashi@linaro.org> References: <20220512022903.65346-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Booting from a short-form device path which starts with the first element being a File Path Media Device Path failed because it doesn't contain any valid device with simple file system protocol and efi_dp_find_obj() in efi_load_image_from_path() will return NULL. For instance, /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)/\helloworld.efi -> shortened version: /\helloworld.efi With this patch applied, all the media devices with simple file system protocol are enumerated and the boot manager attempts to boot temporarily generated device paths one-by-one. This new implementation is still a bit incompatible with the UEFI specification in terms of: * not creating real boot options * not try "If a device does not support the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, but supports the EFI_BLOCK_IO_PROTOCOL protocol, then the EFI Boot Service ConnectController must be called for this device with DriverImageHandle and RemainingDevicePath set to NULL and the Recursive flag is set to TRUE." (See section 3.1.2 "Load Option Processing".) But it still gives us a closer and better solution than the current. Fixes: commit 9cdf470274ff ("efi_loader: support booting via short-form device-path") Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_bootmgr.c | 98 ++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 4 deletions(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 631a25d76e9e..3608e433503e 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -76,6 +76,91 @@ struct efi_device_path *expand_media_path(struct efi_device_path *device_path) return full_path; } +static efi_status_t __try_load(efi_handle_t *fs_handles, efi_uintn_t num, + struct efi_device_path *fp, + efi_handle_t *handle, bool removable) +{ + struct efi_handler *handler; + struct efi_device_path *dp; + int i; + efi_status_t ret; + + for (i = 0; i < num; i++) { + if (removable && !efi_disk_is_removable(fs_handles[i])) + continue; + if (!removable && efi_disk_is_removable(fs_handles[i])) + continue; + + ret = efi_search_protocol(fs_handles[i], &efi_guid_device_path, + &handler); + if (ret != EFI_SUCCESS) + /* unlikely */ + continue; + + dp = handler->protocol_interface; + if (!dp) + /* unlikely */ + continue; + + dp = efi_dp_append(dp, fp); + if (!dp) + /* unlikely */ + continue; + + ret = EFI_CALL(efi_load_image(true, efi_root, dp, NULL, 0, + handle)); + efi_free_pool(dp); + if (ret == EFI_SUCCESS) + return ret; + } + + return EFI_NOT_FOUND; +} + +/** + * try_load_from_short_path + * @fp: file path + * @handle: pointer to handle for newly installed image + * + * Enumerate all the devices which support file system operations, + * prepend its media device path to the file path, @fp, and + * try to load the file. + * This function should be called when handling a short-form path + * which is starting with a file device path. + * + * Return: status code + */ +static efi_status_t try_load_from_short_path(struct efi_device_path *fp, + efi_handle_t *handle) +{ + efi_handle_t *fs_handles; + efi_uintn_t num; + efi_status_t ret; + + ret = EFI_CALL(efi_locate_handle_buffer( + BY_PROTOCOL, + &efi_simple_file_system_protocol_guid, + NULL, + &num, &fs_handles)); + if (ret != EFI_SUCCESS) + return ret; + if (!num) + return EFI_NOT_FOUND; + + /* removable media first */ + ret = __try_load(fs_handles, num, fp, handle, true); + if (ret == EFI_SUCCESS) + goto out; + + /* fixed media */ + ret = __try_load(fs_handles, num, fp, handle, false); + if (ret == EFI_SUCCESS) + goto out; + +out: + return ret; +} + /** * try_load_entry() - try to load image for boot option * @@ -116,10 +201,15 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, log_debug("trying to load \"%ls\" from %pD\n", lo.label, lo.file_path); - file_path = expand_media_path(lo.file_path); - ret = EFI_CALL(efi_load_image(true, efi_root, file_path, - NULL, 0, handle)); - efi_free_pool(file_path); + if (EFI_DP_TYPE(lo.file_path, MEDIA_DEVICE, FILE_PATH)) { + /* file_path doesn't contain a device path */ + ret = try_load_from_short_path(lo.file_path, handle); + } else { + file_path = expand_media_path(lo.file_path); + ret = EFI_CALL(efi_load_image(true, efi_root, file_path, + NULL, 0, handle)); + efi_free_pool(file_path); + } if (ret != EFI_SUCCESS) { log_warning("Loading %ls '%ls' failed\n", varname, lo.label); From patchwork Thu May 12 02:29:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 571794 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:66c4:0:0:0:0 with SMTP id x4csp258806mal; Wed, 11 May 2022 19:30:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiLsRWvHrpTooUh//bIgnQKvjDhucpMKCxuUEkSAQbtLcZucQDHfLlXE762Ij+oDhg5RaD X-Received: by 2002:a17:907:948d:b0:6fa:7f00:ed57 with SMTP id dm13-20020a170907948d00b006fa7f00ed57mr16304409ejc.761.1652322636615; Wed, 11 May 2022 19:30:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652322636; cv=none; d=google.com; s=arc-20160816; b=bWhukaiFCBjgpPFLj//PCLmFiYxOGkhOhzraRY4PEO73xYNwP1Rq4iwvbcwW/ZlweO 4a4jArolHCDFF6vEZff2a1Tv9FSEIeF/CtZBNH7HdVrw4sdIeFJl/MUWANMg1vfYCHI9 /8oWrkibJ1sRDi1Y3c60IjKZ6BlxmBtGwgZLD/htsrwyzuT7Ts9lXBkYvvnwkc3j/vkH v4sd8i/pgFO+TRP/X0I5STWjrN1OGje2V/zKnSbka3CKvxVdtlW0qS03ii/Vlr298mYl wUFefG/kh0xRqdeMEdCT7tVrvsU9FhwybP4r6zK9BVSUqJVTZkJMUYxMYBu2fkuOLmNo gBKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YPOFOE3NvbBxeFM2xBwqWvtaayvQyGUKm3Se3idq6Ps=; b=OW2Q8iKVPXO475tDW4qM4ExEWFlcsr0VJMKEnu06/q6ssx+/biJe0PmQcAEo2Ybw0l Vwu0rWnRzfA5sgM8K1sP9d1Al1VLr+zXTO4egxNAFItm9PbK8knSRlU1P1N/fpuGz4Ec KfkFExiufOyCnBOS2xatxI/prfNFo0pooaf9I1GQe5y3YxzL6xuv7Z061fG+v5u0CdUm GJe26Ao/PvCBbfY5OWc8TlTP9uLW51HUx5lK7MsEZkqz0oCtFpEOmJWDnmVVqZLRdWL0 hnblkPrewUGo1a24LYcgvw/9hBhaLhKz4hs81a3M6ax6j8fRFxcK19QLU9nViVu5tJCI rZAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SsmFlNOD; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id hs3-20020a1709073e8300b006e89e2b6fffsi5636979ejc.479.2022.05.11.19.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 19:30:36 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SsmFlNOD; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 000A1843A0; Thu, 12 May 2022 04:30:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="SsmFlNOD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A83FB8434B; Thu, 12 May 2022 04:29:56 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CED818435B for ; Thu, 12 May 2022 04:29:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x42d.google.com with SMTP id x52so3522838pfu.11 for ; Wed, 11 May 2022 19:29:49 -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=YPOFOE3NvbBxeFM2xBwqWvtaayvQyGUKm3Se3idq6Ps=; b=SsmFlNODfJSlGg1/GzfrjpowU+g+L77tVd42+uncQjxlSaDLvpE/MykYvuE0ogwIPn bPckli3bSMqHw0aThII8f8RuGmnRAk0kYnAAN7T8uZzYOUFEVYGOdrL9fcPMVMjPik44 YGv7m4DOUcnhY4N74zi8CGWPxHk9UTwf8zS4xoM/XYs3PKsjYQWVRyxyqh3oKJqDb/dD 04nRHPKEfvsRP3wG/9ZFzL8MEttTq1BfBoKPirhueQVpnt9i4c3ovXacwfch8zt44X63 HwcZxuhzeORy8J0e+s/0AyknMuESmDiekps30+ahn+v+9xkfFxLv8O6Fe+7A1tbizFFB vKvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YPOFOE3NvbBxeFM2xBwqWvtaayvQyGUKm3Se3idq6Ps=; b=L3ZHDVPkxXbR1sDcXe9mRP8+gIHZDihILlrMNJxIaHd/14Fx1aPPIiPX76HbYwurML ytaN7D9OwpO2Jw2ZrvJhagaIq+BV4QDLxOZ919BUsqxwOsKYGsL8Q/EIN5/hDUG1uRMf BOA5CRhKw6tpyjDx3GfD+pP1YD8Eg7ouYdt61f/SBrmPPqUK88A45A1MnLwbFSTh9G/D GwCbfnjba2V5ZKXwLaRV90Net9F4tMwaxVWetExw7tMfe6oTR7hNeiH3DANC5yvbNK+a +CyQns/YKZrxg+pcw/qEQs9iR7sgaGb0MoJ3WhcYxl6abT7IpGzmZrdpVTFmtYY3xwgd KUww== X-Gm-Message-State: AOAM532qEQrDb5l8zrOre1bKjvtNAWDBz0fjkt59gokFoBN15lhXzGQt hX1GmIO7OofCjbNzEm2SR9PiZA== X-Received: by 2002:a63:286:0:b0:3ab:971a:eb4c with SMTP id 128-20020a630286000000b003ab971aeb4cmr23456016pgc.105.1652322588096; Wed, 11 May 2022 19:29:48 -0700 (PDT) Received: from localhost.localdomain (p914133-ipoe.ipoe.ocn.ne.jp. [153.243.15.132]) by smtp.gmail.com with ESMTPSA id i4-20020aa78b44000000b0050dc7628190sm2445314pfd.106.2022.05.11.19.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 19:29:47 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de Cc: mark.kettenis@xs4all.nl, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 3/3] test: efi_bootmgr: add a test case for a short-form path Date: Thu, 12 May 2022 11:29:03 +0900 Message-Id: <20220512022903.65346-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220512022903.65346-1-takahiro.akashi@linaro.org> References: <20220512022903.65346-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean A short-form path starting with a file device path will be tested in a new test case. This type of short-form path will be created with "efidebug boot add -b", in particular, when a file system has no partition table. Signed-off-by: AKASHI Takahiro --- test/py/tests/test_efi_bootmgr/conftest.py | 25 +++++++++++++++++++ .../test_efi_bootmgr/test_efi_bootmgr.py | 25 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/test/py/tests/test_efi_bootmgr/conftest.py b/test/py/tests/test_efi_bootmgr/conftest.py index a0a754afbe1b..5cd7252671fa 100644 --- a/test/py/tests/test_efi_bootmgr/conftest.py +++ b/test/py/tests/test_efi_bootmgr/conftest.py @@ -38,3 +38,28 @@ def efi_bootmgr_data(u_boot_config): shell=True) return image_path + +@pytest.fixture(scope='session') +def efi_bootmgr_data2(u_boot_config): + """Set up a file system without a partition table to be used + in UEFI bootmanager tests + + Args: + u_boot_config -- U-boot configuration. + + Return: + A path to disk image to be used for testing + """ + mnt_point = u_boot_config.persistent_data_dir + '/test_efi_bootmgr' + image_path = u_boot_config.persistent_data_dir + '/efi_bootmgr_data2.img' + + shutil.rmtree(mnt_point, ignore_errors=True) + os.mkdir(mnt_point, mode = 0o755) + + shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/helloworld.efi', + mnt_point + '/helloworld.efi') + + check_call(f'virt-make-fs --size=+1M --type=vfat {mnt_point} {image_path}', + shell=True) + + return image_path diff --git a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py index 75a6e7c96296..ab3d53a2dc95 100644 --- a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py +++ b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py @@ -41,3 +41,28 @@ def test_efi_bootmgr(u_boot_console, efi_bootmgr_data): u_boot_console.run_command(cmd = 'efidebug boot rm 0001') u_boot_console.run_command(cmd = 'efidebug boot rm 0002') + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_efidebug') +@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr') +def test_efi_bootmgr_short(u_boot_console, efi_bootmgr_data2): + """ Unit test for UEFI bootmanager with a short-form path + In this test case, + - File system has no partition table + - UEFI load option has a short-form path starting with a file device path + + Args: + u_boot_console -- U-Boot console + efi_bootmgr_data2 -- Path to the disk image used for testing. + """ + u_boot_console.run_command(cmd = f'host bind 0 {efi_bootmgr_data2}') + + u_boot_console.run_command(cmd = 'efidebug boot add ' \ + '-b 0001 TEST2 host 0:0 helloworld.efi') + response = u_boot_console.run_command(cmd = 'efidebug boot dump') + assert 'file_path: /helloworld.efi' in response + u_boot_console.run_command(cmd = 'efidebug boot next 0001') + response = u_boot_console.run_command(cmd = 'bootefi bootmgr') + assert 'Hello, world!' in response + + u_boot_console.run_command(cmd = 'efidebug boot rm 0001')