]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
toradex: common: Use SETTINGS_R event to read toradex config block
authorEmanuele Ghidoli <emanuele.ghidoli@toradex.com>
Fri, 23 Feb 2024 09:11:39 +0000 (10:11 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 1 Mar 2024 14:10:44 +0000 (09:10 -0500)
Use SETTINGS_R event to read toradex config block and checkboard()
to print board info.

Acked-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Tested-by: Marcel Ziswiler <marcel.ziswiler@toradex.com> # Verdin iMX8M Plus
Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
Reviewed-by: Fabio Estevam <festevam@gmail.com>
board/toradex/common/tdx-common.c

index cdf645b141774bcb77c2a03da08b9cae7549cf5c..6084436b48b49ae0bc6179118fdd4b76fa7dbfed 100644 (file)
@@ -103,54 +103,69 @@ __weak int print_bootinfo(void)
 
 int checkboard(void)
 {
-       unsigned char ethaddr[6];
-
-       if (read_tdx_cfg_block()) {
-               printf("MISSING TORADEX CONFIG BLOCK\n");
-               get_mac_from_serial(tdx_serial, &tdx_eth_addr);
-       } else {
-               snprintf(tdx_serial_str, sizeof(tdx_serial_str),
-                        "%08u", tdx_serial);
-               snprintf(tdx_board_rev_str, sizeof(tdx_board_rev_str),
-                        "V%1d.%1d%s",
-                        tdx_hw_tag.ver_major,
-                        tdx_hw_tag.ver_minor,
-                        get_board_assembly(tdx_hw_tag.ver_assembly));
-
-               env_set("serial#", tdx_serial_str);
-
+       if (valid_cfgblock) {
                printf("Model: Toradex %04d %s %s\n",
                       tdx_hw_tag.prodid,
                       toradex_modules[tdx_hw_tag.prodid].name,
                       tdx_board_rev_str);
                printf("Serial#: %s\n", tdx_serial_str);
+       }
+
 #ifdef CONFIG_TDX_CFG_BLOCK_EXTRA
-               if (read_tdx_cfg_block_carrier()) {
-                       printf("MISSING TORADEX CARRIER CONFIG BLOCKS\n");
-                       try_migrate_tdx_cfg_block_carrier();
-               } else {
-                       tdx_carrier_board_name =
-                               get_toradex_carrier_boards(tdx_car_hw_tag.prodid);
-
-                       snprintf(tdx_car_serial_str, sizeof(tdx_car_serial_str),
-                                "%08u", tdx_car_serial);
-                       snprintf(tdx_car_rev_str, sizeof(tdx_car_rev_str),
-                                "V%1d.%1d%s",
-                                tdx_car_hw_tag.ver_major,
-                                tdx_car_hw_tag.ver_minor,
-                                get_board_assembly(tdx_car_hw_tag.ver_assembly));
-
-                       env_set("carrier_serial#", tdx_car_serial_str);
-                       printf("Carrier: Toradex %s %s, Serial# %s\n",
-                              tdx_carrier_board_name,
-                              tdx_car_rev_str,
-                              tdx_car_serial_str);
-               }
+       if (tdx_carrier_board_name)
+               printf("Carrier: Toradex %s %s, Serial# %s\n",
+                      tdx_carrier_board_name,
+                      tdx_car_rev_str,
+                      tdx_car_serial_str);
 #endif
-       }
 
        print_bootinfo();
 
+       return 0;
+}
+
+static int settings_r(void)
+{
+       unsigned char ethaddr[6];
+
+       if (read_tdx_cfg_block()) {
+               printf("MISSING TORADEX CONFIG BLOCK\n");
+               get_mac_from_serial(tdx_serial, &tdx_eth_addr);
+
+               /* Board can run even if config block is not present */
+               return 0;
+       }
+
+       snprintf(tdx_serial_str, sizeof(tdx_serial_str),
+                "%08u", tdx_serial);
+       snprintf(tdx_board_rev_str, sizeof(tdx_board_rev_str),
+                "V%1d.%1d%s",
+                tdx_hw_tag.ver_major,
+                tdx_hw_tag.ver_minor,
+                get_board_assembly(tdx_hw_tag.ver_assembly));
+
+       env_set("serial#", tdx_serial_str);
+
+#ifdef CONFIG_TDX_CFG_BLOCK_EXTRA
+       if (read_tdx_cfg_block_carrier()) {
+               printf("MISSING TORADEX CARRIER CONFIG BLOCKS\n");
+               try_migrate_tdx_cfg_block_carrier();
+       } else {
+               tdx_carrier_board_name =
+                       get_toradex_carrier_boards(tdx_car_hw_tag.prodid);
+
+               snprintf(tdx_car_serial_str, sizeof(tdx_car_serial_str),
+                        "%08u", tdx_car_serial);
+               snprintf(tdx_car_rev_str, sizeof(tdx_car_rev_str),
+                        "V%1d.%1d%s",
+                        tdx_car_hw_tag.ver_major,
+                        tdx_car_hw_tag.ver_minor,
+                        get_board_assembly(tdx_car_hw_tag.ver_assembly));
+
+               env_set("carrier_serial#", tdx_car_serial_str);
+       }
+#endif
+
        /*
         * Check if environment contains a valid MAC address,
         * set the one from config block if not
@@ -171,6 +186,7 @@ int checkboard(void)
 
        return 0;
 }
+EVENT_SPY_SIMPLE(EVT_SETTINGS_R, settings_r);
 
 #ifdef CONFIG_TDX_CFG_BLOCK_USB_GADGET_PID
 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)