From patchwork Tue Jun 4 06:52:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1109643 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="kjmFx88/"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45J2f84ZFlz9s1c for ; Tue, 4 Jun 2019 16:52:00 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 4D379C21C2C; Tue, 4 Jun 2019 06:51:52 +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 1B3B3C21DB6; Tue, 4 Jun 2019 06:51:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3D73DC21D74; Tue, 4 Jun 2019 06:51:38 +0000 (UTC) Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by lists.denx.de (Postfix) with ESMTPS id 29370C21D8A for ; Tue, 4 Jun 2019 06:51:35 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id f97so7963290plb.5 for ; Mon, 03 Jun 2019 23:51:35 -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=tlhfh197dH6PkfXZCHBwwzOYm30N2AGQ9L9TAXPtzMM=; b=kjmFx88/7NWzPl+GfmV7Cww1ptquS2wQystKIGdqWPkOx3pI1ZC4Ksbb3t4ZVrv6h2 nAno8smodyuwueS1QO6rTIeVJSjQsxtifh7Dj733ON4mbxWeocGsjnfAXG6HG+RLT180 uQycV86h7bla1qQ5Ffi561BZUESRSwJNJVowOhJb14wFHbFy9+OubGJylx4MqAszybWn t1ZxBBo26Ip/QA2EYYTW0gP1DLrElxt9Q5DmT5JAY88wZ7Sta5HLzyruFku0ojiySAF7 Sgu/+oUCNZ4qc591RYk0T16FmrHChvXcWqOdYeFOREioEX+7p+7CEMRPP9wGH/j5Vwv0 JjBw== 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=tlhfh197dH6PkfXZCHBwwzOYm30N2AGQ9L9TAXPtzMM=; b=aKJC74jp8RPfS3kF+kySLCTZS5ogxA7d0QMmA9DcPGpQjN8FS4aO3XwDKA5zVgJx+6 qznv7cx4qO9ZyABjVTaFGLecrY7mKMfCxCzytXUpgqrZoYwBF18b7IX5wdkayFItLCrm o5wRa+Pqm9+kyGwd7sKTr8dJmIS5+AAYeAJtJrwnbognBYGYWtqjEh/FQQbrFkfGeiSX L8tJRjCKkA4xD9gNe3+RJoSgNiaN5+UJ8KM1PsilR9QObP22oQVB0Q1TRWZuWMOaMlAy 3+0VWTKWe/79RAoB6GacT7qbShKAPvy0AAKBLEfSiHaDDEF0Zgm1iyx//P1tN9iiebrf GjKA== X-Gm-Message-State: APjAAAXn1HO37rAwh1JzCGLcq4SMLoXKYHuBvGVfydKJRWMic4W8d8Kb uWnakyKyDfWBQU1pcUHd62uepA== X-Google-Smtp-Source: APXvYqwtp2uZKakueCPHzeuhz0k8CUxaL/+4HdiqMZBlmpdVMltsxvexF1mMwi78UBugH8s/TPZ5Cw== X-Received: by 2002:a17:902:e311:: with SMTP id cg17mr34604150plb.202.1559631093665; Mon, 03 Jun 2019 23:51:33 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 14sm14617975pgp.37.2019.06.03.23.51.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2019 23:51:32 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Tue, 4 Jun 2019 15:52:05 +0900 Message-Id: <20190604065211.15907-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190604065211.15907-1-takahiro.akashi@linaro.org> References: <20190604065211.15907-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 1/7] 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 | 39 ++++++++ env/env.c | 155 +++++++++++++++++++++++++++++- env/fat.c | 105 ++++++++++++++++++++ include/asm-generic/global_data.h | 3 + include/environment.h | 31 ++++++ 5 files changed, 332 insertions(+), 1 deletion(-) diff --git a/env/Kconfig b/env/Kconfig index 1e10c7a4c46b..a36b6ee48f10 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -399,6 +399,10 @@ config ENV_IS_IN_UBI the environment in. This will enable redundant environments in UBI. It is assumed that both volumes are in the same MTD partition. +config ENV_EFI + bool + default n + config ENV_FAT_INTERFACE string "Name of the block device for the environment" depends on ENV_IS_IN_FAT @@ -438,6 +442,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 ENV_EFI + 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 ENV_EFI + 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 +502,13 @@ 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" + depends on ENV_EFI + default 0x20000 + help + Size of the UEFI variables storage area + if ARCH_ROCKCHIP || ARCH_SUNXI || ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_VERSAL || ARC || ARCH_STM32MP config ENV_OFFSET diff --git a/env/env.c b/env/env.c index 4b417b90a291..202079f6d4c0 100644 --- a/env/env.c +++ b/env/env.c @@ -24,6 +24,12 @@ void env_fix_drivers(void) entry->load += gd->reloc_off; if (entry->save) entry->save += gd->reloc_off; +#ifdef CONFIG_ENV_EFI + if (entry->efi_load) + entry->efi_load += gd->reloc_off; + if (entry->efi_save) + entry->efi_save += gd->reloc_off; +#endif if (entry->init) entry->init += gd->reloc_off; } @@ -125,7 +131,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 +287,149 @@ int env_init(void) return ret; } + +#ifdef CONFIG_ENV_EFI +struct hsearch_data efi_var_htab; +struct hsearch_data efi_nv_var_htab; + +int env_efi_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 - ENV_HEADER_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 - ENV_HEADER_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; +} + +int env_efi_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 - ENV_HEADER_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 - ENV_HEADER_SIZE); + + return 0; +} + +int env_efi_save(void) +{ +#ifdef CONFIG_ENV_IS_NOWHERE + return 0; +#else + struct env_driver *drv = NULL; + int ret; + + if (!efi_nv_var_htab.table) + return 0; + + if (gd->env_efi_prio == -1) { + pr_warn("No UEFI non-volatile variable storage\n"); + return -1; + } + + drv = _env_driver_lookup(env_get_location(ENVOP_EFI, gd->env_efi_prio)); + if (!drv) { + pr_warn("No UEFI non-volatile variable storage\n"); + return -1; + } + + ret = drv->efi_save(); + if (ret) + pr_err("Saving UEFI non-volatile variable failed\n"); + + return ret; +#endif +} + +/* This function should be called only once at init */ +int env_efi_load(void) +{ +#ifndef CONFIG_ENV_IS_NOWHERE + struct env_driver *drv; + int prio; + enum env_location loc; +#endif + int ret; + + /* volatile variables */ + if (!efi_var_htab.table) { + ret = himport_r(&efi_var_htab, NULL, 0, '\0', 0, 0, 0, NULL); + if (!ret) { + pr_err("Creating UEFI volatile variables failed\n"); + return -1; + } + } + +#ifndef CONFIG_ENV_IS_NOWHERE + gd->env_efi_prio = -1; + + /* non-volatile variables */ + if (efi_nv_var_htab.table) + return 0; + + for (drv = NULL, 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)) { + pr_warn("No UEFI non-volatile variable storage\n"); + goto skip_load; + } + + gd->env_efi_prio = prio; + + ret = drv->efi_load(); + if (ret) { + pr_err("Loading UEFI non-volatile variables failed\n"); + return -1; + } +skip_load: +#endif /* CONFIG_ENV_IS_NOWHERE */ + + if (!efi_nv_var_htab.table) { + ret = himport_r(&efi_nv_var_htab, NULL, 0, '\0', 0, 0, 0, NULL); + if (!ret) { + pr_err("Creating UEFI non-volatile variables failed\n"); + return -1; + } + + return 0; + } + + return 0; +} +#endif /* CONFIG_ENV_EFI */ diff --git a/env/fat.c b/env/fat.c index 7f74c64dfe7e..7cd6dc51baea 100644 --- a/env/fat.c +++ b/env/fat.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -128,6 +129,106 @@ err_env_relocate: } #endif /* LOADENV */ +#ifdef CONFIG_ENV_EFI +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 = env_efi_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 env_efi_import(buf, 1); + else + return 0; + +err_env_relocate: + + return -EIO; +} +#endif /* CONFIG_ENV_EFI */ + U_BOOT_ENV_LOCATION(fat) = { .location = ENVL_FAT, ENV_NAME("FAT") @@ -137,4 +238,8 @@ U_BOOT_ENV_LOCATION(fat) = { #ifdef CMD_SAVEENV .save = env_save_ptr(env_fat_save), #endif +#ifdef CONFIG_ENV_EFI + .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 02a3ed683821..5ed390cc31c7 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -52,6 +52,9 @@ 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 */ +#ifdef CONFIG_ENV_EFI + int env_efi_prio; /* Priority of the UEFI variables */ +#endif 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..32a03014690f 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,26 @@ struct env_driver { */ int (*save)(void); +#ifdef CONFIG_ENV_EFI + /** + * 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); +#endif + /** * init() - Set up the initial pre-relocation environment * @@ -312,6 +333,16 @@ 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_ENV_EFI +extern struct hsearch_data efi_var_htab; +extern struct hsearch_data efi_nv_var_htab; + +int env_efi_import(const char *buf, int check); +int env_efi_export(env_t *env_out); +int env_efi_load(void); +int env_efi_save(void); +#endif + #endif /* DO_DEPS_ONLY */ #endif /* _ENVIRONMENT_H_ */ From patchwork Tue Jun 4 06:52:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1109647 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="H7ZNz0iu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45J2hj2Vsbz9s3l for ; Tue, 4 Jun 2019 16:54:13 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E2F80C21DC1; Tue, 4 Jun 2019 06:52:50 +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 E3FF9C21DF8; Tue, 4 Jun 2019 06:51:58 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9C1C6C21DFB; Tue, 4 Jun 2019 06:51:41 +0000 (UTC) Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by lists.denx.de (Postfix) with ESMTPS id ABA34C21DDC for ; Tue, 4 Jun 2019 06:51:37 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id g21so7963354plq.0 for ; Mon, 03 Jun 2019 23:51:37 -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=9KGHT5t69vD82f32LPJVCpkKVUUPV1FRaPgYlc4P9tg=; b=H7ZNz0iuRacbMf6UVUUk4NwR/IFAtG4sWSANkpLRpQBT2YF1b+kvx1OoRLpzfOuv0Q MtE+Bw7vDRb5gWSwFZz0k8z6DnQtdi2g5SdrrmOzTEdZZOJq/jDuQA0Zdq+YZWy63d7T mA/lT3eutJ2wQqse+rVZneaXhUjyNa0tDWZ+iRsLXzrgsKyfcNf/JOi/JwzIOXaDqWLa Mtw2O8H0Fz8+zWlhJWqHS5ElSSq3w2PAX/sk9KhK6u9Gc76zMnCldDAJLK/ZB1xvVvil geCNOMASqAUsuikMsSM11Ad2lb83VTCY+adzkhTsFPLwdc1H1OEJsiBz0h6VrYlrlMDW tgUA== 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=9KGHT5t69vD82f32LPJVCpkKVUUPV1FRaPgYlc4P9tg=; b=ruIGb24/edhn6BOo3KY6Q55285rOfTOpXf4183GzP/hmS4yD9Xfx3HlCKTG9Cu66JI +79mSg4kDRWDJ31vL0FdqvQ6OdLKxml1Tt843JOYzczLGdSUZe+HtC1v/wctPCpSlhtx sjmohgz5Jf5lkMOqSiGvWTTRRAeIKX9twLdE4J0GSk268/73Z9GFVsyc86TbJ0djHN2+ 1/9j2XXLnI8WScy0c8YdhG/wKuAb0k8lmWIADjBuUreqsRgR8OxlOt5jFcNjnLAMH0eX y6MlUiH154IXVJMZMxcEiPo0XNktDRN0IZW7nUQdQuEUlPmv0CKW9vH5JxKuLjcsSdUO lHxA== X-Gm-Message-State: APjAAAU40Xv3mdsCiEs7YoWIesA0LENw6oinXAnxv4PNRY3JcEQSMev3 J0neQZdxDP/ePXrAQkXvsgbDTA== X-Google-Smtp-Source: APXvYqw9AcBU5W1FfNx0n+lyVwyP2CPu9Zi+izR8PQtOHO5uHVjZSGHjBhGX0ZBee6u+yBjPa/v7dw== X-Received: by 2002:a17:902:d715:: with SMTP id w21mr34970160ply.234.1559631096408; Mon, 03 Jun 2019 23:51:36 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e19sm10136256pfd.7.2019.06.03.23.51.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2019 23:51:35 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Tue, 4 Jun 2019 15:52:06 +0900 Message-Id: <20190604065211.15907-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190604065211.15907-1-takahiro.akashi@linaro.org> References: <20190604065211.15907-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 2/7] 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 Reviewed-by: Heinrich Schuchardt --- 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 50bc10537f40..e56053194dae 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"))) { @@ -468,7 +470,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; @@ -480,12 +482,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 Tue Jun 4 06:52:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1109645 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="LSHX6Lvu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45J2gV65crz9s4Y for ; Tue, 4 Jun 2019 16:53:10 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 629B3C21D8A; Tue, 4 Jun 2019 06:52: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 453A5C21DFD; Tue, 4 Jun 2019 06:51:56 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 54135C21C2C; Tue, 4 Jun 2019 06:51:44 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id CBBE3C21DA2 for ; Tue, 4 Jun 2019 06:51:40 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id 20so9774925pgr.4 for ; Mon, 03 Jun 2019 23:51:40 -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=HwgIn09nD2AMx0HJtzQe5VuPY6R4bhEJ9u5AVpXT5VI=; b=LSHX6LvuFEsK77bBHgRKiltQMqUl/pYcpuDALRpbkiV9DudnLYT5A1ivJMBkUmYjvE cbzfqKQpIgJPc9xoRhB4ER1qvHLcm37aa05BawUcgs5z94SWM+SDFcQ/0z8dT8FE61ab e+Qc1Q89qp0t5TTwFO8FnubrqBohaDimjslgQqfwtwh3MMKUE51Wr9qloMc1YagNSvx1 bkmAGbTZH4fPqSoZ3lp3r2915j1yh5NDk9edDo55P/Z4pZFNt8Qg85WVsSC4trICC4Ww fIWXuWiaR3BlrqD6Zi5iCA7vD9w1rUKNUe771lL/Q2ov8+h9piKjSobV/v0Zxer3OTYz SsbQ== 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=HwgIn09nD2AMx0HJtzQe5VuPY6R4bhEJ9u5AVpXT5VI=; b=iPqf9gDHA4qB6oI9xfIu14/GhqzUVF6YfT4iT/TWW0vCFKhA0ecqdiyYrLS8+EWtzX mRt90aG1k94O1XVgL9AIxtW5+c9VpjtxtSZZbJKKY1zxloFl0PywnwZSqW0r1Zj99oY+ 2T7LscLFMfri0mng0+hHh1736F4XotI2uSIHty/joYphzB18JzA0ZsDQH+Y39I7AFtOr QvNQln+3BnmZ+PL2sbfJ6L7igyn4Q+uQ7f1CIyeSeX2Ho4lJnS1bf9fRTdcvkfTNUSvN S6qZLhySLrbfCScnu/qm2/PclzZqKbUPlSDwweUZ2QxbdGwQeGDiIRrlvefxMIsYkWF9 szOQ== X-Gm-Message-State: APjAAAXOpbUKlbqvQZR5HwoIlZoGjKMoLd+D2wJpUTPRtNmIeXqg4EJf gP+YFfhnKsO7ycrDkNTJyCjw7cUkBtI= X-Google-Smtp-Source: APXvYqzGn2QN7pib0WCF/eNausdQgmG5Nvs+kpmrabrfhEA7lX2bxHhkpOcKEVPxUbLCVteWgrh0/w== X-Received: by 2002:a63:1316:: with SMTP id i22mr34528668pgl.274.1559631099276; Mon, 03 Jun 2019 23:51:39 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g3sm19590417pfm.150.2019.06.03.23.51.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2019 23:51:38 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Tue, 4 Jun 2019 15:52:07 +0900 Message-Id: <20190604065211.15907-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190604065211.15907-1-takahiro.akashi@linaro.org> References: <20190604065211.15907-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 3/7] 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/Kconfig | 10 + lib/efi_loader/efi_variable.c | 342 ++++++++++++++++++++++++++-------- 2 files changed, 275 insertions(+), 77 deletions(-) diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index cd5436c576b1..8bf4b1754d06 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -18,6 +18,16 @@ config EFI_LOADER if EFI_LOADER +choice + prompt "Select variables storage" + default EFI_VARIABLE_USE_ENV + +config EFI_VARIABLE_USE_ENV + bool "Same device as U-Boot environment" + select ENV_EFI + +endchoice + config EFI_GET_TIME bool "GetTime() runtime service" depends on DM_RTC diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index e56053194dae..d9887be938c2 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -48,6 +48,66 @@ * 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. + * + * struct hsearch_data efi_var_htab + * struct hsearch_data efi_nv_var_htab + */ + +static char *env_efi_get(const char *name, bool is_non_volatile) +{ + struct hsearch_data *htab; + ENTRY e, *ep; + + /* WATCHDOG_RESET(); */ + + if (is_non_volatile) + htab = &efi_nv_var_htab; + else + htab = &efi_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, + bool is_non_volatile) +{ + struct hsearch_data *htab; + ENTRY e, *ep; + int ret; + + if (is_non_volatile) + htab = &efi_nv_var_htab; + else + htab = &efi_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; +} + #define PREFIX_LEN (strlen("efi_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx_")) /** @@ -147,24 +207,12 @@ static const char *parse_attr(const char *str, u32 *attrp) return str; } -/** - * efi_efi_get_variable() - retrieve value of a UEFI variable - * - * This function implements the GetVariable runtime service. - * - * See the Unified Extensible Firmware Interface (UEFI) specification for - * details. - * - * @variable_name: name of the variable - * @vendor: vendor GUID - * @attributes: attributes of the variable - * @data_size: size of the buffer to which the variable value is copied - * @data: buffer to which the variable value is copied - * Return: status code - */ -efi_status_t EFIAPI efi_get_variable(u16 *variable_name, - const efi_guid_t *vendor, u32 *attributes, - efi_uintn_t *data_size, void *data) +static +efi_status_t EFIAPI efi_get_variable_common(u16 *variable_name, + const efi_guid_t *vendor, + u32 *attributes, + efi_uintn_t *data_size, void *data, + bool is_non_volatile) { char *native_name; efi_status_t ret; @@ -172,22 +220,19 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name, const char *val, *s; u32 attr; - EFI_ENTRY("\"%ls\" %pUl %p %p %p", variable_name, vendor, attributes, - data_size, data); - if (!variable_name || !vendor || !data_size) return EFI_EXIT(EFI_INVALID_PARAMETER); ret = efi_to_native(&native_name, variable_name, vendor); if (ret) - return EFI_EXIT(ret); + return ret; EFI_PRINT("get '%s'\n", native_name); - val = env_get(native_name); + val = env_efi_get(native_name, is_non_volatile); free(native_name); if (!val) - return EFI_EXIT(EFI_NOT_FOUND); + return EFI_NOT_FOUND; val = parse_attr(val, &attr); @@ -198,7 +243,7 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name, /* number of hexadecimal digits must be even */ if (len & 1) - return EFI_EXIT(EFI_DEVICE_ERROR); + return EFI_DEVICE_ERROR; /* two characters per byte: */ len /= 2; @@ -210,10 +255,10 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name, } if (!data) - return EFI_EXIT(EFI_INVALID_PARAMETER); + return EFI_INVALID_PARAMETER; if (hex2bin(data, s, len)) - return EFI_EXIT(EFI_DEVICE_ERROR); + return EFI_DEVICE_ERROR; EFI_PRINT("got value: \"%s\"\n", s); } else if ((s = prefix(val, "(utf8)"))) { @@ -227,7 +272,7 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name, } if (!data) - return EFI_EXIT(EFI_INVALID_PARAMETER); + return EFI_INVALID_PARAMETER; memcpy(data, s, len); ((char *)data)[len] = '\0'; @@ -235,13 +280,67 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name, EFI_PRINT("got value: \"%s\"\n", (char *)data); } else { EFI_PRINT("invalid value: '%s'\n", val); - return EFI_EXIT(EFI_DEVICE_ERROR); + return EFI_DEVICE_ERROR; } out: if (attributes) *attributes = attr & EFI_VARIABLE_MASK; + return ret; +} + +static +efi_status_t EFIAPI efi_get_volatile_variable(u16 *variable_name, + const efi_guid_t *vendor, + u32 *attributes, + efi_uintn_t *data_size, + void *data) +{ + return efi_get_variable_common(variable_name, vendor, attributes, + data_size, data, false); +} + +efi_status_t EFIAPI efi_get_nonvolatile_variable(u16 *variable_name, + const efi_guid_t *vendor, + u32 *attributes, + efi_uintn_t *data_size, + void *data) +{ + return efi_get_variable_common(variable_name, vendor, attributes, + data_size, data, true); +} + +/** + * efi_efi_get_variable() - retrieve value of a UEFI variable + * + * This function implements the GetVariable runtime service. + * + * See the Unified Extensible Firmware Interface (UEFI) specification for + * details. + * + * @variable_name: name of the variable + * @vendor: vendor GUID + * @attributes: attributes of the variable + * @data_size: size of the buffer to which the variable value is copied + * @data: buffer to which the variable value is copied + * Return: status code + */ +efi_status_t EFIAPI efi_get_variable(u16 *variable_name, + const efi_guid_t *vendor, u32 *attributes, + efi_uintn_t *data_size, void *data) +{ + efi_status_t ret; + + EFI_ENTRY("\"%ls\" %pUl %p %p %p", variable_name, vendor, attributes, + data_size, data); + + ret = efi_get_volatile_variable(variable_name, vendor, attributes, + data_size, data); + if (ret == EFI_NOT_FOUND) + ret = efi_get_nonvolatile_variable(variable_name, vendor, + attributes, data_size, data); + return EFI_EXIT(ret); } @@ -331,7 +430,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}; @@ -387,10 +486,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); @@ -403,77 +531,71 @@ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, return EFI_EXIT(ret); } -/** - * efi_efi_set_variable() - set value of a UEFI variable - * - * This function implements the SetVariable runtime service. - * - * See the Unified Extensible Firmware Interface (UEFI) specification for - * details. - * - * @variable_name: name of the variable - * @vendor: vendor GUID - * @attributes: attributes of the variable - * @data_size: size of the buffer with the variable value - * @data: buffer with the variable value - * Return: status code - */ -efi_status_t EFIAPI efi_set_variable(u16 *variable_name, - const efi_guid_t *vendor, u32 attributes, - efi_uintn_t data_size, const void *data) +static +efi_status_t EFIAPI efi_set_variable_common(u16 *variable_name, + const efi_guid_t *vendor, + u32 attributes, + efi_uintn_t data_size, + const void *data, + bool is_non_volatile) { char *native_name = NULL, *val = NULL, *s; - efi_status_t ret = EFI_SUCCESS; + efi_uintn_t size; u32 attr; - - EFI_ENTRY("\"%ls\" %pUl %x %zu %p", variable_name, vendor, attributes, - data_size, data); + efi_status_t ret = EFI_SUCCESS; /* TODO: implement APPEND_WRITE */ if (!variable_name || !vendor || (attributes & EFI_VARIABLE_APPEND_WRITE)) { ret = EFI_INVALID_PARAMETER; - goto out; + goto err; } ret = efi_to_native(&native_name, variable_name, vendor); if (ret) - goto out; + goto err; #define ACCESS_ATTR (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS) - if ((data_size == 0) || !(attributes & ACCESS_ATTR)) { - /* delete the variable: */ - env_set(native_name, NULL); - ret = EFI_SUCCESS; - goto out; + /* check if a variable exists */ + size = 0; + ret = EFI_CALL(efi_get_variable(variable_name, vendor, &attr, + &size, NULL)); + if (ret == EFI_BUFFER_TOO_SMALL) { + if ((is_non_volatile && !(attr & EFI_VARIABLE_NON_VOLATILE)) || + (!is_non_volatile && (attr & EFI_VARIABLE_NON_VOLATILE))) { + ret = EFI_INVALID_PARAMETER; + goto err; + } } - val = env_get(native_name); - if (val) { - parse_attr(val, &attr); - - /* We should not free val */ - val = NULL; - if (attr & READ_ONLY) { - ret = EFI_WRITE_PROTECTED; + /* delete a variable */ + if (data_size == 0 || !(attributes & ACCESS_ATTR)) { + if (size) { + if (attr & READ_ONLY) { + ret = EFI_WRITE_PROTECTED; + goto err; + } goto out; } + ret = EFI_SUCCESS; + goto err; /* not error, but nothing to do */ + } + /* create/modify a variable */ + if (size && attr != attributes) { /* * attributes won't be changed * TODO: take care of APPEND_WRITE once supported */ - if (attr != attributes) { - ret = EFI_INVALID_PARAMETER; - goto out; - } + ret = EFI_INVALID_PARAMETER; + goto err; } val = malloc(2 * data_size + strlen("{ro,run,boot,nv}(blob)") + 1); if (!val) { ret = EFI_OUT_OF_RESOURCES; - goto out; + goto err; } s = val; @@ -487,7 +609,7 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, EFI_VARIABLE_RUNTIME_ACCESS); s += sprintf(s, "{"); while (attributes) { - u32 attr = 1 << (ffs(attributes) - 1); + attr = 1 << (ffs(attributes) - 1); if (attr == EFI_VARIABLE_NON_VOLATILE) s += sprintf(s, "nv"); @@ -509,12 +631,78 @@ 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)) +out: + ret = EFI_SUCCESS; + if (env_efi_set(native_name, val, is_non_volatile)) ret = EFI_DEVICE_ERROR; -out: +err: free(native_name); free(val); + return ret; +} + +static +efi_status_t EFIAPI efi_set_volatile_variable(u16 *variable_name, + const efi_guid_t *vendor, + u32 attributes, + efi_uintn_t data_size, + const void *data) +{ + return efi_set_variable_common(variable_name, vendor, attributes, + data_size, data, false); +} + +efi_status_t EFIAPI efi_set_nonvolatile_variable(u16 *variable_name, + const efi_guid_t *vendor, + u32 attributes, + efi_uintn_t data_size, + const void *data) +{ + efi_status_t ret; + + ret = efi_set_variable_common(variable_name, vendor, attributes, + data_size, data, true); + if (ret == EFI_SUCCESS) + /* FIXME: what if save failed? */ + if (env_efi_save()) + ret = EFI_DEVICE_ERROR; + + return ret; +} + +/** + * efi_efi_set_variable() - set value of a UEFI variable + * + * This function implements the SetVariable runtime service. + * + * See the Unified Extensible Firmware Interface (UEFI) specification for + * details. + * + * @variable_name: name of the variable + * @vendor: vendor GUID + * @attributes: attributes of the variable + * @data_size: size of the buffer with the variable value + * @data: buffer with the variable value + * Return: status code + */ +efi_status_t EFIAPI efi_set_variable(u16 *variable_name, + const efi_guid_t *vendor, u32 attributes, + efi_uintn_t data_size, const void *data) +{ + efi_status_t ret; + + EFI_ENTRY("\"%ls\" %pUl %x %zu %p", variable_name, vendor, attributes, + data_size, data); + + if (attributes & EFI_VARIABLE_NON_VOLATILE) + ret = efi_set_nonvolatile_variable(variable_name, vendor, + attributes, + data_size, data); + else + ret = efi_set_volatile_variable(variable_name, vendor, + attributes, data_size, data); + return EFI_EXIT(ret); } From patchwork Tue Jun 4 06:52:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1109644 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="zpciHrvX"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45J2fw6kN8z9s3l for ; Tue, 4 Jun 2019 16:52:40 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id DD925C21DD3; Tue, 4 Jun 2019 06:52: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=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 CCED7C21D72; Tue, 4 Jun 2019 06:51:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 62C25C21C29; Tue, 4 Jun 2019 06:51:44 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by lists.denx.de (Postfix) with ESMTPS id 3B983C21DCA for ; Tue, 4 Jun 2019 06:51:43 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id v11so9763252pgl.5 for ; Mon, 03 Jun 2019 23:51: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=5P3SIlBk4tkjqvPt2LSKhy2xXlpXcBsZObqeFMT9d8s=; b=zpciHrvXuUcNRkAPxNWoTui8sh6Kl8+8OHVu4+wpGzq6O7jv8KtU0MAVhTLWOaUL2Q EHBKspGwNTuKqn5HD3FniQSIQoaBqYBjk+LmHf3crH5WEtIpsFZgAr6sU68y9eCvdyyh CTfiJW3mFLbsdqY36JD/HTn/8yZbR0xirwVh3ASU0EuLCCVohG7/0YIOFZBrBoewx9cD a5csC2Hj6oUh1BBTeWHRgIzCsZqf0AVqa2mkN7ByOqM1cjV0g9cinNAKF6S5kJRN0rPh 34t2SBRxYmy3gfrJgtJ4Vd4ogMRqMPNkwNE8jZHJHvLy2YiK8BnmfrpwfsvZIMzT5rhs 5wYA== 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=5P3SIlBk4tkjqvPt2LSKhy2xXlpXcBsZObqeFMT9d8s=; b=Vs/YOZbBOdXrHuOXm9URKMtNVADkxIqjm8YNIP9qqxalAyafT2fu8hilRWVrR842Kg uMt1AOzJkhFCfeDkbq5EA+4XID7bHosYhtti968te7PLLLWILBf23N6EtIR4j1oc0Tax rpjhV64eWU0tG7yJwZssyzDOSoNrTtiYqcPcRQxK/ylBJzR7OEGII4XWORp5Z2uQpyQB chxyINFxf8M6x+X2iGF+N4hYeH7QopZMGZG2d2pKyq3Xa/KWEBa18HhStdtlw4ndf6J+ WcdMfZw9tr7bY7+/fD1WPsvm23frxXt0tgZsRqd0dNFe85PKgTBXNGW4nT93Ycm6pinC Coxg== X-Gm-Message-State: APjAAAXPYiSyrKU4+5j1CjJmT0zL7WtgTuGCeFFatkMLrJXyhIiHnUig Hr3AERqDr9Lv2tRg2o5D+E+Ykg== X-Google-Smtp-Source: APXvYqy57hbrIkNMaZ6+COPZfAfYNOPsLWvGiiibe2CtoH5QSAMVTm3kjVU+qdZQaOkqq7AFaXgELw== X-Received: by 2002:aa7:80d2:: with SMTP id a18mr1033858pfn.152.1559631101965; Mon, 03 Jun 2019 23:51:41 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l63sm17777641pfl.181.2019.06.03.23.51.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2019 23:51:41 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Tue, 4 Jun 2019 15:52:08 +0900 Message-Id: <20190604065211.15907-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190604065211.15907-1-takahiro.akashi@linaro.org> References: <20190604065211.15907-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 4/7] 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 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 8691d686d29d..45d6aca051f3 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -8,6 +8,7 @@ #include #include #include +#include #define OBJ_LIST_NOT_INITIALIZED 1 @@ -102,6 +103,11 @@ efi_status_t efi_init_obj_list(void) /* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */ switch_to_non_secure_mode(); +#ifdef CONFIG_EFI_VARIABLE_USE_ENV + /* Load non-volatile variables */ + env_efi_load(); +#endif + /* Define supported languages */ ret = efi_init_platform_lang(); if (ret != EFI_SUCCESS) From patchwork Tue Jun 4 06:52:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1109649 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="k7ngRMaD"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45J2hn13Kdz9s4Y for ; Tue, 4 Jun 2019 16:54:17 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D963BC21C2C; Tue, 4 Jun 2019 06:53:15 +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 48BAEC21D74; Tue, 4 Jun 2019 06:52:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 31F2DC21DFA; Tue, 4 Jun 2019 06:51:46 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id ECA94C21DD4 for ; Tue, 4 Jun 2019 06:51:45 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id 196so9771869pgc.6 for ; Mon, 03 Jun 2019 23:51:45 -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=x1dleHcA8JrBStR3zcVbkd9yW2rFEPUaq3Nu/wTM+CA=; b=k7ngRMaD9ur9k3+qAG7XwvHmTfM6nX3pTCTSL+Lt+KhEHOs9auWPGfAhT3sT6L7qAs O5L2F9z8ZDXubwUpKUdMCJHfZLXmtQzy2Lf36cHLpJlCSmBaLlkqwXNCe/EzBKyKtNAp cakNVR2G5iwHtKo73LjHh9r1sBR+EKvUJTPN2WZCwSfS7MfD1uA+Ogw2hOrDMkatdzRz n7hxQ0q26xf9KzMDJ0/l6hwD3zwMryULoztpNijfoyi+81jDAa7PGUT2xZEL813C5HCo 1HiP5rzVsTpkauzZE+vTVyTy0cvV4Ye7orPTWdLtbTbjJOs31Jrdk0qjBwB1/dAHB3qo kgCg== 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=x1dleHcA8JrBStR3zcVbkd9yW2rFEPUaq3Nu/wTM+CA=; b=Oie03FM/tidez1Q9ALXx/AImkt9rgaTSvE3dr4BgjG0nLN2nLD7Y4YjBrEtq4NC1ct uZf5t2BO9HOTS40a3JS6NpBlmXY+ptctFubGwrrXwic2LtNlOCIhs7vRQOKc4Jvfjlc8 HRD8bpL56hCreX2a6sNltHcx9qBa9tQlLYmSP/lZNRFzSoq44fa6fyPEavlNexIDoG+v cfvdUAjFzupXgHeutwtqt2B+GPqLJq8DYN3vYaccEVgKTq7+gNiFEoUPsSZJf4LYRmoW LtiHQo7RrEIqRGkvwlQqYajqigfRufa/7BYzxzIHVNY9NFPIMhYC8nyYt45q58XTUilV UMvg== X-Gm-Message-State: APjAAAWaQXZwe8f28XSbwIq3l1j8VC0SLez5OhUWbWKxxLa3yK2FuIIO 7925LaBPRdbB81kQKgqDYNd2KMnMBhk= X-Google-Smtp-Source: APXvYqwX6FosgfedYDbHoqHdHuqOjtIFYI9Frl25ztsGqKALDtSMEnqicCWMT8O5pxD75dHt+ElfAA== X-Received: by 2002:a17:90a:c303:: with SMTP id g3mr35777540pjt.58.1559631104641; Mon, 03 Jun 2019 23:51:44 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c129sm16079397pfa.106.2019.06.03.23.51.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2019 23:51:44 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Tue, 4 Jun 2019 15:52:09 +0900 Message-Id: <20190604065211.15907-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190604065211.15907-1-takahiro.akashi@linaro.org> References: <20190604065211.15907-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 5/7] efi_loader: bootmgr: make BootNext 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 Acked-by: Ilias Apalodimas --- 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 43791422c819..b2102c5b5af2 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -210,7 +210,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 Tue Jun 4 06:52:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1109648 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="Zf127HK9"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45J2hm0BR9z9s3l for ; Tue, 4 Jun 2019 16:54:15 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9E04AC21CB6; Tue, 4 Jun 2019 06:53: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 03BF9C21E0D; Tue, 4 Jun 2019 06:52:14 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 63880C21E0D; Tue, 4 Jun 2019 06:51:52 +0000 (UTC) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by lists.denx.de (Postfix) with ESMTPS id D5493C21DDC for ; Tue, 4 Jun 2019 06:51:48 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id i189so79463pfg.10 for ; Mon, 03 Jun 2019 23:51: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=FMUgDM7N8Jh2uLJ7W7PkXQvm1hK5QmiPZl/hAub74js=; b=Zf127HK9j9i7uJc9XcFmBM/xYrN7XH+839rZAoigVX4bH7uXhosIgLGdZZiBZlLP4Y oGoK6/2LsjG0muLXhsuVSHC4OdqTddAm5r68INn2CZAvA15lhzCiK/B2AusujlGxwdJy IUkl7PM4NQU0o0ukL7d8TyCDHnUvRUMJtajsOoFNlh3MwaZGUBT+EIBD40Oigv2o++5V lAx7/fzkDWcN0bBJdW8xkdyDKNBWCCMsbjRmGFgJA46ulnmFRgCRsP8oVDyXADWhM+8J vsRyr+BeKbzwqwA0FeCMwmaw4z8d5W+CdtZrs1wrb8My4dshvFXV2GI10/wRD+rV+7t7 Dkcw== 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=FMUgDM7N8Jh2uLJ7W7PkXQvm1hK5QmiPZl/hAub74js=; b=H9rq6YQu+kbRktT3c7xwXx+qegzzD6vk5H3n0QT68eThXgc0OukE9S5RCmYceHmVvA HiuMAPvA9ZxmVJjJsXeLo3g8dJOSP2uoeomLL281l1IBH3ou7HJWcvYJRaPZ7WJYt5vQ +035QfkY4VsThn3xzs4JX4pVDYzYjDWrjn2lF6D8xQZUtOvY6NQrJ5l+IBfJyy2tIZYv JnVJSuBGpkFQH6BXlZ5gxoIUIqF8DBdUbz2tk9n2L7WjgbHD1c+KsTXIPfda/MDvL0Vm FYRVL5Rjbybd6Ta+Rftmq0cyodmjPwRPFCbj8KR3NuNgdJq6b89u2YoboDyLRV8hNTIU Rdgw== X-Gm-Message-State: APjAAAUhXlDqGiFJjALJhuXcG3gdKgytmtqbChKYkbqRkI9hYpU47Q2Z U5xxPT4q/SPq1ywJ8Rylc8benw== X-Google-Smtp-Source: APXvYqxKG4UXNXeVxKqph6B8s3nuHD21w6sFFdrwHOwCkjexLCls1ZKwHuiRDxDI6hG2B5aRqrHd6g== X-Received: by 2002:a63:4e07:: with SMTP id c7mr23014304pgb.350.1559631107433; Mon, 03 Jun 2019 23:51:47 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f5sm18155466pfn.161.2019.06.03.23.51.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2019 23:51:46 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Tue, 4 Jun 2019 15:52:10 +0900 Message-Id: <20190604065211.15907-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190604065211.15907-1-takahiro.akashi@linaro.org> References: <20190604065211.15907-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 6/7] 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 Reviewed-by: Heinrich Schuchardt Acked-by: Ilias Apalodimas --- cmd/efidebug.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index c4ac9dd634e2..e65722625455 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -558,6 +558,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)); @@ -909,6 +910,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)); @@ -964,6 +966,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)); From patchwork Tue Jun 4 06:52:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1109646 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="b9BxDh6K"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45J2h558KVz9s3l for ; Tue, 4 Jun 2019 16:53:41 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 61A30C21DD9; Tue, 4 Jun 2019 06:53:02 +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 8CCCCC21C2C; Tue, 4 Jun 2019 06:52:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 29413C21DB6; Tue, 4 Jun 2019 06:51:57 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id 76348C21DED for ; Tue, 4 Jun 2019 06:51:51 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id a3so2370450pgb.3 for ; Mon, 03 Jun 2019 23:51:51 -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=vmDqCvsmgLN6e3kdWuVMt2Sg6vDBBt8ISnAnJlmT0yc=; b=b9BxDh6Kwm2zPh3gtlbPsC+GP0vVKFPk9Om1B8spFRRMXNrbqE3nNZOOM0PbVTLJxm iYrQqKE6fP9OjDjIrQJWOi1MstwQ19h/MOUuCp6AcfN3eiH0itMpORl+zosOM2x9qtmy 4O6E108/s3bNJ83xnTIkmvOMf+W8mflSyUFMj+XD8ghStEcr8EeKh7tr2pDWWvceNQYY jFmTRxBBjJTimRQDz1jbTYnf8XKvyNlvT23DQ3ALvzReoDnqA8fmjvwsCQ5wg+WzZjrP A01oXopiL6XcFEa/iXcAFg1SNU54CDNgIMyUCcKNYwKsbwd1yQ9U80GzH1nczgbd57a4 SpUw== 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=vmDqCvsmgLN6e3kdWuVMt2Sg6vDBBt8ISnAnJlmT0yc=; b=ffrIHwblHI1wzmc9qZJHqzN/3JzL03MAnGgEWvVF7Yt8fcpLzGCwk3pc4ZFcnEng9s OPfnkgK+0yU2CJv9pMCIP0CQjWmJyLZ4yh1VDQvxAeuO5abA2Jp/1FSDuXqBgxdR3gmd c69KK5u8JiS3S8AgmWpwqEaI7tz5WMWCScvEP+Rkzj/nRcRM6fEim07hHq6DoyWu1P08 Vcko6x94Y0gG+Dvb034outls8t2zAHma8SDX/Ss6NJE1ie8XqN7bUqolZQ9J6BOMk1tj fKJAaiRKl+sNMbaQLZk2IylCib1q8mYR+IBMyLBpC4P8beNHW0LdI9ToAAtoGZB9mATt 7G4Q== X-Gm-Message-State: APjAAAX5GESr7jPXm/EG47ukkwK5FKAFxHi3BBf8cGaVaMEagWkOROiy ieHZjWP0D+GErbMxCpIwNA06DA== X-Google-Smtp-Source: APXvYqwr39tvpWfobKDdSKFkwpXC+L9b4iwinLNJMSYXFLU5jipfcLPzDg/v0ZZxG+QWptiJum7ZhQ== X-Received: by 2002:a63:b547:: with SMTP id u7mr34011933pgo.322.1559631110181; Mon, 03 Jun 2019 23:51:50 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a16sm16106636pfi.188.2019.06.03.23.51.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2019 23:51:49 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Date: Tue, 4 Jun 2019 15:52:11 +0900 Message-Id: <20190604065211.15907-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190604065211.15907-1-takahiro.akashi@linaro.org> References: <20190604065211.15907-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 7/7] 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 Reviewed-by: Heinrich Schuchardt --- 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 ff8eaa1aad2d..60a8ac84c811 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -349,6 +349,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) @@ -362,6 +363,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 */ @@ -391,9 +402,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)); if (ret == EFI_SUCCESS) { ret = CMD_RET_SUCCESS;