From patchwork Tue Jan 23 20:16:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 125582 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp1984930ljf; Tue, 23 Jan 2018 12:25:29 -0800 (PST) X-Google-Smtp-Source: AH8x226mWW+6dQ6+pOz2da8z9SxcnKsPTSKL/u7OuuNXf70HRzMit1GFjXHiiPl3ytMAouVriqia X-Received: by 10.80.169.53 with SMTP id l50mr21334679edc.128.1516739129222; Tue, 23 Jan 2018 12:25:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516739129; cv=none; d=google.com; s=arc-20160816; b=YwRMBVKixNgUgWCPisEf0y5cRDhjdTMgIA1tfYntyYqpoTRqaAmGkAtWFDExxfAASW e/j/HJllj+/7nB4IUzr+JyudWEAJtTGMSWdtbFueAW8tLVK8W8UJ78ZnGh1PAmFnND61 YIpD/EksmJkdhIHaEeyU99BZDeakKAl78qIq8gOxZ5sB+oYNndz9yMz5xn+25O0oaWCH G6Aepxxlp/ZviYlrh0W6zMzPDRpT3macL0q9DZB2+tBi9AG7q2/ZL4pGpsLxir51aUj7 j0mJTMpinnxc2HI5w9Fn3b9b9synihAL1KHm+QIq8y4eY9nH6k0fyv/k68b4yv0O4DpK 1kjw== 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=hTJcIdMeiekbnUwfFrEqjw+PeHU0yIag0gNj1Hb5nhk=; b=f4xsMWTsOlI76Q690v5B5/Ft3MsXAD2BW9qI+beiGi9ozgSRPlWMJw1XOMFHZjrBSz 5msodZilbdNz3hW0iKWFbgehfAQvfHdV/dC3FxljpyoZDd7egwbKgSFLqIHDKafAq3Kk 9mFdN1KHntGmNFBVmYcoRzcMPFR2nikk4WHRWoNsVqwuWU2DpGLY3lMihCA+upXL199I WnpTJc5ls9SJsguSjzfo15pIV22X3aDVuIMKqRewDoG3UfwzqbGurHAE+oBwmtZdRBEx t3DMMS9QBDDATIz377kv07l19iIpOLuHyenVW4YhvOdWGOnPieVEaBYIYe1GJZJfgijt tfng== 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 e34si1206297eda.52.2018.01.23.12.25.28; Tue, 23 Jan 2018 12:25: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 D37F6C21DB5; Tue, 23 Jan 2018 20:20:18 +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 D262DC22153; Tue, 23 Jan 2018 20:17:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CF8C3C21F03; Tue, 23 Jan 2018 20:17:16 +0000 (UTC) Received: from mail.free-electrons.com (mail.free-electrons.com [62.4.15.54]) by lists.denx.de (Postfix) with ESMTP id EDF3AC21EE3 for ; Tue, 23 Jan 2018 20:17:10 +0000 (UTC) Received: by mail.free-electrons.com (Postfix, from userid 110) id CD3BC20D84; Tue, 23 Jan 2018 21:17:10 +0100 (CET) Received: from localhost (LFbn-1-2035-97.w90-76.abo.wanadoo.fr [90.76.104.97]) by mail.free-electrons.com (Postfix) with ESMTPSA id 98D30207A8; Tue, 23 Jan 2018 21:17:10 +0100 (CET) From: Maxime Ripard To: Tom Rini Date: Tue, 23 Jan 2018 21:16:58 +0100 Message-Id: <844212451999302a41d87526d6616b1af7c781d1.1516723179.git-series.maxime.ripard@free-electrons.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: References: In-Reply-To: References: Cc: Andre Przywara , agraf@suse.de, u-boot@lists.denx.de, Maxime Ripard , Jagan Teki Subject: [U-Boot] [PATCH v3 09/15] 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. Reviewed-by: Andre Przywara Reviewed-by: Simon Glass Signed-off-by: Maxime Ripard --- env/env.c | 80 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/env/env.c b/env/env.c index 906f28ee50a1..1182fdb545db 100644 --- a/env/env.c +++ b/env/env.c @@ -26,6 +26,41 @@ 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 +}; + +static enum env_location env_load_location = ENVL_UNKNOWN; + /** * env_get_location() - Returns the best env location for a board * @op: operations performed on the environment @@ -45,36 +80,21 @@ static struct env_driver *_env_driver_lookup(enum env_location loc) */ static enum env_location env_get_location(enum env_operation op, int prio) { - /* - * We support a single environment, so any environment asked - * with a priority that is not zero is out of our supported - * bounds. - */ - 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 ENVOP_GET_CHAR: + case ENVOP_INIT: + case ENVOP_LOAD: + if (prio >= ARRAY_SIZE(env_locations)) + return ENVL_UNKNOWN; + + env_load_location = env_locations[prio]; + return env_load_location; + + case ENVOP_SAVE: + return env_load_location; + } + + return ENVL_UNKNOWN; }