aboutsummaryrefslogtreecommitdiff
path: root/board/BuR/common
diff options
context:
space:
mode:
authorHannes Schmelzer2019-04-10 14:13:13 +0200
committerTom Rini2019-04-26 17:51:51 -0400
commit2fac7a82945902c79a14357407e8b63fde1a96e8 (patch)
treea14bce96f64eff0596e37aeb62e56f5dc6f5ce5c /board/BuR/common
parent47656d98bd721ef92f944f2c17938e8605c66698 (diff)
board/BuR/common: add 'brdefaulip_setup' function
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>
Diffstat (limited to 'board/BuR/common')
-rw-r--r--board/BuR/common/bur_common.h2
-rw-r--r--board/BuR/common/common.c34
2 files changed, 36 insertions, 0 deletions
diff --git a/board/BuR/common/bur_common.h b/board/BuR/common/bur_common.h
index f743194c346..2591bf4bb3e 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 28ebb84595f..89087d7dba0 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;