From patchwork Wed Apr 24 06:30:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1089963 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="UWL6Cs4a"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44pr9l2hKbz9s47 for ; Wed, 24 Apr 2019 16:33:31 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0A13CC21E0F; Wed, 24 Apr 2019 06:32:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 6FAF4C21E30; Wed, 24 Apr 2019 06:31:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 23D46C21D72; Wed, 24 Apr 2019 06:31:32 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by lists.denx.de (Postfix) with ESMTPS id 85CD3C21E42 for ; Wed, 24 Apr 2019 06:31:27 +0000 (UTC) Received: by mail-yb1-f195.google.com with SMTP id e76so6704546ybc.3 for ; Tue, 23 Apr 2019 23:31:27 -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=eGim/d7jvIHsmmNCCcXkbFt2UVhd/ZTE0psJBadWtTI=; b=UWL6Cs4a8DcYU26vbsMo5X73pBb0CVSkmE1t0uY31ktHxw3SRW3ShhNITJeMDlmrpH R+W4eoacwFP94GfxLJCiQmQ30FNrsRubyXwVKFFoa9OueHwkqvUK77UwTqO8K3IWkjy1 xAN1zbJl1sc8Lj1+lklI4BekObsnl69i/KrybyhX37VRc33dXqN7bO9Guqa5yBFpqaNi Z6TOe0HgfxzK2nFJAGFrNlTNpv8eSnxjQMWt0pNqmwkgxDdpuPvGQLb9LvIoktW9sUDI ZrjyUUTeMn1eVXU8nBCRghVHJFM5pKsWw2JKQfe8C5v0dXun2tyF1B6DHHcvazBS1PYv 8Z0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eGim/d7jvIHsmmNCCcXkbFt2UVhd/ZTE0psJBadWtTI=; b=i7GsPTs0nzBRwMa7de3k51F1RksJsIHoMGJTTHkgyySUBJ1RJ26TN8zJhwumy3iobV P4EzlQdzCaaqImFi5l9WrZo3t6KDbMzsOYY8Nafwu1KsKFd1fDCHLKQJhyadS0oM30Nr 8OAtHEYRdYiDWxvrINIwL2lZbs5671Jrn1K7oa+x/NpoG/bq6sirjr0A341uyjA7/wwg MzVniCtgAWlCyzCCtbvjDcy5kWfzSbgpkHHzVFkykuOxmBpaLACa4/1fzo2JunbmjVpc uZCPmkHAHGt6K9KJEYuA/C5Be1PH9xurFTpZQoBegqkeOgzi4mbONIW4wePcDpOcY6s3 +zTA== X-Gm-Message-State: APjAAAWFM41IrHjSdOhCYvO4Bse5JxkrUvYLtD6zAKpzcJqPN2WzffI3 QtrnJyESF+vPKNpvXLCPAOddTg== X-Google-Smtp-Source: APXvYqxU9UeXvODYrRaNW+7TpjCOB/Iy4RZJWPsQhBeywVnOMh5rc7GHlbA+sGg0XTMkUzVD11zQVw== X-Received: by 2002:a25:55c3:: with SMTP id j186mr2660962ybb.255.1556087486479; Tue, 23 Apr 2019 23:31:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id k128sm4983352ywb.26.2019.04.23.23.31.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:31:26 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 24 Apr 2019 15:30:35 +0900 Message-Id: <20190424063045.14443-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424063045.14443-1-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 01/11] lib: charset: add u16_strcmp() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" u16 version of strcmp() AUTHER: Patrick Wildt Signed-off-by: AKASHI Takahiro --- include/charset.h | 5 +++++ lib/charset.c | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/charset.h b/include/charset.h index 65087f76d1fc..747a9b376c03 100644 --- a/include/charset.h +++ b/include/charset.h @@ -166,6 +166,11 @@ s32 utf_to_lower(const s32 code); */ s32 utf_to_upper(const s32 code); +/* + * u16_strcmp() - strcmp() for u16 strings + */ +int u16_strcmp(const u16 *s1, const u16 *s2); + /** * u16_strlen - count non-zero words * diff --git a/lib/charset.c b/lib/charset.c index 5e349ed5ee45..4a25ac0bdb9c 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -335,6 +335,16 @@ s32 utf_to_upper(const s32 code) return ret; } +int u16_strcmp(const u16 *s1, const u16 *s2) +{ + while (*s1 == *s2++) + if (*s1++ == 0) + return (0); + --s2; + + return (*(uint16_t *)s1 - *(uint16_t *)s2); +} + size_t u16_strlen(const u16 *in) { size_t i; From patchwork Wed Apr 24 06:30:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1089960 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="BkSIwwiy"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44pr8H22nfz9s47 for ; Wed, 24 Apr 2019 16:32:15 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D74CBC21E49; Wed, 24 Apr 2019 06:32:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A325AC21E47; Wed, 24 Apr 2019 06:31:41 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2ED09C21E38; Wed, 24 Apr 2019 06:31:33 +0000 (UTC) Received: from mail-yw1-f42.google.com (mail-yw1-f42.google.com [209.85.161.42]) by lists.denx.de (Postfix) with ESMTPS id BC82CC21D65 for ; Wed, 24 Apr 2019 06:31:29 +0000 (UTC) Received: by mail-yw1-f42.google.com with SMTP id j66so6542548ywc.10 for ; Tue, 23 Apr 2019 23:31:29 -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=qNoHBDCSvtY0Q/0/Hx8BJc4smyqHlfmePt6CT5bWyB0=; b=BkSIwwiy7/Vx0xwNNDPoU/Fuqu7vZE7ac74QEn7bBZjKw8f8ZRb34yfxN04AXC+mMQ G87MnoK0Cpnv7blPpJkN0l9xiHK+6bas8U1+H49H0dg1C+Kw6IY2miHzf+LSWOVKjFqP Qhl8ogwOEvR1sgukrT+7kvCFxjB4keWLkpLl0pzR60IFLupqFdzmAREP+SiSzW8Uto7E +OYXGn3/voMVJ3Dj7Y9QHtBaumPL+bb9YAxESqsV5cWEwSUjZRUGr7EH5KWLtKwE+qS+ 52JgDGt7I8GShycy3+tgfqn8W7+8XgveQh6hJWrf9eiOIFEg/SpaTyg6Uxm1gBo3Bf3u STWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qNoHBDCSvtY0Q/0/Hx8BJc4smyqHlfmePt6CT5bWyB0=; b=MtwARrDxRYBWxMhXZc1pSVnYWr5NVOFoCa008sEOBr470ni7qmi3hq1yPb6UP05H3U 13DRsOOOaqyYyCNogIH0OOCstjWcTGTQnHY962plt0nQ9KN/WHtFac7xKad+UBdkNnZX 9XHEAzYOWnRhxAYsvS9db89igczJkZXHFqFJR0nJjc5SI9Viypg6oHsTmMis32zUGi1h IcKzCgs5mXsbnFZtstrvbuYg+d85wzyKjUtvBM+nO6zevzOhHF+8awS5LnYXkJIw4QqQ rp5nzM87ySXuw9dVFbfw9lKRum96TehWZJVZsnxj1rWBxNA/HrOZPt6Q0nZpdY8nvcFE RV2g== X-Gm-Message-State: APjAAAXm/jPmThzL6OEz67NyWQhutbxIy15uJfPhua2VCp7+IjCT1pab ttuUF763IgzluXIKjl3MS/zwaA== X-Google-Smtp-Source: APXvYqwH6Q35P+hh8sMtM0mn9B4Sw+CtUxSiDBhBlWujB7CfUTciYjJ0q7CZNGR77X3GlZFktHM9pA== X-Received: by 2002:a81:5f03:: with SMTP id t3mr25340720ywb.12.1556087488783; Tue, 23 Apr 2019 23:31:28 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e81sm3905353ywc.45.2019.04.23.23.31.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:31:28 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 24 Apr 2019 15:30:36 +0900 Message-Id: <20190424063045.14443-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424063045.14443-1-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 02/11] lib: charset: add u16_strncmp() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" u16_strncmp() works like u16_strcmp() but only at most n characters (in u16) are compared. This function will be used in a later patch. Signed-off-by: AKASHI Takahiro --- include/charset.h | 5 +++++ lib/charset.c | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/charset.h b/include/charset.h index 747a9b376c03..49842a88bc8b 100644 --- a/include/charset.h +++ b/include/charset.h @@ -171,6 +171,11 @@ s32 utf_to_upper(const s32 code); */ int u16_strcmp(const u16 *s1, const u16 *s2); +/* + * u16_strncmp() - strncmp() for u16 strings + */ +int u16_strncmp(const u16 *s1, const u16 *s2, size_t n); + /** * u16_strlen - count non-zero words * diff --git a/lib/charset.c b/lib/charset.c index 4a25ac0bdb9c..85f08db68fe2 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -345,6 +345,19 @@ int u16_strcmp(const u16 *s1, const u16 *s2) return (*(uint16_t *)s1 - *(uint16_t *)s2); } +int u16_strncmp(const u16 *s1, const u16 *s2, size_t n) +{ + while ((n-- > 0) && (*s1 == *s2++)) { + if (*s1++ == 0) + return 0; + if (!n) + return 0; + } + --s2; + + return (*(uint16_t *)s1 - *(uint16_t *)s2); +} + size_t u16_strlen(const u16 *in) { size_t i; From patchwork Wed Apr 24 06:30:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1089961 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="HDdfkjfy"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44pr8f5VzFz9s47 for ; Wed, 24 Apr 2019 16:32:34 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 710B7C21E5B; Wed, 24 Apr 2019 06:31:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 16EBEC21E34; Wed, 24 Apr 2019 06:31:41 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CCDBCC21E13; Wed, 24 Apr 2019 06:31:33 +0000 (UTC) Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) by lists.denx.de (Postfix) with ESMTPS id 4BB34C21E3B for ; Wed, 24 Apr 2019 06:31:32 +0000 (UTC) Received: by mail-yb1-f179.google.com with SMTP id e190so6703062ybf.2 for ; Tue, 23 Apr 2019 23:31:32 -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=2sAuyQhYmLXbphlK0peY4DCKIGyr3xH/4j9FAn8ocnQ=; b=HDdfkjfyArHQYVyscbXFPjaS0dWCcI0mrFmBPLBzuaVriJR70x7YPFEP6ZRVARly+q UGVoimBsox8zGEp7oLdKACAvJXmy4hBeVopcNQrqApgiB13yqPRC5cCS4NywTCRruYNu b66MUq2pOI/OgUehbU9SylFjPxx5yvPxc8Dxxzl5dr07u/46z+lonlTwuq0sq6VsUbEm Hnl6xI3XdqpTlIhBVAG4475H2Hqz3YCL4J8CkOhx4kZCi0i4cy0Qq0VmmSZiSbtvFerf VVyT17K7ntWUGQiajvdB/NbjChMm5Nf67IvS1N0rOusCcJ3Vwi5lZhKoh98TgOpniUFO SAwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2sAuyQhYmLXbphlK0peY4DCKIGyr3xH/4j9FAn8ocnQ=; b=mfLScL32P7iVDuTrNpG0fiSQVadlOZ6lExZ7eX4L58I0r4VMTAkDhHv6tmsdsUox0U TtoMJondcvUBV7v8GXCqWIVRuHRTpf0tTVoz5EM0/gEtkL3dBqY1vWxIrS7/3tcunhba B9gSW4WDkHpZtS/KFsmYw0vxY8F1wJDIgHqLyeIuwlX6BFVG9lXa+YmPhiihbX7TSlfh ZR3ClRwTN2UvJsDEvhlg3lnQ/5SB6bUpSBeayyAZmc5OEzisVWEJrJKUvi9wQsUiGZNh vgnIwLJ785YmNik6y7YDL32K87acZ/MIh7unZhvarv9L4Qp1ioezZ+fO/EDHjdIy08UD iXSw== X-Gm-Message-State: APjAAAWulmGGXOq84BqmEpe9L6p6B82w2o5O2f6xTvoG1YkFZizJi+jW eI+5DPtjCJPaL4KMOCP7449L5w== X-Google-Smtp-Source: APXvYqzMBdzalVFIN/O8Grg4V0nURScBzPpYCvqu+LnOc0s33LlblYkvALb5e8zMCh/fQYeO96gLRg== X-Received: by 2002:a5b:8c7:: with SMTP id w7mr26268812ybq.214.1556087491259; Tue, 23 Apr 2019 23:31:31 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 139sm6059741ywk.83.2019.04.23.23.31.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:31:30 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 24 Apr 2019 15:30:37 +0900 Message-Id: <20190424063045.14443-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424063045.14443-1-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 03/11] cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Efidebug command should be implemented using well-defined EFI interfaces, rather than using internal functions/data. This change will be needed in a later patch where UEFI variables are re-implemented. Signed-off-by: AKASHI Takahiro --- cmd/efidebug.c | 92 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 26 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index a40c4f4be286..8890dd7268f1 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -509,7 +509,7 @@ static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag, if (argc < 6 || argc > 7) return CMD_RET_USAGE; - id = (int)simple_strtoul(argv[1], &endp, 16); + id = simple_strtoul(argv[1], &endp, 16); if (*endp != '\0' || id > 0xffff) return CMD_RET_USAGE; @@ -595,7 +595,7 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, guid = efi_global_variable_guid; for (i = 1; i < argc; i++, argv++) { - id = (int)simple_strtoul(argv[1], &endp, 16); + id = simple_strtoul(argv[1], &endp, 16); if (*endp != '\0' || id > 0xffff) return CMD_RET_FAILURE; @@ -693,6 +693,27 @@ static void show_efi_boot_opt(int id) free(data); } +static bool u16_isxdigit(u16 c) +{ + if (c & 0xff00) + return false; + + return isxdigit((u8)c); +} + +static int u16_tohex(u16 c) +{ + if (c >= '0' && c < '9') + return c - '0'; + if (c >= 'A' && c < 'F') + return c - 'A' + 10; + if (c >= 'a' && c < 'f') + return c - 'a' + 10; + + /* dummy */ + return -1; +} + /** * show_efi_boot_dump() - dump all UEFI load options * @@ -709,38 +730,57 @@ static void show_efi_boot_opt(int id) static int do_efi_boot_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - char regex[256]; - char * const regexlist[] = {regex}; - char *variables = NULL, *boot, *value; - int len; - int id; + u16 *var_name16, *p; + efi_uintn_t buf_size, size; + efi_guid_t guid; + int id, i; + efi_status_t ret; if (argc > 1) return CMD_RET_USAGE; - snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_Boot[0-9A-F]+"); - - /* TODO: use GetNextVariableName? */ - len = hexport_r(&env_htab, '\n', H_MATCH_REGEX | H_MATCH_KEY, - &variables, 0, 1, regexlist); + buf_size = 128; + var_name16 = malloc(buf_size); + if (!var_name16) + return CMD_RET_FAILURE; - if (!len) - return CMD_RET_SUCCESS; + var_name16[0] = 0; + for (;;) { + size = buf_size; + ret = EFI_CALL(efi_get_next_variable_name(&size, var_name16, + &guid)); + if (ret == EFI_NOT_FOUND) + break; + if (ret == EFI_BUFFER_TOO_SMALL) { + buf_size = size; + p = realloc(var_name16, buf_size); + if (!p) { + free(var_name16); + return CMD_RET_FAILURE; + } + var_name16 = p; + ret = EFI_CALL(efi_get_next_variable_name(&size, + var_name16, + &guid)); + } + if (ret != EFI_SUCCESS) { + free(var_name16); + return CMD_RET_FAILURE; + } - if (len < 0) - return CMD_RET_FAILURE; + if (u16_strncmp(var_name16, L"Boot", 4) || var_name16[8] || + !u16_isxdigit(var_name16[4]) || + !u16_isxdigit(var_name16[5]) || + !u16_isxdigit(var_name16[6]) || + !u16_isxdigit(var_name16[7])) + continue; - boot = variables; - while (*boot) { - value = strstr(boot, "Boot") + 4; - id = (int)simple_strtoul(value, NULL, 16); + for (id = 0, i = 0; i < 4; i++) + id = (id << 4) + u16_tohex(var_name16[4 + i]); show_efi_boot_opt(id); - boot = strchr(boot, '\n'); - if (!*boot) - break; - boot++; } - free(variables); + + free(var_name16); return CMD_RET_SUCCESS; } @@ -914,7 +954,7 @@ static int do_efi_boot_order(cmd_tbl_t *cmdtp, int flag, return CMD_RET_FAILURE; for (i = 0; i < argc; i++) { - id = (int)simple_strtoul(argv[i], &endp, 16); + id = simple_strtoul(argv[i], &endp, 16); if (*endp != '\0' || id > 0xffff) { printf("invalid value: %s\n", argv[i]); ret = CMD_RET_FAILURE; From patchwork Wed Apr 24 06:30:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1089959 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="bEih4pju"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44pr7t03Swz9s4V for ; Wed, 24 Apr 2019 16:31:53 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id AA448C21E7E; Wed, 24 Apr 2019 06:31:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9AFFAC21C57; Wed, 24 Apr 2019 06:31:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C9995C21E1E; Wed, 24 Apr 2019 06:31:35 +0000 (UTC) Received: from mail-yb1-f193.google.com (mail-yb1-f193.google.com [209.85.219.193]) by lists.denx.de (Postfix) with ESMTPS id D0000C21E39 for ; Wed, 24 Apr 2019 06:31:34 +0000 (UTC) Received: by mail-yb1-f193.google.com with SMTP id x71so6695605ybe.6 for ; Tue, 23 Apr 2019 23:31:34 -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=es8Yoox1rl3DztkD0Jyj40pDh5cGSgfYNKTDUAZscnI=; b=bEih4pju9AbxBhkz3Ggdebtpp483108G+TjIWp7dGQdRWWnXtbFiwezRNeCqqsh43b YTqHQVSfbJXJEKaCUuaH29U1P/m2Wli14uJiiY4V7uM228cCkBppOJys3X+hLhm8blpZ X1rI/6HatFTxfXbEf/EC4WlJAFxqXqudU0GoqRIIQDDrJavlOffc2HINuPTv8rVFJtoQ UfNyua713D+zLodGo5y/kXEvNR++CzFBTNX0r6GNB2GL1V1rbNQRR0Hdl+1Ergi97LwW hQtlh1gDNdUNKu6AVraRwvjCCKDgL2dw+/4BOhJ+XwdHHje7gJ/7eZVE6+hJAkzGXAT6 drhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=es8Yoox1rl3DztkD0Jyj40pDh5cGSgfYNKTDUAZscnI=; b=AqMUA9r+ZmTHOAFSf6gq8TMbqnHyrztvK5T/cT9dfWi+PM9x3T36RLONF6lQOYtsqi kWovuCiFuh//0oq3gJwPf7qkgZRi/Dn3rY7H/U8AEcFEPHl3TOAFC0b22C6fzLr8W8gW Nm8H54DxpFSQF9W5pFlYPOOSyykbFSyePfEXSpzBI5Zf18t3vM9QUZC/svL4e6U7U4MO U2xfjzCCjiStyCwKa8Ad+jIgzzccW9Q1Tt/6Uk6G+CwYunGn+vMRwNnT/L6Z1v7fNheF Erryzy+7V7ZyDQI/vlKP2GjP/MwjeEQm5l0DQd8/ahgIKz+VoJMTei//jtxIZKZHKhSz Qy+A== X-Gm-Message-State: APjAAAUW9dna/eIJBu+PWH1MDzOM78MhN6ZYQh9Q3WWU8rLa8aR13w6/ XIa8xWeRCJ8vF/UjwZVbH0QQtg== X-Google-Smtp-Source: APXvYqzszCtyY7grEg6tTzkRHCKfNfs/D1CnfN6XVqpCujLog94Kvv5jytWm1+OsBeQpP5hzfPUl3Q== X-Received: by 2002:a25:2451:: with SMTP id k78mr19860767ybk.126.1556087493474; Tue, 23 Apr 2019 23:31:33 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x66sm3613704ywg.47.2019.04.23.23.31.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:31:33 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 24 Apr 2019 15:30:38 +0900 Message-Id: <20190424063045.14443-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424063045.14443-1-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 04/11] efi_loader: set OsIndicationsSupported at init X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" UEFI variable should be installed using well-defined API. Currently we don't support much, but the value fo OsIndicationsSupported will be updated once some features are added in the future. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 4 ---- lib/efi_loader/efi_setup.c | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index efaa548be4d8..b93d8c6a32cd 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -303,10 +303,6 @@ static efi_status_t do_bootefi_exec(efi_handle_t handle) if (ret != EFI_SUCCESS) return ret; - /* we don't support much: */ - env_set("efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_OsIndicationsSupported", - "{ro,boot}(blob)0000000000000000"); - /* Call our payload! */ ret = EFI_CALL(efi_start_image(handle, NULL, NULL)); diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 7d67a5506335..05d8d754f4c7 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -89,6 +89,7 @@ out: */ efi_status_t efi_init_obj_list(void) { + u64 val = 0; efi_status_t ret = EFI_SUCCESS; /* Initialize once only */ @@ -100,6 +101,14 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + ret = EFI_CALL(efi_set_variable(L"OsIndicationsSupported", + &efi_global_variable_guid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + sizeof(val), &val)); + if (ret != EFI_SUCCESS) + goto out; + /* Initialize system table */ ret = efi_initialize_system_table(); if (ret != EFI_SUCCESS) From patchwork Wed Apr 24 06:30:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1089970 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ermUiyQf"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44prFX1Ycdz9s3q for ; Wed, 24 Apr 2019 16:36:48 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E5D00C21E79; Wed, 24 Apr 2019 06:33:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8FEF9C21E34; Wed, 24 Apr 2019 06:32:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DADB8C21DA1; Wed, 24 Apr 2019 06:31:37 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by lists.denx.de (Postfix) with ESMTPS id 0651BC21E0F for ; Wed, 24 Apr 2019 06:31:37 +0000 (UTC) Received: by mail-yb1-f195.google.com with SMTP id p134so6701870ybc.4 for ; Tue, 23 Apr 2019 23:31:36 -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=sgF1xgnRlGsR/f2/IwNAvkJRgMUyiIAcOkR8aTGx7ho=; b=ermUiyQfbXXeKkmGyGbwhnQ3xfErIy3aTTuSm79reF0a1vxzuxfoB5Lrv2ae5lwU0+ qUGIhh+cw1V1JPrBLbx04+0FF1/bn3RBoRbTm8iHLUWPx/05GAOkP82gDZNrshZTvPDA pYFcZYj/a1TRtGdiFhUaL57stLFGPCWMccby4t0k2G4YVBrq2KOi0nyMuUtC/Z0bm9eT ILQ7MAinaxLvpiI3LrhfuEH9Kr7xP5sYPbCbvrSadKLbJLdQfl9zafvvR9kjFbaJYklX 5P/s4d0mxKpyPCV8SvfbrkqxNbGHSLKdWBdeKeFMlwCC3Wepl+Gl7IOyqkUXCdYcDY8f q1bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sgF1xgnRlGsR/f2/IwNAvkJRgMUyiIAcOkR8aTGx7ho=; b=rkCorLxDlgqXSSzcOVggxTDHVWvjIBIrDDaowFkCFfh6wM7zk/wh+GNOyLCksyKmWN 0PvABK3K8mQB7JDqcBBm+rPZINAlEZN8KXqFeIaM+7ukbcL/Rdn1hCB0G2ReRlRZdFW0 knaLDBs601i9dMJS7xWcrkfQAEB8sGbssmnxANu7R/GJ4y7F4tyQptwPUzovPcTU+NsI WjT3bD52EY9sNZFA46TD9q9yI7sedYo+Uu1X0vCN9bnM7vhZukCiu4JGhib9MtYCdL6U Iv7FvqOzwHosiWgP3FwJ+iI0BzMeAXiBnemCYbrFvrG9Q9B85rZOQqY89OrHU+8FqoW8 OC7g== X-Gm-Message-State: APjAAAVdiuBwJU96f27E5qr1PCjRCx24IRm8RKePuUdGAVHsFTtZcsm/ AOS0l+jhEFkJ8YVVKSqIEaKIDw== X-Google-Smtp-Source: APXvYqzajW7HADWbwT3KQL+gdGfP+Zv4AsEyS1chVAkyq5GFV6FRQFiy28ON3GpZbH7+XSzEcE7FAg== X-Received: by 2002:a25:d305:: with SMTP id e5mr327711ybf.97.1556087495854; Tue, 23 Apr 2019 23:31:35 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d196sm10454982ywh.105.2019.04.23.23.31.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:31:35 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 24 Apr 2019 15:30:39 +0900 Message-Id: <20190424063045.14443-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424063045.14443-1-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 05/11] env: save UEFI non-volatile variables in dedicated storage X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" We need a variant of env_save()/env_load() to handle dedicated storage for UEFI variables. It is assumed that env_efi_load() will be called only ince at init and that env_efi_save() will be called at every SetVariable. In this patch, new parameters will be expected to be configured: CONFIG_ENV_EFI_FAT_DEVICE_AND_PART CONFIG_ENV_EFI_FAT_FILE in case of CONFIG_ENV_IS_IN_FAT. Signed-off-by: AKASHI Takahiro --- env/Kconfig | 34 ++++++++++ env/env.c | 98 ++++++++++++++++++++++++++- env/fat.c | 109 ++++++++++++++++++++++++++++++ include/asm-generic/global_data.h | 1 + include/environment.h | 24 +++++++ 5 files changed, 265 insertions(+), 1 deletion(-) diff --git a/env/Kconfig b/env/Kconfig index 78300660c720..8f59e9347d4b 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -438,6 +438,34 @@ config ENV_FAT_FILE It's a string of the FAT file name. This file use to store the environment. +config ENV_EFI_FAT_DEVICE_AND_PART + string "Device and partition for where to store the UEFI non-volatile variables in FAT" + depends on ENV_IS_IN_FAT + depends on EFI_LOADER + help + Define this to a string to specify the partition of the device. It can + be as following: + + "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1) + - "D:P": device D partition P. Error occurs if device D has no + partition table. + - "D:0": device D. + - "D" or "D:": device D partition 1 if device D has partition + table, or the whole device D if has no partition + table. + - "D:auto": first partition in device D with bootable flag set. + If none, first valid partition in device D. If no + partition table then means device D. + +config ENV_EFI_FAT_FILE + string "Name of the FAT file to use for the UEFI non-volatile variables" + depends on ENV_IS_IN_FAT + depends on EFI_LOADER + default "uboot_efi.env" + help + It's a string of the FAT file name. This file use to store the + UEFI non-volatile variables. + config ENV_EXT4_INTERFACE string "Name of the block device for the environment" depends on ENV_IS_IN_EXT4 @@ -470,6 +498,12 @@ config ENV_EXT4_FILE It's a string of the EXT4 file name. This file use to store the environment (explicit path to the file) +config ENV_EFI_SIZE + hex "UEFI Variables Environment Size" + default 0x20000 + help + Size of the UEFI variables storage area + if ARCH_ROCKCHIP || ARCH_SUNXI || ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_VERSAL || ARC config ENV_OFFSET diff --git a/env/env.c b/env/env.c index 4b417b90a291..d5af761ba57e 100644 --- a/env/env.c +++ b/env/env.c @@ -24,6 +24,10 @@ void env_fix_drivers(void) entry->load += gd->reloc_off; if (entry->save) entry->save += gd->reloc_off; + if (entry->efi_load) + entry->efi_load += gd->reloc_off; + if (entry->efi_save) + entry->efi_save += gd->reloc_off; if (entry->init) entry->init += gd->reloc_off; } @@ -125,7 +129,8 @@ __weak enum env_location env_get_location(enum env_operation op, int prio) if (prio >= ARRAY_SIZE(env_locations)) return ENVL_UNKNOWN; - gd->env_load_prio = prio; + if (op != ENVOP_EFI) + gd->env_load_prio = prio; return env_locations[prio]; } @@ -280,3 +285,94 @@ int env_init(void) return ret; } + +#ifdef CONFIG_EFI_LOADER +extern struct hsearch_data efi_var_htab; +extern struct hsearch_data efi_nv_var_htab; + +/* TODO: experimental */ +int env_efi_save(void) +{ + struct env_driver *drv = NULL; + int ret; + + if (!efi_nv_var_htab.table) + return 0; + + if (gd->env_efi_prio == -1) { + printf("Cannot save UEFI non-volatile variable\n"); + return -1; + } + + drv = _env_driver_lookup(env_get_location(ENVOP_EFI, gd->env_efi_prio)); + if (!drv) { + printf("Cannot save UEFI non-volatile variable\n"); + return -1; + } + + ret = drv->efi_save(); + if (ret) + printf("Saving UEFI non-volatile variable failed\n"); + + return ret; +} + +/* TODO: experimental */ +/* This function should be called only once at init */ +int env_efi_load(void) +{ + struct env_driver *drv = NULL; + int prio, ret; + enum env_location loc; + + gd->env_efi_prio = -1; + + /* volatile variables */ + if (!efi_var_htab.table) { + ret = himport_r(&efi_var_htab, NULL, 0, '\0', 0, 0, 0, NULL); + if (!ret) { + printf("Creating default UEFI variables failed\n"); + return -1; + } + } + + /* non-loratile variables */ + if (efi_nv_var_htab.table) + return 0; + + for (prio = 0; prio < ARRAY_SIZE(env_locations); prio++) { + loc = env_get_location(ENVOP_EFI, prio); + drv = _env_driver_lookup(loc); + if (!drv) + continue; + + if (drv->efi_load && drv->efi_save) + break; + } + if (!drv || prio == ARRAY_SIZE(env_locations)) { + printf("No driver for UEFI storage is available\n"); + return -1; + } + + gd->env_efi_prio = prio; + + ret = drv->efi_load(); + if (ret) { + printf("Loading UEFI non-volatile variables failed\n"); + return -1; + } + + /* FIXME: init needed here? */ + if (!efi_nv_var_htab.table) { + ret = himport_r(&efi_nv_var_htab, NULL, 0, '\0', 0, 0, 0, NULL); + if (!ret) { + printf("Creating default UEFI non-volatile variables failed\n"); + return -1; + } + + return 0; + } + + return 0; +} +#endif /* CONFIG_EFI_LOADER */ diff --git a/env/fat.c b/env/fat.c index 7f74c64dfe7e..e2b050d4553d 100644 --- a/env/fat.c +++ b/env/fat.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -128,6 +129,110 @@ err_env_relocate: } #endif /* LOADENV */ +#ifdef CONFIG_EFI_LOADER +#if 1 +extern int efi_variable_import(const char *buf, int check); +extern int efi_variable_export(env_t *env_out); +#endif +static int env_fat_efi_save(void) +{ + env_t __aligned(ARCH_DMA_MINALIGN) env_new; + struct blk_desc *dev_desc = NULL; + disk_partition_t info; + int dev, part; + int err; + loff_t size; + + err = efi_variable_export(&env_new); + if (err) + return err; + + part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE, + CONFIG_ENV_EFI_FAT_DEVICE_AND_PART, + &dev_desc, &info, 1); + if (part < 0) + return 1; + + dev = dev_desc->devnum; + if (fat_set_blk_dev(dev_desc, &info) != 0) { + /* + * This printf is embedded in the messages from env_save that + * will calling it. The missing \n is intentional. + */ + printf("Unable to use %s %d:%d... ", + CONFIG_ENV_FAT_INTERFACE, dev, part); + return 1; + } + + err = file_fat_write(CONFIG_ENV_EFI_FAT_FILE, + (void *)&env_new, 0, sizeof(env_t), &size); + if (err < 0) { + /* + * This printf is embedded in the messages from env_save that + * will calling it. The missing \n is intentional. + */ + printf("Unable to write \"%s\" from %s%d:%d... ", + CONFIG_ENV_EFI_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, + dev, part); + return 1; + } + + return 0; +} + +static int env_fat_efi_load(void) +{ + ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_EFI_SIZE); + struct blk_desc *dev_desc = NULL; + disk_partition_t info; + int dev, part; + int err; + +#ifdef CONFIG_MMC + if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc")) + mmc_initialize(NULL); +#endif + + part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE, + CONFIG_ENV_EFI_FAT_DEVICE_AND_PART, + &dev_desc, &info, 1); + if (part < 0) + goto err_env_relocate; + + dev = dev_desc->devnum; + if (fat_set_blk_dev(dev_desc, &info) != 0) { + /* + * This printf is embedded in the messages from env_save that + * will calling it. The missing \n is intentional. + */ + printf("Unable to use %s %d:%d...\n", + CONFIG_ENV_FAT_INTERFACE, dev, part); + goto err_env_relocate; + } + + err = file_fat_read(CONFIG_ENV_EFI_FAT_FILE, buf, CONFIG_ENV_EFI_SIZE); + if (err <= 0 && (err != -ENOENT)) { + /* + * This printf is embedded in the messages from env_save that + * will calling it. The missing \n is intentional. + */ + printf("Unable to read \"%s\" from %s %d:%d...\n", + CONFIG_ENV_EFI_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, + dev, part); + goto err_env_relocate; + } + + if (err > 0) + return efi_variable_import(buf, 1); + else + return 0; + +err_env_relocate: + + return -EIO; +} +#endif /* CONFIG_EFI_LOADER */ + U_BOOT_ENV_LOCATION(fat) = { .location = ENVL_FAT, ENV_NAME("FAT") @@ -137,4 +242,8 @@ U_BOOT_ENV_LOCATION(fat) = { #ifdef CMD_SAVEENV .save = env_save_ptr(env_fat_save), #endif +#ifdef CONFIG_EFI_LOADER + .efi_load = env_fat_efi_load, + .efi_save = env_fat_efi_save, +#endif }; diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 78dcf40bff48..8c4d56c346f3 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -51,6 +51,7 @@ typedef struct global_data { unsigned long env_valid; /* Environment valid? enum env_valid */ unsigned long env_has_init; /* Bitmask of boolean of struct env_location offsets */ int env_load_prio; /* Priority of the loaded environment */ + int env_efi_prio; /* Priority of the UEFI variables */ unsigned long ram_base; /* Base address of RAM used by U-Boot */ unsigned long ram_top; /* Top address of RAM used by U-Boot */ diff --git a/include/environment.h b/include/environment.h index cd966761416e..f62399863ef9 100644 --- a/include/environment.h +++ b/include/environment.h @@ -200,6 +200,7 @@ enum env_operation { ENVOP_INIT, /* we want to call the init function */ ENVOP_LOAD, /* we want to call the load function */ ENVOP_SAVE, /* we want to call the save function */ + ENVOP_EFI, /* we want to call the efi_load/save function */ }; struct env_driver { @@ -225,6 +226,24 @@ struct env_driver { */ int (*save)(void); + /** + * efi_load() - Load UEFI non-volatile variables from storage + * + * This method is required for UEFI non-volatile variables + * + * @return 0 if OK, -ve on error + */ + int (*efi_load)(void); + + /** + * efi_save() - Save UEFI non-volatile variables to storage + * + * This method is required for UEFI non-volatile variables + * + * @return 0 if OK, -ve on error + */ + int (*efi_save)(void); + /** * init() - Set up the initial pre-relocation environment * @@ -312,6 +331,11 @@ void eth_parse_enetaddr(const char *addr, uint8_t *enetaddr); int eth_env_get_enetaddr(const char *name, uint8_t *enetaddr); int eth_env_set_enetaddr(const char *name, const uint8_t *enetaddr); +#ifdef CONFIG_EFI_LOADER +int env_efi_load(void); +int env_efi_save(void); +#endif + #endif /* DO_DEPS_ONLY */ #endif /* _ENVIRONMENT_H_ */ From patchwork Wed Apr 24 06:30:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1089969 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="HRBFrF4U"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44prF46Bwyz9s3q for ; Wed, 24 Apr 2019 16:36:24 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 8E4FCC21EA2; Wed, 24 Apr 2019 06:33:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 239A7C21E77; Wed, 24 Apr 2019 06:32:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F01EFC21D65; Wed, 24 Apr 2019 06:31:43 +0000 (UTC) Received: from mail-yw1-f67.google.com (mail-yw1-f67.google.com [209.85.161.67]) by lists.denx.de (Postfix) with ESMTPS id 19804C21E02 for ; Wed, 24 Apr 2019 06:31:39 +0000 (UTC) Received: by mail-yw1-f67.google.com with SMTP id u14so4739166ywe.1 for ; Tue, 23 Apr 2019 23:31:39 -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=tDMeBFGgPU76qfOX1c2xkYbcwxExD6HKXu1uRaZe1Wk=; b=HRBFrF4UHDVXQSpkEW4/kO4UyZjOLxZkn5X5HdfEa1fRa9auHmPTTsiN8YKbZUQytF UjuLVlVzinI0XElWFyud9+z4gT49HkAZ6xCkzOeFNSRW7cXvfBGxzqJxgnr6xTWwPo17 f92rVjFZXYBjWX33tOpIScjg9lJDYPGF4ZiN3RjadR5QFEhFvBGGZmaAVMTghkmOtY6l MiF62yRCUiDeuW19bMebsxiNxZkZjgtqrqjbLg2QTn8ggMxOzKX7TBZwLFzd14FIF4mM rpTWnSSYd0eCgGgdDvtAeV72NzNKR1EXEX+W9QRD+1due9FWyjrEJeDRbX7MJxYOwAdE Gesw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tDMeBFGgPU76qfOX1c2xkYbcwxExD6HKXu1uRaZe1Wk=; b=Y9QJ/jNhI8oUd3cVGgRG9P4sg2ipgAjp8CGoxMPn5G4ok5VSZEE687fz/wjuuEYPQ5 KoxJ8IAFS0s+I76TZq8FSdaDSa2EEMrqZkjyyEXGba7hLTqd0n1wB0Vqus2coHS7A2kU rdd9In7v9rbzA+FondzgALQB0T9neb4Lvoq8BFOxik1SDvNsZwfP35TDuMluuk/XQsPP q0ed2CwYkbPW9BKtp87t9RyEruChcprOW2Pmi9W0V+k9lMjabUJvOY7Hdv3jcR9GiOyR DrkYtIyTWNO9YbI20GmdwQ73L9zcn8x7bLKlbRtBosxmfVAhnglsEfD+walx2nGZgxoY dptQ== X-Gm-Message-State: APjAAAVkLmFRahrFKbLMgT5nEE5rjAdNCh8J6S2NQPNjeEJjb38WNHJ8 uAmkZUVmanKqA59pox5bNTurXA== X-Google-Smtp-Source: APXvYqwlhSl6PMYYpdGAweqZ15+2lebuYPOl4Ask2U1MnHCKz/p5NyLaJpQxVFveEWHBLFS0eq9vDA== X-Received: by 2002:a81:6e45:: with SMTP id j66mr23163834ywc.207.1556087498061; Tue, 23 Apr 2019 23:31:38 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j7sm6235240ywa.18.2019.04.23.23.31.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:31:37 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 24 Apr 2019 15:30:40 +0900 Message-Id: <20190424063045.14443-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424063045.14443-1-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 06/11] efi_loader: variable: support non-volatile attribute X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" The attribute, EFI_VARIABLE_NON_VOLATILE, should be encoded as "nv" flag in U-Boot variable if specified. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_variable.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 37728c3c165d..2f489ab9db97 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -125,6 +125,8 @@ static const char *parse_attr(const char *str, u32 *attrp) if ((s = prefix(str, "ro"))) { attr |= READ_ONLY; + } else if ((s = prefix(str, "nv"))) { + attr |= EFI_VARIABLE_NON_VOLATILE; } else if ((s = prefix(str, "boot"))) { attr |= EFI_VARIABLE_BOOTSERVICE_ACCESS; } else if ((s = prefix(str, "run"))) { @@ -452,7 +454,7 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, } } - val = malloc(2 * data_size + strlen("{ro,run,boot}(blob)") + 1); + val = malloc(2 * data_size + strlen("{ro,run,boot,nv}(blob)") + 1); if (!val) { ret = EFI_OUT_OF_RESOURCES; goto out; @@ -464,12 +466,16 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, * store attributes * TODO: several attributes are not supported */ - attributes &= (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS); + attributes &= (EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS); s += sprintf(s, "{"); while (attributes) { u32 attr = 1 << (ffs(attributes) - 1); - if (attr == EFI_VARIABLE_BOOTSERVICE_ACCESS) + if (attr == EFI_VARIABLE_NON_VOLATILE) + s += sprintf(s, "nv"); + else if (attr == EFI_VARIABLE_BOOTSERVICE_ACCESS) s += sprintf(s, "boot"); else if (attr == EFI_VARIABLE_RUNTIME_ACCESS) s += sprintf(s, "run"); From patchwork Wed Apr 24 06:30:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1089962 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Y2sc2ZOE"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44pr9b5SVnz9s47 for ; Wed, 24 Apr 2019 16:33:23 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 69A60C21E1D; Wed, 24 Apr 2019 06:32:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id BEC3EC21E50; Wed, 24 Apr 2019 06:31:57 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 44E09C21E42; Wed, 24 Apr 2019 06:31:45 +0000 (UTC) Received: from mail-yw1-f68.google.com (mail-yw1-f68.google.com [209.85.161.68]) by lists.denx.de (Postfix) with ESMTPS id 7B46AC21E39 for ; Wed, 24 Apr 2019 06:31:41 +0000 (UTC) Received: by mail-yw1-f68.google.com with SMTP id u14so4739197ywe.1 for ; Tue, 23 Apr 2019 23:31:41 -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=T9GNGuqDkwpVtmJBWmZawmnFCdy5WZmzMewwvkaPOGA=; b=Y2sc2ZOEff8vJXF1E3oSLDMCShGFJ0RI5PHdAcJhJ9bovIB/fAKM8zEHWeMXRZjnYU 2ICRinYSdWjsfd+r3CrlMCRy1FXM6FzJt2PIuyFRNcWHl7slrOT2lU16PIO+hXei0izr 3oq7HBsi8DLld5kpIrWWzQrmy9Hsn9h4SdfU9pguJDYHP691NIj15X1Vg8MSZBNoblll 5N6rLjv+XeGvOb2J8opMMnSNa7oDgbV+N6eqU6VBNnryNKOkrifrzMk1wlKLPra7X2Av 76S/MbFJYEfE5eS9JniAYiw79vcxw133rZwIYpBOmTbIb9OFsVuARBHfhE7Z4jitY5/t a1/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T9GNGuqDkwpVtmJBWmZawmnFCdy5WZmzMewwvkaPOGA=; b=Bzkuml9JahmuDXftRmR8BwaW8owWP6yMahWPAUz7ZAusq/SRRb7rvfzrIPS6PYd0Cp 1xL+WENWiggT7X0NRG4g0ZmWa9nN2D9O0BjJyB30XiQNH/u8sb8w8c8ERNYvCWCEEUNS mrlyqLMYPTITFE1DZ1xfRiy/Jt2OTMaKo/xP6XlPA3LVTJwIALacwUdhGF0lntn9H9S9 6acVEmtNSqzYnNdwgCk1Ym5fHos/te0YHQPYSPmbqr07aPCfj1S0P58YTUCcVXV8RQ3l k2qW7Zh34eX/f7DpfO+LiK+urTk5oEySlAIt15FaI72s2D59KiYPIzCh098gv+YOcPz8 UWuQ== X-Gm-Message-State: APjAAAUg3uHSraieV73QR0s7pUgtOfJMBk6nIL5Tp+HD9MuwbFyDaFDP uExqoAnRv77zUpkzsVno+5mmM8PncIk= X-Google-Smtp-Source: APXvYqxPSZ88RHQlwVdEEOb3PcS/f0KTY+9vSGnxm1A9wf9UoIwWvf6mLe89RWhc0aD050joat9Opw== X-Received: by 2002:a81:578c:: with SMTP id l134mr24992850ywb.157.1556087500436; Tue, 23 Apr 2019 23:31:40 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e81sm3905523ywc.45.2019.04.23.23.31.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:31:40 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 24 Apr 2019 15:30:41 +0900 Message-Id: <20190424063045.14443-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424063045.14443-1-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 07/11] efi_loader: variable: split UEFI variables from U-Boot environment X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" UEFI volatile variables are managed in efi_var_htab while UEFI non-volatile variables are in efi_nv_var_htab. At every SetVariable API, env_efi_save() will also be called to save data cache (hash table) to persistent storage. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_variable.c | 162 ++++++++++++++++++++++++++++++++-- 1 file changed, 155 insertions(+), 7 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 2f489ab9db97..f7b1ce2f3350 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -48,6 +48,115 @@ * converted to utf16? */ +/* + * We will maintain two variable database: one for volatile variables, + * the other for non-volatile variables. The former exists only in memory + * and will go away at re-boot. The latter is currently backed up by the same + * device as U-Boot environment and also works as variables cache. + */ + +enum efi_var_type { + EFI_VAR_TYPE_VOLATILE, + EFI_VAR_TYPE_NON_VOLATILE, +}; + +struct hsearch_data efi_var_htab; +struct hsearch_data efi_nv_var_htab; + +static char *env_efi_get(const char *name, int type) +{ + struct hsearch_data *htab; + ENTRY e, *ep; + + /* WATCHDOG_RESET(); */ + + if (type == EFI_VAR_TYPE_VOLATILE) + htab = &efi_var_htab; + else + htab = &efi_nv_var_htab; + + e.key = name; + e.data = NULL; + hsearch_r(e, FIND, &ep, htab, 0); + + return ep ? ep->data : NULL; +} + +static int env_efi_set(const char *name, const char *value, int type) +{ + struct hsearch_data *htab; + ENTRY e, *ep; + int ret; + + if (type == EFI_VAR_TYPE_VOLATILE) + htab = &efi_var_htab; + else + htab = &efi_nv_var_htab; + + /* delete */ + if (!value || *value == '\0') { + ret = hdelete_r(name, htab, H_PROGRAMMATIC); + return !ret; + } + + /* set */ + e.key = name; + e.data = (char *)value; + hsearch_r(e, ENTER, &ep, htab, H_PROGRAMMATIC); + if (!ep) { + printf("## Error inserting \"%s\" variable, errno=%d\n", + name, errno); + return 1; + } + + return 0; +} + +int efi_variable_import(const char *buf, int check) +{ + env_t *ep = (env_t *)buf; + + if (check) { + u32 crc; + + memcpy(&crc, &ep->crc, sizeof(crc)); + + if (crc32(0, ep->data, CONFIG_ENV_EFI_SIZE) != crc) { + pr_err("bad CRC of UEFI variables\n"); + return -ENOMSG; /* needed for env_load() */ + } + } + + if (himport_r(&efi_nv_var_htab, (char *)ep->data, CONFIG_ENV_EFI_SIZE, + '\0', 0, 0, 0, NULL)) + return 0; + + pr_err("Cannot import environment: errno = %d\n", errno); + + /* set_default_env("import failed", 0); */ + + return -EIO; +} + +/* Export the environment and generate CRC for it. */ +int efi_variable_export(env_t *env_out) +{ + char *res; + ssize_t len; + + res = (char *)env_out->data; + len = hexport_r(&efi_nv_var_htab, '\0', 0, &res, CONFIG_ENV_EFI_SIZE, + 0, NULL); + if (len < 0) { + pr_err("Cannot export environment: errno = %d\n", errno); + return 1; + } + + env_out->crc = crc32(0, env_out->data, CONFIG_ENV_EFI_SIZE); + + return 0; +} + #define PREFIX_LEN (strlen("efi_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx_")) /** @@ -184,7 +293,9 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name, EFI_PRINT("get '%s'\n", native_name); - val = env_get(native_name); + val = env_efi_get(native_name, EFI_VAR_TYPE_VOLATILE); + if (!val) + val = env_efi_get(native_name, EFI_VAR_TYPE_NON_VOLATILE); free(native_name); if (!val) return EFI_EXIT(EFI_NOT_FOUND); @@ -326,7 +437,7 @@ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, u16 *variable_name, const efi_guid_t *vendor) { - char *native_name, *variable; + char *native_name, *variable, *tmp_list, *merged_list; ssize_t name_len, list_len; char regex[256]; char * const regexlist[] = {regex}; @@ -382,10 +493,39 @@ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, efi_cur_variable = NULL; snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_.*"); - list_len = hexport_r(&env_htab, '\n', + list_len = hexport_r(&efi_var_htab, '\n', H_MATCH_REGEX | H_MATCH_KEY, &efi_variables_list, 0, 1, regexlist); - /* 1 indicates that no match was found */ + /* + * Note: '1' indicates that nothing is matched + */ + if (list_len <= 1) { + free(efi_variables_list); + efi_variables_list = NULL; + list_len = hexport_r(&efi_nv_var_htab, '\n', + H_MATCH_REGEX | H_MATCH_KEY, + &efi_variables_list, 0, 1, + regexlist); + } else { + tmp_list = NULL; + list_len = hexport_r(&efi_nv_var_htab, '\n', + H_MATCH_REGEX | H_MATCH_KEY, + &tmp_list, 0, 1, + regexlist); + if (list_len <= 1) { + list_len = 2; /* don't care actual number */ + } else { + /* merge two variables lists */ + merged_list = malloc(strlen(efi_variables_list) + + strlen(tmp_list) + 1); + strcpy(merged_list, efi_variables_list); + strcat(merged_list, tmp_list); + free(efi_variables_list); + free(tmp_list); + efi_variables_list = merged_list; + } + } + if (list_len <= 1) return EFI_EXIT(EFI_NOT_FOUND); @@ -420,6 +560,7 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, char *native_name = NULL, *val = NULL, *s; efi_status_t ret = EFI_SUCCESS; u32 attr; + int type; EFI_ENTRY("\"%ls\" %pUl %x %zu %p", variable_name, vendor, attributes, data_size, data); @@ -435,14 +576,18 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, #define ACCESS_ATTR (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS) + type = (attributes & EFI_VARIABLE_NON_VOLATILE) ? + EFI_VAR_TYPE_NON_VOLATILE : EFI_VAR_TYPE_VOLATILE; if ((data_size == 0) || !(attributes & ACCESS_ATTR)) { /* delete the variable: */ - env_set(native_name, NULL); + env_efi_set(native_name, NULL, type); ret = EFI_SUCCESS; goto out; } - val = env_get(native_name); + val = env_efi_get(native_name, EFI_VAR_TYPE_VOLATILE); + if (!val) + val = env_efi_get(native_name, EFI_VAR_TYPE_NON_VOLATILE); if (val) { parse_attr(val, &attr); @@ -493,9 +638,12 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, EFI_PRINT("setting: %s=%s\n", native_name, val); - if (env_set(native_name, val)) + if (env_efi_set(native_name, val, type)) ret = EFI_DEVICE_ERROR; + /* FIXME: what if save failed? */ + env_efi_save(); + out: free(native_name); free(val); From patchwork Wed Apr 24 06:30:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1089964 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="dkJlmC28"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44prBM4S47z9s3q for ; Wed, 24 Apr 2019 16:34:03 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 1585CC21DA6; Wed, 24 Apr 2019 06:32:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 53296C21E6C; Wed, 24 Apr 2019 06:31:50 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B4630C21DF8; Wed, 24 Apr 2019 06:31:47 +0000 (UTC) Received: from mail-yw1-f65.google.com (mail-yw1-f65.google.com [209.85.161.65]) by lists.denx.de (Postfix) with ESMTPS id ADDCEC21E1B for ; Wed, 24 Apr 2019 06:31:43 +0000 (UTC) Received: by mail-yw1-f65.google.com with SMTP id j4so2556023ywk.11 for ; Tue, 23 Apr 2019 23:31:43 -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=TEgLBZr5Fb4vkACadAWIEXmNBBGpYt1uyJD5mDr+yP8=; b=dkJlmC28aHN3+waT1Xn/xv2esUSB3rDPuhIQTk8SzohsJhC2LorZ2UTwHjF+1AHprc UZKPO6Ow9lMiWKtVFdvJ4HMjZVR+Yprk7NDLmIBl3X2OPgAhBgUaeRqQ7hdnXh7fygHU w1nxAAj/LPtdXeROqfC3B9XBpxO7ewH5IRskxX7/UWwYWTmAJ6WTLBe6hcUOTevDQWcy CyPLol9gwh0vgzIhbdzLQgX5N/7Ir9w/g5t3rn3ruNk7Z/MdmfIackHNCIrop60WD7EK ncFXcMFjDX2PczSRTh/JTCSGb24/ZKjk3bTOgBXS3vaGgIoeoV9ZroF+EQZIIda0QG7X tZQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TEgLBZr5Fb4vkACadAWIEXmNBBGpYt1uyJD5mDr+yP8=; b=Ejk/j7DL+SWs7Iam9M4sWWJCm8sf+j8ohy3LRcBFFRqsJOwJwsJXyXZlH15s2Raov6 bbd7iit5VccLYwN6b24KPymjNtSbkuAk6zCr5xZfRsux3GkYdM+bu5TfxtQE/hzrka9B AncDYHVLGRuYk9Mo+wS2sZFbfAzzSLzNxRiFbUavaPQSm41OC3GuQXwn1ZaJrbIAtvop bDQ4VLCcMV8Y+ZIoa9xgAxdp1l99wZwO+8N8Hn/kZvAjZ67SNHaV2ftT9BJvme/rZGHE 9swmye31lOmmRbyJ737invD2eF0l2J5UEGcoZ2xptHXRpIMpj4a8AtB/xAHIAxJ9mq1l joLw== X-Gm-Message-State: APjAAAW1ixxJv7myDmso9WqrbvHLMJiLDuqQcvmHDGpoXDNEnl5o3vNc eUfCufFW2MS6ysvJkXC/wLPpU13zKi0= X-Google-Smtp-Source: APXvYqwVSGLDoRdfH/iL2qHkatj9T5Ar3KZ0wKKMoTEBv7cg8qJfPGs0cRPD47k+WZRGXgrDyXvmWg== X-Received: by 2002:a81:9bc6:: with SMTP id s189mr23506616ywg.431.1556087502686; Tue, 23 Apr 2019 23:31:42 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h5sm3518337ywe.68.2019.04.23.23.31.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:31:42 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 24 Apr 2019 15:30:42 +0900 Message-Id: <20190424063045.14443-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424063045.14443-1-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 08/11] efi_loader: load saved non-volatile variables at init X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Data cache will be read in from persistent storage after (re)boot to restore UEFI non-volatile variables. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_setup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 05d8d754f4c7..490e3c5eb81a 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -7,6 +7,7 @@ #include #include +#include #if 1 /* TEMPORARILY */ #define DXE_SERVICES_TABLE_GUID \ @@ -96,6 +97,9 @@ efi_status_t efi_init_obj_list(void) if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) return efi_obj_list_initialized; + /* Load non-volatile variables */ + env_efi_load(); + /* Define supported languages */ ret = efi_init_platform_lang(); if (ret != EFI_SUCCESS) From patchwork Wed Apr 24 06:30:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1089967 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YEC70F2n"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44prDP41jhz9s3q for ; Wed, 24 Apr 2019 16:35:49 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 34DDBC21DA1; Wed, 24 Apr 2019 06:34:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 10226C21DFA; Wed, 24 Apr 2019 06:32:48 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6C2E7C21D65; Wed, 24 Apr 2019 06:31:51 +0000 (UTC) Received: from mail-yb1-f193.google.com (mail-yb1-f193.google.com [209.85.219.193]) by lists.denx.de (Postfix) with ESMTPS id 1CB3CC21E42 for ; Wed, 24 Apr 2019 06:31:46 +0000 (UTC) Received: by mail-yb1-f193.google.com with SMTP id v2so4340762ybm.12 for ; Tue, 23 Apr 2019 23:31:46 -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=zN3+qBGekAdfnf8IrQ6mJnJR/yBsANdf1/jDyaEDU3k=; b=YEC70F2nOSl4CBCIs3HgQtdpzofk89fXTAwzWy+u7SMBv0pxXvQ6+ZxN9Iwg3GeWXT 1CqZxJo6WaWo6baEDTIMUrtFnpsJZ9Qft8SfX2WCNYZ4H03sQSn07y1iUZDf7jhpC8lb DUXdXIit589PvIhBiAdwwhJLPUVdxk8ue86jgzmSN5sSx5BvSj+cvmhUBN3YRi5kU44y Wu75E1aceulXFsBWWXjkaZtbRmJcCU4Gb9HD7Vd+kU/rT7RfGPiQZX9oqQdqtNUyyhzn k9PMWK2ZhUqDFSWcZBJOtpLT4aaQNRmbj5X6F/kr/aVtKZuEOQ0D7b6rjsCe4JeLWvIB qJqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zN3+qBGekAdfnf8IrQ6mJnJR/yBsANdf1/jDyaEDU3k=; b=Eutegbd21j7xdtoEql3M5iCw+bkI3+qxLr+Oa66FTDZZKTsOTwhoKyDG1S7x6pPn3/ wFRl7nzi8Y9HqClJP4Vq3cJnY0HcZOYBIlceDsSHksGhrPGh6LIxITspyMbASiyxOBom +hCUMj+X6Lx/LJfIYQbVfQ5Wu7Re/h28IRImJDeKgLtrHcJdu32mMiAqjui9dILBQUQK +1oBMIGds2kroKIGuKnXwYmCoTy2jQ/5C3BmT+rBp8dUpjyUVFxq0LZyo7xWktc6eUeo Nicj4t38iWbFBCqzekMgdae40Fr6fMJR3cJsIjeNVVClwV0x0ksRyiqzl/2husSr4WHb VHkA== X-Gm-Message-State: APjAAAWEoDMsjLmLALM6a/hV9LGGlr6cYBuoLiXRgst4EiWdc2HENY8e rlWy3pigMwAvRBKz/u17mC/hNg== X-Google-Smtp-Source: APXvYqxoPvpSQfZY3VqAMarO7dtDrkfmQOovms995wnUUH6Q38+kPhruRZG92WZMU2b0Pbo4vBW/7g== X-Received: by 2002:a25:1a8b:: with SMTP id a133mr25671169yba.428.1556087505132; Tue, 23 Apr 2019 23:31:45 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 129sm7922692ywv.38.2019.04.23.23.31.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:31:44 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 24 Apr 2019 15:30:43 +0900 Message-Id: <20190424063045.14443-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424063045.14443-1-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 09/11] efi_loader: bootmgr: handle BootNext as non-volatile X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_bootmgr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 4ccba2287572..e8f48684257f 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -206,7 +206,8 @@ efi_status_t efi_bootmgr_load(efi_handle_t *handle) ret = EFI_CALL(efi_set_variable( L"BootNext", (efi_guid_t *)&efi_global_variable_guid, - 0, 0, &bootnext)); + EFI_VARIABLE_NON_VOLATILE, 0, + &bootnext)); /* load BootNext */ if (ret == EFI_SUCCESS) { From patchwork Wed Apr 24 06:30:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1089968 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="AUFkjyvc"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44prDk5Y2rz9s3q for ; Wed, 24 Apr 2019 16:36:06 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 76F21C21E7D; Wed, 24 Apr 2019 06:33:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D0B14C21E39; Wed, 24 Apr 2019 06:32:21 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CCC3AC21E79; Wed, 24 Apr 2019 06:31:54 +0000 (UTC) Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) by lists.denx.de (Postfix) with ESMTPS id 8A1A7C21E2F for ; Wed, 24 Apr 2019 06:31:48 +0000 (UTC) Received: by mail-yb1-f171.google.com with SMTP id q17so6161372ybg.7 for ; Tue, 23 Apr 2019 23:31:48 -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=psnDy9wcXjZhkWCaU4Ta9vvFuXezYTwPoTrIS2I0+nY=; b=AUFkjyvcznFI7pcWA5B4B5kTumMmkyLMeLzovXw5X/XbY2KrmDVlFx0HtMwHOnXBjy OSAZJG5Yup0Lfn44kbPFe/gg6EAcm/wbensNnp3OmLaUSyMT1Kb/w2Votza5WBYGU2wM blcvfFiDoR/ilsqhM8IQmJbEQ8tFmgBDvf0NQO57jh9og2cCg/YGAGDAjLG082bgA4B5 keQ02Pbttc2FJ54equcZgVDX0rUg1K7Hp1UHiHOtLFKs+DUSPgA3dIoGNaxQdQa2H2d1 76eQ8q7QLeJ05U6+AjW1Y2tttB7csxiAxb1b6UwaKtr7QXH5+q9ksklvTs8vuMOC11Y3 w5dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=psnDy9wcXjZhkWCaU4Ta9vvFuXezYTwPoTrIS2I0+nY=; b=LB/ITc85ARCx5t3nLDqv0CLSFhY9XercXoACstqivfisKCVn+1AwoSRa0ZTPiKzp3E vMDVtBqxI+VEf8UTtIGWUocRspFgKwconmtKUWzRNdWocaSBQWWtEx0WAPB9MVcfef1K +dVq5BYP8EBkcJDxIPqVSiXtX5uVBu9/kfkUPDA3Hz+OneHm/tJMBbkYgebT6M29gpiJ BGkXoBBtSMzMKLVpmb2f9YiJzuUU1WO+JinESVgl6MFlO+9KzjWNdEV7EUsU+ouw388Z 9HJIVrSOR/5aA74ahlVZWOkyp9C88JpuMbjvk76rL7BD3iIysHU9VqtRbGxi3XLzS81t l9uQ== X-Gm-Message-State: APjAAAWzrdKRRADH18DWAQYXy+OXzJfMgv7f8Go8JjIfm4P2R7KMFwoH h1feau7QHANN73j+TW1jYexxnKa4Vww= X-Google-Smtp-Source: APXvYqw83ubh+cW5dkEGvYqIDSFBiSJnU0YNUy8B3EBJk1oi3Gg99itQZDEwaurdn5sGzfKUvZkIWA== X-Received: by 2002:a25:c047:: with SMTP id c68mr24035166ybf.409.1556087507499; Tue, 23 Apr 2019 23:31:47 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x189sm2447259ywb.41.2019.04.23.23.31.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:31:46 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 24 Apr 2019 15:30:44 +0900 Message-Id: <20190424063045.14443-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424063045.14443-1-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 10/11] cmd: env: add -nv option for UEFI non-volatile variable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" With this option, -nv, at "setenv -e" command, a variable will be defined as non-volatile. Signed-off-by: AKASHI Takahiro --- cmd/nvedit.c | 3 ++- cmd/nvedit_efi.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 24a6cf7824ad..52c242b4f622 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -1344,8 +1344,9 @@ U_BOOT_CMD_COMPLETE( setenv, CONFIG_SYS_MAXARGS, 0, do_env_set, "set environment variables", #if defined(CONFIG_CMD_NVEDIT_EFI) - "-e name [value ...]\n" + "-e [-nv] name [value ...]\n" " - set UEFI variable 'name' to 'value' ...'\n" + " 'nv' option makes the variable non-volatile\n" " - delete UEFI variable 'name' if 'value' not specified\n" #endif "setenv [-f] name value ...\n" diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index e65b38dbf399..ae0d9c18ad43 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -346,6 +346,7 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) u16 *var_name16 = NULL, *p; size_t len; efi_guid_t guid; + u32 attributes; efi_status_t ret; if (argc == 1) @@ -359,6 +360,16 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_FAILURE; } + attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS; + if (!strcmp(argv[1], "-nv")) { + attributes |= EFI_VARIABLE_NON_VOLATILE; + argc--; + argv++; + if (argc == 1) + return CMD_RET_SUCCESS; + } + var_name = argv[1]; if (argc == 2) { /* delete */ @@ -385,9 +396,7 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) utf8_utf16_strncpy(&p, var_name, len + 1); guid = efi_global_variable_guid; - ret = EFI_CALL(efi_set_variable(var_name16, &guid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, + ret = EFI_CALL(efi_set_variable(var_name16, &guid, attributes, size, value)); ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); out: From patchwork Wed Apr 24 06:30:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1089966 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="pJakCChP"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44prCZ3fkJz9s3q for ; Wed, 24 Apr 2019 16:35:06 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 286BAC21E13; Wed, 24 Apr 2019 06:33:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 653D4C21E7F; Wed, 24 Apr 2019 06:32:25 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7215FC21DA1; Wed, 24 Apr 2019 06:31:55 +0000 (UTC) Received: from mail-yw1-f67.google.com (mail-yw1-f67.google.com [209.85.161.67]) by lists.denx.de (Postfix) with ESMTPS id B8D5DC21E70 for ; Wed, 24 Apr 2019 06:31:50 +0000 (UTC) Received: by mail-yw1-f67.google.com with SMTP id t79so4778407ywc.7 for ; Tue, 23 Apr 2019 23:31:50 -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=ePWknoZBDfvXadtgTZb6Qev26kWt4IQJdgpZLqStZWQ=; b=pJakCChP7lwQ8R6SrL9Eyh7z1Unr8WdZ8vZa/PMq57USxi92EqzvMBGzkRkS8ATHJA goG9UwN24Jv5ySEfQq8r+W/jnn2hq01/N26/l9MEbcBcgyJSwZJtenCrqWjft7FgWsmp 1J/HfQitAw5EEp1A7dqle5L6eBTVpWVdyzAHXZ94cfW2QAAKMu8g728EYoHtV3uHAMT2 s8bkWtVu1rQA0KXYWCnQY4nupJZgKzCVi1b+9+gFUXNKyZF6GoPdCy/mDqUO6Nxm02Bk QEjOcw6dsI7Rsnw1YlJ20TX4vslxO+p0EtDG9isZGnv7TxNlfN74fseew+6c+j2BBKSA 9eZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ePWknoZBDfvXadtgTZb6Qev26kWt4IQJdgpZLqStZWQ=; b=oKzTCK1n+i+L9cLf2f4hgiMsSc15jrj4B36tEJ1+Wv5fYl0YicczVkSbaBD+SQSzOS kzEzol6MOxRUBp0pkwwXX5Q9OdJOHzekFi9PCiJKrRsJXNhEHtWdPDjmUTPElHh0hAdB w8tzEaLcNFbaEXqq4g9mt5B7om6TDber8dbYEHwZ9ogSIfRa3j7j8FHGyKJKsgTuTJ4A RdEAGczQSPWVFLXDaFy5htv5kCVwu2ssq1GhwgCYC68MOxDOcpi+uw1bmJXnqoXYmjEc g9JtLUT+j/nKxhzz1b+ha335UumRza6OBvCqGLLCaIS/uTaY9i+9b6rlcui1Bz6lb4hb DRPQ== X-Gm-Message-State: APjAAAXnv4VowcyR/gZMQG3pwByIJuvrNOSYO6tlGqb3fcLxZG5/1WeV sZ5Drpc3i7z9y7q9j2teGNBe4g== X-Google-Smtp-Source: APXvYqwHBh1Vhpo0jCYc02LgmWWhI3NvG62tRctHJDk/D/Be3jx406RGOc/w93ZJMe7Dt9xosrDFZQ== X-Received: by 2002:a81:6c04:: with SMTP id h4mr24314031ywc.170.1556087509758; Tue, 23 Apr 2019 23:31:49 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 143sm8727147yws.92.2019.04.23.23.31.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:31:49 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 24 Apr 2019 15:30:45 +0900 Message-Id: <20190424063045.14443-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424063045.14443-1-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 11/11] cmd: efidebug: make some boot variables non-volatile X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Boot####, BootOrder and BootNext should be non-volatile. Signed-off-by: AKASHI Takahiro --- cmd/efidebug.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 8890dd7268f1..ff3cad53f1b7 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -554,6 +554,7 @@ static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag, } ret = EFI_CALL(RT->set_variable(var_name16, &guid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, data)); @@ -911,6 +912,7 @@ static int do_efi_boot_next(cmd_tbl_t *cmdtp, int flag, guid = efi_global_variable_guid; size = sizeof(u16); ret = EFI_CALL(RT->set_variable(L"BootNext", &guid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, &bootnext)); @@ -966,6 +968,7 @@ static int do_efi_boot_order(cmd_tbl_t *cmdtp, int flag, guid = efi_global_variable_guid; ret = EFI_CALL(RT->set_variable(L"BootOrder", &guid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, bootorder));