From patchwork Thu Nov 16 09:22:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 119029 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5359512qgn; Thu, 16 Nov 2017 01:26:41 -0800 (PST) X-Google-Smtp-Source: AGs4zMb28Y3Fr9xXLb8977JTEKPF3MkkZnu2NcvRyuGzQQhhASl+CubyFOnCNeIUo2jHxqAYPMME X-Received: by 10.80.174.2 with SMTP id c2mr1789553edd.247.1510824401283; Thu, 16 Nov 2017 01:26:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510824401; cv=none; d=google.com; s=arc-20160816; b=m2A1RXmW9kxIPQf0I1G0sEp6Pzi47GeSPIP0RfyrwGfCz0vCrAmLJVDXCFmtNrfZcm 9lPY3DaOIoWgGY09cEIGsds7sWgnGzzwTWS16qeiZQq2wXRZk4XJk7iqI6iNgxNeB70H E06mdElI0R40asv8+hJk6iqK8twlyrRt4fPY2DHQZq2u3sAPCrcnRCoIPJknWxF5ADUj ZwMG1ZkuEqWgdKrESZQ97zy+2OOJqtUyC9d/RKVcQJc9TrntE+SHmWn8jgDU9saShYre zhK4SH5Lg7MXfBgZWKEVParbtYrn1b8JVqEcdDUd4AcHL1RtP/QpU+O/fbOAHlLWSCEB cKvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=sCc7bTFAtpkLOXzTPuLNuFOsyssOkd5R2NblMgbHm/E=; b=WeaShMlDb2kix0WnZe4qVf2gQyf3Rkgt/tHL/hL+TrSOoJ+DXn9W193WC0pOQwxBlf 4d0cGsc1kigvfRY0Beb6y+pUrLc2gHjHBfyquhMdMgfZaE0etz6z08cheC1TjVOUpEuB zmmVH5Dptu7AbXE4Nw/0+fS0VpWw8HHsXmtkXFieVUpS6uIz5qEttp2X8woKIVMKVq3z qVkLt3xZie8ln+6iUDo4cZJGh8HfSa9lFqVQ6pgfsVU+v1f6ZRsQ56Y37hnGkyv/1qCF jybytYcoON2yLhUcyE/FEnVMhaTKGqgzq+JCZ+sIdubrtBE6u1Ps302Tr1YsBfdPdNM4 4FIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id r49si862787edr.204.2017.11.16.01.26.41; Thu, 16 Nov 2017 01:26:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id E0280C21DCE; Thu, 16 Nov 2017 09:25:30 +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=none 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 A713FC21DAB; Thu, 16 Nov 2017 09:24:25 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 41DFEC21DDF; Thu, 16 Nov 2017 09:23:00 +0000 (UTC) Received: from mail.free-electrons.com (mail.free-electrons.com [62.4.15.54]) by lists.denx.de (Postfix) with ESMTP id B1996C21DBA for ; Thu, 16 Nov 2017 09:22:56 +0000 (UTC) Received: by mail.free-electrons.com (Postfix, from userid 110) id A2FFA20DD4; Thu, 16 Nov 2017 10:22:55 +0100 (CET) Received: from localhost (unknown [185.94.189.187]) by mail.free-electrons.com (Postfix) with ESMTPSA id D4F6B213DA; Thu, 16 Nov 2017 10:22:40 +0100 (CET) From: Maxime Ripard To: Tom Rini Date: Thu, 16 Nov 2017 10:22:27 +0100 Message-Id: <20171116092231.27740-7-maxime.ripard@free-electrons.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171116092231.27740-1-maxime.ripard@free-electrons.com> References: <20171116092231.27740-1-maxime.ripard@free-electrons.com> Cc: Andre Przywara , agraf@suse.de, u-boot@lists.denx.de, Maxime Ripard , Jagan Teki Subject: [U-Boot] [RFC PATCH 06/10] env: Support multiple environments 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Now that we have everything in place to support multiple environment, let's make sure the current code can use it. The priority used between the various environment is the same one that was used in the code previously. At read / init times, the highest priority environment is going to be detected, and we'll use the same one without lookup during writes. This should implement the same behaviour than we currently have. Signed-off-by: Maxime Ripard --- env/env.c | 75 ++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/env/env.c b/env/env.c index 1d13220aa79b..6af9f897b0ae 100644 --- a/env/env.c +++ b/env/env.c @@ -26,33 +26,58 @@ static struct env_driver *_env_driver_lookup(enum env_location loc) return NULL; } +static enum env_location env_locations[] = { +#ifdef CONFIG_ENV_IS_IN_EEPROM + ENVL_EEPROM, +#endif +#ifdef CONFIG_ENV_IS_IN_FAT + ENVL_FAT, +#endif +#ifdef CONFIG_ENV_IS_IN_FLASH + ENVL_FLASH, +#endif +#ifdef CONFIG_ENV_IS_IN_MMC + ENVL_MMC, +#endif +#ifdef CONFIG_ENV_IS_IN_NAND + ENVL_NAND, +#endif +#ifdef CONFIG_ENV_IS_IN_NVRAM + ENVL_NVRAM, +#endif +#ifdef CONFIG_ENV_IS_IN_REMOTE + ENVL_REMOTE, +#endif +#ifdef CONFIG_ENV_IS_IN_SPI_FLASH + ENVL_SPI_FLASH, +#endif +#ifdef CONFIG_ENV_IS_IN_UBI + ENVL_UBI, +#endif +#ifdef CONFIG_ENV_IS_NOWHERE + ENVL_NOWHERE, +#endif + ENVL_UNKNOWN, +}; + +static enum env_location env_load_location; + static enum env_location env_get_location(enum env_operation op, int prio) { - if (prio >= 1) - return ENVL_UNKNOWN; - - if IS_ENABLED(CONFIG_ENV_IS_IN_EEPROM) - return ENVL_EEPROM; - else if IS_ENABLED(CONFIG_ENV_IS_IN_FAT) - return ENVL_FAT; - else if IS_ENABLED(CONFIG_ENV_IS_IN_FLASH) - return ENVL_FLASH; - else if IS_ENABLED(CONFIG_ENV_IS_IN_MMC) - return ENVL_MMC; - else if IS_ENABLED(CONFIG_ENV_IS_IN_NAND) - return ENVL_NAND; - else if IS_ENABLED(CONFIG_ENV_IS_IN_NVRAM) - return ENVL_NVRAM; - else if IS_ENABLED(CONFIG_ENV_IS_IN_REMOTE) - return ENVL_REMOTE; - else if IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH) - return ENVL_SPI_FLASH; - else if IS_ENABLED(CONFIG_ENV_IS_IN_UBI) - return ENVL_UBI; - else if IS_ENABLED(CONFIG_ENV_IS_NOWHERE) - return ENVL_NOWHERE; - else - return ENVL_UNKNOWN; + switch (op) { + case ENVO_GET_CHAR: + case ENVO_INIT: + case ENVO_LOAD: + if (prio >= ARRAY_SIZE(env_locations)) + return -ENODEV; + + return env_load_location = env_locations[prio]; + + case ENVO_SAVE: + return env_load_location; + } + + return ENVL_UNKNOWN; } static struct env_driver *env_driver_lookup(enum env_operation op, int prio)