Skip to contentSkip to conversation

env: Multiple env support and env transition for sunxi

PATCH Superseded Maxime Ripard 3 participants 37 messages Jan 16, 2018 – Jan 22, 2018

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover env: Multiple env support and env transition for sunxi

Hi,

Here is a second attempt at transitioning away from the MMC raw environment to a FAT-based one for Allwinner SoCs. Since the RFC was quite well received, I actually tested it and fixed a few rough edges.

You'll find the first RFC here for reference:
https://lists.denx.de/pipermail/u-boot/2017-October/310111.html

And the second that originated in this series:
https://lists.denx.de/pipermail/u-boot/2017-November/311608.html

I gave it a travis run, and one test seems to fail in one test:
https://travis-ci.org/mripard/u-boot/jobs/329229382

I really cannot really make any sense of why a change in the way the environment loads could affect the operation of a DHCP client. Is there a way to reproduce locally?

Thanks!
Maxime

Original description of the patches:

The fundamental issue I'm trying to adress is that we've had for a very long time the assumption that the main U-Boot binary wouldn't exceed around 500 bytes.

However, we're starting to get real close to that limit, and are running out of silver bullets to deal with the consequences of having a bigger U-Boot binary, the main consequence being that we would have some overlap between the environment and U-Boot.

One way to address this that has been suggested by Tom is to move away from the raw MMC environment to a FAT-based one. This would allow us to slowly migrate away, and eventually remove the MMC-raw option entirely to reclaim that space for the binary.

That cannot be done in a single release however, since we might have environments in the wild already that people rely on. And since we always encouraged people to use the raw MMC environment, noone would expect that.

This is even worse since some platforms are using the U-Boot environment to deal with implement their upgrade mechanism, such as mender.io, and force moving the environment would break any further upgrade.

The suggested implementation is to allow U-Boot to compile multiple environments backend at once, based on the work done by Simon. The default behaviour shouldn't change obviously. We can then piggy-back on this to tweak on a per-board basis the environment lookup algorithm to always favour the FAT-based environment and then fallback to the MMC. It will allow us to migrate a raw-MMC user to a FAT based solution as soon as they update their environment (assuming that there is a bootable FAT partition in the system).

This has just been compile tested on sunxi so far, and I'd like general comments on the approach taken. Obviously, this will need to work properly before being merged.

Changes from v1:
- Collect tags
- Rebased on v2018.01
- Fixed build failures on a couple of boards
- Added back the message and the error code when an environment is failing
- Added some comments about the printf in environments
- Added a build time check about the number of our locations array to see if we're overflowing the location variable
- Fixed the drv->init return code being ignored
- Added helpers to manage the init status
- Changed the ENVO prefix for the operations to ENVOP
- Added some comments and documentation

Changes from the RFC:
- Added more useful messages to see where we're loading / saving
- Init all the environments no matter what, and the deal with whatever env we want to pick at load time
- Added the various tags collected

Maxime Ripard (15):
cmd: nvedit: Get rid of the env lookup
env: Rename env_driver_lookup_default and env_get_default_location
env: Pass additional parameters to the env lookup function
env: Make the env save message a bit more explicit
env: Make it explicit where we're loading our environment from
env: fat: Make the debug messages play a little nicer
env: mmc: Make the debug messages play a little nicer
env: common: Make the debug messages play a little nicer
env: Support multiple environments
env: Initialise all the environments
env: mmc: depends on the MMC framework
env: Allow to build multiple environments in Kconfig
env: Mark env_get_location as weak
sunxi: Transition from the MMC to a FAT-based environment
env: sunxi: Enable FAT-based environment support by default

 board/sunxi/board.c                   |  16 ++-
 cmd/nvedit.c                          |   4 +-
 configs/MPC8313ERDB_NAND_33_defconfig |   1 +-
 configs/MPC8313ERDB_NAND_66_defconfig |   1 +-
 configs/cl-som-imx7_defconfig         |   1 +-
 configs/microblaze-generic_defconfig  |   1 +-
 env/Kconfig                           |  70 ++++----
 env/common.c                          |   2 +-
 env/env.c                             | 252 +++++++++++++++++++--------
 env/fat.c                             |  25 ++-
 env/mmc.c                             |   1 +-
 include/asm-generic/global_data.h     |   1 +-
 include/environment.h                 |  15 +-
 13 files changed, 267 insertions(+), 123 deletions(-)

base-commit: f3dd87e0b98999a78e500e8c6d2b063ebadf535a

Signature · 1 line
git-series 0.9.1
#1 lore raw

PATCH v2 1/15 cmd: nvedit: Get rid of the env lookup

The nvedit command is the only user of env_driver_lookup_default outside of the environment code itself, and it uses it only to print the environment it's about to save to during env save.

As we're about to rework the environment to be able to handle multiple environment sources, we might not have an idea of what environment backend is going to be used before trying (and possibly failing for some).

Therefore, it makes sense to remove that message and move it to the env_save function itself. As a side effect, we also can get rid of the call to env_driver_lookup_default that is also about to get refactored.

---
 cmd/nvedit.c          | 4 ----
 env/env.c             | 4 +++-
 include/environment.h | 7 -------
 3 files changed, 3 insertions(+), 12 deletions(-)
cmd/nvedit.c +0 -4
index 4e79d03856fe..a690d743cd46 100644
@@ -708,10 +708,6 @@ ulong env_get_ulong(const char *name, int base, ulong default_val)
 static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
 		       char * const argv[])
 {
-	struct env_driver *env = env_driver_lookup_default();
-
-	printf("Saving Environment to %s...\n", env->name);
-
 	return env_save() ? 1 : 0;
 }
 
env/env.c +3 -1
index 76a5608628fc..094538ff5b62 100644
@@ -52,7 +52,7 @@ static enum env_location env_get_default_location(void)
 		return ENVL_UNKNOWN;
 }
 
