From patchwork Thu Nov 30 07:15:10 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: 120077 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp329571qgn; Wed, 29 Nov 2017 23:15:50 -0800 (PST) X-Google-Smtp-Source: AGs4zMZqGU7rPOwl/qczYEWkrWG+iKj64sCSC3uzccP+kTRIWMrCES181hSitKbJx6AsCoEwdgQz X-Received: by 10.80.140.176 with SMTP id q45mr12025934edq.186.1512026150410; Wed, 29 Nov 2017 23:15:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512026150; cv=none; d=google.com; s=arc-20160816; b=hAa/vBo8vTlYLCpblixSYSfMZR1x364KMQnHSwg19q7WnYAmHzKoDzcebnCLiwzZJ5 EemNzF/uta+FRzCSHnl2k7n0UBCFj2yCY53zrwnUHDHox4AE4HgQUGidQ4qBBUlzLQZI EGU9iroiGmVp3eRUKDVYUSrW2tM7fOPdsnceZmWb2H2uKPA3u8blU47BzAeO+vthJvLh w9W8+VwwGux39P+iw2FG1OQrHuROuTQgFCtTnYp9tpplwuZ38SrJMMqqq6QdOijI3tIE prKIDC9RiAWPIQm/ALQ0oWfOOG9arzdOkHm3/qjuUkd656dbzLEnxhxBXGnYfU1a/3Jo eVjw== 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:message-id:date:to:from:dkim-signature :arc-authentication-results; bh=7krR9XA7u2pG2ER1dnZ6BBNGdHQ29B1EXuJHJ2VwqQM=; b=JhzTL7N3fdKpf1c7OSqB0TUY0kLFLAmqnBozzEtND/gBkNLRQsSWrHLrxrRpwEqk4a +MYoAgs6lH7mJMJATt70p1OlwSf3qsFaIHX72xYHCyrPFPxUzzhWyWjE0jHrW9BnQsvF Bd5ik0hGC7szJmPkmlz10O7lQP3hHVLn/GWFE8g71el0dvoZmNkNV3Jr7kI6dq72UThC 5DuNbtHfjPBDsC/w81B/czSYB3uX2gc0EWWUonlDS91jm+LB/UOYpymw7Rhnbi/X890M BGSxfBLWjC1DblStuUVl2psnJzcZ6u99Wg+ozNvY/XunBywT6hD39gvLvyOZddLrl8l8 8Sog== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZWVS8RrA; 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 p34si1846298edb.413.2017.11.29.23.15.50; Wed, 29 Nov 2017 23:15:50 -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=ZWVS8RrA; 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 D843CC21F32; Thu, 30 Nov 2017 07:15:45 +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_H3, RCVD_IN_MSPIKE_WL, 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 3FF36C21E57; Thu, 30 Nov 2017 07:15:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F3E8BC21E64; Thu, 30 Nov 2017 07:15:31 +0000 (UTC) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by lists.denx.de (Postfix) with ESMTPS id 401E9C21E64 for ; Thu, 30 Nov 2017 07:15:17 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id g75so11068891wme.0 for ; Wed, 29 Nov 2017 23:15:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=pm3eqAFGAQHAEiPjI5M9BvFlQEe3c56yXmRtc3SQp3c=; b=ZWVS8RrAMXBjyjeYTVjYaIRrqQW28uwaEDPy4aV6Rt0xn3O4630YazZPkE/09OiLZr ecey0h9jgDKTesyIvQ5YGZGQuxA37Zp29ifklgppQuFrEFZAMxwew0uaPuYVehGsjgh/ MqnvK0nHZLKyirOq0qR/D2Mp/MsgHnIDAjFJI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=pm3eqAFGAQHAEiPjI5M9BvFlQEe3c56yXmRtc3SQp3c=; b=ipO+T0wRbOk3CH4wMaaATkg4SQ0SP8ni2bngcCh/cdmlnGyU/wQlC1JMc0Tlajopdp q/4Gf9uDuvlzyjWN+RaFqCoP1X97J10fZEpnYxkZlcazjWNqfrxFRRo0ebPBF/6Dm28a VnksZuFp9PM0NGVH2hfatZ0Gpe8/YTX0BVtm6ha8Dr2J5uBN02YJ4PQhg91Rm1FLXuBb HQbfvZcT9mVDlJQGjPobK7p4wld5sxjDn3yPeu4m/IdN8+mxwXRzeqRaA6AsFXi0CYLP VuB0hNZ2UaxVGlzZiadgrHR5B/PRbMh6NQFljMGpjIZMW9isCWXVhu3zha2OYB/Ejlhj 2c0g== X-Gm-Message-State: AJaThX7i4QF0wDAYpR+JlkfWTByu9BPttCySe35PcNpkzeAD9JRpTeen xjbvu3f8nzCUY5x0sJmx8JRdPJlMEOA= X-Received: by 10.28.135.135 with SMTP id j129mr1034390wmd.144.1512026116655; Wed, 29 Nov 2017 23:15:16 -0800 (PST) Received: from igloo.80.58.61.254 (141.pool85-51-114.dynamic.orange.es. [85.51.114.141]) by smtp.gmail.com with ESMTPSA id s30sm3909485wrc.89.2017.11.29.23.15.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Nov 2017 23:15:15 -0800 (PST) From: Jorge Ramirez-Ortiz To: jorge.ramirez-ortiz@linaro.org, u-boot@lists.denx.de Date: Thu, 30 Nov 2017 08:15:10 +0100 Message-Id: <1512026110-10023-1-git-send-email-jorge.ramirez-ortiz@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [U-Boot] [PATCH 1/3] env: enable accessing the environment in an EXT4 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" For example to store the environment in a file named "/uboot.env" in MMC "0", where partition "1" contains the EXT4 filesystem, the following configs should be added to the board's default config: CONFIG_ENV_IS_IN_EXT4=y CONFIG_ENV_EXT4_DEVICE_AND_PART="0:1" CONFIG_ENV_EXT4_FILE="/uboot.env" CONFIG_ENV_EXT4_INTERFACE="mmc" --- env/Kconfig | 39 +++++++++++++++++++++++++++++++++++++++ env/env.c | 2 ++ env/ext4.c | 20 ++++++++++---------- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/env/Kconfig b/env/Kconfig index 2477bf8..71529b2 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -81,6 +81,13 @@ config ENV_IS_IN_FAT - CONFIG_FAT_WRITE: This must be enabled. Otherwise it cannot save the environment file. +config ENV_IS_IN_EXT4 + bool "Environment is in a EXT4 filesystem" + depends on !CHAIN_OF_TRUST + select EXT4_WRITE + help + Define this if you want to use the EXT4 file system for the environment. + config ENV_IS_IN_FLASH bool "Environment in flash memory" depends on !CHAIN_OF_TRUST @@ -396,6 +403,38 @@ config ENV_FAT_FILE It's a string of the FAT file name. This file use to store the environment. +config ENV_EXT4_INTERFACE + string "Name of the block device for the environment" + depends on ENV_IS_IN_EXT4 + help + Define this to a string that is the name of the block device. + +config ENV_EXT4_DEVICE_AND_PART + string "Device and partition for where to store the environemt in EXT4" + depends on ENV_IS_IN_EXT4 + help + Define this to a string to specify the partition of the device. It can + be as following: + + "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1) + - "D:P": device D partition P. Error occurs if device D has no + partition table. + - "D:0": device D. + - "D" or "D:": device D partition 1 if device D has partition + table, or the whole device D if has no partition + table. + - "D:auto": first partition in device D with bootable flag set. + If none, first valid partition in device D. If no + partition table then means device D. + +config ENV_EXT4_FILE + string "Name of the EXT4 file to use for the environemnt" + depends on ENV_IS_IN_EXT4 + default "uboot.env" + help + It's a string of the EXT4 file name. This file use to store the + environment (explicit path to the file) + if ARCH_SUNXI config ENV_OFFSET diff --git a/env/env.c b/env/env.c index 76a5608..7455632 100644 --- a/env/env.c +++ b/env/env.c @@ -32,6 +32,8 @@ static enum env_location env_get_default_location(void) return ENVL_EEPROM; else if IS_ENABLED(CONFIG_ENV_IS_IN_FAT) return ENVL_FAT; + else if IS_ENABLED(CONFIG_ENV_IS_IN_EXT4) + return ENVL_EXT4; else if IS_ENABLED(CONFIG_ENV_IS_IN_FLASH) return ENVL_FLASH; else if IS_ENABLED(CONFIG_ENV_IS_IN_MMC) diff --git a/env/ext4.c b/env/ext4.c index 6520221..07fd061 100644 --- a/env/ext4.c +++ b/env/ext4.c @@ -46,8 +46,8 @@ static int env_ext4_save(void) if (err) return err; - part = blk_get_device_part_str(EXT4_ENV_INTERFACE, - EXT4_ENV_DEVICE_AND_PART, + part = blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE, + CONFIG_ENV_EXT4_DEVICE_AND_PART, &dev_desc, &info, 1); if (part < 0) return 1; @@ -57,16 +57,16 @@ static int env_ext4_save(void) if (!ext4fs_mount(info.size)) { printf("\n** Unable to use %s %s for saveenv **\n", - EXT4_ENV_INTERFACE, EXT4_ENV_DEVICE_AND_PART); + CONFIG_ENV_EXT4_INTERFACE, CONFIG_ENV_EXT4_DEVICE_AND_PART); return 1; } - err = ext4fs_write(EXT4_ENV_FILE, (void *)&env_new, sizeof(env_t)); + err = ext4fs_write(CONFIG_ENV_EXT4_FILE, (void *)&env_new, sizeof(env_t)); ext4fs_close(); if (err == -1) { printf("\n** Unable to write \"%s\" from %s%d:%d **\n", - EXT4_ENV_FILE, EXT4_ENV_INTERFACE, dev, part); + CONFIG_ENV_EXT4_FILE, CONFIG_ENV_EXT4_INTERFACE, dev, part); return 1; } @@ -84,8 +84,8 @@ static int env_ext4_load(void) int err; loff_t off; - part = blk_get_device_part_str(EXT4_ENV_INTERFACE, - EXT4_ENV_DEVICE_AND_PART, + part = blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE, + CONFIG_ENV_EXT4_DEVICE_AND_PART, &dev_desc, &info, 1); if (part < 0) goto err_env_relocate; @@ -95,16 +95,16 @@ static int env_ext4_load(void) if (!ext4fs_mount(info.size)) { printf("\n** Unable to use %s %s for loading the env **\n", - EXT4_ENV_INTERFACE, EXT4_ENV_DEVICE_AND_PART); + CONFIG_ENV_EXT4_INTERFACE, CONFIG_ENV_EXT4_DEVICE_AND_PART); goto err_env_relocate; } - err = ext4_read_file(EXT4_ENV_FILE, buf, 0, CONFIG_ENV_SIZE, &off); + err = ext4_read_file(CONFIG_ENV_EXT4_FILE, buf, 0, CONFIG_ENV_SIZE, &off); ext4fs_close(); if (err == -1) { printf("\n** Unable to read \"%s\" from %s%d:%d **\n", - EXT4_ENV_FILE, EXT4_ENV_INTERFACE, dev, part); + CONFIG_ENV_EXT4_FILE, CONFIG_ENV_EXT4_INTERFACE, dev, part); goto err_env_relocate; }