All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [U-BOOT PATCH v1] set serial environment variable
@ 2019-08-12 14:57 Sagar Shrikant Kadam
  2019-08-12 14:57 ` [U-Boot] [U-BOOT PATCH v1] riscv: sifive: fu540: set serial environment variable from otp Sagar Shrikant Kadam
  0 siblings, 1 reply; 4+ messages in thread
From: Sagar Shrikant Kadam @ 2019-08-12 14:57 UTC (permalink / raw)
  To: u-boot

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 at 10050000:mmc at 0: 0
In:    serial at 10010000
Out:   serial at 10010000
Err:   serial at 10010000
Net:   eth0: ethernet at 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(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [U-BOOT PATCH v1] riscv: sifive: fu540: set serial environment variable from otp
  2019-08-12 14:57 [U-Boot] [U-BOOT PATCH v1] set serial environment variable Sagar Shrikant Kadam
@ 2019-08-12 14:57 ` Sagar Shrikant Kadam
  2019-08-12 15:13   ` Bin Meng
  0 siblings, 1 reply; 4+ messages in thread
From: Sagar Shrikant Kadam @ 2019-08-12 14:57 UTC (permalink / raw)
  To: u-boot

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;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [U-BOOT PATCH v1] riscv: sifive: fu540: set serial environment variable from otp
  2019-08-12 14:57 ` [U-Boot] [U-BOOT PATCH v1] riscv: sifive: fu540: set serial environment variable from otp Sagar Shrikant Kadam
@ 2019-08-12 15:13   ` Bin Meng
  2019-08-13  4:37     ` Sagar Kadam
  0 siblings, 1 reply; 4+ messages in thread
From: Bin Meng @ 2019-08-12 15:13 UTC (permalink / raw)
  To: u-boot

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>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [U-BOOT PATCH v1] riscv: sifive: fu540: set serial environment variable from otp
  2019-08-12 15:13   ` Bin Meng
@ 2019-08-13  4:37     ` Sagar Kadam
  0 siblings, 0 replies; 4+ messages in thread
From: Sagar Kadam @ 2019-08-13  4:37 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-13  4:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 14:57 [U-Boot] [U-BOOT PATCH v1] set serial environment variable Sagar Shrikant Kadam
2019-08-12 14:57 ` [U-Boot] [U-BOOT PATCH v1] riscv: sifive: fu540: set serial environment variable from otp Sagar Shrikant Kadam
2019-08-12 15:13   ` Bin Meng
2019-08-13  4:37     ` Sagar Kadam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.