[PATCH 1/3] cmd: env: Add 'env import -h' for Marvell hw_info formatted environments

Luka Kovacic luka.kovacic at sartura.hr
Thu Feb 4 11:46:35 CET 2021


The '-h' flag is added to the 'env import' command to enable parsing
Marvell hw_info formatted environments.
This format is often used on Marvell Armada A37XX based devices to store
parameters like the board serial number, factory MAC addresses and some
other information.

Currently this environment format can only be imported, not exported.
These parameters are usually written to the flash in the factory.

This functionality has been tested on the GST ESPRESSOBin-Ultra board
successfully.

Usage example:
 => sf probe
 => sf read ${loadaddr} 0x003E000A 0x1F0 # Read the environment from
SPI flash
 => env import -h ${loadaddr}

Signed-off-by: Luka Kovacic <luka.kovacic at sartura.hr>
Cc: Luka Perkov <luka.perkov at sartura.hr>
Cc: Robert Marko <robert.marko at sartura.hr>
---
 cmd/nvedit.c    | 22 ++++++++++++++++++----
 lib/hashtable.c |  2 +-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index d0d2eca904..eab490ac48 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -1060,7 +1060,7 @@ sep_err:
 
 #ifdef CONFIG_CMD_IMPORTENV
 /*
- * env import [-d] [-t [-r] | -b | -c] addr [size] [var ...]
+ * env import [-d] [-t [-r] | -b | -h | -c] addr [size] [var ...]
  *	-d:	delete existing environment before importing if no var is
  *		passed; if vars are passed, if one var is in the current
  *		environment but not in the environment at addr, delete var from
@@ -1073,6 +1073,7 @@ sep_err:
  *		to import text files created with editors which are using CRLF
  *		for line endings. Only effective in addition to -t.
  *	-b:	assume binary format ('\0' separated, "\0\0" terminated)
+ *	-h:	assume Marvell hw_info format (0x20 separated, "0x20\0" terminated)
  *	-c:	assume checksum protected environment format
  *	addr:	memory address to read from
  *	size:	length of input data; if missing, proper '\0'
@@ -1082,6 +1083,14 @@ sep_err:
  *	var...	List of the names of the only variables that get imported from
  *		the environment at address 'addr'. Without arguments, the whole
  *		environment gets imported.
+ *
+ * Using the "-h" flag you can import a Marvell hw_info formatted environment.
+ * This is commonly used on Marvell Armada A37XX devices to store the board serial
+ * number, MAC addresses and some other information.
+ * Currently you can only import these by loading the data into memory and parse it
+ * using this command. Exporting is currently not supported, due to tight memory
+ * restrictions and a strict formatting scheme.
+ * These parameters are usually populated in the factory.
  */
 static int do_env_import(struct cmd_tbl *cmdtp, int flag,
 			 int argc, char *const argv[])
@@ -1107,6 +1116,11 @@ static int do_env_import(struct cmd_tbl *cmdtp, int flag,
 					goto sep_err;
 				sep = '\0';
 				break;
+			case 'h':		/* Marvell hw_info format */
+				if (fmt++)
+					goto sep_err;
+				sep = 0x20;
+				break;
 			case 'c':		/* external checksum format */
 				if (fmt++)
 					goto sep_err;
@@ -1199,8 +1213,8 @@ static int do_env_import(struct cmd_tbl *cmdtp, int flag,
 	return 0;
 
 sep_err:
-	printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
-		cmd);
+	printf("## %s: only one of \"-b\", \"-h\", \"-c\" or \"-t\" allowed\n",
+	       cmd);
 	return 1;
 }
 #endif
@@ -1450,7 +1464,7 @@ static char env_help_text[] =
 #endif
 #endif
 #if defined(CONFIG_CMD_IMPORTENV)
-	"env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import environment\n"
+	"env import [-d] [-t [-r] | -b | -h | -c] addr [size] [var ...] - import environment\n"
 #endif
 #if defined(CONFIG_CMD_NVEDIT_INFO)
 	"env info - display environment information\n"
diff --git a/lib/hashtable.c b/lib/hashtable.c
index ff5ff72639..06322e3304 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -794,7 +794,7 @@ static int drop_var_from_set(const char *name, int nvars, char * vars[])
  * multi-line values.
  *
  * In theory, arbitrary separator characters can be used, but only
- * '\0' and '\n' have really been tested.
+ * '\0', '\n' and 0x20 have been tested.
  */
 
 int himport_r(struct hsearch_data *htab,
-- 
2.20.1



More information about the U-Boot mailing list