For boards without GPIO neither EEPROM identification, ${carrier} can come
from a NOR segment, an overlay, imported by ${cfg_import}.

The selection priority list becomes:
  1. the saved environment (saveenv)
  2. the NOR overlay, imported by ${cfg_import} when the environment
     defines it, for boards without GPIO or EEPROM identification
  3. the RCW build stamp
  4. NBXV3_CARRIER_DEFAULT, the build's default (fallback).

The NOR overlay is an environment image of ${cfg_nor_size} bytes
(CRC32 + data, as made by "mkenvimage -s 0x1000") that sets
carrier=<name>.

Signed-off-by: Vincent Jardin <[email protected]>

---

Changes in v2:
- new patch

 board/nxp/lx2160a/nbxv3/carrier.c | 24 ++++++++++++++++++++++--
 doc/board/nxp/nbxv3.rst           | 28 ++++++++++++++++++++++++++--
 2 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/board/nxp/lx2160a/nbxv3/carrier.c 
b/board/nxp/lx2160a/nbxv3/carrier.c
index 26b079a1d3a..daa6fce639d 100644
--- a/board/nxp/lx2160a/nbxv3/carrier.c
+++ b/board/nxp/lx2160a/nbxv3/carrier.c
@@ -18,10 +18,12 @@
  * ${carrier} comes, first match wins, from:
  *   1. the environment, e.g. a saved one:
  *        setenv carrier nbv32 && saveenv && reset
- *   2. the RCW build stamp in DCFG SCRATCHRW13, see below
- *   3. NBXV3_CARRIER_DEFAULT
+ *   2. the NOR overlay, imported by ${cfg_import}
+ *   3. the RCW build stamp in DCFG SCRATCHRW13, see below
+ *   4. NBXV3_CARRIER_DEFAULT
  */
 
+#include <command.h>
 #include <env.h>
 #include <hwconfig.h>
 #include <malloc.h>
@@ -114,6 +116,15 @@ static void nbxv3_carrier_disable_mc(void)
        printf("Carrier:       bring-up RCW (no SerDes IO), MC not started\n");
 }
 
+static void nbxv3_carrier_import_overlay(void)
+{
+       if (!env_get("cfg_import"))
+               return;
+
+       if (run_command("run cfg_import", 0))
+               debug("Carrier:       no usable overlay at 
${cfg_nor_offset}\n");
+}
+
 void nbxv3_carrier_env_init(void)
 {
        const char *carrier = env_get("carrier");
@@ -130,6 +141,15 @@ void nbxv3_carrier_env_init(void)
                return;
        }
 
+       nbxv3_carrier_import_overlay();
+
+       carrier = env_get("carrier");
+       if (carrier && *carrier) {
+               printf("Carrier:       %s (from the NOR overlay at %s)\n",
+                      carrier, env_get("cfg_nor_offset"));
+               return;
+       }
+
        carrier = nbxv3_carrier_detect(digit);
        if (carrier) {
                origin = "RCW build stamp";
diff --git a/doc/board/nxp/nbxv3.rst b/doc/board/nxp/nbxv3.rst
index 0e3578b5742..4806f9eada1 100644
--- a/doc/board/nxp/nbxv3.rst
+++ b/doc/board/nxp/nbxv3.rst
@@ -86,9 +86,33 @@ FIT image at NOR offset 0x1000000::
 
      => setenv carrier nbv32 && saveenv && reset
 
-2. the RCW build stamp, see below,
+2. the NOR overlay, imported by ``${cfg_import}`` when the environment
+   defines it, for boards without GPIO or EEPROM identification,
 
-3. ``nbv30``, the built-in default.
+3. the RCW build stamp, see below,
+
+4. ``nbv30``, the built-in default.
+
+NOR overlay
+^^^^^^^^^^^
+
+The NOR overlay is an environment image of ``${cfg_nor_size}`` bytes
+with ``carrier=<name>``.
+It is outside the environment slot, so wiping the
+saved environment keeps the board identity.
+
+``${cfg_import}``, ``${cfg_nor_offset}`` and ``${cfg_nor_size}`` are
+defined by the board's default environment
+(CONFIG_ENV_USE_DEFAULT_ENV_TEXT_FILE + CONFIG_ENV_DEFAULT_ENV_TEXT_FILE),
+or by a saved one.
+
+::
+
+  cfg_nor_offset=0x520000
+  cfg_nor_size=0x1000
+  cfg_import=sf probe 3:0 && \
+    sf read ${loadaddr} ${cfg_nor_offset} ${cfg_nor_size} && \
+    env import -c ${loadaddr} ${cfg_nor_size}
 
 RCW build stamp
 ^^^^^^^^^^^^^^^
-- 
2.43.0

Reply via email to