From patchwork Sun Dec 1 10:23:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Schocher X-Patchwork-Id: 1202832 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47Ql8b1Drdz9sR7 for ; Sun, 1 Dec 2019 21:38:39 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id DA9C4C21E2F; Sun, 1 Dec 2019 10:31:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id CFE49C21C57; Sun, 1 Dec 2019 10:28:51 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 69E38C21DAF; Sun, 1 Dec 2019 10:25:32 +0000 (UTC) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by lists.denx.de (Postfix) with ESMTPS id 9420CC21E45 for ; Sun, 1 Dec 2019 10:25:19 +0000 (UTC) Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 47QksC39V7z1rGS1 for ; Sun, 1 Dec 2019 11:25:19 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 47QksC34jzz1qwZx for ; Sun, 1 Dec 2019 11:25:19 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id h-jwyB9HFAyU for ; Sun, 1 Dec 2019 11:25:18 +0100 (CET) X-Auth-Info: 5TyBv9o/c55LhGk1Ghd29Bn77R9bQg7Sn9zE07VwExM= Received: from mail-internal.denx.de (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA for ; Sun, 1 Dec 2019 11:25:18 +0100 (CET) Received: from pollux.denx.de (pollux [192.168.1.1]) by mail-internal.denx.de (Postfix) with ESMTP id 480521871D4; Sun, 1 Dec 2019 11:23:36 +0100 (CET) Received: by pollux.denx.de (Postfix, from userid 515) id 462221A009A; Sun, 1 Dec 2019 11:23:36 +0100 (CET) From: Heiko Schocher To: U-Boot Mailing List Date: Sun, 1 Dec 2019 11:23:23 +0100 Message-Id: <20191201102332.21397-21-hs@denx.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191201102332.21397-1-hs@denx.de> References: <20191201102332.21397-1-hs@denx.de> MIME-Version: 1.0 Subject: [U-Boot] [PATCH v1 20/29] imx6: aristainetos: add i2c eeprom support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" add support for i2c eeprom and add parsing "Rescue" or "DefEnv" at offset 0x1ff0. Signed-off-by: Heiko Schocher --- board/aristainetos/aristainetos.c | 64 ++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) 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 #include #include +#include +#include #include #include #include @@ -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; }