-struct env_driver *env_driver_lookup_default(void)
+static struct env_driver *env_driver_lookup_default(void)
 {
 	enum env_location loc = env_get_default_location();
 	struct env_driver *drv;
@@ -115,6 +115,8 @@ int env_save(void)
 		return -ENODEV;
 	if (!drv->save)
 		return -ENOSYS;
+
+	printf("Saving Environment to %s...\n", drv->name);
 	ret = drv->save();
 	if (ret) {
 		debug("%s: Environment failed to save (err=%d)\n", __func__,
include/environment.h +0 -7
index d29f82cb5d6f..a2015c299aa9 100644
@@ -293,13 +293,6 @@ int env_import_redund(const char *buf1, const char *buf2);
 #endif
 
 /**
- * env_driver_lookup_default() - Look up the default environment driver
- *
- * @return pointer to driver, or NULL if none (which should not happen)
- */
-struct env_driver *env_driver_lookup_default(void);
-
-/**
  * env_get_char() - Get a character from the early environment
  *
  * This reads from the pre-relocation environemnt
Signature · 1 line
git-series 0.9.1
#2 lore raw

PATCH v2 2/15 env: Rename env_driver_lookup_default and env_get_default_location

In reply to Maxime Ripard

The env_driver_lookup_default and env_get_default_location functions are about to get refactored to support loading from multiple environment.

The name is therefore not really well suited anymore. Drop the default part to be a bit more relevant.

---
 env/env.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
env/env.c +9 -9
index 094538ff5b62..97ada5b5a6fd 100644
@@ -10,7 +10,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static struct env_driver *env_driver_lookup(enum env_location loc)
+static struct env_driver *_env_driver_lookup(enum env_location loc)
 {
 	struct env_driver *drv;
 	const int n_ents = ll_entry_count(struct env_driver, env_driver);
@@ -26,7 +26,7 @@ static struct env_driver *env_driver_lookup(enum env_location loc)
 	return NULL;
 }
 
-static enum env_location env_get_default_location(void)
+static enum env_location env_get_location(void)
 {
 	if IS_ENABLED(CONFIG_ENV_IS_IN_EEPROM)
 		return ENVL_EEPROM;
@@ -52,12 +52,12 @@ static enum env_location env_get_default_location(void)
 		return ENVL_UNKNOWN;
 }
 
-static struct env_driver *env_driver_lookup_default(void)
+static struct env_driver *env_driver_lookup(void)
 {
-	enum env_location loc = env_get_default_location();
+	enum env_location loc = env_get_location();
 	struct env_driver *drv;
 
-	drv = env_driver_lookup(loc);
+	drv = _env_driver_lookup(loc);
 	if (!drv) {
 		debug("%s: No environment driver for location %d\n", __func__,
 		      loc);
@@ -69,7 +69,7 @@ static struct env_driver *env_driver_lookup_default(void)
 
 int env_get_char(int index)
 {
-	struct env_driver *drv = env_driver_lookup_default();
+	struct env_driver *drv = env_driver_lookup();
 	int ret;
 
 	if (gd->env_valid == ENV_INVALID)
@@ -89,7 +89,7 @@ int env_get_char(int index)
 
 int env_load(void)
 {
-	struct env_driver *drv = env_driver_lookup_default();
+	struct env_driver *drv = env_driver_lookup();
 	int ret = 0;
 
 	if (!drv)
@@ -108,7 +108,7 @@ int env_load(void)
 
 int env_save(void)
 {
-	struct env_driver *drv = env_driver_lookup_default();
+	struct env_driver *drv = env_driver_lookup();
 	int ret;
 
 	if (!drv)
@@ -129,7 +129,7 @@ int env_save(void)
 
 int env_init(void)
 {
-	struct env_driver *drv = env_driver_lookup_default();
+	struct env_driver *drv = env_driver_lookup();
 	int ret = -ENOENT;
 
 	if (!drv)
Signature · 1 line
git-series 0.9.1
#3 lore raw

PATCH v2 3/15 env: Pass additional parameters to the env lookup function

In reply to Maxime Ripard

In preparation for the multiple environment support, let's introduce two new parameters to the environment driver lookup function: the priority and operation.

The operation parameter is meant to identify, obviously, the operation you might want to perform on the environment.

The priority is a number passed to identify the environment priority you want to retrieve. The lowest priority parameter (0) will be the primary source.

Combining the two parameters allow you to support multiple environments through different priorities, and to change those priorities between read and writes operations.

This is especially useful to implement migration mechanisms where you want to always use the same environment first, be it to read or write, while the common case is more likely to use the same environment it has read from to write it to.

---
 env/env.c             | 135 +++++++++++++++++++++++++++----------------
 include/environment.h |   8 +++-
 2 files changed, 94 insertions(+), 49 deletions(-)
env/env.c +86 -49
index 97ada5b5a6fd..4dc39b384c1e 100644
@@ -26,8 +26,11 @@ static struct env_driver *_env_driver_lookup(enum env_location loc)
 	return NULL;
 }
 
-static enum env_location env_get_location(void)
+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)
@@ -52,11 +55,27 @@ static enum env_location env_get_location(void)
 		return ENVL_UNKNOWN;
 }
 
-static struct env_driver *env_driver_lookup(void)
+
+/**
+ * env_driver_lookup() - Finds the most suited environment location
+ * @op: operations performed on the environment
+ * @prio: priority between the multiple environments, 0 being the
+ *        highest priority
+ *
+ * This will try to find the available environment with the highest
+ * priority in the system.
+ *
+ * Returns:
+ * NULL on error, a pointer to a struct env_driver otherwise
+ */
+static struct env_driver *env_driver_lookup(enum env_operation op, int prio)
 {
-	enum env_location loc = env_get_location();
+	enum env_location loc = env_get_location(op, prio);
 	struct env_driver *drv;
 
+	if (loc == ENVL_UNKNOWN)
+		return NULL;
+
 	drv = _env_driver_lookup(loc);
 	if (!drv) {
 		debug("%s: No environment driver for location %d\n", __func__,
@@ -69,83 +88,101 @@ static struct env_driver *env_driver_lookup(void)
 
 int env_get_char(int index)
 {
-	struct env_driver *drv = env_driver_lookup();
-	int ret;
+	struct env_driver *drv;
+	int prio;
 
 	if (gd->env_valid == ENV_INVALID)
 		return default_environment[index];
-	if (!drv)
-		return -ENODEV;
-	if (!drv->get_char)
-		return *(uchar *)(gd->env_addr + index);
-	ret = drv->get_char(index);
-	if (ret < 0) {
-		debug("%s: Environment failed to load (err=%d)\n",
-		      __func__, ret);
+
+	for (prio = 0; (drv = env_driver_lookup(ENVOP_GET_CHAR, prio)); prio++) {
+		int ret;
+
+		if (!drv->get_char)
+			continue;
+
+		ret = drv->get_char(index);
+		if (!ret)
+			return 0;
+
+		debug("%s: Environment %s failed to load (err=%d)\n", __func__,
+		      drv->name, ret);
 	}
 
-	return ret;
+	return -ENODEV;
 }
 
 int env_load(void)
 {
-	struct env_driver *drv = env_driver_lookup();
-	int ret = 0;
+	struct env_driver *drv;
+	int prio;
 
-	if (!drv)
-		return -ENODEV;
-	if (!drv->load)
-		return 0;
-	ret = drv->load();
-	if (ret) {
-		debug("%s: Environment failed to load (err=%d)\n", __func__,
-		      ret);
-		return ret;
+	for (prio = 0; (drv = env_driver_lookup(ENVOP_LOAD, prio)); prio++) {
+		int ret;
+
+		if (!drv->load)
+			continue;
+
+		ret = drv->load();
+		if (!ret)
+			return 0;
+
+		debug("%s: Environment %s failed to load (err=%d)\n", __func__,
+		      drv->name, ret);
 	}
 
-	return 0;
+	return -ENODEV;
 }
 
 int env_save(void)
 {
-	struct env_driver *drv = env_driver_lookup();
-	int ret;
+	struct env_driver *drv;
+	int prio;
 
-	if (!drv)
-		return -ENODEV;
-	if (!drv->save)
-		return -ENOSYS;
-
-	printf("Saving Environment to %s...\n", drv->name);
-	ret = drv->save();
-	if (ret) {
-		debug("%s: Environment failed to save (err=%d)\n", __func__,
-		      ret);
-		return ret;
+	for (prio = 0; (drv = env_driver_lookup(ENVOP_SAVE, prio)); prio++) {
+		int ret;
+
+		if (!drv->save)
+			continue;
+
+		printf("Saving Environment to %s...\n", drv->name);
+		ret = drv->save();
+		if (!ret)
+			return 0;
+
+		debug("%s: Environment %s failed to save (err=%d)\n", __func__,
+		      drv->name, ret);
 	}
 
-	return 0;
+	return -ENODEV;
 }
 
 int env_init(void)
 {
-	struct env_driver *drv = env_driver_lookup();
+	struct env_driver *drv;
 	int ret = -ENOENT;
+	int prio;
+
+	for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) {
+		if (!drv->init)
+			continue;
 
-	if (!drv)
-		return -ENODEV;
-	if (drv->init)
 		ret = drv->init();
+		if (!ret)
+			return 0;
+
+		debug("%s: Environment %s failed to init (err=%d)\n", __func__,
+		      drv->name, ret);
+	}
+
+	if (!prio)
+		return -ENODEV;
+
 	if (ret == -ENOENT) {
 		gd->env_addr = (ulong)&default_environment[0];
 		gd->env_valid = ENV_VALID;
 
 		return 0;
-	} else if (ret) {
-		debug("%s: Environment failed to init (err=%d)\n", __func__,
-		      ret);
-		return ret;
 	}
 
-	return 0;
+	return ret;
 }
include/environment.h +8 -0
index a2015c299aa9..a4060506fabb 100644
@@ -205,6 +205,14 @@ enum env_location {
 	ENVL_UNKNOWN,
 };
 
+/* value for the various operations we want to perform on the env */
+enum env_operation {
+	ENVOP_GET_CHAR,	/* we want to call the get_char function */
+	ENVOP_INIT,	/* we want to call the init function */
+	ENVOP_LOAD,	/* we want to call the load function */
+	ENVOP_SAVE,	/* we want to call the save function */
+};
+
 struct env_driver {
 	const char *name;
 	enum env_location location;
Signature · 1 line
git-series 0.9.1
#4 lore raw

PATCH v2 3/15 env: Pass additional parameters to the env lookup function

Hi Maxime,

Quoted 31 lines · Maxime Ripard

In preparation for the multiple environment support, let's introduce two new parameters to the environment driver lookup function: the priority and operation.

The operation parameter is meant to identify, obviously, the operation you might want to perform on the environment.

The priority is a number passed to identify the environment priority you want to retrieve. The lowest priority parameter (0) will be the primary source.

Combining the two parameters allow you to support multiple environments through different priorities, and to change those priorities between read and writes operations.

This is especially useful to implement migration mechanisms where you want to always use the same environment first, be it to read or write, while the common case is more likely to use the same environment it has read from to write it to.

---
 env/env.c             | 135 +++++++++++++++++++++++++++----------------
 include/environment.h |   8 +++-
 2 files changed, 94 insertions(+), 49 deletions(-)
env/env.c +0 -0
index 97ada5b5a6fd..4dc39b384c1e 100644

env/env.c static struct env_driver *_env_driver_lookup(enum env_location loc) · line 29

Quoted 5 lines
env/env.c +1 -1
@@ -26,8 +26,11 @@ static struct env_driver *_env_driver_lookup(enum env_location loc)
        return NULL;
 }
 
-static enum env_location env_get_location(void)
+static enum env_location env_get_location(enum env_operation op, int prio)

Please add a function comment, including why @op is needed.

env/env.c static struct env_driver *_env_driver_lookup(enum env_location loc) · line 32

Quoted 3 lines
env/env.c +2 -0
 {
+       if (prio >= 1)
+               return ENVL_UNKNOWN;

What is this for? Can you please add a comment?

Regards,
Simon

#5 lore raw

PATCH v2 3/15 env: Pass additional parameters to the env lookup function

Quoted 38 lines · Simon Glass

Hi Maxime,

Quoted 34 lines · Maxime Ripard

In preparation for the multiple environment support, let's introduce two new parameters to the environment driver lookup function: the priority and operation.

The operation parameter is meant to identify, obviously, the operation you might want to perform on the environment.

The priority is a number passed to identify the environment priority you want to retrieve. The lowest priority parameter (0) will be the primary source.

Combining the two parameters allow you to support multiple environments through different priorities, and to change those priorities between read and writes operations.

This is especially useful to implement migration mechanisms where you want to always use the same environment first, be it to read or write, while the common case is more likely to use the same environment it has read from to write it to.

---
 env/env.c             | 135 +++++++++++++++++++++++++++----------------
 include/environment.h |   8 +++-
 2 files changed, 94 insertions(+), 49 deletions(-)
env/env.c +0 -0
index 97ada5b5a6fd..4dc39b384c1e 100644
@@ -26,8 +26,11 @@ static struct env_driver *_env_driver_lookup(enum env_location loc)
        return NULL;
 }
 
Quoted 4 lines

env/env.c static struct env_driver *_env_driver_lookup(enum env_location loc) · line 29

Quoted 2 lines
env/env.c +1 -1
-static enum env_location env_get_location(void)
+static enum env_location env_get_location(enum env_operation op, int prio)

Please add a function comment, including why @op is needed.

This was done in a later patch (the __weak one), but you're right that it makes more sense for it to be here.

Quoted 6 lines

env/env.c static struct env_driver *_env_driver_lookup(enum env_location loc) · line 32

Quoted 4 lines
env/env.c +2 -0
 {
+       if (prio >= 1)
+               return ENVL_UNKNOWN;

What is this for? Can you please add a comment?

Done, thanks!
Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180118/b96ad42b/attachment.sig>
#6 lore raw

PATCH v2 4/15 env: Make the env save message a bit more explicit

In reply to Maxime Ripard

Since we'll soon have support for multiple environments, the environment saving message might end up being printed multiple times if the higher priority environment cannot be used.

That might confuse the user, so let's make it explicit if the operation failed or not.

---
 env/env.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
env/env.c +2 -1
index 4dc39b384c1e..afffab4c002a 100644
@@ -144,8 +144,9 @@ int env_save(void)
 		if (!drv->save)
 			continue;
 
-		printf("Saving Environment to %s...\n", drv->name);
+		printf("Saving Environment to %s... ", drv->name);
 		ret = drv->save();
+		printf("%s\n", ret ? "Failed" : "OK");
 		if (!ret)
 			return 0;
 
Signature · 1 line
git-series 0.9.1
#7 lore raw

PATCH v2 5/15 env: Make it explicit where we're loading our environment from

In reply to Maxime Ripard

Since we can have multiple environments now, it's better to provide a decent indication on what environments were tried and which were the one to fail and succeed.

---
 env/env.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
env/env.c +11 -7
index afffab4c002a..9dd4d4cb4d11 100644
@@ -122,12 +122,15 @@ int env_load(void)
 		if (!drv->load)
 			continue;
 
+		printf("Loading Environment from %s... ", drv->name);
 		ret = drv->load();
+		if (ret)
+			printf("Failed (%d)\n", ret);
+		else
+			printf("OK\n");
+
 		if (!ret)
 			return 0;
-
-		debug("%s: Environment %s failed to load (err=%d)\n", __func__,
-		      drv->name, ret);
 	}
 
 	return -ENODEV;
@@ -146,12 +149,13 @@ int env_save(void)
 
 		printf("Saving Environment to %s... ", drv->name);
 		ret = drv->save();
-		printf("%s\n", ret ? "Failed" : "OK");
+		if (ret)
+			printf("Failed (%d)\n", ret);
+		else
+			printf("OK\n");
+
 		if (!ret)
 			return 0;
-
-		debug("%s: Environment %s failed to save (err=%d)\n", __func__,
-		      drv->name, ret);
 	}
 
 	return -ENODEV;
Signature · 1 line
git-series 0.9.1
#8 lore raw

PATCH v2 6/15 env: fat: Make the debug messages play a little nicer

In reply to Maxime Ripard

Since we have global messages to indicate what's going on, the custom messages in the environment drivers only make the output less readable.

Make FAT play a little nicer by removing all the extra \n and formatting that is redundant with the global output.

---
 env/fat.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
env/fat.c +20 -5
index ec49c3905369..158a9a34357b 100644
@@ -55,7 +55,11 @@ static int env_fat_save(void)
 
 	dev = dev_desc->devnum;
 	if (fat_set_blk_dev(dev_desc, &info) != 0) {
-		printf("\n** Unable to use %s %d:%d for saveenv **\n",
+		/*
+		 * This printf is embedded in the messages from env_save that
+		 * will calling it. The missing \n is intentional.
+		 */
+		printf("Unable to use %s %d:%d... ",
 		       CONFIG_ENV_FAT_INTERFACE, dev, part);
 		return 1;
 	}
@@ -63,12 +67,15 @@ static int env_fat_save(void)
 	err = file_fat_write(CONFIG_ENV_FAT_FILE, (void *)&env_new, 0, sizeof(env_t),
 			     &size);
 	if (err == -1) {
-		printf("\n** Unable to write \"%s\" from %s%d:%d **\n",
+		/*
+		 * This printf is embedded in the messages from env_save that
+		 * will calling it. The missing \n is intentional.
+		 */
+		printf("Unable to write \"%s\" from %s%d:%d... ",
 			CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
 		return 1;
 	}
 
-	puts("done\n");
 	return 0;
 }
 #endif /* CMD_SAVEENV */
@@ -90,14 +97,22 @@ static int env_fat_load(void)
 
 	dev = dev_desc->devnum;
 	if (fat_set_blk_dev(dev_desc, &info) != 0) {
-		printf("\n** Unable to use %s %d:%d for loading the env **\n",
+		/*
+		 * This printf is embedded in the messages from env_save that
+		 * will calling it. The missing \n is intentional.
+		 */
+		printf("Unable to use %s %d:%d... ",
 		       CONFIG_ENV_FAT_INTERFACE, dev, part);
 		goto err_env_relocate;
 	}
 
 	err = file_fat_read(CONFIG_ENV_FAT_FILE, buf, CONFIG_ENV_SIZE);
 	if (err == -1) {
-		printf("\n** Unable to read \"%s\" from %s%d:%d **\n",
+		/*
+		 * This printf is embedded in the messages from env_save that
+		 * will calling it. The missing \n is intentional.
+		 */
+		printf("Unable to read \"%s\" from %s%d:%d... ",
 			CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
 		goto err_env_relocate;
 	}
Signature · 1 line
git-series 0.9.1
#9 lore raw

PATCH v2 6/15 env: fat: Make the debug messages play a little nicer

Hi Maxime,

Quoted 11 lines · Maxime Ripard

Since we have global messages to indicate what's going on, the custom messages in the environment drivers only make the output less readable.

Make FAT play a little nicer by removing all the extra \n and formatting that is redundant with the global output.

---
 env/fat.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

Do you have a change log for this patch?

Regards,
Simon

#10 lore raw

PATCH v2 6/15 env: fat: Make the debug messages play a little nicer

Quoted 10 lines · Simon Glass

Hi Maxime,

Quoted 6 lines · Maxime Ripard

Since we have global messages to indicate what's going on, the custom messages in the environment drivers only make the output less readable.

Make FAT play a little nicer by removing all the extra \n and formatting that is redundant with the global output.

Quoted 7 lines
Quoted 5 lines
---
 env/fat.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

Do you have a change log for this patch?

Sorry, it was buried in my cover letter.

You have the diff here:
http://code.bulix.org/g3emu3-259575

tl; dr: I added some comments around the printf's to make it obvious that the missing \n were intentional.

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180118/8f29238e/attachment.sig>
#11 lore raw

PATCH v2 7/15 env: mmc: Make the debug messages play a little nicer

In reply to Maxime Ripard

Since we have global messages to indicate what's going on, the custom messages in the environment drivers only make the output less readable.

Make MMC play a little nicer by removing all the extra \n and formatting that is redundant with the global output.

---
 env/mmc.c | 1 -
 1 file changed, 1 deletion(-)
env/mmc.c +0 -1
index ed7bcf16ae0e..528fbf978162 100644
@@ -233,7 +233,6 @@ static int env_mmc_save(void)
 		goto fini;
 	}
 
-	puts("done\n");
 	ret = 0;
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
Signature · 1 line
git-series 0.9.1
#12 lore raw

PATCH v2 7/15 env: mmc: Make the debug messages play a little nicer

Quoted 11 lines · Maxime Ripard

Since we have global messages to indicate what's going on, the custom messages in the environment drivers only make the output less readable.

Make MMC play a little nicer by removing all the extra \n and formatting that is redundant with the global output.

---
 env/mmc.c | 1 -
 1 file changed, 1 deletion(-)
#13 lore raw

PATCH v2 8/15 env: common: Make the debug messages play a little nicer

In reply to Maxime Ripard

Since we have global messages to indicate what's going on, the custom messages in the environment drivers only make the output less readable.

Make the common code play a little nicer by removing all the extra output in the standard case.

---
 env/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
env/common.c +1 -1
index 8167ea299264..c633502d68bb 100644
@@ -78,7 +78,7 @@ void set_default_env(const char *s)
 			puts(s);
 		}
 	} else {
-		puts("Using default environment\n\n");
+		debug("Using default environment\n");
 	}
 
 	if (himport_r(&env_htab, (char *)default_environment,
Signature · 1 line
git-series 0.9.1
#14 lore raw

PATCH v2 8/15 env: common: Make the debug messages play a little nicer

Quoted 11 lines · Maxime Ripard

Since we have global messages to indicate what's going on, the custom messages in the environment drivers only make the output less readable.

Make the common code play a little nicer by removing all the extra output in the standard case.

---
 env/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#15 lore raw

PATCH v2 9/15 env: Support multiple environments

In reply to Maxime Ripard

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.

---
 env/env.c | 76 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 51 insertions(+), 25 deletions(-)
env/env.c +51 -25
index 9dd4d4cb4d11..333fd71aad53 100644
@@ -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;
 }
 
 
Signature · 1 line
git-series 0.9.1
#16 lore raw

PATCH v2 10/15 env: Initialise all the environments

In reply to Maxime Ripard

Since we want to have multiple environments, we will need to initialise all the environments since we don't know at init time what drivers might fail when calling load.

Let's init all of them, and only consider for further operations the ones that have not reported any errors at init time.

---
 env/env.c                         | 36 +++++++++++++++++++++++++-------
 include/asm-generic/global_data.h |  1 +-
 2 files changed, 30 insertions(+), 7 deletions(-)
env/env.c +29 -7
index 333fd71aad53..75da2b921804 100644
@@ -60,6 +60,23 @@ static enum env_location env_locations[] = {
 	ENVL_UNKNOWN,
 };
 
+static bool env_has_inited(enum env_location location)
+{
+	return gd->env_has_init & BIT(location);
+}
+
+static void env_set_inited(enum env_location location)
+{
+	/*
+	 * We're using a 32-bits bitmask stored in gd (env_has_init)
+	 * using the above enum value as the bit index. We need to
+	 * make sure that we're not overflowing it.
+	 */
+	BUILD_BUG_ON(ARRAY_SIZE(env_locations) > BITS_PER_LONG);
+
+	gd->env_has_init |= BIT(location);
+}
+
 static enum env_location env_load_location;
 
 static enum env_location env_get_location(enum env_operation op, int prio)
@@ -126,6 +143,9 @@ int env_get_char(int index)
 		if (!drv->get_char)
 			continue;
 
+		if (!env_has_inited(drv->location))
+			continue;
+
 		ret = drv->get_char(index);
 		if (!ret)
 			return 0;
@@ -148,6 +168,9 @@ int env_load(void)
 		if (!drv->load)
 			continue;
 
+		if (!env_has_inited(drv->location))
+			continue;
+
 		printf("Loading Environment from %s... ", drv->name);
 		ret = drv->load();
 		if (ret)
@@ -173,6 +196,9 @@ int env_save(void)
 		if (!drv->save)
 			continue;
 
+		if (!env_has_inited(drv->location))
+			continue;
+
 		printf("Saving Environment to %s... ", drv->name);
 		ret = drv->save();
 		if (ret)
@@ -194,14 +220,10 @@ int env_init(void)
 	int prio;
 
 	for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) {
-		if (!drv->init)
-			continue;
-
-		ret = drv->init();
-		if (!ret)
-			return 0;
+		if (!drv->init || !(ret = drv->init()))
+			env_set_inited(drv->location);
 
-		debug("%s: Environment %s failed to init (err=%d)\n", __func__,
+		debug("%s: Environment %s init done (ret=%d)\n", __func__,
 		      drv->name, ret);
 	}
 
include/asm-generic/global_data.h +1 -0
index 73e036d6fd4a..fd8cd45b050e 100644
@@ -50,6 +50,7 @@ typedef struct global_data {
 #endif
 	unsigned long env_addr;		/* Address  of Environment struct */
 	unsigned long env_valid;	/* Environment valid? enum env_valid */
+	unsigned long env_has_init;	/* Bitmask of boolean of struct env_location offsets */
 
 	unsigned long ram_top;		/* Top address of RAM used by U-Boot */
 	unsigned long relocaddr;	/* Start address of U-Boot in RAM */
Signature · 1 line
git-series 0.9.1
#17 lore raw

PATCH v2 10/15 env: Initialise all the environments

Quoted 4 lines · Maxime Ripard

Since we want to have multiple environments, we will need to initialise all the environments since we don't know at init time what drivers might fail when calling load.

Quoted 8 lines

Let's init all of them, and only consider for further operations the ones that have not reported any errors at init time.

---
 env/env.c                         | 36 +++++++++++++++++++++++++-------
 include/asm-generic/global_data.h |  1 +-
 2 files changed, 30 insertions(+), 7 deletions(-)
#18 lore raw

PATCH v2 11/15 env: mmc: depends on the MMC framework

In reply to Maxime Ripard

The raw MMC environment directly calls into the MMC framework. Make sure it's enabled before we can select it.

---
 env/Kconfig | 1 +
 1 file changed, 1 insertion(+)
env/Kconfig +1 -0
index bef6e89bfc3c..ad5ccc253762 100644
@@ -156,6 +156,7 @@ config ENV_IS_IN_FLASH
 config ENV_IS_IN_MMC
 	bool "Environment in an MMC device"
 	depends on !CHAIN_OF_TRUST
+	depends on MMC
 	help
 	  Define this if you have an MMC device which you want to use for the
 	  environment.
Signature · 1 line
git-series 0.9.1
#20 lore raw

PATCH v2 12/15 env: Allow to build multiple environments in Kconfig

In reply to Maxime Ripard

Now that we have everything in place in the code, let's allow to build multiple environments backend through Kconfig.

---
 configs/MPC8313ERDB_NAND_33_defconfig |  1 +-
 configs/MPC8313ERDB_NAND_66_defconfig |  1 +-
 configs/cl-som-imx7_defconfig         |  1 +-
 configs/microblaze-generic_defconfig  |  1 +-
 env/Kconfig                           | 65 +++++++++++++---------------
 5 files changed, 35 insertions(+), 34 deletions(-)
configs/MPC8313ERDB_NAND_33_defconfig +1 -0
index 823001583447..b761516d126a 100644
@@ -22,6 +22,7 @@ CONFIG_CMD_DATE=y
 CONFIG_CMD_MTDPARTS=y
 CONFIG_MTDIDS_DEFAULT="nand0=e2800000.flash"
 CONFIG_MTDPARTS_DEFAULT="mtdparts=e2800000.flash:512k(uboot),128k(env),6m at 1m(kernel),-(fs)"
+# CONFIG_ENV_IS_IN_FLASH is not set
 CONFIG_ENV_IS_IN_NAND=y
 # CONFIG_MMC is not set
 CONFIG_MTD_NOR_FLASH=y
configs/MPC8313ERDB_NAND_66_defconfig +1 -0
index 2639926ab814..0f2a675ae2cf 100644
@@ -22,6 +22,7 @@ CONFIG_CMD_DATE=y
 CONFIG_CMD_MTDPARTS=y
 CONFIG_MTDIDS_DEFAULT="nand0=e2800000.flash"
 CONFIG_MTDPARTS_DEFAULT="mtdparts=e2800000.flash:512k(uboot),128k(env),6m at 1m(kernel),-(fs)"
+# CONFIG_ENV_IS_IN_FLASH is not set
 CONFIG_ENV_IS_IN_NAND=y
 # CONFIG_MMC is not set
 CONFIG_MTD_NOR_FLASH=y
configs/cl-som-imx7_defconfig +1 -0
index d37c82cafac1..0c93159032e5 100644
@@ -41,6 +41,7 @@ CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
+# CONFIG_ENV_IS_IN_MMC is not set
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
configs/microblaze-generic_defconfig +0 -1
index 5254c0da790a..cc80e8a027c8 100644
@@ -40,7 +40,6 @@ CONFIG_CMD_UBI=y
 # CONFIG_CMD_UBIFS is not set
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_EMBED=y
-CONFIG_ENV_IS_IN_FLASH=y
 CONFIG_NETCONSOLE=y
 CONFIG_SPL_DM=y
 CONFIG_MTD_NOR_FLASH=y
env/Kconfig +32 -33

102 lines not on this page · raw message

Signature · 1 line
git-series 0.9.1
#21 lore raw

PATCH v2 13/15 env: Mark env_get_location as weak

In reply to Maxime Ripard

Allow boards and architectures to override the default environment lookup code by overriding env_get_location.

---
 env/env.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
env/env.c +19 -1
index 75da2b921804..6d0ab8ebe1a4 100644
@@ -79,7 +79,25 @@ static void env_set_inited(enum env_location location)
 
 static enum env_location env_load_location;
 
-static enum env_location env_get_location(enum env_operation op, int prio)
+/**
+ * env_get_location() - Returns the best env location for a board
+ * @op: operations performed on the environment
+ * @prio: priority between the multiple environments, 0 being the
+ *        highest priority
+ *
+ * This will return the preferred environment for the given
+ * priority. This is overridable by boards if they need to.
+ *
+ * All implementations are free to use the operation, the priority and
+ * any other data relevant to their choice, but must take into account
+ * the fact that the lowest prority (0) is the most important location
+ * in the system. The following locations should be returned by order
+ * of descending priorities, from the highest to the lowest priority.
+ *
+ * Returns:
+ * an enum env_location value on success, a negative error code otherwise
+ */
+__weak enum env_location env_get_location(enum env_operation op, int prio)
 {
 	switch (op) {
 	case ENVOP_GET_CHAR:
Signature · 1 line
git-series 0.9.1
#22 lore raw

PATCH v2 13/15 env: Mark env_get_location as weak

Hi Maxime,

Quoted 10 lines · Maxime Ripard

Allow boards and architectures to override the default environment lookup code by overriding env_get_location.

---
 env/env.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

I still don't really understand why this needs to be a weak function. If the board knows the priority order, can it not put it into global_data? We could have a little u8 array of 4 items with a terminator?

Quoted 32 lines
env/env.c +19 -2
index 75da2b921804..6d0ab8ebe1a4 100644
@@ -79,7 +79,25 @@ static void env_set_inited(enum env_location location)
 
 static enum env_location env_load_location;
 
-static enum env_location env_get_location(enum env_operation op, int prio)
+/**
+ * env_get_location() - Returns the best env location for a board
+ * @op: operations performed on the environment
+ * @prio: priority between the multiple environments, 0 being the
+ *        highest priority
+ *
+ * This will return the preferred environment for the given
+ * priority. This is overridable by boards if they need to.
+ *
+ * All implementations are free to use the operation, the priority and
+ * any other data relevant to their choice, but must take into account
+ * the fact that the lowest prority (0) is the most important location
+ * in the system. The following locations should be returned by order
+ * of descending priorities, from the highest to the lowest priority.
+ *
+ * Returns:
+ * an enum env_location value on success, a negative error code otherwise
+ */
+__weak enum env_location env_get_location(enum env_operation op, int prio)
 {
        switch (op) {
        case ENVOP_GET_CHAR:
--
Quoted 1 line

git-series 0.9.1

Regards,
Simon

#23 lore raw

PATCH v2 13/15 env: Mark env_get_location as weak

Hi Simon,

Quoted 13 lines · Simon Glass
Quoted 10 lines · Maxime Ripard

Allow boards and architectures to override the default environment lookup code by overriding env_get_location.

---
 env/env.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 4 lines

I still don't really understand why this needs to be a weak function. If the board knows the priority order, can it not put it into global_data? We could have a little u8 array of 4 items with a terminator?

Sure that would be simpler, but that would also prevent us from doing "smart" things based on data other than just whether the previous environment is usable. Things based for example on a GPIO state, or a custom algorithm to transition (or duplicate) the environment.

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180118/0e5f9ddb/attachment.sig>
#24 lore raw

PATCH v2 13/15 env: Mark env_get_location as weak

Hi Maxime,

Quoted 21 lines · Maxime Ripard

Hi Simon,

Quoted 13 lines · Simon Glass
Quoted 10 lines · Maxime Ripard

Allow boards and architectures to override the default environment lookup code by overriding env_get_location.

---
 env/env.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 4 lines

I still don't really understand why this needs to be a weak function. If the board knows the priority order, can it not put it into global_data? We could have a little u8 array of 4 items with a terminator?

Quoted 4 lines

Sure that would be simpler, but that would also prevent us from doing "smart" things based on data other than just whether the previous environment is usable. Things based for example on a GPIO state, or a custom algorithm to transition (or duplicate) the environment.

In that case the board could read the GPIO state, or the algorithm, and then set up the value.

Basically I am saying it could set up the priority order in advance of it being needed, rather than having a callback.

Regards,
Simon

#25 lore raw

PATCH v2 13/15 env: Mark env_get_location as weak

Hi,

Quoted 24 lines · Simon Glass
Quoted 19 lines · Simon Glass
Quoted 13 lines
Quoted 10 lines · Maxime Ripard

Allow boards and architectures to override the default environment lookup code by overriding env_get_location.

---
 env/env.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 4 lines

I still don't really understand why this needs to be a weak function. If the board knows the priority order, can it not put it into global_data? We could have a little u8 array of 4 items with a terminator?

Quoted 4 lines

Sure that would be simpler, but that would also prevent us from doing "smart" things based on data other than just whether the previous environment is usable. Things based for example on a GPIO state, or a custom algorithm to transition (or duplicate) the environment.

Quoted 5 lines

In that case the board could read the GPIO state, or the algorithm, and then set up the value.

Basically I am saying it could set up the priority order in advance of it being needed, rather than having a callback.

Aren't we kind of stuck here?

On the previous iterations, we already discussed this and Tom eventually told he was in favour of __weak functions, and the discussion stopped there. I assumed you were ok with it.

I'd really want to move forward on that. This is something that is really biting us *now* and I'd hate to miss yet another merge window because of debates like this.

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180122/05ce10f3/attachment.sig>
#26 lore raw

PATCH v2 13/15 env: Mark env_get_location as weak

Quoted 35 lines · Maxime Ripard

Hi,

Quoted 24 lines · Simon Glass
Quoted 19 lines · Simon Glass
Quoted 13 lines
Quoted 10 lines · Maxime Ripard

Allow boards and architectures to override the default environment lookup code by overriding env_get_location.

---
 env/env.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 4 lines

I still don't really understand why this needs to be a weak function. If the board knows the priority order, can it not put it into global_data? We could have a little u8 array of 4 items with a terminator?

Quoted 4 lines

Sure that would be simpler, but that would also prevent us from doing "smart" things based on data other than just whether the previous environment is usable. Things based for example on a GPIO state, or a custom algorithm to transition (or duplicate) the environment.

Quoted 5 lines

In that case the board could read the GPIO state, or the algorithm, and then set up the value.

Basically I am saying it could set up the priority order in advance of it being needed, rather than having a callback.

Aren't we kind of stuck here?

Quoted 7 lines

On the previous iterations, we already discussed this and Tom eventually told he was in favour of __weak functions, and the discussion stopped there. I assumed you were ok with it.

I'd really want to move forward on that. This is something that is really biting us *now* and I'd hate to miss yet another merge window because of debates like this.

Yes, I think this is where we want things to be weak, with a reasonable default. If we start to see that "everyone" does the same thing by and large we can re-evaluate.

Signature · 8 lines
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/20180122/5b2523f2/attachment.sig>
#27 lore raw

PATCH v2 13/15 env: Mark env_get_location as weak

Quoted 40 lines · Tom Rini
Quoted 39 lines · Maxime Ripard

Hi,

Quoted 24 lines · Simon Glass
Quoted 19 lines · Simon Glass
Quoted 13 lines
Quoted 10 lines · Maxime Ripard

Allow boards and architectures to override the default environment lookup code by overriding env_get_location.

---
 env/env.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 4 lines

I still don't really understand why this needs to be a weak function. If the board knows the priority order, can it not put it into global_data? We could have a little u8 array of 4 items with a terminator?

Quoted 4 lines

Sure that would be simpler, but that would also prevent us from doing "smart" things based on data other than just whether the previous environment is usable. Things based for example on a GPIO state, or a custom algorithm to transition (or duplicate) the environment.

Quoted 5 lines

In that case the board could read the GPIO state, or the algorithm, and then set up the value.

Basically I am saying it could set up the priority order in advance of it being needed, rather than having a callback.

Aren't we kind of stuck here?

On the previous iterations, we already discussed this and Tom eventually told he was in favour of __weak functions, and the discussion stopped there. I assumed you were ok with it.

Quoted 7 lines
Quoted 3 lines

I'd really want to move forward on that. This is something that is really biting us *now* and I'd hate to miss yet another merge window because of debates like this.

Yes, I think this is where we want things to be weak, with a reasonable default. If we start to see that "everyone" does the same thing by and large we can re-evaluate.

Ok.

I've fixed the bug I mentionned the other day on IRC, should I send a PR?

Thanks!
Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180122/bcccd18e/attachment.sig>
#28 lore raw

PATCH v2 13/15 env: Mark env_get_location as weak

Quoted 45 lines · Maxime Ripard
Quoted 44 lines · Tom Rini
Quoted 42 lines · Maxime Ripard

Hi,

Quoted 24 lines · Simon Glass
Quoted 19 lines · Simon Glass
Quoted 13 lines
Quoted 10 lines · Maxime Ripard

Allow boards and architectures to override the default environment lookup code by overriding env_get_location.

---
 env/env.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 4 lines

I still don't really understand why this needs to be a weak function. If the board knows the priority order, can it not put it into global_data? We could have a little u8 array of 4 items with a terminator?

Quoted 4 lines

Sure that would be simpler, but that would also prevent us from doing "smart" things based on data other than just whether the previous environment is usable. Things based for example on a GPIO state, or a custom algorithm to transition (or duplicate) the environment.

Quoted 5 lines

In that case the board could read the GPIO state, or the algorithm, and then set up the value.

Basically I am saying it could set up the priority order in advance of it being needed, rather than having a callback.

Aren't we kind of stuck here?

On the previous iterations, we already discussed this and Tom eventually told he was in favour of __weak functions, and the discussion stopped there. I assumed you were ok with it.

I'd really want to move forward on that. This is something that is really biting us *now* and I'd hate to miss yet another merge window because of debates like this.

Quoted 7 lines
Quoted 3 lines

Yes, I think this is where we want things to be weak, with a reasonable default. If we start to see that "everyone" does the same thing by and large we can re-evaluate.

Ok.

I've fixed the bug I mentionned the other day on IRC, should I send a PR?

Lets give Simon a chance to provide any other feedback here, or another argument to convince me that no, we don't want to have this abstracted by a weak function but instead ..., thanks!

Signature · 8 lines
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/20180122/f56fce1a/attachment.sig>
#29 lore raw

PATCH v2 13/15 env: Mark env_get_location as weak

Hi,

Quoted 50 lines · Tom Rini
Quoted 49 lines · Maxime Ripard
Quoted 47 lines · Tom Rini
Quoted 35 lines · Maxime Ripard

Hi,

Quoted 24 lines · Simon Glass
Quoted 19 lines · Simon Glass
Quoted 13 lines
Quoted 10 lines · Maxime Ripard

Allow boards and architectures to override the default environment lookup code by overriding env_get_location.

---
 env/env.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 4 lines

I still don't really understand why this needs to be a weak function. If the board knows the priority order, can it not put it into global_data? We could have a little u8 array of 4 items with a terminator?

Quoted 4 lines

Sure that would be simpler, but that would also prevent us from doing "smart" things based on data other than just whether the previous environment is usable. Things based for example on a GPIO state, or a custom algorithm to transition (or duplicate) the environment.

Quoted 5 lines

In that case the board could read the GPIO state, or the algorithm, and then set up the value.

Basically I am saying it could set up the priority order in advance of it being needed, rather than having a callback.

Aren't we kind of stuck here?

Quoted 7 lines

On the previous iterations, we already discussed this and Tom eventually told he was in favour of __weak functions, and the discussion stopped there. I assumed you were ok with it.

I'd really want to move forward on that. This is something that is really biting us *now* and I'd hate to miss yet another merge window because of debates like this.

Yes, I think this is where we want things to be weak, with a reasonable default. If we start to see that "everyone" does the same thing by and large we can re-evaluate.

Quoted 7 lines
Quoted 3 lines

Ok.

I've fixed the bug I mentionned the other day on IRC, should I send a PR?

Lets give Simon a chance to provide any other feedback here, or another argument to convince me that no, we don't want to have this abstracted by a weak function but instead ..., thanks!

I suspect there is a reason why this is better than what I propose. Perhaps when I try it out it will become apparent.

So let's go ahead and revisit later if we have new information.

Regards,
Simon

#30 lore raw

PATCH v2 13/15 env: Mark env_get_location as weak

Quoted 61 lines · Simon Glass

Hi,

Quoted 50 lines · Tom Rini
Quoted 49 lines · Maxime Ripard
Quoted 47 lines · Tom Rini
Quoted 35 lines · Maxime Ripard

Hi,

Quoted 24 lines · Simon Glass
Quoted 19 lines · Simon Glass
Quoted 13 lines
Quoted 10 lines · Maxime Ripard

Allow boards and architectures to override the default environment lookup code by overriding env_get_location.

---
 env/env.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 4 lines

I still don't really understand why this needs to be a weak function. If the board knows the priority order, can it not put it into global_data? We could have a little u8 array of 4 items with a terminator?

Quoted 4 lines

Sure that would be simpler, but that would also prevent us from doing "smart" things based on data other than just whether the previous environment is usable. Things based for example on a GPIO state, or a custom algorithm to transition (or duplicate) the environment.

Quoted 5 lines

In that case the board could read the GPIO state, or the algorithm, and then set up the value.

Basically I am saying it could set up the priority order in advance of it being needed, rather than having a callback.

Aren't we kind of stuck here?

Quoted 7 lines

On the previous iterations, we already discussed this and Tom eventually told he was in favour of __weak functions, and the discussion stopped there. I assumed you were ok with it.

I'd really want to move forward on that. This is something that is really biting us *now* and I'd hate to miss yet another merge window because of debates like this.

Yes, I think this is where we want things to be weak, with a reasonable default. If we start to see that "everyone" does the same thing by and large we can re-evaluate.

Quoted 7 lines
Quoted 3 lines

Ok.

I've fixed the bug I mentionned the other day on IRC, should I send a PR?

Lets give Simon a chance to provide any other feedback here, or another argument to convince me that no, we don't want to have this abstracted by a weak function but instead ..., thanks!

Quoted 6 lines

I suspect there is a reason why this is better than what I propose. Perhaps when I try it out it will become apparent.

So let's go ahead and revisit later if we have new information.

Thanks! Maxime, please re-spin with the bugfix (or wait another day or two for other feedback), repost and I'll take it in Thurs/Fri or so.

Signature · 8 lines
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/20180122/f752a01e/attachment.sig>
#31 lore raw

PATCH v2 14/15 sunxi: Transition from the MMC to a FAT-based environment

In reply to Maxime Ripard

The current environment has been hardcoded to an offset that starts to be an issue given the current size of our main U-Boot binary.

By implementing a custom environment location routine, we can always favor the FAT-based environment, and fallback to the MMC if we don't find something in the FAT partition. We also implement the same order when saving the environment, so that hopefully we can slowly migrate the users over to FAT-based environment and away from the raw MMC one.

Eventually, and hopefully before we reach that limit again, we will have most of our users using that setup, and we'll be able to retire the raw environment, and gain more room for the U-Boot binary.

---
 board/sunxi/board.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
board/sunxi/board.c +16 -0
index dcacdf3e626d..8891961dcc6b 100644
@@ -173,6 +173,22 @@ void i2c_init_board(void)
 #endif
 }
 
+#if defined(CONFIG_ENV_IS_IN_MMC) && defined(CONFIG_ENV_IS_IN_FAT)
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+	switch (prio) {
+	case 0:
+		return ENVL_FAT;
+
+	case 1:
+		return ENVL_MMC;
+
+	default:
+		return ENVL_UNKNOWN;
+	}
+}
+#endif
+
 /* add board specific code here */
 int board_init(void)
 {
Signature · 1 line
git-series 0.9.1
#32 lore raw

PATCH v2 15/15 env: sunxi: Enable FAT-based environment support by default

In reply to Maxime Ripard

Now that we have everything in place to implement the transition scheme, let's enable it by default.

---
 env/Kconfig | 4 ++++
 1 file changed, 4 insertions(+)
env/Kconfig +4 -0
index 6e2fbf416c12..d1bf75ab41ca 100644
@@ -55,6 +55,7 @@ config ENV_IS_IN_FAT
 	bool "Environment is in a FAT filesystem"
 	depends on !CHAIN_OF_TRUST
 	default y if ARCH_BCM283X
+	default y if ARCH_SUNXI && MMC
 	default y if MMC_OMAP_HS && TI_COMMON_CMD_OPTIONS
 	select FAT_WRITE
 	help
@@ -363,6 +364,7 @@ config ENV_IS_IN_UBI
 config ENV_FAT_INTERFACE
 	string "Name of the block device for the environment"
 	depends on ENV_IS_IN_FAT
+	default "mmc" if ARCH_SUNXI
 	default "mmc" if TI_COMMON_CMD_OPTIONS || ARCH_ZYNQMP || ARCH_AT91
 	help
 	  Define this to a string that is the name of the block device.
@@ -372,6 +374,8 @@ config ENV_FAT_DEVICE_AND_PART
 	depends on ENV_IS_IN_FAT
 	default "0:1" if TI_COMMON_CMD_OPTIONS
 	default "0:auto" if ARCH_ZYNQMP
+	default "0:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA = -1
+	default "1:auto" if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA != -1
 	default "0" if ARCH_AT91
 	help
 	  Define this to a string to specify the partition of the device. It can
Signature · 1 line
git-series 0.9.1
#33 lore raw

v2 cover env: Multiple env support and env transition for sunxi

In reply to Maxime Ripard
Quoted 12 lines · Maxime Ripard

Hi,

Here is a second attempt at transitioning away from the MMC raw environment to a FAT-based one for Allwinner SoCs. Since the RFC was quite well received, I actually tested it and fixed a few rough edges.

You'll find the first RFC here for reference:
https://lists.denx.de/pipermail/u-boot/2017-October/310111.html

And the second that originated in this series:
https://lists.denx.de/pipermail/u-boot/2017-November/311608.html

Quoted 6 lines

I gave it a travis run, and one test seems to fail in one test:
https://travis-ci.org/mripard/u-boot/jobs/329229382

I really cannot really make any sense of why a change in the way the environment loads could affect the operation of a DHCP client. Is there a way to reproduce locally?

In this case, roughly, clone https://github.com/swarren/uboot-test-hooks
and then:

$ export PATH=${PATH}:/path/to/uboot-test-hooks/bin
$ export PYTHONPATH=/path/to/uboot-test-hooks/py/travis-ci:${PYTHONPATH}
$ export UBOOT_TRAVIS_BUILD_DIR=`cd .. && pwd`/.bm-work/$1
$ ./test/py/test.py --bd vexpress_ca15_tc2 --build-dir "$UBOOT_TRAVIS_BUILD_DIR" -k 'net'
Signature · 8 lines
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/20180116/51484971/attachment.sig>
#34 lore raw

v2 cover env: Multiple env support and env transition for sunxi

Hi,

Quoted 20 lines · Tom Rini
Quoted 12 lines · Maxime Ripard

Hi,

Here is a second attempt at transitioning away from the MMC raw environment to a FAT-based one for Allwinner SoCs. Since the RFC was quite well received, I actually tested it and fixed a few rough edges.

You'll find the first RFC here for reference:
https://lists.denx.de/pipermail/u-boot/2017-October/310111.html

And the second that originated in this series:
https://lists.denx.de/pipermail/u-boot/2017-November/311608.html

Quoted 6 lines

I gave it a travis run, and one test seems to fail in one test:
https://travis-ci.org/mripard/u-boot/jobs/329229382

I really cannot really make any sense of why a change in the way the environment loads could affect the operation of a DHCP client. Is there a way to reproduce locally?

Quoted 6 lines

In this case, roughly, clone https://github.com/swarren/uboot-test-hooks
and then:

$ export PATH=${PATH}:/path/to/uboot-test-hooks/bin
$ export PYTHONPATH=/path/to/uboot-test-hooks/py/travis-ci:${PYTHONPATH}
$ export UBOOT_TRAVIS_BUILD_DIR=`cd .. && pwd`/.bm-work/$1
$ ./test/py/test.py --bd vexpress_ca15_tc2 --build-dir "$UBOOT_TRAVIS_BUILD_DIR" -k 'net'

Thanks, I had to tweak it a bit to add --id qemu, and copy the conf.vexpress_ca15_tc2_qemu file in a directory with my hostname in the uboot-test-hooks repo.

And this is really getting weird, since the tests passes on my machine:
http://code.bulix.org/rp6z29-258577

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180117/0f883d5c/attachment.sig>
#35 lore raw

v2 cover env: Multiple env support and env transition for sunxi

Quoted 30 lines · Maxime Ripard

Hi,

Quoted 20 lines · Tom Rini
Quoted 12 lines · Maxime Ripard

Hi,

Here is a second attempt at transitioning away from the MMC raw environment to a FAT-based one for Allwinner SoCs. Since the RFC was quite well received, I actually tested it and fixed a few rough edges.

You'll find the first RFC here for reference:
https://lists.denx.de/pipermail/u-boot/2017-October/310111.html

And the second that originated in this series:
https://lists.denx.de/pipermail/u-boot/2017-November/311608.html

Quoted 6 lines

I gave it a travis run, and one test seems to fail in one test:
https://travis-ci.org/mripard/u-boot/jobs/329229382

I really cannot really make any sense of why a change in the way the environment loads could affect the operation of a DHCP client. Is there a way to reproduce locally?

Quoted 6 lines

In this case, roughly, clone https://github.com/swarren/uboot-test-hooks
and then:

$ export PATH=${PATH}:/path/to/uboot-test-hooks/bin
$ export PYTHONPATH=/path/to/uboot-test-hooks/py/travis-ci:${PYTHONPATH}
$ export UBOOT_TRAVIS_BUILD_DIR=`cd .. && pwd`/.bm-work/$1
$ ./test/py/test.py --bd vexpress_ca15_tc2 --build-dir "$UBOOT_TRAVIS_BUILD_DIR" -k 'net'
Quoted 3 lines

Thanks, I had to tweak it a bit to add --id qemu, and copy the conf.vexpress_ca15_tc2_qemu file in a directory with my hostname in the uboot-test-hooks repo.

Ah right, yes, oops. I quickly grabbed bits out of my local wrapper script around it.

Quoted 3 lines

And this is really getting weird, since the tests passes on my machine:
http://code.bulix.org/rp6z29-258577

Does it repeatedly fail in travis (which, uh, stopped working for me yesterday, I haven't seen if it's un-wedged today)? You can restart a specific sub-job rather than the whole.

Signature · 8 lines
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/20180117/10df4368/attachment.sig>
#36 lore raw

v2 cover env: Multiple env support and env transition for sunxi

Quoted 31 lines · Tom Rini
Quoted 30 lines · Maxime Ripard

Hi,

Quoted 26 lines · Tom Rini
Quoted 12 lines · Maxime Ripard

Hi,

Here is a second attempt at transitioning away from the MMC raw environment to a FAT-based one for Allwinner SoCs. Since the RFC was quite well received, I actually tested it and fixed a few rough edges.

You'll find the first RFC here for reference:
https://lists.denx.de/pipermail/u-boot/2017-October/310111.html

And the second that originated in this series:
https://lists.denx.de/pipermail/u-boot/2017-November/311608.html

Quoted 6 lines

I gave it a travis run, and one test seems to fail in one test:
https://travis-ci.org/mripard/u-boot/jobs/329229382

I really cannot really make any sense of why a change in the way the environment loads could affect the operation of a DHCP client. Is there a way to reproduce locally?

In this case, roughly, clone https://github.com/swarren/uboot-test-hooks
and then:

$ export PATH=${PATH}:/path/to/uboot-test-hooks/bin
$ export PYTHONPATH=/path/to/uboot-test-hooks/py/travis-ci:${PYTHONPATH}
$ export UBOOT_TRAVIS_BUILD_DIR=`cd .. && pwd`/.bm-work/$1
$ ./test/py/test.py --bd vexpress_ca15_tc2 --build-dir "$UBOOT_TRAVIS_BUILD_DIR" -k 'net'
Quoted 6 lines
Quoted 3 lines

Thanks, I had to tweak it a bit to add --id qemu, and copy the conf.vexpress_ca15_tc2_qemu file in a directory with my hostname in the uboot-test-hooks repo.

Ah right, yes, oops. I quickly grabbed bits out of my local wrapper script around it.

Don't worry, I was on a good enough path :)

Quoted 7 lines
Quoted 3 lines

And this is really getting weird, since the tests passes on my machine:
http://code.bulix.org/rp6z29-258577

Does it repeatedly fail in travis (which, uh, stopped working for me yesterday, I haven't seen if it's un-wedged today)? You can restart a specific sub-job rather than the whole.

It was repeatedly failing for that commit, but I reordered a few commits since (and I tested the new branch on my machine). I triggered a new build on travis that is currently running, but is taking a long time to complete. I'll let you know the results.

Thanks!
Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180117/009b0185/attachment.sig>