All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] env: Save environment at the end of an MMC partition
@ 2017-11-06 13:16 Jorge Ramirez-Ortiz
  2017-11-06 13:16 ` [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC Jorge Ramirez-Ortiz
  2017-11-17 15:45 ` [U-Boot] [U-Boot, 1/2] env: Save environment at the end of an MMC partition Tom Rini
  0 siblings, 2 replies; 9+ messages in thread
From: Jorge Ramirez-Ortiz @ 2017-11-06 13:16 UTC (permalink / raw)
  To: 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 <jorge.ramirez-ortiz@linaro.org>
---
 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 <malloc.h>
 #include <memalign.h>
 #include <mmc.h>
+#include <part.h>
 #include <search.h>
 #include <errno.h>
 
+#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
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC
  2017-11-06 13:16 [U-Boot] [PATCH 1/2] env: Save environment at the end of an MMC partition Jorge Ramirez-Ortiz
@ 2017-11-06 13:16 ` Jorge Ramirez-Ortiz
  2017-11-07 22:50   ` Tom Rini
                     ` (2 more replies)
  2017-11-17 15:45 ` [U-Boot] [U-Boot, 1/2] env: Save environment at the end of an MMC partition Tom Rini
  1 sibling, 3 replies; 9+ messages in thread
From: Jorge Ramirez-Ortiz @ 2017-11-06 13:16 UTC (permalink / raw)
  To: u-boot

Save the environment data at the end of the boot partition on emmc

Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
---
 arch/arm/dts/dragonboard410c-uboot.dtsi | 7 +++++++
 configs/dragonboard410c_defconfig       | 2 ++
 include/configs/dragonboard410c.h       | 1 +
 3 files changed, 10 insertions(+)

diff --git a/arch/arm/dts/dragonboard410c-uboot.dtsi b/arch/arm/dts/dragonboard410c-uboot.dtsi
index cc2c175..c3475c4 100644
--- a/arch/arm/dts/dragonboard410c-uboot.dtsi
+++ b/arch/arm/dts/dragonboard410c-uboot.dtsi
@@ -6,6 +6,13 @@
  * SPDX-License-Identifier:	GPL-2.0+
  */
 
