[U-Boot] [U-BOOT PATCH v1] set serial environment variable

This patch sets serial environment variable by reading the OTP memory region of FU540-C000 SoC which is mounted on HiFive Unleashed A00 board.
The patch is based on master branch of[1]
[1] https://gitlab.denx.de/u-boot/custodians/u-boot-riscv
Following is the result:
U-Boot 2019.10-rc1-03748-gab38b00-dirty (Aug 11 2019 - 23:14:27 -0700)
CPU: rv64imafdc Model: SiFive HiFive Unleashed A00 DRAM: 8 GiB MMC: spi@10050000:mmc@0: 0 In: serial@10010000 Out: serial@10010000 Err: serial@10010000 Net: eth0: ethernet@10090000 Hit any key to stop autoboot: 0 => env print serial# serial#=000000d0
Change history against base patch: V1: -Reduced buf size by 2 bytes as suggested by Bin Meng. -Used true as argument to WARN message instead of 1. -Terminated the WARN message with newline.
Sagar Shrikant Kadam (1): riscv: sifive: fu540: set serial environment variable from otp
board/sifive/fu540/fu540.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)

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 --- board/sifive/fu540/fu540.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c index 11daf1a..47a2090 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; }

On Mon, Aug 12, 2019 at 10:58 PM Sagar Shrikant Kadam sagar.kadam@sifive.com wrote:
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
board/sifive/fu540/fu540.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
Reviewed-by: Bin Meng bmeng.cn@gmail.com Tested-by: Bin Meng bmeng.cn@gmail.com

Hi Bin,
On Mon, Aug 12, 2019 at 8:43 PM Bin Meng bmeng.cn@gmail.com wrote:
On Mon, Aug 12, 2019 at 10:58 PM Sagar Shrikant Kadam sagar.kadam@sifive.com wrote:
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
board/sifive/fu540/fu540.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
Reviewed-by: Bin Meng bmeng.cn@gmail.com Tested-by: Bin Meng bmeng.cn@gmail.com
Thanks for Reviewing and Testing the patch.
Regards, Sagar
participants (3)
-
Bin Meng
-
Sagar Kadam
-
Sagar Shrikant Kadam