From patchwork Mon Nov 6 13:16:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorge Ramirez-Ortiz X-Patchwork-Id: 118034 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2755457qgn; Mon, 6 Nov 2017 05:16:53 -0800 (PST) X-Google-Smtp-Source: ABhQp+QI3goAC0SHgDTKvNUk7bXJXelspx6Kecg5zy7Weag7wUmHm49oXxHUlpaX1GFoiybwp7Ir X-Received: by 10.80.177.179 with SMTP id m48mr20729113edd.114.1509974213751; Mon, 06 Nov 2017 05:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509974213; cv=none; d=google.com; s=arc-20160816; b=w8W5xAdGaS9Z5saupMExGRQVwkA74KbycCcybyXw+jfm0AO57YdGq1PGwWQDUnZucC DC3GmcS2YlTWLEixcPm5dhWp8UyRq8zMWWhQq+feV0XUxmxo/pSDiXk0avx+KK8Qqujo xr73HVL+RPUsvRBgm+HxWwbqSIPg6dtLVdZfU4aViU6QY1lvqtkdqSdVXM1WxPI4ESPl /Un3sUvrDMnL0GdOSEVqOaibSNoOU8tu4owoIz73Oygrxn9ARsTP8NY8+x+odK9dPNVF 6vY+pqxqclTfAI0Xt4FxX/BByPUAUS48TDuU+RcmAnpPm2q/jE0bBf5C1yGiEfazIEzo F0tA== 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:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=CDMXqQAJreEr8BxK1cvbKbewzRSM56vj/y0Z75uGmMo=; b=nBBAKjX4INF1NIK/BBDHB5EDc+jaCVwKd5oc9XAqhwNuVEwmItx6jFPbUIbkrKFtkl vEygOFOxgQYGoi3S3Mbtc9liVh2AmMU2g7Ti/HKFTEdTsxhhs/8hi89z4DXaKojOEN9L yypArj5KVBifMBCIeaXFmhqPGKadGaYb+KGDTiDq2+yHf72mCVxECBiomYBjoZc5oq7T aepMcNKb5kCHJyYpLayzcZyJQv29Xg/O7T3zM8eZ0nxbKRfi8mUhd/PTyB/KG79E2haa 5OxFENBK1oenW62ogAgBJ78euTsLU+fIM0mTCRE8ouE1DjRcNMbMOVf/EEDrhiGhDFgK hOGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=VQj/X6VA; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id b40si1939340edd.163.2017.11.06.05.16.53; Mon, 06 Nov 2017 05:16:53 -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; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=VQj/X6VA; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id D45C7C21DE9; Mon, 6 Nov 2017 13:16:49 +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_H2, 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 BD895C21D8C; Mon, 6 Nov 2017 13:16:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5961CC21D8C; Mon, 6 Nov 2017 13:16:46 +0000 (UTC) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by lists.denx.de (Postfix) with ESMTPS id 4D233C21D84 for ; Mon, 6 Nov 2017 13:16:45 +0000 (UTC) Received: by mail-wr0-f193.google.com with SMTP id g10so1017832wrg.11 for ; Mon, 06 Nov 2017 05:16:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=RbZC019LYQ5m+qq6jwG37ZpfdEMvTxjUDsk/glXFbOY=; b=VQj/X6VAfEWtGvPL5vy/BsQ740jWJmGvZmxZ1lFkExsE3p2yrjIy55KvP9a7yKUSiV IykkrOnB1CUiA0nHFIBj+83PGLntfjbKSthUFHTHbpRy5KFOQgaGf0RMrwoFFDmmJYdK PsjmPJ0pqbJdeCTVCEMzpUfyWAJyQKkre/a88= 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; bh=RbZC019LYQ5m+qq6jwG37ZpfdEMvTxjUDsk/glXFbOY=; b=UJQSgZrHA0MgqS6cVYjwFiYF0Rajij+ySlwdDfGVHM+k371cCf9zzb9aduO+5cL+TN IO/x49soNAAmp4xKD4pp6vlwIEkng4JCffiHBPWRTOd/aAnIVdtgp96rbagtRH/u6OUa Fdj+V+owC5mktwWnomUGBrYESYMlXtiCX3y1qO+efWVUxXaLfD2h3AXZuZ720YBlfLWH KN0krxoJZGCuOLyEBlDd/yc+ZG8K+AL6vJ6KXpnARctjkqb6NgR30xN+G090zYqQ4i3D oGKfgI3SHBFAXPGA/ZygcmMyFD+Zct+AqYuI6rrV6wuy/UAnBdb1/W+uWg0Wd/rMb3R+ /G/g== X-Gm-Message-State: AMCzsaWODTCu6An9OTclMW1ajdIN/bYNE7SCFpyziN4R6DkiIYWZmxGY bAkXdPKFZ5Q9ee737Qy9NgOMOg== X-Received: by 10.223.130.56 with SMTP id 53mr13804806wrb.131.1509974204845; Mon, 06 Nov 2017 05:16:44 -0800 (PST) Received: from localhost.localdomain ([90.68.73.7]) by smtp.gmail.com with ESMTPSA id 141sm11210302wmr.45.2017.11.06.05.16.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Nov 2017 05:16:44 -0800 (PST) From: Jorge Ramirez-Ortiz To: jorge.ramirez-ortiz@linaro.org, u-boot@lists.denx.de Date: Mon, 6 Nov 2017 14:16:37 +0100 Message-Id: <1509974198-14831-1-git-send-email-jorge.ramirez-ortiz@linaro.org> X-Mailer: git-send-email 2.7.4 Cc: nicolas.dechesne@linaro.org, daniel.lezcano@linaro.org Subject: [U-Boot] [PATCH 1/2] env: Save environment at the end of an MMC partition 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" Allow the platform to define a partition by name at the end of which the environment data will be located. Signed-off-by: Jorge Ramirez-Ortiz --- doc/device-tree-bindings/config.txt | 9 ++++++ env/mmc.c | 62 ++++++++++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/doc/device-tree-bindings/config.txt b/doc/device-tree-bindings/config.txt index fe0e04a..15e4349 100644 --- a/doc/device-tree-bindings/config.txt +++ b/doc/device-tree-bindings/config.txt @@ -21,6 +21,15 @@ u-boot,efi-partition-entries-offset This setting will override any values configured via Kconfig. +u-boot,mmc-env-partition + if present, the environment shall be placed at the last + CONFIG_ENV_SIZE blocks of the partition on the + CONFIG_SYS_MMC_ENV_DEV. + + if u-boot,mmc-env-offset* is present, this setting will take + precedence. In that case, only if the partition is not found, + mmc-env-offset* will be tried. + u-boot,mmc-env-offset u-boot,mmc-env-offset-redundant If present, the values of the 'u-boot,mmc-env-offset' and/or diff --git a/env/mmc.c b/env/mmc.c index 3f3092d..3343f9e 100644 --- a/env/mmc.c +++ b/env/mmc.c @@ -15,9 +15,13 @@ #include #include #include +#include #include #include +#define __STR(X) #X +#define STR(X) __STR(X) + #if defined(CONFIG_ENV_SIZE_REDUND) && \ (CONFIG_ENV_SIZE_REDUND != CONFIG_ENV_SIZE) #error CONFIG_ENV_SIZE_REDUND should be the same as CONFIG_ENV_SIZE @@ -30,18 +34,68 @@ DECLARE_GLOBAL_DATA_PTR; #endif #if CONFIG_IS_ENABLED(OF_CONTROL) +static inline int mmc_offset_try_partition(const char *str, s64 *val) +{ + disk_partition_t info; + struct blk_desc *desc; + int len, i, ret; + + ret = blk_get_device_by_str("mmc", STR(CONFIG_SYS_MMC_ENV_DEV), &desc); + if (ret < 0) + return (ret); + + for (i = 1;;i++) { + ret = part_get_info(desc, i, &info); + if (ret < 0) + return ret; + + if (!strncmp((const char *)info.name, str, sizeof(str))) + break; + } + + /* round up to info.blksz */ + len = (CONFIG_ENV_SIZE + info.blksz - 1) & ~(info.blksz - 1); + + /* use the top of the partion for the environment */ + *val = (info.start + info.size - 1) - len / info.blksz; + + return 0; +} + static inline s64 mmc_offset(int copy) { - const char *propname = "u-boot,mmc-env-offset"; - s64 defvalue = CONFIG_ENV_OFFSET; + const struct { + const char *offset_redund; + const char *partition; + const char *offset; + } dt_prop = { + .offset_redund = "u-boot,mmc-env-offset-redundant", + .partition = "u-boot,mmc-env-partition", + .offset = "u-boot,mmc-env-offset", + }; + s64 val, defvalue; + const char *propname; + const char *str; + int err; + + /* look for the partition in mmc CONFIG_SYS_MMC_ENV_DEV */ + str = fdtdec_get_config_string(gd->fdt_blob, dt_prop.partition); + if (str) { + /* try to place the environment at end of the partition */ + err = mmc_offset_try_partition(str, &val); + if (!err) + return val; + } + + defvalue = CONFIG_ENV_OFFSET; + propname = dt_prop.offset; #if defined(CONFIG_ENV_OFFSET_REDUND) if (copy) { - propname = "u-boot,mmc-env-offset-redundant"; defvalue = CONFIG_ENV_OFFSET_REDUND; + propname = dt_prop.offset_redund; } #endif - return fdtdec_get_config_int(gd->fdt_blob, propname, defvalue); } #else