]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
ARM: legoev3: set serial# env var
authorDavid Lechner <david@lechnology.com>
Mon, 11 Jan 2021 19:24:44 +0000 (13:24 -0600)
committerLokesh Vutla <lokeshvutla@ti.com>
Thu, 4 Feb 2021 15:07:56 +0000 (20:37 +0530)
This sets the serial# environmet variable instead of using ATAGs on
LEGO MINDSTORMS EV3.

Also fix some nomenclature while we are touching this code (Bluetooth
address is not the same as MAC address, EEPROM version is not the same
as board version).

Signed-off-by: David Lechner <david@lechnology.com>
board/lego/ev3/legoev3.c
configs/legoev3_defconfig
include/configs/legoev3.h

index 51b669a891b6e7f28c3693da17d357f22999774b..9ef3e12ce8c04729f8603f4eaeb897f7676ecc77 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include <common.h>
+#include <env.h>
 #include <i2c.h>
 #include <init.h>
 #include <spi.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-u8 board_rev;
-
 #define EEPROM_I2C_ADDR                0x50
 #define EEPROM_REV_OFFSET      0x3F00
-#define EEPROM_MAC_OFFSET      0x3F06
+#define EEPROM_BDADDR_OFFSET   0x3F06
 
 const struct pinmux_resource pinmuxes[] = {
        PINMUX_ITEM(spi0_pins_base),
@@ -52,59 +51,46 @@ const struct lpsc_resource lpsc[] = {
 
 const int lpsc_size = ARRAY_SIZE(lpsc);
 
-u32 get_board_rev(void)
-{
-       u8 buf[2];
-
-       if (!board_rev) {
-               if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) {
-                       printf("\nBoard revision read failed!\n");
-               } else {
-                       /*
-                        * Board rev 3 has MAC address at EEPROM_REV_OFFSET.
-                        * Other revisions have checksum at EEPROM_REV_OFFSET+1
-                        * to detect this.
-                        */
-                       if ((buf[0] ^ buf[1]) == 0xFF)
-                               board_rev = buf[0];
-                       else
-                               board_rev = 3;
-               }
-       }
-
-       return board_rev;
-}
-
 /*
- * The Bluetooth MAC address serves as the board serial number.
+ * The Bluetooth address serves as the board serial number.
  */
-void get_board_serial(struct tag_serialnr *serialnr)
+static void setup_serial_number(void)
 {
        u32 offset;
+       char serial_number[13];
        u8 buf[6];
+       u8 eeprom_rev;
+
+       if (env_get("serial#"))
+               return;
+
+       if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) {
+               printf("\nEEPROM revision read failed!\n");
+               return;
+       }
 
-       if (!board_rev)
-               board_rev = get_board_rev();
+       /*
+        * EEPROM rev 3 has Bluetooth address at EEPROM_REV_OFFSET.
+        * Other revisions have checksum at EEPROM_REV_OFFSET+1
+        * to detect this.
+        */
+       if ((buf[0] ^ buf[1]) == 0xFF)
+               eeprom_rev = buf[0];
+       else
+               eeprom_rev = 3;
 
-       /* Board rev 3 has MAC address where rev should be */
-       offset = (board_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_MAC_OFFSET;
+       /* EEPROM rev 3 has Bluetooth address where rev should be */
+       offset = (eeprom_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_BDADDR_OFFSET;
 
        if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) {
-               printf("\nBoard serial read failed!\n");
-       } else {
-               u8 *nr;
-
-               nr = (u8 *)&serialnr->low;
-               nr[0] = buf[5];
-               nr[1] = buf[4];
-               nr[2] = buf[3];
-               nr[3] = buf[2];
-               nr = (u8 *)&serialnr->high;
-               nr[0] = buf[1];
-               nr[1] = buf[0];
-               nr[2] = 0;
-               nr[3] = 0;
+               printf("\nEEPROM serial read failed!\n");
+               return;
        }
+
+       sprintf(serial_number, "%02X%02X%02X%02X%02X%02X",
+               buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
+
+       env_set("serial#", serial_number);
 }
 
 int board_early_init_f(void)
@@ -150,3 +136,10 @@ int board_init(void)
 
        return 0;
 }
+
+int board_late_init(void)
+{
+       setup_serial_number();
+
+       return 0;
+}
index 7aff11ccca201a9ed62c60add583e849a98e1a51..fb0c4dc951684432c8d4bbc7ecc5a6f2e9a91bff 100644 (file)
@@ -12,6 +12,7 @@ CONFIG_AUTOBOOT_STOP_STR="l"
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_BOARD_LATE_INIT=y
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_ASKENV=y
 CONFIG_CRC32_VERIFY=y
index a5f7fab15e2fee1793107885e5a5296b9deb4baf..ca96683a3a6c7eec1d2a0ee7dd6ec5dd346f8dc6 100644 (file)
@@ -65,8 +65,6 @@
 #define LINUX_BOOT_PARAM_ADDR  (PHYS_SDRAM_1 + 0x100)
 #define CONFIG_HWCONFIG                /* enable hwconfig */
 #define CONFIG_CMDLINE_TAG
-#define CONFIG_REVISION_TAG
-#define CONFIG_SERIAL_TAG
 #define CONFIG_SETUP_MEMORY_TAGS
 #define CONFIG_SETUP_INITRD_TAG
 #define CONFIG_BOOTCOMMAND \