]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
riscv: sifive: fu540: set serial environment variable from otp
authorSagar Shrikant Kadam <sagar.kadam@sifive.com>
Mon, 12 Aug 2019 14:57:40 +0000 (07:57 -0700)
committerAndes <uboot@andestech.com>
Tue, 3 Sep 2019 01:29:54 +0000 (09:29 +0800)
This patch sets the serial# environment variable by reading the
board serial number from the OTP memory region.

Signed-off-by: Sagar Shrikant Kadam <sagar.kadam@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
board/sifive/fu540/fu540.c

index 11daf1a75a0214e93eb0f13e11e35faf4b232140..47a20902517c1584a975b428d908c367c9af81b4 100644 (file)
@@ -122,10 +122,20 @@ static void fu540_setup_macaddr(u32 serialnum)
 
 int misc_init_r(void)
 {
-       /* Set ethaddr environment variable if not set */
-       if (!env_get("ethaddr"))
-               fu540_setup_macaddr(fu540_read_serialnum());
-
+       u32 serial_num;
+       char buf[9] = {0};
+
+       /* Set ethaddr environment variable from board serial number */
+       if (!env_get("serial#")) {
+               serial_num = fu540_read_serialnum();
+               if (!serial_num) {
+                       WARN(true, "Board serial number should not be 0 !!\n");
+                       return 0;
+               }
+               snprintf(buf, sizeof(buf), "%08x", serial_num);
+               env_set("serial#", buf);
+               fu540_setup_macaddr(serial_num);
+       }
        return 0;
 }