From patchwork Tue Jan 16 09:16:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 124636 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp947779lje; Tue, 16 Jan 2018 01:21:06 -0800 (PST) X-Google-Smtp-Source: ACJfBotHLEiNtiGBfSuR7kE851T+CpAUODvQtVX9SjyYWD5uV+/K1IKPpv/JbsZ9j3AlMDOIuypT X-Received: by 10.80.241.23 with SMTP id w23mr23328483edl.111.1516094466192; Tue, 16 Jan 2018 01:21:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516094466; cv=none; d=google.com; s=arc-20160816; b=Z79GbgP+bwZVL+m3SHMuG9KzbAwnotQ/4pMysn9cP3eXJoHKMB6isIbnS/vaLKq86J Yc/zcoA/WbwhRJDur+WPfl9kevYN8FLQkEw5gxzh4zDP72ODmu3lk7mdI6zgj46K35ig y7fV/XIvUib2E71KKwNWhgN/uh1uM0FmdtdgLqdZk8+4r+nlTwsslW9aLDLv84DjPJ93 +zwG+YsuhLO1tQbb4OB9RJSdGJHbZepgaPp5U4b+rtMx4H1LyTvp0E+LlfAGU+6RS/dh mVPtjU2I0e40RxkPnr9YIvMofSDWcO2rJra0YnKdgOR5yG57Yq3c9P+wIFl2hFQVV8x5 4G9g== 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=31LcMsSq81g2G6qCQt4f0OfACWyUK40zDD8C/Xdf3eQ=; b=yArAPuMUD9Mwp5A1TuHDI+3Qq0f8ZtvRUv5QUK8ihjN3gH3HWkHLhKOkZxQYlLoqIr Me8hE9NEO2rLipu4qiz0xFUJX6IIkYZvvhAqYvLkrOUiMO66f51vcNbkNzXhrb1InKCY vJbom2z0gzJvtUko04tGPeXFVYoVHzuvWXCL4MqhJPlcQyVMS4T7X2nTRe6AxC0pXrDR xBDdhIpHMydywKz7BKLlgWiBbpMzh0i6VHClGSYG/lsQHVCtGdd+wkIeO8vRiNVTjSJP iR66Qj4sK8HOakPBJ9PRh2RPmorMwjAFsqsfrQtzqLsTjpaJYX12MCDnXEaSlqM58j8A sxoQ== 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 n18si1881796edf.451.2018.01.16.01.21.05; Tue, 16 Jan 2018 01:21:06 -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 A2711C21DB5; Tue, 16 Jan 2018 09:19:43 +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 BEE4AC21E6F; Tue, 16 Jan 2018 09:17:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A0AFFC21E33; Tue, 16 Jan 2018 09:17:04 +0000 (UTC) Received: from mail.free-electrons.com (mail.free-electrons.com [62.4.15.54]) by lists.denx.de (Postfix) with ESMTP id 4CC0BC21E16 for ; Tue, 16 Jan 2018 09:16:58 +0000 (UTC) Received: by mail.free-electrons.com (Postfix, from userid 110) id 26426208B5; Tue, 16 Jan 2018 10:16:57 +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 E8B0520725; Tue, 16 Jan 2018 10:16:56 +0100 (CET) From: Maxime Ripard To: Tom Rini Date: Tue, 16 Jan 2018 10:16:45 +0100 Message-Id: <30edd1e4507d3818bd85070502b9a5819d0cdcc0.1516094113.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 v2 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 | 76 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/env/env.c b/env/env.c index 9dd4d4cb4d11..333fd71aad53 100644 --- a/env/env.c +++ b/env/env.c @@ -26,33 +26,59 @@ 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 ENVOP_GET_CHAR: + case ENVOP_INIT: + case ENVOP_LOAD: + if (prio >= ARRAY_SIZE(env_locations)) + return -ENODEV; + + env_load_location = env_locations[prio]; + return env_load_location; + + case ENVOP_SAVE: + return env_load_location; + } + + return ENVL_UNKNOWN; }