board: gateworks: venice: add board model/serial# to env
authorTim Harvey <tharvey@gateworks.com>
Tue, 27 Jul 2021 22:19:39 +0000 (15:19 -0700)
committerStefano Babic <sbabic@denx.de>
Mon, 9 Aug 2021 12:46:50 +0000 (14:46 +0200)
Add board model/serial# strings to env. Move the creation of the strings
to gsc_read() and the display of the info into gsc_info() so they are
available to U-Boot proper.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
board/gateworks/venice/gsc.c
board/gateworks/venice/gsc.h
board/gateworks/venice/imx8mm_venice.c

index e3d44ce..7d6acd7 100644 (file)
@@ -18,6 +18,7 @@ DECLARE_GLOBAL_DATA_PTR;
 struct venice_board_info som_info;
 struct venice_board_info base_info;
 char venice_model[32];
+uint32_t venice_serial;
 
 /* return a mac address from EEPROM info */
 int gsc_getmac(int index, uint8_t *address)
@@ -451,6 +452,8 @@ const char *gsc_get_dtb_name(int level, char *buf, int sz)
 
 static int gsc_read(void)
 {
+       char rev_pcb;
+       int rev_bom;
        int ret;
 
        ret = gsc_read_eeprom(GSC_BUSNO, GSC_EEPROM_ADDR, 1, &som_info);
@@ -460,25 +463,11 @@ static int gsc_read(void)
        }
 
        /* read optional baseboard EEPROM */
-       return gsc_read_eeprom(BASEBOARD_EEPROM_BUSNO, BASEBOARD_EEPROM_ADDR,
-                              2, &base_info);
-}
+       gsc_read_eeprom(BASEBOARD_EEPROM_BUSNO, BASEBOARD_EEPROM_ADDR,
+                       2, &base_info);
 
-static int gsc_info(int verbose)
-{
-       struct udevice *dev;
-       unsigned char buf[16];
-       char rev_pcb;
-       int rev_bom;
-
-       if (!base_info.model[0]) {
-               strcpy(venice_model, som_info.model);
-               printf("Model   : %s\n", som_info.model);
-               printf("Serial  : %d\n", som_info.serial);
-               printf("MFGDate : %02x-%02x-%02x%02x\n",
-                      som_info.mfgdate[0], som_info.mfgdate[1],
-                      som_info.mfgdate[2], som_info.mfgdate[3]);
-       } else {
+       /* create model strings */
+       if (base_info.model[0]) {
                sprintf(venice_model, "GW%c%c%c%c-%c%c-",
                        som_info.model[2], /* family */
                        base_info.model[3], /* baseboard */
@@ -499,22 +488,33 @@ static int gsc_info(int verbose)
                        sprintf(venice_model + strlen(venice_model), "%c%d", rev_pcb, rev_bom);
                else
                        sprintf(venice_model + strlen(venice_model), "%c", rev_pcb);
+       } else {
+               strcpy(venice_model, som_info.model);
+       }
+       venice_serial = som_info.serial;
 
-               if (verbose > 1) {
-                       printf("SOM     : %s %d %02x-%02x-%02x%02x\n",
-                              som_info.model, som_info.serial,
-                              som_info.mfgdate[0], som_info.mfgdate[1],
-                              som_info.mfgdate[2], som_info.mfgdate[3]);
-                       printf("BASE    : %s %d %02x-%02x-%02x%02x\n",
-                              base_info.model, base_info.serial,
-                              base_info.mfgdate[0], base_info.mfgdate[1],
-                              base_info.mfgdate[2], base_info.mfgdate[3]);
-               }
-               printf("Model   : %s\n", venice_model);
-               printf("Serial  : %d\n", som_info.serial);
-               printf("MFGDate : %02x-%02x-%02x%02x\n",
+       return 0;
+}
+
+static int gsc_info(int verbose)
+{
+       struct udevice *dev;
+       unsigned char buf[16];
+
+       printf("Model   : %s\n", venice_model);
+       printf("Serial  : %d\n", som_info.serial);
+       printf("MFGDate : %02x-%02x-%02x%02x\n",
+              som_info.mfgdate[0], som_info.mfgdate[1],
+              som_info.mfgdate[2], som_info.mfgdate[3]);
+       if (base_info.model[0] && verbose > 1) {
+               printf("SOM     : %s %d %02x-%02x-%02x%02x\n",
+                      som_info.model, som_info.serial,
                       som_info.mfgdate[0], som_info.mfgdate[1],
                       som_info.mfgdate[2], som_info.mfgdate[3]);
+               printf("BASE    : %s %d %02x-%02x-%02x%02x\n",
+                      base_info.model, base_info.serial,
+                      base_info.mfgdate[0], base_info.mfgdate[1],
+                      base_info.mfgdate[2], base_info.mfgdate[3]);
        }
 
        /* Display RTC */
@@ -576,6 +576,11 @@ const char *gsc_get_model(void)
        return venice_model;
 }
 
+uint32_t gsc_get_serial(void)
+{
+       return venice_serial;
+}
+
 #if !(IS_ENABLED(CONFIG_SPL_BUILD))
 static int gsc_sleep(unsigned long secs)
 {
index e0d0332..b391b2e 100644 (file)
@@ -40,5 +40,6 @@ int gsc_hwmon(void);
 const char *gsc_get_model(void);
 const char *gsc_get_dtb_name(int level, char *buf, int len);
 int gsc_getmac(int index, uint8_t *enetaddr);
+uint32_t gsc_get_serial(void);
 
 #endif
index ff64d69..ca01e75 100644 (file)
@@ -113,6 +113,10 @@ int board_late_init(void)
 
        led_default_state();
 
+       /* Set board serial/model */
+       env_set_ulong("serial#", gsc_get_serial());
+       env_set("model", gsc_get_model());
+
        /* Set fdt_file vars */
        i = 0;
        do {