From patchwork Tue Jan 25 11:31:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 536483 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp3625234imr; Tue, 25 Jan 2022 03:31:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxfwZbpvJFvV06DT/72FPwz8RjM+coFfXiTj7UtciLQNVfKvpODeXID9Vl2Tp9RJt4nCOo X-Received: by 2002:a17:906:1f04:: with SMTP id w4mr15373992ejj.603.1643110302627; Tue, 25 Jan 2022 03:31:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643110302; cv=none; d=google.com; s=arc-20160816; b=AIjtCE9zPlC115i/1UR58hDPnm1nNTiD2Aoq3jKpRs0Lu1bpECfBFFlATSFR7vyeLy r2vdusDYX0WDHYQ/FFurBdqRl12jV1l9c8Bg6Ow5zAQUWlj/XfUuxjlOIZQpCWXjgg9v b2j9/YN6CwEVCdzQvZDGxaY7uB8km0+38Bz4dF/nAdt7SLNBIm7R7jsnP93Ubh4MI5gr 98Ffx++qDgv3+z426/8JJuMGuHt5bsJ9jM9ANi06ArSlPo5m6tzG20alu2wNPQuGsBch 2cjrbaNsVJgpPaD5FwtKmLP2XKl9PAG6Wi59UtyJ3KAQRUxJiBY55DvVS2o0BxtFlZam kHkw== 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:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=QIVzpy0MsSfbcWtcTdJi4HK1q2u6/2sWGEDxNe2d3Jo=; b=z0JlWUftgbab+hS2ZXdDnSDDifVr73w3f9i4PojlyiO1YipSZpcxer97SnA6Qi5niC zBxZo8jiZCzAXyxFsUhPDRWHetAjaakWEykZJhzc3PdjBfZo0S8+22LqomxVoEX1joId DWegFG4wOzbQzyrgmLT4PFd4k2jdcZC80/BxLQyeQQGTbT0u+j/NUsJaJwu4vIlVB0Vx fzFXxwp6N2/ZkMlbrdktlalETQo1cLENkyciFH4AoeWOtOg3jQ52IZMN9PqHPVT+0giv pqVPHbwC1umCQx0P/EhFW1pjouBs5s6ELN/32QQZVSZjYtk8omldv41gVCRhnSRCP4H1 u2bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NW5L8ejD; 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 j5si9149721ejo.649.2022.01.25.03.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 03:31:42 -0800 (PST) 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=NW5L8ejD; 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 D8E728354B; Tue, 25 Jan 2022 12:31:41 +0100 (CET) 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="NW5L8ejD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5745F8354B; Tue, 25 Jan 2022 12:31:40 +0100 (CET) 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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (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 BCBFB837B1 for ; Tue, 25 Jan 2022 12:31:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pl1-x62e.google.com with SMTP id x11so13198111plg.6 for ; Tue, 25 Jan 2022 03:31:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=QIVzpy0MsSfbcWtcTdJi4HK1q2u6/2sWGEDxNe2d3Jo=; b=NW5L8ejD7PpGsLP8mQ0kUAbIqslvLk+brOcwFq4x9CJxpwypVI09Uo21O4/N58V+yN 8dbhxewhGGhg4MG6ItcubETB4WwwczYt1dB/PZaDKmamCVrMt35TPHYffWWtUOEvEL6h XubKImwDW4Sbs3iF0BwhW4Vln1g+98iMiT+Q/9LlRpKMMe/WF2rQZbWdfoHZesGnyiDC emxEJ5fOSi3J5q7ooUpN/iCRBV6UrOA4qRcNnpsrUfvq+1bzZZ8Y7zPUw4dIqp89/10z DX0YA9/AoIkGVBB/q3G1xXz1HI7af4F/c4JzTI1qIeV2QRPDYRALQtsIPmDk7++HBNjW dhkw== 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:user-agent:mime-version:content-transfer-encoding; bh=QIVzpy0MsSfbcWtcTdJi4HK1q2u6/2sWGEDxNe2d3Jo=; b=XS6nr6Jhjth/GEAPFY7vvfCLhE4pq1qNiepdsiAHke0qcQBK/4NGaySRMp5kU4Xkrz y8moRkNaRTVtWzVWvT8OiIVQEOvBbdtSnKDhJiKRLFSbyaXeHA+xD5bNFhv82JUYi0Mr yLTb1koNYlZgcCM/rdWxU6LCKDtkfdAudefcjynXkZZi8v0BWhjQKWWMWqPz9/t+3zZS kddSJ4b8IPOq/0M+Wb7SeRBJx25bCKD6n4uvXKnMGM1zZOp4TatGPD4X6eYsmn7KGKaq 1mKjIpqzb1KWw78GQy07+rIQEGLLNicqT/pNRbMa/eUIrsMrtGW7yiBaG+YxgB/xdlkf QKjg== X-Gm-Message-State: AOAM533azl4DT529YyBy5rMxb2SyoTaryM9tiBAxA4KXVN1Rd6kuP0Pq Iz1tze/kcN3HO6wBqh+RO2Lydb65MsNbvg== X-Received: by 2002:a17:902:aa8b:b0:148:ee33:70fe with SMTP id d11-20020a170902aa8b00b00148ee3370femr18277343plr.38.1643110293972; Tue, 25 Jan 2022 03:31:33 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id n22sm18596296pfu.193.2022.01.25.03.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 03:31:33 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [PATCH 1/2] EFI: Support CAPSULE_FLAGS_INITIATE_RESET for capsule update Date: Tue, 25 Jan 2022 20:31:29 +0900 Message-Id: <164311028928.175897.11020560607087529330.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164311027891.175897.14232281505893559986.stgit@localhost> References: <164311027891.175897.14232281505893559986.stgit@localhost> User-Agent: StGit/0.19 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 Support CAPSULE_FLAGS_INITIATE_RESET for rebooting uboot soon after updating firmware. Note that the machine will reboot soon after applying the capsule file which has CAPSULE_FLAGS_INITIATE_RESET flag. If there are multiple capsules and one has this flag, the machine may reboot while scanning the capsule files. You can control when the machine reboot by renaming the capsule file because the capsule files will be applied alphabetically. Signed-off-by: Masami Hiramatsu --- lib/efi_loader/efi_capsule.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 4463ae00fd..24a2a026a9 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -407,12 +407,20 @@ static efi_status_t efi_capsule_update_firmware( struct efi_firmware_management_protocol *fmp; u16 *abort_reason; efi_status_t ret = EFI_SUCCESS; + bool reset = false; /* sanity check */ if (capsule_data->header_size < sizeof(*capsule) || capsule_data->header_size >= capsule_data->capsule_image_size) return EFI_INVALID_PARAMETER; + if (capsule_data->flags & CAPSULE_FLAGS_INITIATE_RESET) { + /* INITIATE_RESET flag requires PERSIST_ACROSS_RESET flag */ + if (!(capsule_data->flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET)) + return EFI_INVALID_PARAMETER; + reset = true; + } + capsule = (void *)capsule_data + capsule_data->header_size; capsule_size = capsule_data->capsule_image_size - capsule_data->header_size; @@ -498,6 +506,11 @@ static efi_status_t efi_capsule_update_firmware( out: efi_free_pool(handles); + if (ret == EFI_SUCCESS && reset) { + log_debug("This capsule has CAPSULE_FLAGS_INITIATE_RESET. Reboot machine.\n"); + do_reset(NULL, 0, 0, NULL); + } + return ret; } #else From patchwork Tue Jan 25 11:31:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 536484 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp3625417imr; Tue, 25 Jan 2022 03:31:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1AtHJbOzuzgAZr7WzHG2BnCAg7XgWmDcz5yLWIggCgJBVLnE225qE8m4RXW5aDj8gC3V+ X-Received: by 2002:a17:907:62a3:: with SMTP id nd35mr16268192ejc.650.1643110314378; Tue, 25 Jan 2022 03:31:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643110314; cv=none; d=google.com; s=arc-20160816; b=ZniFtGzjjyeMgKmjK79NaZNjvL7kExugpJ9oCBk48GuMK3eHiltzEFMuYG8ABCA/5k mTO03CsFyGhroJCMKJv+8nhpxkd5cINTzz2FFKIl/AMuj4Dp/QobNxzBe90rtPZVYs9A 4LXqwNthZJ0yQFRaCoR1JuPmGX2TZkbT8kXlPHBOtfzQBkd9y5yGpzTJjQlgm3teWSUA mVMXaLLJ9YQN+RGi2mF+KeOt+Fi2LCn5QRDLqoQ1NOUTHbEfLBtx4dyPZ5eKdIH4ERSu Opj+8Q9nswxdxkmGuyoal5asnmAcxXMyvFM8PiMTP2mNyX/UAD+9Q8eNGJXRwW+P/tIc wZ6w== 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:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=8PSNwsqmygvzIPuXCWu+wOIsHFqdY0r8NjQ+TAo6AmI=; b=Hy8SrzKTIHMTB8TeLuOYSiJglrYPLPPoLZnJHVrbT/wTtv9uHBJ4IBHnisnwNljdxZ g/3CA5fqG8PX48OeqepaaF9L6JGvf64kPF1Qu8pESpmUxSmMtkRdMCLWecOLWpr3FM1c S0zJGUxkrAc4mKvP/3IYvrwRb0POtpn7P9xcJDVZ/7l5xANqwmxBbOPsU0btgsNs0fMg vf/eyGL9yCBtwq72F1UoUZkg55SHMttOCtJlZXwOUQ+48uk7NF+wRL7w8vN8atbZP/TT go/WBFhKTeVmMp5Kd8PZIfAFaXHPGYBW4G4IdLpWkSlncT/AlSxaQnSl+SWkxSk/kkSP ZoOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NiigFpsk; 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 z8si9367910ejl.24.2022.01.25.03.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 03:31:54 -0800 (PST) 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=NiigFpsk; 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 91D47837C5; Tue, 25 Jan 2022 12:31:53 +0100 (CET) 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="NiigFpsk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A2880837C4; Tue, 25 Jan 2022 12:31:51 +0100 (CET) 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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (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 74AD4837D2 for ; Tue, 25 Jan 2022 12:31:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pl1-x62a.google.com with SMTP id b15so4422713plg.3 for ; Tue, 25 Jan 2022 03:31:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=8PSNwsqmygvzIPuXCWu+wOIsHFqdY0r8NjQ+TAo6AmI=; b=NiigFpskSRHf8URoK1syjUxJ4ujH+zXYzY1V8lT+9xX73RrMx+9dwZ+MQEG5Zkjyum YcNgS1xFFgYmrDC+68f7XG2WqsOeAuJwW9CIY60cX3dqMda/ut6KJzQvNDCaXW6qqY8I t1VYriLOoZs9QJoXuknYBKGXSfkrkp/+euLt8lsUSWqajQ1JG/Hi8tYqh0Kc5M4u1fY9 TdJMCYhuIqx5cxo5T9lM7XjT6LED1GbsAKctj3UhiBiUHvfocZE62CFmaNj+eMKFoxuo IcDXB5ns2+SyJGtjBef7xywIv2+IkZDENZdOxQMyYpp0iRyW3Sha+h4FGen71bCbfu9F bYFw== 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:user-agent:mime-version:content-transfer-encoding; bh=8PSNwsqmygvzIPuXCWu+wOIsHFqdY0r8NjQ+TAo6AmI=; b=2kaUSayzTZ0OeqISGPsEcDIXTEC4y3ENwf5WmNDU0sdm5KP8yzycxhIy8/1t0g8D37 5cha2GyUNUpKRs/lhO0bwYbP6kcmp44+xM/cpBBzNqV/72+4Fr/x+8Wsqe6rfsDmu44a 4S497mBX5h0Esn4k9D+fsi9musC/9h7l4HDGdjH2GJdieNOfFilNfrbBtpRvWyvl2xv4 lovjBc9Xr2tjrtmHWsd4a5TtxAbbWFug/wRubqy2BKBJL6TRedyD2LVUAhU/lagOMGQx Yw8EiY3uiG3xqIOy9yTmZ5rjc1lYGHnx2O5HnWfbLM1OXlbJd9AQpc13uKmvpeMXFPxY gFxA== X-Gm-Message-State: AOAM533yyCzbB0h7oaIpUghP9Gu6qY3fcyuIc7STr6zbe2jSGQhdtxe/ Hm0xU+IakSSvoJVDco0LI5BLVBYbpvvzRg== X-Received: by 2002:a17:902:cec8:b0:14b:3a22:670a with SMTP id d8-20020a170902cec800b0014b3a22670amr11936695plg.56.1643110304586; Tue, 25 Jan 2022 03:31:44 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id t6sm14863815pgr.90.2022.01.25.03.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 03:31:44 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [PATCH 2/2] mkeficapsule: Support "--flags reset" option Date: Tue, 25 Jan 2022 20:31:39 +0900 Message-Id: <164311029935.175897.10993229897651804648.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164311027891.175897.14232281505893559986.stgit@localhost> References: <164311027891.175897.14232281505893559986.stgit@localhost> User-Agent: StGit/0.19 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 Support "--flags reset" option to set the CAPSULE_FLAGS_INITIATE_RESET flag to capsule header. Signed-off-by: Masami Hiramatsu --- tools/mkeficapsule.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c index 4995ba4e0c..ca3a1c77ad 100644 --- a/tools/mkeficapsule.c +++ b/tools/mkeficapsule.c @@ -44,6 +44,7 @@ static struct option options[] = { {"raw", required_argument, NULL, 'r'}, {"index", required_argument, NULL, 'i'}, {"instance", required_argument, NULL, 'I'}, + {"flags", required_argument, NULL, 'F' }, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}, }; @@ -57,12 +58,13 @@ static void print_usage(void) "\t-r, --raw new raw image file\n" "\t-i, --index update image index\n" "\t-I, --instance update hardware instance\n" + "\t-F, --flags set capsule flags (support only \"reset\")\n" "\t-h, --help print a help message\n", tool_name); } static int create_fwbin(char *path, char *bin, efi_guid_t *guid, - unsigned long index, unsigned long instance) + unsigned long index, unsigned long instance, u32 flags) { struct efi_capsule_header header; struct efi_firmware_management_capsule_header capsule; @@ -101,7 +103,7 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid, header.capsule_guid = efi_guid_fm_capsule; header.header_size = sizeof(header); /* TODO: The current implementation ignores flags */ - header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET; + header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET | flags; header.capsule_image_size = sizeof(header) + sizeof(capsule) + sizeof(u64) + sizeof(image) @@ -171,6 +173,14 @@ err_1: return -1; } +int decode_capsule_flags(const char *flagstr, u32 *flags) +{ + if (strcmp(flagstr, "reset")) + return -EINVAL; + *flags = CAPSULE_FLAGS_INITIATE_RESET; + return 0; +} + /* * Usage: * $ mkeficapsule -f @@ -178,6 +188,7 @@ err_1: int main(int argc, char **argv) { char *file; + u32 flags; efi_guid_t *guid; unsigned long index, instance; int c, idx; @@ -186,8 +197,9 @@ int main(int argc, char **argv) guid = NULL; index = 0; instance = 0; + flags = 0; for (;;) { - c = getopt_long(argc, argv, "f:r:i:I:v:h", options, &idx); + c = getopt_long(argc, argv, "f:r:i:I:v:F:h", options, &idx); if (c == -1) break; @@ -214,6 +226,12 @@ int main(int argc, char **argv) case 'I': instance = strtoul(optarg, NULL, 0); break; + case 'F': + if (decode_capsule_flags(optarg, &flags) < 0) { + printf("Unsupported flags %s\n", optarg); + return -1; + } + break; case 'h': print_usage(); return 0; @@ -232,7 +250,7 @@ int main(int argc, char **argv) exit(EXIT_SUCCESS); } - if (create_fwbin(argv[optind], file, guid, index, instance) + if (create_fwbin(argv[optind], file, guid, index, instance, flags) < 0) { printf("Creating firmware capsule failed\n"); exit(EXIT_FAILURE);