From patchwork Fri Aug 10 17:29:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 956359 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41nBwB50psz9s4Z for ; Sat, 11 Aug 2018 03:30:18 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="O3c5ykI+"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41nBwB3LxtzF0PT for ; Sat, 11 Aug 2018 03:30:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="O3c5ykI+"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="O3c5ykI+"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41nBv32lqYzDrpW for ; Sat, 11 Aug 2018 03:29:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gXRhPOkI6/ml4S/bU2LugCWrqnByRy5FpNCQOY8+J4o=; b=O3c5ykI+ovMBGtXxbLj/aNomQ gGE1mdeSrTDHU244mX/lfh12MCtMh/oDruH2F4LYnXwN2rZOBI7jYopERuiSWDUCF9ivE6YFk0VrI y4eUQNzllAWmYDMKpmb/X5ACAah0UsCEWtJ5ehGPCFRoZMhQy50u0dgUyCxBNTx3vcgp4l5Ujs8bO U1x6Ld4vHbXOc3Gpa7L69aOj4p+cChZ/djP+ha9iJD319bRg0H2aqZOfdb2sLiblGRgwxq0cHiQ9A ro6pA22KdAo0ESNcv9RdPoDFwwPF1Y/lvm8rpI0wKzDmedtyx1wXD+jIWxZiKG1m4yFQW8bkyA7po Kviju5xsQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1foBDu-0002Q3-HS; Fri, 10 Aug 2018 17:29:14 +0000 Message-Id: <14e587d6127aad17d1951156c2fff625e1177ccd.1533921283.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Fri, 10 Aug 2018 10:00:12 -0700 Subject: [PATCH v1 1/6] lib/efi: Add EFI_DEFALT_ATTRIBUTES macro To: Samuel Mendoza-Jonas Date: Fri, 10 Aug 2018 17:29:14 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" For convenience, add a new efi data attributes macro EFI_DEFALT_ATTRIBUTES. Signed-off-by: Geoff Levand --- discover/platform-arm64.c | 5 +---- lib/efi/efivar.h | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/discover/platform-arm64.c b/discover/platform-arm64.c index a70298a..0eb2579 100644 --- a/discover/platform-arm64.c +++ b/discover/platform-arm64.c @@ -70,10 +70,7 @@ static void write_nvram(const struct param_list *pl) struct efi_data efi_data; struct param *param; - efi_data.attributes = - EFI_VARIABLE_NON_VOLATILE | - EFI_VARIABLE_RUNTIME_ACCESS | - EFI_VARIABLE_BOOTSERVICE_ACCESS; + efi_data.attributes = EFI_DEFALT_ATTRIBUTES; param_list_for_each(pl, param) { if (!param->modified) diff --git a/lib/efi/efivar.h b/lib/efi/efivar.h index 0d44100..48edd17 100644 --- a/lib/efi/efivar.h +++ b/lib/efi/efivar.h @@ -30,6 +30,12 @@ #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020 #define EFI_VARIABLE_APPEND_WRITE 0x00000040 +#define EFI_DEFALT_ATTRIBUTES ( \ + EFI_VARIABLE_NON_VOLATILE | \ + EFI_VARIABLE_RUNTIME_ACCESS | \ + EFI_VARIABLE_BOOTSERVICE_ACCESS \ +) + #ifndef EFIVARFS_MAGIC #define EFIVARFS_MAGIC 0xde5e81e4 #endif From patchwork Fri Aug 10 17:29:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 956353 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41nBvG1YPMz9s5b for ; Sat, 11 Aug 2018 03:29:30 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="z8xcSRWn"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41nBvF6ZkXzF0PV for ; Sat, 11 Aug 2018 03:29:29 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="z8xcSRWn"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="z8xcSRWn"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41nBv3284szDrZC for ; Sat, 11 Aug 2018 03:29:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2qQzilk9jYgYUpQtmRVEWLjNuZEllxsRMcrayrBArkg=; b=z8xcSRWn3X6fXqYGay0u4rrim sor0eCFcga8nApjEaftjjCq1V9/p40n9o0XNF46biQpJ7ZFKiTC9w+Wkkkt+as1bhNfV/hlj6g7t2 SFyiulhrHnZd5IT1TiLYsjwHtzEZ47CTXwlWbVgsvsr4koByrqjb6VZnn0VvSZGhjeSPqysJYt6XH fSnZdEZ5e3ggrQ+fZ6x+Qd3Mqqpha0aCB11+TJ7B9NT71Nq1CwhlO+Zo9IBLzcYbi/ocoXZ7uKEpd Jyh6/Wjo/LFtYAmV4JQb22eau2ao3sQg1SPHYsNFlDg5FIRsjtLAUcpVY9Oy5YSxlm3KwG51r1ed1 N55TCSHIA==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1foBDu-0002Q7-Mq; Fri, 10 Aug 2018 17:29:14 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Fri, 10 Aug 2018 10:00:12 -0700 Subject: [PATCH v1 2/6] lib/efi: Log operations to debug log To: Samuel Mendoza-Jonas Date: Fri, 10 Aug 2018 17:29:14 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Signed-off-by: Geoff Levand --- lib/efi/efivar.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/efi/efivar.c b/lib/efi/efivar.c index 91b2507..a0c21b5 100644 --- a/lib/efi/efivar.c +++ b/lib/efi/efivar.c @@ -109,6 +109,7 @@ delete: pb_log_fn("unlink failed: (%d) %s\n", errno, strerror(errno)); goto exit; } + pb_debug_fn("Deleted: '%s'\n", name); exit: talloc_free(path); close(fd); @@ -159,6 +160,7 @@ int efi_get_variable(void *ctx, const char *guidstr, const char *name, (*efi_data)->data_size = total; (*efi_data)->data = (*efi_data)->fill; memcpy((*efi_data)->data, buf + sizeof (uint32_t), total); + pb_debug_fn("Found: '%s'='%s'\n", name, (const char *)(*efi_data)->data); rc = 0; exit: @@ -199,6 +201,7 @@ int efi_set_variable(const char *guidstr, const char *name, goto exit; } rc = 0; + pb_debug_fn("Set: '%s'='%s'\n", name, (const char *)efi_data->data); exit: talloc_free(path); From patchwork Fri Aug 10 17:29:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 956357 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41nBvv0Xyrz9s4Z for ; Sat, 11 Aug 2018 03:30:03 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="fyQffaHp"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41nBvt67lbzDrtm for ; Sat, 11 Aug 2018 03:30:02 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="fyQffaHp"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="fyQffaHp"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41nBv32Zy2zDrbj for ; Sat, 11 Aug 2018 03:29:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gFXRB34LJqFVBSDTLfx1Tn8Beh0ZQcN+v9BmKrfuvv0=; b=fyQffaHpSWiykgfEYus/D0n9u ARCRkDxKlvCRQtffdXqclLxpOicH2c9X1Q04Y9tFA06QzXThbRWcgKmkckkHnJAgfMofXCrWRpj6p cstkeN40eCfny3RmpXcgWprpK4E52XlqtRoOMhbwNDHE2IXf9DveTxkh1gjxhMWBC1Hn8kF4lNLAa ycf6zBzff0rOPyiZncWkMco3hkHvGGAmwyCRodLB2ZmGEVYZRSBXhMDMGWzHQMxmCfOoaxRizRQO/ Z+aoUs51kw2QTRdiCQA/M2woB1MjkJ4WQxNVdF1RacBSn6xn0GLNWY/kSGP2AbFZN5i9Xs94XCrKH KujAerMVQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1foBDu-0002QB-SC; Fri, 10 Aug 2018 17:29:14 +0000 Message-Id: <8621ff34ed74ca46f2df9d20d8df3dc6d2198f0f.1533921283.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Fri, 10 Aug 2018 10:00:12 -0700 Subject: [PATCH v1 3/6] lib/efi: Add new struct efi_mount To: Samuel Mendoza-Jonas Date: Fri, 10 Aug 2018 17:29:14 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" To make it easier to manage EFI variables add a new struct efi_mount that holds the path to the EFI file system mount and the EFI variable name GUID. Update the lib/efi routines to use struct efi_mount. Add a new routine efi_check_mount based on the checks done in platform-arm64. This change to using struct efi_mount removes the static variable efivarfs_path making the lib/efi routines stateless. Signed-off-by: Geoff Levand --- lib/efi/efivar.c | 90 ++++++++++++++++++++++++++++++++++++++++---------------- lib/efi/efivar.h | 28 +++++++++++++----- 2 files changed, 85 insertions(+), 33 deletions(-) diff --git a/lib/efi/efivar.c b/lib/efi/efivar.c index a0c21b5..f1dd002 100644 --- a/lib/efi/efivar.c +++ b/lib/efi/efivar.c @@ -17,6 +17,7 @@ * Author: Ge Song */ +#include #include #include #include @@ -25,35 +26,68 @@ #include #include #include +#include #include "efivar.h" #include "log/log.h" #include "talloc/talloc.h" -static const char *efivarfs_path; - -inline void set_efivarfs_path(const char *path) +void efi_init_mount(struct efi_mount *efi_mount, const char *path, + const char *guid) { - efivarfs_path = path; + assert(efi_mount); + + efi_mount->path = path; + efi_mount->guid = guid; + + pb_debug_fn("%s--%s", efi_mount->path, efi_mount->guid); } -inline const char *get_efivarfs_path(void) +bool efi_check_mount_magic(const struct efi_mount *efi_mount, bool check_magic) { + struct statfs s; - return efivarfs_path; + assert(efi_mount); + + if (!efi_mount->guid) { + pb_debug_fn("guid not set\n"); + return false; + } + + if (access(efi_mount->path, R_OK | W_OK)) { + pb_debug_fn("Can't access %s\n", efi_mount->path); + return false; + } + + memset(&s, '\0', sizeof(s)); + if (statfs(efi_mount->path, &s)) { + pb_debug_fn("statfs failed: %s: (%d) %s\n", efi_mount->path, + errno, strerror(errno)); + return false; + } + + if (check_magic && s.f_type != EFIVARFS_MAGIC) { + pb_debug_fn("Bad magic = 0x%lx\n", (unsigned long)s.f_type); + return false; + } + + return true; } -static int efi_open(const char *name, const char *guidstr, int flags, - mode_t mode, char **path) +static int efi_open(const struct efi_mount *efi_mount, const char *name, + int flags, mode_t mode, char **path) { int fd; + assert(efi_mount); + *path = NULL; - if (!get_efivarfs_path()) + if (!efi_mount->path || !efi_mount->guid) return -1; - *path = talloc_asprintf(NULL, "%s%s-%s", get_efivarfs_path(), name, guidstr); + *path = talloc_asprintf(NULL, "%s/%s-%s", efi_mount->path, name, + efi_mount->guid); if (!*path) return -1; @@ -62,8 +96,8 @@ static int efi_open(const char *name, const char *guidstr, int flags, fd = open(*path, flags, mode); if (fd < 0) { - pb_log("%s: open failed %s: %s\n", __func__, *path, - strerror(errno)); + pb_log("%s: open failed '%s': (%d) %s\n", __func__, *path, + errno, strerror(errno)); talloc_free(*path); *path = NULL; return -1; @@ -72,20 +106,22 @@ static int efi_open(const char *name, const char *guidstr, int flags, return fd; } -int efi_del_variable(const char *guidstr, const char *name) +int efi_del_variable(const struct efi_mount *efi_mount, const char *name) { int fd, flag; int rc = -1; char *path; - fd = efi_open(name, guidstr, 0, 0, &path); + assert(efi_mount); + + fd = efi_open(efi_mount, name, 0, 0, &path); if (fd < 0) return -1; rc = ioctl(fd, FS_IOC_GETFLAGS, &flag); if (rc == -1 && errno == ENOTTY) { pb_debug_fn("'%s' does not support ioctl_iflags.\n", - efivarfs_path); + efi_mount->path); goto delete; } else if (rc == -1) { pb_log_fn("FS_IOC_GETFLAGS failed: (%d) %s\n", errno, @@ -116,8 +152,8 @@ exit: return rc; } -int efi_get_variable(void *ctx, const char *guidstr, const char *name, - struct efi_data **efi_data) +int efi_get_variable(void *ctx, const struct efi_mount *efi_mount, + const char *name, struct efi_data **efi_data) { int fd; int rc = -1; @@ -127,9 +163,11 @@ int efi_get_variable(void *ctx, const char *guidstr, const char *name, ssize_t count; char *path; + assert(efi_mount); + *efi_data = NULL; - fd = efi_open(name, guidstr, 0, 0, &path); + fd = efi_open(efi_mount, name, 0, 0, &path); if (fd < 0) return -1; @@ -139,8 +177,8 @@ int efi_get_variable(void *ctx, const char *guidstr, const char *name, if (errno == EAGAIN || errno == EWOULDBLOCK) continue; - pb_log("%s: read failed %s: (%ld) %s\n", __func__, path, - count, strerror(errno)); + pb_log("%s: read failed %s: (%ld) (%d) %s\n", __func__, path, + count, errno, strerror(errno)); goto exit; } if (p >= (buf + sizeof(buf))) { @@ -169,7 +207,7 @@ exit: return rc; } -int efi_set_variable(const char *guidstr, const char *name, +int efi_set_variable(const struct efi_mount *efi_mount, const char *name, const struct efi_data *efi_data) { int rc = -1; @@ -179,9 +217,11 @@ int efi_set_variable(const char *guidstr, const char *name, size_t bufsize; char *path; - efi_del_variable(guidstr, name); + assert(efi_mount); + + efi_del_variable(efi_mount, name); - fd = efi_open(name, guidstr, O_CREAT | O_WRONLY, + fd = efi_open(efi_mount, name, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, &path); if (fd < 0) return -1; @@ -196,8 +236,8 @@ int efi_set_variable(const char *guidstr, const char *name, count = write(fd, buf, bufsize); if ((size_t)count != bufsize) { - pb_log("%s: write failed %s: (%ld) %s\n", __func__, name, - count, strerror(errno)); + pb_log("%s: write failed %s: (%ld) (%d) %s\n", __func__, name, + count, errno, strerror(errno)); goto exit; } rc = 0; diff --git a/lib/efi/efivar.h b/lib/efi/efivar.h index 48edd17..b74ab64 100644 --- a/lib/efi/efivar.h +++ b/lib/efi/efivar.h @@ -19,9 +19,11 @@ #ifndef EFIVAR_H #define EFIVAR_H -#include +#include #include +#include + #define EFI_VARIABLE_NON_VOLATILE 0x00000001 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002 #define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004 @@ -47,13 +49,23 @@ struct efi_data { uint8_t fill[0]; }; -void set_efivarfs_path(const char *path); -const char *get_efivarfs_path(void); +struct efi_mount { + const char *path; + const char *guid; +}; + +void efi_init_mount(struct efi_mount *efi_mount, const char *path, + const char *guid); +bool efi_check_mount_magic(const struct efi_mount *efi_mount, bool check_magic); +static inline bool efi_check_mount(const struct efi_mount *efi_mount) +{ + return efi_check_mount_magic(efi_mount, true); +} -int efi_get_variable(void *ctx, const char *guidstr, const char *name, - struct efi_data **efi_data); -int efi_set_variable(const char *guidstr, const char *name, - const struct efi_data *efi_data); -int efi_del_variable(const char *guidstr, const char *name); +int efi_get_variable(void *ctx, const struct efi_mount *efi_mount, + const char *name, struct efi_data **efi_data); +int efi_set_variable(const struct efi_mount *efi_mount, const char *name, + const struct efi_data *efi_data); +int efi_del_variable(const struct efi_mount *efi_mount, const char *name); #endif /* EFIVAR_H */ From patchwork Fri Aug 10 17:29:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 956355 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41nBvZ6hMTz9s4Z for ; Sat, 11 Aug 2018 03:29:46 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Vh4AtSfK"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41nBvZ58NzzF0WS for ; Sat, 11 Aug 2018 03:29:46 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Vh4AtSfK"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Vh4AtSfK"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41nBv3203kzDqww for ; Sat, 11 Aug 2018 03:29:18 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=QWXPVO1ISsyCt+PF1U9rJPut9TiCGxIRpEtbxiH9IoY=; b=Vh4AtSfKP8azZh86EDnAehshc 7PqSjJ1Ixoz09G/ct9FOxwv9SLWZPXPbed5Y3NKL44fXQQT6/UAI5UNV3DLJUJTczOGbD8MKU6k05 mlKsxoz8C3hnhIWyQJZ7jd5Ldn654j7+UCHRAJl66ZAUJeRQtesw3qu5njpq3Pmb4AKNTw4vRpSwD TPg3YH0JgkT63SJaboygFPcu2BnA1q7xSrLNwno8TtWJyiM4YcefikhSQrLSfvuI47MnqKFZKNtvj yjufcpQD+ulhTbMmgD4ZAje742HOO116oPttFNJusOXnXKlP9DDonHBoy8b1qfmb8+4NhibAOrmML sea5tZYoQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1foBDv-0002QF-1B; Fri, 10 Aug 2018 17:29:15 +0000 Message-Id: <0d5aac413ac04b15b64dee5ce4ad5490bc9d91e7.1533921283.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Fri, 10 Aug 2018 10:00:12 -0700 Subject: [PATCH v1 4/6] lib/efi: Move magic to implementation To: Samuel Mendoza-Jonas Date: Fri, 10 Aug 2018 17:29:15 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" efi_check_mount now does a magic number check by default, so move the magic number related code from efivar.h to efivar.c. Signed-off-by: Geoff Levand --- lib/efi/efivar.c | 5 +++++ lib/efi/efivar.h | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/efi/efivar.c b/lib/efi/efivar.c index f1dd002..37bb6d9 100644 --- a/lib/efi/efivar.c +++ b/lib/efi/efivar.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -32,6 +33,10 @@ #include "log/log.h" #include "talloc/talloc.h" +#ifndef EFIVARFS_MAGIC +#define EFIVARFS_MAGIC 0xde5e81e4 +#endif + void efi_init_mount(struct efi_mount *efi_mount, const char *path, const char *guid) { diff --git a/lib/efi/efivar.h b/lib/efi/efivar.h index b74ab64..9307d6c 100644 --- a/lib/efi/efivar.h +++ b/lib/efi/efivar.h @@ -22,8 +22,6 @@ #include #include -#include - #define EFI_VARIABLE_NON_VOLATILE 0x00000001 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002 #define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004 @@ -38,10 +36,6 @@ EFI_VARIABLE_BOOTSERVICE_ACCESS \ ) -#ifndef EFIVARFS_MAGIC -#define EFIVARFS_MAGIC 0xde5e81e4 -#endif - struct efi_data { uint32_t attributes; size_t data_size; From patchwork Fri Aug 10 17:29:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 956354 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41nBvQ2R9Qz9s4Z for ; Sat, 11 Aug 2018 03:29:38 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="SavxZmga"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41nBvQ11w3zF0bZ for ; Sat, 11 Aug 2018 03:29:38 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="SavxZmga"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="SavxZmga"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41nBv324fqzDrYj for ; Sat, 11 Aug 2018 03:29:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=WGab+l2oY088n8OzDbk78aieXbgvBxp8LfbPqeuyN0U=; b=SavxZmganp4yseNXGRphaRA/a yb1QH33/6Y86n/02Z+whIXLPWOzkG4NcyXwW++kQyz4E8JTmoftSVT1X9ISODTqmfTQBhy5XSZFaP xgW7d+7iwwB2l99rQYwJpN5pU9fjZNrJycnduT/kyTYmeHyTGT87gysYI2g/WEKPHXg/ahoi2XrFC yKQxzyF4BeY8tm9CKPO3huOFRrHJhSsT6jgY+DtCRSzhmLPX1p86QeFECgQRZOUBFulPuCIfh2d7y PEzDJfINONOCm4yZ9dVDUIMTtJlPUGA0Ghednwm4iO8ci6sU1Fo71Tog/J0JDBNKjNBi7oz8uUp/Q hKDN/fFqg==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1foBDv-0002QJ-6h; Fri, 10 Aug 2018 17:29:15 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Fri, 10 Aug 2018 10:00:12 -0700 Subject: [PATCH v1 5/6] test/efivar: Rework for efi_mount To: Samuel Mendoza-Jonas Date: Fri, 10 Aug 2018 17:29:15 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" --- test/lib/test-efivar.c | 128 +++++++++++++++++++------------------------------ 1 file changed, 49 insertions(+), 79 deletions(-) diff --git a/test/lib/test-efivar.c b/test/lib/test-efivar.c index a85b73c..1be95fd 100644 --- a/test/lib/test-efivar.c +++ b/test/lib/test-efivar.c @@ -16,117 +16,87 @@ * reserved. * Author: Ge Song */ + #include -#include #include -#include -#include #include #include #include #include + #include #include -#include +#include #include "efi/efivar.h" +#include "log/log.h" #include "talloc/talloc.h" -#define DEF_ATTR (EFI_VARIABLE_NON_VOLATILE | \ - EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS) - -static const char *test_efivar_guid = "c9c07add-256e-4452-b911-f8d0d35a1ac7"; -static const char *test_varname = "efivartest"; -static const char *test_data = "petitboot"; +static const struct efi_mount efi_mount = { + .path = "/tmp/pb-test-efivar", + .guid = "c9c07add-256e-4452-b911-f8d0d35a1ac7", +}; +static const char v_name[] = "petitboot-test-one"; +static const char v_data[] = "petitboot-efi-tester"; -static char* find_efitest_path(void) +void finish(int code) { - static char dir[PATH_MAX] = {0}; - static bool run = false; - char *rest_path = "/efivarfs_data/"; - char *pos = NULL; - - if (run) - return dir; - - readlink("/proc/self/exe", dir, PATH_MAX); - - pos = strrchr(dir, '/'); - *pos = '\0'; - - strcat(dir, rest_path); - run = true; - - return dir; + efi_del_variable(&efi_mount, v_name); + rmdir(efi_mount.path); + exit(code); } -static bool probe(void) +int main(void) { - char *path; + struct efi_data *efi_data; int rc; - path = find_efitest_path(); + __pb_log_init(stderr, true); - rc = access(path, F_OK); + rc = mkdir(efi_mount.path, 0755); if (rc) { - if (errno == ENOENT) { - rc = mkdir(path, 0755); - if(rc) - return false; - } else { - return false; + if (errno == EEXIST) + pb_log("mkdir exists\n"); + else { + pb_log("mkdir failed: (%d) %s\n", errno, + strerror(errno)); + finish(__LINE__); } } - set_efivarfs_path(path); + if (!efi_check_mount_magic(&efi_mount, false)) + finish(__LINE__); - return true; -} + efi_data = talloc_zero(NULL, struct efi_data); + efi_data->attributes = EFI_DEFALT_ATTRIBUTES; + efi_data->data = talloc_strdup(efi_data, v_data); + efi_data->data_size = sizeof(v_data); -int main(void) -{ - void *ctx = NULL; - int rc, errno_value; - uint32_t attr = DEF_ATTR; - char *path = NULL; - struct efi_data *efi_data; - - if(!probe()) - return ENOENT; - - talloc_new(ctx); - - efi_data = talloc_zero(ctx, struct efi_data); - efi_data->attributes = attr; - efi_data->data = talloc_strdup(efi_data, test_data); - efi_data->data_size = strlen(test_data) + 1; - - rc = efi_set_variable(test_efivar_guid, test_varname, - efi_data); + if (efi_set_variable(&efi_mount, v_name, efi_data)) + finish(__LINE__); talloc_free(efi_data); - rc = efi_get_variable(ctx, test_efivar_guid, test_varname, - &efi_data); - assert(efi_data->data != NULL); - rc = strcmp((char *)efi_data->data, test_data); - if (rc) { - talloc_free(ctx); - assert(0); - } - - rc = efi_del_variable(test_efivar_guid, test_varname); + if (efi_get_variable(NULL, &efi_mount, v_name, &efi_data)) + finish(__LINE__); - rc = efi_get_variable(ctx, test_efivar_guid, test_varname, - &efi_data); + if (!efi_data->data) { + pb_log("No efi_data->data\n"); + finish(__LINE__); + } - errno_value = errno; - talloc_free(ctx); + if (strcmp((char *)efi_data->data, v_data)) { + pb_log("Bad efi_data->data: '%s' != '%s'\n", + (char *)efi_data->data, v_data); + finish(__LINE__); + } - assert(errno_value == ENOENT); + if (efi_del_variable(&efi_mount, v_name)) + finish(__LINE__); - path = find_efitest_path(); - rmdir(path); + /* Get after delete should fail. */ + if (!efi_get_variable(NULL, &efi_mount, v_name, &efi_data)) + finish(__LINE__); - return EXIT_SUCCESS; + finish(EXIT_SUCCESS); } From patchwork Fri Aug 10 17:29:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 956356 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41nBvk56btz9s4Z for ; Sat, 11 Aug 2018 03:29:54 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="UHVIPU5k"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41nBvk2z7SzF0WK for ; Sat, 11 Aug 2018 03:29:54 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="UHVIPU5k"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="UHVIPU5k"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41nBv31lZ3zDqrN for ; Sat, 11 Aug 2018 03:29:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zZPxAGW+TnzIhMSkaILCvyNADudKCEyjfrfJ6MpiBBk=; b=UHVIPU5kLr9LzpD73YYrZWu6F F60bMWYZXmhm6J4pP8b/mn/sGgmRCagJdFV4DmzK0/9sx7HyOXGi5iRWDp39TArTLmQ7kRb7QNQ1/ P8A1aC581JYFBiY7fEboA2f1yR+3dqI039NQ3QxvwDXHSwS3qCiPn3VVoG5iPCtSV0YTb47eKDJRE 0AUSIZaeKGV6dmx/xFz4Wb4bA4OaXSBUHGzgUzivfSY1uZGuKMoaukrnDPafOWOPp7D4Fs+gYdU2W V8a1S8ZDIpIrIAqF2vyDOUPuyzge7cYp312fqdlnmQskqfPAkKrVR15j568elU1bHj98Q7ewkX7Uz VeafmpYUw==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1foBDv-0002QN-CD; Fri, 10 Aug 2018 17:29:15 +0000 Message-Id: <491ae2a9dd807e5d93bc8e6c1ec27f5e5ce7a33d.1533921283.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Fri, 10 Aug 2018 10:00:12 -0700 Subject: [PATCH v1 6/6] discover/arm64: Update to struct efi_mount To: Samuel Mendoza-Jonas Date: Fri, 10 Aug 2018 17:29:15 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Signed-off-by: Geoff Levand --- discover/platform-arm64.c | 57 +++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/discover/platform-arm64.c b/discover/platform-arm64.c index 0eb2579..6fefa74 100644 --- a/discover/platform-arm64.c +++ b/discover/platform-arm64.c @@ -22,7 +22,6 @@ #include #include #include -#include #include "efi/efivar.h" #include "file/file.h" @@ -32,13 +31,11 @@ #include "talloc/talloc.h" #include "types/types.h" - #include "ipmi.h" #include "platform.h" -static const char *efi_vars_guid = "fb78ab4b-bd43-41a0-99a2-4e74bef9169b"; - struct platform_arm64 { + const struct efi_mount *efi_mount; struct param_list *params; struct ipmi *ipmi; }; @@ -48,28 +45,34 @@ static inline struct platform_arm64 *to_platform_arm64(struct platform *p) return (struct platform_arm64 *)(p->platform_data); } -static void parse_nvram(struct param_list *pl) +static void read_efivars(const struct efi_mount *efi_mount, + struct param_list *pl) { const char** known; + if (!efi_mount) + return; + param_list_for_each_known_param(pl, known) { struct efi_data *efi_data; - if (efi_get_variable(NULL, efi_vars_guid, *known, &efi_data)) + if (efi_get_variable(NULL, efi_mount, *known, &efi_data)) continue; - param_list_set(pl, *known, efi_data->data, - true); - + param_list_set(pl, *known, efi_data->data, true); talloc_free(efi_data); } } -static void write_nvram(const struct param_list *pl) +static void write_efivars(const struct efi_mount *efi_mount, + const struct param_list *pl) { struct efi_data efi_data; struct param *param; + if (!efi_mount) + return; + efi_data.attributes = EFI_DEFALT_ATTRIBUTES; param_list_for_each(pl, param) { @@ -78,7 +81,7 @@ static void write_nvram(const struct param_list *pl) efi_data.data = param->value; efi_data.data_size = strlen(param->value) + 1; - efi_set_variable(efi_vars_guid, param->name, &efi_data); + efi_set_variable(efi_mount, param->name, &efi_data); } } @@ -100,9 +103,10 @@ static void get_active_consoles(struct config *config) static int load_config(struct platform *p, struct config *config) { + const struct efi_mount *efi_mount = to_platform_arm64(p)->efi_mount; struct param_list *pl = to_platform_arm64(p)->params; - parse_nvram(pl); + read_efivars(efi_mount, pl); config_populate_all(config, pl); get_active_consoles(config); @@ -218,6 +222,7 @@ static void params_update_all(struct param_list *pl, static int save_config(struct platform *p, struct config *config) { + const struct efi_mount *efi_mount = to_platform_arm64(p)->efi_mount; struct param_list *pl = to_platform_arm64(p)->params; struct config *defaults; @@ -227,38 +232,26 @@ static int save_config(struct platform *p, struct config *config) params_update_all(pl, config, defaults); talloc_free(defaults); - write_nvram(pl); + write_efivars(efi_mount, pl); return 0; } static bool probe(struct platform *p, void *ctx) { - static const char *efivars = "/sys/firmware/efi/efivars"; + static const struct efi_mount efi_mount = { + .path = "/sys/firmware/efi/efivars", + .guid = "fb78ab4b-bd43-41a0-99a2-4e74bef9169b", + }; struct platform_arm64 *platform; - struct statfs buf; - - if (access(efivars, R_OK | W_OK)) { - pb_debug_fn("Can't access %s\n", efivars); - return false; - } - - memset(&buf, '\0', sizeof(buf)); - if (statfs(efivars, &buf)) { - pb_debug_fn("statfs failed: %s: %s\n", efivars, - strerror(errno)); - return false; - } - - if (buf.f_type != EFIVARFS_MAGIC) { - pb_debug_fn("Bad magic = 0x%lx\n", (unsigned long)buf.f_type); - return false; - } platform = talloc_zero(ctx, struct platform_arm64); platform->params = talloc_zero(platform, struct param_list); param_list_init(platform->params, common_known_params()); + if (efi_check_mount(&efi_mount)) + platform->efi_mount = &efi_mount; + p->platform_data = platform; return true;