From patchwork Wed Apr 17 10:19:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 789310 Delivered-To: patch@linaro.org Received: by 2002:a5d:4dc5:0:b0:346:15ad:a2a with SMTP id f5csp204575wru; Wed, 17 Apr 2024 03:20:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWEohNN2Vrq/fOufrazv4nQyD2AZ5th32dUqBw8v4VGA3iOCUiV1NPohY65TOAP0LjtJlxnxQ3xdEgaXG/rrApS X-Google-Smtp-Source: AGHT+IGro7ezhLPNzKXD1vl4sudYYovctna++a0VvWRO9XoR+b1ua37IzRzYsFRpnpq2AdVS53se X-Received: by 2002:a17:907:724b:b0:a52:5a04:fb0d with SMTP id ds11-20020a170907724b00b00a525a04fb0dmr6960418ejc.3.1713349201252; Wed, 17 Apr 2024 03:20:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713349201; cv=none; d=google.com; s=arc-20160816; b=um2K9817llSknnxrsYorhwrv6dMYRk0/AskmAomA5PoE+qEsxsnoDVBHZ22eiWtCvw iCdyzZF6w2Bdo2nCpzmAqE+Ob47k+fo1wiwDORpA1jBNgYENXXwwezhBlAYkEs/IN7U+ mjl0mNE9ahrym4leQg9nV9zgcUmiL8wH69acrdv/Lb/GTQhVuJrVWkGfHt9ZEnGm7Q76 4KnbtmCJJ4s3qkazuYuaftS8GiqGzwKsZap5+Wb5FF4PY6g3ii++h52JrDe6SVSah85+ xObwC3zgZWHZKrjnVPTXY4SS3FaegjjyaF/QoUTD1ob1mTd6rekLLOT5x6xZetWpjkxg 5gZA== 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=chYdKJSIqCPZ5ji7MNGV72oV6gQgjYtrYtQPdRJyYPA=; fh=ur5iMzZiWL/zwG/0DDxl8+DIdxvyRZrdgA7yGJ2rS8Q=; b=sgDnHJklwZjsvvbXZV/5MlZQ6otW95syb3Rsz0TjFL1awAqAGIR9mbuMJHPRkwHpNW gyi3bB/XPEp8C6I3qhSsOUHDi1zEFqC+GXrBW6Ix2ifTH/0gRtE0fnehCq/INqwiymDS Ghp+b8cVAY2cK5pwTxAaL67MZmxWvHwDw31gEJEoo6QLSgcVX3BcNLGtueZw0a+Pi9XP h1/89QRXON+zUVpGWT0sKlMe8FjEORaQUouoot1F1qUhYqnwKCcL5sLGtrfh6Nvi+Kar idLY5Ijr2PTHtYbGoSF3HDmmpznfnae/NJBoNvPAqEO9q7jsX+e12uEvY5fPu0Huv3Wm kroQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oJ3qbwHK; 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 ka8-20020a170907990800b00a525ea63c7dsi3600967ejc.779.2024.04.17.03.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 03:20:01 -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=oJ3qbwHK; 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 2F0E788464; Wed, 17 Apr 2024 12:19:51 +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="oJ3qbwHK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7EC6D88461; Wed, 17 Apr 2024 12:19:49 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (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 9866E8842A for ; Wed, 17 Apr 2024 12:19: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=ilias.apalodimas@linaro.org Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-418ce99e7fcso134095e9.1 for ; Wed, 17 Apr 2024 03:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713349185; x=1713953985; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=chYdKJSIqCPZ5ji7MNGV72oV6gQgjYtrYtQPdRJyYPA=; b=oJ3qbwHKMyrpHFlnadXV+mO+7vQDx+vsNiuIIJ2GOMHobjklN1YK4aHIdyKJSq+xXy kUjahyANZebAe+wbJ6YI5li5RTGXM3PMvUFieVh9YHT4rW/7iPOmFmPnNVzBMS5nDLJo nKivdBvXU8E9j4etBJU9vnzSL4/RTjB7UitOT1DNfxEW8WAR2s/TsKhYsTkURxeYgA/8 8TvaJtdOje19YDNN4VdVE/nXfgm7L2sww/OKWys5HBDdeyzxf4Eg6jOSWfv1FXJVQglT 7p6uRN/UYLpTugpTVwrJeHJB592bQEWgxiiffrPNKI5To/AJksN0LzU3YmFOX6HlswAt 5PSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713349185; x=1713953985; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=chYdKJSIqCPZ5ji7MNGV72oV6gQgjYtrYtQPdRJyYPA=; b=d+VgpUAdZMlVBQdqcOy9K826OYGgNC8h/GZ9x6HNtGtnajRanzm1P9CgCTYKo39keH CaIGcly4Lc/YyHj6PKz65PoOX/XKhYNwmML7pRaS2BHk9GzN5MOLYFp5NWCz7+8HerbK 7Hgb7N1Xn24yc83wcIhPbIKnBysnz4eX/JSovfgBaOBnXpKYJ/PNYmpfuFuu22y5gOm2 p5vPN3WwO0uJa8iLw0uCxB9yAMB/6uWZIms/u8aI9Bvzgy9ZfrKH47eJw+LtiAk13jIL lx54mGE6AIumFKe3azaVGNyXp1mDY/ucIAW0A4cUgCDXkj7WGgldYG9VlF+RVL3w+mSt 1z2g== X-Forwarded-Encrypted: i=1; AJvYcCWZ0wk+xxQFvx7l2SWWzew9gj2Xc0JLopYzPam30AYB45wuv0n4zwygXFYth6hP6TmGBQHfguNB8aRZixKlUZVeQRSvrw== X-Gm-Message-State: AOJu0YwtZQY2f+YA5i0b1X0EgBlSbZ4Dx4jJEzh6hWZkmAlwyF4XWxBF +uiGzL81AyBsbJan5CkAI5cJKQkDULFmpOOBwUGKwjVrhQ7HB42PYNHn+dMdgfY= X-Received: by 2002:a05:6000:1ace:b0:346:251a:396d with SMTP id i14-20020a0560001ace00b00346251a396dmr13149525wry.51.1713349184914; Wed, 17 Apr 2024 03:19:44 -0700 (PDT) Received: from hades.. (ppp089210071137.access.hol.gr. [89.210.71.137]) by smtp.gmail.com with ESMTPSA id g12-20020a5d488c000000b003472489d26fsm13567780wrq.19.2024.04.17.03.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 03:19:44 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de, kettenis@openbsd.org Cc: caleb.connolly@linaro.org, sumit.garg@linaro.org, quic_llindhol@quicinc.com, ardb@kernel.org, pbrobinson@gmail.com, pjones@redhat.com, Ilias Apalodimas , Tom Rini , Masahisa Kojima , AKASHI Takahiro , Raymond Mao , Simon Glass , Janne Grunau , Matthias Schiffer , Abdellatif El Khlifi , Alper Nebi Yasak , Sughosh Ganu , Richard Henderson , Sam Edwards , Weizhao Ouyang , u-boot@lists.denx.de Subject: [PATCH v2 2/4] efi_loader: Add OS notifications for SetVariable at runtime Date: Wed, 17 Apr 2024 13:19:23 +0300 Message-Id: <20240417101928.119115-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240417101928.119115-1-ilias.apalodimas@linaro.org> References: <20240417101928.119115-1-ilias.apalodimas@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.8 at phobos.denx.de X-Virus-Status: Clean Previous patches enable SetVariable at runtime using a volatile storage backend using EFI_RUNTIME_SERVICES_DATA allocared memory. Since there's no recommendation from the spec on how to notify the OS, add a volatile EFI variable that contains the filename relative to the ESP. OS'es can use that file and update it at runtime $~ efivar -p -n b2ac5fc9-92b7-4acd-aeac-11e818c3130c-RTStorageVolatile GUID: b2ac5fc9-92b7-4acd-aeac-11e818c3130c Name: "RTStorageVolatile" Attributes: Boot Service Access Runtime Service Access Value: 00000000 75 62 6f 6f 74 65 66 69 2e 76 61 72 00 |ubootefi.var. | Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- include/efi_loader.h | 4 ++++ lib/efi_loader/efi_runtime.c | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index bb51c0281774..69442f4e58de 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -159,6 +159,10 @@ static inline void efi_set_bootdev(const char *dev, const char *devnr, #define EFICONFIG_AUTO_GENERATED_ENTRY_GUID \ EFI_GUID(0x8108ac4e, 0x9f11, 0x4d59, \ 0x85, 0x0e, 0xe2, 0x1a, 0x52, 0x2c, 0x59, 0xb2) +#define U_BOOT_EFI_RT_VAR_FILE_GUID \ + EFI_GUID(0xb2ac5fc9, 0x92b7, 0x4acd, \ + 0xae, 0xac, 0x11, 0xe8, 0x18, 0xc3, 0x13, 0x0c) + /* Use internal device tree when starting UEFI application */ #define EFI_FDT_USE_INTERNAL NULL diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index dde083b09665..c8f7a88ba8db 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -110,6 +111,7 @@ static __efi_runtime_data efi_uintn_t efi_descriptor_size; */ efi_status_t efi_init_runtime_supported(void) { + const efi_guid_t efi_guid_efi_rt_var_file = U_BOOT_EFI_RT_VAR_FILE_GUID; efi_status_t ret; struct efi_rt_properties_table *rt_table; @@ -127,9 +129,20 @@ efi_status_t efi_init_runtime_supported(void) EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP | EFI_RT_SUPPORTED_CONVERT_POINTER; - if (IS_ENABLED(CONFIG_EFI_RT_VOLATILE_STORE)) - rt_table->runtime_services_supported |= - EFI_RT_SUPPORTED_SET_VARIABLE; + if (IS_ENABLED(CONFIG_EFI_RT_VOLATILE_STORE)) { + ret = efi_set_variable_int(u"RTStorageVolatile", + &efi_guid_efi_rt_var_file, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_READ_ONLY, + sizeof(EFI_VAR_FILE_NAME), + EFI_VAR_FILE_NAME, false); + if (ret != EFI_SUCCESS) { + log_err("Failed to set RTStorageVolatile\n"); + return ret; + } + rt_table->runtime_services_supported |= EFI_RT_SUPPORTED_SET_VARIABLE; + } /* * This value must be synced with efi_runtime_detach_list