Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1phqIk-0000uV-Lq for mharc-grub-devel@gnu.org; Thu, 30 Mar 2023 07:18:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phqIi-0000u4-Qq for grub-devel@gnu.org; Thu, 30 Mar 2023 07:18:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phqIf-00054K-KW for grub-devel@gnu.org; Thu, 30 Mar 2023 07:18:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680175116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y852UHM7oSTM6ef+yrCtUAGw5ENR/d5UftEGvSaB/k4=; b=KeeaA2VxIi8Co/Pgv+atMXFMVJqhZ8Gh2Uzs4Pw5XyjVzWA/6b64rY+X0Dua+T+Q87CIk1 Fu3G2Y9m5EyxPNw9HJf8GFsVRqOkm7UjLjf4y4BajhEpy2ITxPiOK1wipaaP9IPJyapceh vuYEeq4i+PnR9iraoyAq+KzH1AovBWA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-447-tjWpIm7wOZimvm7O1x5FeA-1; Thu, 30 Mar 2023 07:18:35 -0400 X-MC-Unique: tjWpIm7wOZimvm7O1x5FeA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 91F5B80C8C4; Thu, 30 Mar 2023 11:18:34 +0000 (UTC) Received: from osteffen-laptop.redhat.com (unknown [10.39.195.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2FB92166B33; Thu, 30 Mar 2023 11:18:32 +0000 (UTC) From: Oliver Steffen To: grub-devel@gnu.org Cc: Daniel Kiper , Gerd Hoffmann , Javier Martinez Canillas , Glenn Washburn , Oliver Steffen , Daniel Kiper Subject: [PATCH v5 1/8] efi: Add grub_efi_set_variable_with_attributes Date: Thu, 30 Mar 2023 13:18:06 +0200 Message-Id: <20230330111813.480628-2-osteffen@redhat.com> In-Reply-To: <20230330111813.480628-1-osteffen@redhat.com> References: <20230330111813.480628-1-osteffen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Received-SPF: pass client-ip=170.10.129.124; envelope-from=osteffen@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Mar 2023 11:18:41 -0000 Add a function to the EFI module that allows setting EFI variables with specific attributes. This is useful for marking variables as volatile, for example. Signed-off-by: Oliver Steffen Reviewed-by: Daniel Kiper --- grub-core/kern/efi/efi.c | 19 +++++++++++++------ include/grub/efi/efi.h | 6 ++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index cf49d6357..03abf5531 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -201,8 +201,8 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size, } grub_err_t -grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, - void *data, grub_size_t datasize) +grub_efi_set_variable_with_attributes (const char *var, const grub_efi_guid_t *guid, + void *data, grub_size_t datasize, grub_efi_uint32_t attributes) { grub_efi_status_t status; grub_efi_runtime_services_t *r; @@ -219,10 +219,7 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, r = grub_efi_system_table->runtime_services; - status = efi_call_5 (r->set_variable, var16, guid, - (GRUB_EFI_VARIABLE_NON_VOLATILE - | GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS - | GRUB_EFI_VARIABLE_RUNTIME_ACCESS), + status = efi_call_5 (r->set_variable, var16, guid, attributes, datasize, data); grub_free (var16); if (status == GRUB_EFI_SUCCESS) @@ -231,6 +228,16 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, return grub_error (GRUB_ERR_IO, "could not set EFI variable `%s'", var); } +grub_err_t +grub_efi_set_variable (const char *var, const grub_efi_guid_t *guid, + void *data, grub_size_t datasize) +{ + return grub_efi_set_variable_with_attributes (var, guid, data, datasize, + GRUB_EFI_VARIABLE_NON_VOLATILE + | GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS + | GRUB_EFI_VARIABLE_RUNTIME_ACCESS); +} + grub_efi_status_t grub_efi_get_variable_with_attributes (const char *var, const grub_efi_guid_t *guid, diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index 444bf5b0b..339989c53 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -98,6 +98,12 @@ grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable) (const char *variable, grub_size_t *datasize_out, void **data_out); grub_err_t +EXPORT_FUNC (grub_efi_set_variable_with_attributes) (const char *var, + const grub_efi_guid_t *guid, + void *data, + grub_size_t datasize, + grub_efi_uint32_t attributes); +grub_err_t EXPORT_FUNC (grub_efi_set_variable) (const char *var, const grub_efi_guid_t *guid, void *data, -- 2.39.2