When the environment is reset with "env default -a" before booting,
the kernel device tree gets no /serial-number and keeps its all-zero
MAC addresses, so Linux reports "Using random MAC address".
misc_init_r() reads both values from the ATSHA204A into the environment
at startup, and the device tree fixups take them from there, so the
reset loses them.

Read the OTP again in ft_board_setup() and repeat these fixups, through
a new weak hook in the shared P1/P2 RDB code next to
p1_p2_rdb_pc_fix_fdt_model(). As in misc_init_r(), a valid MAC address
or a 16-character serial# already in the environment is kept. An
EVT_FT_FIXUP spy would not be called: without OFNODE_MULTI_TREE, which
Turris 1.x does not enable, image_setup_libfdt() sends that event only
for the control device tree.

Tested on CZ.NIC Turris 1.1 with the NOR and the SD card build after
"env default -a".

Fixes: f41582035cf7 ("powerpc: Add support for CZ.NIC Turris 1.x routers")
Signed-off-by: Josef Schlehofer <[email protected]>
Reviewed-by: Marek Mojík <[email protected]>
Cc: Marek Mojík <[email protected]>
Cc: Marek Behún <[email protected]>
Cc: Priyanka Jain <[email protected]>
---
(no changes since v1)
---
 board/CZ.NIC/turris_1x/turris_1x.c    | 20 ++++++++++++++++++++
 board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c |  3 +++
 2 files changed, 23 insertions(+)

diff --git a/board/CZ.NIC/turris_1x/turris_1x.c 
b/board/CZ.NIC/turris_1x/turris_1x.c
index 32535ed6ee0..8173e021f11 100644
--- a/board/CZ.NIC/turris_1x/turris_1x.c
+++ b/board/CZ.NIC/turris_1x/turris_1x.c
@@ -315,6 +315,26 @@ int misc_init_r(void)
        return 0;
 }
 
+/*
+ * The generic fixups copy the MAC addresses and the serial number from the
+ * environment into the kernel device tree. misc_init_r() puts them there, but
+ * if the environment is reset before booting, e.g. by "env default -a", they
+ * are gone. Read them from the OTP again and repeat these fixups. Valid MAC
+ * addresses and a 16-character serial# set in the environment are kept.
+ */
+void p1_p2_rdb_pc_fix_fdt_env(void *blob)
+{
+       int ret;
+
+       ret = turris_atsha_otp_init_mac_addresses(0);
+       if (ret)
+               printf("Cannot read MAC addresses from OTP: %d\n", ret);
+       turris_atsha_otp_init_serial_number();
+
+       fdt_fixup_ethernet(blob);
+       fdt_root(blob);
+}
+
 /* This comes from ../../nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c */
 extern int checkboard_p1_p2(void);
 
diff --git a/board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c 
b/board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c
index a19a98dd0d1..07c18117cbe 100644
--- a/board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c
+++ b/board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c
@@ -373,6 +373,8 @@ int board_early_init_r(void)
 
 __weak void p1_p2_rdb_pc_fix_fdt_model(void *blob) {}
 
+__weak void p1_p2_rdb_pc_fix_fdt_env(void *blob) {}
+
 #if defined(CONFIG_OF_BOARD_SETUP) || defined(CONFIG_OF_BOARD_FIXUP)
 static void fix_max6370_watchdog(void *blob)
 {
@@ -418,6 +420,7 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 
        p1_p2_rdb_pc_fix_fdt_model(blob);
        fix_max6370_watchdog(blob);
+       p1_p2_rdb_pc_fix_fdt_env(blob);
 
 #if defined(CONFIG_HAS_FSL_DR_USB)
        fsl_fdt_fixup_dr_usb(blob, bd);
-- 
2.54.0 (Apple Git-157)

Reply via email to