summaryrefslogtreecommitdiff
path: root/board/aristainetos
diff options
context:
space:
mode:
authorHeiko Schocher <hs@denx.de>2019-12-01 11:23:23 +0100
committerStefano Babic <sbabic@denx.de>2020-01-07 10:26:55 +0100
commitf7cf76f8ac9ee61eb54184dd6a971af8a73ddb6a (patch)
tree301cfdba8bbcb89b2d67d232e5f40257a8542b0f /board/aristainetos
parent44184c2aa8cc38c4ea79d7bf4e9821514acb8bae (diff)
imx6: aristainetos: add i2c eeprom support
add support for i2c eeprom and add parsing "Rescue" or "DefEnv" at offset 0x1ff0. Signed-off-by: Heiko Schocher <hs@denx.de>
Diffstat (limited to 'board/aristainetos')
-rw-r--r--board/aristainetos/aristainetos.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/board/aristainetos/aristainetos.c b/board/aristainetos/aristainetos.c
index 846a99804a..55d3ab6f44 100644
--- a/board/aristainetos/aristainetos.c
+++ b/board/aristainetos/aristainetos.c
@@ -24,6 +24,8 @@
#include <bmp_logo.h>
#include <dm/root.h>
#include <env.h>
+#include <i2c_eeprom.h>
+#include <i2c.h>
#include <micrel.h>
#include <miiphy.h>
#include <lcd.h>
@@ -323,6 +325,64 @@ static void setup_board_gpio(void)
setup_one_led("led_blue", LEDST_OFF);
}
+#define ARI_RESC_FMT "setenv rescue_reason setenv bootargs \\${bootargs}" \
+ " rescueReason=%d "
+
+static void aristainetos_run_rescue_command(int reason)
+{
+ char rescue_reason_command[80];
+
+ sprintf(rescue_reason_command, ARI_RESC_FMT, reason);
+ run_command(rescue_reason_command, 0);
+}
+
+static int aristainetos_eeprom(void)
+{
+ struct udevice *dev;
+ int off;
+ int ret;
+ u8 data[0x10];
+ u8 rescue_reason;
+
+ off = fdt_path_offset(gd->fdt_blob, "eeprom0");
+ if (off < 0) {
+ printf("%s: No eeprom0 path offset\n", __func__);
+ return off;
+ }
+
+ ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
+ if (ret) {
+ printf("%s: Could not find EEPROM\n", __func__);
+ return ret;
+ }
+
+ ret = i2c_set_chip_offset_len(dev, 2);
+ if (ret)
+ return ret;
+
+ ret = i2c_eeprom_read(dev, 0x1ff0, (uint8_t *)data, 6);
+ if (ret) {
+ printf("%s: Could not read EEPROM\n", __func__);
+ return ret;
+ }
+
+ if (strncmp((char *)&data[3], "ReScUe", 6) == 0) {
+ rescue_reason = *(uint8_t *)&data[9];
+ memset(&data[3], 0xff, 7);
+ i2c_eeprom_write(dev, 0x1ff0, (uint8_t *)&data[3], 7);
+ printf("\nBooting into Rescue System (EEPROM)\n");
+ aristainetos_run_rescue_command(rescue_reason);
+ run_command("run rescue_load_fit rescueboot", 0);
+ } else if (strncmp((char *)data, "DeF", 3) == 0) {
+ memset(data, 0xff, 3);
+ i2c_eeprom_write(dev, 0x1ff0, (uint8_t *)data, 3);
+ printf("\nClear u-boot environment (set back to defaults)\n");
+ run_command("run default_env; saveenv; saveenv", 0);
+ }
+
+ return 0;
+};
+
int board_late_init(void)
{
char *my_bootdelay;
@@ -372,12 +432,14 @@ int board_late_init(void)
}
}
+ /* eeprom work */
+ aristainetos_eeprom();
+
/* set board_type */
if (gd->board_type == BOARD_TYPE_4)
env_set("board_type", ARI_BT_4);
else
env_set("board_type", ARI_BT_7);
-
return 0;
}