From patchwork Tue Nov 28 10:24:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 119822 Delivered-To: patch@linaro.org Received: by 10.80.225.132 with SMTP id k4csp2911612edl; Tue, 28 Nov 2017 02:30:29 -0800 (PST) X-Google-Smtp-Source: AGs4zMaDSlLM5a5OTgSgUQh7K9d4c+v9VIknhyzDOcPpcRUhQ8adgmEFQ+Vv/oUZYRRMd7iwWGgw X-Received: by 10.80.220.132 with SMTP id r4mr2045287edk.180.1511865029298; Tue, 28 Nov 2017 02:30:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511865029; cv=none; d=google.com; s=arc-20160816; b=flCiBmJs7zRjR48iufoeg/N4NXepBTcPHTgzvSgNvilErTRHMJ0uyffIy4Jfh7oTQb paFgUvLhj6g7qURmaEbsssw8nqBDfe/xncwAIu+A3D6UeUN7IJQuzD3yq5ygX2wZkgKm pZ/Y5PabtmYYtUDY65gBW9NTx5L1DiRUun7YcehMc7/y8ScY4CR4Y/K6GqIww5vErb7n OaD040Q5SeSzYsDv4Prqe43w8pi1BMOsnzsHWXEK+nb1tqVk9HcfnBJIVhegViJjI3ra oq1kCCzTulF20eppmv991C18fm0KohTQISgTIO5RwkxX7bjly2CXfTVlBCdVKZ/LxtwG zMLA== 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:references :in-reply-to:message-id:date:to:from:arc-authentication-results; bh=ry63qEcjqKTpO/YQ0UUv1FrqW3TH9oNewJyzGkuZJP8=; b=M673AxLkW0EclM6/hFNV7CEh/ZZshDF6QgD0PsvRhNPpwxk1OfW0ZDp+CNbeUS6HNk NOr/dRHxuBGuivFRtBbi0TDHrQ4NRXtGgDf5GOhEielvBvAWVtRDqXGGINVW0ExPGYTa SEYmrqPdW2N2THczk5EG5ofBSSnOSk0Ehh+gIO95vWn/e284zH6e21xZAwbPBklynv6/ 5YLkr7Rm2zkfKiAyjoEgnjn04FMpTWJFhM4I3U331EleiONAbaAtalKYveeb0Vtolol/ KBh6V6RHowOc+Wg0YMkRzOFqBsiI0HBjmwIHz/5Mn8sNrsCsbLy2W7TgsxFywhpQ2Qng zCBw== 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 5si5480108edx.248.2017.11.28.02.30.28; Tue, 28 Nov 2017 02:30:29 -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 B7BF1C21E2F; Tue, 28 Nov 2017 10:27:44 +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 16F33C21DA5; Tue, 28 Nov 2017 10:25:13 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3EF24C21DE7; Tue, 28 Nov 2017 10:25:02 +0000 (UTC) Received: from mail.free-electrons.com (mail.free-electrons.com [62.4.15.54]) by lists.denx.de (Postfix) with ESMTP id 738D3C21DF7 for ; Tue, 28 Nov 2017 10:24:56 +0000 (UTC) Received: by mail.free-electrons.com (Postfix, from userid 110) id C73F1203B5; Tue, 28 Nov 2017 11:24:55 +0100 (CET) Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 9CFED2083F; Tue, 28 Nov 2017 11:24:55 +0100 (CET) From: Maxime Ripard To: Tom Rini Date: Tue, 28 Nov 2017 11:24:44 +0100 Message-Id: <2b747a810c8103878d673660bbdc560431d19c73.1511864667.git-series.maxime.ripard@free-electrons.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: References: In-Reply-To: References: Cc: Thomas Petazzoni , u-boot@lists.denx.de, Andre Przywara , agraf@suse.de, Maxime Ripard , Jagan Teki Subject: [U-Boot] [PATCH 09/14] 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 Reviewed-by: Simon Glass --- env/env.c | 75 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/env/env.c b/env/env.c index 44f9908e2c2d..5176700133d3 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)