+/ {
+	config {
+		u-boot,mmc-env-partition = "boot";
+	};
+};
+
+
 &pm8916_gpios {
 	usb_hub_reset_pm {
 		gpios = <&pm8916_gpios 2 0>;
diff --git a/configs/dragonboard410c_defconfig b/configs/dragonboard410c_defconfig
index a85aa74..4c04544 100644
--- a/configs/dragonboard410c_defconfig
+++ b/configs/dragonboard410c_defconfig
@@ -43,3 +43,5 @@ CONFIG_USB_ETHER_ASIX88179=y
 CONFIG_USB_ETHER_MCS7830=y
 CONFIG_USB_ETHER_SMSC95XX=y
 CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_OF_CONTROL=y
+CONFIG_ENV_IS_IN_MMC=y
diff --git a/include/configs/dragonboard410c.h b/include/configs/dragonboard410c.h
index 6b5d59d..d2447b2 100644
--- a/include/configs/dragonboard410c.h
+++ b/include/configs/dragonboard410c.h
@@ -100,6 +100,7 @@ REFLASH(dragonboard/u-boot.img, 8)\
 	BOOTENV
 
 #define CONFIG_ENV_SIZE			0x2000
+#define CONFIG_SYS_MMC_ENV_DEV		0	/* mmc0 = emmc, mmc1 = sd */
 #define CONFIG_ENV_VARS_UBOOT_CONFIG
 
 /* Size of malloc() pool */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC
  2017-11-06 13:16 ` [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC Jorge Ramirez-Ortiz
@ 2017-11-07 22:50   ` Tom Rini
  2017-11-08  7:49     ` Jorge Ramirez
  2017-11-13 16:09   ` Jorge Ramirez
  2017-11-17 15:45   ` [U-Boot] [U-Boot, " Tom Rini
  2 siblings, 1 reply; 9+ messages in thread
From: Tom Rini @ 2017-11-07 22:50 UTC (permalink / raw)
  To: u-boot

On Mon, Nov 06, 2017 at 02:16:38PM +0100, Jorge Ramirez-Ortiz wrote:

> Save the environment data at the end of the boot partition on emmc
> 
> Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
> ---
>  arch/arm/dts/dragonboard410c-uboot.dtsi | 7 +++++++
>  configs/dragonboard410c_defconfig       | 2 ++
>  include/configs/dragonboard410c.h       | 1 +
>  3 files changed, 10 insertions(+)

Implementation this seems fine.  Is there a reason to do this vs
ENV_IS_IN_FAT?  Or ENV_IS_IN_EXT ? And have it be in a filesystem
instead?  That usually seems to be best for eval/dev/etc style boards.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171107/7765841b/attachment.sig>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC
  2017-11-07 22:50   ` Tom Rini
@ 2017-11-08  7:49     ` Jorge Ramirez
  2017-11-09  1:58       ` Tom Rini
  0 siblings, 1 reply; 9+ messages in thread
From: Jorge Ramirez @ 2017-11-08  7:49 UTC (permalink / raw)
  To: u-boot

On 11/07/2017 11:50 PM, Tom Rini wrote:
> On Mon, Nov 06, 2017 at 02:16:38PM +0100, Jorge Ramirez-Ortiz wrote:
>
>> Save the environment data at the end of the boot partition on emmc
>>
>> Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
>> ---
>>   arch/arm/dts/dragonboard410c-uboot.dtsi | 7 +++++++
>>   configs/dragonboard410c_defconfig       | 2 ++
>>   include/configs/dragonboard410c.h       | 1 +
>>   3 files changed, 10 insertions(+)
> Implementation this seems fine.  Is there a reason to do this vs
> ENV_IS_IN_FAT?  Or ENV_IS_IN_EXT ? And have it be in a filesystem
> instead?  That usually seems to be best for eval/dev/etc style boards.

I think having it on a partition offset (a partition that typically just 
stores the uboot image) can be very convenient when having the 
filesystem on an NFS share.

It means that the user can completely ignore flashing and maintaining 
the filesystem until he is ready. The only issue I see is that it is up 
to the user - when he reprograms a new image or modifies the size of the 
environemnt- to make sure the environment and whatever image is in the 
partition dont overlap each other but I think that should be acceptable?











>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC
  2017-11-08  7:49     ` Jorge Ramirez
@ 2017-11-09  1:58       ` Tom Rini
  2017-11-09  8:35         ` Jorge Ramirez
  0 siblings, 1 reply; 9+ messages in thread
From: Tom Rini @ 2017-11-09  1:58 UTC (permalink / raw)
  To: u-boot

On Wed, Nov 08, 2017 at 08:49:09AM +0100, Jorge Ramirez wrote:
> On 11/07/2017 11:50 PM, Tom Rini wrote:
> >On Mon, Nov 06, 2017 at 02:16:38PM +0100, Jorge Ramirez-Ortiz wrote:
> >
> >>Save the environment data at the end of the boot partition on emmc
> >>
> >>Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
> >>---
> >>  arch/arm/dts/dragonboard410c-uboot.dtsi | 7 +++++++
> >>  configs/dragonboard410c_defconfig       | 2 ++
> >>  include/configs/dragonboard410c.h       | 1 +
> >>  3 files changed, 10 insertions(+)
> >Implementation this seems fine.  Is there a reason to do this vs
> >ENV_IS_IN_FAT?  Or ENV_IS_IN_EXT ? And have it be in a filesystem
> >instead?  That usually seems to be best for eval/dev/etc style boards.
> 
> I think having it on a partition offset (a partition that typically just
> stores the uboot image) can be very convenient when having the filesystem on
> an NFS share.
> 
> It means that the user can completely ignore flashing and maintaining the
> filesystem until he is ready. The only issue I see is that it is up to the
> user - when he reprograms a new image or modifies the size of the
> environemnt- to make sure the environment and whatever image is in the
> partition dont overlap each other but I think that should be acceptable?

Well, if you think environment in flash is best, that's fine.  I just
want to make sure the alternatives are known as I keep surprising people
when I note that the env can be a file in FAT or similar.  Thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171108/ed3f7f8e/attachment.sig>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC
  2017-11-09  1:58       ` Tom Rini
@ 2017-11-09  8:35         ` Jorge Ramirez
  0 siblings, 0 replies; 9+ messages in thread
From: Jorge Ramirez @ 2017-11-09  8:35 UTC (permalink / raw)
  To: u-boot

On 11/09/2017 02:58 AM, Tom Rini wrote:
> On Wed, Nov 08, 2017 at 08:49:09AM +0100, Jorge Ramirez wrote:
>> On 11/07/2017 11:50 PM, Tom Rini wrote:
>>> On Mon, Nov 06, 2017 at 02:16:38PM +0100, Jorge Ramirez-Ortiz wrote:
>>>
>>>> Save the environment data at the end of the boot partition on emmc
>>>>
>>>> Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
>>>> ---
>>>>   arch/arm/dts/dragonboard410c-uboot.dtsi | 7 +++++++
>>>>   configs/dragonboard410c_defconfig       | 2 ++
>>>>   include/configs/dragonboard410c.h       | 1 +
>>>>   3 files changed, 10 insertions(+)
>>> Implementation this seems fine.  Is there a reason to do this vs
>>> ENV_IS_IN_FAT?  Or ENV_IS_IN_EXT ? And have it be in a filesystem
>>> instead?  That usually seems to be best for eval/dev/etc style boards.
>> I think having it on a partition offset (a partition that typically just
>> stores the uboot image) can be very convenient when having the filesystem on
>> an NFS share.
>>
>> It means that the user can completely ignore flashing and maintaining the
>> filesystem until he is ready. The only issue I see is that it is up to the
>> user - when he reprograms a new image or modifies the size of the
>> environemnt- to make sure the environment and whatever image is in the
>> partition dont overlap each other but I think that should be acceptable?
> Well, if you think environment in flash is best, that's fine.  I just
> want to make sure the alternatives are known as I keep surprising people
> when I note that the env can be a file in FAT or similar.  Thanks!

cool. yes please, I think - in my experience with poplar and now the 
db410 this is a useful configuration to have

>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC
  2017-11-06 13:16 ` [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC Jorge Ramirez-Ortiz
  2017-11-07 22:50   ` Tom Rini
@ 2017-11-13 16:09   ` Jorge Ramirez
  2017-11-17 15:45   ` [U-Boot] [U-Boot, " Tom Rini
  2 siblings, 0 replies; 9+ messages in thread
From: Jorge Ramirez @ 2017-11-13 16:09 UTC (permalink / raw)
  To: u-boot

On 11/06/2017 02:16 PM, Jorge Ramirez-Ortiz wrote:
> Save the environment data at the end of the boot partition on emmc

any progress on this patchset?
the db410c emmc support remains broken on the dragonboard 410c.

TIA
Jorge

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [U-Boot, 1/2] env: Save environment at the end of an MMC partition
  2017-11-06 13:16 [U-Boot] [PATCH 1/2] env: Save environment at the end of an MMC partition Jorge Ramirez-Ortiz
  2017-11-06 13:16 ` [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC Jorge Ramirez-Ortiz
@ 2017-11-17 15:45 ` Tom Rini
  1 sibling, 0 replies; 9+ messages in thread
From: Tom Rini @ 2017-11-17 15:45 UTC (permalink / raw)
  To: u-boot

On Mon, Nov 06, 2017 at 02:16:37PM +0100, Jorge Ramirez-Ortiz wrote:

> 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 <jorge.ramirez-ortiz@linaro.org>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171117/ce7b5726/attachment.sig>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [U-Boot, 2/2] configs: dragonboard410c: Save environment data on eMMC
  2017-11-06 13:16 ` [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC Jorge Ramirez-Ortiz
  2017-11-07 22:50   ` Tom Rini
  2017-11-13 16:09   ` Jorge Ramirez
@ 2017-11-17 15:45   ` Tom Rini
  2 siblings, 0 replies; 9+ messages in thread
From: Tom Rini @ 2017-11-17 15:45 UTC (permalink / raw)
  To: u-boot

On Mon, Nov 06, 2017 at 02:16:38PM +0100, Jorge Ramirez-Ortiz wrote:

> Save the environment data at the end of the boot partition on emmc
> 
> Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171117/d4c2e057/attachment.sig>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-11-17 15:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-06 13:16 [U-Boot] [PATCH 1/2] env: Save environment at the end of an MMC partition Jorge Ramirez-Ortiz
2017-11-06 13:16 ` [U-Boot] [PATCH 2/2] configs: dragonboard410c: Save environment data on eMMC Jorge Ramirez-Ortiz
2017-11-07 22:50   ` Tom Rini
2017-11-08  7:49     ` Jorge Ramirez
2017-11-09  1:58       ` Tom Rini
2017-11-09  8:35         ` Jorge Ramirez
2017-11-13 16:09   ` Jorge Ramirez
2017-11-17 15:45   ` [U-Boot] [U-Boot, " Tom Rini
2017-11-17 15:45 ` [U-Boot] [U-Boot, 1/2] env: Save environment at the end of an MMC partition Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.