All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Schmelzer <hannes.schmelzer@br-automation.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/6] board/BuR/common: add 'brdefaulip_setup' function
Date: Wed, 10 Apr 2019 14:13:13 +0200	[thread overview]
Message-ID: <1554898396-5549-3-git-send-email-hannes.schmelzer@br-automation.com> (raw)
In-Reply-To: <1554898396-5549-1-git-send-email-hannes.schmelzer@br-automation.com>

Many B&R boards are equipped with an I2C-EEPROM where various
information can be stored.

Today there is only a single byte for 'board_id' used.

We write this 'board_id' into environment for later use during boot.

If the value != 0xFF, meaning the byte is programmed, we modify the
"brdefaultip" environment variable for setting an IP-Address based on
board_id.

Signed-off-by: Hannes Schmelzer <hannes.schmelzer@br-automation.com>
---

 board/BuR/common/bur_common.h |  2 ++
 board/BuR/common/common.c     | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/board/BuR/common/bur_common.h b/board/BuR/common/bur_common.h
index f743194..2591bf4 100644
--- a/board/BuR/common/bur_common.h
+++ b/board/BuR/common/bur_common.h
@@ -21,4 +21,6 @@ void enable_i2c_pin_mux(void);
 void enable_board_pin_mux(void);
 int board_eth_init(bd_t *bis);
 
+int brdefaultip_setup(int bus, int chip);
+
 #endif
diff --git a/board/BuR/common/common.c b/board/BuR/common/common.c
index 28ebb84..89087d7 100644
--- a/board/BuR/common/common.c
+++ b/board/BuR/common/common.c
@@ -266,6 +266,40 @@ int ft_board_setup(void *blob, bd_t *bd)
 	return 0;
 }
 
+int brdefaultip_setup(int bus, int chip)
+{
+	int rc;
+	struct udevice *i2cdev;
+	u8 u8buf = 0;
+	char defip[256] = { 0 };
+
+	rc = i2c_get_chip_for_busnum(bus, chip, 2, &i2cdev);
+	if (rc != 0) {
+		printf("WARN: cannot probe baseboard EEPROM!\n");
+		return -1;
+	}
+
+	rc = dm_i2c_read(i2cdev, 0, &u8buf, 1);
+	if (rc != 0) {
+		printf("WARN: cannot read baseboard EEPROM!\n");
+		return -1;
+	}
+
+	if (u8buf != 0xFF)
+		snprintf(defip, sizeof(defip),
+			 "if test -r ${ipaddr}; then; else setenv ipaddr 192.168.60.%d; setenv serverip 192.168.60.254; setenv gatewayip 192.168.60.254; setenv netmask 255.255.255.0; fi;",
+			 u8buf);
+	else
+		strncpy(defip,
+			"if test -r ${ipaddr}; then; else setenv ipaddr 192.168.60.1; setenv serverip 192.168.60.254; setenv gatewayip 192.168.60.254; setenv netmask 255.255.255.0; fi;",
+			sizeof(defip));
+
+	env_set("brdefaultip", defip);
+	env_set_hex("board_id", u8buf);
+
+	return 0;
+}
+
 int overwrite_console(void)
 {
 	return 1;
-- 
2.7.4

  parent reply	other threads:[~2019-04-10 12:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-10 12:13 [U-Boot] [PATCH 1/6] board/BuR/common: prepare for compiling common into non AM33XX boards Hannes Schmelzer
2019-04-10 12:13 ` [U-Boot] [PATCH 2/6] board/BuR/common: cosmetic: move 'overwrite_console' up to more related stuff Hannes Schmelzer
2019-04-27 14:44   ` [U-Boot] [U-Boot, " Tom Rini
2019-04-10 12:13 ` Hannes Schmelzer [this message]
2019-04-27 14:44   ` [U-Boot] [U-Boot, 3/6] board/BuR/common: add 'brdefaulip_setup' function Tom Rini
2019-04-10 12:13 ` [U-Boot] [PATCH 4/6] board/BuR/common: add br resetcontoller implementation Hannes Schmelzer
2019-04-27 14:44   ` [U-Boot] [U-Boot, " Tom Rini
2019-04-10 12:13 ` [U-Boot] [PATCH 5/6] board/BuR/brxre1: cosmetic cleanup Hannes Schmelzer
2019-04-27 14:44   ` [U-Boot] [U-Boot,5/6] " Tom Rini
2019-04-10 12:13 ` [U-Boot] [PATCH 6/6] board/BuR/brxre1: use common resetcontroller implementation Hannes Schmelzer
2019-04-27 14:44   ` [U-Boot] [U-Boot, " Tom Rini
2019-04-27 14:44 ` [U-Boot] [U-Boot, 1/6] board/BuR/common: prepare for compiling common into non AM33XX boards Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1554898396-5549-3-git-send-email-hannes.schmelzer@br-automation.com \
    --to=hannes.schmelzer@br-automation.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.