[U-Boot] [PATCH 13/17] LEON3: Added GRETH EDCL debug link IP address initialization.

Daniel Hellstrom daniel at gaisler.com
Tue May 18 16:48:59 CEST 2010


Signed-off-by: Daniel Hellstrom <daniel at gaisler.com>
---
 arch/sparc/cpu/leon3/cpu_init.c |   14 ++++
 arch/sparc/cpu/leon3/greth.c    |  152 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 166 insertions(+), 0 deletions(-)
 create mode 100644 arch/sparc/cpu/leon3/greth.c

diff --git a/arch/sparc/cpu/leon3/cpu_init.c b/arch/sparc/cpu/leon3/cpu_init.c
index 1829a08..bb394a1 100644
--- a/arch/sparc/cpu/leon3/cpu_init.c
+++ b/arch/sparc/cpu/leon3/cpu_init.c
@@ -43,6 +43,9 @@ DECLARE_GLOBAL_DATA_PTR;
 /* reset CPU (jump to 0, without reset) */
 void start(void);
 
+/* Initialize GRETH EDCL on startup */
+extern void greth_edcl_init(void);
+
 ambapp_dev_irqmp *irqmp = NULL;
 ambapp_dev_gptimer *gptimer = NULL;
 unsigned int gptimer_irq = 0;
@@ -142,6 +145,17 @@ int cpu_init_r(void)
 	return (0);
 }
 
+/* Late CPU initialization
+ *
+ * At this point environment variables is available.
+ */
+void cpu_late_init(void)
+{
+#ifdef CONFIG_SYS_GRETH_EDCL_IP
+	greth_edcl_init();
+#endif
+}
+
 /* Busy wait a number of ms */
 void cpu_wait_ms_busy(unsigned long ms)
 {
diff --git a/arch/sparc/cpu/leon3/greth.c b/arch/sparc/cpu/leon3/greth.c
new file mode 100644
index 0000000..2e2ee14
--- /dev/null
+++ b/arch/sparc/cpu/leon3/greth.c
@@ -0,0 +1,152 @@
+/* GRETH EDCL IP number initialization
+ *
+ * (C) Copyright 2010
+ * Daniel Hellstrom, Aeroflex Gaisler, daniel at gaisler.com.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include <common.h>
+#include <ambapp.h>
+#include <config.h>
+#include <grlib/greth.h>
+
+#ifdef CONFIG_SYS_GRETH_EDCL_IP
+
+/* Set EDCL IP of GRETH[core_index] to IP number as indicated by ip_str
+ *
+ * This is useful for designs that have a disabled EDCL (IP=0.0.0.0) on
+ * reset, or when the default EDCL IP is no correct. Often 192.168.0.51
+ * is default, the IP must be unique which is a problem when multiple
+ * boards are used.
+ *
+ * NOTE: The EDCL IP must not be the same IP as U-BOOT is using.
+ *
+ * NOTE: This code should not be located in the GRETH driver, because
+ *       we might want to set the EDCL debug link IP but not enable
+ *       u-boot networking.
+ */
+int greth_edcl_ip_set(int core_index, char *ip_str)
+{
+	ambapp_apbdev apbdev;
+	unsigned int *greth_ip_reg;
+	unsigned int ip;
+	char *start, *end;
+	unsigned char ipbyte;
+	int i;
+
+	/* Find Device & IRQ via AMBA Plug&Play information,
+	 * CONFIG_SYS_GRLIB_GRETH_INDEX select which GRETH if multiple
+	 * GRETHs in system.
+	 */
+	if (ambapp_apb_find(&ambapp_plb, VENDOR_GAISLER, GAISLER_ETHMAC,
+				core_index, &apbdev) != 1) {
+		return -1;	/* GRETH not found */
+	}
+	greth_ip_reg = (unsigned int *)(apbdev.address + 0x1C);
+
+	/* Convert IP String into IP number */
+	ip = 0;
+	start = ip_str;
+	for (i = 0; i < 4; i++) {
+		ipbyte = simple_strtoul(start, &end, 10);
+		ip |= ipbyte << (24-i*8);
+		start = end + 1; /* Next byte in IP-string */
+	}
+
+	/* Set new IP address of EDCL */
+	*greth_ip_reg = ip;
+
+	printf("GRETH[0x%08x] EDCL IP: %s\n",
+		(unsigned int)greth_ip_reg, ip_str);
+
+	return 0;
+};
+
+char *greth_edcl_ip_table[8] =
+{
+#ifdef CONFIG_SYS_GRETH0_EDCL_IP_STR
+	CONFIG_SYS_GRETH0_EDCL_IP_STR,
+#else
+	NULL,
+#endif
+#ifdef CONFIG_SYS_GRETH1_EDCL_IP_STR
+	CONFIG_SYS_GRETH1_EDCL_IP_STR,
+#else
+	NULL,
+#endif
+#ifdef CONFIG_SYS_GRETH2_EDCL_IP_STR
+	CONFIG_SYS_GRETH2_EDCL_IP_STR,
+#else
+	NULL,
+#endif
+#ifdef CONFIG_SYS_GRETH3_EDCL_IP_STR
+	CONFIG_SYS_GRETH3_EDCL_IP_STR,
+#else
+	NULL,
+#endif
+#ifdef CONFIG_SYS_GRETH4_EDCL_IP_STR
+	CONFIG_SYS_GRETH4_EDCL_IP_STR,
+#else
+	NULL,
+#endif
+#ifdef CONFIG_SYS_GRETH5_EDCL_IP_STR
+	CONFIG_SYS_GRETH5_EDCL_IP_STR,
+#else
+	NULL,
+#endif
+#ifdef CONFIG_SYS_GRETH6_EDCL_IP_STR
+	CONFIG_SYS_GRETH6_EDCL_IP_STR,
+#else
+	NULL,
+#endif
+#ifdef CONFIG_SYS_GRETH7_EDCL_IP_STR
+	CONFIG_SYS_GRETH7_EDCL_IP_STR,
+#else
+	NULL,
+#endif
+};
+
+void greth_edcl_init(void)
+{
+	int i;
+	char *ip_str;
+	char envname[16];
+
+	/* Set EDCL IP of the first 8 cores, if requested by user through
+	 * Environment variable "greth_edcl_ipN" when N identifies which
+	 * GRETH core, or through defines set in board configuration.
+	 */
+	strcpy(envname, "greth_edcl_ipX");
+	for (i=0; i<8; i++) {
+		/* Is there a config for */
+		envname[13] = '0' + i;
+		ip_str = getenv(envname);
+		if ( ip_str == NULL ) {
+			ip_str = greth_edcl_ip_table[i];
+		}
+		if ( ip_str != NULL ) {
+			if ( greth_edcl_ip_set(i, ip_str) )
+				break;
+		}
+	}
+}
+
+#endif
-- 
1.5.4



More information about the U-Boot mailing list