summaryrefslogtreecommitdiff
path: root/board/sifive/fu540
diff options
context:
space:
mode:
authorSagar Shrikant Kadam <sagar.kadam@sifive.com>2019-08-12 07:57:40 -0700
committerAndes <uboot@andestech.com>2019-09-03 09:29:54 +0800
commitcba0635386df71f7f39d940938811fdf279f83d2 (patch)
tree922a6f163282a1e409c828b43474aa82dea4c05e /board/sifive/fu540
parent4dfea4b5cd68b86dd47d1333f1871a402087deaa (diff)
riscv: sifive: fu540: set serial environment variable from otp
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>
Diffstat (limited to 'board/sifive/fu540')
-rw-r--r--board/sifive/fu540/fu540.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c
index 11daf1a75a..47a2090251 100644
--- a/board/sifive/fu540/fu540.c
+++ b/board/sifive/fu540/fu540.c
@@ -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;
}