From s.hauer at pengutronix.de  Wed Jun  2 04:53:58 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 2 Jun 2010 10:53:58 +0200
Subject: barebox-2010.06.0
Message-ID: <20100602085358.GR26820@pengutronix.de>

I really like monthly releases. They show activity ;)

Here's what happened since the last release:


The following changes since commit 1d6d5108e56b6b6f2fc72d2b35118f8bf545280d:

  barebox 2010.05.0 (2010-05-03 14:32:02 +0200)

are available in the git repository at:
  git://git.pengutronix.de/git/barebox master

Eric Benard (1):
      freescale-mx*5-3-stack : fix __flash_header_start

Eric B?nard (3):
      eukrea_cpuimx27: allow compilation without LP3972 selected
      i.MX27: add required defines for I2C2
      eukrea_cpuimx27_defconfig: increase MALLOC_SIZE

Ivo Clarysse (1):
      MX25PDK: Add support for 64MiB DDR2 SDRAM

Luotao Fu (1):
      fix error return value while loading environment

Sascha Hauer (18):
      i.MX35 stack: Fix mc9sdz60 reset register offset
      ARM: use memalign in dma_alloc_coherent to assure alignment
      fsl_udc: make it work with MMU on
      Increase MAX_FILES to 128
      fix _update scripts
      define __LINUX_ARM_ARCH__ for armv6 processors
      ARM: Add get_cr/set_cr functions
      ARM: update icache functions to use get_cr/set_cr
      add arm helper function to determine the program counter
      arm: remove unused variables from header file
      arm: move __mmu_cache_flush to bare_init section
      arm: reimplement startup code in C
      i.MX: remove __REG from esd controller regs. use readl/writel instead
      pcm043: reimplement lowlevel code in C
      i.MX35: Fix ahbclock calculation
      pcm038: reimplement lowlevel code in C
      pcm043: Fix check for being inside NFC space
      v2010-06.0

Uwe Kleine-K?nig (3):
      cfi_flash: use flash_write_word instead of reimplementing it again
      imx/gpio: make gpio_get_value actually work
      give nice output when generating barebox.bin and barebox.S

Wolfram Sang (1):
      nor: Don't use the sector for the unlock sequence

 Makefile                                     |   19 ++-
 arch/arm/Makefile                            |    1 +
 arch/arm/configs/eukrea_cpuimx27_defconfig   |    2 +-
 arch/arm/cpu/Makefile                        |    6 +-
 arch/arm/cpu/cache-armv4.S                   |    2 +
 arch/arm/cpu/cache-armv5.S                   |    2 +
 arch/arm/cpu/cache-armv6.S                   |    3 +
 arch/arm/cpu/cache-armv7.S                   |    2 +
 arch/arm/cpu/cpu.c                           |   94 ++---------
 arch/arm/cpu/mmu.c                           |    2 +-
 arch/arm/cpu/start-arm.S                     |  248 --------------------------
 arch/arm/cpu/start.c                         |  108 +++++++++++
 arch/arm/include/asm/barebox-arm.h           |   10 +-
 arch/arm/include/asm/common.h                |   18 ++
 arch/arm/include/asm/system.h                |   72 ++++++++
 arch/arm/lib/barebox.lds.S                   |    2 +-
 arch/arm/mach-imx/Kconfig                    |   12 ++-
 arch/arm/mach-imx/gpio.c                     |    2 +-
 arch/arm/mach-imx/include/mach/esdctl.h      |   10 +-
 arch/arm/mach-imx/include/mach/imx27-regs.h  |    3 +
 arch/arm/mach-imx/speed-imx35.c              |    4 +-
 board/a9m2410/env/bin/_update                |    2 +-
 board/a9m2440/env/bin/_update                |    2 +-
 board/at91sam9260ek/env/bin/_update          |    2 +-
 board/at91sam9263ek/env/bin/_update          |    2 +-
 board/eukrea_cpuimx27/env/bin/_update        |    2 +-
 board/eukrea_cpuimx27/eukrea_cpuimx27.c      |    6 +-
 board/freescale-mx25-3-stack/3stack.c        |   32 ++++-
 board/freescale-mx25-3-stack/env/bin/_update |    2 +-
 board/freescale-mx35-3-stack/3stack.c        |    4 +-
 board/freescale-mx35-3-stack/env/bin/_update |    2 +-
 board/freescale-mx35-3-stack/flash_header.c  |    2 +-
 board/imx27ads/env/bin/_update               |    2 +-
 board/ipe337/env/bin/_update                 |    2 +-
 board/kp_ukd_r1_num/env/bin/_update          |    2 +-
 board/mmccpu/env/bin/_update                 |    2 +-
 board/pcm037/env/bin/_update                 |    2 +-
 board/pcm038/Makefile                        |    2 +-
 board/pcm038/env/bin/_update                 |    2 +-
 board/pcm038/lowlevel.c                      |  117 ++++++++++++
 board/pcm038/lowlevel_init.S                 |  116 ------------
 board/pcm038/pcm038.c                        |    9 -
 board/pcm043/Makefile                        |    2 +-
 board/pcm043/env/bin/_update                 |    2 +-
 board/pcm043/lowlevel.c                      |  214 ++++++++++++++++++++++
 board/pcm043/lowlevel_init.S                 |  231 ------------------------
 board/pcm043/pcm043.c                        |   10 -
 board/phycard-i.MX27/env/bin/_update         |    2 +-
 board/phycore_mcf54xx/env/bin/_update        |    2 +-
 board/pm9263/env/bin/_update                 |    2 +-
 common/environment.c                         |    6 +-
 drivers/nor/cfi_flash.c                      |   19 +--
 drivers/nor/cfi_flash_amd.c                  |   16 +-
 drivers/usb/gadget/fsl_udc.c                 |   11 +-
 include/stdio.h                              |    2 +-
 55 files changed, 676 insertions(+), 779 deletions(-)
 delete mode 100644 arch/arm/cpu/start-arm.S
 create mode 100644 arch/arm/cpu/start.c
 create mode 100644 arch/arm/include/asm/system.h
 create mode 100644 board/pcm038/lowlevel.c
 delete mode 100644 board/pcm038/lowlevel_init.S
 create mode 100644 board/pcm043/lowlevel.c
 delete mode 100644 board/pcm043/lowlevel_init.S
-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From mailinglists at erwinrol.com  Thu Jun  3 16:40:18 2010
From: mailinglists at erwinrol.com (Erwin Rol)
Date: Thu, 03 Jun 2010 22:40:18 +0200
Subject: script error
Message-ID: <4C081332.6080904@erwinrol.com>

Hallo,

i have a problem with running scripts. It seems that as soon a command 
in a script fails the whole script is terminated.

I am trying the following in /env/bin/init

echo "Loading env A"
mkdir /env_a/
loadenv /dev/biosdisk0.1 /env_a/
if [ -f /env_a/revision ]; then
         . /env_a/revision
fi


The /dev/biosdisk0.1 is empty so the loadenv fails, and that also stops 
the /env/bin/init script, everything after the "fi" is never executed.

any ideas ?

- Erwin



From eric at eukrea.com  Thu Jun  3 16:52:10 2010
From: eric at eukrea.com (=?ISO-8859-1?Q?Eric_B=E9nard?=)
Date: Thu, 03 Jun 2010 22:52:10 +0200
Subject: script error
In-Reply-To: <4C081332.6080904@erwinrol.com>
References: <4C081332.6080904@erwinrol.com>
Message-ID: <4C0815FA.2080007@eukrea.com>

Hi Erwin,

Le 03/06/2010 22:40, Erwin Rol a ?crit :
> i have a problem with running scripts. It seems that as soon a command
> in a script fails the whole script is terminated.
>
> any ideas ?
>
I met the same problem in init yesterday. I didn't yet had time to 
investigate more.

Eric


From s.hauer at pengutronix.de  Fri Jun  4 05:54:56 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:54:56 +0200
Subject: reworking the network stack
Message-ID: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>

Hi all,

The following series reimplements the network stack. There are not
many uservisible changes (hopefully) other than that the new stack
is smaller in binary size.
As a bonus we get netconsole support at the end of this series.

Sascha



From s.hauer at pengutronix.de  Fri Jun  4 05:54:59 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:54:59 +0200
Subject: [PATCH 03/13] remove unused sntp.h
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-4-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/sntp.h |   61 ------------------------------------------------------------
 1 files changed, 0 insertions(+), 61 deletions(-)
 delete mode 100644 net/sntp.h

diff --git a/net/sntp.h b/net/sntp.h
deleted file mode 100644
index 8a097bf..0000000
--- a/net/sntp.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * (C) Masami Komiya <mkomiya at sonare.it> 2005
- *
- * 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, or (at
- * your option) any later version.
- */
-
-#ifndef __SNTP_H__
-#define __SNTP_H__
-
-#define NTP_SERVICE_PORT	123
-#define SNTP_PACKET_LEN		48
-
-
-/* Leap Indicator */
-#define NTP_LI_NOLEAP		0x0
-#define NTP_LI_61SECS		0x1
-#define NTP_LI_59SECS		0x2
-#define NTP_LI_ALARM		0x3
-
-/* Version */
-
-#define NTP_VERSION		4
-
-/* Mode */
-#define NTP_MODE_RESERVED	0
-#define NTP_MODE_SYMACTIVE	1	/* Symmetric Active */
-#define NTP_MODE_SYMPASSIVE	2	/* Symmetric Passive */
-#define NTP_MODE_CLIENT		3
-#define NTP_MODE_SERVER		4
-#define NTP_MODE_BROADCAST	5
-#define NTP_MODE_NTPCTRL	6	/* Reserved for NTP control message */
-#define NTP_MODE_PRIVATE	7	/* Reserved for private use */
-
-struct sntp_pkt_t {
-#if __LITTLE_ENDIAN
-	uchar mode:3;
-	uchar vn:3;
-	uchar li:2;
-#else
-	uchar li:2;
-	uchar vn:3;
-	uchar mode:3;
-#endif
-	uchar stratum;
-	uchar poll;
-	uchar precision;
-	uint root_delay;
-	uint root_dispersion;
-	uint reference_id;
-	unsigned long long reference_timestamp;
-	unsigned long long originate_timestamp;
-	unsigned long long receive_timestamp;
-	unsigned long long transmit_timestamp;
-};
-
-extern void	SntpStart (void);	/* Begin SNTP */
-
-#endif /* __SNTP_H__ */
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:55:08 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:55:08 +0200
Subject: [PATCH 12/13] errno: add strings for network related error messages
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-13-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/misc.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/common/misc.c b/common/misc.c
index b3292d3..7edf536 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -56,6 +56,10 @@ const char *strerror(int errnum)
 	case	ENAMETOOLONG	: str = "File name too long"; break;
 	case	ENOSYS		: str = "Function not implemented"; break;
 	case	ENOTEMPTY	: str = "Directory not empty"; break;
+	case	EHOSTUNREACH	: str = "No route to host"; break;
+	case	EINTR		: str = "Interrupted system call"; break;
+	case	ENETUNREACH	: str = "Network is unreachable"; break;
+	case	ENETDOWN	: str = "Network is down"; break;
 #if 0 /* These are probably not needed */
 	case	ENOTBLK		: str = "Block device required"; break;
 	case	EFBIG		: str = "File too large"; break;
@@ -79,8 +83,6 @@ const char *strerror(int errnum)
 	case	EAFNOSUPPORT	: str = "Address family not supported by protocol"; break;
 	case	EADDRINUSE	: str = "Address already in use"; break;
 	case	EADDRNOTAVAIL	: str = "Cannot assign requested address"; break;
-	case	ENETDOWN	: str = "Network is down"; break;
-	case	ENETUNREACH	: str = "Network is unreachable"; break;
 	case	ENETRESET	: str = "Network dropped connection because of reset"; break;
 	case	ECONNABORTED	: str = "Software caused connection abort"; break;
 	case	ECONNRESET	: str = "Connection reset by peer"; break;
@@ -88,7 +90,6 @@ const char *strerror(int errnum)
 	case	ETIMEDOUT	: str = "Connection timed out"; break;
 	case	ECONNREFUSED	: str = "Connection refused"; break;
 	case	EHOSTDOWN	: str = "Host is down"; break;
-	case	EHOSTUNREACH	: str = "No route to host"; break;
 	case	EALREADY	: str = "Operation already in progress"; break;
 	case	EINPROGRESS	: str = "Operation now in progress"; break;
 	case	ESTALE		: str = "Stale NFS file handle"; break;
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:54:57 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:54:57 +0200
Subject: [PATCH 01/13] net: remove need for eth_halt/eth_open
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-2-git-send-email-s.hauer@pengutronix.de>

We used to eth_open/eth_halt the network devices during NetLoopInit
which is called whenever the user enters a network command.
Change this behaviour so that the current network device gets opened
when making it the current one.
With this change it's always possible to send packages and we are able
to implement a new network stack in the next step.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/net.c |   20 ++++++++++++--------
 include/net.h  |    1 +
 net/eth.c      |   56 ++++++++++++++++++++++++++++++++++++--------------------
 net/net.c      |   21 +++++++++++++--------
 net/ping.c     |    1 -
 5 files changed, 62 insertions(+), 37 deletions(-)

diff --git a/commands/net.c b/commands/net.c
index 815a566..949963f 100644
--- a/commands/net.c
+++ b/commands/net.c
@@ -39,12 +39,16 @@ void netboot_update_env(void)
 {
 	struct eth_device *eth_current = eth_get_current();
 	char tmp[22];
+	IPaddr_t net_gateway_ip = NetOurGatewayIP;
+	IPaddr_t net_ip = NetOurIP;
+	IPaddr_t net_server_ip = NetServerIP;
+	IPaddr_t netmask = NetOurSubnetMask;
 
-	if (NetOurGatewayIP)
-		dev_set_param_ip(&eth_current->dev, "gateway", NetOurGatewayIP);
+	if (net_gateway_ip)
+		dev_set_param_ip(&eth_current->dev, "gateway", net_gateway_ip);
 
-	if (NetOurSubnetMask)
-		dev_set_param_ip(&eth_current->dev, "netmask", NetOurSubnetMask);
+	if (netmask)
+		dev_set_param_ip(&eth_current->dev, "netmask", netmask);
 
 
 	if (NetOurHostName[0])
@@ -53,11 +57,11 @@ void netboot_update_env(void)
 	if (NetOurRootPath[0])
 		setenv ("rootpath", NetOurRootPath);
 
-	if (NetOurIP)
-		dev_set_param_ip(&eth_current->dev, "ipaddr", NetOurIP);
+	if (net_ip)
+		dev_set_param_ip(&eth_current->dev, "ipaddr", net_ip);
 
-	if (NetServerIP)
-		dev_set_param_ip(&eth_current->dev, "serverip", NetServerIP);
+	if (net_server_ip)
+		dev_set_param_ip(&eth_current->dev, "serverip", net_server_ip);
 
 	if (NetOurDNSIP) {
 		ip_to_string (NetOurDNSIP, tmp);
diff --git a/include/net.h b/include/net.h
index 7353c8f..de78293 100644
--- a/include/net.h
+++ b/include/net.h
@@ -57,6 +57,7 @@ struct device_d;
 struct eth_device {
 	int iobase;
 	int state;
+	int active;
 
 	int  (*init) (struct eth_device*);
 
diff --git a/net/eth.c b/net/eth.c
index 7570198..fc16233 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -36,7 +36,13 @@ static LIST_HEAD(netdev_list);
 
 void eth_set_current(struct eth_device *eth)
 {
+	if (eth_current && eth_current->active) {
+		eth_current->halt(eth_current);
+		eth_current->active = 0;
+	}
+
 	eth_current = eth;
+	net_update_env();
 }
 
 struct eth_device * eth_get_current(void)
@@ -57,37 +63,37 @@ struct eth_device *eth_get_byname(char *ethname)
 	return NULL;
 }
 
-int eth_open(void)
-{
-	if (!eth_current)
-		return -ENODEV;
-
-	return eth_current->open(eth_current);
-}
-
-void eth_halt(void)
-{
-	if (!eth_current)
-		return;
-
-	eth_current->halt(eth_current);
-
-	eth_current->state = ETH_STATE_PASSIVE;
-}
-
 int eth_send(void *packet, int length)
 {
+	int ret;
+
 	if (!eth_current)
 		return -ENODEV;
 
+	if (!eth_current->active) {
+		ret = eth_current->open(eth_current);
+		if (ret)
+			return ret;
+		eth_current->active = 1;
+	}
+
 	return eth_current->send(eth_current, packet, length);
 }
 
 int eth_rx(void)
 {
+	int ret;
+
 	if (!eth_current)
 		return -ENODEV;
 
+	if (!eth_current->active) {
+		ret = eth_current->open(eth_current);
+		if (ret)
+			return ret;
+		eth_current->active = 1;
+	}
+
 	return eth_current->recv(eth_current);
 }
 
@@ -104,11 +110,15 @@ static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const ch
 
 	edev->set_ethaddr(edev, ethaddr);
 
+	if (edev == eth_current)
+		net_update_env();
+
 	return 0;
 }
 
 static int eth_set_ipaddr(struct device_d *dev, struct param_d *param, const char *val)
 {
+	struct eth_device *edev = dev->type_data;
 	IPaddr_t ip;
 
 	if (string_to_ip(val, &ip))
@@ -117,6 +127,9 @@ static int eth_set_ipaddr(struct device_d *dev, struct param_d *param, const cha
 	free(param->value);
 	param->value = strdup(val);
 
+	if (edev == eth_current)
+		net_update_env();
+
 	return 0;
 }
 
@@ -157,7 +170,7 @@ int eth_register(struct eth_device *edev)
 
 	if (edev->get_ethaddr(edev, ethaddr) == 0) {
 		ethaddr_to_string(ethaddr, ethaddr_str);
-		printf("got MAC address from EEPROM: %s\n",ethaddr_str);
+		printf("got MAC address from EEPROM: %s\n",&ethaddr_str);
 		dev_set_param(dev, "ethaddr", ethaddr_str);
 	}
 
@@ -180,9 +193,12 @@ void eth_unregister(struct eth_device *edev)
 	if (edev->param_serverip.value)
 		free(edev->param_serverip.value);
 
-	if (eth_current == edev)
+	if (eth_current == edev) {
+		eth_current->halt(eth_current);
 		eth_current = NULL;
+	}
 
 	list_del(&edev->list);
 }
 
+
diff --git a/net/net.c b/net/net.c
index 4554d49..28943a0 100644
--- a/net/net.c
+++ b/net/net.c
@@ -228,9 +228,6 @@ int NetLoopInit(proto_t protocol)
 	NetArpWaitTxPacket -= (ulong)NetArpWaitTxPacket % PKTALIGN;
 	NetArpWaitTxPacketSize = 0;
 
-	if (eth_open() < 0)
-		return -1;
-
 	string_to_ethaddr(dev_get_param(&eth_get_current()->dev, "ethaddr"),
 			NetOurEther);
 
@@ -243,8 +240,6 @@ int NetLoopInit(proto_t protocol)
 	NetServerIP = dev_get_param_ip(&eth_current->dev, "serverip");
 
 	ret = net_check_prereq(protocol);
-	if (ret)
-		eth_halt();
 
 	return ret;
 }
@@ -281,7 +276,6 @@ int NetLoop(void)
 		 *	Abort if ctrl-c was pressed.
 		 */
 		if (ctrlc()) {
-			eth_halt();
 			puts ("\nAbort\n");
 			return -1;
 		}
@@ -315,11 +309,9 @@ int NetLoop(void)
 				sprintf(buf, "0x%lx", NetBootFileXferSize);
 				setenv("filesize", buf);
 			}
-			eth_halt();
 			return NetBootFileXferSize;
 
 		case NETLOOP_FAIL:
-			eth_halt();
 			return -1;
 		}
 	}
@@ -959,3 +951,16 @@ void ethaddr_to_string(const unsigned char *enetaddr, char *str)
 		 enetaddr[4], enetaddr[5]);
 }
 
+void net_update_env(void)
+{
+	struct eth_device *edev = eth_get_current();
+
+	NetOurIP = dev_get_param_ip(&edev->dev, "ipaddr");
+	NetServerIP = dev_get_param_ip(&edev->dev, "serverip");
+	NetOurGatewayIP = dev_get_param_ip(&edev->dev, "gateway");
+	NetOurSubnetMask = dev_get_param_ip(&edev->dev, "netmask");
+
+	string_to_ethaddr(dev_get_param(&edev->dev, "ethaddr"),
+			NetOurEther);
+}
+
diff --git a/net/ping.c b/net/ping.c
index 1bc481a..7e21fe4 100644
--- a/net/ping.c
+++ b/net/ping.c
@@ -62,7 +62,6 @@ static int PingSend(void)
 static void
 PingTimeout (void)
 {
-	eth_halt();
 	NetState = NETLOOP_FAIL;	/* we did not get the reply */
 }
 
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:55:04 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:55:04 +0200
Subject: [PATCH 08/13] net: consider rarp support as outdated. Remove it
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-9-git-send-email-s.hauer@pengutronix.de>

It is disabled in all defconfigs and probably broken for longer.
Remove it.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/Kconfig  |    4 --
 net/Makefile |    1 -
 net/rarp.c   |  101 ----------------------------------------------------------
 3 files changed, 0 insertions(+), 106 deletions(-)
 delete mode 100644 net/rarp.c

diff --git a/net/Kconfig b/net/Kconfig
index cca2b00..a110bec 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -7,10 +7,6 @@ config NET_DHCP
 	bool
 	prompt "dhcp support"
 
-config NET_RARP
-	bool
-	prompt "rarp protocol support"
-
 config NET_NFS
 	bool
 	prompt "nfs support"
diff --git a/net/Makefile b/net/Makefile
index 0ffc895..bba6f0e 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -2,6 +2,5 @@ obj-$(CONFIG_NET_DHCP)	+= dhcp.o
 obj-$(CONFIG_NET)	+= eth.o
 obj-$(CONFIG_NET)	+= net.o
 obj-$(CONFIG_NET_NFS)	+= nfs.o
-obj-$(CONFIG_NET_RARP)	+= rarp.o
 obj-$(CONFIG_NET_TFTP)	+= tftp.o
 obj-$(CONFIG_NET_PING)	+= ping.o
diff --git a/net/rarp.c b/net/rarp.c
deleted file mode 100644
index 24818f8..0000000
--- a/net/rarp.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * (C) Copyright 2000-2002
- * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
- *
- * 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 <command.h>
-#include <clock.h>
-#include <net.h>
-#include "nfs.h"
-#include "rarp.h"
-#include "tftp.h"
-
-#define TIMEOUT		5		/* Seconds before trying BOOTP again */
-#ifndef	CONFIG_NET_RETRY_COUNT
-# define TIMEOUT_COUNT	5		/* # of timeouts before giving up  */
-#else
-# define TIMEOUT_COUNT  (CONFIG_NET_RETRY_COUNT)
-#endif
-
-
-int		RarpTry;
-
-/*
- *	Handle a RARP received packet.
- */
-static void
-RarpHandler(uchar * dummi0, unsigned dummi1, unsigned dummi2, unsigned dummi3)
-{
-#ifdef	DEBUG
-	puts ("Got good RARP\n");
-#endif
-	NetState = NETLOOP_SUCCESS;
-}
-
-
-/*
- *	Timeout on BOOTP request.
- */
-static void
-RarpTimeout(void)
-{
-	NetSetTimeout (TIMEOUT * SECOND, RarpTimeout);
-	RarpRequest ();
-}
-
-
-void
-RarpRequest (void)
-{
-	int i;
-	uchar *pkt;
-	ARP_t *	rarp;
-
-	NetOurIP = 0;
-	RarpTry = 0;
-
-	printf("RARP broadcast %d\n", ++RarpTry);
-	pkt = NetTxPacket;
-
-	pkt += NetSetEther(pkt, NetBcastAddr, PROT_RARP);
-
-	rarp = (ARP_t *)pkt;
-
-	rarp->ar_hrd = htons (ARP_ETHER);
-	rarp->ar_pro = htons (PROT_IP);
-	rarp->ar_hln = 6;
-	rarp->ar_pln = 4;
-	rarp->ar_op  = htons (RARPOP_REQUEST);
-	memcpy (&rarp->ar_data[0],  NetOurEther, 6);	/* source ET addr */
-	memcpy (&rarp->ar_data[6],  &NetOurIP,   4);	/* source IP addr */
-	memcpy (&rarp->ar_data[10], NetOurEther, 6);	/* dest ET addr = source ET addr ??*/
-	/* dest. IP addr set to broadcast */
-	for (i = 0; i <= 3; i++) {
-		rarp->ar_data[16 + i] = 0xff;
-	}
-
-	NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
-
-	NetSetTimeout(TIMEOUT * SECOND, RarpTimeout);
-	NetSetHandler(RarpHandler);
-}
-
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:55:02 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:55:02 +0200
Subject: [PATCH 06/13] implement ping using new network stack
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-7-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/ping.c |  147 ++++++++++++++++++++++++++++++------------------------------
 1 files changed, 74 insertions(+), 73 deletions(-)

diff --git a/net/ping.c b/net/ping.c
index 7e21fe4..0f9868e 100644
--- a/net/ping.c
+++ b/net/ping.c
@@ -2,102 +2,103 @@
 #include <command.h>
 #include <clock.h>
 #include <net.h>
+#include <errno.h>
+#include <linux/err.h>
 
-static ushort PingSeqNo;
+static uint16_t ping_sequence_number;
 
-static IPaddr_t	NetPingIP;		/* the ip address to ping 		*/
+static IPaddr_t	net_ping_ip;		/* the ip address to ping 		*/
 
-static int PingSend(void)
-{
-	static uchar mac[6];
-	IP_t *ip;
-	ushort *s;
-	uchar *pkt;
-
-	/* XXX always send arp request */
-
-	memcpy(mac, NetEtherNullAddr, 6);
-
-	pr_debug("sending ARP for %08lx\n", NetPingIP);
-
-	NetArpWaitPacketIP = NetPingIP;
-	NetArpWaitPacketMAC = mac;
-
-	pkt = NetArpWaitTxPacket;
-	pkt += NetSetEther(pkt, mac, PROT_IP);
-
-	ip = (IP_t *)pkt;
-
-	/*
-	 *	Construct an IP and ICMP header.  (need to set no fragment bit - XXX)
-	 */
-	ip->ip_hl_v  = 0x45;		/* IP_HDR_SIZE / 4 (not including UDP) */
-	ip->ip_tos   = 0;
-	ip->ip_len   = htons(IP_HDR_SIZE_NO_UDP + 8);
-	ip->ip_id    = htons(NetIPID++);
-	ip->ip_off   = htons(0x4000);	/* No fragmentation */
-	ip->ip_ttl   = 255;
-	ip->ip_p     = 0x01;		/* ICMP */
-	ip->ip_sum   = 0;
-	NetCopyIP((void*)&ip->ip_src, &NetOurIP); /* already in network byte order */
-	NetCopyIP((void*)&ip->ip_dst, &NetPingIP);	   /* - "" - */
-	ip->ip_sum   = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
-
-	s = &ip->udp_src;		/* XXX ICMP starts here */
-	s[0] = htons(0x0800);		/* echo-request, code */
-	s[1] = 0;			/* checksum */
-	s[2] = 0; 			/* identifier */
-	s[3] = htons(PingSeqNo++);	/* sequence number */
-	s[1] = ~NetCksum((uchar *)s, 8/2);
-
-	/* size of the waiting packet */
-	NetArpWaitTxPacketSize = (pkt - NetArpWaitTxPacket) + IP_HDR_SIZE_NO_UDP + 8;
-
-	/* and do the ARP request */
-	NetArpWaitTimerStart = get_time_ns();
-	ArpRequest();
-	return 1;	/* waiting */
-}
+#define PING_STATE_INIT		0
+#define PING_STATE_SUCCESS	1
+
+static int ping_state;
 
-static void
-PingTimeout (void)
+static struct net_connection *ping_con;
+
+static int ping_send(void)
 {
-	NetState = NETLOOP_FAIL;	/* we did not get the reply */
+	unsigned char *payload;
+	struct icmphdr *icmp;
+	uint64_t ts;
+
+	icmp = ping_con->icmp;
+
+	icmp->type = ICMP_ECHO_REQUEST;
+	icmp->code = 0;
+	icmp->checksum = 0;
+	icmp->un.echo.id = 0;
+	icmp->un.echo.sequence = htons(ping_sequence_number);
+
+	ping_sequence_number++;
+
+	payload = (char *)(icmp + 1);
+	ts = get_time_ns();
+	memcpy(payload, &ts, sizeof(ts));
+	payload[8] = 0xab;
+	payload[9] = 0xcd;
+	return net_icmp_send(ping_con, 9);
 }
 
-static void
-PingHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
+void ping_handler(char *pkt, unsigned len)
 {
 	IPaddr_t tmp;
-	IP_t *ip = (IP_t *)pkt;
+	struct iphdr *ip = net_eth_to_iphdr(pkt);
 
-	tmp = NetReadIP((void *)&ip->ip_src);
-	if (tmp != NetPingIP)
+	tmp = net_read_ip((void *)&ip->saddr);
+	if (tmp != net_ping_ip)
 		return;
 
-	NetState = NETLOOP_SUCCESS;
+	ping_state = PING_STATE_SUCCESS;
 }
 
 int do_ping(struct command *cmdtp, int argc, char *argv[])
 {
-	if (argc < 2 || string_to_ip(argv[1], &NetPingIP))
+	int ret;
+	uint64_t ping_start = 0;
+
+	if (argc < 2 || string_to_ip(argv[1], &net_ping_ip))
 		return COMMAND_ERROR_USAGE;
 
-	if (NetLoopInit(PING) < 0)
-		return 1;
+	ping_con = net_icmp_new(net_ping_ip, ping_handler);
+	if (IS_ERR(ping_con)) {
+		ret = PTR_ERR(ping_con);
+		goto out;
+	}
+
+	ping_start = get_time_ns();
+	ret = ping_send();
+	if (ret)
+		goto out_unreg;
+
+	ping_state = PING_STATE_INIT;
+	ping_sequence_number = 0;
+
+	while (ping_state == PING_STATE_INIT) {
+		if (ctrlc()) {
+			ret = -EINTR;
+			break;
+		}
 
-	NetSetTimeout (10 * SECOND, PingTimeout);
-	NetSetHandler (PingHandler);
-	PingSend();
+		net_poll();
 
-	if (NetLoop() < 0) {
-		printf("ping failed; host %s is not alive\n", argv[1]);
-		return 1;
+		if (is_timeout(ping_start, 10 * SECOND)) {
+			ping_start = get_time_ns();
+			ret = ping_send();
+			if (ret)
+				goto out_unreg;
+		}
 	}
 
-	printf("host %s is alive\n", argv[1]);
+	if (!ret)
+		printf("host %s is alive\n", argv[1]);
 
-	return 0;
+out_unreg:
+	net_unregister(ping_con);
+out:
+	if (ret)
+		printf("ping failed: %s\n", strerror(-ret));
+	return ping_state == PING_STATE_SUCCESS ? 0 : 1;
 }
 
 BAREBOX_CMD_START(ping)
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:55:05 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:55:05 +0200
Subject: [PATCH 09/13] network drivers: call net_receive directly instead of
	NetReceive
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-10-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/net/at91_ether.c  |    2 +-
 drivers/net/cs8900.c      |    2 +-
 drivers/net/dm9000.c      |    2 +-
 drivers/net/ep93xx.c      |    4 ++--
 drivers/net/fec_imx.c     |    2 +-
 drivers/net/fec_mpc5200.c |    2 +-
 drivers/net/macb.c        |    2 +-
 drivers/net/netx_eth.c    |    2 +-
 drivers/net/smc91111.c    |    2 +-
 drivers/net/smc911x.c     |    2 +-
 drivers/net/tap.c         |    2 +-
 drivers/net/usb/asix.c    |    2 +-
 drivers/net/usb/usbnet.c  |    2 +-
 13 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/net/at91_ether.c b/drivers/net/at91_ether.c
index a2d1594..3c4f4b0 100644
--- a/drivers/net/at91_ether.c
+++ b/drivers/net/at91_ether.c
@@ -190,7 +190,7 @@ static int at91rm9200_eth_rx (struct eth_device *edev)
 		return 0;
 
 	size = rbfp->size & RBF_SIZE;
-	NetReceive ((volatile uchar *) (rbfp->addr & RBF_ADDR), size);
+	net_receive((volatile uchar *) (rbfp->addr & RBF_ADDR), size);
 
 	rbfp->addr &= ~RBF_OWNER;
 	if (rbfp->addr & RBF_WRAP)
diff --git a/drivers/net/cs8900.c b/drivers/net/cs8900.c
index 64366ac..8120877 100644
--- a/drivers/net/cs8900.c
+++ b/drivers/net/cs8900.c
@@ -309,7 +309,7 @@ static int cs8900_recv(struct eth_device *dev)
 	if (len & 1) {
 		*addr++ = readw(priv->regs + CS8900_RTDATA0);
 	}
-	NetReceive(NetRxPackets[0], len);
+	net_receive(NetRxPackets[0], len);
 
 	return len;
 }
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index 77c771b..2062c66 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -416,7 +416,7 @@ static int dm9000_eth_rx (struct eth_device *edev)
 
 		/* Pass to upper layer */
 		debug("passing packet to upper layer\n");
-		NetReceive(NetRxPackets[0], RxLen);
+		net_receive(NetRxPackets[0], RxLen);
 		return RxLen;
 	}
 	return 0;
diff --git a/drivers/net/ep93xx.c b/drivers/net/ep93xx.c
index e91a92e..c6c4671 100644
--- a/drivers/net/ep93xx.c
+++ b/drivers/net/ep93xx.c
@@ -335,9 +335,9 @@ static int ep93xx_eth_rcv_packet(struct eth_device *edev)
 			 * protocol stack. We track the total number of
 			 * bytes in the frame (nbytes_frame) which will be
 			 * used when we pass the data off to the protocol
-			 * layer via NetReceive().
+			 * layer via net_receive().
 			 */
-			NetReceive((uchar *)priv->rx_dq.current->word1,
+			net_receive((uchar *)priv->rx_dq.current->word1,
 				RX_STATUS_FRAME_LEN(priv->rx_sq.current));
 			pr_debug("reporting %d bytes...\n",
 				RX_STATUS_FRAME_LEN(priv->rx_sq.current));
diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index 5e8e5ca..40a7543 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -515,7 +515,7 @@ static int fec_recv(struct eth_device *dev)
 			 */
 			frame = phys_to_virt(readl(&rbd->data_pointer));
 			frame_length = readw(&rbd->data_length) - 4;
-			NetReceive(frame->data, frame_length);
+			net_receive(frame->data, frame_length);
 			len = frame_length;
 		} else {
 			if (bd_status & FEC_RBD_ERR) {
diff --git a/drivers/net/fec_mpc5200.c b/drivers/net/fec_mpc5200.c
index d803ddf..ce9a21d 100644
--- a/drivers/net/fec_mpc5200.c
+++ b/drivers/net/fec_mpc5200.c
@@ -645,7 +645,7 @@ static int mpc5xxx_fec_recv(struct eth_device *dev)
 			 */
 			memcpy(buff, frame->head, 14);
 			memcpy(buff + 14, frame->data, frame_length);
-			NetReceive(buff, frame_length);
+			net_receive(buff, frame_length);
 			len = frame_length;
 		}
 		/*
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 1bb833a..4feeed0 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -190,7 +190,7 @@ static int macb_recv(struct eth_device *edev)
 				buffer = (void *)NetRxPackets[0];
 			}
 
-			NetReceive(buffer, length);
+			net_receive(buffer, length);
 			if (++rx_tail >= CFG_MACB_RX_RING_SIZE)
 				rx_tail = 0;
 			reclaim_rx_buffers(macb, rx_tail);
diff --git a/drivers/net/netx_eth.c b/drivers/net/netx_eth.c
index 673007a..f2d7b4a 100644
--- a/drivers/net/netx_eth.c
+++ b/drivers/net/netx_eth.c
@@ -111,7 +111,7 @@ static int netx_eth_rx (struct eth_device *edev)
 	/* get data */
 	memcpy((void*)NetRxPackets[0], (void *)(SRAM_BASE(seg) + frameno * 1560), len);
 	/* pass to barebox */
-	NetReceive(NetRxPackets[0], len);
+	net_receive(NetRxPackets[0], len);
 
 	PFIFO_REG(PFIFO_BASE(EMPTY_PTR_FIFO(xcno))) =
 		FIFO_PTR_SEGMENT(seg) |
diff --git a/drivers/net/smc91111.c b/drivers/net/smc91111.c
index 9b41c67..58ebaa9 100644
--- a/drivers/net/smc91111.c
+++ b/drivers/net/smc91111.c
@@ -1156,7 +1156,7 @@ static int smc91c111_eth_rx(struct eth_device *edev)
 
 	if (!is_error) {
 		/* Pass the packet up to the protocol layers. */
-		NetReceive(NetRxPackets[0], packet_length);
+		net_receive(NetRxPackets[0], packet_length);
 		return packet_length;
 	}
 
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 4a5e7b6..ca320d5 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -668,7 +668,7 @@ static int smc911x_eth_rx(struct eth_device *edev)
 				": dropped bad packet. Status: 0x%08x\n",
 				status);
 		else
-			NetReceive(NetRxPackets[0], pktlen);
+			net_receive(NetRxPackets[0], pktlen);
 	}
 
 	return 0;
diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 8673436..522a9f1 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -48,7 +48,7 @@ int tap_eth_rx (struct eth_device *edev)
 	length = linux_read_nonblock(priv->fd, NetRxPackets[0], PKTSIZE);
 
 	if (length > 0)
-		NetReceive(NetRxPackets[0], length);
+		net_receive(NetRxPackets[0], length);
 
 	return 0;
 }
diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c
index e44ce67..fc4146f 100644
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -425,7 +425,7 @@ static int asix_rx_fixup(struct usbnet *dev, void *buf, int len)
 			return 0;
 		}
 
-		NetReceive(buf, size);
+		net_receive(buf, size);
 
 		buf += ((size + 1) & 0xfffe);
 		len -= ((size + 1) & 0xfffe);
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 123cc3b..b0e3090 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -137,7 +137,7 @@ static int usbnet_recv(struct eth_device *edev)
 		if (info->rx_fixup)
 			return info->rx_fixup(dev, rx_buf, alen);
 		else
-			NetReceive(rx_buf, alen);
+			net_receive(rx_buf, alen);
 	}
 
         return 0;
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:55:01 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:55:01 +0200
Subject: [PATCH 05/13] implement tftp using new network stack
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-6-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/tftp.c |  253 ++++++++++++++++++++++++++++--------------------------------
 1 files changed, 119 insertions(+), 134 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index e8a8a3a..b0bc7c5 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -13,9 +13,9 @@
 #include <errno.h>
 #include <libgen.h>
 #include <fcntl.h>
-#include "tftp.h"
+#include <linux/err.h>
 
-#define WELL_KNOWN_PORT	69		/* Well known TFTP port #		*/
+#define TFTP_PORT	69		/* Well known TFTP port #		*/
 #define TIMEOUT		5		/* Seconds to timeout for a lost pkt	*/
 # define TIMEOUT_COUNT	10		/* # of timeouts before giving up  */
 					/* (for checking the image size)	*/
@@ -32,60 +32,45 @@
 #define TFTP_OACK	6
 
 
-static int	TftpServerPort;		/* The UDP port at their end		*/
-static int	TftpOurPort;		/* The UDP port at our end		*/
-static ulong	TftpBlock;		/* packet sequence number		*/
-static ulong	TftpLastBlock;		/* last packet sequence number received */
-static ulong	TftpBlockWrap;		/* count of sequence number wraparounds */
-static ulong	TftpBlockWrapOffset;	/* memory offset due to wrapping	*/
-static int	TftpState;
+static int		tftp_server_port;	/* The UDP port at their end		*/
+static unsigned int	tftp_block;		/* packet sequence number		*/
+static unsigned int	tftp_last_block;	/* last packet sequence number received */
+static unsigned int	tftp_block_wrap;	/* count of sequence number wraparounds */
+static unsigned int	tftp_block_wrap_offset;	/* memory offset due to wrapping	*/
+static int		tftp_state;
+static uint64_t		tftp_timer_start;
+static int		tftp_err;
 
 #define STATE_RRQ	1
 #define STATE_DATA	2
 #define STATE_OACK	3
+#define STATE_DONE	4
 
 #define TFTP_BLOCK_SIZE		512		    /* default TFTP block size	*/
-#define TFTP_SEQUENCE_SIZE	((ulong)(1<<16))    /* sequence number is 16 bit */
+#define TFTP_SEQUENCE_SIZE	((unsigned long)(1<<16))    /* sequence number is 16 bit */
 
 static char *tftp_filename;
-
+static struct net_connection *tftp_con;
 static int net_store_fd;
 
-static int store_block(unsigned block, uchar * src, unsigned len)
-{
-	ulong offset = block * TFTP_BLOCK_SIZE + TftpBlockWrapOffset;
-	ulong newsize = offset + len;
-	int ret;
-
-	ret = write(net_store_fd, src, len);
-	if (ret < 0)
-		return ret;
-
-	if (NetBootFileXferSize < newsize)
-		NetBootFileXferSize = newsize;
-	return 0;
-}
-
-static void TftpSend(void)
+static int tftp_send(void)
 {
-	uchar *pkt;
-	uchar *xp;
+	unsigned char *pkt;
+	unsigned char *xp;
 	int len = 0;
-	ushort *s;
+	uint16_t *s;
+	unsigned char *packet = net_udp_get_payload(tftp_con);
+	int ret;
 
-	/*
-	 *	We will always be sending some sort of packet, so
-	 *	cobble together the packet headers now.
-	 */
-	pkt = NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE;
+	pkt = packet;
 
-	switch (TftpState) {
+	switch (tftp_state) {
 	case STATE_RRQ:
 		xp = pkt;
-		s = (ushort *)pkt;
+		s = (uint16_t *)pkt;
 		*s++ = htons(TFTP_RRQ);
-		pkt = (uchar *)s;
-		pkt += sprintf((uchar *)pkt, "%s%coctet%ctimeout%c%d",
+		pkt = (unsigned char *)s;
+		pkt += sprintf((unsigned char *)pkt, "%s%coctet%ctimeout%c%d",
 				tftp_filename, 0, 0, 0, TIMEOUT) + 1;
 		len = pkt - xp;
 		break;
@@ -93,44 +78,36 @@ static void TftpSend(void)
 	case STATE_DATA:
 	case STATE_OACK:
 		xp = pkt;
-		s = (ushort *)pkt;
+		s = (uint16_t *)pkt;
 		*s++ = htons(TFTP_ACK);
-		*s++ = htons(TftpBlock);
-		pkt = (uchar *)s;
+		*s++ = htons(tftp_block);
+		pkt = (unsigned char *)s;
 		len = pkt - xp;
 		break;
 	}
 
-	NetSendUDPPacket(NetServerEther, NetServerIP, TftpServerPort,
-			TftpOurPort, len);
-}
+	ret = net_udp_send(tftp_con, len);
 
-static void TftpTimeout(void)
-{
-	puts("T ");
-	NetSetTimeout(TIMEOUT * SECOND, TftpTimeout);
-	TftpSend();
+	return ret;
 }
 
-static void TftpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
+static void tftp_handler(char *packet, unsigned len)
 {
-	ushort proto;
-	ushort *s;
-
-	if (dest != TftpOurPort)
-		return;
-
-	if (TftpState != STATE_RRQ && src != TftpServerPort)
-		return;
+	uint16_t proto;
+	uint16_t *s;
+	char *pkt = net_eth_to_udp_payload(packet);
+	struct udphdr *udp = net_eth_to_udphdr(packet);
+	int ret;
 
+	len = net_eth_to_udplen(packet);
 	if (len < 2)
 		return;
 
 	len -= 2;
 	/* warning: don't use increment (++) in ntohs() macros!! */
-	s = (ushort *)pkt;
+	s = (uint16_t *)pkt;
 	proto = *s++;
-	pkt = (uchar *)s;
+	pkt = (unsigned char *)s;
 	switch (ntohs(proto)) {
 	case TFTP_RRQ:
 	case TFTP_WRQ:
@@ -140,16 +117,17 @@ static void TftpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
 		break;
 
 	case TFTP_OACK:
-		debug("Got OACK: %s %s\n", pkt, pkt+strlen(pkt)+1);
-		TftpState = STATE_OACK;
-		TftpServerPort = src;
-		TftpSend(); /* Send ACK */
+		debug("Got OACK: %s %s\n", pkt, pkt + strlen(pkt) + 1);
+		tftp_state = STATE_OACK;
+		tftp_server_port = ntohs(udp->uh_sport);
+		tftp_con->udp->uh_dport = udp->uh_sport;
+		tftp_send(); /* Send ACK */
 		break;
 	case TFTP_DATA:
 		if (len < 2)
 			return;
 		len -= 2;
-		TftpBlock = ntohs(*(ushort *)pkt);
+		tftp_block = ntohs(*(uint16_t *)pkt);
 
 		/*
 		 * RFC1350 specifies that the first data packet will
@@ -157,49 +135,50 @@ static void TftpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
 		 * number of 0 this means that there was a wrap
 		 * around of the (16 bit) counter.
 		 */
-		if (TftpBlock == 0) {
-			TftpBlockWrap++;
-			TftpBlockWrapOffset += TFTP_BLOCK_SIZE * TFTP_SEQUENCE_SIZE;
-			printf ("\n\t %lu MB received\n\t ", TftpBlockWrapOffset>>20);
+		if (tftp_block == 0) {
+			tftp_block_wrap++;
+			tftp_block_wrap_offset += TFTP_BLOCK_SIZE * TFTP_SEQUENCE_SIZE;
 		} else {
-			if (((TftpBlock - 1) % 10) == 0) {
+			if (((tftp_block - 1) % 10) == 0) {
 				putchar('#');
-			} else if ((TftpBlock % (10 * HASHES_PER_LINE)) == 0) {
+			} else if ((tftp_block % (10 * HASHES_PER_LINE)) == 0) {
 				puts("\n\t ");
 			}
 		}
 
-		if (TftpState == STATE_RRQ)
+		if (tftp_state == STATE_RRQ)
 			debug("Server did not acknowledge timeout option!\n");
 
-		if (TftpState == STATE_RRQ || TftpState == STATE_OACK) {
+		if (tftp_state == STATE_RRQ || tftp_state == STATE_OACK) {
 			/* first block received */
-			TftpState = STATE_DATA;
-			TftpServerPort = src;
-			TftpLastBlock = 0;
-			TftpBlockWrap = 0;
-			TftpBlockWrapOffset = 0;
-
-			if (TftpBlock != 1) {	/* Assertion */
-				printf("\nTFTP error: "
-					"First block is not block 1 (%ld)\n"
-					"Starting again\n\n",
-					TftpBlock);
-				NetState = NETLOOP_FAIL;
+			tftp_state = STATE_DATA;
+			tftp_con->udp->uh_dport = udp->uh_sport;
+			tftp_server_port = ntohs(udp->uh_sport);
+			tftp_last_block = 0;
+			tftp_block_wrap = 0;
+			tftp_block_wrap_offset = 0;
+
+			if (tftp_block != 1) {	/* Assertion */
+				printf("error: First block is not block 1 (%ld)\n",
+					tftp_block);
+				tftp_err = -EINVAL;
+				tftp_state = STATE_DONE;
 				break;
 			}
 		}
 
-		if (TftpBlock == TftpLastBlock)
+		if (tftp_block == tftp_last_block)
 			/* Same block again; ignore it. */
 			break;
 
-		TftpLastBlock = TftpBlock;
-		NetSetTimeout(TIMEOUT * SECOND, TftpTimeout);
+		tftp_last_block = tftp_block;
+		tftp_timer_start = get_time_ns();
 
-		if (store_block(TftpBlock - 1, pkt + 2, len) < 0) {
+		ret = write(net_store_fd, pkt + 2, len);
+		if (ret < 0) {
 			perror("write");
-			NetState = NETLOOP_FAIL;
+			tftp_err = -errno;
+			tftp_state = STATE_DONE;
 			return;
 		}
 
@@ -207,58 +186,51 @@ static void TftpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
 		 *	Acknowledge the block just received, which will prompt
 		 *	the server for the next one.
 		 */
-		TftpSend();
-
-		if (len < TFTP_BLOCK_SIZE) {
-			/*
-			 *	We received the whole thing.  Try to
-			 *	run it.
-			 */
-			puts("\ndone\n");
-			NetState = NETLOOP_SUCCESS;
-		}
+		tftp_send();
+
+		if (len < TFTP_BLOCK_SIZE)
+			tftp_state = STATE_DONE;
+
 		break;
 
 	case TFTP_ERROR:
-		printf("\nTFTP error: '%s' (%d)\n",
-					pkt + 2, ntohs(*(ushort *)pkt));
-		NetState = NETLOOP_FAIL;
+		debug("\nTFTP error: '%s' (%d)\n",
+					pkt + 2, ntohs(*(uint16_t *)pkt));
+		switch (ntohs(*(uint16_t *)pkt)) {
+		case 1: tftp_err = -ENOENT; break;
+		case 2: tftp_err = -EACCES; break;
+		default: tftp_err = -EINVAL; break;
+		}
+		tftp_state = STATE_DONE;
 		break;
 	}
 }
 
-void TftpStart(char *filename)
+static int tftp_start(char *filename)
 {
-	char ip1[16], ip2[16];
+	char ip1[16];
 
 	tftp_filename = filename;
 
-	printf("TFTP from server %s; our IP address is %s\n"
-			"\nFilename '%s'.\nLoading: *\b",
-			ip_to_string(NetServerIP, ip1),
-			ip_to_string(NetOurIP, ip2),
+	printf("TFTP from server %s; Filename: '%s'\nLoading: ",
+			ip_to_string(net_get_serverip(), ip1),
 			tftp_filename);
 
-	NetSetTimeout(TIMEOUT * SECOND, TftpTimeout);
-	NetSetHandler(TftpHandler);
+	tftp_timer_start = get_time_ns();
+	tftp_state = STATE_RRQ;
+	tftp_block = 0;
 
-	TftpServerPort = WELL_KNOWN_PORT;
-	TftpState = STATE_RRQ;
-	/* Use a pseudo-random port */
-	TftpOurPort = 1024 + ((unsigned int)get_time_ns() % 3072);
-	TftpBlock = 0;
+	tftp_con = net_udp_new(net_get_serverip(), TFTP_PORT, tftp_handler);
+	if (IS_ERR(tftp_con))
+		return PTR_ERR(tftp_con);
 
-	/* zero out server ether in case the server ip has changed */
-	memset(NetServerEther, 0, 6);
-
-	TftpSend();
+	return tftp_send();
 }
 
 static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 {
-	int   rcode = 0;
-	char  *localfile;
-	char  *remotefile;
+	char *localfile;
+	char *remotefile;
 
 	if (argc < 2)
 		return COMMAND_ERROR_USAGE;
@@ -276,22 +248,35 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 		return 1;
 	}
 
-	if (NetLoopInit(TFTP) < 0)
+	tftp_err = tftp_start(remotefile);
+	if (tftp_err)
 		goto out;
 
-	TftpStart(remotefile);
-
-	if (NetLoop() < 0) {
-		rcode = 1;
-		goto out;
+	while (tftp_state != STATE_DONE) {
+		if (ctrlc()) {
+			tftp_err = -EINTR;
+			break;
+		}
+		net_poll();
+		if (is_timeout(tftp_timer_start, SECOND)) {
+			tftp_timer_start = get_time_ns();
+			printf("T ");
+			tftp_send();
+		}
 	}
 
-	/* NetLoop ok, update environment */
-	netboot_update_env();
+	net_unregister(tftp_con);
 
-out:
 	close(net_store_fd);
-	return rcode;
+out:
+	if (tftp_err) {
+		printf("\ntftp failed: %s\n", strerror(-tftp_err));
+		unlink(localfile);
+	}
+
+	printf("\n");
+
+	return tftp_err == 0 ? 0 : 1;
 }
 
 static const __maybe_unused char cmd_tftp_help[] =
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:55:09 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:55:09 +0200
Subject: [PATCH 13/13] add netconsole support
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-14-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 Documentation/users_manual.dox |    1 +
 Doxyfile                       |    3 +-
 net/Kconfig                    |    7 ++
 net/Makefile                   |    1 +
 net/netconsole.c               |  228 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 239 insertions(+), 1 deletions(-)
 create mode 100644 net/netconsole.c

diff --git a/Documentation/users_manual.dox b/Documentation/users_manual.dox
index 5467bee..cd2b99c 100644
--- a/Documentation/users_manual.dox
+++ b/Documentation/users_manual.dox
@@ -11,5 +11,6 @@ work easier.
 @li @subpage command_reference
 @li @subpage partitions
 @li @subpage x86_bootloader
+ at li @subpage net_netconsole
 
 */
diff --git a/Doxyfile b/Doxyfile
index 94dd6ae..40bcb2f 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -485,7 +485,8 @@ INPUT                  = Documentation \
                          common \
                          board \
                          lib \
-                         scripts/setupmbr
+                         scripts/setupmbr \
+			 net
 
 # This tag can be used to specify the character encoding of the source files that
 # doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default
diff --git a/net/Kconfig b/net/Kconfig
index a110bec..faf2c28 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -18,4 +18,11 @@ config NET_PING
 config NET_TFTP
 	bool
 	prompt "tftp support"
+
+config NET_NETCONSOLE
+	bool
+	prompt "network console support"
+	help
+	  This option adds support for a simple udp based network console.
+
 endif
diff --git a/net/Makefile b/net/Makefile
index bba6f0e..e42a484 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_NET)	+= net.o
 obj-$(CONFIG_NET_NFS)	+= nfs.o
 obj-$(CONFIG_NET_TFTP)	+= tftp.o
 obj-$(CONFIG_NET_PING)	+= ping.o
+obj-$(CONFIG_NET_NETCONSOLE) += netconsole.o
diff --git a/net/netconsole.c b/net/netconsole.c
new file mode 100644
index 0000000..07e6a6c
--- /dev/null
+++ b/net/netconsole.c
@@ -0,0 +1,228 @@
+/*
+ * netconsole.c - network console support
+ *
+ * Copyright (c) 2010 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
+ *
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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 <command.h>
+#include <fs.h>
+#include <linux/stat.h>
+#include <errno.h>
+#include <malloc.h>
+#include <getopt.h>
+#include <stringlist.h>
+#include <net.h>
+#include <kfifo.h>
+#include <init.h>
+#include <linux/err.h>
+
+/**
+ * @file
+ * @brief Network console support
+ */
+
+struct nc_priv {
+	struct console_device cdev;
+	struct kfifo *fifo;
+	int busy;
+	struct net_connection *con;
+
+	uint16_t port;
+	IPaddr_t ip;
+};
+
+static struct nc_priv *g_priv;
+
+static void nc_handler(char *pkt, unsigned len)
+{
+	struct nc_priv *priv = g_priv;
+	unsigned char *packet = net_eth_to_udp_payload(pkt);
+
+	kfifo_put(priv->fifo, packet, net_eth_to_udplen(pkt));
+}
+
+static int nc_init(void)
+{
+	struct nc_priv *priv = g_priv;
+
+	if (priv->con)
+		net_unregister(priv->con);
+
+	priv->con = net_udp_new(priv->ip, priv->port, nc_handler);
+	if (IS_ERR(priv->con)) {
+		int ret = PTR_ERR(priv->con);
+		priv->con = NULL;
+		return ret;
+	}
+
+	net_udp_bind(priv->con, priv->port);
+	priv->cdev.f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
+	return 0;
+}
+
+static int nc_getc(struct console_device *cdev)
+{
+	struct nc_priv *priv = container_of(cdev,
+					struct nc_priv, cdev);
+	unsigned char c;
+
+	while (!kfifo_len(priv->fifo))
+		net_poll();
+
+	kfifo_getc(priv->fifo, &c);
+
+	return c;
+}
+
+static int nc_tstc(struct console_device *cdev)
+{
+	struct nc_priv *priv = container_of(cdev,
+					struct nc_priv, cdev);
+
+	if (priv->busy)
+		return kfifo_len(priv->fifo) ? 1 : 0;
+
+	net_poll();
+
+	return kfifo_len(priv->fifo) ? 1 : 0;
+}
+
+static void nc_putc(struct console_device *cdev, char c)
+{
+	struct nc_priv *priv = container_of(cdev,
+					struct nc_priv, cdev);
+	unsigned char *packet;
+
+	if (!priv->con)
+		return;
+
+	if (priv->busy)
+		return;
+
+	packet = net_udp_get_payload(priv->con);
+	*packet = c;
+
+	priv->busy = 1;
+	net_udp_send(priv->con, 1);
+	priv->busy = 0;
+}
+
+static int nc_setbaudrate(struct console_device *cdev, int baudrate)
+{
+	return 0;
+}
+
+static int nc_port_set(struct device_d *dev, struct param_d *param,
+		const char *val)
+{
+	struct nc_priv *priv = g_priv;
+	char portstr[16];
+	int port;
+
+	if (!val)
+		dev_param_set_generic(dev, param, NULL);
+
+	port = simple_strtoul(val, NULL, 10);
+	if (port > 65535)
+		return -EINVAL;
+
+	priv->port = port;
+	nc_init();
+
+	sprintf(portstr, "%d", port);
+	dev_param_set_generic(dev, param, portstr);
+
+	return 0;
+}
+
+static int nc_remoteip_set(struct device_d *dev, struct param_d *param,
+		const char *val)
+{
+	struct nc_priv *priv = g_priv;
+	IPaddr_t ip;
+	int ret;
+
+	if (!val)
+		dev_param_set_generic(dev, param, NULL);
+
+	if (string_to_ip(val, &ip))
+		return -EINVAL;
+
+	priv->ip = ip;
+	ret = nc_init();
+	if (ret)
+		return ret;
+
+	dev_param_set_generic(dev, param, val);
+
+	return 0;
+}
+
+static int netconsole_init(void)
+{
+	struct nc_priv *priv;
+	struct console_device *cdev;
+
+	priv = xzalloc(sizeof(*priv));
+	cdev = &priv->cdev;
+	cdev->tstc = nc_tstc;
+	cdev->putc = nc_putc;
+	cdev->getc = nc_getc;
+	cdev->setbrg = nc_setbaudrate;
+
+	g_priv = priv;
+
+	priv->fifo = kfifo_alloc(1024);
+
+	console_register(cdev);
+
+	dev_add_param(&cdev->class_dev, "ip", nc_remoteip_set, NULL, 0);
+	dev_add_param(&cdev->class_dev, "port", nc_port_set, NULL, 0);
+	dev_set_param(&cdev->class_dev, "port", "6666");
+
+	printf("registered netconsole as %s%d\n", cdev->class_dev.name, cdev->class_dev.id);
+
+	return 0;
+}
+
+device_initcall(netconsole_init);
+
+/** @page net_netconsole Network console
+
+ at section net_netconsole Using an UDP based network console
+
+If enabled barebox supports a console via udp networking. There is only
+one network console supported registered during init time. It is deactivated
+by default because it opens great security holes, so use with care.
+
+To use the network console you have to configure the remote ip and the local
+and remote ports. Assuming the network console is registered as cs1, it can be
+configured with:
+
+ at code
+cs1.ip=<remotehost>
+cs1.port=<port>
+cs1.active=ioe
+ at endcode
+
+On the remote host call scripts/netconsole with bareboxes ip and port as
+parameters. port is initialized to 6666 by default.
+
+*/
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:55:00 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:55:00 +0200
Subject: [PATCH 04/13] implement dhcp using new network stack
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-5-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/dhcp.c |  484 ++++++++++++++++++++++--------------------------------------
 1 files changed, 173 insertions(+), 311 deletions(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index f27a696..bedfb6e 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -14,64 +14,44 @@
 #include <clock.h>
 #include <net.h>
 #include <libbb.h>
-#include "tftp.h"
-#include "nfs.h"
+#include <errno.h>
+#include <linux/err.h>
 
 #define OPT_SIZE 312	/* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */
 
-typedef struct
-{
-	uchar		bp_op;		/* Operation				*/
-# define OP_BOOTREQUEST	1
-# define OP_BOOTREPLY	2
-	uchar		bp_htype;	/* Hardware type			*/
-# define HWT_ETHER	1
-	uchar		bp_hlen;	/* Hardware address length		*/
-# define HWL_ETHER	6
-	uchar		bp_hops;	/* Hop count (gateway thing)		*/
-	ulong		bp_id;		/* Transaction ID			*/
-	ushort		bp_secs;	/* Seconds since boot			*/
-	ushort		bp_spare1;	/* Alignment				*/
+struct bootp {
+	uint8_t		bp_op;		/* Operation				*/
+#define OP_BOOTREQUEST	1
+#define OP_BOOTREPLY	2
+	uint8_t		bp_htype;	/* Hardware type			*/
+#define HWT_ETHER	1
+	uint8_t		bp_hlen;	/* Hardware address length		*/
+#define HWL_ETHER	6
+	uint8_t		bp_hops;	/* Hop count (gateway thing)		*/
+	uint32_t	bp_id;		/* Transaction ID			*/
+	uint16_t	bp_secs;	/* Seconds since boot			*/
+	uint16_t	bp_spare1;	/* Alignment				*/
 	IPaddr_t	bp_ciaddr;	/* Client IP address			*/
 	IPaddr_t	bp_yiaddr;	/* Your (client) IP address		*/
 	IPaddr_t	bp_siaddr;	/* Server IP address			*/
 	IPaddr_t	bp_giaddr;	/* Gateway IP address			*/
-	uchar		bp_chaddr[16];	/* Client hardware address		*/
+	uint8_t		bp_chaddr[16];	/* Client hardware address		*/
 	char		bp_sname[64];	/* Server host name			*/
 	char		bp_file[128];	/* Boot file name			*/
-	char		bp_vend[OPT_SIZE];	/* Vendor information			*/
-}	Bootp_t;
-
-#define BOOTP_HDR_SIZE	sizeof (Bootp_t)
-#define BOOTP_SIZE	(ETHER_HDR_SIZE + IP_HDR_SIZE + BOOTP_HDR_SIZE)
-
-/**********************************************************************/
-/*
- *	Global functions and variables.
- */
-
-/* bootp.c */
-extern ulong	BootpID;		/* ID of cur BOOTP request		*/
-extern char	BootFile[128];		/* Boot file name			*/
-#ifdef CONFIG_BOOTP_RANDOM_DELAY
-ulong		seed1, seed2;		/* seed for random BOOTP delay		*/
-#endif
-
-
-/* Send a BOOTP request */
-extern void	BootpRequest (void);
-
-/****************** DHCP Support *********************/
+	char		bp_vend[0];	/* Vendor information			*/
+};
 
 /* DHCP States */
-typedef enum { INIT,
-	       INIT_REBOOT,
-	       REBOOTING,
-	       SELECTING,
-	       REQUESTING,
-	       REBINDING,
-	       BOUND,
-	       RENEWING } dhcp_state_t;
+typedef enum {
+	INIT,
+	INIT_REBOOT,
+	REBOOTING,
+	SELECTING,
+	REQUESTING,
+	REBINDING,
+	BOUND,
+	RENEWING,
+} dhcp_state_t;
 
 #define DHCP_DISCOVER 1
 #define DHCP_OFFER    2
@@ -81,44 +61,27 @@ typedef enum { INIT,
 #define DHCP_NAK      6
 #define DHCP_RELEASE  7
 
-#define SELECT_TIMEOUT 3	/* Seconds to wait for offers */
-
-/**********************************************************************/
-
 #define BOOTP_VENDOR_MAGIC	0x63825363	/* RFC1048 Magic Cookie		*/
 
-#define TIMEOUT		5		/* Seconds before trying BOOTP again	*/
-#ifndef CONFIG_NET_RETRY_COUNT
-# define TIMEOUT_COUNT	5		/* # of timeouts before giving up  */
-#else
-# define TIMEOUT_COUNT	(CONFIG_NET_RETRY_COUNT)
-#endif
-
 #define PORT_BOOTPS	67		/* BOOTP server UDP port		*/
 #define PORT_BOOTPC	68		/* BOOTP client UDP port		*/
 
-#ifndef CONFIG_DHCP_MIN_EXT_LEN		/* minimal length of extension list	*/
-#define CONFIG_DHCP_MIN_EXT_LEN 64
-#endif
-
-ulong		BootpID;
-#ifdef CONFIG_BOOTP_RANDOM_DELAY
-ulong		seed1, seed2;
-#endif
+#define DHCP_MIN_EXT_LEN 64	/* minimal length of extension list	*/
 
-dhcp_state_t dhcp_state = INIT;
-unsigned long dhcp_leasetime = 0;
-IPaddr_t NetDHCPServerIP = 0;
-static void DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len);
+static uint32_t Bootp_id;
+static dhcp_state_t dhcp_state;
+static uint32_t dhcp_leasetime;
+static IPaddr_t net_dhcp_server_ip;
+static uint64_t dhcp_start;
 
-static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
+static int bootp_check_packet(unsigned char *pkt, unsigned src, unsigned len)
 {
-	Bootp_t *bp = (Bootp_t *) pkt;
+	struct bootp *bp = (struct bootp *) pkt;
 	int retval = 0;
 
-	if (dest != PORT_BOOTPC || src != PORT_BOOTPS)
+	if (src != PORT_BOOTPS)
 		retval = -1;
-	else if (len < sizeof (Bootp_t) - OPT_SIZE)
+	else if (len < sizeof(struct bootp))
 		retval = -2;
 	else if (bp->bp_op != OP_BOOTREQUEST &&
 	    bp->bp_op != OP_BOOTREPLY &&
@@ -131,11 +94,11 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
 		retval = -4;
 	else if (bp->bp_hlen != HWL_ETHER)
 		retval = -5;
-	else if (NetReadLong((ulong*)&bp->bp_id) != BootpID) {
+	else if (net_read_uint32(&bp->bp_id) != Bootp_id) {
 		retval = -6;
 	}
 
-	debug ("Filtering pkt = %d\n", retval);
+	debug("Filtering pkt = %d\n", retval);
 
 	return retval;
 }
@@ -143,64 +106,31 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
 /*
  * Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet
  */
-static void BootpCopyNetParams(Bootp_t *bp)
+static void bootp_copy_net_params(struct bootp *bp)
 {
 	IPaddr_t tmp_ip;
 
-	NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
-	NetCopyIP(&tmp_ip, &bp->bp_siaddr);
-	if (tmp_ip != 0)
-		NetCopyIP(&NetServerIP, &bp->bp_siaddr);
-	memcpy (NetServerEther, ((Ethernet_t *)NetRxPkt)->et_src, 6);
-	if (strlen(bp->bp_file) > 0)
-		safe_strncpy (BootFile, bp->bp_file, sizeof(BootFile));
+	tmp_ip = net_read_ip(&bp->bp_yiaddr);
+	net_set_ip(tmp_ip);
 
-	debug ("Bootfile: %s\n", BootFile);
-
-	/* Propagate to environment:
-	 * don't delete exising entry when BOOTP / DHCP reply does
-	 * not contain a new value
-	 */
-	if (*BootFile) {
-		setenv ("bootfile", BootFile);
-	}
-}
+	tmp_ip = net_read_ip(&bp->bp_siaddr);
+	if (tmp_ip != 0)
+		net_set_serverip(tmp_ip);
 
-static int truncate_sz (const char *name, int maxlen, int curlen)
-{
-	if (curlen >= maxlen) {
-		printf("*** WARNING: %s is too long (%d - max: %d) - truncated\n",
-			name, curlen, maxlen);
-		curlen = maxlen - 1;
-	}
-	return (curlen);
-}
+	if (strlen(bp->bp_file) > 0)
+		setenv("bootfile", bp->bp_file);
 
-/*
- *	Timeout on BOOTP/DHCP request.
- */
-static void
-BootpTimeout(void)
-{
-	NetSetTimeout (TIMEOUT * SECOND, BootpTimeout);
-	BootpRequest ();
+	debug("bootfile: %s\n", bp->bp_file);
 }
 
 /*
- *	Initialize BOOTP extension fields in the request.
+ * Initialize BOOTP extension fields in the request.
  */
-static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP)
+static int dhcp_extended (u8 *e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP)
 {
 	u8 *start = e;
 	u8 *cnt;
 
-#ifdef CONFIG_BOOTP_VENDOREX
-	u8 *x;
-#endif
-#ifdef CONFIG_BOOTP_SEND_HOSTNAME
-	char *hostname;
-#endif
-
 	*e++ = 99;		/* RFC1048 Magic Cookie */
 	*e++ = 130;
 	*e++ = 83;
@@ -236,175 +166,113 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
 		*e++ = tmp >> 8;
 		*e++ = tmp & 0xff;
 	}
-#ifdef CONFIG_BOOTP_SEND_HOSTNAME
-	if ((hostname = getenv ("hostname"))) {
-		int hostnamelen = strlen (hostname);
-
-		*e++ = 12;	/* Hostname */
-		*e++ = hostnamelen;
-		memcpy (e, hostname, hostnamelen);
-		e += hostnamelen;
-	}
-#endif
 
 	*e++ = 55;		/* Parameter Request List */
 	 cnt = e++;		/* Pointer to count of requested items */
 	*cnt = 0;
-#ifdef CONFIG_BOOTP_SUBNETMASK
 	*e++  = 1;		/* Subnet Mask */
 	*cnt += 1;
-#endif
-#ifdef CONFIG_BOOTP_TIMEOFFSET
-	*e++  = 2;
-	*cnt += 1;
-#endif
-#ifdef CONFIG_BOOTP_GATEWAY
 	*e++  = 3;		/* Router Option */
 	*cnt += 1;
-#endif
-#ifdef CONFIG_BOOTP_DNS
 	*e++  = 6;		/* DNS Server(s) */
 	*cnt += 1;
-#endif
-#ifdef CONFIG_BOOTP_HOSTNAME
 	*e++  = 12;		/* Hostname */
 	*cnt += 1;
-#endif
-#ifdef CONFIG_BOOTP_BOOTFILESIZE
-	*e++  = 13;		/* Boot File Size */
-	*cnt += 1;
-#endif
-#ifdef CONFIG_BOOTP_BOOTPATH
 	*e++  = 17;		/* Boot path */
 	*cnt += 1;
-#endif
-#ifdef CONFIG_BOOTP_NISDOMAIN
-	*e++  = 40;		/* NIS Domain name request */
-	*cnt += 1;
-#endif
-#ifdef CONFIG_BOOTP_NTPSERVER
-	*e++  = 42;
-	*cnt += 1;
-#endif
 	*e++  = 255;		/* End of the list */
 
 	/* Pad to minimal length */
-#ifdef	CONFIG_DHCP_MIN_EXT_LEN
-	while ((e - start) <= CONFIG_DHCP_MIN_EXT_LEN)
+	while ((e - start) <= DHCP_MIN_EXT_LEN)
 		*e++ = 0;
-#endif
 
 	return e - start;
 }
 
-void
-BootpRequest (void)
+static struct net_connection *dhcp_con;
+
+static int bootp_request(void)
 {
-	uchar *pkt, *iphdr;
-	Bootp_t *bp;
-	int ext_len, pktlen, iplen;
+	struct bootp *bp;
+	int ext_len;
+	int ret;
+	unsigned char *payload = net_udp_get_payload(dhcp_con);
+	const char *bfile;
 
 	dhcp_state = INIT;
 
-	printf("BOOTP broadcast\n");
-	pkt = NetTxPacket;
-	memset ((void*)pkt, 0, PKTSIZE);
+	debug("BOOTP broadcast\n");
 
-	pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
-
-	/*
-	 * Next line results in incorrect packet size being transmitted, resulting
-	 * in errors in some DHCP servers, reporting missing bytes.  Size must be
-	 * set in packet header after extension length has been determined.
-	 * C. Hallinan, DS4.COM, Inc.
-	 */
-	/* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, sizeof (Bootp_t)); */
-	iphdr = pkt;	/* We need this later for NetSetIP() */
-	pkt += IP_HDR_SIZE;
-
-	bp = (Bootp_t *)pkt;
+	bp = (struct bootp *)payload;
 	bp->bp_op = OP_BOOTREQUEST;
 	bp->bp_htype = HWT_ETHER;
 	bp->bp_hlen = HWL_ETHER;
 	bp->bp_hops = 0;
 	bp->bp_secs = htons(get_time_ns() >> 30);
-	NetWriteIP(&bp->bp_ciaddr, 0);
-	NetWriteIP(&bp->bp_yiaddr, 0);
-	NetWriteIP(&bp->bp_siaddr, 0);
-	NetWriteIP(&bp->bp_giaddr, 0);
-	memcpy (bp->bp_chaddr, NetOurEther, 6);
-	safe_strncpy (bp->bp_file, BootFile, sizeof(bp->bp_file));
+	net_write_ip(&bp->bp_ciaddr, 0);
+	net_write_ip(&bp->bp_yiaddr, 0);
+	net_write_ip(&bp->bp_siaddr, 0);
+	net_write_ip(&bp->bp_giaddr, 0);
+	memcpy(bp->bp_chaddr, dhcp_con->et->et_src, 6);
 
-	/* Request additional information from the BOOTP/DHCP server */
-	ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
+	bfile = getenv("bootfile");
+	if (bfile)
+		safe_strncpy (bp->bp_file, bfile, sizeof(bp->bp_file));
 
-	/*
-	 *	Bootp ID is the lower 4 bytes of our ethernet address
-	 *	plus the current time in HZ.
-	 */
-	BootpID = ((ulong)NetOurEther[2] << 24)
-		| ((ulong)NetOurEther[3] << 16)
-		| ((ulong)NetOurEther[4] << 8)
-		| (ulong)NetOurEther[5];
-	BootpID += (uint32_t)get_time_ns();
-	BootpID	 = htonl(BootpID);
-	NetCopyLong(&bp->bp_id, &BootpID);
+	/* Request additional information from the BOOTP/DHCP server */
+	ext_len = dhcp_extended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
 
-	/*
-	 * Calculate proper packet lengths taking into account the
-	 * variable size of the options field
-	 */
-	pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + ext_len;
-	iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
-	NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
-	NetSetTimeout(SELECT_TIMEOUT * SECOND, BootpTimeout);
+	Bootp_id = (uint32_t)get_time_ns();
+	net_copy_uint32(&bp->bp_id, &Bootp_id);
 
 	dhcp_state = SELECTING;
-	NetSetHandler(DhcpHandler);
-	NetSendPacket(NetTxPacket, pktlen);
+
+	ret = net_udp_send(dhcp_con, sizeof(*bp) + ext_len);
+
+	return ret;
 }
 
-static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
+static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
 {
-	uchar *end = popt + BOOTP_HDR_SIZE;
-	int oplen, size;
+	unsigned char *end = popt + sizeof(*bp) + OPT_SIZE;
+	int oplen;
+	IPaddr_t ip;
+	char str[256];
 
 	while (popt < end && *popt != 0xff) {
 		oplen = *(popt + 1);
 		switch (*popt) {
 		case 1:
-			NetCopyIP (&NetOurSubnetMask, (popt + 2));
+			ip = net_read_ip(popt + 2);
+			net_set_netmask(ip);
 			break;
 		case 3:
-			NetCopyIP (&NetOurGatewayIP, (popt + 2));
+			ip = net_read_ip(popt + 2);
+			net_set_gateway(ip);
 			break;
 		case 6:
-			NetCopyIP (&NetOurDNSIP, (popt + 2));
-#ifdef CONFIG_BOOTP_DNS2
-			if (*(popt + 1) > 4) {
-				NetCopyIP (&NetOurDNS2IP, (popt + 2 + 4));
-			}
-#endif
+			ip = net_read_ip(popt + 2);
+			net_set_dnsip(ip);
 			break;
 		case 12:
-			size = truncate_sz ("Host Name", sizeof (NetOurHostName), oplen);
-			memcpy (&NetOurHostName, popt + 2, size);
-			NetOurHostName[size] = 0;
+			memcpy(str, popt + 2, oplen);
+			str[oplen] = 0;
+			setenv("hostname", str);
 			break;
 		case 15:	/* Ignore Domain Name Option */
 			break;
 		case 17:
-			size = truncate_sz ("Root Path", sizeof (NetOurRootPath), oplen);
-			memcpy (&NetOurRootPath, popt + 2, size);
-			NetOurRootPath[size] = 0;
+			memcpy(str, popt + 2, oplen);
+			str[oplen] = 0;
+			setenv("rootpath", str);
 			break;
 		case 51:
-			NetCopyLong (&dhcp_leasetime, (ulong *) (popt + 2));
+			net_copy_uint32 (&dhcp_leasetime, (uint32_t *)(popt + 2));
 			break;
 		case 53:	/* Ignore Message Type Option */
 			break;
 		case 54:
-			NetCopyIP (&NetDHCPServerIP, (popt + 2));
+			net_copy_ip(&net_dhcp_server_ip, (popt + 2));
 			break;
 		case 58:	/* Ignore Renewal Time Option */
 			break;
@@ -419,10 +287,9 @@ static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
 			 * pass the bootp packet pointer into here as the
 			 * second arg
 			 */
-			size = truncate_sz ("Opt Boot File",
-					    sizeof(bp->bp_file),
-					    oplen);
-			if (bp->bp_file[0] == '\0' && size > 0) {
+			memcpy(str, popt + 2, oplen);
+			str[oplen] = 0;
+			if (bp->bp_file[0] == '\0') {
 				/*
 				 * only use vendor boot file if we didn't
 				 * receive a boot file in the main non-vendor
@@ -434,8 +301,7 @@ static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
 				 */
 				printf("*** WARNING: using vendor "
 					"optional boot file\n");
-				memcpy(bp->bp_file, popt + 2, size);
-				bp->bp_file[size] = '\0';
+					setenv("bootfile", str);
 			}
 			break;
 		default:
@@ -443,16 +309,16 @@ static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
 			if (dhcp_vendorex_proc (popt))
 				break;
 #endif
-			printf ("*** Unhandled DHCP Option in OFFER/ACK: %d\n", *popt);
+			debug("*** Unhandled DHCP Option in OFFER/ACK: %d\n", *popt);
 			break;
 		}
 		popt += oplen + 2;	/* Process next option */
 	}
 }
 
-static int DhcpMessageType(unsigned char *popt)
+static int dhcp_message_type(unsigned char *popt)
 {
-	if (NetReadLong((ulong*)popt) != htonl(BOOTP_VENDOR_MAGIC))
+	if (net_read_uint32((uint32_t *)popt) != htonl(BOOTP_VENDOR_MAGIC))
 		return -1;
 
 	popt += 4;
@@ -464,76 +330,65 @@ static int DhcpMessageType(unsigned char *popt)
 	return -1;
 }
 
-static void DhcpSendRequestPkt(Bootp_t *bp_offer)
+static void dhcp_send_request_packet(struct bootp *bp_offer)
 {
-	uchar *pkt, *iphdr;
-	Bootp_t *bp;
-	int pktlen, iplen, extlen;
+	struct bootp *bp;
+	int extlen;
 	IPaddr_t OfferedIP;
+	unsigned char *payload = net_udp_get_payload(dhcp_con);
 
-	debug ("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
-	pkt = NetTxPacket;
-	memset ((void*)pkt, 0, PKTSIZE);
-
-	pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
+	debug("%s: Sending DHCPREQUEST\n", __func__);
 
-	iphdr = pkt;		/* We'll need this later to set proper pkt size */
-	pkt += IP_HDR_SIZE;
-
-	bp = (Bootp_t *)pkt;
+	bp = (struct bootp *)payload;
 	bp->bp_op = OP_BOOTREQUEST;
 	bp->bp_htype = HWT_ETHER;
 	bp->bp_hlen = HWL_ETHER;
 	bp->bp_hops = 0;
 	/* FIXME what is this? */
 //	bp->bp_secs = htons(get_timer(0) / CFG_HZ);
-	NetCopyIP(&bp->bp_ciaddr, &bp_offer->bp_ciaddr); /* both in network byte order */
-	NetCopyIP(&bp->bp_yiaddr, &bp_offer->bp_yiaddr);
-	NetCopyIP(&bp->bp_siaddr, &bp_offer->bp_siaddr);
+	net_copy_ip(&bp->bp_ciaddr, &bp_offer->bp_ciaddr); /* both in network byte order */
+	net_copy_ip(&bp->bp_yiaddr, &bp_offer->bp_yiaddr);
+	net_copy_ip(&bp->bp_siaddr, &bp_offer->bp_siaddr);
 	/*
 	 * RFC3046 requires Relay Agents to discard packets with
 	 * nonzero and offered giaddr
 	 */
-	NetWriteIP(&bp->bp_giaddr, 0);
+	net_write_ip(&bp->bp_giaddr, 0);
 
-	memcpy (bp->bp_chaddr, NetOurEther, 6);
+	memcpy(bp->bp_chaddr, dhcp_con->et->et_src, 6);
 
 	/*
 	 * ID is the id of the OFFER packet
 	 */
 
-	NetCopyLong(&bp->bp_id, &bp_offer->bp_id);
+	net_copy_uint32(&bp->bp_id, &bp_offer->bp_id);
 
 	/*
 	 * Copy options from OFFER packet if present
 	 */
-	NetCopyIP(&OfferedIP, &bp->bp_yiaddr);
-	extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP);
-
-	pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + extlen;
-	iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
-	NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
+	net_copy_ip(&OfferedIP, &bp->bp_yiaddr);
+	extlen = dhcp_extended((u8 *)bp->bp_vend, DHCP_REQUEST, net_dhcp_server_ip, OfferedIP);
 
-	debug ("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
-	NetSendPacket(NetTxPacket, pktlen);
+	debug("Transmitting DHCPREQUEST packet\n");
+	net_udp_send(dhcp_con, sizeof(*bp) + extlen);
 }
 
 /*
  *	Handle DHCP received packets.
  */
-static void
-DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
+static void dhcp_handler(char *packet, unsigned int len)
 {
-	Bootp_t *bp = (Bootp_t *)pkt;
+	char *pkt = net_eth_to_udp_payload(packet);
+	struct udphdr *udp = net_eth_to_udphdr(packet);
+	struct bootp *bp = (struct bootp *)pkt;
 
-	debug ("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
-		src, dest, len, dhcp_state);
+	len = net_eth_to_udplen(packet);
 
-	if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
-		return;
+	debug("DHCPHandler: got packet: (len=%d) state: %d\n",
+		len, dhcp_state);
 
-	debug ("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
-		src, dest, len, dhcp_state);
+	if (bootp_check_packet(pkt, ntohs(udp->uh_sport), len)) /* Filter out pkts we don't want */
+		return;
 
 	switch (dhcp_state) {
 	case SELECTING:
@@ -543,69 +398,76 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
 		 * If filename is in format we recognize, assume it is a valid
 		 * OFFER from a server we want.
 		 */
-		debug ("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file);
-#ifdef CFG_BOOTFILE_PREFIX
-		if (strncmp(bp->bp_file,
-			    CFG_BOOTFILE_PREFIX,
-			    strlen(CFG_BOOTFILE_PREFIX)) == 0 ) {
-#endif	/* CFG_BOOTFILE_PREFIX */
-
-			debug ("TRANSITIONING TO REQUESTING STATE\n");
-			dhcp_state = REQUESTING;
+		debug ("%s: state SELECTING, bp_file: \"%s\"\n", __func__, bp->bp_file);
+		dhcp_state = REQUESTING;
 
-			if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
-				DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
+		if (net_read_uint32((uint32_t *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
+			dhcp_options_process((u8 *)&bp->bp_vend[4], bp);
 
-			BootpCopyNetParams(bp); /* Store net params from reply */
+		bootp_copy_net_params(bp); /* Store net params from reply */
 
-			NetSetTimeout(TIMEOUT * SECOND, BootpTimeout);
-			DhcpSendRequestPkt(bp);
-#ifdef CFG_BOOTFILE_PREFIX
-		}
-#endif	/* CFG_BOOTFILE_PREFIX */
+		dhcp_start = get_time_ns();
+		dhcp_send_request_packet(bp);
 
-		return;
 		break;
 	case REQUESTING:
-		debug ("DHCP State: REQUESTING\n");
+		debug ("%s: State REQUESTING\n", __func__);
 
-		if ( DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK ) {
-			if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
-				DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
-			BootpCopyNetParams(bp); /* Store net params from reply */
+		if (dhcp_message_type((u8 *)bp->bp_vend) == DHCP_ACK ) {
+			if (net_read_uint32((uint32_t *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
+				dhcp_options_process((u8 *)&bp->bp_vend[4], bp);
+			bootp_copy_net_params(bp); /* Store net params from reply */
 			dhcp_state = BOUND;
 			puts ("DHCP client bound to address ");
-			print_IPaddr(NetOurIP);
+			print_IPaddr(net_get_ip());
 			putchar('\n');
-
-			NetState = NETLOOP_SUCCESS;
 			return;
 		}
 		break;
 	default:
-		puts ("DHCP: INVALID STATE\n");
+		debug("%s: INVALID STATE\n", __func__);
 		break;
 	}
-
 }
 
 static int do_dhcp(struct command *cmdtp, int argc, char *argv[])
 {
-	int size;
+	int ret;
+
+	dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler);
+	if (IS_ERR(dhcp_con)) {
+		ret = PTR_ERR(dhcp_con);
+		goto out;
+	}
+
+	ret = net_udp_bind(dhcp_con, PORT_BOOTPC);
+	if (ret)
+		goto out;
 
-	if (NetLoopInit(DHCP) < 0)
-		return 1;
+	ret = bootp_request(); /* Basically same as BOOTP */
+	if (ret)
+		goto out;
 
-	NetOurIP = 0;
-	BootpRequest();		/* Basically same as BOOTP */
+	while (dhcp_state != BOUND) {
+		if (ctrlc())
+			break;
+		net_poll();
+		if (is_timeout(dhcp_start, 3 * SECOND)) {
+			dhcp_start = get_time_ns();
+			printf("T ");
+			ret = bootp_request();
+			if (ret)
+				goto out;
+		}
+	}
 
-	if ((size = NetLoop()) < 0)
-		return 1;
+out:
+	net_unregister(dhcp_con);
 
-	/* NetLoop ok, update environment */
-	netboot_update_env();
+	if (ret)
+		printf("dhcp failed: %s\n", strerror(-ret));
 
-	return 0;
+	return ret ? 1 : 0;
 }
 
 BAREBOX_CMD_START(dhcp)
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:55:07 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:55:07 +0200
Subject: [PATCH 11/13] rework device parameters
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-12-git-send-email-s.hauer@pengutronix.de>

Change device parameters so that the memory management is in generic
code. This also removes the need of storing statically initialized
parameters as they are stored in a struct list_head for each device.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/console.c    |   40 ++++++-----
 drivers/nand/nand.c |    7 +-
 drivers/video/fb.c  |   21 +++---
 drivers/video/imx.c |   17 +++--
 include/console.h   |    6 --
 include/driver.h    |    2 +-
 include/fb.h        |    2 -
 include/net.h       |    6 --
 include/param.h     |   15 ++++-
 lib/driver.c        |   12 +--
 lib/parameter.c     |  195 ++++++++++++++++++++++++++++++++-------------------
 net/eth.c           |   48 ++++---------
 12 files changed, 201 insertions(+), 170 deletions(-)

diff --git a/common/console.c b/common/console.c
index d3d31f7..7199d9a 100644
--- a/common/console.c
+++ b/common/console.c
@@ -57,26 +57,32 @@ static int console_std_set(struct device_d *dev, struct param_d *param,
 		const char *val)
 {
 	struct console_device *cdev = dev->type_data;
+	char active[4];
 	unsigned int flag = 0, i = 0;
 
+	if (!val)
+		dev_param_set_generic(dev, param, NULL);
+
 	if (strchr(val, 'i') && cdev->f_caps & CONSOLE_STDIN) {
-		cdev->active[i++] = 'i';
+		active[i++] = 'i';
 		flag |= CONSOLE_STDIN;
 	}
 
 	if (strchr(val, 'o') && cdev->f_caps & CONSOLE_STDOUT) {
-		cdev->active[i++] = 'o';
+		active[i++] = 'o';
 		flag |= CONSOLE_STDOUT;
 	}
 
 	if (strchr(val, 'e') && cdev->f_caps & CONSOLE_STDERR) {
-		cdev->active[i++] = 'e';
+		active[i++] = 'e';
 		flag |= CONSOLE_STDERR;
 	}
 
-	cdev->active[i] = 0;
+	active[i] = 0;
 	cdev->f_active = flag;
 
+	dev_param_set_generic(dev, param, active);
+
 	return 0;
 }
 
@@ -85,8 +91,12 @@ static int console_baudrate_set(struct device_d *dev, struct param_d *param,
 {
 	struct console_device *cdev = dev->type_data;
 	int baudrate;
+	char baudstr[16];
 	unsigned char c;
 
+	if (!val)
+		dev_param_set_generic(dev, param, NULL);
+
 	baudrate = simple_strtoul(val, NULL, 10);
 
 	if (cdev->f_active) {
@@ -101,7 +111,8 @@ static int console_baudrate_set(struct device_d *dev, struct param_d *param,
 	} else
 		cdev->setbrg(cdev, baudrate);
 
-	sprintf(cdev->baudrate_string, "%d", baudrate);
+	sprintf(baudstr, "%d", baudrate);
+	dev_param_set_generic(dev, param, baudstr);
 
 	return 0;
 }
@@ -129,29 +140,20 @@ int console_register(struct console_device *newcdev)
 	register_device(dev);
 
 	if (newcdev->setbrg) {
-		newcdev->baudrate_param.set = console_baudrate_set;
-		newcdev->baudrate_param.name = "baudrate";
-		sprintf(newcdev->baudrate_string, "%d",
-			CONFIG_BAUDRATE);
-		console_baudrate_set(dev, &newcdev->baudrate_param,
-			newcdev->baudrate_string);
-		newcdev->baudrate_param.value = newcdev->baudrate_string;
-		dev_add_param(dev, &newcdev->baudrate_param);
+		dev_add_param(dev, "baudrate", console_baudrate_set, NULL, 0);
+		dev_set_param(dev, "baudrate", "115200");
 	}
 
-	newcdev->active_param.set = console_std_set;
-	newcdev->active_param.name  = "active";
-	newcdev->active_param.value = newcdev->active;
-	dev_add_param(dev, &newcdev->active_param);
+	dev_add_param(dev, "active", console_std_set, NULL, 0);
 
 	initialized = CONSOLE_INIT_FULL;
 #ifdef CONFIG_CONSOLE_ACTIVATE_ALL
-	console_std_set(dev, &newcdev->active_param, "ioe");
+	dev_set_param(dev, "active", "ioe");
 #endif
 #ifdef CONFIG_CONSOLE_ACTIVATE_FIRST
 	if (list_empty(&console_list)) {
 		first = 1;
-		console_std_set(dev, &newcdev->active_param, "ioe");
+		dev_set_param(dev, "active", "ioe");
 	}
 #endif
 
diff --git a/drivers/nand/nand.c b/drivers/nand/nand.c
index bcf52bd..4927231 100644
--- a/drivers/nand/nand.c
+++ b/drivers/nand/nand.c
@@ -210,6 +210,7 @@ static struct file_operations nand_ops_oob = {
 int add_mtd_device(struct mtd_info *mtd)
 {
 	struct nand_chip *chip = mtd->priv;
+	char str[16];
 
 	strcpy(mtd->class_dev.name, "nand");
 	register_device(&mtd->class_dev);
@@ -220,10 +221,8 @@ int add_mtd_device(struct mtd_info *mtd)
 	mtd->cdev.priv = mtd;
 	mtd->cdev.dev = &mtd->class_dev;
 
-	mtd->param_size.flags = PARAM_FLAG_RO;
-	mtd->param_size.name = "size";
-	mtd->param_size.value = asprintf("%u", mtd->size);
-	dev_add_param(&mtd->class_dev, &mtd->param_size);
+	sprintf(str, "%u", mtd->size);
+	dev_add_param_fixed(&mtd->class_dev, "size", str);
 
 	devfs_create(&mtd->cdev);
 
diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index 00a0f6a..841c3af 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -32,15 +32,22 @@ static int fb_enable_set(struct device_d *dev, struct param_d *param,
 {
 	struct fb_info *info = dev->priv;
 	int enable;
+	char *new;
+
+	if (!val)
+		return dev_param_set_generic(dev, param, NULL);
 
 	enable = simple_strtoul(val, NULL, 0);
 
-	if (enable)
+	if (enable) {
 		info->fbops->fb_enable(info);
-	else
+		new = "1";
+	} else {
 		info->fbops->fb_disable(info);
+		new = "0";
+	}
 
-	sprintf(info->enable_string, "%d", !!enable);
+	dev_param_set_generic(dev, param, new);
 
 	return 0;
 }
@@ -71,13 +78,9 @@ int register_framebuffer(struct fb_info *info)
 
 	sprintf(dev->name, "fb");
 
-	info->param_enable.set = fb_enable_set;
-	info->param_enable.name = "enable";
-	sprintf(info->enable_string, "%d", 0);
-	info->param_enable.value = info->enable_string;
-	dev_add_param(dev, &info->param_enable);
-
 	register_device(&info->dev);
+	dev_add_param(dev, "enable", fb_enable_set, NULL, 0);
+	dev_set_param(dev, "enable", "0");
 
 	devfs_create(&info->cdev);
 
diff --git a/drivers/video/imx.c b/drivers/video/imx.c
index 67cae34..d9ba643 100644
--- a/drivers/video/imx.c
+++ b/drivers/video/imx.c
@@ -154,8 +154,6 @@ struct imxfb_info {
 
 
 	struct fb_info		overlay;
-	struct param_d		param_alpha;
-	char			alpha_string[4];
 };
 
 #define IMX_NAME	"IMX"
@@ -427,8 +425,12 @@ static int imxfb_alpha_set(struct device_d *dev, struct param_d *param,
 	struct fb_info *overlay = dev->priv;
 	struct imxfb_info *fbi = overlay->priv;
 	int alpha;
+	char alphastr[16];
 	unsigned int tmp;
 
+	if (!val)
+		return dev_param_set_generic(dev, param, NULL);
+
 	alpha = simple_strtoul(val, NULL, 0);
 	alpha &= 0xff;
 
@@ -437,7 +439,9 @@ static int imxfb_alpha_set(struct device_d *dev, struct param_d *param,
 	tmp |= LGWCR_GWAV(alpha);
 	writel(tmp , fbi->regs + LCDC_LGWCR);
 
-	sprintf(fbi->alpha_string, "%d", alpha);
+	sprintf(alphastr, "%d", alpha);
+
+	dev_param_set_generic(dev, param, alphastr);
 
 	return 0;
 }
@@ -502,11 +506,8 @@ static int imxfb_register_overlay(struct imxfb_info *fbi, void *fb)
 		return ret;
 	}
 
-	fbi->param_alpha.set = imxfb_alpha_set;
-	fbi->param_alpha.name = "alpha";
-	sprintf(fbi->alpha_string, "%d", 0);
-	fbi->param_alpha.value = fbi->alpha_string;
-	dev_add_param(&overlay->dev, &fbi->param_alpha);
+	dev_add_param(&overlay->dev, "alpha", imxfb_alpha_set, NULL, 0);
+	dev_set_param(&overlay->dev, "alpha", "0");
 
 	return 0;
 }
diff --git a/include/console.h b/include/console.h
index 3568c56..3bcc5db 100644
--- a/include/console.h
+++ b/include/console.h
@@ -46,12 +46,6 @@ struct console_device {
 
 	unsigned char f_caps;
 	unsigned char f_active;
-
-	struct param_d baudrate_param;
-	char baudrate_string[8];
-
-	struct param_d active_param;
-	char active[4];
 };
 
 int console_register(struct console_device *cdev);
diff --git a/include/driver.h b/include/driver.h
index 1dde38e..6950c02 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -98,7 +98,7 @@ struct device_d {
 
 	/*! The parameters for this device. This is used to carry information
 	 * of board specific data from the board code to the device driver. */
-	struct param_d *param;
+	struct list_head parameters;
 
 	struct list_head cdevs;
 };
diff --git a/include/fb.h b/include/fb.h
index f213c42..218500b 100644
--- a/include/fb.h
+++ b/include/fb.h
@@ -80,8 +80,6 @@ struct fb_info {
 
 	struct fb_ops *fbops;
 	struct device_d dev;		/* This is this fb device */
-	struct param_d param_enable;
-	char enable_string[1];
 
 	void *screen_base;
 
diff --git a/include/net.h b/include/net.h
index 627b18b..f0321a7 100644
--- a/include/net.h
+++ b/include/net.h
@@ -41,12 +41,6 @@ struct eth_device {
 	struct eth_device *next;
 	void *priv;
 
-	struct param_d param_ip;
-	struct param_d param_netmask;
-	struct param_d param_gateway;
-	struct param_d param_serverip;
-	struct param_d param_ethaddr;
-
 	struct device_d dev;
 
 	struct list_head list;
diff --git a/include/param.h b/include/param.h
index fe4468e..207ad50 100644
--- a/include/param.h
+++ b/include/param.h
@@ -2,6 +2,7 @@
 #define PARAM_H
 
 #include <linux/types.h>
+#include <linux/list.h>
 
 #define PARAM_FLAG_RO	(1 << 0)
 
@@ -15,12 +16,24 @@ struct param_d {
 	char *name;
 	struct param_d *next;
 	char *value;
+	struct list_head list;
 };
 
 const char *dev_get_param(struct device_d *dev, const char *name);
 int dev_set_param(struct device_d *dev, const char *name, const char *val);
 struct param_d *get_param_by_name(struct device_d *dev, const char *name);
-int dev_add_param(struct device_d *dev, struct param_d *par);
+
+int dev_add_param(struct device_d *dev, char *name,
+		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
+		char *(*get)(struct device_d *, struct param_d *p),
+		unsigned long flags);
+
+int dev_add_param_fixed(struct device_d *dev, char *name, char *value);
+
+void dev_remove_parameters(struct device_d *dev);
+
+int dev_param_set_generic(struct device_d *dev, struct param_d *p,
+		const char *val);
 
 /* Convenience functions to handle a parameter as an ip address */
 int dev_set_param_ip(struct device_d *dev, char *name, IPaddr_t ip);
diff --git a/lib/driver.c b/lib/driver.c
index f433c3e..b600745 100644
--- a/lib/driver.c
+++ b/lib/driver.c
@@ -107,6 +107,7 @@ int register_device(struct device_d *new_device)
 	list_add_tail(&new_device->list, &device_list);
 	INIT_LIST_HEAD(&new_device->children);
 	INIT_LIST_HEAD(&new_device->cdevs);
+	INIT_LIST_HEAD(&new_device->parameters);
 
 	for_each_driver(drv) {
 		if (!match(drv, new_device))
@@ -313,16 +314,11 @@ static int do_devinfo(struct command *cmdtp, int argc, char *argv[])
 		if (dev->driver)
 			dev->driver->info(dev);
 
-		param = dev->param;
+		printf("%s\n", list_empty(&dev->parameters) ?
+				"no parameters available" : "Parameters:");
 
-		printf("%s\n", param ?
-				"Parameters:" : "no parameters available");
-
-		while (param) {
+		list_for_each_entry(param, &dev->parameters, list)
 			printf("%16s = %s\n", param->name, param->value);
-			param = param->next;
-		}
-
 	}
 
 	return 0;
diff --git a/lib/parameter.c b/lib/parameter.c
index 6b32207..a3d178f 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -33,17 +33,22 @@
 
 struct param_d *get_param_by_name(struct device_d *dev, const char *name)
 {
-	struct param_d *param = dev->param;
+	struct param_d *p;
 
-	while (param) {
-		if (!strcmp(param->name, name))
-			return param;
-		param = param->next;
+	list_for_each_entry(p, &dev->parameters, list) {
+		if (!strcmp(p->name, name))
+			return p;
 	}
 
 	return NULL;
 }
 
+/**
+ * dev_get_param - get the value of a parameter
+ * @param dev	The device
+ * @param name	The name of the parameter
+ * @return	The value
+ */
 const char *dev_get_param(struct device_d *dev, const char *name)
 {
 	struct param_d *param = get_param_by_name(dev, name);
@@ -53,10 +58,7 @@ const char *dev_get_param(struct device_d *dev, const char *name)
 		return NULL;
 	}
 
-	if (param->get)
-		return param->get(dev, param);
-
-	return param->value;
+	return param->get(dev, param);
 }
 
 #ifdef CONFIG_NET
@@ -80,6 +82,12 @@ int dev_set_param_ip(struct device_d *dev, char *name, IPaddr_t ip)
 }
 #endif
 
+/**
+ * dev_set_param - set a parameter of a device to a new value
+ * @param dev	The device
+ * @param name	The name of the parameter
+ * @param value	The new value of the parameter
+ */
 int dev_set_param(struct device_d *dev, const char *name, const char *val)
 {
 	struct param_d *param;
@@ -101,35 +109,122 @@ int dev_set_param(struct device_d *dev, const char *name, const char *val)
 		return -EACCES;
 	}
 
-	if (param->set) {
-		errno = param->set(dev, param, val);
-		return errno;
-	}
-
-	if (param->value)
-		free(param->value);
+	errno = param->set(dev, param, val);
+	return errno;
+}
 
-	param->value = strdup(val);
+/**
+ * dev_param_set_generic - generic setter function for a parameter
+ * @param dev	The device
+ * @param p	the parameter
+ * @param val	The new value
+ *
+ * If used the value of a parameter is a string allocated with
+ * malloc and freed with free. If val is NULL the value is freed. This is
+ * used during deregistration of the parameter to free the alloctated
+ * memory.
+ */
+int dev_param_set_generic(struct device_d *dev, struct param_d *p,
+		const char *val)
+{
+	if (p->value)
+		free(p->value);
+	if (!val)
+		return 0;
+	p->value = strdup(val);
 	return 0;
 }
 
-int dev_add_param(struct device_d *dev, struct param_d *newparam)
+static char *param_get_generic(struct device_d *dev, struct param_d *p)
+{
+	return p->value;
+}
+
+static struct param_d *__dev_add_param(struct device_d *dev, char *name,
+		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
+		char *(*get)(struct device_d *dev, struct param_d *p),
+		unsigned long flags)
 {
-	struct param_d *param = dev->param;
+	struct param_d *param;
 
-	newparam->next = NULL;
+	param = xzalloc(sizeof(*param));
 
-	if (param) {
-		while (param->next)
-			param = param->next;
-			param->next = newparam;
-	} else {
-		dev->param = newparam;
-	}
+	if (set)
+		param->set = set;
+	else
+		param->set = dev_param_set_generic;
+	if (get)
+		param->get = get;
+	else
+		param->get = param_get_generic;
+
+	param->name = strdup(name);
+	param->flags = flags;
+	list_add_tail(&param->list, &dev->parameters);
+
+	return param;
+}
+
+/**
+ * dev_add_param - add a parameter to a device
+ * @param dev	The device
+ * @param name	The name of the parameter
+ * @param set	setter function for the parameter
+ * @param get	getter function for the parameter
+ * @param flags
+ *
+ * This function adds a new parameter to a device. The get/set functions can
+ * be zero in which case the generic functions are used. The generic functions
+ * expect the parameter value to be a string which can be freed with free(). Do
+ * not use static arrays when using the generic functions.
+ */
+int dev_add_param(struct device_d *dev, char *name,
+		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
+		char *(*get)(struct device_d *dev, struct param_d *param),
+		unsigned long flags)
+{
+	struct param_d *param;
+
+	param = __dev_add_param(dev, name, set, get, flags);
+
+	return param ? 0 : -EINVAL;
+}
+
+/**
+ * dev_add_param_fixed - add a readonly parameter to a device
+ * @param dev	The device
+ * @param name	The name of the parameter
+ * @param value	The value of the parameter
+ */
+int dev_add_param_fixed(struct device_d *dev, char *name, char *value)
+{
+	struct param_d *param;
+
+	param = __dev_add_param(dev, name, NULL, NULL, PARAM_FLAG_RO);
+	if (!param)
+		return -EINVAL;
+
+	param->value = strdup(value);
 
 	return 0;
 }
 
+/**
+ * dev_remove_parameters - remove all parameters from a device and free their
+ * memory
+ * @param dev	The device
+ */
+void dev_remove_parameters(struct device_d *dev)
+{
+	struct param_d *p, *n;
+
+	list_for_each_entry_safe(p, n, &dev->parameters, list) {
+		p->set(dev, p, NULL);
+		list_del(&p->list);
+		free(p);
+	}
+}
+
 /** @page dev_params Device parameters
 
 @section params_devices Devices can have several parameters.
@@ -145,50 +240,6 @@ IP address of the first ethernet device is a matter of typing
 devices currently present. If called with a device id as parameter it shows the
 parameters available for a device.
 
- at section params_programming Device parameters programming API
-
- at code
-struct param_d {
-	char* (*get)(struct device_d *, struct param_d *param);
-	int (*set)(struct device_d *, struct param_d *param, const char *val);
-	ulong flags;
-	char *name;
-	struct param_d *next;
-	char *value;
-};
- at endcode
-
- at code
-int dev_add_param(struct device_d *dev, struct param_d *newparam);
- at endcode
-
-This function adds a new parameter to a device. At least the name field in
-the new parameter struct has to be initialized. The 'get' and 'set' fields
-can be set to NULL in which case the framework handles them. It is also
-allowed to implement only one of the get/set functions. Care must be taken
-with the initial value of the parameter. If the framework handles the set
-function it will try to free the value of the parameter. If this is a
-static array bad things will happen. A parameter can have the flag
-PARAM_FLAG_RO which means that the parameter is readonly. It is perfectly ok
-then to point the value to a static array.
-
- at code
-const char *dev_get_param(struct device_d *dev, const char *name);
- at endcode
-
-This function returns a pointer to the value of the parameter specified
-with dev and name.
-If the framework handles the get/set functions the parameter value strings
-are alloceted with malloc and freed with free when another value is set for
-this parameter. Drivers implementing set/get themselves are allowed to
-return values in static arrays. This means that the pointers returned from
-dev_get_param() are only valid until the next call to dev_get_param. If this
-is not long enough strdup() or similar must be used.
-
- at code
-int dev_set_param(struct device_d *dev, const char *name, const char *val);
- at endcode
-
-Set the value of a parameter.
+See the individual functions for parameter programming.
 
 */
diff --git a/net/eth.c b/net/eth.c
index fc16233..4d58191 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -102,11 +102,13 @@ static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const ch
 	struct eth_device *edev = dev->type_data;
 	char ethaddr[sizeof("xx:xx:xx:xx:xx:xx")];
 
+	if (!val)
+		return dev_param_set_generic(dev, param, NULL);
+
 	if (string_to_ethaddr(val, ethaddr) < 0)
 		return -EINVAL;
 
-	free(param->value);
-	param->value = strdup(val);
+	dev_param_set_generic(dev, param, val);
 
 	edev->set_ethaddr(edev, ethaddr);
 
@@ -121,11 +123,13 @@ static int eth_set_ipaddr(struct device_d *dev, struct param_d *param, const cha
 	struct eth_device *edev = dev->type_data;
 	IPaddr_t ip;
 
+	if (!val)
+		return dev_param_set_generic(dev, param, NULL);
+
 	if (string_to_ip(val, &ip))
 		return -EINVAL;
 
-	free(param->value);
-	param->value = strdup(val);
+	dev_param_set_generic(dev, param, val);
 
 	if (edev == eth_current)
 		net_update_env();
@@ -148,21 +152,11 @@ int eth_register(struct eth_device *edev)
 	register_device(&edev->dev);
 
 	dev->type_data = edev;
-	edev->param_ip.name = "ipaddr";
-	edev->param_ip.set = &eth_set_ipaddr;
-	edev->param_ethaddr.name = "ethaddr";
-	edev->param_ethaddr.set = &eth_set_ethaddr;
-	edev->param_gateway.name = "gateway";
-	edev->param_gateway.set = &eth_set_ipaddr;
-	edev->param_netmask.name = "netmask";
-	edev->param_netmask.set = &eth_set_ipaddr;
-	edev->param_serverip.name = "serverip";
-	edev->param_serverip.set = &eth_set_ipaddr;
-	dev_add_param(dev, &edev->param_ip);
-	dev_add_param(dev, &edev->param_ethaddr);
-	dev_add_param(dev, &edev->param_gateway);
-	dev_add_param(dev, &edev->param_netmask);
-	dev_add_param(dev, &edev->param_serverip);
+	dev_add_param(dev, "ipaddr", eth_set_ipaddr, NULL, 0);
+	dev_add_param(dev, "ethaddr", eth_set_ethaddr, NULL, 0);
+	dev_add_param(dev, "gateway", eth_set_ipaddr, NULL, 0);
+	dev_add_param(dev, "netmask", eth_set_ipaddr, NULL, 0);
+	dev_add_param(dev, "serverip", eth_set_ipaddr, NULL, 0);
 
 	edev->init(edev);
 
@@ -182,21 +176,7 @@ int eth_register(struct eth_device *edev)
 
 void eth_unregister(struct eth_device *edev)
 {
-	if (edev->param_ip.value)
-		free(edev->param_ip.value);
-	if (edev->param_ethaddr.value)
-		free(edev->param_ethaddr.value);
-	if (edev->param_gateway.value)
-		free(edev->param_gateway.value);
-	if (edev->param_netmask.value)
-		free(edev->param_netmask.value);
-	if (edev->param_serverip.value)
-		free(edev->param_serverip.value);
-
-	if (eth_current == edev) {
-		eth_current->halt(eth_current);
-		eth_current = NULL;
-	}
+	dev_remove_parameters(&edev->dev);
 
 	list_del(&edev->list);
 }
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:54:58 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:54:58 +0200
Subject: [PATCH 02/13] net: Implement a new network stack
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-3-git-send-email-s.hauer@pengutronix.de>

The old network stack has some bad limitations:

- network commands are required to call NetLoop() which only returns when
  the network layer wants to. Instead we now use a net_poll() function which
  returns after handling one packet (or immediately if no packet is
  available).
- There can be only one packet handler which makes it impossible to handle
  multiple connections
- CamelCaseMakesItHardToRead

The new network stack is implemented as a parallel universe. Currently all
commands still use the old stack. They are converted in subsequent patches.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/net.h |  339 +++++++++++++++++++++++++++++++++++++-
 net/net.c     |  521 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 854 insertions(+), 6 deletions(-)

diff --git a/include/net.h b/include/net.h
index de78293..f588a3d 100644
--- a/include/net.h
+++ b/include/net.h
@@ -15,6 +15,7 @@
 #include <driver.h>
 #include <linux/types.h>
 #include <param.h>
+#include <malloc.h>
 #include <asm/byteorder.h>	/* for nton* / ntoh* stuff */
 
 
@@ -186,8 +187,6 @@ typedef struct
 	uchar		ar_data[0];
 } ARP_t;
 
-#define ARP_HDR_SIZE	(8+20)		/* Size assuming ethernet	*/
-
 /*
  * ICMP stuff (just enough to handle (host) redirect messages)
  */
@@ -199,7 +198,7 @@ typedef struct
 #define ICMP_REDIR_NET		0	/* Redirect Net			*/
 #define ICMP_REDIR_HOST		1	/* Redirect Host		*/
 
-typedef struct icmphdr {
+typedef struct {
 	uchar		type;
 	uchar		code;
 	ushort		checksum;
@@ -415,4 +414,338 @@ void eth_set_current(struct eth_device *eth);
 struct eth_device *eth_get_current(void);
 struct eth_device *eth_get_byname(char *name);
 
+/*
+ *	Ethernet header
+ */
+struct ethernet {
+	uint8_t		et_dest[6];	/* Destination node		*/
+	uint8_t		et_src[6];	/* Source node			*/
+	uint16_t	et_protlen;	/* Protocol or length		*/
+} __attribute__ ((packed));
+
+#define ETHER_HDR_SIZE	14		/* Ethernet header size		*/
+
+#define PROT_IP		0x0800		/* IP protocol			*/
+#define PROT_ARP	0x0806		/* IP ARP protocol		*/
+#define PROT_RARP	0x8035		/* IP ARP protocol		*/
+#define PROT_VLAN	0x8100		/* IEEE 802.1q protocol		*/
+
+#define IPPROTO_ICMP	 1	/* Internet Control Message Protocol	*/
+#define IPPROTO_UDP	17	/* User Datagram Protocol		*/
+
+/*
+ *	Internet Protocol (IP) header.
+ */
+struct iphdr {
+	uint8_t		hl_v;
+	uint8_t		tos;
+	uint16_t	tot_len;
+	uint16_t	id;
+	uint16_t	frag_off;
+	uint8_t		ttl;
+	uint8_t		protocol;
+	uint16_t	check;
+	uint32_t	saddr;
+	uint32_t	daddr;
+	/* The options start here. */
+} __attribute__ ((packed));
+
+struct udphdr {
+	uint16_t	uh_sport;	/* source port */
+	uint16_t	uh_dport;	/* destination port */
+	uint16_t	uh_ulen;	/* udp length */
+	uint16_t	uh_sum;		/* udp checksum */
+} __attribute__ ((packed));
+
+/*
+ *	Address Resolution Protocol (ARP) header.
+ */
+struct arprequest
+{
+	uint16_t	ar_hrd;		/* Format of hardware address	*/
+#define ARP_ETHER	1		/* Ethernet  hardware address	*/
+	uint16_t	ar_pro;		/* Format of protocol address	*/
+	uint8_t		ar_hln;		/* Length of hardware address	*/
+	uint8_t		ar_pln;		/* Length of protocol address	*/
+	uint16_t	ar_op;		/* Operation			*/
+#define ARPOP_REQUEST	1		/* Request  to resolve  address	*/
+#define ARPOP_REPLY	2		/* Response to previous request	*/
+
+#define RARPOP_REQUEST	3		/* Request  to resolve  address	*/
+#define RARPOP_REPLY	4		/* Response to previous request */
+
+	/*
+	 * The remaining fields are variable in size, according to
+	 * the sizes above, and are defined as appropriate for
+	 * specific hardware/protocol combinations.
+	 */
+	uint8_t		ar_data[0];
+} __attribute__ ((packed));
+
+#define ARP_HDR_SIZE	(8 + 20)	/* Size assuming ethernet	*/
+
+/*
+ * ICMP stuff (just enough to handle (host) redirect messages)
+ */
+#define ICMP_ECHO_REPLY		0	/* Echo reply 			*/
+#define ICMP_REDIRECT		5	/* Redirect (change route)	*/
+#define ICMP_ECHO_REQUEST	8	/* Echo request			*/
+
+/* Codes for REDIRECT. */
+#define ICMP_REDIR_NET		0	/* Redirect Net			*/
+#define ICMP_REDIR_HOST		1	/* Redirect Host		*/
+
+struct icmphdr {
+	uint8_t		type;
+	uint8_t		code;
+	uint16_t	checksum;
+	union {
+		struct {
+			uint16_t	id;
+			uint16_t	sequence;
+		} echo;
+		uint32_t	gateway;
+		struct {
+			uint16_t	__unused;
+			uint16_t	mtu;
+		} frag;
+	} un;
+} __attribute__ ((packed));
+
+
+/*
+ * Maximum packet size; used to allocate packet storage.
+ * TFTP packets can be 524 bytes + IP header + ethernet header.
+ * Lets be conservative, and go for 38 * 16.  (Must also be
+ * a multiple of 32 bytes).
+ */
+#define PKTSIZE			1518
+
+/**********************************************************************/
+/*
+ *	Globals.
+ *
+ * Note:
+ *
+ * All variables of type IPaddr_t are stored in NETWORK byte order
+ * (big endian).
+ */
+
+extern unsigned char *NetRxPackets[PKTBUFSRX];/* Receive packets		*/
+
+void net_set_ip(IPaddr_t ip);
+void net_set_serverip(IPaddr_t ip);
+void net_set_netmask(IPaddr_t ip);
+void net_set_gateway(IPaddr_t ip);
+void net_set_dnsip(IPaddr_t ip);
+IPaddr_t net_get_ip(void);
+IPaddr_t net_get_serverip(void);
+
+/* Do the work */
+void net_poll(void);
+
+static inline struct iphdr *net_eth_to_iphdr(char *pkt)
+{
+	return (struct iphdr *)(pkt + ETHER_HDR_SIZE);
+}
+
+static inline struct udphdr *net_eth_to_udphdr(char *pkt)
+{
+	return (struct udphdr *)(net_eth_to_iphdr(pkt) + 1);
+}
+
+static inline struct icmphdr *net_eth_to_icmphdr(char *pkt)
+{
+	return (struct icmphdr *)(net_eth_to_iphdr(pkt) + 1);
+}
+
+static inline char *net_eth_to_icmp_payload(char *pkt)
+{
+	return (char *)(net_eth_to_icmphdr(pkt) + 1);
+}
+
+static inline char *net_eth_to_udp_payload(char *pkt)
+{
+	return (char *)(net_eth_to_udphdr(pkt) + 1);
+}
+
+static inline int net_eth_to_udplen(char *pkt)
+{
+	struct udphdr *udp = net_eth_to_udphdr(pkt);
+	return ntohs(udp->uh_ulen) - 8;
+}
+
+int net_checksum_ok(unsigned char *, int);	/* Return true if cksum OK	*/
+uint16_t net_checksum(unsigned char *, int);	/* Calculate the checksum	*/
+
+void NetReceive(unsigned char *, int);
+
+/* Print an IP address on the console */
+void print_IPaddr (IPaddr_t);
+
+/*
+ * The following functions are a bit ugly, but necessary to deal with
+ * alignment restrictions on ARM.
+ *
+ * We're using inline functions, which had the smallest memory
+ * footprint in our tests.
+ */
+/* return IP *in network byteorder* */
+static inline IPaddr_t net_read_ip(void *from)
+{
+	IPaddr_t ip;
+	memcpy((void*)&ip, from, sizeof(ip));
+	return ip;
+}
+
+/* return uint32 *in network byteorder* */
+static inline uint32_t net_read_uint32(uint32_t *from)
+{
+	ulong l;
+	memcpy((void*)&l, (void*)from, sizeof(l));
+	return l;
+}
+
+/* write IP *in network byteorder* */
+static inline void net_write_ip(void *to, IPaddr_t ip)
+{
+	memcpy(to, (void*)&ip, sizeof(ip));
+}
+
+/* copy IP */
+static inline void net_copy_ip(void *to, void *from)
+{
+	memcpy(to, from, sizeof(IPaddr_t));
+}
+
+/* copy ulong */
+static inline void net_copy_uint32(uint32_t *to, uint32_t *from)
+{
+	memcpy(to, from, sizeof(uint32_t));
+}
+
+/* Convert an IP address to a string */
+char *ip_to_string (IPaddr_t x, char *s);
+
+/* Convert a string to ip address */
+int string_to_ip(const char *s, IPaddr_t *ip);
+
+int string_to_ethaddr(const char *str, char *enetaddr);
+void ethaddr_to_string(const unsigned char *enetaddr, char *str);
+
+/**
+ * is_zero_ether_addr - Determine if give Ethernet address is all zeros.
+ * @addr: Pointer to a six-byte array containing the Ethernet address
+ *
+ * Return true if the address is all zeroes.
+ */
+static inline int is_zero_ether_addr(const u8 *addr)
+{
+	return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
+}
+
+/**
+ * is_multicast_ether_addr - Determine if the Ethernet address is a multicast.
+ * @addr: Pointer to a six-byte array containing the Ethernet address
+ *
+ * Return true if the address is a multicast address.
+ * By definition the broadcast address is also a multicast address.
+ */
+static inline int is_multicast_ether_addr(const u8 *addr)
+{
+	return (0x01 & addr[0]);
+}
+
+/**
+ * is_local_ether_addr - Determine if the Ethernet address is locally-assigned one (IEEE 802).
+ * @addr: Pointer to a six-byte array containing the Ethernet address
+ *
+ * Return true if the address is a local address.
+ */
+static inline int is_local_ether_addr(const u8 *addr)
+{
+	return (0x02 & addr[0]);
+}
+
+/**
+ * is_broadcast_ether_addr - Determine if the Ethernet address is broadcast
+ * @addr: Pointer to a six-byte array containing the Ethernet address
+ *
+ * Return true if the address is the broadcast address.
+ */
+static inline int is_broadcast_ether_addr(const u8 *addr)
+{
+	return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;
+}
+
+/**
+ * is_valid_ether_addr - Determine if the given Ethernet address is valid
+ * @addr: Pointer to a six-byte array containing the Ethernet address
+ *
+ * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not
+ * a multicast address, and is not FF:FF:FF:FF:FF:FF.
+ *
+ * Return true if the address is valid.
+ */
+static inline int is_valid_ether_addr(const u8 *addr)
+{
+	/* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to
+	 * explicitly check for it here. */
+	return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
+}
+
+typedef void rx_handler_f(char *packet, unsigned int len);
+
+void eth_set_current(struct eth_device *eth);
+struct eth_device *eth_get_current(void);
+struct eth_device *eth_get_byname(char *name);
+void net_update_env(void);
+
+/**
+ * net_receive - Pass a received packet from an ethernet driver to the protocol stack
+ * @pkt: Pointer to the packet
+ * @len: length of the packet
+ *
+ * Return 0 if the packet is successfully handled. Can be ignored
+ */
+int net_receive(unsigned char *pkt, int len);
+
+struct net_connection {
+	struct ethernet *et;
+	struct iphdr *ip;
+	struct udphdr *udp;
+	struct icmphdr *icmp;
+	unsigned char *packet;
+	struct list_head list;
+	rx_handler_f *handler;
+	int proto;
+};
+
+static inline char *net_alloc_packet(void)
+{
+	return memalign(32, PKTSIZE);
+}
+
+struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
+		rx_handler_f *handler);
+
+struct net_connection *net_icmp_new(IPaddr_t dest, rx_handler_f *handler);
+
+void net_unregister(struct net_connection *con);
+
+static inline int net_udp_bind(struct net_connection *con, int sport)
+{
+	con->udp->uh_sport = ntohs(sport);
+	return 0;
+}
+
+static inline unsigned char *net_udp_get_payload(struct net_connection *con)
+{
+	return con->packet + sizeof(struct ethernet) + sizeof(struct iphdr) +
+		sizeof(struct udphdr);
+}
+
+int net_udp_send(struct net_connection *con, int len);
+int net_icmp_send(struct net_connection *con, int len);
+
 #endif /* __NET_H__ */
diff --git a/net/net.c b/net/net.c
index 28943a0..6569b6f 100644
--- a/net/net.c
+++ b/net/net.c
@@ -77,7 +77,9 @@
 #include <net.h>
 #include <driver.h>
 #include <errno.h>
+#include <init.h>
 #include <linux/ctype.h>
+#include <linux/err.h>
 #include "tftp.h"
 #include "rarp.h"
 #include "nfs.h"
@@ -407,6 +409,9 @@ NetReceive(uchar * inpkt, int len)
 
 	pr_debug("packet received\n");
 
+	if (!net_receive(inpkt, len))
+		return;
+
 	NetRxPkt = inpkt;
 	NetRxPktLen = len;
 	et = (Ethernet_t *)inpkt;
@@ -582,7 +587,8 @@ NetReceive(uchar * inpkt, int len)
 				NetCopyIP(&NetServerIP, &arp->ar_data[ 6]);
 			memcpy (NetServerEther, &arp->ar_data[ 0], 6);
 
-			(*packetHandler)(0,0,0,0);
+			if (packetHandler)
+				(*packetHandler)(0,0,0,0);
 		}
 		break;
 
@@ -649,7 +655,8 @@ NetReceive(uchar * inpkt, int len)
 				 *	IP header OK.  Pass the packet to the current handler.
 				 */
 				/* XXX point to ip packet */
-				(*packetHandler)((uchar *)ip, 0, 0, 0);
+				if (packetHandler)
+					(*packetHandler)((uchar *)ip, 0, 0, 0);
 				return;
 #endif
 			default:
@@ -701,7 +708,8 @@ NetReceive(uchar * inpkt, int len)
 		/*
 		 *	IP header OK.  Pass the packet to the current handler.
 		 */
-		(*packetHandler)((uchar *)ip +IP_HDR_SIZE,
+		if (packetHandler)
+			(*packetHandler)((uchar *)ip +IP_HDR_SIZE,
 						ntohs(ip->udp_dst),
 						ntohs(ip->udp_src),
 						ntohs(ip->udp_len) - 8);
@@ -951,10 +959,29 @@ void ethaddr_to_string(const unsigned char *enetaddr, char *str)
 		 enetaddr[4], enetaddr[5]);
 }
 
+static IPaddr_t	net_netmask;		/* Our subnet mask (0=unknown)	*/
+static IPaddr_t	net_gateway;		/* Our gateways IP address	*/
+static IPaddr_t	net_dns_server;		/* Our DNS IP address		*/
+
+static unsigned char net_ether[6];	/* Our ethernet address		*/
+static IPaddr_t	net_ip;			/* Our IP addr (0 = unknown)	*/
+static IPaddr_t	net_serverip;		/* Our IP addr (0 = unknown)	*/
+
+unsigned char *NetRxPackets[PKTBUFSRX]; /* Receive packets		*/
+static unsigned int net_ip_id;
+
 void net_update_env(void)
 {
 	struct eth_device *edev = eth_get_current();
 
+	net_ip = dev_get_param_ip(&edev->dev, "ipaddr");
+	net_serverip = dev_get_param_ip(&edev->dev, "serverip");
+	net_gateway = dev_get_param_ip(&edev->dev, "gateway");
+	net_netmask = dev_get_param_ip(&edev->dev, "netmask");
+
+	string_to_ethaddr(dev_get_param(&edev->dev, "ethaddr"),
+			net_ether);
+
 	NetOurIP = dev_get_param_ip(&edev->dev, "ipaddr");
 	NetServerIP = dev_get_param_ip(&edev->dev, "serverip");
 	NetOurGatewayIP = dev_get_param_ip(&edev->dev, "gateway");
@@ -964,3 +991,491 @@ void net_update_env(void)
 			NetOurEther);
 }
 
+int net_checksum_ok(unsigned char *ptr, int len)
+{
+	return net_checksum(ptr, len) + 1;
+}
+
+uint16_t net_checksum(unsigned char *ptr, int len)
+{
+	uint32_t xsum = 0;
+	uint16_t *p = (uint16_t *)ptr;
+
+	if (len & 1)
+		ptr[len] = 0;
+
+	len = (len + 1) >> 1;
+
+	while (len-- > 0)
+		xsum += *p++;
+
+	xsum = (xsum & 0xffff) + (xsum >> 16);
+	xsum = (xsum & 0xffff) + (xsum >> 16);
+	return xsum & 0xffff;
+}
+
+static unsigned char *arp_ether;
+static IPaddr_t arp_wait_ip;
+
+static void arp_handler(struct arprequest *arp)
+{
+	IPaddr_t tmp;
+
+	/* are we waiting for a reply */
+	if (!arp_wait_ip)
+		return;
+
+	tmp = net_read_ip(&arp->ar_data[6]);
+
+	/* matched waiting packet's address */
+	if (tmp == arp_wait_ip) {
+		/* save address for later use */
+		memcpy(arp_ether, &arp->ar_data[0], 6);
+
+		/* no arp request pending now */
+		arp_wait_ip = 0;
+	}
+}
+
+int arp_request(IPaddr_t dest, unsigned char *ether)
+{
+	char *pkt;
+	struct arprequest *arp;
+	uint64_t arp_start;
+	static char *arp_packet;
+	struct ethernet *et;
+
+	if (!arp_packet) {
+		arp_packet = net_alloc_packet();
+		if (!arp_packet)
+			return -ENOMEM;
+	}
+
+	pkt = arp_packet;
+	et = (struct ethernet *)arp_packet;
+
+	arp_wait_ip = dest;
+
+	pr_debug("ARP broadcast\n");
+
+	memset(et->et_dest, 0xff, 6);
+	memcpy(et->et_src, net_ether, 6);
+	et->et_protlen = htons(PROT_ARP);
+
+	arp = (struct arprequest *)(pkt + ETHER_HDR_SIZE);
+
+	arp->ar_hrd = htons(ARP_ETHER);
+	arp->ar_pro = htons(PROT_IP);
+	arp->ar_hln = 6;
+	arp->ar_pln = 4;
+	arp->ar_op = htons(ARPOP_REQUEST);
+
+	memcpy(arp->ar_data, net_ether, 6);	/* source ET addr	*/
+	net_write_ip(arp->ar_data + 6, net_ip);	/* source IP addr	*/
+	memset(arp->ar_data + 10, 0, 6);	/* dest ET addr = 0     */
+
+	if ((dest & net_netmask) != (net_ip & net_netmask)) {
+		if (!net_gateway)
+			arp_wait_ip = dest;
+		else
+			arp_wait_ip = net_gateway;
+	} else {
+		arp_wait_ip = dest;
+	}
+
+	net_write_ip(arp->ar_data + 16, arp_wait_ip);
+
+	arp_ether = ether;
+
+	eth_send(arp_packet, ETHER_HDR_SIZE + ARP_HDR_SIZE);
+	arp_start = get_time_ns();
+
+	while (arp_wait_ip) {
+		if (ctrlc())
+			return -EINTR;
+
+		if (is_timeout(arp_start, 3 * SECOND)) {
+			printf("T ");
+			arp_start = get_time_ns();
+			eth_send(arp_packet, ETHER_HDR_SIZE + ARP_HDR_SIZE);
+		}
+
+		net_poll();
+	}
+
+	pr_debug("Got ARP REPLY, set server/gtwy eth addr (%02x:%02x:%02x:%02x:%02x:%02x)\n",
+		ether[0], ether[1],
+		ether[2], ether[3],
+		ether[4], ether[5]);
+	return 0;
+}
+
+void net_poll(void)
+{
+	eth_rx();
+}
+
+static uint16_t net_udp_new_localport(void)
+{
+	static uint16_t localport;
+
+	localport++;
+
+	if (localport < 1024)
+		localport = 1024;
+
+	return localport;
+}
+
+IPaddr_t net_get_serverip(void)
+{
+	return net_serverip;
+}
+
+void net_set_serverip(IPaddr_t ip)
+{
+	struct eth_device *edev = eth_get_current();
+
+	net_serverip = ip;
+	dev_set_param_ip(&edev->dev, "serverip", net_serverip);
+}
+
+void net_set_ip(IPaddr_t ip)
+{
+	struct eth_device *edev = eth_get_current();
+
+	net_ip = ip;
+	dev_set_param_ip(&edev->dev, "ipaddr", net_ip);
+}
+
+IPaddr_t net_get_ip(void)
+{
+	return net_ip;
+}
+
+void net_set_netmask(IPaddr_t nm)
+{
+	struct eth_device *edev = eth_get_current();
+
+	net_netmask = nm;
+	dev_set_param_ip(&edev->dev, "netmask", net_netmask);
+}
+
+void net_set_gateway(IPaddr_t gw)
+{
+	struct eth_device *edev = eth_get_current();
+
+	net_gateway = gw;
+	dev_set_param_ip(&edev->dev, "gateway", net_gateway);
+}
+
+void net_set_dnsip(IPaddr_t dns)
+{
+	net_dns_server = dns;
+}
+
+static LIST_HEAD(connection_list);
+
+static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler)
+{
+	struct net_connection *con;
+	int ret;
+
+	if (!is_valid_ether_addr(net_ether))
+		return ERR_PTR(-ENETDOWN);
+
+	/* If we don't have an ip only broadcast is allowed */
+	if (!net_ip && dest != 0xffffffff)
+		return ERR_PTR(-ENETDOWN);
+
+	con = xzalloc(sizeof(*con));
+	con->packet = memalign(32, PKTSIZE);
+	memset(con->packet, 0, PKTSIZE);
+
+	con->et = (struct ethernet *)con->packet;
+	con->ip = (struct iphdr *)(con->packet + ETHER_HDR_SIZE);
+	con->udp = (struct udphdr *)(con->packet + ETHER_HDR_SIZE + sizeof(struct iphdr));
+	con->icmp = (struct icmphdr *)(con->packet + ETHER_HDR_SIZE + sizeof(struct iphdr));
+	con->handler = handler;
+
+	if (dest == 0xffffffff) {
+		memset(con->et->et_dest, 0xff, 6);
+	} else {
+		ret = arp_request(dest, con->et->et_dest);
+		if (ret)
+			goto out;
+	}
+
+	con->et->et_protlen = htons(PROT_IP);
+	memcpy(con->et->et_src, net_ether, 6);
+
+	con->ip->hl_v = 0x45;
+	con->ip->tos = 0;
+	con->ip->frag_off = htons(0x4000);	/* No fragmentation */;
+	con->ip->ttl = 255;
+	net_copy_ip(&con->ip->daddr, &dest);
+	net_copy_ip(&con->ip->saddr, &net_ip);
+
+	list_add_tail(&con->list, &connection_list);
+
+	return con;
+out:
+	free(con->packet);
+	free(con);
+	return ERR_PTR(ret);
+}
+
+struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
+		rx_handler_f *handler)
+{
+	struct net_connection *con = net_new(dest, handler);
+
+	if (IS_ERR(con))
+		return con;
+
+	con->proto = IPPROTO_UDP;
+	con->udp->uh_dport = htons(dport);
+	con->udp->uh_sport = htons(net_udp_new_localport());
+	con->ip->protocol = IPPROTO_UDP;
+
+	return con;
+}
+
+struct net_connection *net_icmp_new(IPaddr_t dest, rx_handler_f *handler)
+{
+	struct net_connection *con = net_new(dest, handler);
+
+	if (IS_ERR(con))
+		return con;
+
+	con->proto = IPPROTO_ICMP;
+	con->ip->protocol = IPPROTO_ICMP;
+
+	return con;
+}
+
+void net_unregister(struct net_connection *con)
+{
+	list_del(&con->list);
+	free(con->packet);
+	free(con);
+}
+
+int net_ip_send(struct net_connection *con, int len)
+{
+	con->ip->tot_len = htons(sizeof(struct iphdr) + len);
+	con->ip->id = htons(net_ip_id++);;
+	con->ip->check = 0;
+	con->ip->check = ~net_checksum((unsigned char *)con->ip, sizeof(struct iphdr));
+
+	eth_send(con->packet, ETHER_HDR_SIZE + sizeof(struct iphdr) + len);
+
+	return 0;
+}
+
+int net_udp_send(struct net_connection *con, int len)
+{
+	con->udp->uh_ulen = htons(len + 8);
+	con->udp->uh_sum = 0;
+
+	return net_ip_send(con, sizeof(struct udphdr) + len);
+}
+
+int net_icmp_send(struct net_connection *con, int len)
+{
+	con->icmp->checksum = ~net_checksum((unsigned char *)con->icmp,
+			sizeof(struct icmphdr) + len);
+
+	return net_ip_send(con, sizeof(struct icmphdr) + len);
+}
+
+static int net_answer_arp(unsigned char *pkt, int len)
+{
+	struct arprequest *arp = (struct arprequest *)(pkt + ETHER_HDR_SIZE);
+	struct ethernet *et = (struct ethernet *)pkt;
+	unsigned char *packet;
+
+	debug("%s\n", __func__);
+
+	memcpy (et->et_dest, et->et_src, 6);
+	memcpy (et->et_src, net_ether, 6);
+
+	et->et_protlen = htons(PROT_ARP);
+	arp->ar_op = htons(ARPOP_REPLY);
+	memcpy(&arp->ar_data[10], &arp->ar_data[0], 6);
+	net_copy_ip(&arp->ar_data[16], &arp->ar_data[6]);
+	memcpy(&arp->ar_data[0], net_ether, 6);
+	net_copy_ip(&arp->ar_data[6], &net_ip);
+
+	packet = net_alloc_packet();
+	if (!packet)
+		return 0;
+	memcpy(packet, pkt, ETHER_HDR_SIZE + ARP_HDR_SIZE);
+	eth_send(packet, ETHER_HDR_SIZE + ARP_HDR_SIZE);
+	free(packet);
+
+	return 0;
+}
+
+static void net_bad_packet(unsigned char *pkt, int len)
+{
+#ifdef DEBUG
+	/*
+	 * We received a bad packet. for now just dump it.
+	 * We could add more sophisticated debugging here
+	 */
+	memory_display(pkt, 0, len, 1);
+#endif
+}
+
+static int net_handle_arp(unsigned char *pkt, int len)
+{
+	struct arprequest *arp;
+
+	debug("%s: got arp\n", __func__);
+
+	/*
+	 * We have to deal with two types of ARP packets:
+	 * - REQUEST packets will be answered by sending  our
+	 *   IP address - if we know it.
+	 * - REPLY packets are expected only after we asked
+	 *   for the TFTP server's or the gateway's ethernet
+	 *   address; so if we receive such a packet, we set
+	 *   the server ethernet address
+	 */
+	arp = (struct arprequest *)(pkt + ETHER_HDR_SIZE);
+	if (len < ARP_HDR_SIZE)
+		goto bad;
+	if (ntohs(arp->ar_hrd) != ARP_ETHER)
+		goto bad;
+	if (ntohs(arp->ar_pro) != PROT_IP)
+		goto bad;
+	if (arp->ar_hln != 6)
+		goto bad;
+	if (arp->ar_pln != 4)
+		goto bad;
+	if (net_ip == 0)
+		return 0;
+	if (net_read_ip(&arp->ar_data[16]) != net_ip)
+		return 0;
+
+	switch (ntohs(arp->ar_op)) {
+	case ARPOP_REQUEST:
+		return net_answer_arp(pkt, len);
+	case ARPOP_REPLY:
+		arp_handler(arp);
+		return 1;
+	default:
+		pr_debug("Unexpected ARP opcode 0x%x\n", ntohs(arp->ar_op));
+		return -EINVAL;
+	}
+
+	return 0;
+
+bad:
+	net_bad_packet(pkt, len);
+	return -EINVAL;
+}
+
+static int net_handle_udp(unsigned char *pkt, int len)
+{
+	struct iphdr *ip = (struct iphdr *)(pkt + ETHER_HDR_SIZE);
+	struct net_connection *con;
+	struct udphdr *udp;
+	int port;
+
+	udp = (struct udphdr *)(ip + 1);
+	port = ntohs(udp->uh_dport);
+	list_for_each_entry(con, &connection_list, list) {
+		if (con->proto == IPPROTO_UDP && port == ntohs(con->udp->uh_sport)) {
+			con->handler(pkt, len);
+			return 0;
+		}
+	}
+	return -EINVAL;
+}
+
+static int net_handle_icmp(unsigned char *pkt, int len)
+{
+	struct net_connection *con;
+
+	debug("%s\n", __func__);
+
+	list_for_each_entry(con, &connection_list, list) {
+		if (con->proto == IPPROTO_ICMP) {
+			con->handler(pkt, len);
+			return 0;
+		}
+	}
+	return 0;
+}
+
+static int net_handle_ip(unsigned char *pkt, int len)
+{
+	struct iphdr *ip = (struct iphdr *)(pkt + ETHER_HDR_SIZE);
+	IPaddr_t tmp;
+
+	debug("%s\n", __func__);
+
+	if (len < sizeof(struct ethernet) + sizeof(struct iphdr) ||
+		len < ETHER_HDR_SIZE + ntohs(ip->tot_len)) {
+		debug("%s: bad len\n", __func__);
+		goto bad;
+	}
+
+	if ((ip->hl_v & 0xf0) != 0x40)
+		goto bad;
+
+	if (ip->frag_off & htons(0x1fff)) /* Can't deal w/ fragments */
+		goto bad;
+	if (!net_checksum_ok((unsigned char *)ip, sizeof(struct iphdr)))
+		goto bad;
+
+	tmp = net_read_ip(&ip->daddr);
+	if (net_ip && tmp != net_ip && tmp != 0xffffffff)
+		return 0;
+
+	switch (ip->protocol) {
+	case IPPROTO_ICMP:
+		return net_handle_icmp(pkt, len);
+	case IPPROTO_UDP:
+		return net_handle_udp(pkt, len);
+	}
+
+	return 0;
+bad:
+	net_bad_packet(pkt, len);
+	return 0;
+}
+
+int net_receive(unsigned char *pkt, int len)
+{
+	struct ethernet *et = (struct ethernet *)pkt;
+	int et_protlen = ntohs(et->et_protlen);
+
+	if (len < ETHER_HDR_SIZE)
+		return 0;
+
+	switch (et_protlen) {
+	case PROT_ARP:
+		return net_handle_arp(pkt, len);
+	case PROT_IP:
+		return net_handle_ip(pkt, len);
+	default:
+		debug("%s: got unknown protocol type: %d\n", __func__, et_protlen);
+		return 1;
+	}
+}
+
+static int net_init(void)
+{
+	int i;
+
+	for (i = 0; i < PKTBUFSRX; i++)
+		NetRxPackets[i] =  memalign(32, PKTSIZE);
+
+	return 0;
+}
+
+postcore_initcall(net_init);
+
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:55:03 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:55:03 +0200
Subject: [PATCH 07/13] implement nfs using new network stack
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-8-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/nfs.c |  716 +++++++++++++++++++++++++++++-------------------------------
 1 files changed, 346 insertions(+), 370 deletions(-)

diff --git a/net/nfs.c b/net/nfs.c
index 15f91ab..51df7a3 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -32,28 +32,111 @@
 #include <libgen.h>
 #include <fcntl.h>
 #include <errno.h>
-#include "nfs.h"
-
-/*#define NFS_DEBUG*/
+#include <linux/err.h>
+
+#define SUNRPC_PORT     111
+
+#define PROG_PORTMAP    100000
+#define PROG_NFS        100003
+#define PROG_MOUNT      100005
+
+#define MSG_CALL        0
+#define MSG_REPLY       1
+
+#define PORTMAP_GETPORT 3
+
+#define MOUNT_ADDENTRY  1
+#define MOUNT_UMOUNTALL 4
+
+#define NFS_LOOKUP      4
+#define NFS_READLINK    5
+#define NFS_READ        6
+
+#define NFS_FHSIZE      32
+
+enum nfs_stat {
+	NFS_OK		= 0,
+	NFSERR_PERM	= 1,
+	NFSERR_NOENT	= 2,
+	NFSERR_IO	= 5,
+	NFSERR_NXIO	= 6,
+	NFSERR_ACCES	= 13,
+	NFSERR_EXIST	= 17,
+	NFSERR_NODEV	= 19,
+	NFSERR_NOTDIR	= 20,
+	NFSERR_ISDIR	= 21,
+	NFSERR_FBIG	= 27,
+	NFSERR_NOSPC	= 28,
+	NFSERR_ROFS	= 30,
+	NFSERR_NAMETOOLONG=63,
+	NFSERR_NOTEMPTY	= 66,
+	NFSERR_DQUOT	= 69,
+	NFSERR_STALE	= 70,
+	NFSERR_WFLUSH	= 99,
+};
+
+/* Block size used for NFS read accesses.  A RPC reply packet (including  all
+ * headers) must fit within a single Ethernet frame to avoid fragmentation.
+ * Chosen to be a power of two, as most NFS servers are optimized for this.  */
+#define NFS_READ_SIZE   1024
+
+struct rpc_call {
+	uint32_t id;
+	uint32_t type;
+	uint32_t rpcvers;
+	uint32_t prog;
+	uint32_t vers;
+	uint32_t proc;
+	uint32_t data[0];
+};
+
+struct rpc_reply {
+	uint32_t id;
+	uint32_t type;
+	uint32_t rstatus;
+	uint32_t verifier;
+	uint32_t v2;
+	uint32_t astatus;
+	uint32_t data[0];
+};
+
+struct rpc_t {
+	union {
+		struct {
+			uint32_t id;
+			uint32_t type;
+			uint32_t rpcvers;
+			uint32_t prog;
+			uint32_t vers;
+			uint32_t proc;
+			uint32_t data[1];
+		} call;
+		struct {
+			uint32_t id;
+			uint32_t type;
+			uint32_t rstatus;
+			uint32_t verifier;
+			uint32_t v2;
+			uint32_t astatus;
+			uint32_t data[19];
+		} reply;
+	} u;
+};
 
 #define HASHES_PER_LINE 65	/* Number of "loading" hashes per line	*/
 #define NFS_TIMEOUT 60
 
-static int fs_mounted = 0;
 static unsigned long rpc_id = 0;
 static int nfs_offset = -1;
-static int nfs_len;
+static uint64_t nfs_timer_start;
+static int nfs_err;
 
 static char dirfh[NFS_FHSIZE];	/* file handle of directory */
 static char filefh[NFS_FHSIZE]; /* file handle of kernel image */
 
-static int	NfsDownloadState;
-static IPaddr_t NfsServerIP;
-static int	NfsSrvMountPort;
-static int	NfsSrvNfsPort;
-static int	NfsOurPort;
-static int	NfsTimeoutCount;
-static int	NfsState;
+static int	nfs_server_mount_port;
+static int	nfs_server_nfs_port;
+static int	nfs_state;
 #define STATE_PRCLOOKUP_PROG_MOUNT_REQ	1
 #define STATE_PRCLOOKUP_PROG_NFS_REQ	2
 #define STATE_MOUNT_REQ			3
@@ -61,40 +144,22 @@ static int	NfsState;
 #define STATE_LOOKUP_REQ		5
 #define STATE_READ_REQ			6
 #define STATE_READLINK_REQ		7
+#define STATE_DONE			8
 
 static char *nfs_filename;
 static char *nfs_path;
 static char nfs_path_buff[2048];
 
 static int net_store_fd;
-
-static __inline__ int
-store_block (uchar * src, unsigned offset, unsigned len)
-{
-	ulong newsize = offset + len;
-	int ret;
-
-	ret = write(net_store_fd, src, len);
-	if (ret < 0)
-		return ret;
-
-	if (NetBootFileXferSize < (offset+len))
-		NetBootFileXferSize = newsize;
-
-	return 0;
-}
+static struct net_connection *nfs_con;
 
 /**************************************************************************
 RPC_ADD_CREDENTIALS - Add RPC authentication/verifier entries
 **************************************************************************/
-static long *rpc_add_credentials (long *p)
+static uint32_t *rpc_add_credentials(uint32_t *p)
 {
 	int hl;
-	int hostnamelen;
-	char hostname[256];
-
-	strcpy (hostname, "");
-	hostnamelen=strlen (hostname);
+	int hostnamelen = 0;
 
 	/* Here's the executive summary on authentication requirements of the
 	 * various NFS server implementations:	Linux accepts both AUTH_NONE
@@ -112,10 +177,12 @@ static long *rpc_add_credentials (long *p)
 	*p++ = htonl(hl+20);		/* auth length */
 	*p++ = htonl(0);		/* stamp */
 	*p++ = htonl(hostnamelen);	/* hostname string */
-	if (hostnamelen & 3) {
+
+	if (hostnamelen & 3)
 		*(p + hostnamelen / 4) = 0; /* add zero padding */
-	}
-	memcpy (p, hostname, hostnamelen);
+
+	/* memcpy(p, hostname, hostnamelen); */ /* empty hostname */
+
 	p += hl / 4;
 	*p++ = 0;			/* uid */
 	*p++ = 0;			/* gid */
@@ -131,46 +198,42 @@ static long *rpc_add_credentials (long *p)
 /**************************************************************************
 RPC_LOOKUP - Lookup RPC Port numbers
 **************************************************************************/
-static void
-rpc_req (int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
+static int rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
 {
-	struct rpc_t pkt;
+	struct rpc_call pkt;
 	unsigned long id;
-	uint32_t *p;
-	int pktlen;
 	int sport;
+	int ret;
+	unsigned char *payload = net_udp_get_payload(nfs_con);
 
 	id = ++rpc_id;
-	pkt.u.call.id = htonl(id);
-	pkt.u.call.type = htonl(MSG_CALL);
-	pkt.u.call.rpcvers = htonl(2);	/* use RPC version 2 */
-	pkt.u.call.prog = htonl(rpc_prog);
-	pkt.u.call.vers = htonl(2);	/* portmapper is version 2 */
-	pkt.u.call.proc = htonl(rpc_proc);
-	p = (uint32_t *)&(pkt.u.call.data);
-
-	if (datalen)
-		memcpy ((char *)p, (char *)data, datalen*sizeof(uint32_t));
-
-	pktlen = (char *)p + datalen*sizeof(uint32_t) - (char *)&pkt;
+	pkt.id = htonl(id);
+	pkt.type = htonl(MSG_CALL);
+	pkt.rpcvers = htonl(2);	/* use RPC version 2 */
+	pkt.prog = htonl(rpc_prog);
+	pkt.vers = htonl(2);	/* portmapper is version 2 */
+	pkt.proc = htonl(rpc_proc);
 
-	memcpy ((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE, (char *)&pkt, pktlen);
+	memcpy(payload, &pkt, sizeof(pkt));
+	memcpy(payload + sizeof(pkt), data, datalen * sizeof(uint32_t));
 
 	if (rpc_prog == PROG_PORTMAP)
 		sport = SUNRPC_PORT;
 	else if (rpc_prog == PROG_MOUNT)
-		sport = NfsSrvMountPort;
+		sport = nfs_server_mount_port;
 	else
-		sport = NfsSrvNfsPort;
+		sport = nfs_server_nfs_port;
 
-	NetSendUDPPacket (NetServerEther, NfsServerIP, sport, NfsOurPort, pktlen);
+	nfs_con->udp->uh_dport = htons(sport);
+	ret = net_udp_send(nfs_con, sizeof(pkt) + datalen * sizeof(uint32_t));
+
+	return ret;
 }
 
 /**************************************************************************
 RPC_LOOKUP - Lookup RPC Port numbers
 **************************************************************************/
-static void
-rpc_lookup_req (int prog, int ver)
+static void rpc_lookup_req(int prog, int ver)
 {
 	uint32_t data[16];
 
@@ -181,14 +244,13 @@ rpc_lookup_req (int prog, int ver)
 	data[6] = htonl(17);	/* IP_UDP */
 	data[7] = 0;
 
-	rpc_req (PROG_PORTMAP, PORTMAP_GETPORT, data, 8);
+	rpc_req(PROG_PORTMAP, PORTMAP_GETPORT, data, 8);
 }
 
 /**************************************************************************
 NFS_MOUNT - Mount an NFS Filesystem
 **************************************************************************/
-static void
-nfs_mount_req (char *path)
+static void nfs_mount_req(char *path)
 {
 	uint32_t data[1024];
 	uint32_t *p;
@@ -198,39 +260,38 @@ nfs_mount_req (char *path)
 	pathlen = strlen (path);
 
 	p = &(data[0]);
-	p = (uint32_t *)rpc_add_credentials((long *)p);
+	p = rpc_add_credentials(p);
 
 	*p++ = htonl(pathlen);
-	if (pathlen & 3) *(p + pathlen / 4) = 0;
+	if (pathlen & 3)
+		*(p + pathlen / 4) = 0;
 	memcpy (p, path, pathlen);
 	p += (pathlen + 3) / 4;
 
-	len = (uint32_t *)p - (uint32_t *)&(data[0]);
+	len = p - &(data[0]);
 
-	rpc_req (PROG_MOUNT, MOUNT_ADDENTRY, data, len);
+	rpc_req(PROG_MOUNT, MOUNT_ADDENTRY, data, len);
 }
 
 /**************************************************************************
 NFS_UMOUNTALL - Unmount all our NFS Filesystems on the Server
 **************************************************************************/
-static void
-nfs_umountall_req (void)
+static void nfs_umountall_req(void)
 {
 	uint32_t data[1024];
 	uint32_t *p;
 	int len;
 
-	if ((NfsSrvMountPort == -1) || (!fs_mounted)) {
+	if (nfs_server_mount_port < 0)
 		/* Nothing mounted, nothing to umount */
 		return;
-	}
 
 	p = &(data[0]);
-	p = (uint32_t *)rpc_add_credentials ((long *)p);
+	p = rpc_add_credentials(p);
 
-	len = (uint32_t *)p - (uint32_t *)&(data[0]);
+	len = p - &(data[0]);
 
-	rpc_req (PROG_MOUNT, MOUNT_UMOUNTALL, data, len);
+	rpc_req(PROG_MOUNT, MOUNT_UMOUNTALL, data, len);
 }
 
 /***************************************************************************
@@ -240,29 +301,27 @@ nfs_umountall_req (void)
  * In case of successful readlink(), the dirname is manipulated,
  * so that inside the nfs() function a recursion can be done.
  **************************************************************************/
-static void
-nfs_readlink_req (void)
+static void nfs_readlink_req(void)
 {
 	uint32_t data[1024];
 	uint32_t *p;
 	int len;
 
 	p = &(data[0]);
-	p = (uint32_t *)rpc_add_credentials ((long *)p);
+	p = rpc_add_credentials(p);
 
 	memcpy (p, filefh, NFS_FHSIZE);
 	p += (NFS_FHSIZE / 4);
 
-	len = (uint32_t *)p - (uint32_t *)&(data[0]);
+	len = p - &(data[0]);
 
-	rpc_req (PROG_NFS, NFS_READLINK, data, len);
+	rpc_req(PROG_NFS, NFS_READLINK, data, len);
 }
 
 /**************************************************************************
 NFS_LOOKUP - Lookup Pathname
 **************************************************************************/
-static void
-nfs_lookup_req (char *fname)
+static void nfs_lookup_req(char *fname)
 {
 	uint32_t data[1024];
 	uint32_t *p;
@@ -272,32 +331,32 @@ nfs_lookup_req (char *fname)
 	fnamelen = strlen (fname);
 
 	p = &(data[0]);
-	p = (uint32_t *)rpc_add_credentials ((long *)p);
+	p = rpc_add_credentials(p);
 
 	memcpy (p, dirfh, NFS_FHSIZE);
 	p += (NFS_FHSIZE / 4);
 	*p++ = htonl(fnamelen);
-	if (fnamelen & 3) *(p + fnamelen / 4) = 0;
+	if (fnamelen & 3)
+		*(p + fnamelen / 4) = 0;
 	memcpy (p, fname, fnamelen);
 	p += (fnamelen + 3) / 4;
 
-	len = (uint32_t *)p - (uint32_t *)&(data[0]);
+	len = p - &(data[0]);
 
-	rpc_req (PROG_NFS, NFS_LOOKUP, data, len);
+	rpc_req(PROG_NFS, NFS_LOOKUP, data, len);
 }
 
 /**************************************************************************
 NFS_READ - Read File on NFS Server
 **************************************************************************/
-static void
-nfs_read_req (int offset, int readlen)
+static void nfs_read_req(int offset, int readlen)
 {
 	uint32_t data[1024];
 	uint32_t *p;
 	int len;
 
 	p = &(data[0]);
-	p = (uint32_t *)rpc_add_credentials ((long *)p);
+	p = rpc_add_credentials(p);
 
 	memcpy (p, filefh, NFS_FHSIZE);
 	p += (NFS_FHSIZE / 4);
@@ -305,238 +364,194 @@ nfs_read_req (int offset, int readlen)
 	*p++ = htonl(readlen);
 	*p++ = 0;
 
-	len = (uint32_t *)p - (uint32_t *)&(data[0]);
+	len = p - &(data[0]);
 
-	rpc_req (PROG_NFS, NFS_READ, data, len);
+	rpc_req(PROG_NFS, NFS_READ, data, len);
 }
 
 /**************************************************************************
 RPC request dispatcher
 **************************************************************************/
-
-static void
-NfsSend (void)
+static void nfs_send(void)
 {
-#ifdef NFS_DEBUG
-	printf ("%s\n", __FUNCTION__);
-#endif
+	debug("%s\n", __func__);
 
-	switch (NfsState) {
+	switch (nfs_state) {
 	case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
-		rpc_lookup_req (PROG_MOUNT, 1);
+		rpc_lookup_req(PROG_MOUNT, 1);
 		break;
 	case STATE_PRCLOOKUP_PROG_NFS_REQ:
-		rpc_lookup_req (PROG_NFS, 2);
+		rpc_lookup_req(PROG_NFS, 2);
 		break;
 	case STATE_MOUNT_REQ:
-		nfs_mount_req (nfs_path);
+		nfs_mount_req(nfs_path);
 		break;
 	case STATE_UMOUNT_REQ:
-		nfs_umountall_req ();
+		nfs_umountall_req();
 		break;
 	case STATE_LOOKUP_REQ:
-		nfs_lookup_req (nfs_filename);
+		nfs_lookup_req(nfs_filename);
 		break;
 	case STATE_READ_REQ:
-		nfs_read_req (nfs_offset, nfs_len);
+		nfs_read_req(nfs_offset, NFS_READ_SIZE);
 		break;
 	case STATE_READLINK_REQ:
-		nfs_readlink_req ();
+		nfs_readlink_req();
 		break;
 	}
 }
 
-/**************************************************************************
-Handlers for the reply from server
-**************************************************************************/
-
-static int
-rpc_lookup_reply (int prog, uchar *pkt, unsigned len)
+static int rpc_check_reply(unsigned char *pkt, int isnfs)
 {
-	struct rpc_t rpc_pkt;
-
-	memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+	uint32_t *data;
+	int nfserr;
+	struct rpc_reply rpc;
 
-#ifdef NFS_DEBUG
-	printf ("%s\n", __FUNCTION__);
-#endif
+	memcpy(&rpc, pkt, sizeof(rpc));
 
-	if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
-		return -1;
+	if (ntohl(rpc.id) != rpc_id)
+		return -EINVAL;
 
-	if (rpc_pkt.u.reply.rstatus  ||
-	    rpc_pkt.u.reply.verifier ||
-	    rpc_pkt.u.reply.astatus  ||
-	    rpc_pkt.u.reply.astatus) {
-		return -1;
+	if (rpc.rstatus  ||
+	    rpc.verifier ||
+	    rpc.astatus ) {
+		return -EINVAL;
 	}
 
+	if (!isnfs)
+		return 0;
+
+	data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
+	nfserr = ntohl(net_read_uint32(data));
+
+	debug("%s: state: %d, err %d\n", __func__, nfs_state, -nfserr);
+
+	if (nfserr <= 30)
+		/* These nfs codes correspond with those in errno.h */
+		return -nfserr;
+	if (nfserr == NFSERR_STALE)
+		return -ESTALE;
+
+	return -EINVAL;
+}
+
+static int rpc_lookup_reply(int prog, unsigned char *pkt, unsigned len)
+{
+	uint32_t port;
+	int ret;
+
+	ret = rpc_check_reply(pkt, 0);
+	if (ret)
+		return ret;
+
+	port = net_read_uint32((uint32_t *)(pkt + sizeof(struct rpc_reply)));
 	switch (prog) {
 	case PROG_MOUNT:
-		NfsSrvMountPort = ntohl(rpc_pkt.u.reply.data[0]);
+		nfs_server_mount_port = ntohl(port);
 		break;
 	case PROG_NFS:
-		NfsSrvNfsPort = ntohl(rpc_pkt.u.reply.data[0]);
+		nfs_server_nfs_port = ntohl(port);
 		break;
 	}
 
 	return 0;
 }
 
-static int
-nfs_mount_reply (uchar *pkt, unsigned len)
+static int nfs_mount_reply(unsigned char *pkt, unsigned len)
 {
-	struct rpc_t rpc_pkt;
-
-#ifdef NFS_DEBUG
-	printf ("%s\n", __FUNCTION__);
-#endif
-
-	memcpy ((unsigned char *)&rpc_pkt, pkt, len);
-
-	if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
-		return -1;
+	int ret;
 
-	if (rpc_pkt.u.reply.rstatus  ||
-	    rpc_pkt.u.reply.verifier ||
-	    rpc_pkt.u.reply.astatus  ||
-	    rpc_pkt.u.reply.data[0]) {
-		return -1;
-	}
+	ret = rpc_check_reply(pkt, 1);
+	if (ret)
+		return ret;
 
-	fs_mounted = 1;
-	memcpy (dirfh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
+	memcpy(dirfh, pkt + sizeof(struct rpc_reply) + 4, NFS_FHSIZE);
 
 	return 0;
 }
 
-static int
-nfs_umountall_reply (uchar *pkt, unsigned len)
+static int nfs_umountall_reply(unsigned char *pkt, unsigned len)
 {
-	struct rpc_t rpc_pkt;
-
-#ifdef NFS_DEBUG
-	printf ("%s\n", __FUNCTION__);
-#endif
-
-	memcpy ((unsigned char *)&rpc_pkt, pkt, len);
-
-	if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
-		return -1;
+	int ret;
 
-	if (rpc_pkt.u.reply.rstatus  ||
-	    rpc_pkt.u.reply.verifier ||
-	    rpc_pkt.u.reply.astatus) {
-		return -1;
-	}
+	ret = rpc_check_reply(pkt, 0);
+	if (ret)
+		return ret;
 
-	fs_mounted = 0;
-	memset (dirfh, 0, sizeof(dirfh));
+	memset(dirfh, 0, sizeof(dirfh));
 
 	return 0;
 }
 
-static int
-nfs_lookup_reply (uchar *pkt, unsigned len)
+static int nfs_lookup_reply(unsigned char *pkt, unsigned len)
 {
-	struct rpc_t rpc_pkt;
-
-#ifdef NFS_DEBUG
-	printf ("%s\n", __FUNCTION__);
-#endif
-
-	memcpy ((unsigned char *)&rpc_pkt, pkt, len);
-
-	if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
-		return -1;
+	int ret;
 
-	if (rpc_pkt.u.reply.rstatus  ||
-	    rpc_pkt.u.reply.verifier ||
-	    rpc_pkt.u.reply.astatus  ||
-	    rpc_pkt.u.reply.data[0]) {
-		return -1;
-	}
+	ret = rpc_check_reply(pkt, 1);
+	if (ret)
+		return ret;
 
-	memcpy (filefh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
+	memcpy(filefh, pkt + sizeof(struct rpc_reply) + 4, NFS_FHSIZE);
 
 	return 0;
 }
 
-static int
-nfs_readlink_reply (uchar *pkt, unsigned len)
+static int nfs_readlink_reply(unsigned char *pkt, unsigned len)
 {
-	struct rpc_t rpc_pkt;
+	uint32_t *data;
+	char *path;
 	int rlen;
+	int ret;
 
-#ifdef NFS_DEBUG
-	printf ("%s\n", __FUNCTION__);
-#endif
+	ret = rpc_check_reply(pkt, 1);
+	if (ret)
+		return ret;
 
-	memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+	data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
 
-	if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
-		return -1;
+	data++;
 
-	if (rpc_pkt.u.reply.rstatus  ||
-	    rpc_pkt.u.reply.verifier ||
-	    rpc_pkt.u.reply.astatus  ||
-	    rpc_pkt.u.reply.data[0]) {
-		return -1;
-	}
+	rlen = ntohl(net_read_uint32(data)); /* new path length */
 
-	rlen = ntohl (rpc_pkt.u.reply.data[1]); /* new path length */
+	data++;
+	path = (char *)data;
 
-	if (*((char *)&(rpc_pkt.u.reply.data[2])) != '/') {
-		int pathlen;
-		strcat (nfs_path, "/");
-		pathlen = strlen(nfs_path);
-		memcpy (nfs_path+pathlen, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
-		nfs_path[pathlen+rlen+1] = 0;
+	if (*path != '/') {
+		strcat(nfs_path, "/");
+		strncat(nfs_path, path, rlen);
 	} else {
-		memcpy (nfs_path, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
+		memcpy(nfs_path, path, rlen);
 		nfs_path[rlen] = 0;
 	}
 	return 0;
 }
 
-static int
-nfs_read_reply (uchar *pkt, unsigned len)
+static int nfs_read_reply(unsigned char *pkt, unsigned len)
 {
-	struct rpc_t rpc_pkt;
 	int rlen;
+	uint32_t *data;
+	int ret;
 
-#ifdef NFS_DEBUG_nop
-	printf ("%s\n", __FUNCTION__);
-#endif
-
-	memcpy ((uchar *)&rpc_pkt, pkt, sizeof(rpc_pkt.u.reply));
+	debug("%s\n", __func__);
 
-	if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
-		return -1;
+	ret = rpc_check_reply(pkt, 1);
+	if (ret)
+		return ret;
 
-	if (rpc_pkt.u.reply.rstatus  ||
-	    rpc_pkt.u.reply.verifier ||
-	    rpc_pkt.u.reply.astatus  ||
-	    rpc_pkt.u.reply.data[0]) {
-		if (rpc_pkt.u.reply.rstatus) {
-			return -9999;
-		}
-		if (rpc_pkt.u.reply.astatus) {
-			return -9999;
-		}
-		return -ntohl(rpc_pkt.u.reply.data[0]);;
-	}
+	data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
 
-	if ((nfs_offset!=0) && !((nfs_offset) % (NFS_READ_SIZE/2*10*HASHES_PER_LINE))) {
+	if (nfs_offset && !((nfs_offset) % (NFS_READ_SIZE / 2 * 10 * HASHES_PER_LINE)))
 		puts ("\n\t ");
-	}
-	if (!(nfs_offset % ((NFS_READ_SIZE/2)*10))) {
+	if (!(nfs_offset % ((NFS_READ_SIZE / 2) * 10)))
 		putchar ('#');
-	}
 
-	rlen = ntohl(rpc_pkt.u.reply.data[18]);
-	if ( store_block ((uchar *)pkt+sizeof(rpc_pkt.u.reply), nfs_offset, rlen) )
-		return -9999;
+	rlen = ntohl(net_read_uint32(data + 18));
+
+	ret = write(net_store_fd, (char *)(data + 19), rlen);
+	if (ret < 0) {
+		perror("write");
+		return ret;
+	}
 
 	return rlen;
 }
@@ -545,170 +560,116 @@ nfs_read_reply (uchar *pkt, unsigned len)
 Interfaces of barebox
 **************************************************************************/
 
-static void
-NfsTimeout (void)
+static void nfs_handler(char *packet, unsigned len)
 {
-	puts ("Timeout\n");
-	NetState = NETLOOP_FAIL;
-	return;
-}
-
-static void
-NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
-{
-	int rlen;
-
-#ifdef NFS_DEBUG
-	printf ("%s\n", __FUNCTION__);
-#endif
+	char *pkt = net_eth_to_udp_payload(packet);
+	int ret;
 
-	if (dest != NfsOurPort) return;
+	debug("%s\n", __func__);
 
-	switch (NfsState) {
+	switch (nfs_state) {
 	case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
-		rpc_lookup_reply (PROG_MOUNT, pkt, len);
-		NfsState = STATE_PRCLOOKUP_PROG_NFS_REQ;
-		NfsSend ();
+		ret = rpc_lookup_reply(PROG_MOUNT, pkt, len);
+		if (ret)
+			goto err_out;
+		nfs_state = STATE_PRCLOOKUP_PROG_NFS_REQ;
 		break;
 
 	case STATE_PRCLOOKUP_PROG_NFS_REQ:
-		rpc_lookup_reply (PROG_NFS, pkt, len);
-		NfsState = STATE_MOUNT_REQ;
-		NfsSend ();
+		ret = rpc_lookup_reply(PROG_NFS, pkt, len);
+		if (ret)
+			goto err_out;
+		nfs_state = STATE_MOUNT_REQ;
 		break;
 
 	case STATE_MOUNT_REQ:
-		if (nfs_mount_reply(pkt, len)) {
-			puts ("*** ERROR: Cannot mount\n");
-			/* just to be sure... */
-			NfsState = STATE_UMOUNT_REQ;
-			NfsSend ();
-		} else {
-			NfsState = STATE_LOOKUP_REQ;
-			NfsSend ();
-		}
+		ret = nfs_mount_reply(pkt, len);
+		if (ret)
+			goto err_out;
+
+		nfs_state = STATE_LOOKUP_REQ;
 		break;
 
 	case STATE_UMOUNT_REQ:
-		if (nfs_umountall_reply(pkt, len)) {
-			puts ("*** ERROR: Cannot umount\n");
-			NetState = NETLOOP_FAIL;
-		} else {
-			puts ("\ndone\n");
-			NetState = NfsDownloadState;
-		}
-		break;
+		ret = nfs_umountall_reply(pkt, len);
+		if (ret)
+			nfs_err = ret;
+		nfs_state = STATE_DONE;
+		return;
 
 	case STATE_LOOKUP_REQ:
-		if (nfs_lookup_reply(pkt, len)) {
-			puts ("*** ERROR: File lookup fail\n");
-			NfsState = STATE_UMOUNT_REQ;
-			NfsSend ();
-		} else {
-			NfsState = STATE_READ_REQ;
-			nfs_offset = 0;
-			nfs_len = NFS_READ_SIZE;
-			NfsSend ();
-		}
+		ret = nfs_lookup_reply(pkt, len);
+		if (ret)
+			goto err_umount;
+
+		nfs_state = STATE_READ_REQ;
+		nfs_offset = 0;
 		break;
 
 	case STATE_READLINK_REQ:
-		if (nfs_readlink_reply(pkt, len)) {
-			puts ("*** ERROR: Symlink fail\n");
-			NfsState = STATE_UMOUNT_REQ;
-			NfsSend ();
-		} else {
-#ifdef NFS_DEBUG
-			printf ("Symlink --> %s\n", nfs_path);
-#endif
-			nfs_filename = basename (nfs_path);
-			nfs_path     = dirname (nfs_path);
-
-			NfsState = STATE_MOUNT_REQ;
-			NfsSend ();
-		}
+		ret = nfs_readlink_reply(pkt, len);
+		if (ret)
+			goto err_umount;
+
+		debug("Symlink --> %s\n", nfs_path);
+
+		nfs_filename = basename(nfs_path);
+		nfs_path     = dirname(nfs_path);
+
+		nfs_state = STATE_MOUNT_REQ;
 		break;
 
 	case STATE_READ_REQ:
-		rlen = nfs_read_reply (pkt, len);
-		NetSetTimeout (NFS_TIMEOUT * SECOND, NfsTimeout);
-		if (rlen > 0) {
-			nfs_offset += rlen;
-			NfsSend ();
-		}
-		else if ((rlen == -NFSERR_ISDIR)||(rlen == -NFSERR_INVAL)) {
+		ret = nfs_read_reply(pkt, len);
+		nfs_timer_start = get_time_ns();
+		if (ret > 0)
+			nfs_offset += ret;
+		else if (ret == -EISDIR || ret == -EINVAL)
 			/* symbolic link */
-			NfsState = STATE_READLINK_REQ;
-			NfsSend ();
-		} else {
-			if ( ! rlen ) NfsDownloadState = NETLOOP_SUCCESS;
-			NfsState = STATE_UMOUNT_REQ;
-			NfsSend ();
-		}
+			nfs_state = STATE_READLINK_REQ;
+		else
+			goto err_umount;
+
 		break;
 	}
-}
 
+	nfs_send();
+
+	return;
+
+err_umount:
+	nfs_state = STATE_UMOUNT_REQ;
+	nfs_err = ret;
+	nfs_send();
+	return;
+
+err_out:
+	nfs_state = STATE_DONE;
+	nfs_err = ret;
+}
 
-void
-NfsStart (char *p)
+static void nfs_start(char *p)
 {
-#ifdef NFS_DEBUG
-	printf ("%s\n", __FUNCTION__);
-#endif
-	NfsDownloadState = NETLOOP_FAIL;
+	debug("%s\n", __func__);
 
-	NfsServerIP = NetServerIP;
 	nfs_path = (char *)nfs_path_buff;
 
-	if (nfs_path == NULL) {
-		NetState = NETLOOP_FAIL;
-		puts ("*** ERROR: Fail allocate memory\n");
-		return;
-	}
-
-	strcpy (nfs_path, p);
+	strcpy(nfs_path, p);
 
 	nfs_filename = basename (nfs_path);
 	nfs_path     = dirname (nfs_path);
 
-#if defined(CONFIG_NET_MULTI)
-	printf ("Using %s device\n", eth_get_name());
-#endif
+	printf("\nFilename '%s/%s'.\nLoading: ", nfs_path, nfs_filename);
 
-	puts ("File transfer via NFS from server "); print_IPaddr (NfsServerIP);
-	puts ("; our IP address is ");		    print_IPaddr (NetOurIP);
+	nfs_timer_start = get_time_ns();
 
-	/* Check if we need to send across this subnet */
-	if (NetOurGatewayIP && NetOurSubnetMask) {
-		IPaddr_t OurNet	    = NetOurIP	  & NetOurSubnetMask;
-		IPaddr_t ServerNet  = NetServerIP & NetOurSubnetMask;
+	nfs_state = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
 
-		if (OurNet != ServerNet) {
-			puts ("; sending through gateway ");
-			print_IPaddr (NetOurGatewayIP) ;
-		}
-	}
-	printf ("\nFilename '%s/%s'.", nfs_path, nfs_filename);
-
-	NetSetTimeout (NFS_TIMEOUT * SECOND, NfsTimeout);
-	NetSetHandler (NfsHandler);
-
-	NfsTimeoutCount = 0;
-	NfsState = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
-
-	/*FIX ME !!!*/
-	NfsOurPort = 1000;
-
-	/* zero out server ether in case the server ip has changed */
-	memset (NetServerEther, 0, 6);
-
-	NfsSend ();
+	nfs_send();
 }
 
 static int do_nfs(struct command *cmdtp, int argc, char *argv[])
 {
-	int   rcode = 0;
 	char  *localfile;
 	char  *remotefile;
 
@@ -728,23 +689,38 @@ static int do_nfs(struct command *cmdtp, int argc, char *argv[])
 		return 1;
 	}
 
-	if (NetLoopInit(NFS) < 0)
-		goto out;
+	nfs_con = net_udp_new(net_get_serverip(), 0, nfs_handler);
+	if (IS_ERR(nfs_con)) {
+		nfs_err = PTR_ERR(nfs_con);
+		goto err_udp;
+	}
+	net_udp_bind(nfs_con, 1000);
 
-	NfsStart(remotefile);
+	nfs_err = 0;
 
-	rcode = NetLoop();
-	if (rcode < 0) {
-		rcode = 1;
-		goto out;
-	}
+	nfs_start(remotefile);
 
-	/* NetLoop ok, update environment */
-	netboot_update_env();
+	while (nfs_state != STATE_DONE) {
+		if (ctrlc()) {
+			nfs_err = -EINTR;
+			break;
+		}
+		net_poll();
+		if (is_timeout(nfs_timer_start, NFS_TIMEOUT * SECOND))
+			break;
+	}
 
-out:
+	net_unregister(nfs_con);
+err_udp:
 	close(net_store_fd);
-	return rcode;
+	if (nfs_err) {
+		printf("NFS failed: %s\n", strerror(-nfs_err));
+		unlink(localfile);
+	}
+
+	printf("\n");
+
+	return nfs_err == 0 ? 0 : 1;
 }
 
 static const __maybe_unused char cmd_nfs_help[] =
-- 
1.7.1



From s.hauer at pengutronix.de  Fri Jun  4 05:55:06 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  4 Jun 2010 11:55:06 +0200
Subject: [PATCH 10/13] net: remove old network stack
In-Reply-To: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1275645309-9756-11-git-send-email-s.hauer@pengutronix.de>

All network commands now use the new stack, so remove the old one.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/net.c |   42 ---
 include/net.h  |  359 +---------------------
 net/net.c      |  947 +++-----------------------------------------------------
 3 files changed, 50 insertions(+), 1298 deletions(-)

diff --git a/commands/net.c b/commands/net.c
index 949963f..938463c 100644
--- a/commands/net.c
+++ b/commands/net.c
@@ -35,48 +35,6 @@
 #include <errno.h>
 #include <libbb.h>
 
-void netboot_update_env(void)
-{
-	struct eth_device *eth_current = eth_get_current();
-	char tmp[22];
-	IPaddr_t net_gateway_ip = NetOurGatewayIP;
-	IPaddr_t net_ip = NetOurIP;
-	IPaddr_t net_server_ip = NetServerIP;
-	IPaddr_t netmask = NetOurSubnetMask;
-
-	if (net_gateway_ip)
-		dev_set_param_ip(&eth_current->dev, "gateway", net_gateway_ip);
-
-	if (netmask)
-		dev_set_param_ip(&eth_current->dev, "netmask", netmask);
-
-
-	if (NetOurHostName[0])
-		setenv ("hostname", NetOurHostName);
-
-	if (NetOurRootPath[0])
-		setenv ("rootpath", NetOurRootPath);
-
-	if (net_ip)
-		dev_set_param_ip(&eth_current->dev, "ipaddr", net_ip);
-
-	if (net_server_ip)
-		dev_set_param_ip(&eth_current->dev, "serverip", net_server_ip);
-
-	if (NetOurDNSIP) {
-		ip_to_string (NetOurDNSIP, tmp);
-		setenv ("dnsip", tmp);
-	}
-#ifdef CONFIG_BOOTP_DNS2
-	if (NetOurDNS2IP) {
-		ip_to_string (NetOurDNS2IP, tmp);
-		setenv ("dnsip2", tmp);
-	}
-#endif
-	if (NetOurNISDomain[0])
-		setenv ("domain", NetOurNISDomain);
-}
-
 #ifdef CONFIG_NET_RARP
 extern void RarpRequest(void);
 
diff --git a/include/net.h b/include/net.h
index f588a3d..627b18b 100644
--- a/include/net.h
+++ b/include/net.h
@@ -19,39 +19,8 @@
 #include <asm/byteorder.h>	/* for nton* / ntoh* stuff */
 
 
-/*
- *	The number of receive packet buffers, and the required packet buffer
- *	alignment in memory.
- *
- */
-
-#ifdef CFG_RX_ETH_BUFFER
-# define PKTBUFSRX	CFG_RX_ETH_BUFFER
-#else
-# define PKTBUFSRX	4
-#endif
-
-#define PKTALIGN	32
-
-/*
- * The current receive packet handler.  Called with a pointer to the
- * application packet, and a protocol type (PORT_BOOTPC or PORT_TFTP).
- * All other packets are dealt with without calling the handler.
- */
-typedef void	rxhand_f(uchar *, unsigned, unsigned, unsigned);
-
-/*
- *	A timeout handler.  Called after time interval has expired.
- */
-typedef void	thand_f(void);
-
-#define NAMESIZE 16
-
-enum eth_state_t {
-	ETH_STATE_INIT,
-	ETH_STATE_PASSIVE,
-	ETH_STATE_ACTIVE
-};
+/* The number of receive packet buffers */
+#define PKTBUFSRX	4
 
 struct device_d;
 
@@ -92,328 +61,6 @@ int eth_rx(void);			/* Check for received packets	*/
 void eth_halt(void);			/* stop SCC			*/
 char *eth_get_name(void);		/* get name of current device	*/
 
-
-/**********************************************************************/
-/*
- *	Protocol headers.
- */
-
-/*
- *	Ethernet header
- */
-typedef struct {
-	uchar		et_dest[6];	/* Destination node		*/
-	uchar		et_src[6];	/* Source node			*/
-	ushort		et_protlen;	/* Protocol or length		*/
-	uchar		et_dsap;	/* 802 DSAP			*/
-	uchar		et_ssap;	/* 802 SSAP			*/
-	uchar		et_ctl;		/* 802 control			*/
-	uchar		et_snap1;	/* SNAP				*/
-	uchar		et_snap2;
-	uchar		et_snap3;
-	ushort		et_prot;	/* 802 protocol			*/
-} Ethernet_t;
-
-#define ETHER_HDR_SIZE	14		/* Ethernet header size		*/
-#define E802_HDR_SIZE	22		/* 802 ethernet header size	*/
-
-/*
- *	Ethernet header
- */
-typedef struct {
-	uchar		vet_dest[6];	/* Destination node		*/
-	uchar		vet_src[6];	/* Source node			*/
-	ushort		vet_vlan_type;	/* PROT_VLAN			*/
-	ushort		vet_tag;	/* TAG of VLAN			*/
-	ushort		vet_type;	/* protocol type		*/
-} VLAN_Ethernet_t;
-
-#define VLAN_ETHER_HDR_SIZE	18	/* VLAN Ethernet header size	*/
-
-#define PROT_IP		0x0800		/* IP protocol			*/
-#define PROT_ARP	0x0806		/* IP ARP protocol		*/
-#define PROT_RARP	0x8035		/* IP ARP protocol		*/
-#define PROT_VLAN	0x8100		/* IEEE 802.1q protocol		*/
-
-#define IPPROTO_ICMP	 1	/* Internet Control Message Protocol	*/
-#define IPPROTO_UDP	17	/* User Datagram Protocol		*/
-
-/*
- *	Internet Protocol (IP) header.
- */
-typedef struct {
-	uchar		ip_hl_v;	/* header length and version	*/
-	uchar		ip_tos;		/* type of service		*/
-	ushort		ip_len;		/* total length			*/
-	ushort		ip_id;		/* identification		*/
-	ushort		ip_off;		/* fragment offset field	*/
-	uchar		ip_ttl;		/* time to live			*/
-	uchar		ip_p;		/* protocol			*/
-	ushort		ip_sum;		/* checksum			*/
-	IPaddr_t	ip_src;		/* Source IP address		*/
-	IPaddr_t	ip_dst;		/* Destination IP address	*/
-	ushort		udp_src;	/* UDP source port		*/
-	ushort		udp_dst;	/* UDP destination port		*/
-	ushort		udp_len;	/* Length of UDP packet		*/
-	ushort		udp_xsum;	/* Checksum			*/
-} IP_t;
-
-#define IP_HDR_SIZE_NO_UDP	(sizeof (IP_t) - 8)
-#define IP_HDR_SIZE		(sizeof (IP_t))
-
-
-/*
- *	Address Resolution Protocol (ARP) header.
- */
-typedef struct
-{
-	ushort		ar_hrd;		/* Format of hardware address	*/
-#   define ARP_ETHER	    1		/* Ethernet  hardware address	*/
-	ushort		ar_pro;		/* Format of protocol address	*/
-	uchar		ar_hln;		/* Length of hardware address	*/
-	uchar		ar_pln;		/* Length of protocol address	*/
-	ushort		ar_op;		/* Operation			*/
-#   define ARPOP_REQUEST    1		/* Request  to resolve  address	*/
-#   define ARPOP_REPLY	    2		/* Response to previous request	*/
-
-#   define RARPOP_REQUEST   3		/* Request  to resolve  address	*/
-#   define RARPOP_REPLY	    4		/* Response to previous request */
-
-	/*
-	 * The remaining fields are variable in size, according to
-	 * the sizes above, and are defined as appropriate for
-	 * specific hardware/protocol combinations.
-	 */
-	uchar		ar_data[0];
-} ARP_t;
-
-/*
- * ICMP stuff (just enough to handle (host) redirect messages)
- */
-#define ICMP_ECHO_REPLY		0	/* Echo reply 			*/
-#define ICMP_REDIRECT		5	/* Redirect (change route)	*/
-#define ICMP_ECHO_REQUEST	8	/* Echo request			*/
-
-/* Codes for REDIRECT. */
-#define ICMP_REDIR_NET		0	/* Redirect Net			*/
-#define ICMP_REDIR_HOST		1	/* Redirect Host		*/
-
-typedef struct {
-	uchar		type;
-	uchar		code;
-	ushort		checksum;
-	union {
-		struct {
-			ushort	id;
-			ushort	sequence;
-		} echo;
-		ulong	gateway;
-		struct {
-			ushort	__unused;
-			ushort	mtu;
-		} frag;
-	} un;
-} ICMP_t;
-
-
-/*
- * Maximum packet size; used to allocate packet storage.
- * TFTP packets can be 524 bytes + IP header + ethernet header.
- * Lets be conservative, and go for 38 * 16.  (Must also be
- * a multiple of 32 bytes).
- */
-/*
- * AS.HARNOIS : Better to set PKTSIZE to maximum size because
- * traffic type is not always controlled
- * maximum packet size =  1518
- * maximum packet size and multiple of 32 bytes =  1536
- */
-#define PKTSIZE			1518
-#define PKTSIZE_ALIGN		1536
-/*#define PKTSIZE		608*/
-
-/*
- * Maximum receive ring size; that is, the number of packets
- * we can buffer before overflow happens. Basically, this just
- * needs to be enough to prevent a packet being discarded while
- * we are processing the previous one.
- */
-#define RINGSZ		4
-#define RINGSZ_LOG2	2
-
-/**********************************************************************/
-/*
- *	Globals.
- *
- * Note:
- *
- * All variables of type IPaddr_t are stored in NETWORK byte order
- * (big endian).
- */
-
-/* net.c */
-/** BOOTP EXTENTIONS **/
-extern IPaddr_t		NetOurGatewayIP;	/* Our gateway IP addresse	*/
-extern IPaddr_t		NetOurSubnetMask;	/* Our subnet mask (0 = unknown)*/
-extern IPaddr_t		NetOurDNSIP;	 /* Our Domain Name Server (0 = unknown)*/
-extern IPaddr_t		NetOurDNS2IP;	 /* Our 2nd Domain Name Server (0 = unknown)*/
-extern char		NetOurNISDomain[32];	/* Our NIS domain		*/
-extern char		NetOurHostName[32];	/* Our hostname			*/
-extern char		NetOurRootPath[64];	/* Our root path		*/
-/** END OF BOOTP EXTENTIONS **/
-extern ulong		NetBootFileXferSize;	/* size of bootfile in bytes	*/
-extern uchar		NetOurEther[6];		/* Our ethernet address		*/
-extern uchar		NetServerEther[6];	/* Boot server enet address	*/
-extern IPaddr_t		NetOurIP;		/* Our    IP addr (0 = unknown)	*/
-extern IPaddr_t		NetServerIP;		/* Server IP addr (0 = unknown)	*/
-extern uchar * 		NetTxPacket;		/* THE transmit packet		*/
-extern uchar *		NetRxPackets[PKTBUFSRX];/* Receive packets		*/
-extern uchar *		NetRxPkt;		/* Current receive packet	*/
-extern int		NetRxPktLen;		/* Current rx packet length	*/
-extern unsigned		NetIPID;		/* IP ID (counting)		*/
-extern uchar		NetBcastAddr[6];	/* Ethernet boardcast address	*/
-extern uchar		NetEtherNullAddr[6];
-
-#define VLAN_NONE	4095			/* untagged 			*/
-#define VLAN_IDMASK	0x0fff			/* mask of valid vlan id 	*/
-extern ushort		NetOurVLAN;		/* Our VLAN 			*/
-extern ushort		NetOurNativeVLAN;	/* Our Native VLAN 		*/
-
-extern int		NetState;		/* Network loop state		*/
-
-/* ---------- Added by sha ------------ */
-extern IPaddr_t  NetArpWaitPacketIP;
-extern uchar            *NetArpWaitPacketMAC;
-extern uchar          *NetArpWaitTxPacket;     /* THE transmit packet                  */
-extern int             NetArpWaitTxPacketSize;
-extern int             NetArpWaitTry;
-extern uint64_t        NetArpWaitTimerStart;
-extern void ArpRequest (void);
-/* ------------------------------------ */
-
-#define NETLOOP_CONTINUE	1
-#define NETLOOP_SUCCESS		2
-#define NETLOOP_FAIL		3
-
-typedef enum { BOOTP, RARP, ARP, TFTP, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP } proto_t;
-
-/* Initialize the network adapter */
-int	NetLoopInit(proto_t);
-
-/* Do the work */
-int	NetLoop(void);
-
-/* Shutdown adapters and cleanup */
-void	NetStop(void);
-
-/* Load failed.	 Start again. */
-void	NetStartAgain(void);
-
-/* Get size of the ethernet header when we send */
-int 	NetEthHdrSize(void);
-
-/* Set ethernet header; returns the size of the header */
-int	NetSetEther(uchar *, uchar *, uint);
-
-/* Set IP header */
-void	NetSetIP(uchar *, IPaddr_t, int, int, int);
-
-/* Checksum */
-int	NetCksumOk(uchar *, int);	/* Return true if cksum OK	*/
-uint	NetCksum(uchar *, int);		/* Calculate the checksum	*/
-
-/* Set callbacks */
-void	NetSetHandler(rxhand_f *);	/* Set RX packet handler	*/
-void	NetSetTimeout(uint64_t, thand_f *);/* Set timeout handler		*/
-
-/* Transmit "NetTxPacket" */
-void	NetSendPacket(uchar *, int);
-
-/* Transmit UDP packet, performing ARP request if needed */
-int	NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len);
-
-/* Processes a received packet */
-void	NetReceive(uchar *, int);
-
-/* Print an IP address on the console */
-#ifdef CONFIG_NET
-void	print_IPaddr (IPaddr_t);
-#else
-#define print_IPaddr(IPaddr_t);
-#endif
-
-void netboot_update_env(void);
-
-/*
- * The following functions are a bit ugly, but necessary to deal with
- * alignment restrictions on ARM.
- *
- * We're using inline functions, which had the smallest memory
- * footprint in our tests.
- */
-/* return IP *in network byteorder* */
-static inline IPaddr_t NetReadIP(void *from)
-{
-	IPaddr_t ip;
-	memcpy((void*)&ip, from, sizeof(ip));
-	return ip;
-}
-
-/* return ulong *in network byteorder* */
-static inline ulong NetReadLong(ulong *from)
-{
-	ulong l;
-	memcpy((void*)&l, (void*)from, sizeof(l));
-	return l;
-}
-
-/* write IP *in network byteorder* */
-static inline void NetWriteIP(void *to, IPaddr_t ip)
-{
-	memcpy(to, (void*)&ip, sizeof(ip));
-}
-
-/* copy IP */
-static inline void NetCopyIP(void *to, void *from)
-{
-	memcpy(to, from, sizeof(IPaddr_t));
-}
-
-/* copy ulong */
-static inline void NetCopyLong(ulong *to, ulong *from)
-{
-	memcpy((void*)to, (void*)from, sizeof(ulong));
-}
-
-/* Convert an IP address to a string */
-char *	ip_to_string (IPaddr_t x, char *s);
-
-/* Convert a string to ip address */
-int string_to_ip(const char *s, IPaddr_t *ip);
-
-/* Convert a VLAN id to a string */
-void	VLAN_to_string (ushort x, char *s);
-
-/* Convert a string to a vlan id */
-ushort string_to_VLAN(const char *s);
-
-/* read an IP address from a environment variable */
-IPaddr_t getenv_IPaddr (char *);
-
-/* read a VLAN id from an environment variable */
-ushort getenv_VLAN(char *);
-
-int string_to_ethaddr(const char *str, char *enetaddr);
-void ethaddr_to_string(const unsigned char *enetaddr, char *str);
-
-/**********************************************************************/
-/* Network devices                                                    */
-/**********************************************************************/
-
-void eth_set_current(struct eth_device *eth);
-struct eth_device *eth_get_current(void);
-struct eth_device *eth_get_byname(char *name);
-
 /*
  *	Ethernet header
  */
@@ -578,8 +225,6 @@ static inline int net_eth_to_udplen(char *pkt)
 int net_checksum_ok(unsigned char *, int);	/* Return true if cksum OK	*/
 uint16_t net_checksum(unsigned char *, int);	/* Calculate the checksum	*/
 
-void NetReceive(unsigned char *, int);
-
 /* Print an IP address on the console */
 void print_IPaddr (IPaddr_t);
 
diff --git a/net/net.c b/net/net.c
index 6569b6f..1ae2fb4 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1,73 +1,31 @@
 /*
- *	Copied from Linux Monitor (LiMon) - Networking.
+ * net.c - barebox networking support
  *
- *	Copyright 1994 - 2000 Neil Russell.
- *	(See License)
- *	Copyright 2000 Roland Borde
- *	Copyright 2000 Paolo Scaffardi
- *	Copyright 2000-2002 Wolfgang Denk, wd at denx.de
- */
-
-/*
- * General Desription:
- *
- * The user interface supports commands for BOOTP, RARP, and TFTP.
- * Also, we support ARP internally. Depending on available data,
- * these interact as follows:
- *
- * BOOTP:
- *
- *	Prerequisites:	- own ethernet address
- *	We want:	- own IP address
- *			- TFTP server IP address
- *			- name of bootfile
- *	Next step:	ARP
- *
- * RARP:
- *
- *	Prerequisites:	- own ethernet address
- *	We want:	- own IP address
- *			- TFTP server IP address
- *	Next step:	ARP
- *
- * ARP:
- *
- *	Prerequisites:	- own ethernet address
- *			- own IP address
- *			- TFTP server IP address
- *	We want:	- TFTP server ethernet address
- *	Next step:	TFTP
+ * Copyright (c) 2010 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
  *
- * DHCP:
+ * based on U-Boot (LiMon) code
  *
- *     Prerequisites:	- own ethernet address
- *     We want:		- IP, Netmask, ServerIP, Gateway IP
- *			- bootfilename, lease time
- *     Next step:	- TFTP
+ * Copyright 1994 - 2000 Neil Russell.
+ * Copyright 2000 Roland Borde
+ * Copyright 2000 Paolo Scaffardi
+ * Copyright 2000-2002 Wolfgang Denk, wd at denx.de
  *
- * TFTP:
+ * See file CREDITS for list of people who contributed to this
+ * project.
  *
- *	Prerequisites:	- own ethernet address
- *			- own IP address
- *			- TFTP server IP address
- *			- TFTP server ethernet address
- *			- name of bootfile (if unknown, we use a default name
- *			  derived from our own IP address)
- *	We want:	- load the boot file
- *	Next step:	none
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
  *
- * NFS:
- *
- *	Prerequisites:	- own ethernet address
- *			- own IP address
- *			- name of bootfile (if unknown, we use a default name
- *			  derived from our own IP address)
- *	We want:	- load the boot file
- *	Next step:	none
+ * 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 <clock.h>
 #include <watchdog.h>
@@ -77,779 +35,58 @@
 #include <net.h>
 #include <driver.h>
 #include <errno.h>
+#include <malloc.h>
 #include <init.h>
 #include <linux/ctype.h>
 #include <linux/err.h>
-#include "tftp.h"
-#include "rarp.h"
-#include "nfs.h"
-
-#define ARP_TIMEOUT		(5 * SECOND)	/* Seconds before trying ARP again */
-#ifndef	CONFIG_NET_RETRY_COUNT
-# define ARP_TIMEOUT_COUNT	5		/* # of timeouts before giving up  */
-#else
-# define ARP_TIMEOUT_COUNT  (CONFIG_NET_RETRY_COUNT)
-#endif
-
-
-/** BOOTP EXTENTIONS **/
-
-IPaddr_t	NetOurSubnetMask=0;		/* Our subnet mask (0=unknown)	*/
-IPaddr_t	NetOurGatewayIP=0;		/* Our gateways IP address	*/
-IPaddr_t	NetOurDNSIP=0;			/* Our DNS IP address		*/
-#ifdef CONFIG_BOOTP_DNS2
-IPaddr_t	NetOurDNS2IP=0;			/* Our 2nd DNS IP address	*/
-#endif
-char		NetOurNISDomain[32]={0,};	/* Our NIS domain		*/
-char		NetOurHostName[32]={0,};	/* Our hostname			*/
-char		NetOurRootPath[64]={0,};	/* Our bootpath			*/
-
-/** END OF BOOTP EXTENTIONS **/
-
-ulong		NetBootFileXferSize;	/* The actual transferred size of the bootfile (in bytes) */
-uchar		NetOurEther[6];		/* Our ethernet address			*/
-uchar		NetServerEther[6] =	/* Boot server enet address		*/
-			{ 0, 0, 0, 0, 0, 0 };
-IPaddr_t	NetOurIP;		/* Our IP addr (0 = unknown)		*/
-IPaddr_t	NetServerIP;		/* Our IP addr (0 = unknown)		*/
-uchar *NetRxPkt;			/* Current receive packet		*/
-int		NetRxPktLen;		/* Current rx packet length		*/
-unsigned	NetIPID;		/* IP packet ID				*/
-uchar		NetBcastAddr[6] =	/* Ethernet bcast address		*/
-			{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
-uchar		NetEtherNullAddr[6] =
-			{ 0, 0, 0, 0, 0, 0 };
-int		NetState;		/* Network loop state			*/
-
-/* XXX in both little & big endian machines 0xFFFF == ntohs(-1) */
-ushort		NetOurVLAN = 0xFFFF;		/* default is without VLAN	*/
-ushort		NetOurNativeVLAN = 0xFFFF;	/* ditto			*/
-
-char		BootFile[128];		/* Boot File name			*/
-
-uchar	PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
-
-uchar *NetRxPackets[PKTBUFSRX]; /* Receive packets			*/
-
-static rxhand_f *packetHandler;		/* Current RX packet handler		*/
-static thand_f *timeHandler;		/* Current timeout handler		*/
-static uint64_t	timeStart;		/* Time base value			*/
-static uint64_t	timeDelta;		/* Current timeout value		*/
-uchar *NetTxPacket = 0;			/* THE transmit packet			*/
-
-static int net_check_prereq (proto_t protocol);
-
-/**********************************************************************/
-
-IPaddr_t	NetArpWaitPacketIP;
-IPaddr_t	NetArpWaitReplyIP;
-uchar	       *NetArpWaitPacketMAC;	/* MAC address of waiting packet's destination	*/
-uchar	       *NetArpWaitTxPacket;	/* THE transmit packet			*/
-int		NetArpWaitTxPacketSize;
-uchar 		NetArpWaitPacketBuf[PKTSIZE_ALIGN + PKTALIGN];
-uint64_t	NetArpWaitTimerStart;
-
-void ArpRequest (void)
-{
-	int i;
-	uchar *pkt;
-	ARP_t *arp;
-
-	pr_debug("ARP broadcast\n");
-
-	pkt = NetTxPacket;
-
-	pkt += NetSetEther (pkt, NetBcastAddr, PROT_ARP);
-
-	arp = (ARP_t *) pkt;
-
-	arp->ar_hrd = htons (ARP_ETHER);
-	arp->ar_pro = htons (PROT_IP);
-	arp->ar_hln = 6;
-	arp->ar_pln = 4;
-	arp->ar_op = htons (ARPOP_REQUEST);
-
-	memcpy (&arp->ar_data[0], NetOurEther, 6);		/* source ET addr	*/
-	NetWriteIP ((uchar *) & arp->ar_data[6], NetOurIP);	/* source IP addr	*/
-	for (i = 10; i < 16; ++i) {
-		arp->ar_data[i] = 0;				/* dest ET addr = 0     */
-	}
-
-	if ((NetArpWaitPacketIP & NetOurSubnetMask) !=
-	    (NetOurIP & NetOurSubnetMask)) {
-		if (NetOurGatewayIP == 0) {
-			puts ("## Warning: gatewayip needed but not set\n");
-			NetArpWaitReplyIP = NetArpWaitPacketIP;
-		} else {
-			NetArpWaitReplyIP = NetOurGatewayIP;
-		}
-	} else {
-		NetArpWaitReplyIP = NetArpWaitPacketIP;
-	}
-
-	NetWriteIP ((uchar *) & arp->ar_data[16], NetArpWaitReplyIP);
-	(void) eth_send (NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
-}
-
-/**********************************************************************/
-/*
- *	Main network processing loop.
- */
-
-int NetLoopInit(proto_t protocol)
-{
-	struct eth_device *eth_current = eth_get_current();
-	IPaddr_t ip;
-	int ret;
-	int	i;
-
-	if (!eth_current) {
-		printf("Current ethernet device not set!\n");
-		return -1;
-	}
-
-	ip = dev_get_param_ip(&eth_current->dev, "ipaddr");
-	NetCopyIP(&NetOurIP, &ip);
-
-	/* XXX problem with bss workaround */
-	NetArpWaitPacketMAC = NULL;
-	NetArpWaitTxPacket = NULL;
-	NetArpWaitPacketIP = 0;
-	NetArpWaitReplyIP = 0;
-
-	/*
-	 *	Setup packet buffers, aligned correctly.
-	 */
-	NetTxPacket = &PktBuf[0] + (PKTALIGN - 1);
-	NetTxPacket -= (ulong)NetTxPacket % PKTALIGN;
-	for (i = 0; i < PKTBUFSRX; i++) {
-		NetRxPackets[i] = NetTxPacket + (i+1)*PKTSIZE_ALIGN;
-	}
-
-	NetArpWaitTxPacket = &NetArpWaitPacketBuf[0] + (PKTALIGN - 1);
-	NetArpWaitTxPacket -= (ulong)NetArpWaitTxPacket % PKTALIGN;
-	NetArpWaitTxPacketSize = 0;
-
-	string_to_ethaddr(dev_get_param(&eth_get_current()->dev, "ethaddr"),
-			NetOurEther);
-
-	NetState = NETLOOP_CONTINUE;
-
-	NetOurGatewayIP = dev_get_param_ip(&eth_current->dev, "gateway");
-	NetOurSubnetMask = dev_get_param_ip(&eth_current->dev, "netmask");
-	NetOurVLAN = getenv_VLAN("vlan");
-	NetOurNativeVLAN = getenv_VLAN("nvlan");
-	NetServerIP = dev_get_param_ip(&eth_current->dev, "serverip");
-
-	ret = net_check_prereq(protocol);
-
-	return ret;
-}
-
-int NetLoop(void)
-{
-	/*
-	 *	Start the ball rolling with the given start function.  From
-	 *	here on, this code is a state machine driven by received
-	 *	packets and timer events.
-	 */
-
-	NetBootFileXferSize = 0;
-
-	/*
-	 *	Main packet reception loop.  Loop receiving packets until
-	 *	someone sets `NetState' to a state that terminates.
-	 */
-	for (;;) {
-		WATCHDOG_RESET();
-#ifdef CONFIG_SHOW_ACTIVITY
-		{
-			extern void show_activity(int arg);
-			show_activity(1);
-		}
-#endif
-		/*
-		 *	Check the ethernet for a new packet.  The ethernet
-		 *	receive routine will process it.
-		 */
-		eth_rx();
-
-		/*
-		 *	Abort if ctrl-c was pressed.
-		 */
-		if (ctrlc()) {
-			puts ("\nAbort\n");
-			return -1;
-		}
-
-		/* check for arp timeout */
-		if (NetArpWaitPacketIP &&
-				is_timeout(NetArpWaitTimerStart, ARP_TIMEOUT)) {
-			NetArpWaitTimerStart = get_time_ns();
-			ArpRequest();
-		}
-
-		/*
-		 *	Check for a timeout, and run the timeout handler
-		 *	if we have one.
-		 */
-		if (timeHandler && is_timeout(timeStart, timeDelta)) {
-			thand_f *x;
-			x = timeHandler;
-			timeHandler = (thand_f *)0;
-			(*x)();
-		}
-
 
-		switch (NetState) {
-		case NETLOOP_SUCCESS:
-			if (NetBootFileXferSize > 0) {
-				char buf[10];
-				printf("Bytes transferred = %ld (%lx hex)\n",
-					NetBootFileXferSize,
-					NetBootFileXferSize);
-				sprintf(buf, "0x%lx", NetBootFileXferSize);
-				setenv("filesize", buf);
-			}
-			return NetBootFileXferSize;
-
-		case NETLOOP_FAIL:
-			return -1;
-		}
-	}
-}
-
-/**********************************************************************/
-/*
- *	Miscelaneous bits.
- */
-
-void
-NetSetHandler(rxhand_f * f)
-{
-	packetHandler = f;
-}
-
-
-void
-NetSetTimeout(uint64_t iv, thand_f * f)
-{
-	if (iv == 0) {
-		timeHandler = (thand_f *)0;
-	} else {
-		timeHandler = f;
-		timeStart = get_time_ns();
-		timeDelta = iv;
-	}
-}
-
-
-void
-NetSendPacket(uchar * pkt, int len)
-{
-	(void) eth_send(pkt, len);
-}
-
-int
-NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
-{
-	uchar *pkt;
-
-	/* convert to new style broadcast */
-	if (dest == 0)
-		dest = 0xFFFFFFFF;
-
-	/* if broadcast, make the ether address a broadcast and don't do ARP */
-	if (dest == 0xFFFFFFFF)
-		ether = NetBcastAddr;
-
-	/* if MAC address was not discovered yet, save the packet and do an ARP request */
-	if (memcmp(ether, NetEtherNullAddr, 6) == 0) {
-		pr_debug("sending ARP for %08lx\n", dest);
-
-		NetArpWaitPacketIP = dest;
-		NetArpWaitPacketMAC = ether;
-
-		pkt = NetArpWaitTxPacket;
-		pkt += NetSetEther (pkt, NetArpWaitPacketMAC, PROT_IP);
-
-		NetSetIP (pkt, dest, dport, sport, len);
-		memcpy(pkt + IP_HDR_SIZE, (uchar *)NetTxPacket + (pkt - (uchar *)NetArpWaitTxPacket) + IP_HDR_SIZE, len);
-
-		/* size of the waiting packet */
-		NetArpWaitTxPacketSize = (pkt - NetArpWaitTxPacket) + IP_HDR_SIZE + len;
-
-		/* and do the ARP request */
-		NetArpWaitTimerStart = get_time_ns();
-		ArpRequest();
-		return 1;	/* waiting */
-	}
-
-	pr_debug("sending UDP to %08lx/%02x:%02x:%02x:%02x:%02x:%02x\n",
-		dest, ether[0], ether[1], ether[2], ether[3], ether[4], ether[5]);
+static IPaddr_t	net_netmask;		/* Our subnet mask (0=unknown)	*/
+static IPaddr_t	net_gateway;		/* Our gateways IP address	*/
+static IPaddr_t	net_dns_server;		/* Our DNS IP address		*/
 
-	pkt = (uchar *)NetTxPacket;
-	pkt += NetSetEther (pkt, ether, PROT_IP);
-	NetSetIP (pkt, dest, dport, sport, len);
-	(void) eth_send(NetTxPacket, (pkt - NetTxPacket) + IP_HDR_SIZE + len);
+static unsigned char net_ether[6];	/* Our ethernet address		*/
+static IPaddr_t	net_ip;			/* Our IP addr (0 = unknown)	*/
+static IPaddr_t	net_serverip;		/* Our IP addr (0 = unknown)	*/
 
-	return 0;	/* transmitted */
-}
+unsigned char *NetRxPackets[PKTBUFSRX]; /* Receive packets		*/
+static unsigned int net_ip_id;
 
-void
-NetReceive(uchar * inpkt, int len)
+void net_update_env(void)
 {
-	Ethernet_t *et;
-	IP_t	*ip;
-	ARP_t	*arp;
-	IPaddr_t tmp;
-	int	x;
-	uchar *pkt;
-	ushort cti = 0, vlanid = VLAN_NONE, myvlanid, mynvlanid;
-
-	pr_debug("packet received\n");
-
-	if (!net_receive(inpkt, len))
-		return;
-
-	NetRxPkt = inpkt;
-	NetRxPktLen = len;
-	et = (Ethernet_t *)inpkt;
-
-	/* too small packet? */
-	if (len < ETHER_HDR_SIZE)
-		return;
-
-	myvlanid = ntohs(NetOurVLAN);
-	if (myvlanid == (ushort)-1)
-		myvlanid = VLAN_NONE;
-	mynvlanid = ntohs(NetOurNativeVLAN);
-	if (mynvlanid == (ushort)-1)
-		mynvlanid = VLAN_NONE;
-
-	x = ntohs(et->et_protlen);
-
-	pr_debug("packet received\n");
-
-	if (x < 1514) {
-		/*
-		 *	Got a 802 packet.  Check the other protocol field.
-		 */
-		x = ntohs(et->et_prot);
-
-		ip = (IP_t *)(inpkt + E802_HDR_SIZE);
-		len -= E802_HDR_SIZE;
-
-	} else if (x != PROT_VLAN) {	/* normal packet */
-		ip = (IP_t *)(inpkt + ETHER_HDR_SIZE);
-		len -= ETHER_HDR_SIZE;
-
-	} else {			/* VLAN packet */
-		VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)et;
-
-		pr_debug("VLAN packet received\n");
-
-		/* too small packet? */
-		if (len < VLAN_ETHER_HDR_SIZE)
-			return;
-
-		/* if no VLAN active */
-		if ((ntohs(NetOurVLAN) & VLAN_IDMASK) == VLAN_NONE
-				)
-			return;
-
-		cti = ntohs(vet->vet_tag);
-		vlanid = cti & VLAN_IDMASK;
-		x = ntohs(vet->vet_type);
-
-		ip = (IP_t *)(inpkt + VLAN_ETHER_HDR_SIZE);
-		len -= VLAN_ETHER_HDR_SIZE;
-	}
-
-	pr_debug("Receive from protocol 0x%x\n", x);
-
-	if ((myvlanid & VLAN_IDMASK) != VLAN_NONE) {
-		if (vlanid == VLAN_NONE)
-			vlanid = (mynvlanid & VLAN_IDMASK);
-		/* not matched? */
-		if (vlanid != (myvlanid & VLAN_IDMASK))
-			return;
-	}
-
-	switch (x) {
-
-	case PROT_ARP:
-		/*
-		 * We have to deal with two types of ARP packets:
-		 * - REQUEST packets will be answered by sending  our
-		 *   IP address - if we know it.
-		 * - REPLY packets are expected only after we asked
-		 *   for the TFTP server's or the gateway's ethernet
-		 *   address; so if we receive such a packet, we set
-		 *   the server ethernet address
-		 */
-		pr_debug("Got ARP\n");
-
-		arp = (ARP_t *)ip;
-		if (len < ARP_HDR_SIZE) {
-			printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
-			return;
-		}
-		if (ntohs(arp->ar_hrd) != ARP_ETHER) {
-			return;
-		}
-		if (ntohs(arp->ar_pro) != PROT_IP) {
-			return;
-		}
-		if (arp->ar_hln != 6) {
-			return;
-		}
-		if (arp->ar_pln != 4) {
-			return;
-		}
-
-		if (NetOurIP == 0) {
-			return;
-		}
-
-		if (NetReadIP(&arp->ar_data[16]) != NetOurIP) {
-			return;
-		}
-
-		switch (ntohs(arp->ar_op)) {
-		case ARPOP_REQUEST:		/* reply with our IP address	*/
-			pr_debug("Got ARP REQUEST, return our IP\n");
-
-			pkt = (uchar *)et;
-			pkt += NetSetEther(pkt, et->et_src, PROT_ARP);
-			arp->ar_op = htons(ARPOP_REPLY);
-			memcpy   (&arp->ar_data[10], &arp->ar_data[0], 6);
-			NetCopyIP(&arp->ar_data[16], &arp->ar_data[6]);
-			memcpy   (&arp->ar_data[ 0], NetOurEther, 6);
-			NetCopyIP(&arp->ar_data[ 6], &NetOurIP);
-			memcpy(NetTxPacket, et, (pkt - (uchar *)et) + ARP_HDR_SIZE);
-			eth_send((uchar *)NetTxPacket, (pkt - (uchar *)et) + ARP_HDR_SIZE);
-			return;
-
-		case ARPOP_REPLY:		/* arp reply */
-			/* are we waiting for a reply */
-			if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)
-				break;
-			pr_debug("Got ARP REPLY, set server/gtwy eth addr (%02x:%02x:%02x:%02x:%02x:%02x)\n",
-				arp->ar_data[0], arp->ar_data[1],
-				arp->ar_data[2], arp->ar_data[3],
-				arp->ar_data[4], arp->ar_data[5]);
-
-			tmp = NetReadIP(&arp->ar_data[6]);
-
-			/* matched waiting packet's address */
-			if (tmp == NetArpWaitReplyIP) {
-				pr_debug("Got it\n");
-
-				/* save address for later use */
-				memcpy(NetArpWaitPacketMAC, &arp->ar_data[0], 6);
-
-				/* modify header, and transmit it */
-				memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, NetArpWaitPacketMAC, 6);
-				(void) eth_send(NetArpWaitTxPacket, NetArpWaitTxPacketSize);
-
-				/* no arp request pending now */
-				NetArpWaitPacketIP = 0;
-				NetArpWaitTxPacketSize = 0;
-				NetArpWaitPacketMAC = NULL;
-
-			}
-			return;
-		default:
-			pr_debug("Unexpected ARP opcode 0x%x\n", ntohs(arp->ar_op));
-			return;
-		}
-		break;
-
-	case PROT_RARP:
-		pr_debug("Got RARP\n");
-
-		arp = (ARP_t *)ip;
-		if (len < ARP_HDR_SIZE) {
-			printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
-			return;
-		}
-
-		if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
-			(ntohs(arp->ar_hrd) != ARP_ETHER)   ||
-			(ntohs(arp->ar_pro) != PROT_IP)     ||
-			(arp->ar_hln != 6) || (arp->ar_pln != 4)) {
-
-			puts ("invalid RARP header\n");
-		} else {
-			NetCopyIP(&NetOurIP,    &arp->ar_data[16]);
-			if (NetServerIP == 0)
-				NetCopyIP(&NetServerIP, &arp->ar_data[ 6]);
-			memcpy (NetServerEther, &arp->ar_data[ 0], 6);
-
-			if (packetHandler)
-				(*packetHandler)(0,0,0,0);
-		}
-		break;
-
-	case PROT_IP:
-		pr_debug("Got IP\n");
-
-		if (len < IP_HDR_SIZE) {
-			debug ("len bad %d < %d\n", len, IP_HDR_SIZE);
-			return;
-		}
-		if (len < ntohs(ip->ip_len)) {
-			printf("len bad %d < %d\n", len, ntohs(ip->ip_len));
-			return;
-		}
-		len = ntohs(ip->ip_len);
-
-		pr_debug("len=%d, v=%02x\n", len, ip->ip_hl_v & 0xff);
+	struct eth_device *edev = eth_get_current();
 
-		if ((ip->ip_hl_v & 0xf0) != 0x40) {
-			return;
-		}
-		if (ip->ip_off & htons(0x1fff)) { /* Can't deal w/ fragments */
-			return;
-		}
-		if (!NetCksumOk((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2)) {
-			puts ("checksum bad\n");
-			return;
-		}
-		tmp = NetReadIP(&ip->ip_dst);
-		if (NetOurIP && tmp != NetOurIP && tmp != 0xFFFFFFFF) {
-			return;
-		}
-		/*
-		 * watch for ICMP host redirects
-		 *
-		 * There is no real handler code (yet). We just watch
-		 * for ICMP host redirect messages. In case anybody
-		 * sees these messages: please contact me
-		 * (wd at denx.de), or - even better - send me the
-		 * necessary fixes :-)
-		 *
-		 * Note: in all cases where I have seen this so far
-		 * it was a problem with the router configuration,
-		 * for instance when a router was configured in the
-		 * BOOTP reply, but the TFTP server was on the same
-		 * subnet. So this is probably a warning that your
-		 * configuration might be wrong. But I'm not really
-		 * sure if there aren't any other situations.
-		 */
-		if (ip->ip_p == IPPROTO_ICMP) {
-			ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);
-
-			switch (icmph->type) {
-			case ICMP_REDIRECT:
-				if (icmph->code != ICMP_REDIR_HOST)
-					return;
-				puts (" ICMP Host Redirect to ");
-				print_IPaddr(icmph->un.gateway);
-				putchar(' ');
-				return;
-#ifdef CONFIG_NET_PING
-			case ICMP_ECHO_REPLY:
-				/*
-				 *	IP header OK.  Pass the packet to the current handler.
-				 */
-				/* XXX point to ip packet */
-				if (packetHandler)
-					(*packetHandler)((uchar *)ip, 0, 0, 0);
-				return;
-#endif
-			default:
-				return;
-			}
-		} else if (ip->ip_p != IPPROTO_UDP) {	/* Only UDP packets */
-			return;
-		}
+	net_ip = dev_get_param_ip(&edev->dev, "ipaddr");
+	net_serverip = dev_get_param_ip(&edev->dev, "serverip");
+	net_gateway = dev_get_param_ip(&edev->dev, "gateway");
+	net_netmask = dev_get_param_ip(&edev->dev, "netmask");
 
-#ifdef CONFIG_UDP_CHECKSUM
-		if (ip->udp_xsum != 0) {
-			ulong   xsum;
-			ushort *sumptr;
-			ushort  sumlen;
-
-			xsum  = ip->ip_p;
-			xsum += (ntohs(ip->udp_len));
-			xsum += (ntohl(ip->ip_src) >> 16) & 0x0000ffff;
-			xsum += (ntohl(ip->ip_src) >>  0) & 0x0000ffff;
-			xsum += (ntohl(ip->ip_dst) >> 16) & 0x0000ffff;
-			xsum += (ntohl(ip->ip_dst) >>  0) & 0x0000ffff;
-
-			sumlen = ntohs(ip->udp_len);
-			sumptr = (ushort *) &(ip->udp_src);
-
-			while (sumlen > 1) {
-				ushort sumdata;
-
-				sumdata = *sumptr++;
-				xsum += ntohs(sumdata);
-				sumlen -= 2;
-			}
-			if (sumlen > 0) {
-				ushort sumdata;
-
-				sumdata = *(unsigned char *) sumptr;
-				sumdata = (sumdata << 8) & 0xff00;
-				xsum += sumdata;
-			}
-			while ((xsum >> 16) != 0) {
-				xsum = (xsum & 0x0000ffff) + ((xsum >> 16) & 0x0000ffff);
-			}
-			if ((xsum != 0x00000000) && (xsum != 0x0000ffff)) {
-				printf(" UDP wrong checksum %08x %08x\n", xsum, ntohs(ip->udp_xsum));
-				return;
-			}
-		}
-#endif
-		/*
-		 *	IP header OK.  Pass the packet to the current handler.
-		 */
-		if (packetHandler)
-			(*packetHandler)((uchar *)ip +IP_HDR_SIZE,
-						ntohs(ip->udp_dst),
-						ntohs(ip->udp_src),
-						ntohs(ip->udp_len) - 8);
-		break;
-	}
+	string_to_ethaddr(dev_get_param(&edev->dev, "ethaddr"),
+			net_ether);
 }
 
-
-/**********************************************************************/
-
-static int net_check_prereq (proto_t protocol)
+int net_checksum_ok(unsigned char *ptr, int len)
 {
-	struct eth_device *edev = eth_get_current();
-
-	switch (protocol) {
-		/* Fall through */
-#ifdef CONFIG_NET_NFS
-	case NFS:
-#endif
-	case NETCONS:
-	case TFTP:
-		if (NetServerIP == 0) {
-			printf("*** ERROR: `%s.serverip' not set\n", dev_id(&edev->dev));
-			return -1;
-		}
-
-		if (NetOurIP == 0) {
-			printf("*** ERROR: `%s.ipaddr' not set\n", dev_id(&edev->dev));
-			return -1;
-		}
-		/* Fall through */
-
-	case DHCP:
-	case RARP:
-	case BOOTP:
-		if (memcmp (NetOurEther, "\0\0\0\0\0\0", 6) == 0) {
-			printf("*** ERROR: `%s.ethaddr' not set\n", dev_id(&edev->dev));
-			return -1;
-		}
-		/* Fall through */
-	default:
-		return 0;
-	}
-
-	return -1; /* not reached */
+	return net_checksum(ptr, len) + 1;
 }
-/**********************************************************************/
 
-int
-NetCksumOk(uchar * ptr, int len)
+uint16_t net_checksum(unsigned char *ptr, int len)
 {
-	return !((NetCksum(ptr, len) + 1) & 0xfffe);
-}
+	uint32_t xsum = 0;
+	uint16_t *p = (uint16_t *)ptr;
 
+	if (len & 1)
+		ptr[len] = 0;
 
-unsigned
-NetCksum(uchar * ptr, int len)
-{
-	ulong	xsum;
-	ushort *p = (ushort *)ptr;
+	len = (len + 1) >> 1;
 
-	xsum = 0;
 	while (len-- > 0)
 		xsum += *p++;
+
 	xsum = (xsum & 0xffff) + (xsum >> 16);
 	xsum = (xsum & 0xffff) + (xsum >> 16);
 	return xsum & 0xffff;
 }
 
-int
-NetEthHdrSize(void)
-{
-	ushort myvlanid;
-
-	myvlanid = ntohs(NetOurVLAN);
-	if (myvlanid == (ushort)-1)
-		myvlanid = VLAN_NONE;
-
-	return ((myvlanid & VLAN_IDMASK) == VLAN_NONE) ? ETHER_HDR_SIZE : VLAN_ETHER_HDR_SIZE;
-}
-
-int
-NetSetEther(uchar * xet, uchar * addr, uint prot)
-{
-	Ethernet_t *et = (Ethernet_t *)xet;
-	ushort myvlanid;
-
-	myvlanid = ntohs(NetOurVLAN);
-	if (myvlanid == (ushort)-1)
-		myvlanid = VLAN_NONE;
-
-	memcpy (et->et_dest, addr, 6);
-	memcpy (et->et_src, NetOurEther, 6);
-	if ((myvlanid & VLAN_IDMASK) == VLAN_NONE) {
-	et->et_protlen = htons(prot);
-		return ETHER_HDR_SIZE;
-	} else {
-		VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)xet;
-
-		vet->vet_vlan_type = htons(PROT_VLAN);
-		vet->vet_tag = htons((0 << 5) | (myvlanid & VLAN_IDMASK));
-		vet->vet_type = htons(prot);
-		return VLAN_ETHER_HDR_SIZE;
-	}
-}
-
-void
-NetSetIP(uchar * xip, IPaddr_t dest, int dport, int sport, int len)
-{
-	IP_t *ip = (IP_t *)xip;
-
-	/*
-	 *	If the data is an odd number of bytes, zero the
-	 *	byte after the last byte so that the checksum
-	 *	will work.
-	 */
-	if (len & 1)
-		xip[IP_HDR_SIZE + len] = 0;
-
-	/*
-	 *	Construct an IP and UDP header.
-	 *	(need to set no fragment bit - XXX)
-	 */
-	ip->ip_hl_v  = 0x45;		/* IP_HDR_SIZE / 4 (not including UDP) */
-	ip->ip_tos   = 0;
-	ip->ip_len   = htons(IP_HDR_SIZE + len);
-	ip->ip_id    = htons(NetIPID++);
-	ip->ip_off   = htons(0x4000);	/* No fragmentation */
-	ip->ip_ttl   = 255;
-	ip->ip_p     = 17;		/* UDP */
-	ip->ip_sum   = 0;
-	NetCopyIP((void*)&ip->ip_src, &NetOurIP); /* already in network byte order */
-	NetCopyIP((void*)&ip->ip_dst, &dest);	   /* - "" - */
-	ip->udp_src  = htons(sport);
-	ip->udp_dst  = htons(dport);
-	ip->udp_len  = htons(8 + len);
-	ip->udp_xsum = 0;
-	ip->ip_sum   = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
-}
-
 char *ip_to_string (IPaddr_t x, char *s)
 {
 	x = ntohl (x);
@@ -871,7 +108,7 @@ int string_to_ip(const char *s, IPaddr_t *ip)
 		return -EINVAL;
 
 	for (i = 0; i < 4; i++) {
-		ulong val;
+		unsigned long val;
 
 		if (!isdigit(*s))
 			return -EINVAL;
@@ -890,34 +127,6 @@ int string_to_ip(const char *s, IPaddr_t *ip)
 	return 0;
 }
 
-void VLAN_to_string(ushort x, char *s)
-{
-	x = ntohs(x);
-
-	if (x == (ushort)-1)
-		x = VLAN_NONE;
-
-	if (x == VLAN_NONE)
-		strcpy(s, "none");
-	else
-		sprintf(s, "%d", x & VLAN_IDMASK);
-}
-
-ushort string_to_VLAN(const char *s)
-{
-	ushort id;
-
-	if (s == NULL)
-		return htons(VLAN_NONE);
-
-	if (*s < '0' || *s > '9')
-		id = VLAN_NONE;
-	else
-		id = (ushort)simple_strtoul(s, NULL, 10);
-
-	return htons(id);
-}
-
 void print_IPaddr (IPaddr_t x)
 {
 	char tmp[16];
@@ -927,14 +136,9 @@ void print_IPaddr (IPaddr_t x)
 	puts (tmp);
 }
 
-ushort getenv_VLAN(char *var)
-{
-	return string_to_VLAN(getenv(var));
-}
-
 int string_to_ethaddr(const char *str, char *enetaddr)
 {
-	ulong reg;
+	int reg;
 	char *e;
 
         if (!str || strlen(str) != 17)
@@ -954,66 +158,11 @@ int string_to_ethaddr(const char *str, char *enetaddr)
 
 void ethaddr_to_string(const unsigned char *enetaddr, char *str)
 {
-	sprintf (str, "%02X:%02X:%02X:%02X:%02X:%02X",
+	sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X",
 		 enetaddr[0], enetaddr[1], enetaddr[2], enetaddr[3],
 		 enetaddr[4], enetaddr[5]);
 }
 
-static IPaddr_t	net_netmask;		/* Our subnet mask (0=unknown)	*/
-static IPaddr_t	net_gateway;		/* Our gateways IP address	*/
-static IPaddr_t	net_dns_server;		/* Our DNS IP address		*/
-
-static unsigned char net_ether[6];	/* Our ethernet address		*/
-static IPaddr_t	net_ip;			/* Our IP addr (0 = unknown)	*/
-static IPaddr_t	net_serverip;		/* Our IP addr (0 = unknown)	*/
-
-unsigned char *NetRxPackets[PKTBUFSRX]; /* Receive packets		*/
-static unsigned int net_ip_id;
-
-void net_update_env(void)
-{
-	struct eth_device *edev = eth_get_current();
-
-	net_ip = dev_get_param_ip(&edev->dev, "ipaddr");
-	net_serverip = dev_get_param_ip(&edev->dev, "serverip");
-	net_gateway = dev_get_param_ip(&edev->dev, "gateway");
-	net_netmask = dev_get_param_ip(&edev->dev, "netmask");
-
-	string_to_ethaddr(dev_get_param(&edev->dev, "ethaddr"),
-			net_ether);
-
-	NetOurIP = dev_get_param_ip(&edev->dev, "ipaddr");
-	NetServerIP = dev_get_param_ip(&edev->dev, "serverip");
-	NetOurGatewayIP = dev_get_param_ip(&edev->dev, "gateway");
-	NetOurSubnetMask = dev_get_param_ip(&edev->dev, "netmask");
-
-	string_to_ethaddr(dev_get_param(&edev->dev, "ethaddr"),
-			NetOurEther);
-}
-
-int net_checksum_ok(unsigned char *ptr, int len)
-{
-	return net_checksum(ptr, len) + 1;
-}
-
-uint16_t net_checksum(unsigned char *ptr, int len)
-{
-	uint32_t xsum = 0;
-	uint16_t *p = (uint16_t *)ptr;
-
-	if (len & 1)
-		ptr[len] = 0;
-
-	len = (len + 1) >> 1;
-
-	while (len-- > 0)
-		xsum += *p++;
-
-	xsum = (xsum & 0xffff) + (xsum >> 16);
-	xsum = (xsum & 0xffff) + (xsum >> 16);
-	return xsum & 0xffff;
-}
-
 static unsigned char *arp_ether;
 static IPaddr_t arp_wait_ip;
 
-- 
1.7.1



From T.Gamez at phytec.de  Tue Jun  8 06:03:02 2010
From: T.Gamez at phytec.de (Teresa Gamez)
Date: Tue, 08 Jun 2010 12:03:02 +0200
Subject: [PATCH] mx2 GPIO OCRx register
Message-ID: <1275991382.18173.37.camel@lws-gamez>

The GPIO OCRx register has to be set correct or the output is not set as expected.

Signed-off-by: Teresa G?mez <T.Gamez at phytec.de> 
---
Index: barebox-2010.06.0/arch/arm/mach-imx/gpio.c
===================================================================
--- barebox-2010.06.0/arch/arm/mach-imx/gpio.c	2010-06-02 10:36:28.000000000 +0200
+++ barebox-2010.06.0/arch/arm/mach-imx/gpio.c	2010-06-08 11:02:31.282473877 +0200
@@ -31,6 +31,8 @@
 #if defined CONFIG_ARCH_IMX1 || defined CONFIG_ARCH_IMX21 || defined CONFIG_ARCH_IMX27
 #define GPIO_DR		0x1c
 #define GPIO_GDIR	0x00
+#define GPIO_OCR1	0x04
+#define GPIO_OCR2	0x08
 #define GPIO_PSR	0x24
 #define GPIO_ICR1	0x28
 #define GPIO_ICR2	0x2C
@@ -103,6 +105,18 @@
 	if (!base)
 		return -EINVAL;
 
+#if defined GPIO_OCR1 && defined GPIO_OCR2
+	if (shift < 16) {
+		val = readl(base + GPIO_OCR1);
+		val |= (3 << (shift * 2));
+		writel(val, base + GPIO_OCR1);
+	} else {
+		val = readl(base + GPIO_OCR2);
+		val |= (3 << ((shift - 16) * 2));
+		writel(val, base + GPIO_OCR2);
+	}
+#endif
+
 	gpio_set_value(gpio, value);
 
 	val = readl(base + GPIO_GDIR);



From baruch at tkos.co.il  Tue Jun  8 14:36:04 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Tue,  8 Jun 2010 21:36:04 +0300
Subject: [PATCH] i2c: fix adapter_list manipulation
Message-ID: <471ada329c4028bfda67cfa2bca1e131aed6ae0e.1276022070.git.baruch@tkos.co.il>

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 drivers/i2c/i2c.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 1fa114a..87360f3 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -365,7 +365,7 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
 	if (i2c_get_adapter(adapter->nr))
 		return -EBUSY;
 
-	list_add_tail(&adapter_list, &adapter->list);
+	list_add_tail(&adapter->list, &adapter_list);
 
 	/* populate children from any i2c device tables */
 	scan_boardinfo(adapter);
-- 
1.7.1



From baruch at tkos.co.il  Wed Jun  9 03:05:01 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Wed,  9 Jun 2010 10:05:01 +0300
Subject: [PATCH 2/8] mx25: fix typo in imx25-regs.h
In-Reply-To: <cover.1276065824.git.baruch@tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
Message-ID: <ece2125da175783e1fe89d56996f1cd6e4542ec9.1276065824.git.baruch@tkos.co.il>

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 arch/arm/mach-imx/include/mach/imx25-regs.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/arm/mach-imx/include/mach/imx25-regs.h b/arch/arm/mach-imx/include/mach/imx25-regs.h
index 556ffb0..8052125 100644
--- a/arch/arm/mach-imx/include/mach/imx25-regs.h
+++ b/arch/arm/mach-imx/include/mach/imx25-regs.h
@@ -21,7 +21,7 @@
  */
 
 #ifndef __ASM_ARCH_MX25_REGS_H
-#define __ASM_ARCH_MX35_REGS_H
+#define __ASM_ARCH_MX25_REGS_H
 
 /*
  * sanity check
-- 
1.7.1



From baruch at tkos.co.il  Wed Jun  9 03:05:00 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Wed,  9 Jun 2010 10:05:00 +0300
Subject: [PATCH 1/8] mx25 3ds: fix build failure
In-Reply-To: <cover.1276065824.git.baruch@tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
Message-ID: <d6ab8b960d4e16db3eb43418354bb4bc2a06f8bf.1276065824.git.baruch@tkos.co.il>

Remove redundant parameters from the imx_nand_load_image() call.

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 board/freescale-mx25-3-stack/3stack.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/board/freescale-mx25-3-stack/3stack.c b/board/freescale-mx25-3-stack/3stack.c
index f5316bf..6659185 100644
--- a/board/freescale-mx25-3-stack/3stack.c
+++ b/board/freescale-mx25-3-stack/3stack.c
@@ -320,7 +320,7 @@ console_initcall(imx25_console_init);
 #ifdef CONFIG_NAND_IMX_BOOT
 void __bare_init nand_boot(void)
 {
-	imx_nand_load_image((void *)TEXT_BASE, 256 * 1024, 2048, 16384);
+	imx_nand_load_image((void *)TEXT_BASE, 256 * 1024);
 }
 #endif
 
-- 
1.7.1



From baruch at tkos.co.il  Wed Jun  9 03:04:59 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Wed,  9 Jun 2010 10:04:59 +0300
Subject: [PATCH 0/8] i.MX25 3DS fixes and enhancements
Message-ID: <cover.1276065824.git.baruch@tkos.co.il>

This series of patches includes the following:

1. Fixes and clean-ups for the i.MX25 3DS board code
2. New driver for the i.MX25 3DS on-board PMIC
3. Enable proper FEC initialization including PHY power supply enable
4. Add support for boot from UART on the i.MX25 3DS

Note that currently there is no watchdog service routine. Since the UART boot 
mode enables the watchdog, this means that you can only have Barebox running 
for 90 seconds before the watchdog resets the CPU.

Baruch Siach (8):
  mx25 3ds: fix build failure
  mx25: fix typo in imx25-regs.h
  mx25 3ds: cleanup lowlevel_init code
  mx25: add support for i2c
  i2c: add driver for the MC34704 PMIC
  mx25 3ds: add support for i2c master and PMIC
  mx25 3ds: fix fec initialization
  mx25 3ds: add support for boot from UART

 arch/arm/mach-imx/Kconfig                    |    5 +
 arch/arm/mach-imx/include/mach/imx25-regs.h  |    3 +-
 arch/arm/mach-imx/include/mach/iomux-mx25.h  |    4 +-
 arch/arm/mach-imx/speed-imx25.c              |    5 +
 board/freescale-mx25-3-stack/3stack.c        |   87 ++++++++++------
 board/freescale-mx25-3-stack/lowlevel_init.S |   18 ++--
 drivers/i2c/Kconfig                          |    3 +
 drivers/i2c/Makefile                         |    1 +
 drivers/i2c/mc34704.c                        |  140 ++++++++++++++++++++++++++
 include/i2c/mc34704.h                        |   26 +++++
 10 files changed, 247 insertions(+), 45 deletions(-)
 create mode 100644 drivers/i2c/mc34704.c
 create mode 100644 include/i2c/mc34704.h



From baruch at tkos.co.il  Wed Jun  9 03:05:02 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Wed,  9 Jun 2010 10:05:02 +0300
Subject: [PATCH 3/8] mx25 3ds: cleanup lowlevel_init code
In-Reply-To: <cover.1276065824.git.baruch@tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
Message-ID: <1b4ced2813ef508ad294faba378f9999431c9cdd.1276065824.git.baruch@tkos.co.il>

* remove unused asm/cache-l2x0.h header include
* remove out of place comment
* remove redundant defines

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 board/freescale-mx25-3-stack/lowlevel_init.S |   13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/board/freescale-mx25-3-stack/lowlevel_init.S b/board/freescale-mx25-3-stack/lowlevel_init.S
index bf03390..73bb147 100644
--- a/board/freescale-mx25-3-stack/lowlevel_init.S
+++ b/board/freescale-mx25-3-stack/lowlevel_init.S
@@ -24,7 +24,6 @@
 #include <mach/imx-regs.h>
 #include <mach/imx-pll.h>
 #include <mach/esdctl.h>
-#include <asm/cache-l2x0.h>
 
 #define writel(val, reg) \
 	ldr		r0,	=reg;	\
@@ -56,13 +55,7 @@ CCM_BASE_ADDR_W:        .word   IMX_CCM_BASE
 board_init_lowlevel:
 	mov     r10, lr
 
-/*
- * End of ARM1136 init
- */
 #define MX25_CCM_MCR	0x64
-#define MX25_CCM_CGR0	0x0c
-#define MX25_CCM_CGR1	0x10
-#define MX25_CCM_CGR2	0x14
 
 	ldr r0, CCM_BASE_ADDR_W
 	/* default CLKO to 1/32 of the ARM core */
@@ -75,9 +68,9 @@ board_init_lowlevel:
 	str r1, [r0, #MX25_CCM_MCR]
 
 	/* enable all the clocks */
-	writel(0x1FFFFFFF, IMX_CCM_BASE + MX25_CCM_CGR0)
-	writel(0xFFFFFFFF, IMX_CCM_BASE + MX25_CCM_CGR1)
-	writel(0x000FDFFF, IMX_CCM_BASE + MX25_CCM_CGR2)
+	writel(0x1FFFFFFF, IMX_CCM_BASE + CCM_CGCR0)
+	writel(0xFFFFFFFF, IMX_CCM_BASE + CCM_CGCR1)
+	writel(0x000FDFFF, IMX_CCM_BASE + CCM_CGCR2)
 	writel(0x0000FEFF, IMX_CCM_BASE + MX25_CCM_MCR)
 
 	/* Skip SDRAM initialization if we run from RAM */
-- 
1.7.1



From baruch at tkos.co.il  Wed Jun  9 03:05:03 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Wed,  9 Jun 2010 10:05:03 +0300
Subject: [PATCH 4/8] mx25: add support for i2c
In-Reply-To: <cover.1276065824.git.baruch@tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
Message-ID: <b6fba9ab7986aecf20f31329916ebd9d89c046ce.1276065824.git.baruch@tkos.co.il>

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 arch/arm/mach-imx/include/mach/imx25-regs.h |    1 +
 arch/arm/mach-imx/include/mach/iomux-mx25.h |    4 ++--
 arch/arm/mach-imx/speed-imx25.c             |    5 +++++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/include/mach/imx25-regs.h b/arch/arm/mach-imx/include/mach/imx25-regs.h
index 8052125..e91e7b6 100644
--- a/arch/arm/mach-imx/include/mach/imx25-regs.h
+++ b/arch/arm/mach-imx/include/mach/imx25-regs.h
@@ -46,6 +46,7 @@
 #define IMX_M3IF_BASE		0xB8003000
 #define IMX_NFC_BASE		0xBB000000
 #define IMX_FEC_BASE		0x50038000
+#define IMX_I2C1_BASE		0x43F80000
 
 /*
  * Clock Controller Module (CCM)
diff --git a/arch/arm/mach-imx/include/mach/iomux-mx25.h b/arch/arm/mach-imx/include/mach/iomux-mx25.h
index 379bfcb..a290a33 100644
--- a/arch/arm/mach-imx/include/mach/iomux-mx25.h
+++ b/arch/arm/mach-imx/include/mach/iomux-mx25.h
@@ -417,10 +417,10 @@
 #define MX25_PAD_HSYNC__GPIO22                             IOMUX_PAD(0x300, 0x108, 5,     0, 0, NO_PAD_CTRL)
 #define MX25_PAD_HSYNC__USBH2_DATA4                        IOMUX_PAD(0x300, 0x108, 6,     0, 0, 0xe5)
 #define MX25_PAD_HSYNC__BT_UART_SRC1                       IOMUX_PAD(0x300, 0x108, 7,     0, 0, NO_PAD_CTRL)
-#define MX25_PAD_I2C1_CLK__SCL                             IOMUX_PAD(0x348, 0x150, 0,     0, 0, NO_PAD_CTRL)
+#define MX25_PAD_I2C1_CLK__SCL                             IOMUX_PAD(0x348, 0x150, 0,     0, 0, (HYS | PKE | PUE | PUS_100K_UP))
 #define MX25_PAD_I2C1_CLK__GPIO12                          IOMUX_PAD(0x348, 0x150, 5,     0, 0, NO_PAD_CTRL)
 #define MX25_PAD_I2C1_CLK__SLCDC_DATA6                     IOMUX_PAD(0x348, 0x150, 6,     0, 0, NO_PAD_CTRL)
-#define MX25_PAD_I2C1_DAT__SDA                             IOMUX_PAD(0x34c, 0x154, 0,     0, 0, NO_PAD_CTRL)
+#define MX25_PAD_I2C1_DAT__SDA                             IOMUX_PAD(0x34c, 0x154, 0,     0, 0, (HYS | PKE | PUE | PUS_100K_UP))
 #define MX25_PAD_I2C1_DAT__GPIO13                          IOMUX_PAD(0x34c, 0x154, 5,     0, 0, NO_PAD_CTRL)
 #define MX25_PAD_I2C1_DAT__SLCDC_DATA7                     IOMUX_PAD(0x34c, 0x154, 6,     0, 0, NO_PAD_CTRL)
 #define MX25_PAD_KPP_COL0__COL0                            IOMUX_PAD(0x3b0, 0x1b8, 0,     0, 0, NO_PAD_CTRL)
diff --git a/arch/arm/mach-imx/speed-imx25.c b/arch/arm/mach-imx/speed-imx25.c
index a615017..9605674 100644
--- a/arch/arm/mach-imx/speed-imx25.c
+++ b/arch/arm/mach-imx/speed-imx25.c
@@ -77,6 +77,11 @@ unsigned long imx_get_lcdclk(void)
 	return imx_get_perclk(7);
 }
 
+unsigned long imx_get_i2cclk(void)
+{
+	return imx_get_perclk(6);
+}
+
 int imx_dump_clocks(void)
 {
 	printf("mpll:    %10d Hz\n", imx_get_mpllclk());
-- 
1.7.1



From baruch at tkos.co.il  Wed Jun  9 03:05:04 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Wed,  9 Jun 2010 10:05:04 +0300
Subject: [PATCH 5/8] i2c: add driver for the MC34704 PMIC
In-Reply-To: <cover.1276065824.git.baruch@tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
Message-ID: <b981284781213701d06a225d0ebbf11a29028330.1276065824.git.baruch@tkos.co.il>

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 drivers/i2c/Kconfig   |    3 +
 drivers/i2c/Makefile  |    1 +
 drivers/i2c/mc34704.c |  140 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/i2c/mc34704.h |   26 +++++++++
 4 files changed, 170 insertions(+), 0 deletions(-)
 create mode 100644 drivers/i2c/mc34704.c
 create mode 100644 include/i2c/mc34704.h

diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index f1b2949..a9ee411 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -10,6 +10,9 @@ config DRIVER_I2C_IMX
 config DRIVER_I2C_MC13892
 	bool "MC13892 a.k.a. PMIC driver"
 
+config DRIVER_I2C_MC34704
+	bool "MC34704 PMIC driver"
+
 config DRIVER_I2C_MC9SDZ60
 	bool "MC9SDZ60 driver"
 
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 62d030b..13e5804 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -3,5 +3,6 @@ obj-$(CONFIG_I2C) += i2c.o
 obj-$(CONFIG_DRIVER_I2C_IMX) += i2c-imx.o
 
 obj-$(CONFIG_DRIVER_I2C_MC13892) += mc13892.o
+obj-$(CONFIG_DRIVER_I2C_MC34704) += mc34704.o
 obj-$(CONFIG_DRIVER_I2C_MC9SDZ60) += mc9sdz60.o
 obj-$(CONFIG_DRIVER_I2C_LP3972) += lp3972.o
diff --git a/drivers/i2c/mc34704.c b/drivers/i2c/mc34704.c
new file mode 100644
index 0000000..51a8737
--- /dev/null
+++ b/drivers/i2c/mc34704.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2007 Sascha Hauer, Pengutronix
+ *               2009 Marc Kleine-Budde <mkl at pengutronix.de>
+ * Copyright (C) 2010 Baruch Siach <baruch at tkos.co.il>
+ *
+ * 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 <init.h>
+#include <driver.h>
+#include <xfuncs.h>
+#include <errno.h>
+
+#include <i2c/i2c.h>
+#include <i2c/mc34704.h>
+
+#define DRIVERNAME		"mc34704"
+
+#define to_mc34704(a)		container_of(a, struct mc34704, cdev)
+
+static struct mc34704 *mc34704_dev;
+
+struct mc34704 *mc34704_get(void)
+{
+	if (!mc34704_dev)
+		return NULL;
+
+	return mc34704_dev;
+}
+EXPORT_SYMBOL(mc34704_get);
+
+int mc34704_reg_read(struct mc34704 *mc34704, u8 reg, u8 *val)
+{
+	int ret;
+
+	ret = i2c_read_reg(mc34704->client, reg, val, 1);
+
+	return ret == 1 ? 0 : ret;
+}
+EXPORT_SYMBOL(mc34704_reg_read)
+
+int mc34704_reg_write(struct mc34704 *mc34704, u8 reg, u8 val)
+{
+	int ret;
+
+	ret = i2c_write_reg(mc34704->client, reg, &val, 1);
+
+	return ret == 1 ? 0 : ret;
+}
+EXPORT_SYMBOL(mc34704_reg_write)
+
+static ssize_t mc34704_read(struct cdev *cdev, void *_buf, size_t count,
+		ulong offset, ulong flags)
+{
+	struct mc34704 *priv = to_mc34704(cdev);
+	u8 *buf = _buf;
+	size_t i = count;
+	int err;
+
+	while (i) {
+		err = mc34704_reg_read(priv, offset, buf);
+		if (err)
+			return (ssize_t)err;
+		buf++;
+		i--;
+		offset++;
+	}
+
+	return count;
+}
+
+static ssize_t mc34704_write(struct cdev *cdev, const void *_buf, size_t count,
+		ulong offset, ulong flags)
+{
+	struct mc34704 *mc34704 = to_mc34704(cdev);
+	const u8 *buf = _buf;
+	size_t i = count;
+	int err;
+
+	while (i) {
+		err = mc34704_reg_write(mc34704, offset, *buf);
+		if (err)
+			return (ssize_t)err;
+		buf++;
+		i--;
+		offset++;
+	}
+
+	return count;
+}
+
+static struct file_operations mc34704_fops = {
+	.lseek	= dev_lseek_default,
+	.read	= mc34704_read,
+	.write	= mc34704_write,
+};
+
+static int mc34704_probe(struct device_d *dev)
+{
+	if (mc34704_dev)
+		return -EBUSY;
+
+	mc34704_dev = xzalloc(sizeof(struct mc34704));
+	mc34704_dev->cdev.name = DRIVERNAME;
+	mc34704_dev->client = to_i2c_client(dev);
+	mc34704_dev->cdev.size = 256;
+	mc34704_dev->cdev.dev = dev;
+	mc34704_dev->cdev.ops = &mc34704_fops;
+
+	devfs_create(&mc34704_dev->cdev);
+
+	return 0;
+}
+
+static struct driver_d mc34704_driver = {
+	.name  = DRIVERNAME,
+	.probe = mc34704_probe,
+};
+
+static int mc34704_init(void)
+{
+	register_driver(&mc34704_driver);
+        return 0;
+}
+device_initcall(mc34704_init);
diff --git a/include/i2c/mc34704.h b/include/i2c/mc34704.h
new file mode 100644
index 0000000..a3723d7
--- /dev/null
+++ b/include/i2c/mc34704.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2009 Marc Kleine-Budde <mkl at pengutronix.de>
+ * Copyright (C) 2010 Baruch Siach <baruch at tkos.co.il>
+ *
+ * This file is released under the GPLv2
+ *
+ * Derived from:
+ * - arch-mxc/pmic_external.h --  contains interface of the PMIC protocol driver
+ *   Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ */
+
+#ifndef __I2C_MC34704_H
+#define __I2C_MC34704_H
+
+struct mc34704 {
+	struct cdev		cdev;
+	struct i2c_client	*client;
+};
+
+extern struct mc34704 *mc34704_get(void);
+
+extern int mc34704_reg_read(struct mc34704 *mc34704, u8 reg, u8 *val);
+extern int mc34704_reg_write(struct mc34704 *mc34704, u8 reg, u8 val);
+
+#endif /* __I2C_MC34704_H */
-- 
1.7.1



From baruch at tkos.co.il  Wed Jun  9 03:05:05 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Wed,  9 Jun 2010 10:05:05 +0300
Subject: [PATCH 6/8] mx25 3ds: add support for i2c master and PMIC
In-Reply-To: <cover.1276065824.git.baruch@tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
Message-ID: <a2ce7c2796ea62c9ff75eeb6e72a8a36c2675337.1276065824.git.baruch@tkos.co.il>

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 board/freescale-mx25-3-stack/3stack.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/board/freescale-mx25-3-stack/3stack.c b/board/freescale-mx25-3-stack/3stack.c
index 6659185..316a2bc 100644
--- a/board/freescale-mx25-3-stack/3stack.c
+++ b/board/freescale-mx25-3-stack/3stack.c
@@ -36,6 +36,8 @@
 #include <nand.h>
 #include <mach/imx-flash-header.h>
 #include <mach/iomux-mx25.h>
+#include <i2c/i2c.h>
+#include <i2c/mc34704.h>
 
 extern unsigned long _stext;
 
@@ -183,8 +185,18 @@ static struct device_d usbh2_dev = {
 };
 #endif
 
+static struct i2c_board_info i2c_devices[] = {
+	{
+		I2C_BOARD_INFO("mc34704", 0x54),
+	},
+};
 #define IOMUXC_BASE_ADDR        0x43FAC000
 
+static struct device_d i2c_dev = {
+	.name     = "i2c-imx",
+	.map_base = IMX_I2C1_BASE,
+};
+
 static int imx25_devices_init(void)
 {
 	ulong val;
@@ -256,6 +268,9 @@ static int imx25_devices_init(void)
 	register_device(&sdram0_dev);
 	register_device(&sram0_dev);
 
+	i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices));
+	register_device(&i2c_dev);
+
 	armlinux_set_bootparams((void *)0x80000100);
 	armlinux_set_architecture(MACH_TYPE_MX25_3DS);
 
@@ -303,6 +318,9 @@ static struct pad_desc imx25_pads[] = {
 	MX25_PAD_VSYNC__USBH2_DATA5,
 	MX25_PAD_LSCLK__USBH2_DATA6,
 	MX25_PAD_OE_ACD__USBH2_DATA7,
+	/* i2c */
+	MX25_PAD_I2C1_CLK__SCL,
+	MX25_PAD_I2C1_DAT__SDA,
 };
 
 static int imx25_console_init(void)
-- 
1.7.1



From baruch at tkos.co.il  Wed Jun  9 03:05:06 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Wed,  9 Jun 2010 10:05:06 +0300
Subject: [PATCH 7/8] mx25 3ds: fix fec initialization
In-Reply-To: <cover.1276065824.git.baruch@tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
Message-ID: <0c6a2352b19406feb0fbf814962d53325d973164.1276065824.git.baruch@tkos.co.il>

The fec network interface initialization depends on the initialization of the
PMIC. Once the MC34704 driver is registered we can enable the PHY power supply,
and go on with the PHY initialization.

While we are at it convert the hard-coded GPIO registers access to the general
GPIO API for shorter and clearer code.

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 board/freescale-mx25-3-stack/3stack.c |   63 +++++++++++++++++----------------
 1 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/board/freescale-mx25-3-stack/3stack.c b/board/freescale-mx25-3-stack/3stack.c
index 316a2bc..a657a47 100644
--- a/board/freescale-mx25-3-stack/3stack.c
+++ b/board/freescale-mx25-3-stack/3stack.c
@@ -36,6 +36,7 @@
 #include <nand.h>
 #include <mach/imx-flash-header.h>
 #include <mach/iomux-mx25.h>
+#include <linux/err.h>
 #include <i2c/i2c.h>
 #include <i2c/mc34704.h>
 
@@ -190,16 +191,30 @@ static struct i2c_board_info i2c_devices[] = {
 		I2C_BOARD_INFO("mc34704", 0x54),
 	},
 };
-#define IOMUXC_BASE_ADDR        0x43FAC000
 
 static struct device_d i2c_dev = {
 	.name     = "i2c-imx",
 	.map_base = IMX_I2C1_BASE,
 };
 
-static int imx25_devices_init(void)
+static int imx25_3ds_pmic_init(void)
+{
+	struct mc34704 *pmic;
+
+	pmic = mc34704_get();
+	if (pmic == NULL)
+		return -EIO;
+
+	return mc34704_reg_write(pmic, 0x2, 0x9);
+}
+
+static int imx25_3ds_fec_init(void)
 {
-	ulong val;
+	int ret;
+
+	ret = imx25_3ds_pmic_init();
+	if (ret < 0)
+		return ret;
 
 	/*
 	 * Set up the FEC_RESET_B and FEC_ENABLE GPIO pins.
@@ -209,36 +224,27 @@ static int imx25_devices_init(void)
 	 * FEC_RESET_B: gpio2[3] is ALT 5 mode of pin A17
 	 * FEC_ENABLE_B: gpio4[8] is ALT 5 mode of pin D12
 	 */
-	writel(0x8, IOMUXC_BASE_ADDR + 0x0238); /* open drain */
-	writel(0x0, IOMUXC_BASE_ADDR + 0x028C); /* cmos, no pu/pd */
+	writel(0x8, IMX_IOMUXC_BASE + 0x0238); /* open drain */
+	writel(0x0, IMX_IOMUXC_BASE + 0x028C); /* cmos, no pu/pd */
 
-#define GPIO2_BASE_ADDR         0x53FD0000
-#define GPIO4_BASE_ADDR         0x53F9C000
-#define GPIO_GDIR               0x04
-#define GPIO_DR                 0x00
+#define FEC_ENABLE_GPIO		35
+#define FEC_RESET_B_GPIO	104
 
 	/* make the pins output */
-	val = (1 << 3) | readl(GPIO2_BASE_ADDR + GPIO_GDIR);
-	writel(val, GPIO2_BASE_ADDR + GPIO_GDIR);
-
-	val = (1 << 8) | readl(GPIO4_BASE_ADDR + GPIO_GDIR);
-	writel(val, GPIO4_BASE_ADDR + GPIO_GDIR);
-
-	/* drop PHY power */
-	val = readl(GPIO2_BASE_ADDR + GPIO_DR) & ~(1 << 3);
-	writel(val, GPIO2_BASE_ADDR + GPIO_DR);
-
-	/* assert reset */
-	val = readl(GPIO4_BASE_ADDR + GPIO_DR) & ~(1 << 8);
-	writel(val, GPIO4_BASE_ADDR + GPIO_DR);
+	gpio_direction_output(FEC_ENABLE_GPIO, 0);  /* drop PHY power */
+	gpio_direction_output(FEC_RESET_B_GPIO, 0); /* assert reset */
 	udelay(2);
 
 	/* turn on power & lift reset */
-	val = (1 << 3) | readl(GPIO2_BASE_ADDR + GPIO_DR);
-	writel(val, GPIO2_BASE_ADDR + GPIO_DR);
-	val = (1 << 8) | readl(GPIO4_BASE_ADDR + GPIO_DR);
-	writel(val, GPIO4_BASE_ADDR + GPIO_DR);
+	gpio_set_value(FEC_ENABLE_GPIO, 1);
+	gpio_set_value(FEC_RESET_B_GPIO, 1);
+
+	return 0;
+}
+late_initcall(imx25_3ds_fec_init);
 
+static int imx25_devices_init(void)
+{
 #ifdef CONFIG_USB
 	/* USB does not work yet. Don't know why. Maybe
 	 * the CPLD has to be initialized.
@@ -247,11 +253,6 @@ static int imx25_devices_init(void)
 	register_device(&usbh2_dev);
 #endif
 
-	/* FEC does only work when the CPLD is initialized.
-	 * Currently we do not do this in barebox, so it
-	 * does only work when Linux has been started after
-	 * the last powercycle.
-	 */
 	register_device(&fec_dev);
 
 	if (readl(IMX_CCM_BASE + CCM_RCSR) & (1 << 14))
-- 
1.7.1



From baruch at tkos.co.il  Wed Jun  9 03:05:07 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Wed,  9 Jun 2010 10:05:07 +0300
Subject: [PATCH 8/8] mx25 3ds: add support for boot from UART
In-Reply-To: <cover.1276065824.git.baruch@tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
Message-ID: <f9f84cc251848d133fae379e6d20253df2121ffb.1276065824.git.baruch@tkos.co.il>

For details of the UART protocol see the i.MX25 Reference Manual, section 7.8
"Serial Download protocol".

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 arch/arm/mach-imx/Kconfig                    |    5 +++++
 board/freescale-mx25-3-stack/3stack.c        |    4 ++++
 board/freescale-mx25-3-stack/lowlevel_init.S |    5 +++++
 3 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 419daab..40cebed 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -319,6 +319,11 @@ config FREESCALE_MX25_3STACK_SDRAM_64MB_DDR2
 config FREESCALE_MX25_3STACK_SDRAM_128MB_MDDR
 	bool "128 MB (mDDR)"
 endchoice
+
+config FREESCALE_MX25_3STACK_UART_BOOT
+	bool "Boot from UART"
+	depends on ARCH_IMX_INTERNAL_BOOT
+
 endif
 endmenu
 
diff --git a/board/freescale-mx25-3-stack/3stack.c b/board/freescale-mx25-3-stack/3stack.c
index a657a47..081487a 100644
--- a/board/freescale-mx25-3-stack/3stack.c
+++ b/board/freescale-mx25-3-stack/3stack.c
@@ -44,7 +44,11 @@ extern unsigned long _stext;
 
 void __naked __flash_header_start go(void)
 {
+#if defined CONFIG_FREESCALE_MX25_3STACK_UART_BOOT
+	__asm__ (".word	exception_vectors\n");
+#else
 	__asm__ __volatile__("b exception_vectors\n");
+#endif
 }
 
 struct imx_dcd_entry __dcd_entry_0x400 dcd_entry[] = {
diff --git a/board/freescale-mx25-3-stack/lowlevel_init.S b/board/freescale-mx25-3-stack/lowlevel_init.S
index 73bb147..b65a070 100644
--- a/board/freescale-mx25-3-stack/lowlevel_init.S
+++ b/board/freescale-mx25-3-stack/lowlevel_init.S
@@ -73,6 +73,11 @@ board_init_lowlevel:
 	writel(0x000FDFFF, IMX_CCM_BASE + CCM_CGCR2)
 	writel(0x0000FEFF, IMX_CCM_BASE + MX25_CCM_MCR)
 
+#if defined CONFIG_FREESCALE_MX25_3STACK_UART_BOOT
+	/* initialize CCM_CCTL, ARM clk = 400, AHB clk = 133 */
+	writel(0x20034000, IMX_CCM_BASE + 0x8);
+#endif
+
 	/* Skip SDRAM initialization if we run from RAM */
 	cmp	pc, #0x80000000
 	bls	1f
-- 
1.7.1



From baruch at tkos.co.il  Wed Jun  9 04:24:56 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Wed,  9 Jun 2010 11:24:56 +0300
Subject: [PATCH] mx25 3ds: fix memory initialization
Message-ID: <96c838395b1ca05a2712bc6e2a7c37564c68c7d4.1276071863.git.baruch@tkos.co.il>

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 board/freescale-mx25-3-stack/3stack.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/board/freescale-mx25-3-stack/3stack.c b/board/freescale-mx25-3-stack/3stack.c
index 081487a..4aa2f21 100644
--- a/board/freescale-mx25-3-stack/3stack.c
+++ b/board/freescale-mx25-3-stack/3stack.c
@@ -276,6 +276,7 @@ static int imx25_devices_init(void)
 	i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices));
 	register_device(&i2c_dev);
 
+	armlinux_add_dram(&sdram0_dev);
 	armlinux_set_bootparams((void *)0x80000100);
 	armlinux_set_architecture(MACH_TYPE_MX25_3DS);
 
-- 
1.7.1



From s.hauer at pengutronix.de  Tue Jun  8 02:49:29 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 8 Jun 2010 08:49:29 +0200
Subject: script error
In-Reply-To: <4C081332.6080904@erwinrol.com>
References: <4C081332.6080904@erwinrol.com>
Message-ID: <20100608064929.GC20799@pengutronix.de>

Hi Erwin,

Sorry for the delay.

On Thu, Jun 03, 2010 at 10:40:18PM +0200, Erwin Rol wrote:
> Hallo,
>
> i have a problem with running scripts. It seems that as soon a command  
> in a script fails the whole script is terminated.
>
> I am trying the following in /env/bin/init
>
> echo "Loading env A"
> mkdir /env_a/
> loadenv /dev/biosdisk0.1 /env_a/
> if [ -f /env_a/revision ]; then
>         . /env_a/revision
> fi
>
>
> The /dev/biosdisk0.1 is empty so the loadenv fails, and that also stops  
> the /env/bin/init script, everything after the "fi" is never executed.

That is because of the wrong exit code of loadenv. In do_loadenv we have

return envfs_load(filename, dirname);

which returns negative numbers as errors. The shell interpretes negative
numbers as return codes from commands as 'exit', so this should really be

return envfs_load(filename, dirname) ? 1 : 0;

Probably other commands have this bug aswell.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From marek.belisko at gmail.com  Wed Jun  9 06:55:47 2010
From: marek.belisko at gmail.com (Belisko Marek)
Date: Wed, 9 Jun 2010 12:55:47 +0200
Subject: barebox with usb cdc-eth driver?
Message-ID: <AANLkTikVBjnjLbC2LZBzRZ0C4FqgxOrbsT-tCgMTqGy8@mail.gmail.com>

Hi,

I'm not sure if this would be possible and also make a sense
but I think about possibility to add cdc-eth driver to barebox.

If some board doesn't have a eth interface and could be used for development
it would be nice to load kernel via usb cdc-eth and also mount rootfs
via nfs for kernel.

Is there any plan to make it?

Thanks,

Marek

-- 
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
icq: 290551086
web: http://open-nandra.com


From eric at eukrea.com  Thu Jun 10 03:43:02 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Thu, 10 Jun 2010 09:43:02 +0200
Subject: [PATCH] Add support for Eukrea CPUIMX35
Message-ID: <1276155782-6173-1-git-send-email-eric@eukrea.com>

From: Eric Benard <eric at eukrea.com>

this modules is based on Freescale's i.MX357 CPU, with 128MB of
mDDR, 256 MB NAND, and ethernet PHY.

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 arch/arm/Makefile                           |    1 +
 arch/arm/configs/eukrea_cpuimx35_defconfig  |  254 ++++++++++++++++++++
 arch/arm/mach-imx/Kconfig                   |   11 +
 board/eukrea_cpuimx35/Makefile              |   25 ++
 board/eukrea_cpuimx35/config.h              |   23 ++
 board/eukrea_cpuimx35/env/bin/_update       |   36 +++
 board/eukrea_cpuimx35/env/bin/boot          |   52 ++++
 board/eukrea_cpuimx35/env/bin/hush_hack     |    1 +
 board/eukrea_cpuimx35/env/bin/init          |   41 ++++
 board/eukrea_cpuimx35/env/bin/update_kernel |    8 +
 board/eukrea_cpuimx35/env/bin/update_root   |    8 +
 board/eukrea_cpuimx35/env/config            |   27 ++
 board/eukrea_cpuimx35/eukrea_cpuimx35.c     |  343 +++++++++++++++++++++++++++
 board/eukrea_cpuimx35/eukrea_cpuimx35.dox   |    4 +
 board/eukrea_cpuimx35/flash_header.c        |   60 +++++
 board/eukrea_cpuimx35/lowlevel.c            |  218 +++++++++++++++++
 16 files changed, 1112 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/configs/eukrea_cpuimx35_defconfig
 create mode 100644 board/eukrea_cpuimx35/Makefile
 create mode 100644 board/eukrea_cpuimx35/config.h
 create mode 100644 board/eukrea_cpuimx35/env/bin/_update
 create mode 100644 board/eukrea_cpuimx35/env/bin/boot
 create mode 100644 board/eukrea_cpuimx35/env/bin/hush_hack
 create mode 100644 board/eukrea_cpuimx35/env/bin/init
 create mode 100644 board/eukrea_cpuimx35/env/bin/update_kernel
 create mode 100644 board/eukrea_cpuimx35/env/bin/update_root
 create mode 100644 board/eukrea_cpuimx35/env/config
 create mode 100644 board/eukrea_cpuimx35/eukrea_cpuimx35.c
 create mode 100644 board/eukrea_cpuimx35/eukrea_cpuimx35.dox
 create mode 100644 board/eukrea_cpuimx35/flash_header.c
 create mode 100644 board/eukrea_cpuimx35/lowlevel.c

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 0bdce21..85ff9c8 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -63,6 +63,7 @@ board-$(CONFIG_MACH_EDB9315)			:= edb93xx
 board-$(CONFIG_MACH_EDB9315A)			:= edb93xx
 board-$(CONFIG_MACH_EUKREA_CPUIMX25)		:= eukrea_cpuimx25
 board-$(CONFIG_MACH_EUKREA_CPUIMX27)		:= eukrea_cpuimx27
+board-$(CONFIG_MACH_EUKREA_CPUIMX35)		:= eukrea_cpuimx35
 board-$(CONFIG_MACH_FREESCALE_MX25_3STACK)	:= freescale-mx25-3-stack
 board-$(CONFIG_MACH_FREESCALE_MX35_3STACK)	:= freescale-mx35-3-stack
 board-$(CONFIG_MACH_IMX21ADS)			:= imx21ads
diff --git a/arch/arm/configs/eukrea_cpuimx35_defconfig b/arch/arm/configs/eukrea_cpuimx35_defconfig
new file mode 100644
index 0000000..ff6547f
--- /dev/null
+++ b/arch/arm/configs/eukrea_cpuimx35_defconfig
@@ -0,0 +1,254 @@
+#
+# Automatically generated make config: don't edit
+# barebox version: 2010.06.0
+# Mon Jun  7 18:25:47 2010
+#
+# CONFIG_BOARD_LINKER_SCRIPT is not set
+CONFIG_GENERIC_LINKER_SCRIPT=y
+CONFIG_ARM=y
+
+#
+# System Type
+#
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_AT91RM9200 is not set
+# CONFIG_ARCH_EP93XX is not set
+CONFIG_ARCH_IMX=y
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_S3C24xx is not set
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_V6=y
+CONFIG_CPU_32v6=y
+
+#
+# processor features
+#
+CONFIG_ARCH_HAS_L2X0=y
+CONFIG_CACHE_L2X0=y
+CONFIG_ARCH_TEXT_BASE=0x87f00000
+CONFIG_BOARDINFO="Eukrea CPUIMX35"
+CONFIG_ARCH_HAS_FEC_IMX=y
+CONFIG_ARCH_IMX_INTERNAL_BOOT=y
+
+#
+# Freescale i.MX System-on-Chip
+#
+# CONFIG_ARCH_IMX1 is not set
+# CONFIG_ARCH_IMX21 is not set
+# CONFIG_ARCH_IMX25 is not set
+# CONFIG_ARCH_IMX27 is not set
+# CONFIG_ARCH_IMX31 is not set
+CONFIG_ARCH_IMX35=y
+CONFIG_MACH_EUKREA_CPUIMX35=y
+# CONFIG_MACH_FREESCALE_MX35_3STACK is not set
+# CONFIG_MACH_PCM043 is not set
+
+#
+# Board specific settings       
+#
+
+#
+# i.MX specific settings        
+#
+# CONFIG_IMX_CLKO is not set
+# CONFIG_AEABI is not set
+
+#
+# Arm specific settings         
+#
+CONFIG_CMD_ARM_CPUINFO=y
+CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
+CONFIG_GREGORIAN_CALENDER=y
+CONFIG_HAS_KALLSYMS=y
+CONFIG_HAS_MODULES=y
+CONFIG_CMD_MEMORY=y
+CONFIG_ENV_HANDLING=y
+CONFIG_GENERIC_GPIO=y
+
+#
+# General Settings              
+#
+CONFIG_LOCALVERSION_AUTO=y
+
+#
+# memory layout                 
+#
+CONFIG_HAVE_MMU=y
+CONFIG_MMU=y
+CONFIG_HAVE_CONFIGURABLE_TEXT_BASE=y
+CONFIG_TEXT_BASE=0x87f00000
+CONFIG_HAVE_CONFIGURABLE_MEMORY_LAYOUT=y
+CONFIG_MEMORY_LAYOUT_DEFAULT=y
+# CONFIG_MEMORY_LAYOUT_FIXED is not set
+CONFIG_STACK_SIZE=0x8000
+CONFIG_MALLOC_SIZE=0x800000
+# CONFIG_BROKEN is not set
+# CONFIG_EXPERIMENTAL is not set
+CONFIG_MACH_HAS_LOWLEVEL_INIT=y
+CONFIG_MACH_DO_LOWLEVEL_INIT=y
+CONFIG_PROMPT="barebox:"
+CONFIG_BAUDRATE=115200
+CONFIG_LONGHELP=y
+CONFIG_CBSIZE=1024
+CONFIG_MAXARGS=16
+CONFIG_SHELL_HUSH=y
+# CONFIG_SHELL_SIMPLE is not set
+CONFIG_GLOB=y
+CONFIG_PROMPT_HUSH_PS2="> "
+CONFIG_HUSH_FANCY_PROMPT=y
+CONFIG_CMDLINE_EDITING=y
+CONFIG_AUTO_COMPLETE=y
+CONFIG_DYNAMIC_CRC_TABLE=y
+CONFIG_ERRNO_MESSAGES=y
+CONFIG_TIMESTAMP=y
+CONFIG_CONSOLE_FULL=y
+CONFIG_CONSOLE_ACTIVATE_FIRST=y
+# CONFIG_OF_FLAT_TREE is not set
+# CONFIG_PARTITION is not set
+# CONFIG_DEFAULT_ENVIRONMENT is not set
+
+#
+# Debugging                     
+#
+# CONFIG_DEBUG_INFO is not set
+# CONFIG_ENABLE_FLASH_NOISE is not set
+# CONFIG_ENABLE_PARTITION_NOISE is not set
+# CONFIG_ENABLE_DEVICE_NOISE is not set
+
+#
+# Commands                      
+#
+
+#
+# scripting                     
+#
+CONFIG_CMD_EDIT=y
+CONFIG_CMD_SLEEP=y
+CONFIG_CMD_SAVEENV=y
+CONFIG_CMD_LOADENV=y
+CONFIG_CMD_EXPORT=y
+CONFIG_CMD_PRINTENV=y
+CONFIG_CMD_READLINE=y
+CONFIG_CMD_TRUE=y
+CONFIG_CMD_FALSE=y
+
+#
+# file commands                 
+#
+CONFIG_CMD_LS=y
+CONFIG_CMD_RM=y
+CONFIG_CMD_CAT=y
+CONFIG_CMD_MKDIR=y
+CONFIG_CMD_RMDIR=y
+CONFIG_CMD_CP=y
+CONFIG_CMD_PWD=y
+CONFIG_CMD_CD=y
+CONFIG_CMD_MOUNT=y
+CONFIG_CMD_UMOUNT=y
+
+#
+# console                       
+#
+CONFIG_CMD_CLEAR=y
+CONFIG_CMD_ECHO=y
+CONFIG_CMD_ECHO_E=y
+
+#
+# memory                        
+#
+CONFIG_CMD_LOADB=y
+CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_CRC=y
+CONFIG_CMD_MTEST=y
+# CONFIG_CMD_MTEST_ALTERNATIVE is not set
+
+#
+# flash                         
+#
+# CONFIG_CMD_FLASH is not set
+
+#
+# booting                       
+#
+CONFIG_CMD_BOOTM=y
+# CONFIG_CMD_BOOTM_ZLIB is not set
+# CONFIG_CMD_BOOTM_BZLIB is not set
+# CONFIG_CMD_BOOTM_SHOW_TYPE is not set
+CONFIG_CMD_BOOTZ=y
+CONFIG_CMD_BOOTU=y
+# CONFIG_CMD_LINUX16 is not set
+CONFIG_CMD_RESET=y
+CONFIG_CMD_GO=y
+CONFIG_CMD_TIMEOUT=y
+CONFIG_CMD_PARTITION=y
+CONFIG_CMD_TEST=y
+CONFIG_CMD_VERSION=y
+CONFIG_CMD_HELP=y
+CONFIG_CMD_DEVINFO=y
+CONFIG_CMD_BMP=y
+CONFIG_CMD_GPIO=y
+CONFIG_CMD_UNLZO=y
+CONFIG_NET=y
+CONFIG_NET_DHCP=y
+# CONFIG_NET_RARP is not set
+# CONFIG_NET_NFS is not set
+CONFIG_NET_PING=y
+CONFIG_NET_TFTP=y
+
+#
+# Drivers                       
+#
+
+#
+# serial drivers                
+#
+# CONFIG_DRIVER_SERIAL_ARM_DCC is not set
+CONFIG_DRIVER_SERIAL_IMX=y
+# CONFIG_DRIVER_SERIAL_NS16550 is not set
+CONFIG_MIIPHY=y
+
+#
+# Network drivers               
+#
+# CONFIG_DRIVER_NET_SMC911X is not set
+# CONFIG_DRIVER_NET_SMC91111 is not set
+CONFIG_DRIVER_NET_FEC_IMX=y
+
+#
+# SPI drivers                   
+#
+# CONFIG_SPI is not set
+# CONFIG_I2C is not set
+
+#
+# flash drivers                 
+#
+# CONFIG_DRIVER_CFI is not set
+CONFIG_NAND=y
+CONFIG_NAND_IMX=y
+# CONFIG_NAND_IMX_BOOT is not set
+# CONFIG_MTD_NAND_VERIFY_WRITE is not set
+# CONFIG_MTD_NAND_ECC_SMC is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_ATA is not set
+# CONFIG_USB is not set
+# CONFIG_USB_GADGET is not set
+CONFIG_VIDEO=y
+CONFIG_DRIVER_VIDEO_IMX_IPU=y
+
+#
+# Filesystem support            
+#
+# CONFIG_FS_CRAMFS is not set
+CONFIG_FS_RAMFS=y
+CONFIG_FS_DEVFS=y
+CONFIG_CRC32=y
+CONFIG_CRC16=y
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+CONFIG_PROCESS_ESCAPE_SEQUENCE=y
+CONFIG_LZO_DECOMPRESS=y
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 419daab..afd8cae 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -4,6 +4,7 @@ config ARCH_TEXT_BASE
 	hex
 	default 0x83f00000 if MACH_EUKREA_CPUIMX25
 	default 0xa0000000 if MACH_EUKREA_CPUIMX27
+	default 0x87f00000 if MACH_EUKREA_CPUIMX35
 	default 0x08f00000 if MACH_MX1ADS
 	default 0xc0000000 if MACH_IMX21ADS
 	default 0xa0000000 if MACH_IMX27ADS
@@ -19,6 +20,7 @@ config ARCH_TEXT_BASE
 config BOARDINFO
 	default "Eukrea CPUIMX25" if MACH_EUKREA_CPUIMX25
 	default "Eukrea CPUIMX27" if MACH_EUKREA_CPUIMX27
+	default "Eukrea CPUIMX35" if MACH_EUKREA_CPUIMX35
 	default "Freescale i.MX21 ADS" if MACH_IMX21ADS
 	default "Freescale i.MX27 ADS" if MACH_IMX27ADS
 	default "Freescale MX35 3Stack" if MACH_FREESCALE_MX35_3STACK
@@ -223,6 +225,15 @@ choice
 
 	prompt "i.MX35 Board Type"
 
+config MACH_EUKREA_CPUIMX35
+	bool "EUKREA CPUIMX35"
+	select HAVE_MMU
+	select MACH_HAS_LOWLEVEL_INIT
+	select ARCH_HAS_L2X0
+	help
+	  Say Y here if you are using Eukrea's CPUIMX35 equipped
+	  with a Freescale i.MX35 Processor
+
 config MACH_FREESCALE_MX35_3STACK
 	bool "Freescale MX35 3stack"
 	select HAS_CFI
diff --git a/board/eukrea_cpuimx35/Makefile b/board/eukrea_cpuimx35/Makefile
new file mode 100644
index 0000000..32ffe42
--- /dev/null
+++ b/board/eukrea_cpuimx35/Makefile
@@ -0,0 +1,25 @@
+#
+# (C) Copyright 2007 Juergen Beisert <jbe at pengutronix.de>
+#
+# 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
+#
+
+obj-y					+= lowlevel.o
+obj-y					+= eukrea_cpuimx35.o
+obj-$(CONFIG_ARCH_IMX_INTERNAL_BOOT)	+= flash_header.o
diff --git a/board/eukrea_cpuimx35/config.h b/board/eukrea_cpuimx35/config.h
new file mode 100644
index 0000000..bfd3b39
--- /dev/null
+++ b/board/eukrea_cpuimx35/config.h
@@ -0,0 +1,23 @@
+/*
+ * 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
+ */
+
+#ifndef __CONFIG_H
+#define __CONFIG_H
+
+#define CONFIG_MX35_HCLK_FREQ        24000000
+
+#endif	/* __CONFIG_H */
diff --git a/board/eukrea_cpuimx35/env/bin/_update b/board/eukrea_cpuimx35/env/bin/_update
new file mode 100644
index 0000000..014bce3
--- /dev/null
+++ b/board/eukrea_cpuimx35/env/bin/_update
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+if [ -z "$part" -o -z "$image" ]; then
+	echo "define \$part and \$image"
+	exit 1
+fi
+
+if [ ! -e "$part" ]; then
+	echo "Partition $part does not exist"
+	exit 1
+fi
+
+if [ $# = 1 ]; then
+	image=$1
+fi
+
+if [ x$ip = xdhcp ]; then
+	dhcp
+fi
+
+ping $eth0.serverip
+if [ $? -ne 0 ] ; then
+	echo "update aborted"
+	exit 1
+fi
+
+unprotect $part
+
+echo
+echo "erasing partition $part"
+erase $part
+
+echo
+echo "flashing $image to $part"
+echo
+tftp $image $part
diff --git a/board/eukrea_cpuimx35/env/bin/boot b/board/eukrea_cpuimx35/env/bin/boot
new file mode 100644
index 0000000..fca5b8c
--- /dev/null
+++ b/board/eukrea_cpuimx35/env/bin/boot
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+. /env/config
+
+if [ x$1 = xjffS2 ]; then
+	root=jffs2
+	kernel=nand
+fi
+
+if [ x$1 = xubifs ]; then
+	root=ubifs
+	kernel=nand
+fi
+
+if [ x$1 = xnet ]; then
+	root=net
+	kernel=net
+fi
+
+if [ x$ip = xdhcp ]; then
+	bootargs="$bootargs ip=dhcp"
+else
+	if [ x$ip = xoff ]; then
+		bootargs="$bootargs ip=off"
+	else
+		bootargs="$bootargs ip=$eth0.ipaddr:$eth0.serverip:$eth0.gateway:$eth0.netmask:::"
+	fi
+fi
+
+if [ x$root = xjffs2 ]; then
+	bootargs="$bootargs root=/dev/mtdblock$rootpartnum_nand rootfstype=jffs2"
+fi
+
+if [ x$root = xubifs ]; then
+	bootargs="$bootargs root=ubi0:$ubiroot ubi.mtd=$rootpartnum_nand rootfstype=ubifs"
+fi
+
+if [ x$root = xnet ]; then
+	bootargs="$bootargs root=/dev/nfs nfsroot=$eth0.serverip:$nfsroot,v3,tcp"
+fi
+
+bootargs="$bootargs mtdparts=mxc_nand:$nand_parts"
+
+if [ $kernel = net ]; then
+	if [ x$ip = xdhcp ]; then
+		dhcp
+	fi
+	tftp $uimage uImage || exit 1
+	bootm uImage
+else
+	bootm /dev/nand0.kernel.bb
+fi
diff --git a/board/eukrea_cpuimx35/env/bin/hush_hack b/board/eukrea_cpuimx35/env/bin/hush_hack
new file mode 100644
index 0000000..5fffa92
--- /dev/null
+++ b/board/eukrea_cpuimx35/env/bin/hush_hack
@@ -0,0 +1 @@
+nand -a /dev/nand0.*
diff --git a/board/eukrea_cpuimx35/env/bin/init b/board/eukrea_cpuimx35/env/bin/init
new file mode 100644
index 0000000..49e54c5
--- /dev/null
+++ b/board/eukrea_cpuimx35/env/bin/init
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+PATH=/env/bin
+export PATH
+
+. /env/config
+if [ -e /dev/nand0 ]; then
+	addpart /dev/nand0 $nand_parts
+
+	# Uh, oh, hush first expands wildcards and then starts executing
+	# commands. What a bug!
+	source /env/bin/hush_hack 
+fi
+
+if [ -f /env/logo.bmp ]; then
+	bmp /env/logo.bmp
+elif [ -f /env/logo.bmp.lzo ]; then
+	unlzo /env/logo.bmp.lzo /logo.bmp
+	bmp /logo.bmp
+fi
+
+if [ -z $eth0.ethaddr ]; then
+	while [ -z $eth0.ethaddr ]; do
+		readline "no MAC address set for eth0. please enter the one found on your board: " eth0.ethaddr
+	done
+	echo -a /env/config "eth0.ethaddr=$eth0.ethaddr"
+	saveenv
+fi
+
+echo
+echo -n "Hit any key to stop autoboot: "
+timeout -a $autoboot_timeout
+if [ $? != 0 ]; then
+	echo
+	echo "type update_kernel [<imagename>] to update kernel into flash"
+	echo "type update_root [<imagename>] to update rootfs into flash"
+	echo
+	exit
+fi
+
+boot
diff --git a/board/eukrea_cpuimx35/env/bin/update_kernel b/board/eukrea_cpuimx35/env/bin/update_kernel
new file mode 100644
index 0000000..c2d2cc3
--- /dev/null
+++ b/board/eukrea_cpuimx35/env/bin/update_kernel
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+. /env/config
+
+image=$uimage
+part=/dev/nand0.kernel.bb
+
+. /env/bin/_update $1
diff --git a/board/eukrea_cpuimx35/env/bin/update_root b/board/eukrea_cpuimx35/env/bin/update_root
new file mode 100644
index 0000000..dd89a5a
--- /dev/null
+++ b/board/eukrea_cpuimx35/env/bin/update_root
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+. /env/config
+
+image=$rootfs
+part=/dev/nand0.root.bb
+
+. /env/bin/_update $1
diff --git a/board/eukrea_cpuimx35/env/config b/board/eukrea_cpuimx35/env/config
new file mode 100644
index 0000000..df2079f
--- /dev/null
+++ b/board/eukrea_cpuimx35/env/config
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# can be either 'net' or 'nand''
+kernel=nand
+root=ubifs
+
+basedir=cpuimx35
+uimage=$basedir/uImage
+rootfs=$basedir/rootfs
+
+autoboot_timeout=1
+
+nfsroot=""
+bootargs="console=ttymxc0,115200"
+
+nand_parts="256k(barebox)ro,128k(bareboxenv),2176k(kernel),-(root)"
+rootpartnum_nand=3
+ubiroot="eukrea-cpuimx35-rootfs"
+
+# use 'dhcp' to do dhcp in barebox and in kernel
+ip=off
+
+# or set your networking parameters here
+#eth0.ipaddr=a.b.c.d
+#eth0.netmask=a.b.c.d
+#eth0.gateway=a.b.c.d
+#eth0.serverip=a.b.c.d
diff --git a/board/eukrea_cpuimx35/eukrea_cpuimx35.c b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
new file mode 100644
index 0000000..7f1c782
--- /dev/null
+++ b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
@@ -0,0 +1,343 @@
+/*
+ * Copyright (C) 2007 Sascha Hauer, Pengutronix
+ *               2009 Marc Kleine-Budde, Pengutronix
+ * (c) 2010 Eukrea Electromatique, Eric B?nard <eric at eukrea.com>
+ *
+ * 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
+ *
+ * Derived from:
+ *
+ * * mx35_3stack.c - board file for uboot-v1
+ *   Copyright (C) 2007, Guennadi Liakhovetski <lg at denx.de>
+ *   (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ */
+
+#include <common.h>
+#include <command.h>
+#include <environment.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fec.h>
+#include <fs.h>
+#include <init.h>
+#include <nand.h>
+#include <net.h>
+#include <partition.h>
+
+#include <asm/armlinux.h>
+#include <asm/io.h>
+#include <asm/mach-types.h>
+#include <asm/mmu.h>
+
+#include <mach/gpio.h>
+#include <mach/imx-nand.h>
+#include <mach/imx-regs.h>
+#include <mach/iomux-mx35.h>
+#include <mach/iomux-v3.h>
+#include <mach/pmic.h>
+#include <mach/imx-ipu-fb.h>
+#include <mach/imx-pll.h>
+
+static struct fec_platform_data fec_info = {
+	.xcv_type	= MII100,
+	.phy_addr	= 0x1F,
+};
+
+static struct device_d fec_dev = {
+	.name		= "fec_imx",
+	.map_base	= IMX_FEC_BASE,
+	.platform_data	= &fec_info,
+};
+
+static struct memory_platform_data sdram_pdata = {
+	.name	= "ram0",
+	.flags	= DEVFS_RDWR,
+};
+
+static struct device_d sdram_dev = {
+	.name		= "mem",
+	.map_base	= IMX_SDRAM_CS0,
+	.size		= 128 * 1024 * 1024,
+	.platform_data	= &sdram_pdata,
+};
+
+struct imx_nand_platform_data nand_info = {
+	.width		= 1,
+	.hw_ecc		= 1,
+	.flash_bbt	= 1,
+};
+
+static struct device_d nand_dev = {
+	.name		= "imx_nand",
+	.map_base	= IMX_NFC_BASE,
+	.platform_data	= &nand_info,
+};
+
+static struct fb_videomode imxfb_mode = {
+	.name		= "CMO_QVGA",
+	.refresh	= 60,
+	.xres		= 320,
+	.yres		= 240,
+	.pixclock	= KHZ2PICOS(7000),
+	.left_margin	= 68,
+	.right_margin	= 20,
+	.upper_margin	= 15,
+	.lower_margin	= 4,
+	.hsync_len	= 30,
+	.vsync_len	= 3,
+	.sync		= FB_SYNC_OE_ACT_HIGH,
+	.vmode		= FB_VMODE_NONINTERLACED,
+	.flag		= 0,
+};
+
+static struct imx_ipu_fb_platform_data ipu_fb_data = {
+	.mode		= &imxfb_mode,
+	.bpp		= 16,
+};
+
+static struct device_d imxfb_dev = {
+	.name		= "imx-ipu-fb",
+	.map_base	= 0x53fc0000,
+	.size		= 0x1000,
+	.platform_data	= &ipu_fb_data,
+};
+
+#ifdef CONFIG_MMU
+static int eukrea_cpuimx35_mmu_init(void)
+{
+	mmu_init();
+
+	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
+	arm_create_section(0x90000000, 0x80000000, 128, PMD_SECT_DEF_UNCACHED);
+
+	setup_dma_coherent(0x10000000);
+
+#if TEXT_BASE & (0x100000 - 1)
+#warning cannot create vector section. Adjust TEXT_BASE to a 1M boundary
+#else
+	arm_create_section(0x0,        TEXT_BASE,   1, PMD_SECT_DEF_UNCACHED);
+#endif
+	mmu_enable();
+
+#ifdef CONFIG_CACHE_L2X0
+	l2x0_init((void __iomem *)0x30000000, 0x00030024, 0x00000000);
+#endif
+	return 0;
+}
+postcore_initcall(eukrea_cpuimx35_mmu_init);
+#endif
+
+static int eukrea_cpuimx35_devices_init(void)
+{
+	register_device(&nand_dev);
+
+	devfs_add_partition("nand0", 0x00000, 0x40000, PARTITION_FIXED, "self_raw");
+	dev_add_bb_dev("self_raw", "self0");
+	devfs_add_partition("nand0", 0x40000, 0x20000, PARTITION_FIXED, "env_raw");
+	dev_add_bb_dev("env_raw", "env0");
+
+	register_device(&fec_dev);
+
+	register_device(&sdram_dev);
+	register_device(&imxfb_dev);
+
+	armlinux_add_dram(&sdram_dev);
+	armlinux_set_bootparams((void *)0x80000100);
+	armlinux_set_architecture(MACH_TYPE_EUKREA_CPUIMX35);
+
+	return 0;
+}
+
+device_initcall(eukrea_cpuimx35_devices_init);
+
+static int eukrea_cpuimx35_enable_display(void)
+{
+	gpio_direction_output(1, 1);
+	gpio_direction_output(0, 0);
+	return 0;
+}
+
+late_initcall(eukrea_cpuimx35_enable_display);
+
+static struct device_d eukrea_cpuimx35_serial_device = {
+	.name		= "imx_serial",
+	.map_base	= IMX_UART1_BASE,
+	.size		= 4096,
+};
+
+static struct pad_desc eukrea_cpuimx35_pads[] = {
+	MX35_PAD_FEC_TX_CLK__FEC_TX_CLK,
+	MX35_PAD_FEC_RX_CLK__FEC_RX_CLK,
+	MX35_PAD_FEC_RX_DV__FEC_RX_DV,
+	MX35_PAD_FEC_COL__FEC_COL,
+	MX35_PAD_FEC_RDATA0__FEC_RDATA_0,
+	MX35_PAD_FEC_TDATA0__FEC_TDATA_0,
+	MX35_PAD_FEC_TX_EN__FEC_TX_EN,
+	MX35_PAD_FEC_MDC__FEC_MDC,
+	MX35_PAD_FEC_MDIO__FEC_MDIO,
+	MX35_PAD_FEC_TX_ERR__FEC_TX_ERR,
+	MX35_PAD_FEC_RX_ERR__FEC_RX_ERR,
+	MX35_PAD_FEC_CRS__FEC_CRS,
+	MX35_PAD_FEC_RDATA0__FEC_RDATA_0,
+	MX35_PAD_FEC_TDATA0__FEC_TDATA_0,
+	MX35_PAD_FEC_RDATA1__FEC_RDATA_1,
+	MX35_PAD_FEC_TDATA1__FEC_TDATA_1,
+	MX35_PAD_FEC_RDATA2__FEC_RDATA_2,
+	MX35_PAD_FEC_TDATA2__FEC_TDATA_2,
+	MX35_PAD_FEC_RDATA3__FEC_RDATA_3,
+	MX35_PAD_FEC_TDATA3__FEC_TDATA_3,
+
+	MX35_PAD_RXD1__UART1_RXD_MUX,
+	MX35_PAD_TXD1__UART1_TXD_MUX,
+	MX35_PAD_RTS1__UART1_RTS,
+	MX35_PAD_CTS1__UART1_CTS,
+};
+
+static int eukrea_cpuimx35_console_init(void)
+{
+	mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx35_pads,
+		ARRAY_SIZE(eukrea_cpuimx35_pads));
+
+	register_device(&eukrea_cpuimx35_serial_device);
+	return 0;
+}
+
+console_initcall(eukrea_cpuimx35_console_init);
+
+static int eukrea_cpuimx35_core_init(void)
+{
+	u32 reg;
+
+	/* enable clock for I2C1 and FEC */
+	reg = readl(IMX_CCM_BASE + CCM_CGR1);
+	reg |= 0x3 << CCM_CGR1_FEC_SHIFT;
+	reg = writel(reg, IMX_CCM_BASE + CCM_CGR1);
+
+	/* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
+	/*
+	 * Set all MPROTx to be non-bufferable, trusted for R/W,
+	 * not forced to user-mode.
+	 */
+	writel(0x77777777, IMX_AIPS1_BASE);
+	writel(0x77777777, IMX_AIPS1_BASE + 0x4);
+	writel(0x77777777, IMX_AIPS2_BASE);
+	writel(0x77777777, IMX_AIPS2_BASE + 0x4);
+
+	/*
+	 * Clear the on and off peripheral modules Supervisor Protect bit
+	 * for SDMA to access them. Did not change the AIPS control registers
+	 * (offset 0x20) access type
+	 */
+	writel(0x0, IMX_AIPS1_BASE + 0x40);
+	writel(0x0, IMX_AIPS1_BASE + 0x44);
+	writel(0x0, IMX_AIPS1_BASE + 0x48);
+	writel(0x0, IMX_AIPS1_BASE + 0x4C);
+	reg = readl(IMX_AIPS1_BASE + 0x50);
+	reg &= 0x00FFFFFF;
+	writel(reg, IMX_AIPS1_BASE + 0x50);
+
+	writel(0x0, IMX_AIPS2_BASE + 0x40);
+	writel(0x0, IMX_AIPS2_BASE + 0x44);
+	writel(0x0, IMX_AIPS2_BASE + 0x48);
+	writel(0x0, IMX_AIPS2_BASE + 0x4C);
+	reg = readl(IMX_AIPS2_BASE + 0x50);
+	reg &= 0x00FFFFFF;
+	writel(reg, IMX_AIPS2_BASE + 0x50);
+
+	/* MAX (Multi-Layer AHB Crossbar Switch) setup */
+
+	/* MPR - priority is M4 > M2 > M3 > M5 > M0 > M1 */
+#define MAX_PARAM1 0x00302154
+	writel(MAX_PARAM1, IMX_MAX_BASE + 0x000); /* for S0 */
+	writel(MAX_PARAM1, IMX_MAX_BASE + 0x100); /* for S1 */
+	writel(MAX_PARAM1, IMX_MAX_BASE + 0x200); /* for S2 */
+	writel(MAX_PARAM1, IMX_MAX_BASE + 0x300); /* for S3 */
+	writel(MAX_PARAM1, IMX_MAX_BASE + 0x400); /* for S4 */
+
+	/* SGPCR - always park on last master */
+	writel(0x10, IMX_MAX_BASE + 0x10);	/* for S0 */
+	writel(0x10, IMX_MAX_BASE + 0x110);	/* for S1 */
+	writel(0x10, IMX_MAX_BASE + 0x210);	/* for S2 */
+	writel(0x10, IMX_MAX_BASE + 0x310);	/* for S3 */
+	writel(0x10, IMX_MAX_BASE + 0x410);	/* for S4 */
+
+	/* MGPCR - restore default values */
+	writel(0x0, IMX_MAX_BASE + 0x800);	/* for M0 */
+	writel(0x0, IMX_MAX_BASE + 0x900);	/* for M1 */
+	writel(0x0, IMX_MAX_BASE + 0xa00);	/* for M2 */
+	writel(0x0, IMX_MAX_BASE + 0xb00);	/* for M3 */
+	writel(0x0, IMX_MAX_BASE + 0xc00);	/* for M4 */
+	writel(0x0, IMX_MAX_BASE + 0xd00);	/* for M5 */
+
+	/*
+	 * M3IF Control Register (M3IFCTL)
+	 * MRRP[0] = L2CC0 not on priority list (0 << 0)	= 0x00000000
+	 * MRRP[1] = MAX1 not on priority list (0 << 0)		= 0x00000000
+	 * MRRP[2] = L2CC1 not on priority list (0 << 0)	= 0x00000000
+	 * MRRP[3] = USB  not on priority list (0 << 0)		= 0x00000000
+	 * MRRP[4] = SDMA not on priority list (0 << 0)		= 0x00000000
+	 * MRRP[5] = GPU not on priority list (0 << 0)		= 0x00000000
+	 * MRRP[6] = IPU1 on priority list (1 << 6)		= 0x00000040
+	 * MRRP[7] = IPU2 not on priority list (0 << 0)		= 0x00000000
+	 *                                                       ------------
+	 *                                                        0x00000040
+	 */
+	writel(0x40, IMX_M3IF_BASE);
+
+	return 0;
+}
+
+core_initcall(eukrea_cpuimx35_core_init);
+
+#define MPCTL_PARAM_399     (IMX_PLL_PD(0) | IMX_PLL_MFD(15) | IMX_PLL_MFI(8) | IMX_PLL_MFN(5))
+#define MPCTL_PARAM_532     ((1 << 31) | IMX_PLL_PD(0) | IMX_PLL_MFD(11) | IMX_PLL_MFI(11) | IMX_PLL_MFN(1))
+
+static int do_cpufreq(struct command *cmdtp, int argc, char *argv[])
+{
+	unsigned long freq;
+
+	if (argc != 2)
+		return COMMAND_ERROR_USAGE;
+
+	freq = simple_strtoul(argv[1], NULL, 0);
+
+	switch (freq) {
+	case 399:
+		writel(MPCTL_PARAM_399, IMX_CCM_BASE + CCM_MPCTL);
+		break;
+	case 532:
+		writel(MPCTL_PARAM_532, IMX_CCM_BASE + CCM_MPCTL);
+		break;
+	default:
+		return COMMAND_ERROR_USAGE;
+	}
+
+	printf("Switched CPU frequency to %dMHz\n", freq);
+
+	return 0;
+}
+
+static const __maybe_unused char cmd_cpufreq_help[] =
+"Usage: cpufreq 399|532\n"
+"\n"
+"Set CPU frequency to <freq> MHz\n";
+
+BAREBOX_CMD_START(cpufreq)
+	.cmd            = do_cpufreq,
+	.usage          = "adjust CPU frequency",
+	BAREBOX_CMD_HELP(cmd_cpufreq_help)
+BAREBOX_CMD_END
diff --git a/board/eukrea_cpuimx35/eukrea_cpuimx35.dox b/board/eukrea_cpuimx35/eukrea_cpuimx35.dox
new file mode 100644
index 0000000..cbdf69d
--- /dev/null
+++ b/board/eukrea_cpuimx35/eukrea_cpuimx35.dox
@@ -0,0 +1,4 @@
+/** @page eukrea_cpuimx35 Eukrea's CPUIMX35
+
+
+*/
diff --git a/board/eukrea_cpuimx35/flash_header.c b/board/eukrea_cpuimx35/flash_header.c
new file mode 100644
index 0000000..a0ccf5c
--- /dev/null
+++ b/board/eukrea_cpuimx35/flash_header.c
@@ -0,0 +1,60 @@
+#include <common.h>
+#include <mach/imx-flash-header.h>
+
+extern unsigned long _stext;
+
+void __naked __flash_header_start go(void)
+{
+	__asm__ __volatile__("b exception_vectors\n");
+}
+
+struct imx_dcd_entry __dcd_entry_0x400 dcd_entry[] = {
+	{ .ptr_type = 4, .addr = 0xB8001010, .val = 0x00000004, },
+	{ .ptr_type = 4, .addr = 0xB8001010, .val = 0x0000000C, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc3f, },
+	{ .ptr_type = 4, .addr = 0xB8001000, .val = 0x92220000, },
+	{ .ptr_type = 1, .addr = 0x80000400, .val = 0x12345678, },
+	{ .ptr_type = 4, .addr = 0xB8001000, .val = 0xA2220000, },
+	{ .ptr_type = 1, .addr = 0x80000000, .val = 0x87654321, },
+	{ .ptr_type = 1, .addr = 0x80000000, .val = 0x87654321, },
+	{ .ptr_type = 4, .addr = 0xB8001000, .val = 0xB2220000, },
+	{ .ptr_type = 1, .addr = 0x80000033, .val = 0xda, },
+	{ .ptr_type = 1, .addr = 0x82000000, .val = 0xda, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
+	{ .ptr_type = 4, .addr = 0xB8001000, .val = 0x82220080, },
+	{ .ptr_type = 4, .addr = 0xB8001000, .val = 0x82228080, },
+	{ .ptr_type = 4, .addr = 0xB8001020, .val = 0x80000028, },
+	{ .ptr_type = 4, .addr = 0xB8001024, .val = 0x80000028, },
+	{ .ptr_type = 4, .addr = 0xB8001028, .val = 0x80000028, },
+	{ .ptr_type = 4, .addr = 0xB800102c, .val = 0x80000028, },
+	{ .ptr_type = 4, .addr = 0xB8001030, .val = 0x80000028, },
+};
+
+#define APP_DEST	0x80000000
+
+struct imx_flash_header __flash_header_0x400 flash_header = {
+	.app_code_jump_vector	= APP_DEST + 0x1000,
+	.app_code_barker	= APP_CODE_BARKER,
+	.app_code_csf		= 0,
+	.dcd_ptr_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header, dcd),
+	.super_root_key		= 0,
+	.dcd			= APP_DEST + 0x400 + offsetof(struct imx_flash_header, dcd_barker),
+	.app_dest		= APP_DEST,
+	.dcd_barker		= DCD_BARKER,
+	.dcd_block_len		= sizeof (dcd_entry),
+};
+
+unsigned long __image_len_0x400 barebox_len = 0x40000;
+
diff --git a/board/eukrea_cpuimx35/lowlevel.c b/board/eukrea_cpuimx35/lowlevel.c
new file mode 100644
index 0000000..44f3cf0
--- /dev/null
+++ b/board/eukrea_cpuimx35/lowlevel.c
@@ -0,0 +1,218 @@
+/*
+ *
+ * (c) 2007 Pengutronix, Sascha Hauer <s.hauer at pengutronix.de>
+ *
+ * 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 <init.h>
+#include <mach/imx-regs.h>
+#include <mach/imx-pll.h>
+#include <mach/esdctl.h>
+#include <asm/cache-l2x0.h>
+#include <asm/io.h>
+#include <mach/imx-nand.h>
+#include <asm/barebox-arm.h>
+#include <asm-generic/memory_layout.h>
+#include <asm/system.h>
+
+/* Assuming 24MHz input clock */
+#define MPCTL_PARAM_399     (IMX_PLL_PD(0) | IMX_PLL_MFD(15) | IMX_PLL_MFI(8) | IMX_PLL_MFN(5))
+#define MPCTL_PARAM_532     ((1 << 31) | IMX_PLL_PD(0) | IMX_PLL_MFD(11) | IMX_PLL_MFI(11) | IMX_PLL_MFN(1))
+#define PPCTL_PARAM_300     (IMX_PLL_PD(0) | IMX_PLL_MFD(3) | IMX_PLL_MFI(6) | IMX_PLL_MFN(1))
+
+#ifdef CONFIG_NAND_IMX_BOOT
+static void __bare_init __naked insdram(void)
+{
+	uint32_t r;
+
+	/* Speed up NAND controller by adjusting the NFC divider */
+	r = readl(IMX_CCM_BASE + CCM_PDR4);
+	r &= ~(0xf << 28);
+	r |= 0x1 << 28;
+	writel(r, IMX_CCM_BASE + CCM_PDR4);
+
+	/* setup a stack to be able to call imx_nand_load_image() */
+	r = STACK_BASE + STACK_SIZE - 12;
+	__asm__ __volatile__("mov sp, %0" : : "r"(r));
+
+	imx_nand_load_image((void *)TEXT_BASE, 256 * 1024);
+
+	board_init_lowlevel_return();
+}
+#endif
+
+void __bare_init __naked board_init_lowlevel(void)
+{
+	uint32_t r, s;
+	unsigned long ccm_base = IMX_CCM_BASE;
+	unsigned long iomuxc_base = IMX_IOMUXC_BASE;
+#ifdef CONFIG_NAND_IMX_BOOT
+	unsigned int *trg, *src;
+	int i;
+#endif
+
+	r = get_cr();
+	r |= CR_Z; /* Flow prediction (Z) */
+	r |= CR_U; /* unaligned accesses  */
+	r |= CR_FI; /* Low Int Latency     */
+
+	__asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(s));
+	s |= 0x7;
+	__asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1" : : "r"(s));
+
+	set_cr(r);
+
+	r = 0;
+	__asm__ __volatile__("mcr p15, 0, %0, c15, c2, 4" : : "r"(r));
+
+	/*
+	 * Branch predicition is now enabled.  Flush the BTAC to ensure a valid
+	 * starting point.  Don't flush BTAC while it is disabled to avoid
+	 * ARM1136 erratum 408023.
+	 */
+	__asm__ __volatile__("mcr p15, 0, %0, c7, c5, 6" : : "r"(r));
+
+	/* invalidate I cache and D cache */
+	__asm__ __volatile__("mcr p15, 0, %0, c7, c7, 0" : : "r"(r));
+
+	/* invalidate TLBs */
+	__asm__ __volatile__("mcr p15, 0, %0, c8, c7, 0" : : "r"(r));
+
+	/* Drain the write buffer */
+	__asm__ __volatile__("mcr p15, 0, %0, c7, c10, 4" : : "r"(r));
+
+	/* Also setup the Peripheral Port Remap register inside the core */
+	r = 0x40000015; /* start from AIPS 2GB region */
+	__asm__ __volatile__("mcr p15, 0, %0, c15, c2, 4" : : "r"(r));
+
+	/*
+	 * End of ARM1136 init
+	 */
+
+	writel(0x003F4208, ccm_base + CCM_CCMR);
+
+	/* Set MPLL , arm clock and ahb clock*/
+	writel(MPCTL_PARAM_532, ccm_base + CCM_MPCTL);
+
+	writel(PPCTL_PARAM_300, ccm_base + CCM_PPCTL);
+	writel(0x00001000, ccm_base + CCM_PDR0);
+
+	r = readl(ccm_base + CCM_CGR0);
+	r |= 0x00300000;
+	writel(r, ccm_base + CCM_CGR0);
+
+	r = readl(ccm_base + CCM_CGR1);
+	r |= 0x00000C00;
+	r |= 0x00000003;
+	writel(r, ccm_base + CCM_CGR1);
+
+	r = readl(IMX_L2CC_BASE + L2X0_AUX_CTRL);
+	r |= 0x1000;
+	writel(r, IMX_L2CC_BASE + L2X0_AUX_CTRL);
+
+	/* Skip SDRAM initialization if we run from RAM */
+	r = get_pc();
+	if (r > 0x80000000 && r < 0x90000000)
+		board_init_lowlevel_return();
+
+	/* Set DDR Type to SDRAM, drive strength workaround	*
+	 * 0x00000000	MDDR					*
+	 * 0x00000800	3,3V SDRAM				*/
+
+	r = 0x00000800;
+	writel(r, iomuxc_base + 0x794);
+	writel(r, iomuxc_base + 0x798);
+	writel(r, iomuxc_base + 0x79c);
+	writel(r, iomuxc_base + 0x7a0);
+	writel(r, iomuxc_base + 0x7a4);
+
+	/* MDDR init, enable mDDR*/
+	writel(0x00000304, ESDMISC); /* was 0x00000004 */
+
+	/* set timing paramters */
+	writel(0x00255417, ESDCFG0);
+	/* select Precharge-All mode */
+	writel(0x92220000, ESDCTL0);
+	/* Precharge-All */
+	writel(0x12345678, IMX_SDRAM_CS0 + 0x400);
+
+	/* select Load-Mode-Register mode */
+	writel(0xB8001000, ESDCTL0);
+	/* Load reg EMR2 */
+	writeb(0xda, 0x84000000);
+	/* Load reg EMR3 */
+	writeb(0xda, 0x86000000);
+	/* Load reg EMR1 -- enable DLL */
+	writeb(0xda, 0x82000400);
+	/* Load reg MR -- reset DLL */
+	writeb(0xda, 0x80000333);
+
+	/* select Precharge-All mode */
+	writel(0x92220000, ESDCTL0);
+	/* Precharge-All */
+	writel(0x12345678, IMX_SDRAM_CS0 + 0x400);
+
+	/* select Manual-Refresh mode */
+	writel(0xA2220000, ESDCTL0);
+	/* Manual-Refresh 2 times */
+	writel(0x87654321, IMX_SDRAM_CS0);
+	writel(0x87654321, IMX_SDRAM_CS0);
+
+	/* select Load-Mode-Register mode */
+	writel(0xB2220000, ESDCTL0);
+	/* Load reg MR -- CL3, BL8, end DLL reset */
+	writeb(0xda, 0x80000233);
+	/* Load reg EMR1 -- OCD default */
+	writeb(0xda, 0x82000780);
+	/* Load reg EMR1 -- OCD exit */
+	writeb(0xda, 0x82000400);
+
+	/* select normal-operation mode
+	 * DSIZ32-bit, BL8, COL10-bit, ROW13-bit
+	 * disable PWT & PRCT
+	 * disable Auto-Refresh */
+	writel(0x82220080, ESDCTL0);
+
+	/* enable Auto-Refresh */
+	writel(0x82228080, ESDCTL0);
+	/* enable Auto-Refresh */
+	writel(0x00002000, ESDCTL1);
+
+#ifdef CONFIG_NAND_IMX_BOOT
+	/* skip NAND boot if not running from NFC space */
+	r = get_pc();
+	if (r < IMX_NFC_BASE || r > IMX_NFC_BASE + 0x800)
+		board_init_lowlevel_return();
+
+	src = (unsigned int *)IMX_NFC_BASE;
+	trg = (unsigned int *)TEXT_BASE;
+
+	/* Move ourselves out of NFC SRAM */
+	for (i = 0; i < 0x800 / sizeof(int); i++)
+		*trg++ = *src++;
+
+	/* Jump to SDRAM */
+	r = (unsigned int)&insdram;
+	__asm__ __volatile__("mov pc, %0" : : "r"(r));
+#else
+	board_init_lowlevel_return();
+#endif
+}
+
-- 
1.6.3.3



From eric at eukrea.com  Thu Jun 10 03:52:11 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Thu, 10 Jun 2010 09:52:11 +0200
Subject: [PATCH 1/2] eukrea_cpuimx25: add compressed logo support
Message-ID: <1276156332-7160-1-git-send-email-eric@eukrea.com>

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 board/eukrea_cpuimx25/env/bin/init |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/board/eukrea_cpuimx25/env/bin/init b/board/eukrea_cpuimx25/env/bin/init
index 8bcc732..335d7ae 100644
--- a/board/eukrea_cpuimx25/env/bin/init
+++ b/board/eukrea_cpuimx25/env/bin/init
@@ -14,6 +14,9 @@ fi
 
 if [ -f /env/logo.bmp ]; then
 	bmp /env/logo.bmp
+elif [ -f /env/logo.bmp.lzo ]; then
+	unlzo /env/logo.bmp.lzo /logo.bmp
+	bmp /logo.bmp
 fi
 
 if [ -z $eth0.ethaddr ]; then
-- 
1.6.3.3



From eric at eukrea.com  Thu Jun 10 03:52:12 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Thu, 10 Jun 2010 09:52:12 +0200
Subject: [PATCH 2/2] eukrea_cpuimx25: update defconfig
In-Reply-To: <1276156332-7160-1-git-send-email-eric@eukrea.com>
References: <1276156332-7160-1-git-send-email-eric@eukrea.com>
Message-ID: <1276156332-7160-2-git-send-email-eric@eukrea.com>

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 arch/arm/configs/eukrea_cpuimx25_defconfig |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/arch/arm/configs/eukrea_cpuimx25_defconfig b/arch/arm/configs/eukrea_cpuimx25_defconfig
index 81f9c80..574d322 100644
--- a/arch/arm/configs/eukrea_cpuimx25_defconfig
+++ b/arch/arm/configs/eukrea_cpuimx25_defconfig
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# barebox version: 2010.03.0
-# Fri Mar 19 11:12:11 2010
+# barebox version: 2010.05.0
+# Wed Jun  2 01:04:00 2010
 #
 # CONFIG_BOARD_LINKER_SCRIPT is not set
 CONFIG_GENERIC_LINKER_SCRIPT=y
@@ -88,19 +88,20 @@ CONFIG_MALLOC_SIZE=0x1000000
 # CONFIG_EXPERIMENTAL is not set
 CONFIG_MACH_HAS_LOWLEVEL_INIT=y
 CONFIG_MACH_DO_LOWLEVEL_INIT=y
-CONFIG_PROMPT="barebox:"
+CONFIG_PROMPT="cpuimx25:"
 CONFIG_BAUDRATE=115200
-# CONFIG_LONGHELP is not set
+CONFIG_LONGHELP=y
 CONFIG_CBSIZE=1024
 CONFIG_MAXARGS=16
 CONFIG_SHELL_HUSH=y
 # CONFIG_SHELL_SIMPLE is not set
 CONFIG_GLOB=y
 CONFIG_PROMPT_HUSH_PS2="cpuimx25>"
+CONFIG_HUSH_FANCY_PROMPT=y
 CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
 CONFIG_DYNAMIC_CRC_TABLE=y
-# CONFIG_ERRNO_MESSAGES is not set
+CONFIG_ERRNO_MESSAGES=y
 CONFIG_TIMESTAMP=y
 CONFIG_CONSOLE_FULL=y
 CONFIG_CONSOLE_ACTIVATE_FIRST=y
@@ -153,6 +154,7 @@ CONFIG_CMD_UMOUNT=y
 #
 CONFIG_CMD_CLEAR=y
 CONFIG_CMD_ECHO=y
+CONFIG_CMD_ECHO_E=y
 
 #
 # memory                        
@@ -172,9 +174,9 @@ CONFIG_CMD_FLASH=y
 # booting                       
 #
 CONFIG_CMD_BOOTM=y
-# CONFIG_CMD_BOOTM_ZLIB is not set
-# CONFIG_CMD_BOOTM_BZLIB is not set
-# CONFIG_CMD_BOOTM_SHOW_TYPE is not set
+CONFIG_CMD_BOOTM_ZLIB=y
+CONFIG_CMD_BOOTM_BZLIB=y
+CONFIG_CMD_BOOTM_SHOW_TYPE=y
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_BOOTU=y
 # CONFIG_CMD_LINUX16 is not set
@@ -188,6 +190,7 @@ CONFIG_CMD_HELP=y
 CONFIG_CMD_DEVINFO=y
 CONFIG_CMD_BMP=y
 CONFIG_CMD_GPIO=y
+CONFIG_CMD_UNLZO=y
 CONFIG_NET=y
 CONFIG_NET_DHCP=y
 # CONFIG_NET_RARP is not set
@@ -243,5 +246,9 @@ CONFIG_DRIVER_VIDEO_IMX=y
 # CONFIG_FS_CRAMFS is not set
 CONFIG_FS_RAMFS=y
 CONFIG_FS_DEVFS=y
+CONFIG_ZLIB=y
+CONFIG_BZLIB=y
 CONFIG_CRC32=y
 # CONFIG_GENERIC_FIND_NEXT_BIT is not set
+CONFIG_PROCESS_ESCAPE_SEQUENCE=y
+CONFIG_LZO_DECOMPRESS=y
-- 
1.6.3.3



From eric at eukrea.com  Thu Jun 10 03:55:36 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Thu, 10 Jun 2010 09:55:36 +0200
Subject: [PATCH] cpuimx25: remove unused define
Message-ID: <1276156536-8062-1-git-send-email-eric@eukrea.com>

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 board/eukrea_cpuimx25/eukrea_cpuimx25.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/board/eukrea_cpuimx25/eukrea_cpuimx25.c b/board/eukrea_cpuimx25/eukrea_cpuimx25.c
index 8cbbc4f..b19efcc 100644
--- a/board/eukrea_cpuimx25/eukrea_cpuimx25.c
+++ b/board/eukrea_cpuimx25/eukrea_cpuimx25.c
@@ -63,8 +63,6 @@ struct imx_dcd_entry __dcd_entry_0x400 dcd_entry[] = {
 	{ .ptr_type = 4, .addr = 0x53f80008, .val = 0x20034000, },
 };
 
-#define APP_DEST	0x80000000
-
 struct imx_flash_header __flash_header_0x400 eukrea_cpuimx25_header = {
 	.app_code_jump_vector	= TEXT_BASE + 0x2000,
 	.app_code_barker	= APP_CODE_BARKER,
-- 
1.6.3.3



From s.hauer at pengutronix.de  Thu Jun 10 07:10:36 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 10 Jun 2010 13:10:36 +0200
Subject: [PATCH 0/8] i.MX25 3DS fixes and enhancements
In-Reply-To: <cover.1276065824.git.baruch@tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
Message-ID: <20100610111035.GG20799@pengutronix.de>

Hi Baruch,

On Wed, Jun 09, 2010 at 10:04:59AM +0300, Baruch Siach wrote:
> This series of patches includes the following:
> 
> 1. Fixes and clean-ups for the i.MX25 3DS board code
> 2. New driver for the i.MX25 3DS on-board PMIC
> 3. Enable proper FEC initialization including PHY power supply enable
> 4. Add support for boot from UART on the i.MX25 3DS

Applied them all except the last one, see the comment there.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 10 07:12:37 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 10 Jun 2010 13:12:37 +0200
Subject: [PATCH 8/8] mx25 3ds: add support for boot from UART
In-Reply-To: <f9f84cc251848d133fae379e6d20253df2121ffb.1276065824.git.baruch@tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
	<f9f84cc251848d133fae379e6d20253df2121ffb.1276065824.git.baruch@tkos.co.il>
Message-ID: <20100610111237.GH20799@pengutronix.de>

On Wed, Jun 09, 2010 at 10:05:07AM +0300, Baruch Siach wrote:
> For details of the UART protocol see the i.MX25 Reference Manual, section 7.8
> "Serial Download protocol".
> 
> Signed-off-by: Baruch Siach <baruch at tkos.co.il>
> ---
>  arch/arm/mach-imx/Kconfig                    |    5 +++++
>  board/freescale-mx25-3-stack/3stack.c        |    4 ++++
>  board/freescale-mx25-3-stack/lowlevel_init.S |    5 +++++
>  3 files changed, 14 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
> index 419daab..40cebed 100644
> --- a/arch/arm/mach-imx/Kconfig
> +++ b/arch/arm/mach-imx/Kconfig
> @@ -319,6 +319,11 @@ config FREESCALE_MX25_3STACK_SDRAM_64MB_DDR2
>  config FREESCALE_MX25_3STACK_SDRAM_128MB_MDDR
>  	bool "128 MB (mDDR)"
>  endchoice
> +
> +config FREESCALE_MX25_3STACK_UART_BOOT
> +	bool "Boot from UART"
> +	depends on ARCH_IMX_INTERNAL_BOOT
> +
>  endif
>  endmenu
>  
> diff --git a/board/freescale-mx25-3-stack/3stack.c b/board/freescale-mx25-3-stack/3stack.c
> index a657a47..081487a 100644
> --- a/board/freescale-mx25-3-stack/3stack.c
> +++ b/board/freescale-mx25-3-stack/3stack.c
> @@ -44,7 +44,11 @@ extern unsigned long _stext;
>  
>  void __naked __flash_header_start go(void)
>  {
> +#if defined CONFIG_FREESCALE_MX25_3STACK_UART_BOOT
> +	__asm__ (".word	exception_vectors\n");
> +#else
>  	__asm__ __volatile__("b exception_vectors\n");
> +#endif

Do we need this change? I booted other i.MX SoCs without it. I really
like to keep this because it enables to jump to the first address if
booting second stage.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 10 07:17:26 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 10 Jun 2010 13:17:26 +0200
Subject: barebox with usb cdc-eth driver?
In-Reply-To: <AANLkTikVBjnjLbC2LZBzRZ0C4FqgxOrbsT-tCgMTqGy8@mail.gmail.com>
References: <AANLkTikVBjnjLbC2LZBzRZ0C4FqgxOrbsT-tCgMTqGy8@mail.gmail.com>
Message-ID: <20100610111726.GI20799@pengutronix.de>

Hi Marek,

On Wed, Jun 09, 2010 at 12:55:47PM +0200, Belisko Marek wrote:
> Hi,
> 
> I'm not sure if this would be possible and also make a sense
> but I think about possibility to add cdc-eth driver to barebox.
> 
> If some board doesn't have a eth interface and could be used for development
> it would be nice to load kernel via usb cdc-eth and also mount rootfs
> via nfs for kernel.

Currently we do not have plans to add support for cdc ethernet, patches
welcome ;)

What we have if dfu support (device firmware upgrade) which can at least
be used to flash images to the board. We also have regular USB
networking support, so if you have a host interface you could use this.

Adding cdc ethernet support should be doable since barebox uses the
Linux Kernel gadget framework.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 10 07:42:02 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 10 Jun 2010 13:42:02 +0200
Subject: [PATCH] Add support for Eukrea CPUIMX35
In-Reply-To: <1276155782-6173-1-git-send-email-eric@eukrea.com>
References: <1276155782-6173-1-git-send-email-eric@eukrea.com>
Message-ID: <20100610114202.GK20799@pengutronix.de>

Hi Eric,

On Thu, Jun 10, 2010 at 09:43:02AM +0200, Eric B?nard wrote:
> +
> +#define MPCTL_PARAM_399     (IMX_PLL_PD(0) | IMX_PLL_MFD(15) | IMX_PLL_MFI(8) | IMX_PLL_MFN(5))
> +#define MPCTL_PARAM_532     ((1 << 31) | IMX_PLL_PD(0) | IMX_PLL_MFD(11) | IMX_PLL_MFI(11) | IMX_PLL_MFN(1))
> +
> +static int do_cpufreq(struct command *cmdtp, int argc, char *argv[])
> +{
> +	unsigned long freq;
> +
> +	if (argc != 2)
> +		return COMMAND_ERROR_USAGE;
> +
> +	freq = simple_strtoul(argv[1], NULL, 0);
> +
> +	switch (freq) {
> +	case 399:
> +		writel(MPCTL_PARAM_399, IMX_CCM_BASE + CCM_MPCTL);
> +		break;
> +	case 532:
> +		writel(MPCTL_PARAM_532, IMX_CCM_BASE + CCM_MPCTL);
> +		break;
> +	default:
> +		return COMMAND_ERROR_USAGE;
> +	}
> +
> +	printf("Switched CPU frequency to %dMHz\n", freq);
> +
> +	return 0;
> +}

I originally added this to the phyCORE i.MX35 board because we had
problems running it at 532 MHz. If you do not have it you probably don't
need it. Though I can keep it if you wish.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 10 07:44:05 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 10 Jun 2010 13:44:05 +0200
Subject: [PATCH 1/2] eukrea_cpuimx25: add compressed logo support
In-Reply-To: <1276156332-7160-1-git-send-email-eric@eukrea.com>
References: <1276156332-7160-1-git-send-email-eric@eukrea.com>
Message-ID: <20100610114405.GL20799@pengutronix.de>

On Thu, Jun 10, 2010 at 09:52:11AM +0200, Eric B?nard wrote:
> Signed-off-by: Eric B?nard <eric at eukrea.com>
> ---
>  board/eukrea_cpuimx25/env/bin/init |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/board/eukrea_cpuimx25/env/bin/init b/board/eukrea_cpuimx25/env/bin/init
> index 8bcc732..335d7ae 100644
> --- a/board/eukrea_cpuimx25/env/bin/init
> +++ b/board/eukrea_cpuimx25/env/bin/init
> @@ -14,6 +14,9 @@ fi
>  
>  if [ -f /env/logo.bmp ]; then
>  	bmp /env/logo.bmp
> +elif [ -f /env/logo.bmp.lzo ]; then
> +	unlzo /env/logo.bmp.lzo /logo.bmp
> +	bmp /logo.bmp
>  fi

So the lzo support also is of other use than only for the kernel.
Nice :)

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From baruch at tkos.co.il  Thu Jun 10 07:49:39 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Thu, 10 Jun 2010 14:49:39 +0300
Subject: [PATCH 8/8] mx25 3ds: add support for boot from UART
In-Reply-To: <20100610111237.GH20799@pengutronix.de>
References: <cover.1276065824.git.baruch@tkos.co.il>
	<f9f84cc251848d133fae379e6d20253df2121ffb.1276065824.git.baruch@tkos.co.il>
	<20100610111237.GH20799@pengutronix.de>
Message-ID: <20100610114939.GF31840@jasper.tkos.co.il>

Hi Sascha,

On Thu, Jun 10, 2010 at 01:12:37PM +0200, Sascha Hauer wrote:
> On Wed, Jun 09, 2010 at 10:05:07AM +0300, Baruch Siach wrote:

[snip]

> > --- a/board/freescale-mx25-3-stack/3stack.c
> > +++ b/board/freescale-mx25-3-stack/3stack.c
> > @@ -44,7 +44,11 @@ extern unsigned long _stext;
> >  
> >  void __naked __flash_header_start go(void)
> >  {
> > +#if defined CONFIG_FREESCALE_MX25_3STACK_UART_BOOT
> > +	__asm__ (".word	exception_vectors\n");
> > +#else
> >  	__asm__ __volatile__("b exception_vectors\n");
> > +#endif
> 
> Do we need this change? I booted other i.MX SoCs without it. I really
> like to keep this because it enables to jump to the first address if
> booting second stage.

This is actually a (very) short "flash" header with only the 
app_code_jump_vector entry left. Only reverse engineering the Freescale ATK 
software revealed this secret. Reading through the i.MX25 Reference Manual I 
now see that there is an option to pass DCD separately, but it complicates the 
boot sequence.  This change only affects builds when this configuration 
option, and this option is disabled by default.

baruch

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -


From list at lucaceresoli.net  Tue Jun  8 04:02:44 2010
From: list at lucaceresoli.net (Luca Ceresoli)
Date: Tue,  8 Jun 2010 10:02:44 +0200
Subject: OMAP 3530 arch_shutdown "undefined instruction"
Message-ID: <L3OROK$8E14E73C17D97B7C877E590EED33976C@aruba.it>

Orjan Friberg wrote:> On 2010-05-27 11:31, Sascha Hauer wrote:
> > Seems this does not work on Cortex Processors. Can you try replacing
> > this with the following please:
> >
> > 	asm volatile (
> > 		"bl __mmu_cache_flush;"
> > 		"bl __mmu_cache_off;"
> > 		:
> > 		:
> > 		: "r0", "r1", "r2", "r3", "r6", "r10", "r12", "cc", "memory"
> > 	);
> 
> Thanks, this seems to work fine (in the sense that I can load and run a 
> second stage bootloader; I haven't tried verifying what happens with the 
> I and D cache).

Works for me as well.
Is it going to be committed?

Thanks,
Luca




From s.hauer at pengutronix.de  Thu Jun 10 07:54:54 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 10 Jun 2010 13:54:54 +0200
Subject: [PATCH] mx2 GPIO OCRx register
In-Reply-To: <1275991382.18173.37.camel@lws-gamez>
References: <1275991382.18173.37.camel@lws-gamez>
Message-ID: <20100610115454.GN20799@pengutronix.de>

Hi Teresa,

On Tue, Jun 08, 2010 at 12:03:02PM +0200, Teresa Gamez wrote:
> The GPIO OCRx register has to be set correct or the output is not set as expected.

No. The gpio functions are not expected to change the iomuxer. This is
what imx_gpio_mode() is for.

Sascha


> 
> Signed-off-by: Teresa G?mez <T.Gamez at phytec.de> 
> ---
> Index: barebox-2010.06.0/arch/arm/mach-imx/gpio.c
> ===================================================================
> --- barebox-2010.06.0/arch/arm/mach-imx/gpio.c	2010-06-02 10:36:28.000000000 +0200
> +++ barebox-2010.06.0/arch/arm/mach-imx/gpio.c	2010-06-08 11:02:31.282473877 +0200
> @@ -31,6 +31,8 @@
>  #if defined CONFIG_ARCH_IMX1 || defined CONFIG_ARCH_IMX21 || defined CONFIG_ARCH_IMX27
>  #define GPIO_DR		0x1c
>  #define GPIO_GDIR	0x00
> +#define GPIO_OCR1	0x04
> +#define GPIO_OCR2	0x08
>  #define GPIO_PSR	0x24
>  #define GPIO_ICR1	0x28
>  #define GPIO_ICR2	0x2C
> @@ -103,6 +105,18 @@
>  	if (!base)
>  		return -EINVAL;
>  
> +#if defined GPIO_OCR1 && defined GPIO_OCR2
> +	if (shift < 16) {
> +		val = readl(base + GPIO_OCR1);
> +		val |= (3 << (shift * 2));
> +		writel(val, base + GPIO_OCR1);
> +	} else {
> +		val = readl(base + GPIO_OCR2);
> +		val |= (3 << ((shift - 16) * 2));
> +		writel(val, base + GPIO_OCR2);
> +	}
> +#endif
> +
>  	gpio_set_value(gpio, value);
>  
>  	val = readl(base + GPIO_GDIR);
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 10 08:12:08 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 10 Jun 2010 14:12:08 +0200
Subject: [PATCH 8/8] mx25 3ds: add support for boot from UART
In-Reply-To: <20100610114939.GF31840@jasper.tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
	<f9f84cc251848d133fae379e6d20253df2121ffb.1276065824.git.baruch@tkos.co.il>
	<20100610111237.GH20799@pengutronix.de>
	<20100610114939.GF31840@jasper.tkos.co.il>
Message-ID: <20100610121208.GO20799@pengutronix.de>

On Thu, Jun 10, 2010 at 02:49:39PM +0300, Baruch Siach wrote:
> Hi Sascha,
> 
> On Thu, Jun 10, 2010 at 01:12:37PM +0200, Sascha Hauer wrote:
> > On Wed, Jun 09, 2010 at 10:05:07AM +0300, Baruch Siach wrote:
> 
> [snip]
> 
> > > --- a/board/freescale-mx25-3-stack/3stack.c
> > > +++ b/board/freescale-mx25-3-stack/3stack.c
> > > @@ -44,7 +44,11 @@ extern unsigned long _stext;
> > >  
> > >  void __naked __flash_header_start go(void)
> > >  {
> > > +#if defined CONFIG_FREESCALE_MX25_3STACK_UART_BOOT
> > > +	__asm__ (".word	exception_vectors\n");
> > > +#else
> > >  	__asm__ __volatile__("b exception_vectors\n");
> > > +#endif
> > 
> > Do we need this change? I booted other i.MX SoCs without it. I really
> > like to keep this because it enables to jump to the first address if
> > booting second stage.
> 
> This is actually a (very) short "flash" header with only the 
> app_code_jump_vector entry left. Only reverse engineering the Freescale ATK 
> software revealed this secret. Reading through the i.MX25 Reference Manual I 
> now see that there is an option to pass DCD separately, but it complicates the 
> boot sequence.  This change only affects builds when this configuration 
> option, and this option is disabled by default.

What do you use to upload images? I once updated my favourite terminal
program microcom (git://git.pengutronix.de/git/tools/microcom) to be
able to upload and start images. I didn't need any special images. I
just used the ability to write registers to initialize the SDRAM and
then uploaded an image to sdram with image type 0xaa which seems to
just start the image at the given address. Find a log attached (which is
on an i.MX27, but I tested it on i.MX35 and i.MX51 aswell)
Maybe this could be a solution for you aswell.

Anyway, that said, I can apply your patch, too. I just find it very
comfortable to use one image for all boot scenarios.

Sascha

sha at kiwi:~/octopus/microcom/microcom ./microcom -p /dev/ttyS0 -f
connected to /dev/ttyS0
Escape character: Ctrl-\
Type the escape character followed by c to get to the menu or q to quit

barebox:/
Enter command. Try 'help' for a list of builtin commands
-> x b
mw 0xD8001010 0x00000004
mw 0xD8001004 0x006ac73a
mw 0xD8001000 0x92100000
mw 0xA0000f00 0x12344321
mw 0xD8001000 0xa2100000
mw 0xA0000000 0x12344321
mw 0xA0000000 0x12344321
mw 0xD8001000 0xb2100000
mwb 0xA0000033 0xda
mwb 0xA1000000 0xff
mw 0xD8001000 0x82226080
mw 0xA0000000 0xDEADBEEF
mw 0xD8001010 0x0000000c
upload 0xa0000000 /home/sha/octopus/barebox/barebox/barebox-pcm038.bin 0xaa
image type: 0xaa

    ################################################################
    ################################################################
    ########################################

----------------------
????

barebox 2010.04.0-00140-g0a28ada-dirty (Apr 15 2010 - 11:40:21)

Board: Phytec phyCORE-i.MX27
cfi_probe: cfi_flash base: 0xc0000000 size: 0x02000000
NAND device: Manufacturer ID: 0x20, Chip ID: 0x36 (ST Micro NAND 64MiB
1,8V 8-bit)
Bad block table found at page 131040, version 0x01
Bad block table found at page 131008, version 0x01
imxfb at imxfb0: i.MX Framebuffer driver
ULPI Vendor ID 0xffffff92    Product ID 0xffffff92
No ISP1504 found
ehci at ehci0: USB EHCI 1.00
cfi_protect: protect 0xc0040000 (size 131072)

Using environment in NOR Flash
initialising PLLs: 0xa7f1ea18 0xa7f291f4
Malloc space: 0xa6f00000 -> 0xa7f00000 (size 16 MB)
Stack space : 0xa6ef8000 -> 0xa6f00000 (size 32 kB)
running /env/bin/init...

Hit any key to stop autoboot:  2

type update_kernel nand|nor [<imagename>] to update kernel into flash
type update_root nand|nor [<imagename>] to update rootfs into flash

barebox:/

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

> 
> baruch
> 
> -- 
>                                                      ~. .~   Tk Open Systems
> =}------------------------------------------------ooO--U--Ooo------------{=
>    - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 10 08:22:42 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 10 Jun 2010 14:22:42 +0200
Subject: OMAP 3530 arch_shutdown "undefined instruction"
In-Reply-To: <L3OROK$8E14E73C17D97B7C877E590EED33976C@aruba.it>
References: <L3OROK$8E14E73C17D97B7C877E590EED33976C@aruba.it>
Message-ID: <20100610122242.GP20799@pengutronix.de>

On Tue, Jun 08, 2010 at 10:02:44AM +0200, Luca Ceresoli wrote:
> Orjan Friberg wrote:> On 2010-05-27 11:31, Sascha Hauer wrote:
> > > Seems this does not work on Cortex Processors. Can you try replacing
> > > this with the following please:
> > >
> > > 	asm volatile (
> > > 		"bl __mmu_cache_flush;"
> > > 		"bl __mmu_cache_off;"
> > > 		:
> > > 		:
> > > 		: "r0", "r1", "r2", "r3", "r6", "r10", "r12", "cc", "memory"
> > > 	);
> > 
> > Thanks, this seems to work fine (in the sense that I can load and run a 
> > second stage bootloader; I haven't tried verifying what happens with the 
> > I and D cache).
> 
> Works for me as well.
> Is it going to be committed?

Ok, done.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From baruch at tkos.co.il  Thu Jun 10 08:42:46 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Thu, 10 Jun 2010 15:42:46 +0300
Subject: [PATCH 8/8] mx25 3ds: add support for boot from UART
In-Reply-To: <20100610121208.GO20799@pengutronix.de>
References: <cover.1276065824.git.baruch@tkos.co.il>
	<f9f84cc251848d133fae379e6d20253df2121ffb.1276065824.git.baruch@tkos.co.il>
	<20100610111237.GH20799@pengutronix.de>
	<20100610114939.GF31840@jasper.tkos.co.il>
	<20100610121208.GO20799@pengutronix.de>
Message-ID: <20100610124246.GG31840@jasper.tkos.co.il>

Hi Sascha,

On Thu, Jun 10, 2010 at 02:12:08PM +0200, Sascha Hauer wrote:
> On Thu, Jun 10, 2010 at 02:49:39PM +0300, Baruch Siach wrote:
> > On Thu, Jun 10, 2010 at 01:12:37PM +0200, Sascha Hauer wrote:
> > > On Wed, Jun 09, 2010 at 10:05:07AM +0300, Baruch Siach wrote:
> > 
> > [snip]
> > 
> > > > --- a/board/freescale-mx25-3-stack/3stack.c
> > > > +++ b/board/freescale-mx25-3-stack/3stack.c
> > > > @@ -44,7 +44,11 @@ extern unsigned long _stext;
> > > >  
> > > >  void __naked __flash_header_start go(void)
> > > >  {
> > > > +#if defined CONFIG_FREESCALE_MX25_3STACK_UART_BOOT
> > > > +	__asm__ (".word	exception_vectors\n");
> > > > +#else
> > > >  	__asm__ __volatile__("b exception_vectors\n");
> > > > +#endif
> > > 
> > > Do we need this change? I booted other i.MX SoCs without it. I really
> > > like to keep this because it enables to jump to the first address if
> > > booting second stage.
> > 
> > This is actually a (very) short "flash" header with only the 
> > app_code_jump_vector entry left. Only reverse engineering the Freescale ATK 
> > software revealed this secret. Reading through the i.MX25 Reference Manual I 
> > now see that there is an option to pass DCD separately, but it complicates the 
> > boot sequence.  This change only affects builds when this configuration 
> > option, and this option is disabled by default.
> 
> What do you use to upload images?

I use a custom Perl script that parses a .inc file with the same syntax as the 
those distributed with the Freescale ATK. This script and the .inc file are 
attached.

> I once updated my favourite terminal program microcom 
> (git://git.pengutronix.de/git/tools/microcom) to be
> able to upload and start images. I didn't need any special images. I
> just used the ability to write registers to initialize the SDRAM and
> then uploaded an image to sdram with image type 0xaa which seems to
> just start the image at the given address.

What is this "given address"? Is this the same address as the image load 
address, i.e., the first instruction in the image?

> Find a log attached (which is on an i.MX27, but I tested it on i.MX35 and 
> i.MX51 aswell) Maybe this could be a solution for you aswell.

This could really simplify things. Is this support integrated in the git 
version of microcom?

Some more question below.

> Anyway, that said, I can apply your patch, too. I just find it very
> comfortable to use one image for all boot scenarios.
> 
> Sascha
> 
> sha at kiwi:~/octopus/microcom/microcom ./microcom -p /dev/ttyS0 -f
> connected to /dev/ttyS0
> Escape character: Ctrl-\
> Type the escape character followed by c to get to the menu or q to quit
> 
> barebox:/
> Enter command. Try 'help' for a list of builtin commands
> -> x b

Do you have Barebox running on the board at this point?
Is the above 'x b' a special microcom command, or a Barebox script?

I must say that Barebox is much more fun to work with than RedBoot. A huge 
improvement.

Thanks.

baruch

> mw 0xD8001010 0x00000004
> mw 0xD8001004 0x006ac73a
> mw 0xD8001000 0x92100000
> mw 0xA0000f00 0x12344321
> mw 0xD8001000 0xa2100000
> mw 0xA0000000 0x12344321
> mw 0xA0000000 0x12344321
> mw 0xD8001000 0xb2100000
> mwb 0xA0000033 0xda
> mwb 0xA1000000 0xff
> mw 0xD8001000 0x82226080
> mw 0xA0000000 0xDEADBEEF
> mw 0xD8001010 0x0000000c
> upload 0xa0000000 /home/sha/octopus/barebox/barebox/barebox-pcm038.bin 0xaa
> image type: 0xaa
> 
>     ################################################################
>     ################################################################
>     ########################################
> 
> ----------------------
> ????
> 
> barebox 2010.04.0-00140-g0a28ada-dirty (Apr 15 2010 - 11:40:21)
> 
> Board: Phytec phyCORE-i.MX27
> cfi_probe: cfi_flash base: 0xc0000000 size: 0x02000000
> NAND device: Manufacturer ID: 0x20, Chip ID: 0x36 (ST Micro NAND 64MiB
> 1,8V 8-bit)
> Bad block table found at page 131040, version 0x01
> Bad block table found at page 131008, version 0x01
> imxfb at imxfb0: i.MX Framebuffer driver
> ULPI Vendor ID 0xffffff92    Product ID 0xffffff92
> No ISP1504 found
> ehci at ehci0: USB EHCI 1.00
> cfi_protect: protect 0xc0040000 (size 131072)
> 
> Using environment in NOR Flash
> initialising PLLs: 0xa7f1ea18 0xa7f291f4
> Malloc space: 0xa6f00000 -> 0xa7f00000 (size 16 MB)
> Stack space : 0xa6ef8000 -> 0xa6f00000 (size 32 kB)
> running /env/bin/init...
> 
> Hit any key to stop autoboot:  2
> 
> type update_kernel nand|nor [<imagename>] to update kernel into flash
> type update_root nand|nor [<imagename>] to update rootfs into flash
> 
> barebox:/

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -


From baruch at tkos.co.il  Thu Jun 10 08:46:32 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Thu, 10 Jun 2010 15:46:32 +0300
Subject: [PATCH 8/8] mx25 3ds: add support for boot from UART
In-Reply-To: <20100610124246.GG31840@jasper.tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
	<f9f84cc251848d133fae379e6d20253df2121ffb.1276065824.git.baruch@tkos.co.il>
	<20100610111237.GH20799@pengutronix.de>
	<20100610114939.GF31840@jasper.tkos.co.il>
	<20100610121208.GO20799@pengutronix.de>
	<20100610124246.GG31840@jasper.tkos.co.il>
Message-ID: <20100610124632.GI31840@jasper.tkos.co.il>

Hi Sascha,

Now really attaching the files.

baruch

On Thu, Jun 10, 2010 at 03:42:46PM +0300, Baruch Siach wrote:
> Hi Sascha,
> 
> On Thu, Jun 10, 2010 at 02:12:08PM +0200, Sascha Hauer wrote:
> > On Thu, Jun 10, 2010 at 02:49:39PM +0300, Baruch Siach wrote:
> > > On Thu, Jun 10, 2010 at 01:12:37PM +0200, Sascha Hauer wrote:
> > > > On Wed, Jun 09, 2010 at 10:05:07AM +0300, Baruch Siach wrote:
> > > 
> > > [snip]
> > > 
> > > > > --- a/board/freescale-mx25-3-stack/3stack.c
> > > > > +++ b/board/freescale-mx25-3-stack/3stack.c
> > > > > @@ -44,7 +44,11 @@ extern unsigned long _stext;
> > > > >  
> > > > >  void __naked __flash_header_start go(void)
> > > > >  {
> > > > > +#if defined CONFIG_FREESCALE_MX25_3STACK_UART_BOOT
> > > > > +	__asm__ (".word	exception_vectors\n");
> > > > > +#else
> > > > >  	__asm__ __volatile__("b exception_vectors\n");
> > > > > +#endif
> > > > 
> > > > Do we need this change? I booted other i.MX SoCs without it. I really
> > > > like to keep this because it enables to jump to the first address if
> > > > booting second stage.
> > > 
> > > This is actually a (very) short "flash" header with only the 
> > > app_code_jump_vector entry left. Only reverse engineering the Freescale ATK 
> > > software revealed this secret. Reading through the i.MX25 Reference Manual I 
> > > now see that there is an option to pass DCD separately, but it complicates the 
> > > boot sequence.  This change only affects builds when this configuration 
> > > option, and this option is disabled by default.
> > 
> > What do you use to upload images?
> 
> I use a custom Perl script that parses a .inc file with the same syntax as the 
> those distributed with the Freescale ATK. This script and the .inc file are 
> attached.
> 
> > I once updated my favourite terminal program microcom 
> > (git://git.pengutronix.de/git/tools/microcom) to be
> > able to upload and start images. I didn't need any special images. I
> > just used the ability to write registers to initialize the SDRAM and
> > then uploaded an image to sdram with image type 0xaa which seems to
> > just start the image at the given address.
> 
> What is this "given address"? Is this the same address as the image load 
> address, i.e., the first instruction in the image?
> 
> > Find a log attached (which is on an i.MX27, but I tested it on i.MX35 and 
> > i.MX51 aswell) Maybe this could be a solution for you aswell.
> 
> This could really simplify things. Is this support integrated in the git 
> version of microcom?
> 
> Some more question below.
> 
> > Anyway, that said, I can apply your patch, too. I just find it very
> > comfortable to use one image for all boot scenarios.
> > 
> > Sascha
> > 
> > sha at kiwi:~/octopus/microcom/microcom ./microcom -p /dev/ttyS0 -f
> > connected to /dev/ttyS0
> > Escape character: Ctrl-\
> > Type the escape character followed by c to get to the menu or q to quit
> > 
> > barebox:/
> > Enter command. Try 'help' for a list of builtin commands
> > -> x b
> 
> Do you have Barebox running on the board at this point?
> Is the above 'x b' a special microcom command, or a Barebox script?
> 
> I must say that Barebox is much more fun to work with than RedBoot. A huge 
> improvement.
> 
> Thanks.
> 
> baruch
> 
> > mw 0xD8001010 0x00000004
> > mw 0xD8001004 0x006ac73a
> > mw 0xD8001000 0x92100000
> > mw 0xA0000f00 0x12344321
> > mw 0xD8001000 0xa2100000
> > mw 0xA0000000 0x12344321
> > mw 0xA0000000 0x12344321
> > mw 0xD8001000 0xb2100000
> > mwb 0xA0000033 0xda
> > mwb 0xA1000000 0xff
> > mw 0xD8001000 0x82226080
> > mw 0xA0000000 0xDEADBEEF
> > mw 0xD8001010 0x0000000c
> > upload 0xa0000000 /home/sha/octopus/barebox/barebox/barebox-pcm038.bin 0xaa
> > image type: 0xaa
> > 
> >     ################################################################
> >     ################################################################
> >     ########################################
> > 
> > ----------------------
> > ????
> > 
> > barebox 2010.04.0-00140-g0a28ada-dirty (Apr 15 2010 - 11:40:21)
> > 
> > Board: Phytec phyCORE-i.MX27
> > cfi_probe: cfi_flash base: 0xc0000000 size: 0x02000000
> > NAND device: Manufacturer ID: 0x20, Chip ID: 0x36 (ST Micro NAND 64MiB
> > 1,8V 8-bit)
> > Bad block table found at page 131040, version 0x01
> > Bad block table found at page 131008, version 0x01
> > imxfb at imxfb0: i.MX Framebuffer driver
> > ULPI Vendor ID 0xffffff92    Product ID 0xffffff92
> > No ISP1504 found
> > ehci at ehci0: USB EHCI 1.00
> > cfi_protect: protect 0xc0040000 (size 131072)
> > 
> > Using environment in NOR Flash
> > initialising PLLs: 0xa7f1ea18 0xa7f291f4
> > Malloc space: 0xa6f00000 -> 0xa7f00000 (size 16 MB)
> > Stack space : 0xa6ef8000 -> 0xa6f00000 (size 32 kB)
> > running /env/bin/init...
> > 
> > Hit any key to stop autoboot:  2
> > 
> > type update_kernel nand|nor [<imagename>] to update kernel into flash
> > type update_root nand|nor [<imagename>] to update rootfs into flash
> > 
> > barebox:/

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
-------------- next part --------------
A non-text attachment was scrubbed...
Name: imx_uart_boot.pl
Type: text/x-perl
Size: 5274 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20100610/5f47ae64/attachment-0001.bin>
-------------- next part --------------
; WEIM config-CS5 init -- CPLD
setmem /32 0xB8002050 = 0x0000D843
setmem /32 0xB8002054 = 0x22252521
setmem /32 0xB8002058 = 0x22220A00

; DDR2 init
setmem /32 0xB8001004 = 0x0076E83A
setmem /32 0xB8001010 = 0x00000204
setmem /32 0xB8001000 = 0x92210000
setmem /32 0x80000f00 = 0x12344321
setmem /32 0xB8001000 = 0xB2210000
setmem /8  0x82000000 = 0xda
setmem /8  0x83000000 = 0xda
setmem /8  0x81000000 = 0xda
setmem /8  0x80000333 = 0xda

setmem /32 0xB8001000 = 0x92210000
setmem /8  0x80000400 = 0x12345678

setmem /32 0xB8001000 = 0xA2210000
setmem /32 0x80000000 = 0x87654321
setmem /32 0x80000000 = 0x87654321

setmem /32 0xB8001000 = 0xB2210000
setmem /8  0x80000233 = 0xda
setmem /8  0x81000780 = 0xda
setmem /8  0x81000400 = 0xda

setmem /32 0xB8001000 = 0x82216080

setmem /32 0x43FAC454 = 0x00001000

setmem /32 0x80000000 = 0x00000000

;setmem /32 0x53F80008 = 0x20034000

readfile,raw,gui "barebox.bin"=0x83f00000

From eric at eukrea.com  Thu Jun 10 09:18:36 2010
From: eric at eukrea.com (=?ISO-8859-15?Q?Eric_B=E9nard?=)
Date: Thu, 10 Jun 2010 15:18:36 +0200
Subject: [PATCH 1/2] eukrea_cpuimx25: add compressed logo support
In-Reply-To: <20100610114405.GL20799@pengutronix.de>
References: <1276156332-7160-1-git-send-email-eric@eukrea.com>
	<20100610114405.GL20799@pengutronix.de>
Message-ID: <4C10E62C.3020808@eukrea.com>

Le 10/06/2010 13:44, Sascha Hauer a ?crit :
> On Thu, Jun 10, 2010 at 09:52:11AM +0200, Eric B?nard wrote:
>> Signed-off-by: Eric B?nard<eric at eukrea.com>
>> ---
>>   board/eukrea_cpuimx25/env/bin/init |    3 +++
>>   1 files changed, 3 insertions(+), 0 deletions(-)
>>
>> diff --git a/board/eukrea_cpuimx25/env/bin/init b/board/eukrea_cpuimx25/env/bin/init
>> index 8bcc732..335d7ae 100644
>> --- a/board/eukrea_cpuimx25/env/bin/init
>> +++ b/board/eukrea_cpuimx25/env/bin/init
>> @@ -14,6 +14,9 @@ fi
>>
>>   if [ -f /env/logo.bmp ]; then
>>   	bmp /env/logo.bmp
>> +elif [ -f /env/logo.bmp.lzo ]; then
>> +	unlzo /env/logo.bmp.lzo /logo.bmp
>> +	bmp /logo.bmp
>>   fi
>
> So the lzo support also is of other use than only for the kernel.
> Nice :)
>
yes, that allow to have a 1 sector environement even with an 
uncompressed BMP logo !

Thanks,
Eric


From eric at eukrea.com  Thu Jun 10 09:26:43 2010
From: eric at eukrea.com (=?ISO-8859-15?Q?Eric_B=E9nard?=)
Date: Thu, 10 Jun 2010 15:26:43 +0200
Subject: [PATCH] Add support for Eukrea CPUIMX35
In-Reply-To: <20100610114202.GK20799@pengutronix.de>
References: <1276155782-6173-1-git-send-email-eric@eukrea.com>
	<20100610114202.GK20799@pengutronix.de>
Message-ID: <4C10E813.5080904@eukrea.com>

Hi Sascha,

Le 10/06/2010 13:42, Sascha Hauer a ?crit :
> I originally added this to the phyCORE i.MX35 board because we had
> problems running it at 532 MHz. If you do not have it you probably don't
> need it. Though I can keep it if you wish.
>
in fact this may be interesting for configurations where the CPU speed 
can be 400MHz to reduce power consumption. In that case, barebox could 
start at 400MHz and /env/bin/init would set the speed depending on 
/env/config variable. So you can keep it for now.

Thanks,
Eric


From s.hauer at pengutronix.de  Thu Jun 10 09:56:44 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 10 Jun 2010 15:56:44 +0200
Subject: [PATCH 8/8] mx25 3ds: add support for boot from UART
In-Reply-To: <20100610124246.GG31840@jasper.tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
	<f9f84cc251848d133fae379e6d20253df2121ffb.1276065824.git.baruch@tkos.co.il>
	<20100610111237.GH20799@pengutronix.de>
	<20100610114939.GF31840@jasper.tkos.co.il>
	<20100610121208.GO20799@pengutronix.de>
	<20100610124246.GG31840@jasper.tkos.co.il>
Message-ID: <20100610135644.GR20799@pengutronix.de>

On Thu, Jun 10, 2010 at 03:42:46PM +0300, Baruch Siach wrote:
> Hi Sascha,
> 
> On Thu, Jun 10, 2010 at 02:12:08PM +0200, Sascha Hauer wrote:
> > On Thu, Jun 10, 2010 at 02:49:39PM +0300, Baruch Siach wrote:
> > > On Thu, Jun 10, 2010 at 01:12:37PM +0200, Sascha Hauer wrote:
> > > > On Wed, Jun 09, 2010 at 10:05:07AM +0300, Baruch Siach wrote:
> > > 
> > > [snip]
> > > 
> > > > > --- a/board/freescale-mx25-3-stack/3stack.c
> > > > > +++ b/board/freescale-mx25-3-stack/3stack.c
> > > > > @@ -44,7 +44,11 @@ extern unsigned long _stext;
> > > > >  
> > > > >  void __naked __flash_header_start go(void)
> > > > >  {
> > > > > +#if defined CONFIG_FREESCALE_MX25_3STACK_UART_BOOT
> > > > > +	__asm__ (".word	exception_vectors\n");
> > > > > +#else
> > > > >  	__asm__ __volatile__("b exception_vectors\n");
> > > > > +#endif
> > > > 
> > > > Do we need this change? I booted other i.MX SoCs without it. I really
> > > > like to keep this because it enables to jump to the first address if
> > > > booting second stage.
> > > 
> > > This is actually a (very) short "flash" header with only the 
> > > app_code_jump_vector entry left. Only reverse engineering the Freescale ATK 
> > > software revealed this secret. Reading through the i.MX25 Reference Manual I 
> > > now see that there is an option to pass DCD separately, but it complicates the 
> > > boot sequence.  This change only affects builds when this configuration 
> > > option, and this option is disabled by default.
> > 
> > What do you use to upload images?
> 
> I use a custom Perl script that parses a .inc file with the same syntax as the 
> those distributed with the Freescale ATK. This script and the .inc file are 
> attached.
> 
> > I once updated my favourite terminal program microcom 
> > (git://git.pengutronix.de/git/tools/microcom) to be
> > able to upload and start images. I didn't need any special images. I
> > just used the ability to write registers to initialize the SDRAM and
> > then uploaded an image to sdram with image type 0xaa which seems to
> > just start the image at the given address.
> 
> What is this "given address"? Is this the same address as the image load 
> address, i.e., the first instruction in the image?

Yes.

> 
> > Find a log attached (which is on an i.MX27, but I tested it on i.MX35 and 
> > i.MX51 aswell) Maybe this could be a solution for you aswell.
> 
> This could really simplify things. Is this support integrated in the git 
> version of microcom?

It is now. It's in the cli-fsl branch.

> 
> Some more question below.
> 
> > Anyway, that said, I can apply your patch, too. I just find it very
> > comfortable to use one image for all boot scenarios.
> > 
> > Sascha
> > 
> > sha at kiwi:~/octopus/microcom/microcom ./microcom -p /dev/ttyS0 -f
> > connected to /dev/ttyS0
> > Escape character: Ctrl-\
> > Type the escape character followed by c to get to the menu or q to quit
> > 
> > barebox:/

Ok, barebox is running here, but...

> > Enter command. Try 'help' for a list of builtin commands

I pressed the escape sequence for microcom here and pushed the reset
button. The board is in UART boot mode now and waits.

> > -> x b

This is to execute a (microcom) script. It just executes the 'mw'
instructions below. (In microcom, they are just named after the barebox
pendants)

> 
> Do you have Barebox running on the board at this point?
> Is the above 'x b' a special microcom command, or a Barebox script?


> 
> I must say that Barebox is much more fun to work with than RedBoot. A huge 
> improvement.

Thanks, nice to hear ;)

> 
> Thanks.
> 
> baruch
> 
> > mw 0xD8001010 0x00000004
> > mw 0xD8001004 0x006ac73a
> > mw 0xD8001000 0x92100000
> > mw 0xA0000f00 0x12344321
> > mw 0xD8001000 0xa2100000
> > mw 0xA0000000 0x12344321
> > mw 0xA0000000 0x12344321
> > mw 0xD8001000 0xb2100000
> > mwb 0xA0000033 0xda
> > mwb 0xA1000000 0xff
> > mw 0xD8001000 0x82226080
> > mw 0xA0000000 0xDEADBEEF
> > mw 0xD8001010 0x0000000c
> > upload 0xa0000000 /home/sha/octopus/barebox/barebox/barebox-pcm038.bin 0xaa
> > image type: 0xaa
> > 
> >     ################################################################
> >     ################################################################
> >     ########################################
> > 
> > ----------------------
> > ????
> > 
> > barebox 2010.04.0-00140-g0a28ada-dirty (Apr 15 2010 - 11:40:21)
> > 
> > Board: Phytec phyCORE-i.MX27
> > cfi_probe: cfi_flash base: 0xc0000000 size: 0x02000000
> > NAND device: Manufacturer ID: 0x20, Chip ID: 0x36 (ST Micro NAND 64MiB
> > 1,8V 8-bit)
> > Bad block table found at page 131040, version 0x01
> > Bad block table found at page 131008, version 0x01
> > imxfb at imxfb0: i.MX Framebuffer driver
> > ULPI Vendor ID 0xffffff92    Product ID 0xffffff92
> > No ISP1504 found
> > ehci at ehci0: USB EHCI 1.00
> > cfi_protect: protect 0xc0040000 (size 131072)
> > 
> > Using environment in NOR Flash
> > initialising PLLs: 0xa7f1ea18 0xa7f291f4
> > Malloc space: 0xa6f00000 -> 0xa7f00000 (size 16 MB)
> > Stack space : 0xa6ef8000 -> 0xa6f00000 (size 32 kB)
> > running /env/bin/init...
> > 
> > Hit any key to stop autoboot:  2
> > 
> > type update_kernel nand|nor [<imagename>] to update kernel into flash
> > type update_root nand|nor [<imagename>] to update rootfs into flash
> > 
> > barebox:/
> 
> -- 
>                                                      ~. .~   Tk Open Systems
> =}------------------------------------------------ooO--U--Ooo------------{=
>    - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From eric at eukrea.com  Thu Jun 10 10:38:29 2010
From: eric at eukrea.com (=?ISO-8859-1?Q?Eric_B=E9nard?=)
Date: Thu, 10 Jun 2010 16:38:29 +0200
Subject: barebox for i.MX51
Message-ID: <4C10F8E5.3010600@eukrea.com>

Hi,

Is anyone working on barebox for i.MX51 ?
We actually have u-boot on our i.MX51 boards but I would like to migrate 
to barebox asap so I should start porting i.MX51 to barebox during spare 
time.
If someone has started this work, we could colaborate to avoid 
duplicated work.

Thanks,
Eric


From s.hauer at pengutronix.de  Thu Jun 10 11:00:31 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 10 Jun 2010 17:00:31 +0200
Subject: barebox for i.MX51
In-Reply-To: <4C10F8E5.3010600@eukrea.com>
References: <4C10F8E5.3010600@eukrea.com>
Message-ID: <20100610150031.GT20799@pengutronix.de>

On Thu, Jun 10, 2010 at 04:38:29PM +0200, Eric B?nard wrote:
> Hi,
>
> Is anyone working on barebox for i.MX51 ?
> We actually have u-boot on our i.MX51 boards but I would like to migrate  
> to barebox asap so I should start porting i.MX51 to barebox during spare  
> time.
> If someone has started this work, we could colaborate to avoid  
> duplicated work.

I have started to work on it, but it surely needs some polishing. Find it in
the mx51 branch in the master repository.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From baruch at tkos.co.il  Thu Jun 10 12:09:21 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Thu, 10 Jun 2010 19:09:21 +0300
Subject: [PATCH 8/8] mx25 3ds: add support for boot from UART
In-Reply-To: <20100610135644.GR20799@pengutronix.de>
References: <cover.1276065824.git.baruch@tkos.co.il>
	<f9f84cc251848d133fae379e6d20253df2121ffb.1276065824.git.baruch@tkos.co.il>
	<20100610111237.GH20799@pengutronix.de>
	<20100610114939.GF31840@jasper.tkos.co.il>
	<20100610121208.GO20799@pengutronix.de>
	<20100610124246.GG31840@jasper.tkos.co.il>
	<20100610135644.GR20799@pengutronix.de>
Message-ID: <20100610160920.GJ31840@jasper.tkos.co.il>

Hi Sascha,

On Thu, Jun 10, 2010 at 03:56:44PM +0200, Sascha Hauer wrote:
> On Thu, Jun 10, 2010 at 03:42:46PM +0300, Baruch Siach wrote:
> > On Thu, Jun 10, 2010 at 02:12:08PM +0200, Sascha Hauer wrote:
> > > -> x b
> 
> This is to execute a (microcom) script. It just executes the 'mw'
> instructions below. (In microcom, they are just named after the barebox
> pendants)

OK. You're right. Generating the header at run time makes much more sense. I 
updated my Perl script and .inc file (changed the load address), and I'm now 
able to boot over UART without this patch.

Thank you very much.

baruch

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
-------------- next part --------------
A non-text attachment was scrubbed...
Name: imx_uart_boot.pl
Type: text/x-perl
Size: 5481 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20100610/11b21a38/attachment.bin>
-------------- next part --------------
; WEIM config-CS5 init -- CPLD
setmem /32 0xB8002050 = 0x0000D843
setmem /32 0xB8002054 = 0x22252521
setmem /32 0xB8002058 = 0x22220A00

; DDR2 init
setmem /32 0xB8001004 = 0x0076E83A
setmem /32 0xB8001010 = 0x00000204
setmem /32 0xB8001000 = 0x92210000
setmem /32 0x80000f00 = 0x12344321
setmem /32 0xB8001000 = 0xB2210000
setmem /8  0x82000000 = 0xda
setmem /8  0x83000000 = 0xda
setmem /8  0x81000000 = 0xda
setmem /8  0x80000333 = 0xda

setmem /32 0xB8001000 = 0x92210000
setmem /8  0x80000400 = 0x12345678

setmem /32 0xB8001000 = 0xA2210000
setmem /32 0x80000000 = 0x87654321
setmem /32 0x80000000 = 0x87654321

setmem /32 0xB8001000 = 0xB2210000
setmem /8  0x80000233 = 0xda
setmem /8  0x81000780 = 0xda
setmem /8  0x81000400 = 0xda

setmem /32 0xB8001000 = 0x82216080

setmem /32 0x43FAC454 = 0x00001000

setmem /32 0x80000000 = 0x00000000

;setmem /32 0x53F80008 = 0x20034000

readfile,raw,gui "barebox.bin"=0x83000000

From thomas.petazzoni at free-electrons.com  Sat Jun 12 09:51:21 2010
From: thomas.petazzoni at free-electrons.com (Thomas Petazzoni)
Date: Sat, 12 Jun 2010 15:51:21 +0200
Subject: ARM/AT91 build failure: Error: symbol *ABS* is in a different section
Message-ID: <20100612155121.0909adf8@surf>

Hello,

In barebox 2010.05, the at91sam9263ek defconfig was building properly
with my 2009q1 CodeSourcery ARM toolchain. Barebox 2010.06 no longer
builds with the same defconfig/toolchain. The build failure is:

  CC      arch/arm/cpu/start.o
{standard input}: Assembler messages:
{standard input}:37: Error: symbol *ABS* is in a different section

The commit that introduced the regression is
78104ae181f78d83664fdc7522eb632d9c3b2ec9 (i.e "arm: reimplement startup
code in C").

The part causing the problem is in board_init_lowlevel_return(), more
precisely

    /* Get runtime address of this function */
    __asm__ __volatile__("adr %0, 0":"=r"(r));

I have investigated further for the moment.

Best regards,

Thomas
-- 
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com


From s.hauer at pengutronix.de  Sun Jun 13 07:08:54 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 13 Jun 2010 13:08:54 +0200
Subject: ARM/AT91 build failure: Error: symbol *ABS* is in a different
	section
In-Reply-To: <20100612155121.0909adf8@surf>
References: <20100612155121.0909adf8@surf>
Message-ID: <20100613110854.GV20799@pengutronix.de>

Hi Thomas,

On Sat, Jun 12, 2010 at 03:51:21PM +0200, Thomas Petazzoni wrote:
> Hello,
> 
> In barebox 2010.05, the at91sam9263ek defconfig was building properly
> with my 2009q1 CodeSourcery ARM toolchain. Barebox 2010.06 no longer
> builds with the same defconfig/toolchain. The build failure is:
> 
>   CC      arch/arm/cpu/start.o
> {standard input}: Assembler messages:
> {standard input}:37: Error: symbol *ABS* is in a different section
> 
> The commit that introduced the regression is
> 78104ae181f78d83664fdc7522eb632d9c3b2ec9 (i.e "arm: reimplement startup
> code in C").
> 
> The part causing the problem is in board_init_lowlevel_return(), more
> precisely
> 
>     /* Get runtime address of this function */
>     __asm__ __volatile__("adr %0, 0":"=r"(r));
> 
> I have investigated further for the moment.

This was mentioned before and the result was the following patch. Sorry,
somehow I forgot to check it in. It's now in the master branch.

Sascha

commit c21a7fb9f15ee1fb213e22c0e7a9d0f53b274cb2
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Wed May 19 13:23:43 2010 +0200

    arm start.c: Make runtime function address calculation tolerant for more compilers
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 67d54a6..eea7dcf 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -81,21 +81,24 @@ void __naked __bare_init reset(void)
  */
 void __naked __bare_init board_init_lowlevel_return(void)
 {
-	uint32_t r;
+	uint32_t r, addr;
+
+	/*
+	 * Get runtime address of this function. Do not
+	 * put any code above this.
+	 */
+	__asm__ __volatile__("1: adr %0, 1b":"=r"(addr));
 
 	/* Setup the stack */
 	r = STACK_BASE + STACK_SIZE - 16;
 	__asm__ __volatile__("mov sp, %0" : : "r"(r));
 
-	/* Get runtime address of this function */
-	__asm__ __volatile__("adr %0, 0":"=r"(r));
-
 	/* Get start of binary image */
-	r -= (uint32_t)&board_init_lowlevel_return - TEXT_BASE;
+	addr -= (uint32_t)&board_init_lowlevel_return - TEXT_BASE;
 
 	/* relocate to link address if necessary */
-	if (r != TEXT_BASE)
-		memcpy((void *)TEXT_BASE, (void *)r,
+	if (addr != TEXT_BASE)
+		memcpy((void *)TEXT_BASE, (void *)addr,
 				(unsigned int)&__bss_start - TEXT_BASE);
 
 	/* clear bss */

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun 14 03:43:41 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 09:43:41 +0200
Subject: Some (new-) network stack fixes
Message-ID: <1276501424-3224-1-git-send-email-s.hauer@pengutronix.de>

These patches fix some bugs introduced with the new network stack. I'll
squash them into the original patches.

Sascha



From s.hauer at pengutronix.de  Mon Jun 14 03:43:42 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 09:43:42 +0200
Subject: [PATCH 1/3] tftp: do not forget to close the file in error case
In-Reply-To: <1276501424-3224-1-git-send-email-s.hauer@pengutronix.de>
References: <1276501424-3224-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276501424-3224-2-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/tftp.c |   48 ++++++++++++++++++++++--------------------------
 1 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index b0bc7c5..38d16bc 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -206,31 +206,11 @@ static void tftp_handler(char *packet, unsigned len)
 	}
 }
 
-static int tftp_start(char *filename)
-{
-	char ip1[16];
-
-	tftp_filename = filename;
-
-	printf("TFTP from server %s; Filename: '%s'\nLoading: ",
-			ip_to_string(net_get_serverip(), ip1),
-			tftp_filename);
-
-	tftp_timer_start = get_time_ns();
-	tftp_state = STATE_RRQ;
-	tftp_block = 0;
-
-	tftp_con = net_udp_new(net_get_serverip(), TFTP_PORT, tftp_handler);
-	if (IS_ERR(tftp_con))
-		return PTR_ERR(tftp_con);
-
-	return tftp_send();
-}
-
 static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 {
 	char *localfile;
 	char *remotefile;
+	char ip1[16];
 
 	if (argc < 2)
 		return COMMAND_ERROR_USAGE;
@@ -248,9 +228,25 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 		return 1;
 	}
 
-	tftp_err = tftp_start(remotefile);
+	tftp_con = net_udp_new(net_get_serverip(), TFTP_PORT, tftp_handler);
+	if (IS_ERR(tftp_con)) {
+		tftp_err = PTR_ERR(tftp_con);
+		goto out_close;
+	}
+
+	tftp_filename = remotefile;
+
+	printf("TFTP from server %s; Filename: '%s'\nLoading: ",
+			ip_to_string(net_get_serverip(), ip1),
+			tftp_filename);
+
+	tftp_timer_start = get_time_ns();
+	tftp_state = STATE_RRQ;
+	tftp_block = 0;
+
+	tftp_err = tftp_send();
 	if (tftp_err)
-		goto out;
+		goto out_unreg;
 
 	while (tftp_state != STATE_DONE) {
 		if (ctrlc()) {
@@ -264,11 +260,11 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 			tftp_send();
 		}
 	}
-
+out_unreg:
 	net_unregister(tftp_con);
-
+out_close:
 	close(net_store_fd);
-out:
+
 	if (tftp_err) {
 		printf("\ntftp failed: %s\n", strerror(-tftp_err));
 		unlink(localfile);
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 03:43:44 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 09:43:44 +0200
Subject: [PATCH 3/3] dhcp: do not call net_unregister if net_udp_new failed
In-Reply-To: <1276501424-3224-1-git-send-email-s.hauer@pengutronix.de>
References: <1276501424-3224-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276501424-3224-4-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/dhcp.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index 54c5179..0771964 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -447,13 +447,13 @@ static int do_dhcp(struct command *cmdtp, int argc, char *argv[])
 
 	ret = net_udp_bind(dhcp_con, PORT_BOOTPC);
 	if (ret)
-		goto out;
+		goto out1;
 
 	net_set_ip(0);
 
 	ret = bootp_request(); /* Basically same as BOOTP */
 	if (ret)
-		goto out;
+		goto out1;
 
 	while (dhcp_state != BOUND) {
 		if (ctrlc())
@@ -464,13 +464,13 @@ static int do_dhcp(struct command *cmdtp, int argc, char *argv[])
 			printf("T ");
 			ret = bootp_request();
 			if (ret)
-				goto out;
+				goto out1;
 		}
 	}
 
-out:
+out1:
 	net_unregister(dhcp_con);
-
+out:
 	if (ret)
 		printf("dhcp failed: %s\n", strerror(-ret));
 
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 03:43:43 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 09:43:43 +0200
Subject: [PATCH 2/3] parameter: set p->value to NULL to avoid freeing it again
In-Reply-To: <1276501424-3224-1-git-send-email-s.hauer@pengutronix.de>
References: <1276501424-3224-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276501424-3224-3-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 lib/parameter.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/lib/parameter.c b/lib/parameter.c
index a3d178f..0aa4193 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -129,8 +129,10 @@ int dev_param_set_generic(struct device_d *dev, struct param_d *p,
 {
 	if (p->value)
 		free(p->value);
-	if (!val)
+	if (!val) {
+		p->value = NULL;
 		return 0;
+	}
 	p->value = strdup(val);
 	return 0;
 }
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 05:48:31 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:31 +0200
Subject: [PATCH 01/11] pcm037: Add MMU support
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276508921-3264-2-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/Kconfig |    2 ++
 board/pcm037/pcm037.c     |   31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 419daab..721264b 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -206,7 +206,9 @@ choice
 config MACH_PCM037
 	bool "phyCORE-i.MX31"
 	select MACH_HAS_LOWLEVEL_INIT
+	select HAVE_MMU
 	select USB_ISP1504 if USB
+	select ARCH_HAS_L2X0
 	help
 	  Say Y here if you are using Phytec's phyCORE-i.MX31 (pcm037) equipped
 	  with a Freescale i.MX31 Processor
diff --git a/board/pcm037/pcm037.c b/board/pcm037/pcm037.c
index aee40c6..2e6968b 100644
--- a/board/pcm037/pcm037.c
+++ b/board/pcm037/pcm037.c
@@ -33,6 +33,7 @@
 #include <asm/armlinux.h>
 #include <mach/gpio.h>
 #include <asm/io.h>
+#include <asm/mmu.h>
 #include <partition.h>
 #include <asm/mach-types.h>
 #include <mach/imx-nand.h>
@@ -117,6 +118,7 @@ static struct device_d sdram1_dev = {
 struct imx_nand_platform_data nand_info = {
 	.width = 1,
 	.hw_ecc = 1,
+	.flash_bbt = 1,
 };
 
 static struct device_d nand_dev = {
@@ -226,8 +228,37 @@ static void pcm037_usb_init(void)
 }
 #endif
 
+#ifdef CONFIG_MMU
+static void pcm037_mmu_init(void)
+{
+	mmu_init();
+
+	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
+	arm_create_section(0x90000000, 0x80000000, 128, PMD_SECT_DEF_UNCACHED);
+
+	setup_dma_coherent(0x10000000);
+
+#if TEXT_BASE & (0x100000 - 1)
+#warning cannot create vector section. Adjust TEXT_BASE to a 1M boundary
+#else
+	arm_create_section(0x0,        TEXT_BASE,   1, PMD_SECT_DEF_UNCACHED);
+#endif
+	mmu_enable();
+
+#ifdef CONFIG_CACHE_L2X0
+	l2x0_init((void __iomem *)0x30000000, 0x00030024, 0x00000000);
+#endif
+}
+#else
+static void pcm037_mmu_init(void)
+{
+}
+#endif
+
 static int imx31_devices_init(void)
 {
+	pcm037_mmu_init();
+
 	__REG(CSCR_U(0)) = 0x0000cf03; /* CS0: Nor Flash */
 	__REG(CSCR_L(0)) = 0x10000d03;
 	__REG(CSCR_A(0)) = 0x00720900;
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 05:48:35 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:35 +0200
Subject: [PATCH 05/11] net: implement random_ether_addr
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276508921-3264-6-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/net.h |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/include/net.h b/include/net.h
index 8db83d8..2e17e39 100644
--- a/include/net.h
+++ b/include/net.h
@@ -16,6 +16,8 @@
 #include <linux/types.h>
 #include <param.h>
 #include <malloc.h>
+#include <clock.h>
+#include <random.h>
 #include <asm/byteorder.h>	/* for nton* / ntoh* stuff */
 
 
@@ -331,6 +333,21 @@ static inline int is_broadcast_ether_addr(const u8 *addr)
 }
 
 /**
+ * random_ether_addr - Generate software assigned random Ethernet address
+ * @addr: Pointer to a six-byte array containing the Ethernet address
+ *
+ * Generate a random Ethernet address (MAC) that is not multicast
+ * and has the local assigned bit set.
+ */
+static inline void random_ether_addr(u8 *addr)
+{
+	srand(get_time_ns());
+	get_random_bytes(addr, 6);
+	addr [0] &= 0xfe;	/* clear multicast bit */
+	addr [0] |= 0x02;	/* set local assignment bit (IEEE802) */
+}
+
+/**
  * is_valid_ether_addr - Determine if the given Ethernet address is valid
  * @addr: Pointer to a six-byte array containing the Ethernet address
  *
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 05:48:32 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:32 +0200
Subject: [PATCH 02/11] bootu: Allow passing in devices as parameter
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276508921-3264-3-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/lib/armlinux.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/arm/lib/armlinux.c b/arch/arm/lib/armlinux.c
index 75c6519..a38c6bf 100644
--- a/arch/arm/lib/armlinux.c
+++ b/arch/arm/lib/armlinux.c
@@ -332,15 +332,21 @@ BAREBOX_CMD_END
 #ifdef CONFIG_CMD_BOOTU
 static int do_bootu(struct command *cmdtp, int argc, char *argv[])
 {
-	void (*theKernel)(int zero, int arch, void *params);
+	void (*theKernel)(int zero, int arch, void *params) = NULL;
 	const char *commandline = getenv("bootargs");
+	int fd;
 
 	if (argc != 2) {
 		barebox_cmd_usage(cmdtp);
 		return 1;
 	}
 
-	theKernel = (void *)simple_strtoul(argv[1], NULL, 0);
+	fd = open(argv[1], O_RDONLY);
+	if (fd > 0)
+		theKernel = (void *)memmap(fd, PROT_READ);
+
+	if (!theKernel)
+		theKernel = (void *)simple_strtoul(argv[1], NULL, 0);
 
 	setup_start_tag();
 	setup_memory_tags();
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 05:48:33 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:33 +0200
Subject: [PATCH 03/11] Allow to merge default environment from more than one
	directory
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276508921-3264-4-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 Makefile        |   15 ---------------
 common/Kconfig  |    4 ++--
 common/Makefile |    6 ++++--
 scripts/genenv  |   17 +++++++++++++++++
 4 files changed, 23 insertions(+), 19 deletions(-)
 create mode 100755 scripts/genenv

diff --git a/Makefile b/Makefile
index d17ca47..e24ae45 100644
--- a/Makefile
+++ b/Makefile
@@ -1299,18 +1299,3 @@ Makefile: ;
 # information in a variable se we can use it in if_changed and friends.
 .PHONY: $(PHONY)
 
-#
-# sanity checks for check default environemnt
-#
-ifdef CONFIG_DEFAULT_ENVIRONMENT
-
-ifeq ($(CONFIG_DEFAULT_ENVIRONMENT_PATH),"")
-$(error default environment path empty))
-endif
-
-saved-env_path := $(CONFIG_DEFAULT_ENVIRONMENT_PATH)
-CONFIG_DEFAULT_ENVIRONMENT_PATH := $(shell cd $(if $(filter /%,$(CONFIG_DEFAULT_ENVIRONMENT_PATH)),,$(srctree)/)$(CONFIG_DEFAULT_ENVIRONMENT_PATH) && /bin/pwd)
-$(if $(CONFIG_DEFAULT_ENVIRONMENT_PATH),, \
-	$(error default environment path $(saved-env_path) does not exist))
-
-endif # ifdef CONFIG_DEFAULT_ENVIRONMENT
diff --git a/common/Kconfig b/common/Kconfig
index f514759..a58f242 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -339,8 +339,8 @@ config DEFAULT_ENVIRONMENT_PATH
 	depends on DEFAULT_ENVIRONMENT
 	prompt "Default environment path"
 	help
-	  The path the default environment will be taken from. Relative
-	  pathes will be relative to the barebox Toplevel dir, but absolute
+	  Space separated list of pathes the default environment will be taken from.
+	  Relative pathes will be relative to the barebox Toplevel dir, but absolute
 	  pathes are fine aswell.
 
 endmenu
diff --git a/common/Makefile b/common/Makefile
index 0c075a9..aebaa39 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -15,6 +15,7 @@ obj-y += env.o
 obj-y += startup.o
 obj-y += misc.o
 obj-y += memsize.o
+obj-y += sysdev.o
 obj-$(CONFIG_MODULES) += module.o
 extra-$(CONFIG_MODULES) += module.lds
 
@@ -22,9 +23,10 @@ ifdef CONFIG_DEFAULT_ENVIRONMENT
 $(obj)/startup.o: include/barebox_default_env.h
 $(obj)/env.o: include/barebox_default_env.h
 
-ENV_FILES := $(shell find $(srctree)/$(CONFIG_DEFAULT_ENVIRONMENT_PATH))
+ENV_FILES := $(shell cd $(srctree); for i in $(CONFIG_DEFAULT_ENVIRONMENT_PATH); do find $${i} -type f -exec readlink -f {} \;; done)
+
 endif # ifdef CONFIG_DEFAULT_ENVIRONMENT
 
 include/barebox_default_env.h: $(ENV_FILES)
-	$(Q)scripts/bareboxenv -s $(srctree)/$(CONFIG_DEFAULT_ENVIRONMENT_PATH) barebox_default_env
+	$(Q)scripts/genenv $(srctree) $(CONFIG_DEFAULT_ENVIRONMENT_PATH)
 	$(Q)cat barebox_default_env | scripts/bin2c default_environment > $@
diff --git a/scripts/genenv b/scripts/genenv
new file mode 100755
index 0000000..6a833b1
--- /dev/null
+++ b/scripts/genenv
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# Generate the default environment file from a list of directories
+# usage: genenv <basedir> <dir>...
+# where <basedir> is the base directory for relative pathes in <dir>
+cd $1 || exit 1
+shift
+
+tempdir=$(mktemp -d)
+
+for i in $*; do
+	cp -r $i/* $tempdir
+done
+scripts/bareboxenv -s $tempdir barebox_default_env
+
+rm -r $tempdir
+
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 05:48:36 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:36 +0200
Subject: [PATCH 06/11] net: use a random mac address if the current device
	does not have one
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276508921-3264-7-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/net.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/net/net.c b/net/net.c
index 4305c72..8d99595 100644
--- a/net/net.c
+++ b/net/net.c
@@ -345,12 +345,21 @@ static LIST_HEAD(connection_list);
 
 static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler)
 {
+	struct eth_device *edev = eth_get_current();
 	struct net_connection *con;
 	int ret;
 
-	if (!is_valid_ether_addr(net_ether))
+	if (!edev)
 		return ERR_PTR(-ENETDOWN);
 
+	if (!is_valid_ether_addr(net_ether)) {
+		char str[sizeof("xx:xx:xx:xx:xx:xx")];
+		random_ether_addr(net_ether);
+		ethaddr_to_string(net_ether, str);
+		printf("warning: No MAC address set. Using random address %s\n", str);
+		dev_set_param(&edev->dev, "ethaddr", str);
+	}
+
 	/* If we don't have an ip only broadcast is allowed */
 	if (!net_ip && dest != 0xffffffff)
 		return ERR_PTR(-ENETDOWN);
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 05:48:34 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:34 +0200
Subject: [PATCH 04/11] include support for a simple pseudo number generator
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276508921-3264-5-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/random.h |    7 +++++++
 lib/Makefile     |    1 +
 lib/random.c     |   22 ++++++++++++++++++++++
 3 files changed, 30 insertions(+), 0 deletions(-)
 create mode 100644 include/random.h
 create mode 100644 lib/random.c

diff --git a/include/random.h b/include/random.h
new file mode 100644
index 0000000..29911d8
--- /dev/null
+++ b/include/random.h
@@ -0,0 +1,7 @@
+#ifndef __RANDOM_H
+#define __RANDOM_H
+
+void get_random_bytes(char *buf, int len);
+void srand(unsigned int);
+
+#endif /* __RANDOM_H */
diff --git a/lib/Makefile b/lib/Makefile
index b072fb6..4a33aaa 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
 obj-y			+= glob.o
 obj-y			+= notifier.o
 obj-y			+= copy_file.o
+obj-y			+= random.o
 obj-y			+= lzo/
 obj-$(CONFIG_LZO_DECOMPRESS)		+= decompress_unlzo.o
 obj-$(CONFIG_PROCESS_ESCAPE_SEQUENCE)	+= process_escape_sequence.o
diff --git a/lib/random.c b/lib/random.c
new file mode 100644
index 0000000..25315e7
--- /dev/null
+++ b/lib/random.c
@@ -0,0 +1,22 @@
+#include <common.h>
+#include <random.h>
+
+static int random_seed;
+
+static unsigned char rand(void)
+{
+	random_seed = random_seed * 1103515245 + 12345;
+	return (unsigned char)(random_seed / 65536) % 256;
+}
+
+void srand(unsigned int seed)
+{
+	random_seed = seed;
+}
+
+void get_random_bytes(char *buf, int len)
+{
+	while (len--)
+		*buf++ = rand();
+}
+
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 05:48:30 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:30 +0200
Subject: More patches
Message-ID: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>

Hi all,

Here are some more patches, most notably the the possibility to merge
the default environment together from different directories. We can then
introduce a generic default environment which can be used from multiple
boards. Each board can make specific additions to this default environment.

Also, maybe this is controversal, the network stack now generates a random
MAC address if now valid address is found.

Sascha

The following changes since commit 52f760cd61e3f6ca6deb8e5c47eef168b598a674:

  dhcp: do not call net_unregister if net_udp_new failed (2010-06-14 09:39:29 +0200)

are available in the git repository at:
  git://git.pengutronix.de/git/barebox.git pu

Sascha Hauer (11):
      pcm037: Add MMU support
      bootu: Allow passing in devices as parameter
      Allow to merge default environment from more than one directory
      include support for a simple pseudo number generator
      net: implement random_ether_addr
      net: use a random mac address if the current device does not have one
      add a generic default environment
      pcm038: use generic default env
      pcm043: use generic default env
      pcm037: use generic default env
      pca100: use generic default env

 Makefile                                           |   15 ---
 arch/arm/configs/pca100_defconfig                  |    2 +-
 arch/arm/configs/pcm037_defconfig                  |    2 +-
 arch/arm/configs/pcm038_defconfig                  |    2 +-
 arch/arm/configs/pcm043_defconfig                  |    2 +-
 arch/arm/lib/armlinux.c                            |   10 ++-
 arch/arm/mach-imx/Kconfig                          |    2 +
 board/pcm037/env/bin/boot                          |   47 ---------
 board/pcm037/env/bin/init                          |   37 -------
 board/pcm037/env/bin/update_root                   |   16 ---
 board/pcm037/env/config                            |   62 ++++++++---
 board/pcm037/pcm037.c                              |   31 ++++++
 board/pcm038/env/bin/_update                       |   36 -------
 board/pcm038/env/bin/boot                          |   47 ---------
 board/pcm038/env/bin/hush_hack                     |    1 -
 board/pcm038/env/bin/init                          |   37 -------
 board/pcm038/env/bin/update_kernel                 |   15 ---
 board/pcm038/env/bin/update_root                   |   16 ---
 board/pcm038/env/config                            |   62 ++++++++---
 board/pcm043/env/bin/_update                       |   36 -------
 board/pcm043/env/bin/boot                          |   47 ---------
 board/pcm043/env/bin/hush_hack                     |    1 -
 board/pcm043/env/bin/update_kernel                 |   15 ---
 board/pcm043/env/config                            |   65 +++++++++---
 board/phycard-i.MX27/env/bin/_update               |   36 -------
 board/phycard-i.MX27/env/bin/boot                  |   40 -------
 board/phycard-i.MX27/env/bin/hush_hack             |    1 -
 board/phycard-i.MX27/env/bin/init                  |   37 -------
 board/phycard-i.MX27/env/bin/update_kernel         |   15 ---
 board/phycard-i.MX27/env/bin/update_root           |   16 ---
 board/phycard-i.MX27/env/config                    |   57 ++++++++---
 common/Kconfig                                     |    4 +-
 common/Makefile                                    |    6 +-
 {board/pcm037/env => defaultenv}/bin/_update       |    5 +-
 defaultenv/bin/boot                                |  110 ++++++++++++++++++++
 {board/pcm037/env => defaultenv}/bin/hush_hack     |    0
 {board/pcm043/env => defaultenv}/bin/init          |   11 +--
 {board/pcm037/env => defaultenv}/bin/update_kernel |    2 +-
 .../update_root => defaultenv/bin/update_rootfs    |    4 +-
 include/net.h                                      |   17 +++
 include/random.h                                   |    7 ++
 lib/Makefile                                       |    1 +
 lib/random.c                                       |   22 ++++
 net/net.c                                          |   11 ++-
 scripts/genenv                                     |   17 +++
 45 files changed, 424 insertions(+), 601 deletions(-)
 delete mode 100644 board/pcm037/env/bin/boot
 delete mode 100644 board/pcm037/env/bin/init
 delete mode 100644 board/pcm037/env/bin/update_root
 delete mode 100644 board/pcm038/env/bin/_update
 delete mode 100644 board/pcm038/env/bin/boot
 delete mode 100644 board/pcm038/env/bin/hush_hack
 delete mode 100644 board/pcm038/env/bin/init
 delete mode 100644 board/pcm038/env/bin/update_kernel
 delete mode 100644 board/pcm038/env/bin/update_root
 delete mode 100644 board/pcm043/env/bin/_update
 delete mode 100644 board/pcm043/env/bin/boot
 delete mode 100644 board/pcm043/env/bin/hush_hack
 delete mode 100644 board/pcm043/env/bin/update_kernel
 delete mode 100644 board/phycard-i.MX27/env/bin/_update
 delete mode 100644 board/phycard-i.MX27/env/bin/boot
 delete mode 100644 board/phycard-i.MX27/env/bin/hush_hack
 delete mode 100644 board/phycard-i.MX27/env/bin/init
 delete mode 100644 board/phycard-i.MX27/env/bin/update_kernel
 delete mode 100644 board/phycard-i.MX27/env/bin/update_root
 rename {board/pcm037/env => defaultenv}/bin/_update (86%)
 create mode 100644 defaultenv/bin/boot
 rename {board/pcm037/env => defaultenv}/bin/hush_hack (100%)
 rename {board/pcm043/env => defaultenv}/bin/init (59%)
 rename {board/pcm037/env => defaultenv}/bin/update_kernel (91%)
 rename board/pcm043/env/bin/update_root => defaultenv/bin/update_rootfs (91%)
 create mode 100644 include/random.h
 create mode 100644 lib/random.c
 create mode 100755 scripts/genenv


From s.hauer at pengutronix.de  Mon Jun 14 05:48:38 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:38 +0200
Subject: [PATCH 08/11] pcm038: use generic default env
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276508921-3264-9-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/pcm038_defconfig  |    2 +-
 board/pcm038/env/bin/_update       |   36 ---------------------
 board/pcm038/env/bin/boot          |   47 ---------------------------
 board/pcm038/env/bin/hush_hack     |    1 -
 board/pcm038/env/bin/init          |   37 ---------------------
 board/pcm038/env/bin/update_kernel |   15 ---------
 board/pcm038/env/bin/update_root   |   16 ---------
 board/pcm038/env/config            |   62 ++++++++++++++++++++++++++----------
 8 files changed, 46 insertions(+), 170 deletions(-)
 delete mode 100644 board/pcm038/env/bin/_update
 delete mode 100644 board/pcm038/env/bin/boot
 delete mode 100644 board/pcm038/env/bin/hush_hack
 delete mode 100644 board/pcm038/env/bin/init
 delete mode 100644 board/pcm038/env/bin/update_kernel
 delete mode 100644 board/pcm038/env/bin/update_root

diff --git a/arch/arm/configs/pcm038_defconfig b/arch/arm/configs/pcm038_defconfig
index 0c9ac5f..a80089c 100644
--- a/arch/arm/configs/pcm038_defconfig
+++ b/arch/arm/configs/pcm038_defconfig
@@ -110,7 +110,7 @@ CONFIG_CONSOLE_ACTIVATE_FIRST=y
 # CONFIG_OF_FLAT_TREE is not set
 CONFIG_PARTITION=y
 CONFIG_DEFAULT_ENVIRONMENT=y
-CONFIG_DEFAULT_ENVIRONMENT_PATH="board/pcm038/env"
+CONFIG_DEFAULT_ENVIRONMENT_PATH="defaultenv board/pcm038/env"
 
 #
 # Debugging
diff --git a/board/pcm038/env/bin/_update b/board/pcm038/env/bin/_update
deleted file mode 100644
index 014bce3..0000000
--- a/board/pcm038/env/bin/_update
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-
-if [ -z "$part" -o -z "$image" ]; then
-	echo "define \$part and \$image"
-	exit 1
-fi
-
-if [ ! -e "$part" ]; then
-	echo "Partition $part does not exist"
-	exit 1
-fi
-
-if [ $# = 1 ]; then
-	image=$1
-fi
-
-if [ x$ip = xdhcp ]; then
-	dhcp
-fi
-
-ping $eth0.serverip
-if [ $? -ne 0 ] ; then
-	echo "update aborted"
-	exit 1
-fi
-
-unprotect $part
-
-echo
-echo "erasing partition $part"
-erase $part
-
-echo
-echo "flashing $image to $part"
-echo
-tftp $image $part
diff --git a/board/pcm038/env/bin/boot b/board/pcm038/env/bin/boot
deleted file mode 100644
index dfb59aa..0000000
--- a/board/pcm038/env/bin/boot
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-if [ x$1 = xnand ]; then
-	root=nand
-	kernel=nand
-fi
-
-if [ x$1 = xnet ]; then
-	root=net
-	kernel=net
-fi
-
-if [ x$1 = xnor ]; then
-	root=nor
-	kernel=nor
-fi
-
-if [ x$ip = xdhcp ]; then
-	bootargs="$bootargs ip=dhcp"
-else
-	bootargs="$bootargs ip=$eth0.ipaddr:$eth0.serverip:$eth0.gateway:$eth0.netmask:::"
-fi
-
-if [ x$root = xnand ]; then
-	bootargs="$bootargs root=$rootpart_nand rootfstype=jffs2"
-elif [ x$root = xnor ]; then
-	bootargs="$bootargs root=$rootpart_nor rootfstype=jffs2"
-else
-	bootargs="$bootargs root=/dev/nfs nfsroot=$eth0.serverip:$nfsroot,v3,tcp"
-fi
-
-bootargs="$bootargs mtdparts=physmap-flash.0:$nor_parts;imx_nand:$nand_parts"
-
-if [ $kernel = net ]; then
-	if [ x$ip = xdhcp ]; then
-		dhcp
-	fi
-	tftp $uimage uImage || exit 1
-	bootm uImage
-elif [ $kernel = nor ]; then
-	bootm /dev/nor0.kernel
-else
-	bootm /dev/nand0.kernel.bb
-fi
-
diff --git a/board/pcm038/env/bin/hush_hack b/board/pcm038/env/bin/hush_hack
deleted file mode 100644
index 5fffa92..0000000
--- a/board/pcm038/env/bin/hush_hack
+++ /dev/null
@@ -1 +0,0 @@
-nand -a /dev/nand0.*
diff --git a/board/pcm038/env/bin/init b/board/pcm038/env/bin/init
deleted file mode 100644
index 3bfd194..0000000
--- a/board/pcm038/env/bin/init
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-
-PATH=/env/bin
-export PATH
-
-. /env/config
-if [ -e /dev/nor0 ]; then
-	addpart /dev/nor0 $nor_parts
-fi
-
-if [ -e /dev/nand0 ]; then
-	addpart /dev/nand0 $nand_parts
-
-	# Uh, oh, hush first expands wildcards and then starts executing
-	# commands. What a bug!
-	source /env/bin/hush_hack 
-fi
-
-if [ -z $eth0.ethaddr ]; then
-	while [ -z $eth0.ethaddr ]; do
-		readline "no MAC address set for eth0. please enter the one found on your board: " eth0.ethaddr
-	done
-	echo -a /env/config "eth0.ethaddr=$eth0.ethaddr"
-fi
-
-echo
-echo -n "Hit any key to stop autoboot: "
-timeout -a $autoboot_timeout
-if [ $? != 0 ]; then
-	echo
-	echo "type update_kernel nand|nor [<imagename>] to update kernel into flash"
-	echo "type update_root nand|nor [<imagename>] to update rootfs into flash"
-	echo
-	exit
-fi
-
-boot
diff --git a/board/pcm038/env/bin/update_kernel b/board/pcm038/env/bin/update_kernel
deleted file mode 100644
index 05c822d..0000000
--- a/board/pcm038/env/bin/update_kernel
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-image=$uimage
-if [ x$1 = xnand ]; then
-	part=/dev/nand0.kernel.bb
-elif [ x$1 = xnor ]; then
-	part=/dev/nor0.kernel
-else
-	echo "usage: $0 nor|nand [imagename]"
-	exit 1
-fi
-
-. /env/bin/_update $2
diff --git a/board/pcm038/env/bin/update_root b/board/pcm038/env/bin/update_root
deleted file mode 100644
index eaf36eb..0000000
--- a/board/pcm038/env/bin/update_root
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-image=$uimage
-if [ x$1 = xnand ]; then
-	part=/dev/nand0.root.bb
-elif [ x$1 = xnor ]; then
-	part=/dev/nor0.root
-else
-	echo "usage: $0 nor|nand [imagename]"
-	exit 1
-fi
-
-. /env/bin/_update $2
-
diff --git a/board/pcm038/env/config b/board/pcm038/env/config
index 9fcb3dc..a8be5c9 100644
--- a/board/pcm038/env/config
+++ b/board/pcm038/env/config
@@ -1,24 +1,11 @@
 #!/bin/sh
 
-# can be either 'net', 'nor' or 'nand''
-kernel=net
-root=net
-
-uimage=uImage-pcm038
-jffs2=root-pcm038.jffs2
-
-autoboot_timeout=3
-
-nfsroot="/ptx/work/octopus/rsc/svn/oselas/bsp/phytec/phyCORE-i.MX27/OSELAS.BSP-Phytec-phyCORE-i.MX27-trunk/root"
-bootargs="console=ttymxc0,115200"
-
-nor_parts="256k(barebox)ro,128k(bareboxenv),1536k(kernel),-(root)"
-rootpart_nor="/dev/mtdblock3"
-
-nand_parts="256k(barebox)ro,128k(bareboxenv),1536k(kernel),-(root)"
-rootpart_nand="/dev/mtdblock7"
+machine=pcm038
+eth0.serverip=
+user=
 
 # use 'dhcp' to do dhcp in barebox and in kernel
+# use 'none' if you want to skip kernel ip autoconfiguration
 ip=dhcp
 
 # or set your networking parameters here
@@ -26,3 +13,44 @@ ip=dhcp
 #eth0.netmask=a.b.c.d
 #eth0.gateway=a.b.c.d
 #eth0.serverip=a.b.c.d
+
+# can be either 'net', 'nor' or 'nand'
+kernel_loc=net
+# can be either 'net', 'nor', 'nand' or 'initrd'
+rootfs_loc=net
+
+# can be either 'jffs2' or 'ubifs'
+rootfs_type=ubifs
+rootfsimage=root-$machine.$rootfs_type
+
+# The image type of the kernel. Can be uimage, zimage, raw, or raw_lzo
+kernelimage_type=zimage
+kernelimage=zImage-$machine
+#kernelimage_type=uimage
+#kernelimage=uImage-$machine
+#kernelimage_type=raw
+#kernelimage=Image-$machine
+#kernelimage_type=raw_lzo
+#kernelimage=Image-$machine.lzo
+
+if [ -n $user ]; then
+	kernelimage="$user"-"$kernelimage"
+	nfsroot="$eth0.serverip:/home/$user/nfsroot/$machine"
+	rootfsimage="$user"-"$rootfsimage"
+else
+	nfsroot="$eth0.serverip:/path/to/nfs/root"
+fi
+
+autoboot_timeout=3
+
+bootargs="console=ttymxc0,115200"
+
+nor_parts="256k(barebox)ro,128k(bareboxenv),2M(kernel),-(root)"
+rootfs_mtdblock_nor=3
+
+nand_parts="256k(barebox)ro,128k(bareboxenv),2M(kernel),-(root)"
+rootfs_mtdblock_nand=7
+
+# set a fancy prompt (if support is compiled in)
+PS1="\e[1;32mbarebox@\e[1;31m\h:\w\e[0m "
+
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 05:48:41 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:41 +0200
Subject: [PATCH 11/11] pca100: use generic default env
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276508921-3264-12-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/pca100_defconfig          |    2 +-
 board/phycard-i.MX27/env/bin/_update       |   36 -----------------
 board/phycard-i.MX27/env/bin/boot          |   40 -------------------
 board/phycard-i.MX27/env/bin/hush_hack     |    1 -
 board/phycard-i.MX27/env/bin/init          |   37 ------------------
 board/phycard-i.MX27/env/bin/update_kernel |   15 -------
 board/phycard-i.MX27/env/bin/update_root   |   16 --------
 board/phycard-i.MX27/env/config            |   57 +++++++++++++++++++++-------
 8 files changed, 44 insertions(+), 160 deletions(-)
 delete mode 100644 board/phycard-i.MX27/env/bin/_update
 delete mode 100644 board/phycard-i.MX27/env/bin/boot
 delete mode 100644 board/phycard-i.MX27/env/bin/hush_hack
 delete mode 100644 board/phycard-i.MX27/env/bin/init
 delete mode 100644 board/phycard-i.MX27/env/bin/update_kernel
 delete mode 100644 board/phycard-i.MX27/env/bin/update_root

diff --git a/arch/arm/configs/pca100_defconfig b/arch/arm/configs/pca100_defconfig
index f0a9512..52a5d93 100644
--- a/arch/arm/configs/pca100_defconfig
+++ b/arch/arm/configs/pca100_defconfig
@@ -110,7 +110,7 @@ CONFIG_CONSOLE_ACTIVATE_FIRST=y
 # CONFIG_OF_FLAT_TREE is not set
 CONFIG_PARTITION=y
 CONFIG_DEFAULT_ENVIRONMENT=y
-CONFIG_DEFAULT_ENVIRONMENT_PATH="board/phycard-i.MX27/env/"
+CONFIG_DEFAULT_ENVIRONMENT_PATH="defaultenv board/phycard-i.MX27/env"
 
 #
 # Debugging
diff --git a/board/phycard-i.MX27/env/bin/_update b/board/phycard-i.MX27/env/bin/_update
deleted file mode 100644
index 014bce3..0000000
--- a/board/phycard-i.MX27/env/bin/_update
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-
-if [ -z "$part" -o -z "$image" ]; then
-	echo "define \$part and \$image"
-	exit 1
-fi
-
-if [ ! -e "$part" ]; then
-	echo "Partition $part does not exist"
-	exit 1
-fi
-
-if [ $# = 1 ]; then
-	image=$1
-fi
-
-if [ x$ip = xdhcp ]; then
-	dhcp
-fi
-
-ping $eth0.serverip
-if [ $? -ne 0 ] ; then
-	echo "update aborted"
-	exit 1
-fi
-
-unprotect $part
-
-echo
-echo "erasing partition $part"
-erase $part
-
-echo
-echo "flashing $image to $part"
-echo
-tftp $image $part
diff --git a/board/phycard-i.MX27/env/bin/boot b/board/phycard-i.MX27/env/bin/boot
deleted file mode 100644
index 56a0377..0000000
--- a/board/phycard-i.MX27/env/bin/boot
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-if [ x$1 = xnand ]; then
-	root=nand
-	kernel=nand
-fi
-
-if [ x$1 = xnet ]; then
-	root=net
-	kernel=net
-fi
-
-if [ x$ip = xdhcp ]; then
-	bootargs="$bootargs ip=dhcp"
-else
-	bootargs="$bootargs ip=$eth0.ipaddr:$eth0.serverip:$eth0.gateway:$eth0.netmask:::"
-fi
-
-if [ x$root = xnand ]; then
-	bootargs="$bootargs root=$rootpart_nand rootfstype=jffs2"
-else
-	bootargs="$bootargs root=/dev/nfs nfsroot=$eth0.serverip:$nfsroot,v3,tcp"
-fi
-
-bootargs="$bootargs mtdparts=mxc_nand:$nand_parts"
-
-if [ $kernel = net ]; then
-	if [ x$ip = xdhcp ]; then
-		dhcp
-	fi
-	tftp $uimage uImage || exit 1
-	bootm uImage
-elif [ $kernel = nor ]; then
-	bootm /dev/nor0.kernel
-else
-	bootm /dev/nand0.kernel.bb
-fi
-
diff --git a/board/phycard-i.MX27/env/bin/hush_hack b/board/phycard-i.MX27/env/bin/hush_hack
deleted file mode 100644
index 5fffa92..0000000
--- a/board/phycard-i.MX27/env/bin/hush_hack
+++ /dev/null
@@ -1 +0,0 @@
-nand -a /dev/nand0.*
diff --git a/board/phycard-i.MX27/env/bin/init b/board/phycard-i.MX27/env/bin/init
deleted file mode 100644
index 3bfd194..0000000
--- a/board/phycard-i.MX27/env/bin/init
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-
-PATH=/env/bin
-export PATH
-
-. /env/config
-if [ -e /dev/nor0 ]; then
-	addpart /dev/nor0 $nor_parts
-fi
-
-if [ -e /dev/nand0 ]; then
-	addpart /dev/nand0 $nand_parts
-
-	# Uh, oh, hush first expands wildcards and then starts executing
-	# commands. What a bug!
-	source /env/bin/hush_hack 
-fi
-
-if [ -z $eth0.ethaddr ]; then
-	while [ -z $eth0.ethaddr ]; do
-		readline "no MAC address set for eth0. please enter the one found on your board: " eth0.ethaddr
-	done
-	echo -a /env/config "eth0.ethaddr=$eth0.ethaddr"
-fi
-
-echo
-echo -n "Hit any key to stop autoboot: "
-timeout -a $autoboot_timeout
-if [ $? != 0 ]; then
-	echo
-	echo "type update_kernel nand|nor [<imagename>] to update kernel into flash"
-	echo "type update_root nand|nor [<imagename>] to update rootfs into flash"
-	echo
-	exit
-fi
-
-boot
diff --git a/board/phycard-i.MX27/env/bin/update_kernel b/board/phycard-i.MX27/env/bin/update_kernel
deleted file mode 100644
index 05c822d..0000000
--- a/board/phycard-i.MX27/env/bin/update_kernel
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-image=$uimage
-if [ x$1 = xnand ]; then
-	part=/dev/nand0.kernel.bb
-elif [ x$1 = xnor ]; then
-	part=/dev/nor0.kernel
-else
-	echo "usage: $0 nor|nand [imagename]"
-	exit 1
-fi
-
-. /env/bin/_update $2
diff --git a/board/phycard-i.MX27/env/bin/update_root b/board/phycard-i.MX27/env/bin/update_root
deleted file mode 100644
index eaf36eb..0000000
--- a/board/phycard-i.MX27/env/bin/update_root
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-image=$uimage
-if [ x$1 = xnand ]; then
-	part=/dev/nand0.root.bb
-elif [ x$1 = xnor ]; then
-	part=/dev/nor0.root
-else
-	echo "usage: $0 nor|nand [imagename]"
-	exit 1
-fi
-
-. /env/bin/_update $2
-
diff --git a/board/phycard-i.MX27/env/config b/board/phycard-i.MX27/env/config
index 6a93580..d0670de 100644
--- a/board/phycard-i.MX27/env/config
+++ b/board/phycard-i.MX27/env/config
@@ -1,21 +1,11 @@
 #!/bin/sh
 
-# can be either 'net', 'nor' or 'nand''
-kernel=net
-root=net
-
-uimage=uImage-pca100
-jffs2=root-pca100.jffs2
-
-autoboot_timeout=3
-
-nfsroot="/tmp/root"
-bootargs="console=ttymxc0,115200"
-
-nand_parts="256k(barebox)ro,128k(bareboxenv),1536k(kernel),-(root)"
-rootpart_nand="/dev/mtdblock3"
+machine=pca100
+eth0.serverip=
+user=
 
 # use 'dhcp' to do dhcp in barebox and in kernel
+# use 'none' if you want to skip kernel ip autoconfiguration
 ip=dhcp
 
 # or set your networking parameters here
@@ -23,3 +13,42 @@ ip=dhcp
 #eth0.netmask=a.b.c.d
 #eth0.gateway=a.b.c.d
 #eth0.serverip=a.b.c.d
+
+# can be either 'net', 'nor' or 'nand'
+kernel_loc=net
+# can be either 'net', 'nor', 'nand' or 'initrd'
+rootfs_loc=net
+
+# can be either 'jffs2' or 'ubifs'
+rootfs_type=ubifs
+rootfsimage=root-$machine.$rootfs_type
+
+# The image type of the kernel. Can be uimage, zimage, raw, or raw_lzo
+kernelimage_type=zimage
+kernelimage=zImage-$machine
+#kernelimage_type=uimage
+#kernelimage=uImage-$machine
+#kernelimage_type=raw
+#kernelimage=Image-$machine
+#kernelimage_type=raw_lzo
+#kernelimage=Image-$machine.lzo
+
+if [ -n $user ]; then
+	kernelimage="$user"-"$kernelimage"
+	nfsroot="$eth0.serverip:/home/$user/nfsroot/$machine"
+	rootfsimage="$user"-"$rootfsimage"
+else
+	nfsroot="$eth0.serverip:/path/to/nfs/root"
+fi
+
+autoboot_timeout=3
+
+bootargs="console=ttymxc0,115200"
+
+nand_parts="256k(barebox)ro,128k(bareboxenv),2M(kernel),-(root)"
+rootfs_mtdblock_nand=7
+
+# set a fancy prompt (if support is compiled in)
+PS1="\e[1;32mbarebox@\e[1;31m\h:\w\e[0m "
+
+
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 05:48:39 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:39 +0200
Subject: [PATCH 09/11] pcm043: use generic default env
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276508921-3264-10-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/pcm043_defconfig  |    2 +-
 board/pcm043/env/bin/_update       |   36 --------------------
 board/pcm043/env/bin/boot          |   47 --------------------------
 board/pcm043/env/bin/hush_hack     |    1 -
 board/pcm043/env/bin/init          |   37 --------------------
 board/pcm043/env/bin/update_kernel |   15 --------
 board/pcm043/env/bin/update_root   |   16 ---------
 board/pcm043/env/config            |   65 ++++++++++++++++++++++++++----------
 8 files changed, 48 insertions(+), 171 deletions(-)
 delete mode 100644 board/pcm043/env/bin/_update
 delete mode 100644 board/pcm043/env/bin/boot
 delete mode 100644 board/pcm043/env/bin/hush_hack
 delete mode 100644 board/pcm043/env/bin/init
 delete mode 100644 board/pcm043/env/bin/update_kernel
 delete mode 100644 board/pcm043/env/bin/update_root

diff --git a/arch/arm/configs/pcm043_defconfig b/arch/arm/configs/pcm043_defconfig
index 5563356..72a8a42 100644
--- a/arch/arm/configs/pcm043_defconfig
+++ b/arch/arm/configs/pcm043_defconfig
@@ -109,7 +109,7 @@ CONFIG_CONSOLE_ACTIVATE_FIRST=y
 # CONFIG_OF_FLAT_TREE is not set
 CONFIG_PARTITION=y
 CONFIG_DEFAULT_ENVIRONMENT=y
-CONFIG_DEFAULT_ENVIRONMENT_PATH="board/pcm043/env/"
+CONFIG_DEFAULT_ENVIRONMENT_PATH="defaultenv board/pcm043/env"
 
 #
 # Debugging
diff --git a/board/pcm043/env/bin/_update b/board/pcm043/env/bin/_update
deleted file mode 100644
index 014bce3..0000000
--- a/board/pcm043/env/bin/_update
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-
-if [ -z "$part" -o -z "$image" ]; then
-	echo "define \$part and \$image"
-	exit 1
-fi
-
-if [ ! -e "$part" ]; then
-	echo "Partition $part does not exist"
-	exit 1
-fi
-
-if [ $# = 1 ]; then
-	image=$1
-fi
-
-if [ x$ip = xdhcp ]; then
-	dhcp
-fi
-
-ping $eth0.serverip
-if [ $? -ne 0 ] ; then
-	echo "update aborted"
-	exit 1
-fi
-
-unprotect $part
-
-echo
-echo "erasing partition $part"
-erase $part
-
-echo
-echo "flashing $image to $part"
-echo
-tftp $image $part
diff --git a/board/pcm043/env/bin/boot b/board/pcm043/env/bin/boot
deleted file mode 100644
index 7bbff2d..0000000
--- a/board/pcm043/env/bin/boot
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-if [ x$1 = xnand ]; then
-	root=nand
-	kernel=nand
-fi
-
-if [ x$1 = xnet ]; then
-	root=net
-	kernel=net
-fi
-
-if [ x$1 = xnor ]; then
-	root=nor
-	kernel=nor
-fi
-
-if [ x$ip = xdhcp ]; then
-	bootargs="$bootargs ip=dhcp"
-else
-	bootargs="$bootargs ip=$eth0.ipaddr:$eth0.serverip:$eth0.gateway:$eth0.netmask:::"
-fi
-
-if [ x$root = xnand ]; then
-	bootargs="$bootargs root=$rootpart_nand rootfstype=jffs2"
-elif [ x$root = xnor ]; then
-	bootargs="$bootargs root=$rootpart_nor rootfstype=jffs2"
-else
-	bootargs="$bootargs root=/dev/nfs nfsroot=$eth0.serverip:$nfsroot,v3,tcp"
-fi
-
-bootargs="$bootargs mtdparts=physmap-flash.0:$nor_parts;mxc_nand:$nand_parts"
-
-if [ $kernel = net ]; then
-	if [ x$ip = xdhcp ]; then
-		dhcp
-	fi
-	tftp $uimage uImage || exit 1
-	bootm uImage
-elif [ $kernel = nor ]; then
-	bootm /dev/nor0.kernel
-else
-	bootm /dev/nand0.kernel.bb
-fi
-
diff --git a/board/pcm043/env/bin/hush_hack b/board/pcm043/env/bin/hush_hack
deleted file mode 100644
index 5fffa92..0000000
--- a/board/pcm043/env/bin/hush_hack
+++ /dev/null
@@ -1 +0,0 @@
-nand -a /dev/nand0.*
diff --git a/board/pcm043/env/bin/init b/board/pcm043/env/bin/init
deleted file mode 100644
index 3bfd194..0000000
--- a/board/pcm043/env/bin/init
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-
-PATH=/env/bin
-export PATH
-
-. /env/config
-if [ -e /dev/nor0 ]; then
-	addpart /dev/nor0 $nor_parts
-fi
-
-if [ -e /dev/nand0 ]; then
-	addpart /dev/nand0 $nand_parts
-
-	# Uh, oh, hush first expands wildcards and then starts executing
-	# commands. What a bug!
-	source /env/bin/hush_hack 
-fi
-
-if [ -z $eth0.ethaddr ]; then
-	while [ -z $eth0.ethaddr ]; do
-		readline "no MAC address set for eth0. please enter the one found on your board: " eth0.ethaddr
-	done
-	echo -a /env/config "eth0.ethaddr=$eth0.ethaddr"
-fi
-
-echo
-echo -n "Hit any key to stop autoboot: "
-timeout -a $autoboot_timeout
-if [ $? != 0 ]; then
-	echo
-	echo "type update_kernel nand|nor [<imagename>] to update kernel into flash"
-	echo "type update_root nand|nor [<imagename>] to update rootfs into flash"
-	echo
-	exit
-fi
-
-boot
diff --git a/board/pcm043/env/bin/update_kernel b/board/pcm043/env/bin/update_kernel
deleted file mode 100644
index 05c822d..0000000
--- a/board/pcm043/env/bin/update_kernel
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-image=$uimage
-if [ x$1 = xnand ]; then
-	part=/dev/nand0.kernel.bb
-elif [ x$1 = xnor ]; then
-	part=/dev/nor0.kernel
-else
-	echo "usage: $0 nor|nand [imagename]"
-	exit 1
-fi
-
-. /env/bin/_update $2
diff --git a/board/pcm043/env/bin/update_root b/board/pcm043/env/bin/update_root
deleted file mode 100644
index eaf36eb..0000000
--- a/board/pcm043/env/bin/update_root
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-image=$uimage
-if [ x$1 = xnand ]; then
-	part=/dev/nand0.root.bb
-elif [ x$1 = xnor ]; then
-	part=/dev/nor0.root
-else
-	echo "usage: $0 nor|nand [imagename]"
-	exit 1
-fi
-
-. /env/bin/_update $2
-
diff --git a/board/pcm043/env/config b/board/pcm043/env/config
index c1ab234..212b6a9 100644
--- a/board/pcm043/env/config
+++ b/board/pcm043/env/config
@@ -1,29 +1,58 @@
 #!/bin/sh
 
-# can be either 'net', 'nor' or 'nand''
-kernel=nor
-root=nor
+machine=pcm043
+eth0.serverip=
+user=
 
-uimage=uImage-pcm043
-jffs2=root-pcm043.jffs2
+# use 'dhcp' to do dhcp in barebox and in kernel
+# use 'none' if you want to skip kernel ip autoconfiguration
+ip=dhcp
+
+# or set your networking parameters here
+#eth0.ipaddr=a.b.c.d
+#eth0.netmask=a.b.c.d
+#eth0.gateway=a.b.c.d
+#eth0.serverip=a.b.c.d
+
+# can be either 'net', 'nor' or 'nand'
+kernel_loc=net
+# can be either 'net', 'nor', 'nand' or 'initrd'
+rootfs_loc=net
+
+# can be either 'jffs2' or 'ubifs'
+rootfs_type=ubifs
+rootfsimage=root-$machine.$rootfs_type
+
+# The image type of the kernel. Can be uimage, zimage, raw, or raw_lzo
+kernelimage_type=zimage
+kernelimage=zImage-$machine
+#kernelimage_type=uimage
+#kernelimage=uImage-$machine
+#kernelimage_type=raw
+#kernelimage=Image-$machine
+#kernelimage_type=raw_lzo
+#kernelimage=Image-$machine.lzo
+
+if [ -n $user ]; then
+	kernelimage="$user"-"$kernelimage"
+	nfsroot="$eth0.serverip:/home/$user/nfsroot/$machine"
+	rootfsimage="$user"-"$rootfsimage"
+else
+	nfsroot="$eth0.serverip:/path/to/nfs/root"
+fi
 
 autoboot_timeout=3
 
-nfsroot="/path/to/nfs_root"
 bootargs="console=ttymxc0,115200"
 
-nor_parts="256k(barebox)ro,128k(bareboxenv),2048k(kernel),-(root)"
-rootpart_nor="/dev/mtdblock3"
-nand_parts="256k(barebox)ro,128k(bareboxenv),2048k(kernel),-(root)"
-rootpart_nand="/dev/mtdblock3"
+bootargs="$bootargs video=mx3fb:CTP-CLAA070LC0ACW"
 
-# use 'dhcp' to do dhcp in barebox and in kernel
-ip=dhcp
+nor_parts="256k(barebox)ro,128k(bareboxenv),2M(kernel),-(root)"
+rootfs_mtdblock_nor=3
 
-# or set your networking parameters here
-eth0.ipaddr=192.168.3.11
-eth0.netmask=255.255.255.0
-#eth0.gateway=a.b.c.d
-#eth0.serverip=192.168.3.10
-#eth0.ethaddr=aa.bb.cc.dd.ee.ff
+nand_parts="256k(barebox)ro,128k(bareboxenv),2M(kernel),-(root)"
+rootfs_mtdblock_nand=7
+
+# set a fancy prompt (if support is compiled in)
+PS1="\e[1;32mbarebox@\e[1;31m\h:\w\e[0m "
 
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 05:48:37 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:37 +0200
Subject: [PATCH 07/11] add a generic default environment
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276508921-3264-8-git-send-email-s.hauer@pengutronix.de>

We have several nearly identical default environments in the tree.
Lets merge them to a single environment and use it on many boards.
This defaultenv is arm centric at the moment due to the use of arm
specific boot commands. This can be improved over time.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 defaultenv/bin/_update       |   39 +++++++++++++++
 defaultenv/bin/boot          |  110 ++++++++++++++++++++++++++++++++++++++++++
 defaultenv/bin/hush_hack     |    1 +
 defaultenv/bin/init          |   30 +++++++++++
 defaultenv/bin/update_kernel |   15 ++++++
 defaultenv/bin/update_rootfs |   16 ++++++
 6 files changed, 211 insertions(+), 0 deletions(-)
 create mode 100644 defaultenv/bin/_update
 create mode 100644 defaultenv/bin/boot
 create mode 100644 defaultenv/bin/hush_hack
 create mode 100644 defaultenv/bin/init
 create mode 100644 defaultenv/bin/update_kernel
 create mode 100644 defaultenv/bin/update_rootfs

diff --git a/defaultenv/bin/_update b/defaultenv/bin/_update
new file mode 100644
index 0000000..ddd6b84
--- /dev/null
+++ b/defaultenv/bin/_update
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+if [ -z "$part" -o -z "$image" ]; then
+	echo "define \$part and \$image"
+	exit 1
+fi
+
+if [ ! -e "$part" ]; then
+	echo "Partition $part does not exist"
+	exit 1
+fi
+
+if [ $# = 1 ]; then
+	image=$1
+fi
+
+if [ x$ip = xdhcp ]; then
+	dhcp
+fi
+
+ping $eth0.serverip
+if [ $? -ne 0 ] ; then
+	echo "Server did not reply! Update aborted."
+	exit 1
+fi
+
+unprotect $part
+
+echo
+echo "erasing partition $part"
+echo
+erase $part
+
+echo
+echo "flashing $image to $part"
+echo
+tftp $image $part
+
+protect $part
diff --git a/defaultenv/bin/boot b/defaultenv/bin/boot
new file mode 100644
index 0000000..8c300a3
--- /dev/null
+++ b/defaultenv/bin/boot
@@ -0,0 +1,110 @@
+#!/bin/sh
+
+. /env/config
+
+if [ x$1 = xnand ]; then
+	rootfs_loc=nand
+	kernel_loc=nand
+elif [ x$1 = xnor ]; then
+	rootfs_loc=nor
+	kernel_loc=nor
+elif [ x$1 = xnet ]; then
+	rootfs_loc=net
+	kernel_loc=net
+fi
+
+
+if [ x$ip = xdhcp ]; then
+	bootargs="$bootargs ip=dhcp"
+elif [ x$ip = xnone ]; then
+	bootargs="ip=none"
+else
+	bootargs="$bootargs ip=$eth0.ipaddr::$eth0.gateway:$eth0.netmask:::"
+fi
+
+
+if [ $rootfs_loc = net ]; then
+	bootargs="$bootargs root=/dev/nfs nfsroot=$nfsroot,v3,tcp noinitrd"
+elif [ $rootfs_loc = initrd ]; then
+	bootargs="$bootargs root=/dev/ram0 rdinit=/sbin/init"
+else
+	if [ x$rootfs_loc = xnand ]; then
+		rootfs_mtdblock=$rootfs_mtdblock_nand
+	else
+		rootfs_mtdblock=$rootfs_mtdblock_nor
+	fi
+
+	if [ $rootfs_type = ubifs ]; then
+		bootargs="$bootargs root=ubi0:root ubi.mtd=$rootfs_mtdblock"
+	else
+		bootargs="$bootargs root=/dev/mtdblock$rootfs_mtdblock"
+	fi
+
+	bootargs="$bootargs rootfstype=$rootfs_type noinitrd"
+fi
+
+if [ -n $nor_parts ]; then
+	mtdparts="${mtdparts}physmap-flash.o:${nor_parts};"
+fi
+
+if [ -n $nand_parts ]; then
+	mtdparts="${mtdparts}$nand_device:${nor_parts};"
+fi
+
+if [ -n $mtdparts ]; then
+	bootargs="${bootargs} mtdparts=\"${mtdparts}\""
+fi
+
+if [ ! -e /dev/ram0.kernelraw ]; then
+	# arm raw kernel images are usually located at sdram start + 0x8000
+	addpart dev/ram0 8M at 0x8000(kernelraw)
+fi
+
+if [ ! -e /dev/ram0.kernel ]; then
+	# Here we can safely put the kernel without risking of overwriting it
+	# while extracting
+	addpart dev/ram0 8M(kernel)
+fi
+
+if [ $kernel_loc = net ]; then
+	if [ x$ip = xdhcp ]; then
+		dhcp
+	fi
+	if [ $kernelimage_type = uimage ]; then
+		netload="/dev/ram0.kernel"
+	elif [ $kernelimage_type = zimage ]; then
+		netload="/dev/ram0.kernel"
+	elif [ $kernelimage_type = raw ]; then
+		netload="/dev/ram0.kernelraw"
+	elif [ $kernelimage_type = raw_lzo ]; then
+		netload="/dev/ram0.kernel"
+	else
+		echo "error: missing kernel_image_type"
+		exit 1
+	fi
+	tftp $kernelimage $netload || exit 1
+	kdev="$netload"
+elif [ $kernel_loc = nor ]; then
+	kdev="/dev/nor0.kernel"
+elif [ $kernel_loc = nand ]; then
+	kdev="/dev/nand0.kernel.bb"
+else
+	echo "error: missing kernel_loc"
+	exit 1
+fi
+
+if [ $kernelimage_type = uimage ]; then
+	bootm $kdev
+elif [ $kernelimage_type = zimage ]; then
+	bootz $kdev
+elif [ $kernelimage_type = raw ]; then
+	if [ $kernel_loc != net ]; then
+		ec
+		cp $kdev /dev/ram0.kernelraw
+	fi
+	bootu /dev/ram0.kernelraw
+elif [ $kernelimage_type = raw_lzo ]; then
+	unlzo $kdev /dev/ram0.kernelraw
+	bootu /dev/ram0.kernelraw
+fi
+
diff --git a/defaultenv/bin/hush_hack b/defaultenv/bin/hush_hack
new file mode 100644
index 0000000..5fffa92
--- /dev/null
+++ b/defaultenv/bin/hush_hack
@@ -0,0 +1 @@
+nand -a /dev/nand0.*
diff --git a/defaultenv/bin/init b/defaultenv/bin/init
new file mode 100644
index 0000000..b17fcbc
--- /dev/null
+++ b/defaultenv/bin/init
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+PATH=/env/bin
+export PATH
+
+. /env/config
+if [ -e /dev/nor0 ]; then
+	addpart /dev/nor0 $nor_parts
+fi
+
+if [ -e /dev/nand0 ]; then
+	addpart /dev/nand0 $nand_parts
+
+	# Uh, oh, hush first expands wildcards and then starts executing
+	# commands. What a bug!
+	source /env/bin/hush_hack
+fi
+
+echo
+echo -n "Hit any key to stop autoboot: "
+timeout -a $autoboot_timeout
+if [ $? != 0 ]; then
+	echo
+	echo "type update_kernel nand|nor [<imagename>] to update kernel into flash"
+	echo "type update_rootfs nand|nor [<imagename>] to update rootfs into flash"
+	echo
+	exit
+fi
+
+boot
diff --git a/defaultenv/bin/update_kernel b/defaultenv/bin/update_kernel
new file mode 100644
index 0000000..1d35ed9
--- /dev/null
+++ b/defaultenv/bin/update_kernel
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+. /env/config
+image=$kernelimage
+
+if [ x$1 = xnand ]; then
+	part=/dev/nand0.kernel.bb
+elif [ x$1 = xnor ]; then
+	part=/dev/nor0.kernel
+else
+	echo "usage: $0 nor|nand [imagename]"
+	exit 1
+fi
+
+. /env/bin/_update $2
diff --git a/defaultenv/bin/update_rootfs b/defaultenv/bin/update_rootfs
new file mode 100644
index 0000000..6366315
--- /dev/null
+++ b/defaultenv/bin/update_rootfs
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+. /env/config
+
+image=$rootfsimage
+
+if [ x$1 = xnand ]; then
+	part=/dev/nand0.root.bb
+elif [ x$1 = xnor ]; then
+	part=/dev/nor0.root
+else
+	echo "usage: $0 nor|nand [imagename]"
+	exit 1
+fi
+
+. /env/bin/_update $2
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 14 05:48:40 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 14 Jun 2010 11:48:40 +0200
Subject: [PATCH 10/11] pcm037: use generic default env
In-Reply-To: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1276508921-3264-11-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/pcm037_defconfig  |    2 +-
 board/pcm037/env/bin/_update       |   36 ---------------------
 board/pcm037/env/bin/boot          |   47 ---------------------------
 board/pcm037/env/bin/hush_hack     |    1 -
 board/pcm037/env/bin/init          |   37 ---------------------
 board/pcm037/env/bin/update_kernel |   15 ---------
 board/pcm037/env/bin/update_root   |   16 ---------
 board/pcm037/env/config            |   62 ++++++++++++++++++++++++++----------
 8 files changed, 46 insertions(+), 170 deletions(-)
 delete mode 100644 board/pcm037/env/bin/_update
 delete mode 100644 board/pcm037/env/bin/boot
 delete mode 100644 board/pcm037/env/bin/hush_hack
 delete mode 100644 board/pcm037/env/bin/init
 delete mode 100644 board/pcm037/env/bin/update_kernel
 delete mode 100644 board/pcm037/env/bin/update_root

diff --git a/arch/arm/configs/pcm037_defconfig b/arch/arm/configs/pcm037_defconfig
index e82733f..9353d0e 100644
--- a/arch/arm/configs/pcm037_defconfig
+++ b/arch/arm/configs/pcm037_defconfig
@@ -106,7 +106,7 @@ CONFIG_CONSOLE_ACTIVATE_FIRST=y
 # CONFIG_OF_FLAT_TREE is not set
 CONFIG_PARTITION=y
 CONFIG_DEFAULT_ENVIRONMENT=y
-CONFIG_DEFAULT_ENVIRONMENT_PATH="board/pcm037/env"
+CONFIG_DEFAULT_ENVIRONMENT_PATH="defaultenv board/pcm037/env"
 
 #
 # Debugging
diff --git a/board/pcm037/env/bin/_update b/board/pcm037/env/bin/_update
deleted file mode 100644
index 014bce3..0000000
--- a/board/pcm037/env/bin/_update
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-
-if [ -z "$part" -o -z "$image" ]; then
-	echo "define \$part and \$image"
-	exit 1
-fi
-
-if [ ! -e "$part" ]; then
-	echo "Partition $part does not exist"
-	exit 1
-fi
-
-if [ $# = 1 ]; then
-	image=$1
-fi
-
-if [ x$ip = xdhcp ]; then
-	dhcp
-fi
-
-ping $eth0.serverip
-if [ $? -ne 0 ] ; then
-	echo "update aborted"
-	exit 1
-fi
-
-unprotect $part
-
-echo
-echo "erasing partition $part"
-erase $part
-
-echo
-echo "flashing $image to $part"
-echo
-tftp $image $part
diff --git a/board/pcm037/env/bin/boot b/board/pcm037/env/bin/boot
deleted file mode 100644
index dfb59aa..0000000
--- a/board/pcm037/env/bin/boot
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-if [ x$1 = xnand ]; then
-	root=nand
-	kernel=nand
-fi
-
-if [ x$1 = xnet ]; then
-	root=net
-	kernel=net
-fi
-
-if [ x$1 = xnor ]; then
-	root=nor
-	kernel=nor
-fi
-
-if [ x$ip = xdhcp ]; then
-	bootargs="$bootargs ip=dhcp"
-else
-	bootargs="$bootargs ip=$eth0.ipaddr:$eth0.serverip:$eth0.gateway:$eth0.netmask:::"
-fi
-
-if [ x$root = xnand ]; then
-	bootargs="$bootargs root=$rootpart_nand rootfstype=jffs2"
-elif [ x$root = xnor ]; then
-	bootargs="$bootargs root=$rootpart_nor rootfstype=jffs2"
-else
-	bootargs="$bootargs root=/dev/nfs nfsroot=$eth0.serverip:$nfsroot,v3,tcp"
-fi
-
-bootargs="$bootargs mtdparts=physmap-flash.0:$nor_parts;imx_nand:$nand_parts"
-
-if [ $kernel = net ]; then
-	if [ x$ip = xdhcp ]; then
-		dhcp
-	fi
-	tftp $uimage uImage || exit 1
-	bootm uImage
-elif [ $kernel = nor ]; then
-	bootm /dev/nor0.kernel
-else
-	bootm /dev/nand0.kernel.bb
-fi
-
diff --git a/board/pcm037/env/bin/hush_hack b/board/pcm037/env/bin/hush_hack
deleted file mode 100644
index 5fffa92..0000000
--- a/board/pcm037/env/bin/hush_hack
+++ /dev/null
@@ -1 +0,0 @@
-nand -a /dev/nand0.*
diff --git a/board/pcm037/env/bin/init b/board/pcm037/env/bin/init
deleted file mode 100644
index 3bfd194..0000000
--- a/board/pcm037/env/bin/init
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-
-PATH=/env/bin
-export PATH
-
-. /env/config
-if [ -e /dev/nor0 ]; then
-	addpart /dev/nor0 $nor_parts
-fi
-
-if [ -e /dev/nand0 ]; then
-	addpart /dev/nand0 $nand_parts
-
-	# Uh, oh, hush first expands wildcards and then starts executing
-	# commands. What a bug!
-	source /env/bin/hush_hack 
-fi
-
-if [ -z $eth0.ethaddr ]; then
-	while [ -z $eth0.ethaddr ]; do
-		readline "no MAC address set for eth0. please enter the one found on your board: " eth0.ethaddr
-	done
-	echo -a /env/config "eth0.ethaddr=$eth0.ethaddr"
-fi
-
-echo
-echo -n "Hit any key to stop autoboot: "
-timeout -a $autoboot_timeout
-if [ $? != 0 ]; then
-	echo
-	echo "type update_kernel nand|nor [<imagename>] to update kernel into flash"
-	echo "type update_root nand|nor [<imagename>] to update rootfs into flash"
-	echo
-	exit
-fi
-
-boot
diff --git a/board/pcm037/env/bin/update_kernel b/board/pcm037/env/bin/update_kernel
deleted file mode 100644
index 05c822d..0000000
--- a/board/pcm037/env/bin/update_kernel
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-image=$uimage
-if [ x$1 = xnand ]; then
-	part=/dev/nand0.kernel.bb
-elif [ x$1 = xnor ]; then
-	part=/dev/nor0.kernel
-else
-	echo "usage: $0 nor|nand [imagename]"
-	exit 1
-fi
-
-. /env/bin/_update $2
diff --git a/board/pcm037/env/bin/update_root b/board/pcm037/env/bin/update_root
deleted file mode 100644
index eaf36eb..0000000
--- a/board/pcm037/env/bin/update_root
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-. /env/config
-
-image=$uimage
-if [ x$1 = xnand ]; then
-	part=/dev/nand0.root.bb
-elif [ x$1 = xnor ]; then
-	part=/dev/nor0.root
-else
-	echo "usage: $0 nor|nand [imagename]"
-	exit 1
-fi
-
-. /env/bin/_update $2
-
diff --git a/board/pcm037/env/config b/board/pcm037/env/config
index fb1f5af..bf15620 100644
--- a/board/pcm037/env/config
+++ b/board/pcm037/env/config
@@ -1,24 +1,11 @@
 #!/bin/sh
 
-# can be either 'net', 'nor' or 'nand''
-kernel=net
-root=net
-
-uimage=uImage-pcm037
-jffs2=root-pcm037.jffs2
-
-autoboot_timeout=3
-
-nfsroot="/ptx/work/octopus/rsc/svn/oselas/bsp/phytec/phyCORE-i.MX27/OSELAS.BSP-Phytec-phyCORE-i.MX27-trunk/root"
-bootargs="console=ttymxc0,115200"
-
-nor_parts="256k(barebox)ro,128k(bareboxenv),1536k(kernel),-(root)"
-rootpart_nor="/dev/mtdblock3"
-
-nand_parts="256k(barebox)ro,128k(bareboxenv),1536k(kernel),-(root)"
-rootpart_nand="/dev/mtdblock7"
+machine=pcm037
+eth0.serverip=
+user=
 
 # use 'dhcp' to do dhcp in barebox and in kernel
+# use 'none' if you want to skip kernel ip autoconfiguration
 ip=dhcp
 
 # or set your networking parameters here
@@ -26,3 +13,44 @@ ip=dhcp
 #eth0.netmask=a.b.c.d
 #eth0.gateway=a.b.c.d
 #eth0.serverip=a.b.c.d
+
+# can be either 'net', 'nor' or 'nand'
+kernel_loc=net
+# can be either 'net', 'nor', 'nand' or 'initrd'
+rootfs_loc=net
+
+# can be either 'jffs2' or 'ubifs'
+rootfs_type=ubifs
+rootfsimage=root-$machine.$rootfs_type
+
+# The image type of the kernel. Can be uimage, zimage, raw, or raw_lzo
+kernelimage_type=zimage
+kernelimage=zImage-$machine
+#kernelimage_type=uimage
+#kernelimage=uImage-$machine
+#kernelimage_type=raw
+#kernelimage=Image-$machine
+#kernelimage_type=raw_lzo
+#kernelimage=Image-$machine.lzo
+
+if [ -n $user ]; then
+	kernelimage="$user"-"$kernelimage"
+	nfsroot="$eth0.serverip:/home/$user/nfsroot/$machine"
+	rootfsimage="$user"-"$rootfsimage"
+else
+	nfsroot="$eth0.serverip:/path/to/nfs/root"
+fi
+
+autoboot_timeout=3
+
+bootargs="console=ttymxc0,115200"
+
+nor_parts="256k(barebox)ro,128k(bareboxenv),2M(kernel),-(root)"
+rootfs_mtdblock_nor=3
+
+nand_parts="256k(barebox)ro,128k(bareboxenv),2M(kernel),-(root)"
+rootfs_mtdblock_nand=7
+
+# set a fancy prompt (if support is compiled in)
+PS1="\e[1;32mbarebox@\e[1;31m\h:\w\e[0m "
+
-- 
1.7.1



From eric at eukrea.com  Mon Jun 14 08:04:40 2010
From: eric at eukrea.com (=?ISO-8859-15?Q?Eric_B=E9nard?=)
Date: Mon, 14 Jun 2010 14:04:40 +0200
Subject: barebox for i.MX51
In-Reply-To: <20100610150031.GT20799@pengutronix.de>
References: <4C10F8E5.3010600@eukrea.com>
	<20100610150031.GT20799@pengutronix.de>
Message-ID: <4C161AD8.3060209@eukrea.com>

Hi Sascha,

Le 10/06/2010 17:00, Sascha Hauer a ?crit :
> I have started to work on it, but it surely needs some polishing. Find it in
> the mx51 branch in the master repository.

thanks, I'll start on this next week I hope.

Eric


From ivo.clarysse at gmail.com  Mon Jun 14 09:01:48 2010
From: ivo.clarysse at gmail.com (Ivo Clarysse)
Date: Mon, 14 Jun 2010 15:01:48 +0200
Subject: [PATCH 6/8] mx25 3ds: add support for i2c master and PMIC
In-Reply-To: <a2ce7c2796ea62c9ff75eeb6e72a8a36c2675337.1276065824.git.baruch@tkos.co.il>
References: <cover.1276065824.git.baruch@tkos.co.il>
	<a2ce7c2796ea62c9ff75eeb6e72a8a36c2675337.1276065824.git.baruch@tkos.co.il>
Message-ID: <AANLkTimRyz5AGQltJB8G1_J5RkXZBt9lL8xHIGurAyJC@mail.gmail.com>

On barebox-next, I get:

board/freescale-mx25-3-stack/built-in.o: In function `go':
3stack.c:(.flash_header_start+0x0): undefined reference to `_start'
board/freescale-mx25-3-stack/built-in.o: In function `imx25_3ds_fec_init':
3stack.c:(.text.imx25_3ds_fec_init+0x4): undefined reference to `mc34704_get'
3stack.c:(.text.imx25_3ds_fec_init+0x1c): undefined reference to
`mc34704_reg_write'


I guess this change also needs:

diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index afd8cae..18a9cbc 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -140,6 +140,8 @@ config MACH_FREESCALE_MX25_3STACK
        bool "Freescale MX25 3stack"
        select HAS_CFI
        select MACH_HAS_LOWLEVEL_INIT
+       select I2C
+       select DRIVER_I2C_MC34704
        help
          Say Y here if you are using the Freescale MX25 3stack board equipped
          with a Freescale i.MX25 Processor



On Wed, Jun 9, 2010 at 9:05 AM, Baruch Siach <baruch at tkos.co.il> wrote:
> Signed-off-by: Baruch Siach <baruch at tkos.co.il>
> ---
> ?board/freescale-mx25-3-stack/3stack.c | ? 18 ++++++++++++++++++
> ?1 files changed, 18 insertions(+), 0 deletions(-)
>
> diff --git a/board/freescale-mx25-3-stack/3stack.c b/board/freescale-mx25-3-stack/3stack.c
> index 6659185..316a2bc 100644
> --- a/board/freescale-mx25-3-stack/3stack.c
> +++ b/board/freescale-mx25-3-stack/3stack.c
> @@ -36,6 +36,8 @@
> ?#include <nand.h>
> ?#include <mach/imx-flash-header.h>
> ?#include <mach/iomux-mx25.h>
> +#include <i2c/i2c.h>
> +#include <i2c/mc34704.h>
>
> ?extern unsigned long _stext;
>
> @@ -183,8 +185,18 @@ static struct device_d usbh2_dev = {
> ?};
> ?#endif
>
> +static struct i2c_board_info i2c_devices[] = {
> + ? ? ? {
> + ? ? ? ? ? ? ? I2C_BOARD_INFO("mc34704", 0x54),
> + ? ? ? },
> +};
> ?#define IOMUXC_BASE_ADDR ? ? ? ?0x43FAC000
>
> +static struct device_d i2c_dev = {
> + ? ? ? .name ? ? = "i2c-imx",
> + ? ? ? .map_base = IMX_I2C1_BASE,
> +};
> +
> ?static int imx25_devices_init(void)
> ?{
> ? ? ? ?ulong val;
> @@ -256,6 +268,9 @@ static int imx25_devices_init(void)
> ? ? ? ?register_device(&sdram0_dev);
> ? ? ? ?register_device(&sram0_dev);
>
> + ? ? ? i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices));
> + ? ? ? register_device(&i2c_dev);
> +
> ? ? ? ?armlinux_set_bootparams((void *)0x80000100);
> ? ? ? ?armlinux_set_architecture(MACH_TYPE_MX25_3DS);
>
> @@ -303,6 +318,9 @@ static struct pad_desc imx25_pads[] = {
> ? ? ? ?MX25_PAD_VSYNC__USBH2_DATA5,
> ? ? ? ?MX25_PAD_LSCLK__USBH2_DATA6,
> ? ? ? ?MX25_PAD_OE_ACD__USBH2_DATA7,
> + ? ? ? /* i2c */
> + ? ? ? MX25_PAD_I2C1_CLK__SCL,
> + ? ? ? MX25_PAD_I2C1_DAT__SDA,
> ?};
>
> ?static int imx25_console_init(void)
> --
> 1.7.1
>
>
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>


From baruch at tkos.co.il  Mon Jun 14 09:39:20 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Mon, 14 Jun 2010 16:39:20 +0300
Subject: [PATCH 6/8] mx25 3ds: add support for i2c master and PMIC
In-Reply-To: <AANLkTimRyz5AGQltJB8G1_J5RkXZBt9lL8xHIGurAyJC@mail.gmail.com>
References: <cover.1276065824.git.baruch@tkos.co.il>
	<a2ce7c2796ea62c9ff75eeb6e72a8a36c2675337.1276065824.git.baruch@tkos.co.il>
	<AANLkTimRyz5AGQltJB8G1_J5RkXZBt9lL8xHIGurAyJC@mail.gmail.com>
Message-ID: <20100614133920.GC2395@tarshish>

Hi Ivo,

On Mon, Jun 14, 2010 at 03:01:48PM +0200, Ivo Clarysse wrote:
> On barebox-next, I get:
> 
> board/freescale-mx25-3-stack/built-in.o: In function `go':
> 3stack.c:(.flash_header_start+0x0): undefined reference to `_start'
> board/freescale-mx25-3-stack/built-in.o: In function `imx25_3ds_fec_init':
> 3stack.c:(.text.imx25_3ds_fec_init+0x4): undefined reference to `mc34704_get'
> 3stack.c:(.text.imx25_3ds_fec_init+0x1c): undefined reference to
> `mc34704_reg_write'
> 
> 
> I guess this change also needs:
> 
> diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
> index afd8cae..18a9cbc 100644
> --- a/arch/arm/mach-imx/Kconfig
> +++ b/arch/arm/mach-imx/Kconfig
> @@ -140,6 +140,8 @@ config MACH_FREESCALE_MX25_3STACK
>         bool "Freescale MX25 3stack"
>         select HAS_CFI
>         select MACH_HAS_LOWLEVEL_INIT
> +       select I2C
> +       select DRIVER_I2C_MC34704
>         help
>           Say Y here if you are using the Freescale MX25 3stack board equipped
>           with a Freescale i.MX25 Processor

Thanks.
Acked-by: Baruch Siach <baruch at tkos.co.il>

baruch

> On Wed, Jun 9, 2010 at 9:05 AM, Baruch Siach <baruch at tkos.co.il> wrote:
> > Signed-off-by: Baruch Siach <baruch at tkos.co.il>
> > ---
> > ?board/freescale-mx25-3-stack/3stack.c | ? 18 ++++++++++++++++++
> > ?1 files changed, 18 insertions(+), 0 deletions(-)
> >
> > diff --git a/board/freescale-mx25-3-stack/3stack.c b/board/freescale-mx25-3-stack/3stack.c
> > index 6659185..316a2bc 100644
> > --- a/board/freescale-mx25-3-stack/3stack.c
> > +++ b/board/freescale-mx25-3-stack/3stack.c
> > @@ -36,6 +36,8 @@
> > ?#include <nand.h>
> > ?#include <mach/imx-flash-header.h>
> > ?#include <mach/iomux-mx25.h>
> > +#include <i2c/i2c.h>
> > +#include <i2c/mc34704.h>
> >
> > ?extern unsigned long _stext;
> >
> > @@ -183,8 +185,18 @@ static struct device_d usbh2_dev = {
> > ?};
> > ?#endif
> >
> > +static struct i2c_board_info i2c_devices[] = {
> > + ? ? ? {
> > + ? ? ? ? ? ? ? I2C_BOARD_INFO("mc34704", 0x54),
> > + ? ? ? },
> > +};
> > ?#define IOMUXC_BASE_ADDR ? ? ? ?0x43FAC000
> >
> > +static struct device_d i2c_dev = {
> > + ? ? ? .name ? ? = "i2c-imx",
> > + ? ? ? .map_base = IMX_I2C1_BASE,
> > +};
> > +
> > ?static int imx25_devices_init(void)
> > ?{
> > ? ? ? ?ulong val;
> > @@ -256,6 +268,9 @@ static int imx25_devices_init(void)
> > ? ? ? ?register_device(&sdram0_dev);
> > ? ? ? ?register_device(&sram0_dev);
> >
> > + ? ? ? i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices));
> > + ? ? ? register_device(&i2c_dev);
> > +
> > ? ? ? ?armlinux_set_bootparams((void *)0x80000100);
> > ? ? ? ?armlinux_set_architecture(MACH_TYPE_MX25_3DS);
> >
> > @@ -303,6 +318,9 @@ static struct pad_desc imx25_pads[] = {
> > ? ? ? ?MX25_PAD_VSYNC__USBH2_DATA5,
> > ? ? ? ?MX25_PAD_LSCLK__USBH2_DATA6,
> > ? ? ? ?MX25_PAD_OE_ACD__USBH2_DATA7,
> > + ? ? ? /* i2c */
> > + ? ? ? MX25_PAD_I2C1_CLK__SCL,
> > + ? ? ? MX25_PAD_I2C1_DAT__SDA,
> > ?};
> >
> > ?static int imx25_console_init(void)
> > --
> > 1.7.1

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -


From baruch at tkos.co.il  Tue Jun 15 01:12:35 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Tue, 15 Jun 2010 08:12:35 +0300
Subject: [PATCH] i2c: fix adapter_list manipulation
In-Reply-To: <471ada329c4028bfda67cfa2bca1e131aed6ae0e.1276022070.git.baruch@tkos.co.il>
References: <471ada329c4028bfda67cfa2bca1e131aed6ae0e.1276022070.git.baruch@tkos.co.il>
Message-ID: <20100615051235.GC3233@jasper.tkos.co.il>

Hi barebox list,

Ping?
This seems to fix an obvious bug.

baruch

On Tue, Jun 08, 2010 at 09:36:04PM +0300, Baruch Siach wrote:
> Signed-off-by: Baruch Siach <baruch at tkos.co.il>
> ---
>  drivers/i2c/i2c.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> index 1fa114a..87360f3 100644
> --- a/drivers/i2c/i2c.c
> +++ b/drivers/i2c/i2c.c
> @@ -365,7 +365,7 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
>  	if (i2c_get_adapter(adapter->nr))
>  		return -EBUSY;
>  
> -	list_add_tail(&adapter_list, &adapter->list);
> +	list_add_tail(&adapter->list, &adapter_list);
>  
>  	/* populate children from any i2c device tables */
>  	scan_boardinfo(adapter);
> -- 
> 1.7.1
> 

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -


From u.kleine-koenig at pengutronix.de  Tue Jun 15 05:13:03 2010
From: u.kleine-koenig at pengutronix.de (Uwe =?iso-8859-1?Q?Kleine-K=F6nig?=)
Date: Tue, 15 Jun 2010 11:13:03 +0200
Subject: [PATCH 07/11] add a generic default environment
In-Reply-To: <1276508921-3264-8-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
	<1276508921-3264-8-git-send-email-s.hauer@pengutronix.de>
Message-ID: <20100615091303.GB17595@pengutronix.de>

Hello Sascha,

> diff --git a/defaultenv/bin/boot b/defaultenv/bin/boot
> new file mode 100644
> index 0000000..8c300a3
> --- /dev/null
> +++ b/defaultenv/bin/boot
> @@ -0,0 +1,110 @@
> +#!/bin/sh
> +
> +. /env/config
> +
> +if [ x$1 = xnand ]; then
> +	rootfs_loc=nand
> +	kernel_loc=nand
> +elif [ x$1 = xnor ]; then
> +	rootfs_loc=nor
> +	kernel_loc=nor
> +elif [ x$1 = xnet ]; then
> +	rootfs_loc=net
> +	kernel_loc=net
> +fi
case "$1" in
nand|nor|net)
	rootfs_loc=$1;
	kernel_loc=$1;
	;;
esac

> +
> +
> +if [ x$ip = xdhcp ]; then
> +	bootargs="$bootargs ip=dhcp"
> +elif [ x$ip = xnone ]; then
> +	bootargs="ip=none"
> +else
> +	bootargs="$bootargs ip=$eth0.ipaddr::$eth0.gateway:$eth0.netmask:::"
> +fi
> +
> +
> +if [ $rootfs_loc = net ]; then
"x$rootfs_loc" = "xnet"

> +	bootargs="$bootargs root=/dev/nfs nfsroot=$nfsroot,v3,tcp noinitrd"
> +elif [ $rootfs_loc = initrd ]; then
> +	bootargs="$bootargs root=/dev/ram0 rdinit=/sbin/init"
Wouldn't it be nice to load the initrd into /dev/ram0, too?

> +else
> +	if [ x$rootfs_loc = xnand ]; then
> +		rootfs_mtdblock=$rootfs_mtdblock_nand
> +	else
> +		rootfs_mtdblock=$rootfs_mtdblock_nor
> +	fi
> +
> +	if [ $rootfs_type = ubifs ]; then
> +		bootargs="$bootargs root=ubi0:root ubi.mtd=$rootfs_mtdblock"
> +	else
> +		bootargs="$bootargs root=/dev/mtdblock$rootfs_mtdblock"
> +	fi
> +
> +	bootargs="$bootargs rootfstype=$rootfs_type noinitrd"
> +fi
> +
> +if [ -n $nor_parts ]; then
> +	mtdparts="${mtdparts}physmap-flash.o:${nor_parts};"
> +fi
> +
> +if [ -n $nand_parts ]; then
> +	mtdparts="${mtdparts}$nand_device:${nor_parts};"
> +fi
> +
> +if [ -n $mtdparts ]; then
> +	bootargs="${bootargs} mtdparts=\"${mtdparts}\""
> +fi
> +
> +if [ ! -e /dev/ram0.kernelraw ]; then
> +	# arm raw kernel images are usually located at sdram start + 0x8000
> +	addpart dev/ram0 8M at 0x8000(kernelraw)
> +fi
> +
> +if [ ! -e /dev/ram0.kernel ]; then
> +	# Here we can safely put the kernel without risking of overwriting it
> +	# while extracting
> +	addpart dev/ram0 8M(kernel)
> +fi
> +
> +if [ $kernel_loc = net ]; then
> +	if [ x$ip = xdhcp ]; then
> +		dhcp
> +	fi
> +	if [ $kernelimage_type = uimage ]; then
> +		netload="/dev/ram0.kernel"
> +	elif [ $kernelimage_type = zimage ]; then
> +		netload="/dev/ram0.kernel"
> +	elif [ $kernelimage_type = raw ]; then
> +		netload="/dev/ram0.kernelraw"
> +	elif [ $kernelimage_type = raw_lzo ]; then
> +		netload="/dev/ram0.kernel"
> +	else
> +		echo "error: missing kernel_image_type"
> +		exit 1
> +	fi
> +	tftp $kernelimage $netload || exit 1
> +	kdev="$netload"
> +elif [ $kernel_loc = nor ]; then
> +	kdev="/dev/nor0.kernel"
> +elif [ $kernel_loc = nand ]; then
> +	kdev="/dev/nand0.kernel.bb"
> +else
> +	echo "error: missing kernel_loc"
> +	exit 1
> +fi
> +
> +if [ $kernelimage_type = uimage ]; then
> +	bootm $kdev
> +elif [ $kernelimage_type = zimage ]; then
> +	bootz $kdev
> +elif [ $kernelimage_type = raw ]; then
> +	if [ $kernel_loc != net ]; then
> +		ec
maybe better spell that out?

> +		cp $kdev /dev/ram0.kernelraw
> +	fi
> +	bootu /dev/ram0.kernelraw
> +elif [ $kernelimage_type = raw_lzo ]; then
> +	unlzo $kdev /dev/ram0.kernelraw
> +	bootu /dev/ram0.kernelraw
> +fi
> +
trailing new line

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |


From jacmet at sunsite.dk  Tue Jun 15 05:39:39 2010
From: jacmet at sunsite.dk (Peter Korsgaard)
Date: Tue, 15 Jun 2010 11:39:39 +0200
Subject: [PATCH 04/11] include support for a simple pseudo number generator
In-Reply-To: <1276508921-3264-5-git-send-email-s.hauer@pengutronix.de> (Sascha
	Hauer's message of "Mon, 14 Jun 2010 11:48:34 +0200")
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
	<1276508921-3264-5-git-send-email-s.hauer@pengutronix.de>
Message-ID: <87d3vseisk.fsf@macbook.be.48ers.dk>

>>>>> "Sascha" == Sascha Hauer <s.hauer at pengutronix.de> writes:

 Sascha> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
 Sascha> ---
 Sascha>  include/random.h |    7 +++++++
 Sascha>  lib/Makefile     |    1 +
 Sascha>  lib/random.c     |   22 ++++++++++++++++++++++
 Sascha>  3 files changed, 30 insertions(+), 0 deletions(-)
 Sascha>  create mode 100644 include/random.h
 Sascha>  create mode 100644 lib/random.c

 Sascha> diff --git a/lib/random.c b/lib/random.c
 Sascha> new file mode 100644
 Sascha> index 0000000..25315e7
 Sascha> --- /dev/null
 Sascha> +++ b/lib/random.c
 Sascha> @@ -0,0 +1,22 @@
 Sascha> +#include <common.h>
 Sascha> +#include <random.h>
 Sascha> +
 Sascha> +static int random_seed;
 Sascha> +
 Sascha> +static unsigned char rand(void)
 Sascha> +{
 Sascha> +	random_seed = random_seed * 1103515245 + 12345;
 Sascha> +	return (unsigned char)(random_seed / 65536) % 256;
 Sascha> +}

Any reason to not make this public and return int instead similar to
rand(3)?

We could presumably simply do:

#define RAND_MAX 255

And to be completely correct, these prototypes should be in stdlib.h
instead.

-- 
Bye, Peter Korsgaard


From mkl at pengutronix.de  Tue Jun 15 06:01:26 2010
From: mkl at pengutronix.de (Marc Kleine-Budde)
Date: Tue, 15 Jun 2010 12:01:26 +0200
Subject: [PATCH 07/11] add a generic default environment
In-Reply-To: <20100615091303.GB17595@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>	<1276508921-3264-8-git-send-email-s.hauer@pengutronix.de>
	<20100615091303.GB17595@pengutronix.de>
Message-ID: <4C174F76.2040109@pengutronix.de>

Uwe Kleine-K?nig wrote:
> Hello Sascha,
> 
>> diff --git a/defaultenv/bin/boot b/defaultenv/bin/boot
>> new file mode 100644
>> index 0000000..8c300a3
>> --- /dev/null
>> +++ b/defaultenv/bin/boot
>> @@ -0,0 +1,110 @@
>> +#!/bin/sh
>> +
>> +. /env/config
>> +
>> +if [ x$1 = xnand ]; then
>> +	rootfs_loc=nand
>> +	kernel_loc=nand
>> +elif [ x$1 = xnor ]; then
>> +	rootfs_loc=nor
>> +	kernel_loc=nor
>> +elif [ x$1 = xnet ]; then
>> +	rootfs_loc=net
>> +	kernel_loc=net
>> +fi
> case "$1" in
> nand|nor|net)
> 	rootfs_loc=$1;
> 	kernel_loc=$1;
> 	;;
> esac

AFAIK, the barebox shell doesn't support case.

> 
>> +
>> +
>> +if [ x$ip = xdhcp ]; then
>> +	bootargs="$bootargs ip=dhcp"
>> +elif [ x$ip = xnone ]; then
>> +	bootargs="ip=none"
>> +else
>> +	bootargs="$bootargs ip=$eth0.ipaddr::$eth0.gateway:$eth0.netmask:::"
>> +fi
>> +
>> +
>> +if [ $rootfs_loc = net ]; then
> "x$rootfs_loc" = "xnet"
> 
>> +	bootargs="$bootargs root=/dev/nfs nfsroot=$nfsroot,v3,tcp noinitrd"
>> +elif [ $rootfs_loc = initrd ]; then
>> +	bootargs="$bootargs root=/dev/ram0 rdinit=/sbin/init"
> Wouldn't it be nice to load the initrd into /dev/ram0, too?

at least for ARM barebox only supports initrd compiled into the kernel,
thus there's no need to load the inird explicitly.

> 
>> +else
>> +	if [ x$rootfs_loc = xnand ]; then
>> +		rootfs_mtdblock=$rootfs_mtdblock_nand
>> +	else
>> +		rootfs_mtdblock=$rootfs_mtdblock_nor
>> +	fi
>> +
>> +	if [ $rootfs_type = ubifs ]; then
>> +		bootargs="$bootargs root=ubi0:root ubi.mtd=$rootfs_mtdblock"
>> +	else
>> +		bootargs="$bootargs root=/dev/mtdblock$rootfs_mtdblock"
>> +	fi
>> +
>> +	bootargs="$bootargs rootfstype=$rootfs_type noinitrd"
>> +fi
>> +
>> +if [ -n $nor_parts ]; then
>> +	mtdparts="${mtdparts}physmap-flash.o:${nor_parts};"
>> +fi
>> +
>> +if [ -n $nand_parts ]; then
>> +	mtdparts="${mtdparts}$nand_device:${nor_parts};"
>> +fi
>> +
>> +if [ -n $mtdparts ]; then
>> +	bootargs="${bootargs} mtdparts=\"${mtdparts}\""
>> +fi
>> +
>> +if [ ! -e /dev/ram0.kernelraw ]; then
>> +	# arm raw kernel images are usually located at sdram start + 0x8000
>> +	addpart dev/ram0 8M at 0x8000(kernelraw)
>> +fi
>> +
>> +if [ ! -e /dev/ram0.kernel ]; then
>> +	# Here we can safely put the kernel without risking of overwriting it
>> +	# while extracting
>> +	addpart dev/ram0 8M(kernel)
>> +fi
>> +
>> +if [ $kernel_loc = net ]; then
>> +	if [ x$ip = xdhcp ]; then
>> +		dhcp
>> +	fi
>> +	if [ $kernelimage_type = uimage ]; then
>> +		netload="/dev/ram0.kernel"
>> +	elif [ $kernelimage_type = zimage ]; then
>> +		netload="/dev/ram0.kernel"
>> +	elif [ $kernelimage_type = raw ]; then
>> +		netload="/dev/ram0.kernelraw"
>> +	elif [ $kernelimage_type = raw_lzo ]; then
>> +		netload="/dev/ram0.kernel"
>> +	else
>> +		echo "error: missing kernel_image_type"
>> +		exit 1
>> +	fi
>> +	tftp $kernelimage $netload || exit 1
>> +	kdev="$netload"
>> +elif [ $kernel_loc = nor ]; then
>> +	kdev="/dev/nor0.kernel"
>> +elif [ $kernel_loc = nand ]; then
>> +	kdev="/dev/nand0.kernel.bb"
>> +else
>> +	echo "error: missing kernel_loc"
>> +	exit 1
>> +fi
>> +
>> +if [ $kernelimage_type = uimage ]; then
>> +	bootm $kdev
>> +elif [ $kernelimage_type = zimage ]; then
>> +	bootz $kdev
>> +elif [ $kernelimage_type = raw ]; then
>> +	if [ $kernel_loc != net ]; then
>> +		ec
> maybe better spell that out?
> 
>> +		cp $kdev /dev/ram0.kernelraw
>> +	fi
>> +	bootu /dev/ram0.kernelraw
>> +elif [ $kernelimage_type = raw_lzo ]; then
>> +	unlzo $kdev /dev/ram0.kernelraw
>> +	bootu /dev/ram0.kernelraw
>> +fi
>> +
> trailing new line
> 
> Best regards
> Uwe
> 

cheers, Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20100615/b1897fbc/attachment.sig>

From s.hauer at pengutronix.de  Tue Jun 15 07:54:52 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 15 Jun 2010 13:54:52 +0200
Subject: [PATCH 04/11] include support for a simple pseudo number generator
In-Reply-To: <87d3vseisk.fsf@macbook.be.48ers.dk>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
	<1276508921-3264-5-git-send-email-s.hauer@pengutronix.de>
	<87d3vseisk.fsf@macbook.be.48ers.dk>
Message-ID: <20100615115452.GC20799@pengutronix.de>

Hi Peter,

On Tue, Jun 15, 2010 at 11:39:39AM +0200, Peter Korsgaard wrote:
> >>>>> "Sascha" == Sascha Hauer <s.hauer at pengutronix.de> writes:
> 
>  Sascha> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
>  Sascha> ---
>  Sascha>  include/random.h |    7 +++++++
>  Sascha>  lib/Makefile     |    1 +
>  Sascha>  lib/random.c     |   22 ++++++++++++++++++++++
>  Sascha>  3 files changed, 30 insertions(+), 0 deletions(-)
>  Sascha>  create mode 100644 include/random.h
>  Sascha>  create mode 100644 lib/random.c
> 
>  Sascha> diff --git a/lib/random.c b/lib/random.c
>  Sascha> new file mode 100644
>  Sascha> index 0000000..25315e7
>  Sascha> --- /dev/null
>  Sascha> +++ b/lib/random.c
>  Sascha> @@ -0,0 +1,22 @@
>  Sascha> +#include <common.h>
>  Sascha> +#include <random.h>
>  Sascha> +
>  Sascha> +static int random_seed;
>  Sascha> +
>  Sascha> +static unsigned char rand(void)
>  Sascha> +{
>  Sascha> +	random_seed = random_seed * 1103515245 + 12345;
>  Sascha> +	return (unsigned char)(random_seed / 65536) % 256;
>  Sascha> +}
> 
> Any reason to not make this public and return int instead similar to
> rand(3)?

The reason was that I did not need rand but get_random_bytes and I
wasn't aware that rand() is that close to the corresponding libc
function.

> 
> We could presumably simply do:
> 
> #define RAND_MAX 255
> 
> And to be completely correct, these prototypes should be in stdlib.h
> instead.

Ok, will do.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From w.sang at pengutronix.de  Wed Jun 16 23:22:45 2010
From: w.sang at pengutronix.de (Wolfram Sang)
Date: Thu, 17 Jun 2010 05:22:45 +0200
Subject: [PATCH] drivers/nor: allow overriding of AMD_ADDR_* in board-configs
Message-ID: <1276744965-994-1-git-send-email-w.sang@pengutronix.de>

Because there are a number of flash-makers who did it wrong.

Signed-off-by: Wolfram Sang <w.sang at pengutronix.de>
---
 drivers/nor/cfi_flash.h |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/nor/cfi_flash.h b/drivers/nor/cfi_flash.h
index a8fa879..a278772 100644
--- a/drivers/nor/cfi_flash.h
+++ b/drivers/nor/cfi_flash.h
@@ -109,9 +109,16 @@ extern struct cfi_cmd_set cfi_cmd_set_amd;
 #define AMD_STATUS_TOGGLE		0x40
 #define AMD_STATUS_ERROR		0x20
 
-#define AMD_ADDR_ERASE_START	((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
-#define AMD_ADDR_START		((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
-#define AMD_ADDR_ACK		((info->portwidth == FLASH_CFI_8BIT) ? 0x555 : 0x2AA)
+/* AMD_ADDR_* can be overridden in board-specific config.h files */
+#ifndef AMD_ADDR_ERASE_START
+#  define AMD_ADDR_ERASE_START	((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
+#endif
+#ifndef AMD_ADDR_START
+#  define AMD_ADDR_START	((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
+#endif
+#ifndef AMD_ADDR_ACK
+#  define AMD_ADDR_ACK		((info->portwidth == FLASH_CFI_8BIT) ? 0x555 : 0x2AA)
+#endif
 
 #define FLASH_OFFSET_MANUFACTURER_ID	0x00
 #define FLASH_OFFSET_DEVICE_ID		0x01
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 17 04:54:04 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 17 Jun 2010 10:54:04 +0200
Subject: [PATCH] drivers/nor: allow overriding of AMD_ADDR_* in
	board-configs
In-Reply-To: <1276744965-994-1-git-send-email-w.sang@pengutronix.de>
References: <1276744965-994-1-git-send-email-w.sang@pengutronix.de>
Message-ID: <20100617085404.GL20799@pengutronix.de>

On Thu, Jun 17, 2010 at 05:22:45AM +0200, Wolfram Sang wrote:
> Because there are a number of flash-makers who did it wrong.
> 
> Signed-off-by: Wolfram Sang <w.sang at pengutronix.de>
> ---
>  drivers/nor/cfi_flash.h |   13 ++++++++++---
>  1 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/nor/cfi_flash.h b/drivers/nor/cfi_flash.h
> index a8fa879..a278772 100644
> --- a/drivers/nor/cfi_flash.h
> +++ b/drivers/nor/cfi_flash.h
> @@ -109,9 +109,16 @@ extern struct cfi_cmd_set cfi_cmd_set_amd;
>  #define AMD_STATUS_TOGGLE		0x40
>  #define AMD_STATUS_ERROR		0x20
>  
> -#define AMD_ADDR_ERASE_START	((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
> -#define AMD_ADDR_START		((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
> -#define AMD_ADDR_ACK		((info->portwidth == FLASH_CFI_8BIT) ? 0x555 : 0x2AA)
> +/* AMD_ADDR_* can be overridden in board-specific config.h files */
> +#ifndef AMD_ADDR_ERASE_START
> +#  define AMD_ADDR_ERASE_START	((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
> +#endif
> +#ifndef AMD_ADDR_START
> +#  define AMD_ADDR_START	((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
> +#endif
> +#ifndef AMD_ADDR_ACK
> +#  define AMD_ADDR_ACK		((info->portwidth == FLASH_CFI_8BIT) ? 0x555 : 0x2AA)
> +#endif

Uh, Having arbitrary board specific defines is exactly what I wanted to
get rid of while rewriting U-Boot. Sorry, this is not acceptable.

There are some ways to do this: You could add a runtime detection if
possible, maybe combined with a kconfig option if it influences image
size too badly. Or you could add the information to platform_data.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 17 08:00:37 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 17 Jun 2010 14:00:37 +0200
Subject: [PATCH] i2c: fix adapter_list manipulation
In-Reply-To: <20100615051235.GC3233@jasper.tkos.co.il>
References: <471ada329c4028bfda67cfa2bca1e131aed6ae0e.1276022070.git.baruch@tkos.co.il>
	<20100615051235.GC3233@jasper.tkos.co.il>
Message-ID: <20100617120037.GM20799@pengutronix.de>

On Tue, Jun 15, 2010 at 08:12:35AM +0300, Baruch Siach wrote:
> Hi barebox list,
> 
> Ping?

Sorry, missed this one. Applied.

Sascha

> This seems to fix an obvious bug.
> 
> baruch
> 
> On Tue, Jun 08, 2010 at 09:36:04PM +0300, Baruch Siach wrote:
> > Signed-off-by: Baruch Siach <baruch at tkos.co.il>
> > ---
> >  drivers/i2c/i2c.c |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> > 
> > diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> > index 1fa114a..87360f3 100644
> > --- a/drivers/i2c/i2c.c
> > +++ b/drivers/i2c/i2c.c
> > @@ -365,7 +365,7 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
> >  	if (i2c_get_adapter(adapter->nr))
> >  		return -EBUSY;
> >  
> > -	list_add_tail(&adapter_list, &adapter->list);
> > +	list_add_tail(&adapter->list, &adapter_list);
> >  
> >  	/* populate children from any i2c device tables */
> >  	scan_boardinfo(adapter);
> > -- 
> > 1.7.1
> > 
> 
> -- 
>                                                      ~. .~   Tk Open Systems
> =}------------------------------------------------ooO--U--Ooo------------{=
>    - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From mailinglists at erwinrol.com  Thu Jun 17 08:18:17 2010
From: mailinglists at erwinrol.com (Erwin Rol)
Date: Thu, 17 Jun 2010 14:18:17 +0200
Subject: bareboxenv for target
Message-ID: <4C1A1289.4010505@erwinrol.com>

Hey all,

i would like to have the bareboxenv tool on my target system, but 
barebox only builds it for the host system.

I am not that fit with kconfig so anybody a hint on how to compile it 
for the target system ?

- Erwin


From eric at eukrea.com  Thu Jun 17 08:57:19 2010
From: eric at eukrea.com (=?ISO-8859-1?Q?Eric_B=E9nard?=)
Date: Thu, 17 Jun 2010 14:57:19 +0200
Subject: bareboxenv for target
In-Reply-To: <4C1A1289.4010505@erwinrol.com>
References: <4C1A1289.4010505@erwinrol.com>
Message-ID: <4C1A1BAF.2050603@eukrea.com>

Hi Erwin,

Le 17/06/2010 14:18, Erwin Rol a ?crit :
> i would like to have the bareboxenv tool on my target system, but
> barebox only builds it for the host system.
>
> I am not that fit with kconfig so anybody a hint on how to compile it
> for the target system ?
>
# cd scripts
# arm-none-linux-gnueabi-gcc bareboxenv.c -o bbarm
# file bbarm
bbarm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically 
linked (uses shared libs), for GNU/Linux 2.6.14, not stripped

Eric


From s.hauer at pengutronix.de  Thu Jun 17 09:17:24 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 17 Jun 2010 15:17:24 +0200
Subject: [PATCH 04/11] include support for a simple pseudo number generator
In-Reply-To: <1276508921-3264-5-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
	<1276508921-3264-5-git-send-email-s.hauer@pengutronix.de>
Message-ID: <20100617131724.GN20799@pengutronix.de>


Here is an updated version. I have put get_random_bytes() into
stdlib.h aswell, though of course this is no stdlib function.

Sascha

[PATCH 04/24] include support for a simple pseudo number generator

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/net.h    |    1 +
 include/stdlib.h |   16 ++++++++++++++++
 lib/Makefile     |    1 +
 lib/random.c     |   22 ++++++++++++++++++++++
 4 files changed, 40 insertions(+), 0 deletions(-)
 create mode 100644 include/stdlib.h
 create mode 100644 lib/random.c

diff --git a/include/net.h b/include/net.h
index 8db83d8..709e76c 100644
--- a/include/net.h
+++ b/include/net.h
@@ -16,6 +16,7 @@
 #include <linux/types.h>
 #include <param.h>
 #include <malloc.h>
+#include <stdlib.h>
 #include <asm/byteorder.h>	/* for nton* / ntoh* stuff */
 
 
diff --git a/include/stdlib.h b/include/stdlib.h
new file mode 100644
index 0000000..dc72013
--- /dev/null
+++ b/include/stdlib.h
@@ -0,0 +1,16 @@
+#ifndef __STDLIB_H
+#define __STDLIB_H
+
+#define RAND_MAX 32767
+
+/* return a pseudo-random integer in the range [0, RAND_MAX] */
+unsigned int rand(void);
+
+/* set the seed for rand () */
+void srand(unsigned int seed);
+
+/* fill a buffer with pseudo-random data */
+void get_random_bytes(char *buf, int len);
+
+
+#endif /* __STDLIB_H */
diff --git a/lib/Makefile b/lib/Makefile
index b072fb6..4a33aaa 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
 obj-y			+= glob.o
 obj-y			+= notifier.o
 obj-y			+= copy_file.o
+obj-y			+= random.o
 obj-y			+= lzo/
 obj-$(CONFIG_LZO_DECOMPRESS)		+= decompress_unlzo.o
 obj-$(CONFIG_PROCESS_ESCAPE_SEQUENCE)	+= process_escape_sequence.o
diff --git a/lib/random.c b/lib/random.c
new file mode 100644
index 0000000..48c923f
--- /dev/null
+++ b/lib/random.c
@@ -0,0 +1,22 @@
+#include <common.h>
+#include <stdlib.h>
+
+static unsigned int random_seed;
+
+unsigned int rand(void)
+{
+	random_seed = random_seed * 1103515245 + 12345;
+	return (random_seed / 65536) % 32768;
+}
+
+void srand(unsigned int seed)
+{
+	random_seed = seed;
+}
+
+void get_random_bytes(char *buf, int len)
+{
+	while (len--)
+		*buf++ = rand() % 256;
+}
+
-- 
1.7.1


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 17 09:20:59 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 17 Jun 2010 15:20:59 +0200
Subject: [PATCH 07/11] add a generic default environment
In-Reply-To: <1276508921-3264-8-git-send-email-s.hauer@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
	<1276508921-3264-8-git-send-email-s.hauer@pengutronix.de>
Message-ID: <20100617132059.GO20799@pengutronix.de>

next try...

We have several nearly identical default environments in the tree.
Lets merge them to a single environment and use it on many boards.
This defaultenv is arm centric at the moment due to the use of arm
specific boot commands. This can be improved over time.

changes since last version:

- fix potentially empty variable tests
- be a bit more verbose in boot script
- run a board specific init script (/env/bin/init_board) if it exists

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 defaultenv/bin/_update       |   39 +++++++++++++++
 defaultenv/bin/boot          |  109 ++++++++++++++++++++++++++++++++++++++++++
 defaultenv/bin/hush_hack     |    1 +
 defaultenv/bin/init          |   34 +++++++++++++
 defaultenv/bin/update_kernel |   15 ++++++
 defaultenv/bin/update_rootfs |   16 ++++++
 6 files changed, 214 insertions(+), 0 deletions(-)
 create mode 100644 defaultenv/bin/_update
 create mode 100644 defaultenv/bin/boot
 create mode 100644 defaultenv/bin/hush_hack
 create mode 100644 defaultenv/bin/init
 create mode 100644 defaultenv/bin/update_kernel
 create mode 100644 defaultenv/bin/update_rootfs

diff --git a/defaultenv/bin/_update b/defaultenv/bin/_update
new file mode 100644
index 0000000..ddd6b84
--- /dev/null
+++ b/defaultenv/bin/_update
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+if [ -z "$part" -o -z "$image" ]; then
+	echo "define \$part and \$image"
+	exit 1
+fi
+
+if [ ! -e "$part" ]; then
+	echo "Partition $part does not exist"
+	exit 1
+fi
+
+if [ $# = 1 ]; then
+	image=$1
+fi
+
+if [ x$ip = xdhcp ]; then
+	dhcp
+fi
+
+ping $eth0.serverip
+if [ $? -ne 0 ] ; then
+	echo "Server did not reply! Update aborted."
+	exit 1
+fi
+
+unprotect $part
+
+echo
+echo "erasing partition $part"
+echo
+erase $part
+
+echo
+echo "flashing $image to $part"
+echo
+tftp $image $part
+
+protect $part
diff --git a/defaultenv/bin/boot b/defaultenv/bin/boot
new file mode 100644
index 0000000..6a508fb
--- /dev/null
+++ b/defaultenv/bin/boot
@@ -0,0 +1,109 @@
+#!/bin/sh
+
+. /env/config
+
+if [ x$1 = xnand ]; then
+	rootfs_loc=nand
+	kernel_loc=nand
+elif [ x$1 = xnor ]; then
+	rootfs_loc=nor
+	kernel_loc=nor
+elif [ x$1 = xnet ]; then
+	rootfs_loc=net
+	kernel_loc=net
+fi
+
+if [ x$ip = xdhcp ]; then
+	bootargs="$bootargs ip=dhcp"
+elif [ x$ip = xnone ]; then
+	bootargs="ip=none"
+else
+	bootargs="$bootargs ip=$eth0.ipaddr::$eth0.gateway:$eth0.netmask:::"
+fi
+
+
+if [ x$rootfs_loc = xnet ]; then
+	bootargs="$bootargs root=/dev/nfs nfsroot=$nfsroot,v3,tcp noinitrd"
+elif [ x$rootfs_loc = xinitrd ]; then
+	bootargs="$bootargs root=/dev/ram0 rdinit=/sbin/init"
+else
+	if [ x$rootfs_loc = xnand ]; then
+		rootfs_mtdblock=$rootfs_mtdblock_nand
+	else
+		rootfs_mtdblock=$rootfs_mtdblock_nor
+	fi
+
+	if [ x$rootfs_type = xubifs ]; then
+		bootargs="$bootargs root=ubi0:root ubi.mtd=$rootfs_mtdblock"
+	else
+		bootargs="$bootargs root=/dev/mtdblock$rootfs_mtdblock"
+	fi
+
+	bootargs="$bootargs rootfstype=$rootfs_type noinitrd"
+fi
+
+if [ -n $nor_parts ]; then
+	mtdparts="${mtdparts}physmap-flash.o:${nor_parts};"
+fi
+
+if [ -n $nand_parts ]; then
+	mtdparts="${mtdparts}$nand_device:${nor_parts};"
+fi
+
+if [ -n $mtdparts ]; then
+	bootargs="${bootargs} mtdparts=\"${mtdparts}\""
+fi
+
+if [ ! -e /dev/ram0.kernelraw ]; then
+	# arm raw kernel images are usually located at sdram start + 0x8000
+	addpart dev/ram0 8M at 0x8000(kernelraw)
+fi
+
+if [ ! -e /dev/ram0.kernel ]; then
+	# Here we can safely put the kernel without risking of overwriting it
+	# while extracting
+	addpart dev/ram0 8M(kernel)
+fi
+
+if [ x$kernel_loc = xnet ]; then
+	if [ x$ip = xdhcp ]; then
+		dhcp
+	fi
+	if [ $kernelimage_type = uimage ]; then
+		netload="/dev/ram0.kernel"
+	elif [ $kernelimage_type = zimage ]; then
+		netload="/dev/ram0.kernel"
+	elif [ $kernelimage_type = raw ]; then
+		netload="/dev/ram0.kernelraw"
+	elif [ $kernelimage_type = raw_lzo ]; then
+		netload="/dev/ram0.kernel"
+	else
+		echo "error: set kernelimage_type to one of 'uimage', 'zimage', 'raw' or 'raw_lzo'"
+		exit 1
+	fi
+	tftp $kernelimage $netload || exit 1
+	kdev="$netload"
+elif [ x$kernel_loc = xnor ]; then
+	kdev="/dev/nor0.kernel"
+elif [ x$kernel_loc = xnand ]; then
+	kdev="/dev/nand0.kernel.bb"
+else
+	echo "error: set kernel_loc to one of 'net', 'nand' or 'nor'"
+	exit 1
+fi
+
+echo "booting kernel of type $kernelimage_type from $kdev"
+
+if [ x$kernelimage_type = xuimage ]; then
+	bootm $kdev
+elif [ x$kernelimage_type = xzimage ]; then
+	bootz $kdev
+elif [ x$kernelimage_type = xraw ]; then
+	if [ $kernel_loc != net ]; then
+		cp $kdev /dev/ram0.kernelraw
+	fi
+	bootu /dev/ram0.kernelraw
+elif [ x$kernelimage_type = xraw_lzo ]; then
+	unlzo $kdev /dev/ram0.kernelraw
+	bootu /dev/ram0.kernelraw
+fi
diff --git a/defaultenv/bin/hush_hack b/defaultenv/bin/hush_hack
new file mode 100644
index 0000000..5fffa92
--- /dev/null
+++ b/defaultenv/bin/hush_hack
@@ -0,0 +1 @@
+nand -a /dev/nand0.*
diff --git a/defaultenv/bin/init b/defaultenv/bin/init
new file mode 100644
index 0000000..a55e8e6
--- /dev/null
+++ b/defaultenv/bin/init
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+PATH=/env/bin
+export PATH
+
+. /env/config
+if [ -e /dev/nor0 ]; then
+	addpart /dev/nor0 $nor_parts
+fi
+
+if [ -e /dev/nand0 ]; then
+	addpart /dev/nand0 $nand_parts
+
+	# Uh, oh, hush first expands wildcards and then starts executing
+	# commands. What a bug!
+	source /env/bin/hush_hack
+fi
+
+if [ -f /env/bin/init_board ]; then
+	/env/bin/init_board
+fi
+
+echo
+echo -n "Hit any key to stop autoboot: "
+timeout -a $autoboot_timeout
+if [ $? != 0 ]; then
+	echo
+	echo "type update_kernel nand|nor [<imagename>] to update kernel into flash"
+	echo "type update_rootfs nand|nor [<imagename>] to update rootfs into flash"
+	echo
+	exit
+fi
+
+boot
diff --git a/defaultenv/bin/update_kernel b/defaultenv/bin/update_kernel
new file mode 100644
index 0000000..1d35ed9
--- /dev/null
+++ b/defaultenv/bin/update_kernel
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+. /env/config
+image=$kernelimage
+
+if [ x$1 = xnand ]; then
+	part=/dev/nand0.kernel.bb
+elif [ x$1 = xnor ]; then
+	part=/dev/nor0.kernel
+else
+	echo "usage: $0 nor|nand [imagename]"
+	exit 1
+fi
+
+. /env/bin/_update $2
diff --git a/defaultenv/bin/update_rootfs b/defaultenv/bin/update_rootfs
new file mode 100644
index 0000000..6366315
--- /dev/null
+++ b/defaultenv/bin/update_rootfs
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+. /env/config
+
+image=$rootfsimage
+
+if [ x$1 = xnand ]; then
+	part=/dev/nand0.root.bb
+elif [ x$1 = xnor ]; then
+	part=/dev/nor0.root
+else
+	echo "usage: $0 nor|nand [imagename]"
+	exit 1
+fi
+
+. /env/bin/_update $2
-- 
1.7.1

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From andy.pont at sdcsystems.com  Thu Jun 17 09:26:58 2010
From: andy.pont at sdcsystems.com (Andy Pont)
Date: Thu, 17 Jun 2010 14:26:58 +0100
Subject: [PATCH 04/11] include support for a simple pseudo number generator
In-Reply-To: <20100617131724.GN20799@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>	<1276508921-3264-5-git-send-email-s.hauer@pengutronix.de>
	<20100617131724.GN20799@pengutronix.de>
Message-ID: <00e901cb0e20$c3d5eb70$4b81c250$@pont@sdcsystems.com>

Sascha Hauer wrote...

> +#define RAND_MAX 32767
> +
> +/* return a pseudo-random integer in the range [0, RAND_MAX] */
> +unsigned int rand(void);

*Snip*

> +unsigned int rand(void)
> +{
> +	random_seed = random_seed * 1103515245 + 12345;
> +	return (random_seed / 65536) % 32768;
> +}

The return value on this function seems wrong as it will always return a
value between 0 and 32767 irrespective of what RAND_MAX is set to which
doesn't agree with the comment on the function prototype.

Although it may just be me being dim as my hayfever is driving me mad today
:-)

A.




From jacmet at sunsite.dk  Thu Jun 17 10:14:49 2010
From: jacmet at sunsite.dk (Peter Korsgaard)
Date: Thu, 17 Jun 2010 16:14:49 +0200
Subject: [PATCH 04/11] include support for a simple pseudo number generator
In-Reply-To: <20100617131724.GN20799@pengutronix.de> (Sascha Hauer's message
	of "Thu, 17 Jun 2010 15:17:24 +0200")
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
	<1276508921-3264-5-git-send-email-s.hauer@pengutronix.de>
	<20100617131724.GN20799@pengutronix.de>
Message-ID: <87vd9hbvae.fsf@macbook.be.48ers.dk>

>>>>> "Sascha" == Sascha Hauer <s.hauer at pengutronix.de> writes:

 Sascha> Here is an updated version. I have put get_random_bytes() into
 Sascha> stdlib.h aswell, though of course this is no stdlib function.

 Sascha> Sascha

Looks good to me, thanks

Acked-by: Peter Korsgaard <jacmet at sunsite.dk>

-- 
Bye, Peter Korsgaard


From s.hauer at pengutronix.de  Fri Jun 18 02:28:26 2010
From: s.hauer at pengutronix.de ('Sascha Hauer')
Date: Fri, 18 Jun 2010 08:28:26 +0200
Subject: [PATCH 04/11] include support for a simple pseudo number generator
Message-ID: <20100618062826.GP20799@pengutronix.de>

On Thu, Jun 17, 2010 at 02:26:58PM +0100, Andy Pont wrote:
> Sascha Hauer wrote...
> 
> > +#define RAND_MAX 32767
> > +
> > +/* return a pseudo-random integer in the range [0, RAND_MAX] */
> > +unsigned int rand(void);
> 
> *Snip*
> 
> > +unsigned int rand(void)
> > +{
> > +	random_seed = random_seed * 1103515245 + 12345;
> > +	return (random_seed / 65536) % 32768;
> > +}
> 
> The return value on this function seems wrong as it will always return a
> value between 0 and 32767 irrespective of what RAND_MAX is set to which
> doesn't agree with the comment on the function prototype.

Well the way the rand function is implemented it is not suitable for
RAND_MAX > 32767. Ok, changed it for the attached patch.

I originally thought there would be discussion about the pros and cons
of random ethernet addresses, but about not this patch ;)

Sascha

commit dcd5248b7dceb918c5c5d9b045893421ddc6c112
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Fri Jun 11 14:10:36 2010 +0200

    include support for a simple pseudo number generator
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

diff --git a/include/net.h b/include/net.h
index 8db83d8..709e76c 100644
--- a/include/net.h
+++ b/include/net.h
@@ -16,6 +16,7 @@
 #include <linux/types.h>
 #include <param.h>
 #include <malloc.h>
+#include <stdlib.h>
 #include <asm/byteorder.h>	/* for nton* / ntoh* stuff */
 
 
diff --git a/include/stdlib.h b/include/stdlib.h
new file mode 100644
index 0000000..dc72013
--- /dev/null
+++ b/include/stdlib.h
@@ -0,0 +1,16 @@
+#ifndef __STDLIB_H
+#define __STDLIB_H
+
+#define RAND_MAX 32767
+
+/* return a pseudo-random integer in the range [0, RAND_MAX] */
+unsigned int rand(void);
+
+/* set the seed for rand () */
+void srand(unsigned int seed);
+
+/* fill a buffer with pseudo-random data */
+void get_random_bytes(char *buf, int len);
+
+
+#endif /* __STDLIB_H */
diff --git a/lib/Makefile b/lib/Makefile
index b072fb6..4a33aaa 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
 obj-y			+= glob.o
 obj-y			+= notifier.o
 obj-y			+= copy_file.o
+obj-y			+= random.o
 obj-y			+= lzo/
 obj-$(CONFIG_LZO_DECOMPRESS)		+= decompress_unlzo.o
 obj-$(CONFIG_PROCESS_ESCAPE_SEQUENCE)	+= process_escape_sequence.o
diff --git a/lib/random.c b/lib/random.c
new file mode 100644
index 0000000..352d6bf
--- /dev/null
+++ b/lib/random.c
@@ -0,0 +1,26 @@
+#include <common.h>
+#include <stdlib.h>
+
+static unsigned int random_seed;
+
+#if RAND_MAX > 32767
+#error this rand implementation is for RAND_MAX < 32678 only.
+#endif
+
+unsigned int rand(void)
+{
+	random_seed = random_seed * 1103515245 + 12345;
+	return (random_seed / 65536) % (RAND_MAX + 1);
+}
+
+void srand(unsigned int seed)
+{
+	random_seed = seed;
+}
+
+void get_random_bytes(char *buf, int len)
+{
+	while (len--)
+		*buf++ = rand() % 256;
+}
+
-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From T.Gamez at phytec.de  Fri Jun 18 07:41:42 2010
From: T.Gamez at phytec.de (Teresa Gamez)
Date: Fri, 18 Jun 2010 13:41:42 +0200
Subject: [PATCH] mx2 GPIO OCRx register
In-Reply-To: <20100610115454.GN20799@pengutronix.de>
References: <1275991382.18173.37.camel@lws-gamez>
	<20100610115454.GN20799@pengutronix.de>
Message-ID: <1276861302.27924.13.camel@lws-gamez>

Hello Sascha,

is it reasonable to create a gpio_mode commad then? Or is there an other
way to do this in the barebox shell?

Teresa

Am Donnerstag, den 10.06.2010, 13:54 +0200 schrieb Sascha Hauer:
> Hi Teresa,
> 
> On Tue, Jun 08, 2010 at 12:03:02PM +0200, Teresa Gamez wrote:
> > The GPIO OCRx register has to be set correct or the output is not set as expected.
> 
> No. The gpio functions are not expected to change the iomuxer. This is
> what imx_gpio_mode() is for.
> 
> Sascha




From s.hauer at pengutronix.de  Fri Jun 18 08:48:34 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 18 Jun 2010 14:48:34 +0200
Subject: [PATCH] mx2 GPIO OCRx register
In-Reply-To: <1276861302.27924.13.camel@lws-gamez>
References: <1275991382.18173.37.camel@lws-gamez>
	<20100610115454.GN20799@pengutronix.de>
	<1276861302.27924.13.camel@lws-gamez>
Message-ID: <20100618124834.GA15561@pengutronix.de>

Hello Teresa,

On Fri, Jun 18, 2010 at 01:41:42PM +0200, Teresa Gamez wrote:
> Hello Sascha,
> 
> is it reasonable to create a gpio_mode commad then? Or is there an other
> way to do this in the barebox shell?

A gpio_mode command should be fine. Maybe something like
'mux_mode <pin_no> <mode>'. We could then put a list of variables
into the environment:

PC5_PF_I2C2_SDA="69 0"
Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From u.kleine-koenig at pengutronix.de  Sat Jun 19 16:14:51 2010
From: u.kleine-koenig at pengutronix.de (Uwe =?iso-8859-1?Q?Kleine-K=F6nig?=)
Date: Sat, 19 Jun 2010 22:14:51 +0200
Subject: [PATCH 07/11] add a generic default environment
In-Reply-To: <20100617132059.GO20799@pengutronix.de>
References: <1276508921-3264-1-git-send-email-s.hauer@pengutronix.de>
	<1276508921-3264-8-git-send-email-s.hauer@pengutronix.de>
	<20100617132059.GO20799@pengutronix.de>
Message-ID: <20100619201451.GA29054@pengutronix.de>

Hello Sascha,

On Thu, Jun 17, 2010 at 03:20:59PM +0200, Sascha Hauer wrote:
> diff --git a/defaultenv/bin/boot b/defaultenv/bin/boot
> new file mode 100644
> index 0000000..6a508fb
> --- /dev/null
> +++ b/defaultenv/bin/boot
> @@ -0,0 +1,109 @@
> +#!/bin/sh
> +
> +. /env/config
> +
> +if [ x$1 = xnand ]; then
> +	rootfs_loc=nand
> +	kernel_loc=nand
> +elif [ x$1 = xnor ]; then
> +	rootfs_loc=nor
> +	kernel_loc=nor
> +elif [ x$1 = xnet ]; then
> +	rootfs_loc=net
> +	kernel_loc=net
> +fi
I'm not sure if barebox supports the case statement.  Even if not you
can simplify that to

	if [ "x$1" = "xnand" ] || [ "x$1" = "xnor" ] || [ "x$1" = "xnet" ]; then
		rootfs_loc="$1";
		kernel_loc="$1";
	fi

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |


From jlz.3008 at gmail.com  Mon Jun 21 00:25:58 2010
From: jlz.3008 at gmail.com (Jose Luis Zabalza)
Date: Mon, 21 Jun 2010 06:25:58 +0200
Subject: Fat32 support
Message-ID: <AANLkTikVJUYKIck4wWFb125HMGJB19Bva0ZBHwit_-F6@mail.gmail.com>

Hello all

-- 
Jos? Luis Zabalza
jlz.3008  a t  gmail.com
Linux Counter 172551


From jlz.3008 at gmail.com  Mon Jun 21 00:34:31 2010
From: jlz.3008 at gmail.com (Jose Luis Zabalza)
Date: Mon, 21 Jun 2010 06:34:31 +0200
Subject: Fat32 support
Message-ID: <AANLkTilzfYtRwI1kdFG0O53fRz9NApQnW0P98dZEK-Yo@mail.gmail.com>

Hello All.

A simple question. Is it posible read a file on fat32 USB memory
device from barebox?

If not, is it posible write some code to do this? What steps will be necessary?
- port from linux kernel usb-storage support.?
- port form linux kernel fat 32 support?

My final objetive is firmwarize the board from a USB fat32 USB memory
device with a new barebox "firmwarize" command because I am surprised
that there is not on barebox?

Thanks in avance


-- 
Jos? Luis Zabalza
jlz.3008  a t  gmail.com
Linux Counter 172551


From s.hauer at pengutronix.de  Mon Jun 21 02:32:47 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 21 Jun 2010 08:32:47 +0200
Subject: Fat32 support
In-Reply-To: <AANLkTilzfYtRwI1kdFG0O53fRz9NApQnW0P98dZEK-Yo@mail.gmail.com>
References: <AANLkTilzfYtRwI1kdFG0O53fRz9NApQnW0P98dZEK-Yo@mail.gmail.com>
Message-ID: <20100621063247.GB12115@pengutronix.de>

Hello Jos?,

On Mon, Jun 21, 2010 at 06:34:31AM +0200, Jose Luis Zabalza wrote:
> Hello All.
> 
> A simple question. Is it posible read a file on fat32 USB memory
> device from barebox?

No, currently not.

> 
> If not, is it posible write some code to do this? What steps will be necessary?
> - port from linux kernel usb-storage support.?
> - port form linux kernel fat 32 support?

This is surely possible, though you might be better off with the U-Boot
code as a template for porting. You'll probably also need dos
partitioning support.

> 
> My final objetive is firmwarize the board from a USB fat32 USB memory
> device with a new barebox "firmwarize" command because I am surprised
> that there is not on barebox?

I think you don't need an extra command to do this once all necessary
code is in place. It's more a matter of a script like 'usb; mount -tfat
/dev/xxx /mnt; cp /mnt/xy /dev/nor0.kernel;'
We don't have this at the moment because nobody needed it yet. We mostly
use networking or dfu (device firmware update) for updating purposes.
That said patches are very welcome ;)

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From jlz.3008 at gmail.com  Mon Jun 21 02:43:15 2010
From: jlz.3008 at gmail.com (Jose Luis Zabalza)
Date: Mon, 21 Jun 2010 08:43:15 +0200
Subject: Fat32 support
In-Reply-To: <20100621063247.GB12115@pengutronix.de>
References: <AANLkTilzfYtRwI1kdFG0O53fRz9NApQnW0P98dZEK-Yo@mail.gmail.com>
	<20100621063247.GB12115@pengutronix.de>
Message-ID: <AANLkTimItYRXe7D_cBHDCmyVwFQsg7FEoEnsZK_D3N9A@mail.gmail.com>

2010/6/21 Sascha Hauer <s.hauer at pengutronix.de>
>
> Hello Jos?,
>
> On Mon, Jun 21, 2010 at 06:34:31AM +0200, Jose Luis Zabalza wrote:
> > Hello All.
> >
> > A simple question. Is it posible read a file on fat32 USB memory
> > device from barebox?
>
> No, currently not.
>
> >
> > If not, is it posible write some code to do this? What steps will be necessary?
> > - port from linux kernel usb-storage support.?
> > - port form linux kernel fat 32 support?
>
> This is surely possible, though you might be better off with the U-Boot
> code as a template for porting. You'll probably also need dos
> partitioning support.
>
> >
> > My final objetive is firmwarize the board from a USB fat32 USB memory
> > device with a new barebox "firmwarize" command because I am surprised
> > that there is not on barebox?
>
> I think you don't need an extra command to do this once all necessary
> code is in place. It's more a matter of a script like 'usb; mount -tfat
> /dev/xxx /mnt; cp /mnt/xy /dev/nor0.kernel;'
> We don't have this at the moment because nobody needed it yet. We mostly
> use networking or dfu (device firmware update) for updating purposes.
> That said patches are very welcome ;)
>
> Sascha
>

Thanks Sascha. But cp command didn't run on NOR flash . unprotect and
erase run ok so I thought cp command is not a good command to write on
NOR flash. I must revise NOR device code when I have time.


Thanks again.




--
Jos? Luis Zabalza
jlz.3008 ?a t ?gmail.com
Linux Counter 172551


From s.hauer at pengutronix.de  Mon Jun 21 02:56:57 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 21 Jun 2010 08:56:57 +0200
Subject: Fat32 support
In-Reply-To: <AANLkTimItYRXe7D_cBHDCmyVwFQsg7FEoEnsZK_D3N9A@mail.gmail.com>
References: <AANLkTilzfYtRwI1kdFG0O53fRz9NApQnW0P98dZEK-Yo@mail.gmail.com>
	<20100621063247.GB12115@pengutronix.de>
	<AANLkTimItYRXe7D_cBHDCmyVwFQsg7FEoEnsZK_D3N9A@mail.gmail.com>
Message-ID: <20100621065657.GE12115@pengutronix.de>

On Mon, Jun 21, 2010 at 08:43:15AM +0200, Jose Luis Zabalza wrote:
> 
> Thanks Sascha. But cp command didn't run on NOR flash . unprotect and
> erase run ok so I thought cp command is not a good command to write on
> NOR flash. I must revise NOR device code when I have time.

It's supposed to run, otherwise it's a bug.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From mailinglists at erwinrol.com  Mon Jun 21 04:32:05 2010
From: mailinglists at erwinrol.com (Erwin Rol)
Date: Mon, 21 Jun 2010 10:32:05 +0200
Subject: Fat32 support
In-Reply-To: <20100621063247.GB12115@pengutronix.de>
References: <AANLkTilzfYtRwI1kdFG0O53fRz9NApQnW0P98dZEK-Yo@mail.gmail.com>
	<20100621063247.GB12115@pengutronix.de>
Message-ID: <4C1F2385.20807@erwinrol.com>

Sascha Hauer wrote:

> This is surely possible, though you might be better off with the U-Boot
> code as a template for porting. You'll probably also need dos
> partitioning support.

That is (atleast in part, no extended partitions) already there. The x86 
target has DOS partition support. And i have EFI GUID partition support 
here, that should be merged as soon as i have time to clean it up.


Both things probably should than be moved out of the x86 target and 
moved to a more generic place.


- Erwin



From luca at lucaceresoli.net  Tue Jun 22 08:26:11 2010
From: luca at lucaceresoli.net (Luca Ceresoli)
Date: Tue, 22 Jun 2010 14:26:11 +0200
Subject: Regression: not booting anymore on OMAP35xx
Message-ID: <L4F17N$3581604971B72AFF2E4EE2E9FBF2CD32@aruba.it>

Hi,

recent versions of barebox do not boot anymore on OMAP3530 (Cortex-A8).

I build barebox with omap3530_beagle_per_uart_defconfig, and load it
using pserial from Nishanth Menon's omap-u-boot-utils
(http://github.com/nmenon/omap-u-boot-utils).

Symptoms:
pserial detects the OMAP ID, then starts sending via UART.
The transfer apparently gets completed (obvious as there is no control),
but after that the UART line to the target is totally mute.

This happens since commit:
 78104ae arm: reimplement startup code in C

And is still happening on current master:
 ea5230c i2c: fix adapter_list manipulation

This issue seems independent on another one recently discussed in ml
('OMAP 3530 arch_shutdown "undefined instruction"',
http://lists.infradead.org/pipermail/barebox/2010-May/000919.html),
for which a patch has recently been committed in:
 ce971c2 arm: use processor specififc functions to turn off MMU

Thanks,
Luca




From s.hauer at pengutronix.de  Tue Jun 22 09:11:32 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 22 Jun 2010 15:11:32 +0200
Subject: Regression: not booting anymore on OMAP35xx
In-Reply-To: <L4F17N$3581604971B72AFF2E4EE2E9FBF2CD32@aruba.it>
References: <L4F17N$3581604971B72AFF2E4EE2E9FBF2CD32@aruba.it>
Message-ID: <20100622131132.GK12115@pengutronix.de>

Hi Luca,

On Tue, Jun 22, 2010 at 02:26:11PM +0200, Luca Ceresoli wrote:
> Hi,
> 
> recent versions of barebox do not boot anymore on OMAP3530 (Cortex-A8).
> 
> I build barebox with omap3530_beagle_per_uart_defconfig, and load it
> using pserial from Nishanth Menon's omap-u-boot-utils
> (http://github.com/nmenon/omap-u-boot-utils).
> 
> Symptoms:
> pserial detects the OMAP ID, then starts sending via UART.
> The transfer apparently gets completed (obvious as there is no control),
> but after that the UART line to the target is totally mute.
> 
> This happens since commit:
>  78104ae arm: reimplement startup code in C
> 
> And is still happening on current master:
>  ea5230c i2c: fix adapter_list manipulation

Seems that I lost the call to arch_init_lowlevel. Does the following
patch help?


diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index eea7dcf..91d2ccd 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -50,6 +50,8 @@ void __naked __bare_init reset(void)
 {
 	uint32_t r;
 
+	arch_init_lowlevel();
+
 	/* set the cpu to SVC32 mode */
 	__asm__ __volatile__("mrs %0, cpsr":"=r"(r));
 	r &= ~0x1f;
diff --git a/arch/arm/mach-omap/omap3_core.S b/arch/arm/mach-omap/omap3_core.S
index 7337d4c..d904231 100644
--- a/arch/arm/mach-omap/omap3_core.S
+++ b/arch/arm/mach-omap/omap3_core.S
@@ -92,7 +92,7 @@ next:
 arch_start:
 	.word	arch_init_lowlevel
 barebox_start:
-	.word	_start
+	.word	exception_vectors
 SRAM_INTVECT:
 	.word	OMAP_SRAM_INTVECT

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From eric at eukrea.com  Tue Jun 22 11:59:44 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Tue, 22 Jun 2010 17:59:44 +0200
Subject: [PATCH] eukrea_cpuimx25: fix env partition size
Message-ID: <1277222384-4321-1-git-send-email-eric@eukrea.com>

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 board/eukrea_cpuimx25/eukrea_cpuimx25.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/board/eukrea_cpuimx25/eukrea_cpuimx25.c b/board/eukrea_cpuimx25/eukrea_cpuimx25.c
index b19efcc..caeb46e 100644
--- a/board/eukrea_cpuimx25/eukrea_cpuimx25.c
+++ b/board/eukrea_cpuimx25/eukrea_cpuimx25.c
@@ -221,7 +221,7 @@ static int eukrea_cpuimx25_devices_init(void)
 		PARTITION_FIXED, "self_raw");
 	dev_add_bb_dev("self_raw", "self0");
 
-	devfs_add_partition("nand0", 0x40000, 0x40000,
+	devfs_add_partition("nand0", 0x40000, 0x20000,
 		PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
 
-- 
1.6.3.3



From luca at lucaceresoli.net  Tue Jun 22 10:04:52 2010
From: luca at lucaceresoli.net (Luca Ceresoli)
Date: Tue, 22 Jun 2010 16:04:52 +0200
Subject: Regression: not booting anymore on OMAP35xx
Message-ID: <L4F5S4$2423D397FA7BDC615C5A7C3556F0B4F1@aruba.it>

Sascha Hauer wrote:
> Hi Luca,
> 
> On Tue, Jun 22, 2010 at 02:26:11PM +0200, Luca Ceresoli wrote:
> > Hi,
> > 
> > recent versions of barebox do not boot anymore on OMAP3530 (Cortex-A8).
> > 
> > I build barebox with omap3530_beagle_per_uart_defconfig, and load it
> > using pserial from Nishanth Menon's omap-u-boot-utils
> > (http://github.com/nmenon/omap-u-boot-utils).
> > 
> > Symptoms:
> > pserial detects the OMAP ID, then starts sending via UART.
> > The transfer apparently gets completed (obvious as there is no control),
> > but after that the UART line to the target is totally mute.
> > 
> > This happens since commit:
> >  78104ae arm: reimplement startup code in C
> > 
> > And is still happening on current master:
> >  ea5230c i2c: fix adapter_list manipulation
> 
> Seems that I lost the call to arch_init_lowlevel. Does the following
> patch help?

I'm afraid it doesn't seem to.
It fails with the same symptoms.

Luca

> 
> 
> diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
> index eea7dcf..91d2ccd 100644
> --- a/arch/arm/cpu/start.c
> +++ b/arch/arm/cpu/start.c
> @@ -50,6 +50,8 @@ void __naked __bare_init reset(void)
>  {
>  	uint32_t r;
>  
> +	arch_init_lowlevel();
> +
>  	/* set the cpu to SVC32 mode */
>  	__asm__ __volatile__("mrs %0, cpsr":"=r"(r));
>  	r &= ~0x1f;
> diff --git a/arch/arm/mach-omap/omap3_core.S b/arch/arm/mach-omap/omap3_core.S
> index 7337d4c..d904231 100644
> --- a/arch/arm/mach-omap/omap3_core.S
> +++ b/arch/arm/mach-omap/omap3_core.S
> @@ -92,7 +92,7 @@ next:
>  arch_start:
>  	.word	arch_init_lowlevel
>  barebox_start:
> -	.word	_start
> +	.word	exception_vectors
>  SRAM_INTVECT:
>  	.word	OMAP_SRAM_INTVECT
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 



From s.hauer at pengutronix.de  Wed Jun 23 02:42:57 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 23 Jun 2010 08:42:57 +0200
Subject: Regression: not booting anymore on OMAP35xx
In-Reply-To: <L4F5S4$2423D397FA7BDC615C5A7C3556F0B4F1@aruba.it>
References: <L4F5S4$2423D397FA7BDC615C5A7C3556F0B4F1@aruba.it>
Message-ID: <20100623064257.GM12115@pengutronix.de>

On Tue, Jun 22, 2010 at 04:04:52PM +0200, Luca Ceresoli wrote:
> Sascha Hauer wrote:
> > Hi Luca,
> > 
> > On Tue, Jun 22, 2010 at 02:26:11PM +0200, Luca Ceresoli wrote:
> > > Hi,
> > > 
> > 
> > Seems that I lost the call to arch_init_lowlevel. Does the following
> > patch help?
> 
> I'm afraid it doesn't seem to.
> It fails with the same symptoms.
> 
> Luca
> 
> > 
> > 
> > diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
> > index eea7dcf..91d2ccd 100644
> > --- a/arch/arm/cpu/start.c
> > +++ b/arch/arm/cpu/start.c
> > @@ -50,6 +50,8 @@ void __naked __bare_init reset(void)
> >  {
> >  	uint32_t r;
> >  
> > +	arch_init_lowlevel();
> > +

Ok, this has to be done *after* switching the cpu to SVC32 mode.

I tested this on my beagle board and now it works again. I pushed
a patch to the master repository.

Sorry for the inconvenience and thanks for reporting.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From jlz.3008 at gmail.com  Wed Jun 23 04:39:35 2010
From: jlz.3008 at gmail.com (Jose Luis Zabalza)
Date: Wed, 23 Jun 2010 10:39:35 +0200
Subject: USB device not found
Message-ID: <AANLkTikXVF6EEgpWHoiVcBpdn17Kld8b7WMN7laRqcMC@mail.gmail.com>

Hello all.

I connect a usb device to my board but I can't see the device on /dev.
Is it usual?
I should see a /dev/usb0-20 device file?




jlxx:/ usb
USB: scanning bus for devices...
...
usb0-2: 1516:8628 FlashDisk
usb0-1: 0000:0000 EHCI Host Controller
2 USB Device(s) found

jlxx:/ devinfo
devices:
|----imx_serial0
|----cs0
|----ramfs0
|----devfs0
|----mem0 (defaultenv)
|----mem1 (mem)
|----cfi_flash0 (nor0, self, env, nor0.uboot, nor0.kernel, nor0.root)
|----mem2 (ram0)
|----fec_imx0
|----miiphy0 (phy0)
|----eth0
|----imxfb0
|----fb0 (fb0)
|----ehci0
|----usb0-20
|----usb0-10

drivers:
imx_serial
     ramfs
     devfs
   fec_imx
    miiphy
 cfi_flash
      ehci
     imxfb
       mem


jlxx:/ ls /dev
zero           defaultenv     mem            nor0           ram0
phy0           fb0            self           env            nor0.uboot
nor0.kernel    nor0.root


Thanks in avance




-- 
Jos? Luis Zabalza
jlz.3008  a t  gmail.com
Linux Counter 172551


From s.hauer at pengutronix.de  Thu Jun 24 03:00:11 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 09:00:11 +0200
Subject: USB device not found
In-Reply-To: <AANLkTikXVF6EEgpWHoiVcBpdn17Kld8b7WMN7laRqcMC@mail.gmail.com>
References: <AANLkTikXVF6EEgpWHoiVcBpdn17Kld8b7WMN7laRqcMC@mail.gmail.com>
Message-ID: <20100624070011.GP12115@pengutronix.de>

On Wed, Jun 23, 2010 at 10:39:35AM +0200, Jose Luis Zabalza wrote:
> Hello all.
> 
> I connect a usb device to my board but I can't see the device on /dev.
> Is it usual?
> I should see a /dev/usb0-20 device file?
> 
> jlxx:/ usb
> USB: scanning bus for devices...
> ...
> usb0-2: 1516:8628 FlashDisk
> usb0-1: 0000:0000 EHCI Host Controller
> 2 USB Device(s) found
> 
> jlxx:/ devinfo
> devices:
> |----imx_serial0
> |----cs0
> |----ramfs0
> |----devfs0
> |----mem0 (defaultenv)
> |----mem1 (mem)
> |----cfi_flash0 (nor0, self, env, nor0.uboot, nor0.kernel, nor0.root)
> |----mem2 (ram0)
> |----fec_imx0
> |----miiphy0 (phy0)
> |----eth0
> |----imxfb0
> |----fb0 (fb0)
> |----ehci0
> |----usb0-20
> |----usb0-10

The devinfo command should be worked on. Traditionally each device
automatically had a file under /dev, but this behaviour was not really
nice because several devices do not need a file. I changed this
so that files under /dev have to be explicitely registered. What you
see with the devinfo command are the devices registered in the system
and in brackets the /dev files registered from these devices. so for
example the device 'miiphy0' has registered a file /dev/phy0.

usb0-2 is a device registered for housekeeping only with no files at
all, that's normal.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From baruch at tkos.co.il  Thu Jun 24 05:04:59 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Thu, 24 Jun 2010 12:04:59 +0300
Subject: [PATCH] envfs: fix build warning
Message-ID: <60663606c7efe2aaede86326339cb620c0a6bf8a.1277370124.git.baruch@tkos.co.il>

__LITTLE_ENDIAN or __BIG_ENDIAN are not always defined. E.g. the CodeSourcery
G++ Lite 2010q1 for ARM (4.4.1) does not define __BIG_ENDIAN. This causes a
compile time warning.

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 include/envfs.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/envfs.h b/include/envfs.h
index b5849d9..0dd4e6a 100644
--- a/include/envfs.h
+++ b/include/envfs.h
@@ -36,7 +36,7 @@ struct envfs_super {
 #error "No byte order defined in __BYTE_ORDER"
 #endif
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN
 #define ENVFS_16(x)	(x)
 #define ENVFS_24(x)	(x)
 #define ENVFS_32(x)	(x)
@@ -44,7 +44,7 @@ struct envfs_super {
 #define ENVFS_GET_OFFSET(x)	((x)->offset)
 #define ENVFS_SET_OFFSET(x,y)	((x)->offset = (y))
 #define ENVFS_SET_NAMELEN(x,y) ((x)->namelen = (y))
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN
 #ifdef __KERNEL__
 #define ENVFS_16(x)	swab16(x)
 #define ENVFS_24(x)	((swab32(x)) >> 8)
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:35:01 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:35:01 +0200
Subject: [PATCH 1/8] tftp: remove unused variables
In-Reply-To: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372108-30332-2-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/tftp.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 38d16bc..338359b 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -35,8 +35,6 @@
 static int		tftp_server_port;	/* The UDP port at their end		*/
 static unsigned int	tftp_block;		/* packet sequence number		*/
 static unsigned int	tftp_last_block;	/* last packet sequence number received */
-static unsigned int	tftp_block_wrap;	/* count of sequence number wraparounds */
-static unsigned int	tftp_block_wrap_offset;	/* memory offset due to wrapping	*/
 static int		tftp_state;
 static uint64_t		tftp_timer_start;
 static int		tftp_err;
@@ -135,10 +133,7 @@ static void tftp_handler(char *packet, unsigned len)
 		 * number of 0 this means that there was a wrap
 		 * around of the (16 bit) counter.
 		 */
-		if (tftp_block == 0) {
-			tftp_block_wrap++;
-			tftp_block_wrap_offset += TFTP_BLOCK_SIZE * TFTP_SEQUENCE_SIZE;
-		} else {
+		if (tftp_block) {
 			if (((tftp_block - 1) % 10) == 0) {
 				putchar('#');
 			} else if ((tftp_block % (10 * HASHES_PER_LINE)) == 0) {
@@ -155,8 +150,6 @@ static void tftp_handler(char *packet, unsigned len)
 			tftp_con->udp->uh_dport = udp->uh_sport;
 			tftp_server_port = ntohs(udp->uh_sport);
 			tftp_last_block = 0;
-			tftp_block_wrap = 0;
-			tftp_block_wrap_offset = 0;
 
 			if (tftp_block != 1) {	/* Assertion */
 				printf("error: First block is not block 1 (%ld)\n",
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:35:07 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:35:07 +0200
Subject: [PATCH 7/8] nfs: resend requests after timeout
In-Reply-To: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372108-30332-8-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/nfs.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/net/nfs.c b/net/nfs.c
index bdf05bd..4ca1d6e 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -124,7 +124,7 @@ struct rpc_t {
 	} u;
 };
 
-#define NFS_TIMEOUT 60
+#define NFS_TIMEOUT 1
 
 static unsigned long rpc_id = 0;
 static int nfs_offset = -1;
@@ -399,6 +399,8 @@ static void nfs_send(void)
 		nfs_readlink_req();
 		break;
 	}
+
+	nfs_timer_start = get_time_ns();
 }
 
 static int rpc_check_reply(unsigned char *pkt, int isnfs)
@@ -661,8 +663,6 @@ static void nfs_start(char *p)
 
 	printf("\nFilename '%s/%s'.\n", nfs_path, nfs_filename);
 
-	nfs_timer_start = get_time_ns();
-
 	nfs_state = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
 
 	nfs_send();
@@ -706,8 +706,10 @@ static int do_nfs(struct command *cmdtp, int argc, char *argv[])
 			break;
 		}
 		net_poll();
-		if (is_timeout(nfs_timer_start, NFS_TIMEOUT * SECOND))
-			break;
+		if (is_timeout(nfs_timer_start, NFS_TIMEOUT * SECOND)) {
+			show_progress(-1);
+			nfs_send();
+		}
 	}
 
 	net_unregister(nfs_con);
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:35:03 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:35:03 +0200
Subject: [PATCH 3/8] cfi flash driver: Use generic progression bar function
In-Reply-To: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372108-30332-4-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/nor/cfi_flash.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index dbfb004..b21739b 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -42,6 +42,7 @@
 #include <malloc.h>
 #include <asm/io.h>
 #include <errno.h>
+#include <progress.h>
 #include "cfi_flash.h"
 
 /*
@@ -499,11 +500,13 @@ static int cfi_erase(struct cdev *cdev, size_t count, unsigned long offset)
         start = find_sector(finfo, cdev->dev->map_base + offset);
         end   = find_sector(finfo, cdev->dev->map_base + offset + count - 1);
 
+	init_progression_bar(end - start);
+
         for (i = start; i <= end; i++) {
                 ret = finfo->cfi_cmd_set->flash_erase_one(finfo, i);
                 if (ret)
                         goto out;
-		printf(".");
+		show_progress(i - start);
         }
 out:
         putchar('\n');
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:35:04 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:35:04 +0200
Subject: [PATCH 4/8] tftp: use generic progression bar
In-Reply-To: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372108-30332-5-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/tftp.c |   34 +++++++++++++---------------------
 1 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 338359b..4b60cc8 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -13,13 +13,11 @@
 #include <errno.h>
 #include <libgen.h>
 #include <fcntl.h>
+#include <progress.h>
 #include <linux/err.h>
 
 #define TFTP_PORT	69		/* Well known TFTP port #		*/
 #define TIMEOUT		5		/* Seconds to timeout for a lost pkt	*/
-# define TIMEOUT_COUNT	10		/* # of timeouts before giving up  */
-					/* (for checking the image size)	*/
-#define HASHES_PER_LINE	65		/* Number of "loading" hashes per line	*/
 
 /*
  *	TFTP operations.
@@ -50,6 +48,7 @@ static int		tftp_err;
 static char *tftp_filename;
 static struct net_connection *tftp_con;
 static int net_store_fd;
+static int tftp_size;
 
 static int tftp_send(void)
 {
@@ -84,6 +83,8 @@ static int tftp_send(void)
 		break;
 	}
 
+	tftp_timer_start = get_time_ns();
+	show_progress(tftp_size);
 	ret = net_udp_send(tftp_con, len);
 
 	return ret;
@@ -127,20 +128,6 @@ static void tftp_handler(char *packet, unsigned len)
 		len -= 2;
 		tftp_block = ntohs(*(uint16_t *)pkt);
 
-		/*
-		 * RFC1350 specifies that the first data packet will
-		 * have sequence number 1. If we receive a sequence
-		 * number of 0 this means that there was a wrap
-		 * around of the (16 bit) counter.
-		 */
-		if (tftp_block) {
-			if (((tftp_block - 1) % 10) == 0) {
-				putchar('#');
-			} else if ((tftp_block % (10 * HASHES_PER_LINE)) == 0) {
-				puts("\n\t ");
-			}
-		}
-
 		if (tftp_state == STATE_RRQ)
 			debug("Server did not acknowledge timeout option!\n");
 
@@ -165,7 +152,9 @@ static void tftp_handler(char *packet, unsigned len)
 			break;
 
 		tftp_last_block = tftp_block;
-		tftp_timer_start = get_time_ns();
+
+		if (!(tftp_block % 10))
+			tftp_size++;
 
 		ret = write(net_store_fd, pkt + 2, len);
 		if (ret < 0) {
@@ -205,6 +194,8 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 	char *remotefile;
 	char ip1[16];
 
+	tftp_size = 0;
+
 	if (argc < 2)
 		return COMMAND_ERROR_USAGE;
 
@@ -229,10 +220,12 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 
 	tftp_filename = remotefile;
 
-	printf("TFTP from server %s; Filename: '%s'\nLoading: ",
+	printf("TFTP from server %s; Filename: '%s'\n",
 			ip_to_string(net_get_serverip(), ip1),
 			tftp_filename);
 
+	init_progression_bar(0);
+
 	tftp_timer_start = get_time_ns();
 	tftp_state = STATE_RRQ;
 	tftp_block = 0;
@@ -248,8 +241,7 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 		}
 		net_poll();
 		if (is_timeout(tftp_timer_start, SECOND)) {
-			tftp_timer_start = get_time_ns();
-			printf("T ");
+			show_progress(-1);
 			tftp_send();
 		}
 	}
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:35:06 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:35:06 +0200
Subject: [PATCH 6/8] nfs: Use generic progression bar
In-Reply-To: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372108-30332-7-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/nfs.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/net/nfs.c b/net/nfs.c
index 51df7a3..bdf05bd 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -32,6 +32,7 @@
 #include <libgen.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <progress.h>
 #include <linux/err.h>
 
 #define SUNRPC_PORT     111
@@ -123,7 +124,6 @@ struct rpc_t {
 	} u;
 };
 
-#define HASHES_PER_LINE 65	/* Number of "loading" hashes per line	*/
 #define NFS_TIMEOUT 60
 
 static unsigned long rpc_id = 0;
@@ -540,10 +540,10 @@ static int nfs_read_reply(unsigned char *pkt, unsigned len)
 
 	data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
 
-	if (nfs_offset && !((nfs_offset) % (NFS_READ_SIZE / 2 * 10 * HASHES_PER_LINE)))
-		puts ("\n\t ");
-	if (!(nfs_offset % ((NFS_READ_SIZE / 2) * 10)))
-		putchar ('#');
+	if (!nfs_offset) {
+		uint32_t filesize = ntohl(net_read_uint32(data + 6));
+		init_progression_bar(filesize);
+	}
 
 	rlen = ntohl(net_read_uint32(data + 18));
 
@@ -629,7 +629,7 @@ static void nfs_handler(char *packet, unsigned len)
 			nfs_state = STATE_READLINK_REQ;
 		else
 			goto err_umount;
-
+		show_progress(nfs_offset);
 		break;
 	}
 
@@ -659,7 +659,7 @@ static void nfs_start(char *p)
 	nfs_filename = basename (nfs_path);
 	nfs_path     = dirname (nfs_path);
 
-	printf("\nFilename '%s/%s'.\nLoading: ", nfs_path, nfs_filename);
+	printf("\nFilename '%s/%s'.\n", nfs_path, nfs_filename);
 
 	nfs_timer_start = get_time_ns();
 
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:35:08 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:35:08 +0200
Subject: [PATCH 8/8] tftp: update doxygen information
In-Reply-To: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372108-30332-9-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/tftp.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 000d0cf..c0d3278 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -376,16 +376,21 @@ BAREBOX_CMD_END
 /**
  * @page tftp_command tftp
  *
- * Usage is: tftp \<filename\> [\<localfilename\>]
+ * Usage:
+ *	tftp \<remotefilename\> [\<localfilename\>]
  *
- * Load a file via network using BootP/TFTP protocol. The loaded file you
- * can find after download in you current ramdisk. Refer \b ls command.
+ * or
  *
- * \<localfile> can be the local filename only, or also a device name. In the
- * case of a device name, the will gets stored there. This works also for
- * partitions of flash memory. Refer \b erase, \b unprotect for flash
- * preparation.
+ *	tftp -p \<localfilename\> [\<remotefilename\>]
  *
- * Note: This command is available only, if enabled in the menuconfig.
+ * Load a file from a tftp server or upload a file to a tftp server if
+ * the -p option is given. The second file argument can be skipped in
+ * which case the first filename is used (without the directory part).
+ *
+ * \<localfile> can be the local filename or a device file under /dev.
+ * This also works for flash memory. Refer to \b erase, \b unprotect for
+ * flash preparation.
+ *
+ * Note: This command is available only if enabled in menuconfig.
  */
 
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:35:00 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:35:00 +0200
Subject: more network patches
Message-ID: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>

Hi All,

Here are some more network related patches. I added a generic progression
bar function for use with tftp/nfs. Further more tftp gets push support.

Sascha

The following changes since commit 334fe1dc8a1b866d1f0f4ccf82ff7b06589ec022:

  pca100: use generic default env (2010-06-22 15:44:45 +0200)

are available in the git repository at:
  git://git.pengutronix.de/git/barebox.git net-pu

Sascha Hauer (8):
      tftp: remove unused variables
      add progression bar function
      cfi flash driver: Use generic progression bar function
      tftp: use generic progression bar
      tftp: Add push support
      nfs: Use generic progression bar
      nfs: resend requests after timeout
      tftp: update doxygen information

 drivers/nor/cfi_flash.c |    5 +-
 include/progress.h      |   15 +++
 lib/Makefile            |    1 +
 lib/show_progress.c     |   62 +++++++++++++
 net/Kconfig             |    4 +
 net/nfs.c               |   26 +++---
 net/tftp.c              |  231 +++++++++++++++++++++++++++++++++--------------
 7 files changed, 262 insertions(+), 82 deletions(-)
 create mode 100644 include/progress.h
 create mode 100644 lib/show_progress.c




From s.hauer at pengutronix.de  Thu Jun 24 05:35:02 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:35:02 +0200
Subject: [PATCH 2/8] add progression bar function
In-Reply-To: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372108-30332-3-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/progress.h  |   15 ++++++++++++
 lib/Makefile        |    1 +
 lib/show_progress.c |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 0 deletions(-)
 create mode 100644 include/progress.h
 create mode 100644 lib/show_progress.c

diff --git a/include/progress.h b/include/progress.h
new file mode 100644
index 0000000..5c4dd1e
--- /dev/null
+++ b/include/progress.h
@@ -0,0 +1,15 @@
+#ifndef __PROGRSS_H
+#define __PROGRSS_H
+
+/* Initialize a progress bar. If max > 0 a one line progress
+ * bar is printed where 'max' corresponds to 100%. If max == 0
+ * a multi line progress bar is printed.
+ */
+void init_progression_bar(int max);
+
+/* update a progress bar to a new value. If now < 0 then a
+ * spinner is printed.
+ */
+void show_progress(int now);
+
+#endif /*  __PROGRSS_H */
diff --git a/lib/Makefile b/lib/Makefile
index 4a33aaa..5afbf13 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -30,5 +30,6 @@ obj-y			+= notifier.o
 obj-y			+= copy_file.o
 obj-y			+= random.o
 obj-y			+= lzo/
+obj-y			+= show_progress.o
 obj-$(CONFIG_LZO_DECOMPRESS)		+= decompress_unlzo.o
 obj-$(CONFIG_PROCESS_ESCAPE_SEQUENCE)	+= process_escape_sequence.o
diff --git a/lib/show_progress.c b/lib/show_progress.c
new file mode 100644
index 0000000..333f498
--- /dev/null
+++ b/lib/show_progress.c
@@ -0,0 +1,62 @@
+/*
+ * show_progress.c - simple progress bar functions
+ *
+ * Copyright (c) 2010 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
+ *
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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 <progress.h>
+
+#define HASHES_PER_LINE	65
+
+static int printed;
+static int progress_max;
+static int spin;
+
+void show_progress(int now)
+{
+	char spinchr[] = "\\|/-";
+
+	if (now < 0) {
+		printf("%c\b", spinchr[spin++ % (sizeof(spinchr) - 1)]);
+		return;
+	}
+
+	if (progress_max)
+		now = now * HASHES_PER_LINE / progress_max;
+
+	while (printed < now) {
+		if (!(printed % HASHES_PER_LINE) && printed)
+			printf("\n\t");
+		printf("#");
+		printed++;
+	}
+}
+
+void init_progression_bar(int max)
+{
+	printed = 0;
+	progress_max = max;
+	spin = 0;
+	if (progress_max)
+		printf("\t[%65s]\r\t[", "");
+	else
+		printf("\t");
+}
+
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:35:05 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:35:05 +0200
Subject: [PATCH 5/8] tftp: Add push support
In-Reply-To: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372108-30332-6-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/Kconfig |    4 ++
 net/tftp.c  |  173 +++++++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 142 insertions(+), 35 deletions(-)

diff --git a/net/Kconfig b/net/Kconfig
index ff6e455..3169d20 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -19,6 +19,10 @@ config NET_TFTP
 	bool
 	prompt "tftp support"
 
+config NET_TFTP_PUSH
+	bool
+	prompt "tftp push support"
+
 config NET_NETCONSOLE
 	bool
 	prompt "network console support"
diff --git a/net/tftp.c b/net/tftp.c
index 4b60cc8..000d0cf 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -14,6 +14,9 @@
 #include <libgen.h>
 #include <fcntl.h>
 #include <progress.h>
+#include <getopt.h>
+#include <fs.h>
+#include <linux/stat.h>
 #include <linux/err.h>
 
 #define TFTP_PORT	69		/* Well known TFTP port #		*/
@@ -38,41 +41,89 @@ static uint64_t		tftp_timer_start;
 static int		tftp_err;
 
 #define STATE_RRQ	1
-#define STATE_DATA	2
-#define STATE_OACK	3
-#define STATE_DONE	4
+#define STATE_WRQ	2
+#define STATE_RDATA	3
+#define STATE_WDATA	4
+#define STATE_OACK	5
+#define STATE_LAST	6
+#define STATE_DONE	7
 
 #define TFTP_BLOCK_SIZE		512		    /* default TFTP block size	*/
-#define TFTP_SEQUENCE_SIZE	((unsigned long)(1<<16))    /* sequence number is 16 bit */
 
 static char *tftp_filename;
 static struct net_connection *tftp_con;
-static int net_store_fd;
+static int tftp_fd;
 static int tftp_size;
 
+#ifdef CONFIG_NET_TFTP_PUSH
+static int tftp_put;
+
+static inline void do_tftp_push(int push)
+{
+	tftp_put = push;
+}
+
+#else
+
+#define tftp_put	0
+
+static inline void do_tftp_push(int push)
+{
+}
+#endif
+
 static int tftp_send(void)
 {
-	unsigned char *pkt;
 	unsigned char *xp;
 	int len = 0;
 	uint16_t *s;
-	unsigned char *packet = net_udp_get_payload(tftp_con);
+	unsigned char *pkt = net_udp_get_payload(tftp_con);
 	int ret;
-
-	pkt = packet;
+	static int last_len;
 
 	switch (tftp_state) {
 	case STATE_RRQ:
+	case STATE_WRQ:
 		xp = pkt;
 		s = (uint16_t *)pkt;
-		*s++ = htons(TFTP_RRQ);
+		if (tftp_state == STATE_RRQ)
+			*s++ = htons(TFTP_RRQ);
+		else
+			*s++ = htons(TFTP_WRQ);
 		pkt = (unsigned char *)s;
 		pkt += sprintf((unsigned char *)pkt, "%s%coctet%ctimeout%c%d",
 				tftp_filename, 0, 0, 0, TIMEOUT) + 1;
 		len = pkt - xp;
 		break;
 
-	case STATE_DATA:
+	case STATE_WDATA:
+		if (!tftp_put)
+			break;
+
+		if (tftp_last_block == tftp_block) {
+			len = last_len;
+			break;
+		}
+
+		tftp_last_block = tftp_block;
+		s = (uint16_t *)pkt;
+		*s++ = htons(TFTP_DATA);
+		*s++ = htons(tftp_block);
+		len = read(tftp_fd, s, 512);
+		if (len < 0) {
+			perror("read");
+			tftp_err = -errno;
+			tftp_state = STATE_DONE;
+			return tftp_err;
+		}
+		tftp_size += len;
+		if (len < 512)
+			tftp_state = STATE_LAST;
+		len += 4;
+		last_len = len;
+		break;
+
+	case STATE_RDATA:
 	case STATE_OACK:
 		xp = pkt;
 		s = (uint16_t *)pkt;
@@ -103,17 +154,34 @@ static void tftp_handler(char *packet, unsigned len)
 		return;
 
 	len -= 2;
-	/* warning: don't use increment (++) in ntohs() macros!! */
+
 	s = (uint16_t *)pkt;
 	proto = *s++;
 	pkt = (unsigned char *)s;
+
 	switch (ntohs(proto)) {
 	case TFTP_RRQ:
 	case TFTP_WRQ:
-	case TFTP_ACK:
-		break;
 	default:
 		break;
+	case TFTP_ACK:
+		if (!tftp_put)
+			break;
+
+		tftp_block = ntohs(*(uint16_t *)pkt);
+		if (tftp_block != tftp_last_block) {
+			debug("ack %d != %d\n", tftp_block, tftp_last_block);
+			break;
+		}
+		tftp_block++;
+		if (tftp_state == STATE_LAST) {
+			tftp_state = STATE_DONE;
+			break;
+		}
+		tftp_con->udp->uh_dport = udp->uh_sport;
+		tftp_state = STATE_WDATA;
+		tftp_send();
+		break;
 
 	case TFTP_OACK:
 		debug("Got OACK: %s %s\n", pkt, pkt + strlen(pkt) + 1);
@@ -133,7 +201,7 @@ static void tftp_handler(char *packet, unsigned len)
 
 		if (tftp_state == STATE_RRQ || tftp_state == STATE_OACK) {
 			/* first block received */
-			tftp_state = STATE_DATA;
+			tftp_state = STATE_RDATA;
 			tftp_con->udp->uh_dport = udp->uh_sport;
 			tftp_server_port = ntohs(udp->uh_sport);
 			tftp_last_block = 0;
@@ -156,7 +224,7 @@ static void tftp_handler(char *packet, unsigned len)
 		if (!(tftp_block % 10))
 			tftp_size++;
 
-		ret = write(net_store_fd, pkt + 2, len);
+		ret = write(tftp_fd, pkt + 2, len);
 		if (ret < 0) {
 			perror("write");
 			tftp_err = -errno;
@@ -190,24 +258,47 @@ static void tftp_handler(char *packet, unsigned len)
 
 static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 {
-	char *localfile;
-	char *remotefile;
+	char *localfile, *remotefile, *file1, *file2;
 	char ip1[16];
+	int opt;
+	struct stat s;
+	unsigned long flags;
 
+	do_tftp_push(0);
+	tftp_last_block = 0;
 	tftp_size = 0;
 
-	if (argc < 2)
+	while((opt = getopt(argc, argv, "p")) > 0) {
+		switch(opt) {
+		case 'p':
+			do_tftp_push(1);
+			break;
+		}
+	}
+
+	if (argc <= optind)
 		return COMMAND_ERROR_USAGE;
 
-	remotefile = argv[1];
+	file1 = argv[optind++];
 
-	if (argc == 2)
-		localfile = basename(remotefile);
+	if (argc == optind)
+		file2 = basename(file1);
 	else
-		localfile = argv[2];
+		file2 = argv[optind];
+
+	if (tftp_put) {
+		localfile = file1;
+		remotefile = file2;
+		stat(localfile, &s);
+		flags = O_RDONLY;
+	} else {
+		localfile = file2;
+		remotefile = file1;
+		flags = O_WRONLY | O_CREAT;
+	}
 
-	net_store_fd = open(localfile, O_WRONLY | O_CREAT);
-	if (net_store_fd < 0) {
+	tftp_fd = open(localfile, flags);
+	if (tftp_fd < 0) {
 		perror("open");
 		return 1;
 	}
@@ -220,15 +311,16 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 
 	tftp_filename = remotefile;
 
-	printf("TFTP from server %s; Filename: '%s'\n",
+	printf("TFTP %s server %s ('%s' -> '%s')\n",
+			tftp_put ? "to" : "from",
 			ip_to_string(net_get_serverip(), ip1),
-			tftp_filename);
+			file1, file2);
 
-	init_progression_bar(0);
+	init_progression_bar(tftp_put ? s.st_size : 0);
 
 	tftp_timer_start = get_time_ns();
-	tftp_state = STATE_RRQ;
-	tftp_block = 0;
+	tftp_state = tftp_put ? STATE_WRQ : STATE_RRQ;
+	tftp_block = 1;
 
 	tftp_err = tftp_send();
 	if (tftp_err)
@@ -248,11 +340,12 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 out_unreg:
 	net_unregister(tftp_con);
 out_close:
-	close(net_store_fd);
+	close(tftp_fd);
 
 	if (tftp_err) {
 		printf("\ntftp failed: %s\n", strerror(-tftp_err));
-		unlink(localfile);
+		if (!tftp_put)
+			unlink(localfile);
 	}
 
 	printf("\n");
@@ -261,12 +354,22 @@ out_close:
 }
 
 static const __maybe_unused char cmd_tftp_help[] =
-"Usage: tftp <file> [localfile]\n"
-"Load a file via network using BootP/TFTP protocol.\n";
+"Usage: tftp <remotefile> [localfile]\n"
+"Load a file from a TFTP server.\n"
+#ifdef CONFIG_NET_TFTP_PUSH
+"or\n"
+"       tftp -p <localfile> [remotefile]\n"
+"Upload a file to a TFTP server\n"
+#endif
+;
 
 BAREBOX_CMD_START(tftp)
 	.cmd		= do_tftpb,
-	.usage		= "Load file using tftp protocol",
+	.usage		=
+#ifdef CONFIG_NET_TFTP_PUSH
+			"(up-)"
+#endif
+			"Load file using tftp protocol",
 	BAREBOX_CMD_HELP(cmd_tftp_help)
 BAREBOX_CMD_END
 
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:39:05 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:05 +0200
Subject: assorted patches
Message-ID: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>


The following changes since commit 334fe1dc8a1b866d1f0f4ccf82ff7b06589ec022:

  pca100: use generic default env (2010-06-22 15:44:45 +0200)

are available in the git repository at:
  git://git.pengutronix.de/git/barebox.git assorted-pu

Sascha Hauer (11):
      i.MX27: merge iomux pim definitions from kernel
      imxfb: Add board specific hook to enable display
      imxfb: do not enable framebuffer on startup
      memcpy cmd: Do not expect to read/write the whole chunk at once
      armlinux: reorder tag setup
      remove eco920 board support
      usbnet: remove unused dev member in struct usbnet
      i.MX serial: Use readl/writel instead of pointer deref
      i.MX clocksource: Use readl/writel instead of pointer deref
      i.MX27: Add some missing device base addresses
      fb: add a usage counter to prevent double enable/disable

 arch/arm/Makefile                           |    1 -
 arch/arm/lib/armlinux.c                     |   51 +++----
 arch/arm/mach-at91rm9200/Kconfig            |    8 -
 arch/arm/mach-imx/clocksource.c             |   18 ++-
 arch/arm/mach-imx/include/mach/imx21-regs.h |   33 ----
 arch/arm/mach-imx/include/mach/imx27-regs.h |   96 +-----------
 arch/arm/mach-imx/include/mach/imxfb.h      |    2 +
 arch/arm/mach-imx/include/mach/iomux-mx21.h |  121 ++++++++++++++
 arch/arm/mach-imx/include/mach/iomux-mx27.h |  204 ++++++++++++++++++++++++
 arch/arm/mach-imx/include/mach/iomux-mx2x.h |  230 +++++++++++++++++++++++++++
 board/eco920/Makefile                       |    2 -
 board/eco920/config.h                       |  134 ----------------
 board/eco920/config.mk                      |    1 -
 board/eco920/eco920.c                       |  211 ------------------------
 board/eukrea_cpuimx27/eukrea_cpuimx27.c     |    3 +-
 board/imx21ads/imx21ads.c                   |    1 +
 board/imx27ads/imx27ads.c                   |    3 +-
 board/pcm038/pcm038.c                       |    3 +-
 board/phycard-i.MX27/pca100.c               |    3 +-
 commands/mem.c                              |   30 +++--
 drivers/net/usb/asix.c                      |   12 +-
 drivers/net/usb/usbnet.c                    |    9 +-
 drivers/serial/serial_imx.c                 |  137 ++++++++--------
 drivers/video/fb.c                          |    5 +
 drivers/video/imx.c                         |    9 +-
 include/fb.h                                |    4 +-
 include/usb/usbnet.h                        |    2 -
 27 files changed, 718 insertions(+), 615 deletions(-)
 create mode 100644 arch/arm/mach-imx/include/mach/iomux-mx21.h
 create mode 100644 arch/arm/mach-imx/include/mach/iomux-mx27.h
 create mode 100644 arch/arm/mach-imx/include/mach/iomux-mx2x.h
 delete mode 100644 board/eco920/Makefile
 delete mode 100644 board/eco920/config.h
 delete mode 100644 board/eco920/config.mk
 delete mode 100644 board/eco920/eco920.c



From s.hauer at pengutronix.de  Thu Jun 24 05:39:12 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:12 +0200
Subject: [PATCH 07/11] usbnet: remove unused dev member in struct usbnet
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372356-32370-8-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/net/usb/asix.c   |   12 ++++++------
 drivers/net/usb/usbnet.c |    9 +++++----
 include/usb/usbnet.h     |    2 --
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c
index fc4146f..ca71b34 100644
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -415,13 +415,13 @@ static int asix_rx_fixup(struct usbnet *dev, void *buf, int len)
 
 	while (len > 0) {
 		if ((short)(header & 0x0000ffff) != ~((short)((header & 0xffff0000) >> 16)))
-			dev_err(&dev->dev, "asix_rx_fixup() Bad Header Length");
-	
+			dev_err(&dev->edev.dev, "asix_rx_fixup() Bad Header Length");
+
 		/* get the packet length */
 		size = (unsigned short) (header & 0x0000ffff);
 
 		if (size > 1514) {
-			dev_err(&dev->dev, "asix_rx_fixup() Bad RX Length %d", size);
+			dev_err(&dev->edev.dev, "asix_rx_fixup() Bad RX Length %d", size);
 			return 0;
 		}
 
@@ -440,7 +440,7 @@ static int asix_rx_fixup(struct usbnet *dev, void *buf, int len)
 	}
 
 	if (len < 0) {
-		dev_err(&dev->dev,"asix_rx_fixup() Bad SKB Length %d", len);
+		dev_err(&dev->edev.dev,"asix_rx_fixup() Bad SKB Length %d", len);
 		return -1;
 	}
 	return 0;
@@ -503,13 +503,13 @@ static int ax88172_bind(struct usbnet *dev)
 	unsigned long gpio_bits = dev->driver_info->data;
 	struct asix_data *data = (struct asix_data *)&dev->data;
 
-	dev_dbg(&dev->dev, "%s\n", __func__);
+	dev_dbg(&dev->edev.dev, "%s\n", __func__);
 
 	data->eeprom_len = AX88172_EEPROM_LEN;
 
 	ret = usbnet_get_endpoints(dev);
 	if (ret) {
-		dev_err(&dev->dev, "can not get EPs\n");
+		dev_err(&dev->edev.dev, "can not get EPs\n");
 		return ret;
 	}
 
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index b0e3090..cc170f6 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -74,7 +74,7 @@ int usbnet_get_endpoints(struct usbnet *dev)
 			in->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
 	dev->out = usb_sndbulkpipe (dev->udev,
 			out->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
-	dev_dbg(&dev->dev, "found endpoints: IN=%d OUT=%d\n",
+	dev_dbg(&dev->edev.dev, "found endpoints: IN=%d OUT=%d\n",
 			in->bEndpointAddress, out->bEndpointAddress);
 
 	return 0;
@@ -89,14 +89,14 @@ static int usbnet_send(struct eth_device *edev, void *eth_data, int data_length)
 	struct driver_info	*info = dev->driver_info;
 	int			len, alen, ret;
 
-	dev_dbg(&dev->dev, "%s\n",__func__);
+	dev_dbg(&edev->dev, "%s\n",__func__);
 
 	/* some devices want funky USB-level framing, for
 	 * win32 driver (usually) and/or hardware quirks
 	 */
         if(info->tx_fixup) {
                 if(info->tx_fixup(dev, eth_data, data_length, tx_buffer, &len)) {
-                        dev_dbg(&dev->dev, "can't tx_fixup packet");
+			dev_dbg(&edev->dev, "can't tx_fixup packet");
                         return 0;
                 }
         } else {
@@ -191,7 +191,7 @@ int usbnet_probe(struct usb_device *usbdev, const struct usb_device_id *prod)
 	struct driver_info *info;
 	int status;
 
-	dev_dbg(&edev->dev, "%s\n", __func__);
+	dev_dbg(&usbdev->dev, "%s\n", __func__);
 
 	undev = xzalloc(sizeof (*undev));
 
@@ -206,6 +206,7 @@ int usbnet_probe(struct usb_device *usbdev, const struct usb_device_id *prod)
 	edev->recv = usbnet_recv,
 	edev->halt = usbnet_halt,
 	edev->priv = undev;
+	edev->dev = usbdev->dev; /* will be overwritten by eth_register */
 
 	info = (struct driver_info *)prod->driver_info;
 	undev->driver_info = info;
diff --git a/include/usb/usbnet.h b/include/usb/usbnet.h
index 77f1960..e3ea373 100644
--- a/include/usb/usbnet.h
+++ b/include/usb/usbnet.h
@@ -54,8 +54,6 @@ struct usbnet {
 #		define EVENT_RX_MEMORY	2
 #		define EVENT_STS_SPLIT	3
 #		define EVENT_LINK_RESET	4
-	/* FIXME: Our eth_device should have this, not us! */
-	struct device_d dev;
 };
 
 #if 0
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:39:08 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:08 +0200
Subject: [PATCH 03/11] imxfb: do not enable framebuffer on startup
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372356-32370-4-git-send-email-s.hauer@pengutronix.de>

The board code or startup script should enable it when
it actually wants to.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/video/imx.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/drivers/video/imx.c b/drivers/video/imx.c
index 3a4f938..ac51858 100644
--- a/drivers/video/imx.c
+++ b/drivers/video/imx.c
@@ -579,8 +579,6 @@ static int imxfb_probe(struct device_d *dev)
 #ifdef CONFIG_IMXFB_DRIVER_VIDEO_IMX_OVERLAY
 	imxfb_register_overlay(fbi, pdata->framebuffer_ovl);
 #endif
-	imxfb_enable_controller(info);
-
 	return 0;
 }
 
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:39:09 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:09 +0200
Subject: [PATCH 04/11] memcpy cmd: Do not expect to read/write the whole chunk
	at once
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372356-32370-5-git-send-email-s.hauer@pengutronix.de>

read() does not necessarily return the number of bytes
we want to read, so deal with less bytes.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/mem.c |   30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/commands/mem.c b/commands/mem.c
index 6192466..bd1d349 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -455,27 +455,35 @@ static int do_mem_cp(struct command *cmdtp, int argc, char *argv[])
 	}
 
 	while (count > 0) {
-		int now, r, w;
+		int now, r, w, tmp;
 
 		now = min(RW_BUF_SIZE, count);
 
-		if ((r = read(sourcefd, rw_buf, now)) < 0) {
+		r = read(sourcefd, rw_buf, now);
+		if (r < 0) {
 			perror("read");
 			goto out;
 		}
 
-		if ((w = write(destfd, rw_buf, r)) < 0) {
-			perror("write");
-			goto out;
-		}
-
-		if (r < now)
+		if (!r)
 			break;
 
-		if (w < r)
-			break;
+		tmp = 0;
+		now = r;
+		while (now) {
+			w = write(destfd, rw_buf + tmp, now);
+			if (w < 0) {
+				perror("write");
+				goto out;
+			}
+	                if (!w)
+			        break;
 
-		count -= now;
+			now -= w;
+			tmp += w;
+		}
+
+		count -= r;
 	}
 
 	if (count) {
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:39:07 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:07 +0200
Subject: [PATCH 02/11] imxfb: Add board specific hook to enable display
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372356-32370-3-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/include/mach/imxfb.h |    2 ++
 drivers/video/imx.c                    |    7 +++++++
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-imx/include/mach/imxfb.h b/arch/arm/mach-imx/include/mach/imxfb.h
index e31b668..16b43ea 100644
--- a/arch/arm/mach-imx/include/mach/imxfb.h
+++ b/arch/arm/mach-imx/include/mach/imxfb.h
@@ -74,6 +74,8 @@ struct imx_fb_platform_data {
 	void		*framebuffer;
 	/** force a memory area to be used, else NULL for dynamic allocation */
 	void		*framebuffer_ovl;
+	/** hook to enable backlight and stuff */
+	void		(*enable)(int enable);
 };
 
 void set_imx_fb_info(struct imx_fb_platform_data *);
diff --git a/drivers/video/imx.c b/drivers/video/imx.c
index d9ba643..3a4f938 100644
--- a/drivers/video/imx.c
+++ b/drivers/video/imx.c
@@ -152,6 +152,7 @@ struct imxfb_info {
 	struct fb_info		info;
 	struct device_d		*dev;
 
+	void			(*enable)(int enable);
 
 	struct fb_info		overlay;
 };
@@ -262,12 +263,17 @@ static void imxfb_enable_controller(struct fb_info *info)
 	writel(readl(IMX_CCM_BASE + CCM_CGCR1) | (1 << 29),
 		IMX_CCM_BASE + CCM_CGCR1);
 #endif
+	if (fbi->enable)
+		fbi->enable(1);
 }
 
 static void imxfb_disable_controller(struct fb_info *info)
 {
 	struct imxfb_info *fbi = info->priv;
 
+	if (fbi->enable)
+		fbi->enable(0);
+
 	writel(0, fbi->regs + LCDC_RMCR);
 #ifdef CONFIG_ARCH_IMX21
 	PCCR0 &= ~(PCCR0_PERCLK3_EN | PCCR0_HCLK_LCDC_EN);
@@ -546,6 +552,7 @@ static int imxfb_probe(struct device_d *dev)
 	fbi->pwmr = pdata->pwmr;
 	fbi->lscr1 = pdata->lscr1;
 	fbi->dmacr = pdata->dmacr;
+	fbi->enable = pdata->enable;
 	fbi->dev = dev;
 	info->priv = fbi;
 	info->mode = &pdata->mode->mode;
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:39:15 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:15 +0200
Subject: [PATCH 10/11] i.MX27: Add some missing device base addresses
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372356-32370-11-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/include/mach/imx27-regs.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-imx/include/mach/imx27-regs.h b/arch/arm/mach-imx/include/mach/imx27-regs.h
index d804a9d..8d0bcda 100644
--- a/arch/arm/mach-imx/include/mach/imx27-regs.h
+++ b/arch/arm/mach-imx/include/mach/imx27-regs.h
@@ -16,6 +16,7 @@
 #define IMX_UART2_BASE             (0x0b000 + IMX_IO_BASE)
 #define IMX_UART3_BASE             (0x0c000 + IMX_IO_BASE)
 #define IMX_UART4_BASE             (0x0d000 + IMX_IO_BASE)
+#define IMX_SPI1_BASE              (0x0e000 + IMX_IO_BASE)
 #define IMX_I2C1_BASE              (0x12000 + IMX_IO_BASE)
 #define IMX_GPIO_BASE              (0x15000 + IMX_IO_BASE)
 #define IMX_TIM4_BASE              (0x19000 + IMX_IO_BASE)
@@ -25,9 +26,11 @@
 #define IMX_I2C2_BASE              (0x1d000 + IMX_IO_BASE)
 #define IMX_TIM6_BASE              (0x1f000 + IMX_IO_BASE)
 #define IMX_AIPI2_BASE             (0x20000 + IMX_IO_BASE)
+#define IMX_FB_BASE                (0x21000 + IMX_IO_BASE)
 #define IMX_PLL_BASE               (0x27000 + IMX_IO_BASE)
 #define IMX_SYSTEM_CTL_BASE        (0x27800 + IMX_IO_BASE)
 #define IMX_OTG_BASE               (0x24000 + IMX_IO_BASE)
+#define IMX_FEC_BASE               (0x2b000 + IMX_IO_BASE)
 
 #define IMX_NFC_BASE               (0xd8000000)
 #define IMX_ESD_BASE               (0xd8001000)
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:39:10 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:10 +0200
Subject: [PATCH 05/11] armlinux: reorder tag setup
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372356-32370-6-git-send-email-s.hauer@pengutronix.de>

We call the individual setup_*_tag functions from three different
boot commands. Waste less space by calling a single setup_tags function
instead.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/lib/armlinux.c |   51 ++++++++++++++++++++--------------------------
 1 files changed, 22 insertions(+), 29 deletions(-)

diff --git a/arch/arm/lib/armlinux.c b/arch/arm/lib/armlinux.c
index a38c6bf..89d989a 100644
--- a/arch/arm/lib/armlinux.c
+++ b/arch/arm/lib/armlinux.c
@@ -142,6 +142,25 @@ static void setup_end_tag (void)
 	params->hdr.size = 0;
 }
 
+static void setup_tags(void)
+{
+	const char *commandline = getenv("bootargs");
+
+	setup_start_tag();
+	setup_memory_tags();
+	setup_commandline_tag(commandline);
+#if 0
+	if (initrd_start && initrd_end)
+		setup_initrd_tag (initrd_start, initrd_end);
+#endif
+	setup_revision_tag();
+	setup_end_tag();
+
+	printf("commandline: %s\n"
+	       "arch_number: %d\n", commandline, armlinux_architecture);
+
+}
+
 void armlinux_set_bootparams(void *params)
 {
 	armlinux_bootparams = params;
@@ -172,7 +191,6 @@ int do_bootm_linux(struct image_data *data)
 {
 	void (*theKernel)(int zero, int arch, void *params);
 	image_header_t *os_header = &data->os->header;
-	const char *commandline = getenv("bootargs");
 
 	if (os_header->ih_type == IH_TYPE_MULTI) {
 		printf("Multifile images not handled at the moment\n");
@@ -189,23 +207,12 @@ int do_bootm_linux(struct image_data *data)
 		return -1;
 	}
 
-	printf("commandline: %s\n"
-	       "arch_number: %d\n", commandline, armlinux_architecture);
-
 	theKernel = (void *)ntohl(os_header->ih_ep);
 
 	debug("## Transferring control to Linux (at address 0x%p) ...\n",
 	       theKernel);
 
-	setup_start_tag();
-	setup_memory_tags();
-	setup_commandline_tag(commandline);
-#if 0
-	if (initrd_start && initrd_end)
-		setup_initrd_tag (initrd_start, initrd_end);
-#endif
-	setup_revision_tag();
-	setup_end_tag();
+	setup_tags();
 
 	if (relocate_image(data->os, (void *)ntohl(os_header->ih_load)))
 		return -1;
@@ -259,7 +266,6 @@ struct zimage_header {
 static int do_bootz(struct command *cmdtp, int argc, char *argv[])
 {
 	void (*theKernel)(int zero, int arch, void *params);
-	const char *commandline = getenv("bootargs");
 	int fd, ret;
 	struct zimage_header header;
 	void *zimage;
@@ -295,15 +301,7 @@ static int do_bootz(struct command *cmdtp, int argc, char *argv[])
 
 	printf("loaded zImage from %s with size %d\n", argv[1], header.end);
 
-	setup_start_tag();
-	setup_memory_tags();
-	setup_commandline_tag(commandline);
-#if 0
-	if (initrd_start && initrd_end)
-		setup_initrd_tag (initrd_start, initrd_end);
-#endif
-	setup_revision_tag();
-	setup_end_tag();
+	setup_tags();
 
 	shutdown_barebox();
 	theKernel(0, armlinux_architecture, armlinux_bootparams);
@@ -333,7 +331,6 @@ BAREBOX_CMD_END
 static int do_bootu(struct command *cmdtp, int argc, char *argv[])
 {
 	void (*theKernel)(int zero, int arch, void *params) = NULL;
-	const char *commandline = getenv("bootargs");
 	int fd;
 
 	if (argc != 2) {
@@ -348,11 +345,7 @@ static int do_bootu(struct command *cmdtp, int argc, char *argv[])
 	if (!theKernel)
 		theKernel = (void *)simple_strtoul(argv[1], NULL, 0);
 
-	setup_start_tag();
-	setup_memory_tags();
-	setup_commandline_tag(commandline);
-	setup_revision_tag();
-	setup_end_tag();
+	setup_tags();
 
 	shutdown_barebox();
 	theKernel(0, armlinux_architecture, armlinux_bootparams);
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:39:16 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:16 +0200
Subject: [PATCH 11/11] fb: add a usage counter to prevent double enable/disable
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372356-32370-12-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/video/fb.c |    5 +++++
 include/fb.h       |    4 +++-
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index 841c3af..f9a425e 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -39,6 +39,9 @@ static int fb_enable_set(struct device_d *dev, struct param_d *param,
 
 	enable = simple_strtoul(val, NULL, 0);
 
+	if (info->enabled == !!enable)
+		return 0;
+
 	if (enable) {
 		info->fbops->fb_enable(info);
 		new = "1";
@@ -49,6 +52,8 @@ static int fb_enable_set(struct device_d *dev, struct param_d *param,
 
 	dev_param_set_generic(dev, param, new);
 
+	info->enabled = !!enable;
+
 	return 0;
 }
 
diff --git a/include/fb.h b/include/fb.h
index 218500b..379f931 100644
--- a/include/fb.h
+++ b/include/fb.h
@@ -96,7 +96,9 @@ struct fb_info {
 	struct fb_bitfield red;		/* bitfield in fb mem if true color, */
 	struct fb_bitfield green;	/* else only length is significant */
 	struct fb_bitfield blue;
-	struct fb_bitfield transp;	/* transparency			*/	
+	struct fb_bitfield transp;	/* transparency			*/
+
+	int enabled;
 };
 
 int register_framebuffer(struct fb_info *info);
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:39:11 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:11 +0200
Subject: [PATCH 06/11] remove eco920 board support
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372356-32370-7-git-send-email-s.hauer@pengutronix.de>

It has been broken for long time and nobody cared, so remove it.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/Makefile                |    1 -
 arch/arm/mach-at91rm9200/Kconfig |    8 --
 board/eco920/Makefile            |    2 -
 board/eco920/config.h            |  134 ------------------------
 board/eco920/config.mk           |    1 -
 board/eco920/eco920.c            |  211 --------------------------------------
 6 files changed, 0 insertions(+), 357 deletions(-)
 delete mode 100644 board/eco920/Makefile
 delete mode 100644 board/eco920/config.h
 delete mode 100644 board/eco920/config.mk
 delete mode 100644 board/eco920/eco920.c

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 85ff9c8..1c9f24e 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -52,7 +52,6 @@ board-$(CONFIG_MACH_A9M2410)			:= a9m2410
 board-$(CONFIG_MACH_A9M2440)			:= a9m2440
 board-$(CONFIG_MACH_AT91SAM9260EK)		:= at91sam9260ek
 board-$(CONFIG_MACH_AT91SAM9263EK)		:= at91sam9263ek
-board-$(CONFIG_MACH_ECO920)			:= eco920
 board-$(CONFIG_MACH_EDB9301)			:= edb93xx
 board-$(CONFIG_MACH_EDB9302)			:= edb93xx
 board-$(CONFIG_MACH_EDB9302A)			:= edb93xx
diff --git a/arch/arm/mach-at91rm9200/Kconfig b/arch/arm/mach-at91rm9200/Kconfig
index 7e90179..c062097 100644
--- a/arch/arm/mach-at91rm9200/Kconfig
+++ b/arch/arm/mach-at91rm9200/Kconfig
@@ -2,7 +2,6 @@ if ARCH_AT91RM9200
 
 config ARCH_TEXT_BASE
 	hex
-	default 0x21e00000 if MACH_ECO920
 
 config BOARDINFO
 
@@ -12,13 +11,6 @@ choice
 
 	prompt "AT91RM9200 Board Type"
 
-config MACH_ECO920
-	bool "eco920"
-	select HAS_AT91_ETHER
-	select HAS_CFI
-	help
-	  Say Y here if you are using the Motorola MX1ADS board
-
 endchoice
 
 endif
diff --git a/board/eco920/Makefile b/board/eco920/Makefile
deleted file mode 100644
index 2cc70ca..0000000
--- a/board/eco920/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
-obj-y	+= eco920.o
-
diff --git a/board/eco920/config.h b/board/eco920/config.h
deleted file mode 100644
index 3fb8beb..0000000
--- a/board/eco920/config.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * (C) Copyright 2007 Pengutronix
- * Sascha Hauer, <s.hauer at pengutronix.de>
- *
- * 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
- */
-
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-/* ARM asynchronous clock */
-#define AT91C_MAIN_CLOCK	179712000	/* from 18.432 MHz crystal (18432000 / 4 * 39) */
-#define AT91C_MASTER_CLOCK	59904000	/* peripheral clock (AT91C_MASTER_CLOCK / 3) */
-/* #define AT91C_MASTER_CLOCK	44928000 */	/* peripheral clock (AT91C_MASTER_CLOCK / 4) */
-
-#define AT91_SLOW_CLOCK		32768	/* slow clock */
-
-#undef  CONFIG_USE_IRQ			/* we don't need IRQ/FIQ stuff	*/
-#define USE_920T_MMU		1
-
-#define CONFIG_CMDLINE_TAG	1	/* enable passing of ATAGs	*/
-#define CONFIG_SETUP_MEMORY_TAGS 1
-#define CONFIG_INITRD_TAG	1
-
-#define CFG_USE_MAIN_OSCILLATOR		1
-/* flash */
-#define MC_PUIA_VAL	0x00000000
-#define MC_PUP_VAL	0x00000000
-#define MC_PUER_VAL	0x00000000
-#define MC_ASR_VAL	0x00000000
-#define MC_AASR_VAL	0x00000000
-#define EBI_CFGR_VAL	0x00000000
-#define SMC2_CSR_VAL	0x00003287
-
-/* clocks */
-#define PLLAR_VAL	0x2026be04
-#define PLLBR_VAL	0x10483e0e
-#define MCKR_VAL	0x00000202
-
-/* sdram */
-#define PIOC_ASR_VAL	0xffff0000
-#define PIOC_BSR_VAL	0x00000000
-#define PIOC_PDR_VAL	0xffff0000
-#define EBI_CSA_VAL	0x00000002 /* CS1=SDRAM */
-#define SDRC_CR_VAL	0x2188c155 /* set up the SDRAM */
-#define SDRAM		0x20000000 /* address of the SDRAM */
-#define SDRAM1		0x20000080 /* address of the SDRAM */
-#define SDRAM_VAL	0x00000000 /* value written to SDRAM */
-#define SDRC_MR_VAL	0x00000002 /* Precharge All */
-#define SDRC_MR_VAL1	0x00000004 /* refresh */
-#define SDRC_MR_VAL2	0x00000003 /* Load Mode Register */
-#define SDRC_MR_VAL3	0x00000000 /* Normal Mode */
-#define SDRC_TR_VAL	0x000002E0 /* Write refresh rate */
-
-#define CONFIG_BAUDRATE 115200
-
-/*
- * Hardware drivers
- */
-
-/* define one of CONFIG_DBGU, CONFIG_USART0 or CONFIG_USART1 to choose console */
-#define CONFIG_DBGU
-
-#define CONFIG_BOOTDELAY      3
-
-#define CONFIG_CMDLINE_EDITING  1
-
-#define	CONFIG_EXTRA_ENV_SETTINGS											\
-	"mtdids=nor0=physmap-flash.0\0"											\
-	"mtdparts=mtdparts=physmap-flash.0:128k(barebox)ro,128k(env),1536k(kernel),-(jffs2)\0"				\
-	"bootargs_base=setenv bootargs console=ttyAT0,115200\0"								\
-	"bootargs_nfs=setenv bootargs $(bootargs) root=/dev/nfs ip=dhcp nfsroot=$(serverip):$(nfsrootfs),v3,tcp\0"	\
-	"bootargs_mtd=setenv bootargs $(bootargs) $(mtdparts)\0"							\
-	"bootargs_flash=setenv bootargs $(bootargs) root=/dev/mtdblock3 rootfstype=jffs2\0"				\
-	"bootcmd_flash=run bootargs_base bootargs_mtd bootargs_flash; bootm 0x11040000\0"				\
-	"bootcmd_net=run bootargs_base bootargs_mtd bootargs_nfs; tftpboot 0x20000000 $(uimage); bootm\0"		\
-	"autoload=n\0"													\
-	"uimage=uImage-eco920\0"											\
-	"jffs2=root-eco920.jffs2\0"
-
-/* this must be included AFTER the definition of CONFIG_COMMANDS (if any) */
-#include <cmd_confdefs.h>
-
-#define CONFIG_NR_DRAM_BANKS		1
-#define PHYS_SDRAM			0x20000000
-#define PHYS_SDRAM_SIZE			0x2000000
-
-#define CFG_MEMTEST_START		PHYS_SDRAM
-#define CFG_MEMTEST_END			CFG_MEMTEST_START + PHYS_SDRAM_SIZE - 262144
-
-#define CONFIG_DRIVER_ETHER
-#define CONFIG_NET_RETRY_COUNT		20
-#define CONFIG_AT91C_USE_RMII
-
-#define CFG_LOAD_ADDR		0x21000000  /* default load address */
-
-#define CFG_BAUDRATE_TABLE	{115200 , 19200, 38400, 57600, 9600 }
-
-#define	CFG_LONGHELP				/* undef to save memory		*/
-#define CFG_PROMPT		"barebox> "	/* Monitor Command Prompt */
-#define CFG_CBSIZE		1024		/* Console I/O Buffer Size */
-#define CFG_MAXARGS		32		/* max number of command args */
-#define CFG_PBSIZE		(CFG_CBSIZE+sizeof(CFG_PROMPT)+16) /* Print Buffer Size */
-
-#define CLOCK_TICK_RATE		AT91C_MASTER_CLOCK/2	/* AT91C_TC0_CMR is implicitly set to */
-							/* AT91C_TC_TIMER_DIV1_CLOCK */
-
-#define CONFIG_MISC_INIT_R      1       /* call misc_init_r() on init   */
-#define CFG_SPLASH		1
-#define CFG_S1D13706FB		1
-
-#define CFG_USB_OHCI_MAX_ROOT_PORTS     15
-#define CFG_USB_OHCI_SLOT_NAME           "at91rm9200"
-#define LITTLEENDIAN
-#define CONFIG_AT91C_PQFP_UHPBUG
-
-#endif
-
diff --git a/board/eco920/config.mk b/board/eco920/config.mk
deleted file mode 100644
index 9ce161e..0000000
--- a/board/eco920/config.mk
+++ /dev/null
@@ -1 +0,0 @@
-TEXT_BASE = 0x21f00000
diff --git a/board/eco920/eco920.c b/board/eco920/eco920.c
deleted file mode 100644
index 8d00877..0000000
--- a/board/eco920/eco920.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * (C) Copyright 2007 Pengutronix
- * Sascha Hauer, <s.hauer at pengutronix.de>
- *
- * 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 <mach/AT91RM9200.h>
-#include <at91rm9200_net.h>
-#include <dm9161.h>
-#include <miiphy.h>
-#include <splash.h>
-#include <asm/armlinux.h>
-#include <s1d13706fb.h>
-#include <net.h>
-#include <init.h>
-
-/*
- * Miscelaneous platform dependent initialisations
- */
-
-static struct cfi_platform_data cfi_info = {
-};
-
-struct device_d cfi_dev = {
-	.name     = "cfi_flash",
-	.map_base = 0x11000000,
-	.size     = 16 * 1024 * 1024,
-
-	.platform_data = &cfi_info,
-};
-
-static struct memory_platform_data ram_pdata = {
-	.name = "ram0",
-	.flags = DEVFS_RDWR,
-};
-
-struct device_d sdram_dev = {
-	.name     = "mem",
-	.map_base = 0x20000000,
-	.size     = 32 * 1024 * 1024,
-	.platform_data = &ram_pdata,
-};
-
-static struct device_d at91_ath_dev = {
-	.name     = "at91_eth",
-};
-
-static int devices_init (void)
-{
-	register_device(&cfi_dev);
-	register_device(&sdram_dev);
-	register_device(&at91_ath_dev);
-
-	armlinux_set_bootparams((void *)(PHYS_SDRAM + 0x100));
-	armlinux_set_architecture(MACH_TYPE_ECO920);
-
-	return 0;
-}
-
-device_initcall(devices_init);
-
-static unsigned int phy_is_connected (AT91PS_EMAC p_mac)
-{
-	return 1;
-}
-
-static unsigned char phy_init_bogus (AT91PS_EMAC p_mac)
-{
-	unsigned short val;
-	int timeout, adr, speed, fullduplex;
-
-	at91rm9200_EmacEnableMDIO (p_mac);
-
-	/* Scan through phy addresses to find a phy */
-	for (adr = 0; adr < 16; adr++) {
-		at91rm9200_EmacReadPhy(p_mac, PHY_PHYIDR1 | (adr << 5), &val);
-		if (val != 0xffff)
-			break;
-	}
-
-	adr <<= 5;
-
-	val = PHY_BMCR_RESET;
-	at91rm9200_EmacWritePhy(p_mac, PHY_BMCR | adr, &val);
-
-	udelay(1000);
-
-	val = 0x01e1; /* ADVERTISE_100FULL | ADVERTISE_100HALF |
-	               * ADVERTISE_10FULL | ADVERTISE_10HALF |
-		       * ADVERTISE_CSMA */
-	at91rm9200_EmacWritePhy(p_mac, PHY_ANAR | adr, &val);
-
-	at91rm9200_EmacReadPhy(p_mac, PHY_BMCR | adr, &val);
-	val |= PHY_BMCR_AUTON | PHY_BMCR_RST_NEG;
-	at91rm9200_EmacWritePhy(p_mac, PHY_BMCR | adr, &val);
-
-	timeout = 500;
-	do {
-		/* at91rm9200_EmacReadPhy() has a udelay(10000)
-		 * in it, so this should be about 5 deconds
-		 */
-		if ((timeout--) == 0) {
-			printf("Autonegotiation timeout\n");
-			goto out;
-		}
-
-		at91rm9200_EmacReadPhy(p_mac, PHY_BMSR | adr, &val);
-	} while (!(val & PHY_BMSR_LS));
-
-	at91rm9200_EmacReadPhy(p_mac, PHY_ANLPAR | adr, &val);
-
-	if (val & PHY_ANLPAR_100) {
-		speed = 100;
-		p_mac->EMAC_CFG |= AT91C_EMAC_SPD;
-	} else {
-		speed = 10;
-		p_mac->EMAC_CFG &= ~AT91C_EMAC_SPD;
-	}
-
-	if (val & (PHY_ANLPAR_TXFD | PHY_ANLPAR_10FD)) {
-		fullduplex = 1;
-		p_mac->EMAC_CFG |= AT91C_EMAC_FD;
-	} else {
-		fullduplex = 0;
-		p_mac->EMAC_CFG &= ~AT91C_EMAC_FD;
-	}
-
-	printf("running at %d-%sDuplex\n",speed, fullduplex ? "FUll" : "Half");
-
-out:
-	at91rm9200_EmacDisableMDIO (p_mac);
-
-	return 1;
-}
-
-void at91rm9200_GetPhyInterface(AT91PS_PhyOps p_phyops)
-{
-	p_phyops->Init = phy_init_bogus;
-	p_phyops->IsPhyConnected = phy_is_connected;
-	/* This is not used anywhere */
-	p_phyops->GetLinkSpeed = NULL;
-	/* ditto */
-	p_phyops->AutoNegotiate = NULL;
-}
-
-#ifdef CONFIG_DRIVER_VIDEO_S1D13706
-static int efb_init(struct efb_info *efb)
-{
-	writeb(GPIO_CONTROL0_GPO, efb->regs + EFB_GPIO_CONTROL1);
-	writeb(PCLK_SOURCE_CLKI2, efb->regs + EFB_PCLK_CONF);
-	writeb(0x1, efb->regs + 0x26); /* FIXME: display specific, should be set to zero
-					*        according to datasheet
-					*/
-	return 0;
-}
-
-/* Nanya STN Display */
-static struct efb_info efb = {
-	.fbd = {
-		.xres = 320,
-		.yres = 240,
-		.bpp = 8,
-		.fb = (void*)0x40020000,
-	},
-
-	.init			= efb_init,
-	.regs			= (void*)0x40000000,
-	.pixclock		= 100000,
-	.hsync_len		= 1,
-	.left_margin		= 22,
-	.right_margin		= 1,
-	.vsync_len		= 1,
-	.upper_margin		= 0,
-	.lower_margin		= 1,
-	.sync			= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
-	.panel_type		= PANEL_TYPE_STN | PANEL_TYPE_WIDTH_8 |
-				  PANEL_TYPE_COLOR | PANEL_TYPE_FORMAT_2,
-};
-#endif
-#define SMC_CSR3	0xFFFFFF7C
-
-int misc_init_r(void)
-{
-	/* Initialization of the Static Memory Controller for Chip Select 3 */
-	*(volatile unsigned long*)SMC_CSR3 = 0x00002185;
-#ifdef CONFIG_DRIVER_VIDEO_S1D13706
-	s1d13706fb_init(&efb);
-#endif
-#ifdef CONFIG_CMD_SPLASH
-	splash_set_fb_data(&efb.fbd);
-#endif
-	return 0;
-}
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:39:14 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:14 +0200
Subject: [PATCH 09/11] i.MX clocksource: Use readl/writel instead of pointer
	deref
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372356-32370-10-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/clocksource.c |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-imx/clocksource.c b/arch/arm/mach-imx/clocksource.c
index 4b400a0..a166038 100644
--- a/arch/arm/mach-imx/clocksource.c
+++ b/arch/arm/mach-imx/clocksource.c
@@ -35,12 +35,14 @@
 #include <notifier.h>
 #include <mach/imx-regs.h>
 #include <mach/clock.h>
+#include <asm/io.h>
 
 #define GPT(x) __REG(IMX_TIM1_BASE + (x))
+#define timer_base (IMX_TIM1_BASE)
 
 uint64_t imx_clocksource_read(void)
 {
-	return GPT(GPT_TCN);
+	return readl(timer_base + GPT_TCN);
 }
 
 static struct clocksource cs = {
@@ -62,8 +64,10 @@ static struct notifier_block imx_clock_notifier = {
 static int clocksource_init (void)
 {
 	int i;
+	uint32_t val;
+
 	/* setup GP Timer 1 */
-	GPT(GPT_TCTL) = TCTL_SWR;
+	writel(TCTL_SWR, timer_base + GPT_TCTL);
 
 #ifdef CONFIG_ARCH_IMX21
 	PCCR1 |= PCCR1_GPT1_EN;
@@ -74,12 +78,12 @@ static int clocksource_init (void)
 #endif
 
 	for (i = 0; i < 100; i++)
-		GPT(GPT_TCTL) = 0; /* We have no udelay by now */
+		writel(0, timer_base + GPT_TCTL); /* We have no udelay by now */
 
-	GPT(GPT_TPRER) = 0;
-	GPT(GPT_TCTL) |= TCTL_FRR | (1<<TCTL_CLKSOURCE); /* Freerun Mode, PERCLK1 input */
-	GPT(GPT_TCTL) &= ~TCTL_TEN;
-	GPT(GPT_TCTL) |= TCTL_TEN; /* Enable timer */
+	writel(0, timer_base + GPT_TPRER);
+	val = readl(timer_base + GPT_TCTL);
+	val |= TCTL_FRR | (1 << TCTL_CLKSOURCE) | TCTL_TEN; /* Freerun Mode, PERCLK1 input */
+	writel(val, timer_base + GPT_TCTL);
 
 	cs.mult = clocksource_hz2mult(imx_get_gptclk(), cs.shift);
 
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:39:13 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:13 +0200
Subject: [PATCH 08/11] i.MX serial: Use readl/writel instead of pointer deref
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372356-32370-9-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/serial/serial_imx.c |  137 ++++++++++++++++++++++---------------------
 1 files changed, 71 insertions(+), 66 deletions(-)

diff --git a/drivers/serial/serial_imx.c b/drivers/serial/serial_imx.c
index 91d3b18..801004e 100644
--- a/drivers/serial/serial_imx.c
+++ b/drivers/serial/serial_imx.c
@@ -24,34 +24,35 @@
 #include <init.h>
 #include <malloc.h>
 #include <notifier.h>
-
-#define URXD0(base) __REG( 0x0 +(base))  /* Receiver Register */
-#define URTX0(base) __REG( 0x40 +(base)) /* Transmitter Register */
-#define UCR1(base)  __REG( 0x80 +(base)) /* Control Register 1 */
-#define UCR2(base)  __REG( 0x84 +(base)) /* Control Register 2 */
-#define UCR3(base)  __REG( 0x88 +(base)) /* Control Register 3 */
-#define UCR4(base)  __REG( 0x8c +(base)) /* Control Register 4 */
-#define UFCR(base)  __REG( 0x90 +(base)) /* FIFO Control Register */
-#define USR1(base)  __REG( 0x94 +(base)) /* Status Register 1 */
-#define USR2(base)  __REG( 0x98 +(base)) /* Status Register 2 */
-#define UESC(base)  __REG( 0x9c +(base)) /* Escape Character Register */
-#define UTIM(base)  __REG( 0xa0 +(base)) /* Escape Timer Register */
-#define UBIR(base)  __REG( 0xa4 +(base)) /* BRM Incremental Register */
-#define UBMR(base)  __REG( 0xa8 +(base)) /* BRM Modulator Register */
-#define UBRC(base)  __REG( 0xac +(base)) /* Baud Rate Count Register */
+#include <asm/io.h>
+
+#define URXD0	0x0	/* Receiver Register */
+#define URTX0	0x40	/* Transmitter Register */
+#define UCR1	0x80	/* Control Register 1 */
+#define UCR2	0x84	/* Control Register 2 */
+#define UCR3	0x88	/* Control Register 3 */
+#define UCR4	0x8c	/* Control Register 4 */
+#define UFCR	0x90	/* FIFO Control Register */
+#define USR1	0x94	/* Status Register 1 */
+#define USR2	0x98	/* Status Register 2 */
+#define UESC	0x9c	/* Escape Character Register */
+#define UTIM	0xa0	/* Escape Timer Register */
+#define UBIR	0xa4	/* BRM Incremental Register */
+#define UBMR	0xa8	/* BRM Modulator Register */
+#define UBRC	0xac	/* Baud Rate Count Register */
 #ifdef CONFIG_ARCH_IMX1
-#define BIPR1(base) __REG( 0xb0 +(base)) /* Incremental Preset Register 1 */
-#define BIPR2(base) __REG( 0xb4 +(base)) /* Incremental Preset Register 2 */
-#define BIPR3(base) __REG( 0xb8 +(base)) /* Incremental Preset Register 3 */
-#define BIPR4(base) __REG( 0xbc +(base)) /* Incremental Preset Register 4 */
-#define BMPR1(base) __REG( 0xc0 +(base)) /* BRM Modulator Register 1 */
-#define BMPR2(base) __REG( 0xc4 +(base)) /* BRM Modulator Register 2 */
-#define BMPR3(base) __REG( 0xc8 +(base)) /* BRM Modulator Register 3 */
-#define BMPR4(base) __REG( 0xcc +(base)) /* BRM Modulator Register 4 */
-#define UTS(base)   __REG( 0xd0 +(base)) /* UART Test Register */
+#define BIPR1	0xb0	/* Incremental Preset Register 1 */
+#define BIPR2	0xb4	/* Incremental Preset Register 2 */
+#define BIPR3	0xb8	/* Incremental Preset Register 3 */
+#define BIPR4	0xbc	/* Incremental Preset Register 4 */
+#define BMPR1	0xc0	/* BRM Modulator Register 1 */
+#define BMPR2	0xc4	/* BRM Modulator Register 2 */
+#define BMPR3	0xc8	/* BRM Modulator Register 3 */
+#define BMPR4	0xcc	/* BRM Modulator Register 4 */
+#define UTS	0xd0	/* UART Test Register */
 #else
-#define ONEMS(base) __REG( 0xb0 +(base)) /* One Millisecond register */
-#define UTS(base)   __REG( 0xb4 +(base)) /* UART Test Register */
+#define ONEMS	0xb0 /* One Millisecond register */
+#define UTS	0xb4 /* UART Test Register */
 #endif
 
 /* UART Control Register Bit Fields.*/
@@ -175,7 +176,7 @@ static int imx_serial_reffreq(ulong base)
 {
 	ulong rfdiv;
 
-	rfdiv = (UFCR(base) >> 7) & 7;
+	rfdiv = (readl(base + UFCR) >> 7) & 7;
 	rfdiv = rfdiv < 6 ? 6 - rfdiv : 7;
 
 	return imx_get_uartclk() / rfdiv;
@@ -190,45 +191,42 @@ static int imx_serial_init_port(struct console_device *cdev)
 {
 	struct device_d *dev = cdev->dev;
 	ulong base = dev->map_base;
+	uint32_t val;
+
+	writel(UCR1_VAL, base + UCR1);
+	writel(UCR2_WS | UCR2_IRTS, base + UCR2);
+	writel(UCR3_VAL, base + UCR3);
+	writel(UCR4_VAL, base + UCR4);
+	writel(0x0000002B, base + UESC);
+	writel(0, base + UTIM);
+	writel(0, base + UBIR);
+	writel(0, base + UBMR);
+	writel(0, base + UTS);
 
-	UCR1(base) = UCR1_VAL;
-	UCR2(base) = UCR2_WS | UCR2_IRTS;
-	UCR3(base) = UCR3_VAL;
-	UCR4(base) = UCR4_VAL;
-	UESC(base) = 0x0000002B;
-	UTIM(base) = 0;
-	UBIR(base) = 0;
-	UBMR(base) = 0;
-	UTS(base)  = 0;
 
 	/* Configure FIFOs */
-	UFCR(base) = 0xa81;
+	writel(0xa81, base + UFCR);
 
 #ifdef ONEMS
-	ONEMS(base) = imx_serial_reffreq(base) / 1000;
+	writel(imx_serial_reffreq(base) / 1000, base + ONEMS);
 #endif
 
 	/* Enable FIFOs */
-	UCR2(base) |= UCR2_SRST | UCR2_RXEN | UCR2_TXEN;
+	val = readl(base + UCR2);
+	val |= UCR2_SRST | UCR2_RXEN | UCR2_TXEN;
+	writel(val, base + UCR2);
 
   	/* Clear status flags */
-	USR2(base) |= USR2_ADET  |
-	          USR2_DTRF  |
-	          USR2_IDLE  |
-	          USR2_IRINT |
-	          USR2_WAKE  |
-	          USR2_RTSF  |
-	          USR2_BRCD  |
-	          USR2_ORE   |
-	          USR2_RDR;
+	val = readl(base + USR2);
+	val |= USR2_ADET | USR2_DTRF | USR2_IDLE | USR2_IRINT | USR2_WAKE |
+	       USR2_RTSF | USR2_BRCD | USR2_ORE | USR2_RDR;
+	writel(val, base + USR2);
 
   	/* Clear status flags */
-	USR1(base) |= USR1_PARITYERR |
-	          USR1_RTSD      |
-	          USR1_ESCF      |
-	          USR1_FRAMERR   |
-	          USR1_AIRINT    |
-	          USR1_AWAKE;
+	val = readl(base + USR2);
+	val |= USR1_PARITYERR | USR1_RTSD | USR1_ESCF | USR1_FRAMERR | USR1_AIRINT |
+	       USR1_AWAKE;
+	writel(val, base + USR2);
 
 	return 0;
 }
@@ -238,9 +236,9 @@ static void imx_serial_putc(struct console_device *cdev, char c)
 	struct device_d *dev = cdev->dev;
 
 	/* Wait for Tx FIFO not full */
-	while (UTS(dev->map_base) & UTS_TXFULL);
+	while (readl(dev->map_base + UTS) & UTS_TXFULL);
 
-        URTX0(dev->map_base) = c;
+        writel(c, dev->map_base + URTX0);
 }
 
 static int imx_serial_tstc(struct console_device *cdev)
@@ -248,7 +246,7 @@ static int imx_serial_tstc(struct console_device *cdev)
 	struct device_d *dev = cdev->dev;
 
 	/* If receive fifo is empty, return false */
-	if (UTS(dev->map_base) & UTS_RXEMPTY)
+	if (readl(dev->map_base + UTS) & UTS_RXEMPTY)
 		return 0;
 	return 1;
 }
@@ -258,9 +256,9 @@ static int imx_serial_getc(struct console_device *cdev)
 	struct device_d *dev = cdev->dev;
 	unsigned char ch;
 
-	while (UTS(dev->map_base) & UTS_RXEMPTY);
+	while (readl(dev->map_base + UTS) & UTS_RXEMPTY);
 
-	ch = URXD0(dev->map_base);
+	ch = readl(dev->map_base + URXD0);
 
 	return ch;
 }
@@ -269,7 +267,7 @@ static void imx_serial_flush(struct console_device *cdev)
 {
 	struct device_d *dev = cdev->dev;
 
-	while (!(USR2(dev->map_base) & USR2_TXDC));
+	while (!(readl(dev->map_base + USR2) & USR2_TXDC));
 }
 
 static int imx_serial_setbaudrate(struct console_device *cdev, int baudrate)
@@ -277,18 +275,22 @@ static int imx_serial_setbaudrate(struct console_device *cdev, int baudrate)
 	struct device_d *dev = cdev->dev;
 	struct imx_serial_priv *priv = container_of(cdev,
 					struct imx_serial_priv, cdev);
+	uint32_t val;
+
 	ulong base = dev->map_base;
-	ulong ucr1 = UCR1(base);
+	ulong ucr1 = readl(base + UCR1);
 
 	/* disable UART */
-	UCR1(base) &= ~UCR1_UARTEN;
+	val = readl(base + UCR1);
+	val &= ~UCR1_UARTEN;
+	writel(val, base + UCR1);
 
 	/* Set the numerator value minus one of the BRM ratio */
-	UBIR(base) = (baudrate / 100) - 1;
+	writel((baudrate / 100) - 1, base + UBIR);
 	/* Set the denominator value minus one of the BRM ratio    */
-	UBMR(base) = ((imx_serial_reffreq(base) / 1600) - 1);
+	writel((imx_serial_reffreq(base) / 1600) - 1, base + UBMR);
 
-	UCR1(base) = ucr1;
+	writel(ucr1, base + UCR1);
 
 	priv->baudrate = baudrate;
 
@@ -310,6 +312,7 @@ static int imx_serial_probe(struct device_d *dev)
 {
 	struct console_device *cdev;
 	struct imx_serial_priv *priv;
+	uint32_t val;
 
 	priv = malloc(sizeof(*priv));
 	cdev = &priv->cdev;
@@ -327,7 +330,9 @@ static int imx_serial_probe(struct device_d *dev)
 	imx_serial_setbaudrate(cdev, 115200);
 
 	/* Enable UART */
-	UCR1(cdev->dev->map_base) |= UCR1_UARTEN;
+	val = readl(cdev->dev->map_base + UCR1);
+	val |= UCR1_UARTEN;
+	writel(val, cdev->dev->map_base + UCR1);
 
 	console_register(cdev);
 	priv->notify.notifier_call = imx_clocksource_clock_change;
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:39:06 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:39:06 +0200
Subject: [PATCH 01/11] i.MX27: merge iomux pim definitions from kernel
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372356-32370-2-git-send-email-s.hauer@pengutronix.de>

The Kernel pin definitions are more complete and up to date. Being
here we also use seperate files for the iomuxer like the other
i.MX SoCs already do.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/include/mach/imx21-regs.h |   33 ----
 arch/arm/mach-imx/include/mach/imx27-regs.h |   93 -----------
 arch/arm/mach-imx/include/mach/iomux-mx21.h |  121 ++++++++++++++
 arch/arm/mach-imx/include/mach/iomux-mx27.h |  204 ++++++++++++++++++++++++
 arch/arm/mach-imx/include/mach/iomux-mx2x.h |  230 +++++++++++++++++++++++++++
 board/eukrea_cpuimx27/eukrea_cpuimx27.c     |    3 +-
 board/imx21ads/imx21ads.c                   |    1 +
 board/imx27ads/imx27ads.c                   |    3 +-
 board/pcm038/pcm038.c                       |    3 +-
 board/phycard-i.MX27/pca100.c               |    3 +-
 10 files changed, 564 insertions(+), 130 deletions(-)
 create mode 100644 arch/arm/mach-imx/include/mach/iomux-mx21.h
 create mode 100644 arch/arm/mach-imx/include/mach/iomux-mx27.h
 create mode 100644 arch/arm/mach-imx/include/mach/iomux-mx2x.h

diff --git a/arch/arm/mach-imx/include/mach/imx21-regs.h b/arch/arm/mach-imx/include/mach/imx21-regs.h
index 3d21749..6d64b81 100644
--- a/arch/arm/mach-imx/include/mach/imx21-regs.h
+++ b/arch/arm/mach-imx/include/mach/imx21-regs.h
@@ -115,39 +115,6 @@
 
 #define CCSR_32K_SR		(1 << 15)
 
-#define PA5_PF_LSCLK            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 5)
-#define PA6_PF_LD0              (GPIO_PORTA | GPIO_PF | GPIO_OUT | 6)
-#define PA7_PF_LD1              (GPIO_PORTA | GPIO_PF | GPIO_OUT | 7)
-#define PA8_PF_LD2              (GPIO_PORTA | GPIO_PF | GPIO_OUT | 8)
-#define PA9_PF_LD3              (GPIO_PORTA | GPIO_PF | GPIO_OUT | 9)
-#define PA10_PF_LD4             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 10)
-#define PA11_PF_LD5             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 11)
-#define PA12_PF_LD6             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 12)
-#define PA13_PF_LD7             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 13)
-#define PA14_PF_LD8             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 14)
-#define PA15_PF_LD9             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 15)
-#define PA16_PF_LD10            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 16)
-#define PA17_PF_LD11            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 17)
-#define PA18_PF_LD12            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 18)
-#define PA19_PF_LD13            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 19)
-#define PA20_PF_LD14            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 20)
-#define PA21_PF_LD15            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 21)
-#define PA22_PF_LD16            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 22)
-#define PA23_PF_LD17            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 23)
-#define PA24_PF_REV             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 24)
-#define PA25_PF_CLS             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 25)
-#define PA26_PF_PS              (GPIO_PORTA | GPIO_PF | GPIO_OUT | 26)
-#define PA27_PF_SPL_SPR         (GPIO_PORTA | GPIO_PF | GPIO_OUT | 27)
-#define PA28_PF_HSYNC           (GPIO_PORTA | GPIO_PF | GPIO_OUT | 28)
-#define PA29_PF_VSYNC           (GPIO_PORTA | GPIO_PF | GPIO_OUT | 29)
-#define PA30_PF_CONTRAST        (GPIO_PORTA | GPIO_PF | GPIO_OUT | 30)
-#define PA31_PF_OE_ACD          (GPIO_PORTA | GPIO_PF | GPIO_OUT | 31)
-
-#define PE12_PF_UART1_TXD	(GPIO_PORTE | GPIO_OUT | GPIO_PF | 12)
-#define PE13_PF_UART1_RXD	(GPIO_PORTE | GPIO_IN  | GPIO_PF | 13)
-#define PE14_PF_UART1_CTS	(GPIO_PORTE | GPIO_OUT | GPIO_PF | 14)
-#define PE15_PF_UART1_RTS	(GPIO_PORTE | GPIO_IN  | GPIO_PF | 15)
-
 /*
  * Definitions for the clocksource driver
  */
diff --git a/arch/arm/mach-imx/include/mach/imx27-regs.h b/arch/arm/mach-imx/include/mach/imx27-regs.h
index 4e22612..d804a9d 100644
--- a/arch/arm/mach-imx/include/mach/imx27-regs.h
+++ b/arch/arm/mach-imx/include/mach/imx27-regs.h
@@ -232,99 +232,6 @@
 #define ESDMISC_MA10_SHARE	(1 << 6)
 #define ESDMISC_SDRAM_RDY	(1 << 6)
 
-#define PA0_PF_USBH2_CLK        (GPIO_PORTA | GPIO_PF | 0)
-#define PA1_PF_USBH2_DIR        (GPIO_PORTA | GPIO_PF | 1)
-#define PA2_PF_USBH2_DATA7      (GPIO_PORTA | GPIO_PF | 2)
-#define PA3_PF_USBH2_NXT        (GPIO_PORTA | GPIO_PF | 3)
-#define PA4_PF_USBH2_STP        (GPIO_PORTA | GPIO_PF | 4)
-#define PA5_PF_LSCLK            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 5)
-#define PA6_PF_LD0              (GPIO_PORTA | GPIO_PF | GPIO_OUT | 6)
-#define PA7_PF_LD1              (GPIO_PORTA | GPIO_PF | GPIO_OUT | 7)
-#define PA8_PF_LD2              (GPIO_PORTA | GPIO_PF | GPIO_OUT | 8)
-#define PA9_PF_LD3              (GPIO_PORTA | GPIO_PF | GPIO_OUT | 9)
-#define PA10_PF_LD4             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 10)
-#define PA11_PF_LD5             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 11)
-#define PA12_PF_LD6             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 12)
-#define PA13_PF_LD7             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 13)
-#define PA14_PF_LD8             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 14)
-#define PA15_PF_LD9             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 15)
-#define PA16_PF_LD10            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 16)
-#define PA17_PF_LD11            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 17)
-#define PA18_PF_LD12            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 18)
-#define PA19_PF_LD13            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 19)
-#define PA20_PF_LD14            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 20)
-#define PA21_PF_LD15            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 21)
-#define PA22_PF_LD16            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 22)
-#define PA23_PF_LD17            (GPIO_PORTA | GPIO_PF | GPIO_OUT | 23)
-#define PA24_PF_REV             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 24)
-#define PA25_PF_CLS             (GPIO_PORTA | GPIO_PF | GPIO_OUT | 25)
-#define PA26_PF_PS              (GPIO_PORTA | GPIO_PF | GPIO_OUT | 26)
-#define PA27_PF_SPL_SPR         (GPIO_PORTA | GPIO_PF | GPIO_OUT | 27)
-#define PA28_PF_HSYNC           (GPIO_PORTA | GPIO_PF | GPIO_OUT | 28)
-#define PA29_PF_VSYNC           (GPIO_PORTA | GPIO_PF | GPIO_OUT | 29)
-#define PA30_PF_CONTRAST        (GPIO_PORTA | GPIO_PF | GPIO_OUT | 30)
-#define PA31_PF_OE_ACD          (GPIO_PORTA | GPIO_PF | GPIO_OUT | 31)
-#define PD0_AIN_FEC_TXD0	(GPIO_PORTD | GPIO_OUT | GPIO_AIN | 0)
-#define PD1_AIN_FEC_TXD1	(GPIO_PORTD | GPIO_OUT | GPIO_AIN | 1)
-#define PD2_AIN_FEC_TXD2	(GPIO_PORTD | GPIO_OUT | GPIO_AIN | 2)
-#define PD3_AIN_FEC_TXD3	(GPIO_PORTD | GPIO_OUT | GPIO_AIN | 3)
-#define PD4_AOUT_FEC_RX_ER	(GPIO_PORTD | GPIO_IN | GPIO_AOUT | 4)
-#define PD5_AOUT_FEC_RXD1	(GPIO_PORTD | GPIO_IN | GPIO_AOUT | 5)
-#define PD6_AOUT_FEC_RXD2	(GPIO_PORTD | GPIO_IN | GPIO_AOUT | 6)
-#define PD7_AOUT_FEC_RXD3	(GPIO_PORTD | GPIO_IN | GPIO_AOUT | 7)
-#define PD8_AF_FEC_MDIO		(GPIO_PORTD | GPIO_IN | GPIO_AF | 8)
-#define PD9_AIN_FEC_MDC		(GPIO_PORTD | GPIO_OUT | GPIO_AIN | 9)
-#define PD10_AOUT_FEC_CRS	(GPIO_PORTD | GPIO_IN | GPIO_AOUT | 10)
-#define PD11_AOUT_FEC_TX_CLK	(GPIO_PORTD | GPIO_IN | GPIO_AOUT | 11)
-#define PD12_AOUT_FEC_RXD0	(GPIO_PORTD | GPIO_IN | GPIO_AOUT | 12)
-#define PD13_AOUT_FEC_RX_DV	(GPIO_PORTD | GPIO_IN | GPIO_AOUT | 13)
-#define PD14_AOUT_FEC_CLR	(GPIO_PORTD | GPIO_IN | GPIO_AOUT | 14)
-#define PD15_AOUT_FEC_COL	(GPIO_PORTD | GPIO_IN | GPIO_AOUT | 15)
-#define PD16_AIN_FEC_TX_ER	(GPIO_PORTD | GPIO_OUT | GPIO_AIN | 16)
-#define PD17_PF_I2C_DATA	(GPIO_PORTD | GPIO_OUT | GPIO_PF | 17)
-#define PD18_PF_I2C_CLK		(GPIO_PORTD | GPIO_OUT | GPIO_PF | 18)
-#define PD19_AF_USBH2_DATA4     (GPIO_PORTD | GPIO_AF | 19)
-#define PD20_AF_USBH2_DATA3     (GPIO_PORTD | GPIO_AF | 20)
-#define PD21_AF_USBH2_DATA6     (GPIO_PORTD | GPIO_AF | 21)
-#define PD22_AF_USBH2_DATA0     (GPIO_PORTD | GPIO_AF | 22)
-#define PD23_AF_USBH2_DATA2     (GPIO_PORTD | GPIO_AF | 23)
-#define PD24_AF_USBH2_DATA1     (GPIO_PORTD | GPIO_AF | 24)
-#define PD25_PF_CSPI1_RDY	(GPIO_PORTD | GPIO_OUT | GPIO_PF  | 25)
-#define PD26_PF_CSPI1_SS2	(GPIO_PORTD | GPIO_OUT | GPIO_PF  | 26)
-#define PD26_AF_USBH2_DATA5     (GPIO_PORTD | GPIO_AF | 26)
-#define PD27_PF_CSPI1_SS1	(GPIO_PORTD | GPIO_OUT | GPIO_PF  | 27)
-#define PD28_PF_CSPI1_SS0	(GPIO_PORTD | GPIO_OUT | GPIO_PF  | 28)
-#define PD29_PF_CSPI1_SCLK	(GPIO_PORTD | GPIO_OUT | GPIO_PF  | 29)
-#define PD30_PF_CSPI1_MISO	(GPIO_PORTD | GPIO_IN | GPIO_PF  | 30)
-#define PD31_PF_CSPI1_MOSI	(GPIO_PORTD | GPIO_OUT | GPIO_PF  | 31)
-#define PF23_AIN_FEC_TX_EN	(GPIO_PORTF | GPIO_OUT | GPIO_AIN | 23)
-#define PE3_PF_UART2_CTS	(GPIO_PORTE | GPIO_OUT | GPIO_PF | 3)
-#define PE4_PF_UART2_RTS	(GPIO_PORTE | GPIO_IN  | GPIO_PF | 4)
-#define PE6_PF_UART2_TXD	(GPIO_PORTE | GPIO_OUT | GPIO_PF | 6)
-#define PE7_PF_UART2_RXD	(GPIO_PORTE | GPIO_IN  | GPIO_PF | 7)
-#define PE8_PF_UART3_TXD	(GPIO_PORTE | GPIO_OUT | GPIO_PF | 8)
-#define PE9_PF_UART3_RXD	(GPIO_PORTE | GPIO_IN  | GPIO_PF | 9)
-#define PE10_PF_UART3_CTS	(GPIO_PORTE | GPIO_OUT | GPIO_PF | 10)
-#define PE11_PF_UART3_RTS	(GPIO_PORTE | GPIO_IN  | GPIO_PF | 11)
-#define PE12_PF_UART1_TXD	(GPIO_PORTE | GPIO_OUT | GPIO_PF | 12)
-#define PE13_PF_UART1_RXD	(GPIO_PORTE | GPIO_IN  | GPIO_PF | 13)
-#define PE14_PF_UART1_CTS	(GPIO_PORTE | GPIO_OUT | GPIO_PF | 14)
-#define PE15_PF_UART1_RTS	(GPIO_PORTE | GPIO_IN  | GPIO_PF | 15)
-#define PC5_PF_I2C2_DATA	(GPIO_PORTC | GPIO_OUT | GPIO_PF | 5)
-#define PC6_PF_I2C2_CLK		(GPIO_PORTC | GPIO_OUT | GPIO_PF | 6)
-#define PC7_PF_USBOTG_DATA5     (GPIO_PORTC | GPIO_PF | GPIO_OUT | 7)
-#define PC8_PF_USBOTG_DATA6     (GPIO_PORTC | GPIO_PF | GPIO_OUT | 8)
-#define PC9_PF_USBOTG_DATA0     (GPIO_PORTC | GPIO_PF | GPIO_OUT | 9)
-#define PC10_PF_USBOTG_DATA2    (GPIO_PORTC | GPIO_PF | GPIO_OUT | 10)
-#define PC11_PF_USBOTG_DATA1    (GPIO_PORTC | GPIO_PF | GPIO_OUT | 11)
-#define PC12_PF_USBOTG_DATA4    (GPIO_PORTC | GPIO_PF | GPIO_OUT | 12)
-#define PC13_PF_USBOTG_DATA3    (GPIO_PORTC | GPIO_PF | GPIO_OUT | 13)
-#define PE0_PF_USBOTG_NXT       (GPIO_PORTE | GPIO_PF | GPIO_OUT | 0)
-#define PE1_PF_USBOTG_STP       (GPIO_PORTE | GPIO_PF | GPIO_OUT | 1)
-#define PE2_PF_USBOTG_DIR       (GPIO_PORTE | GPIO_PF | GPIO_OUT | 2)
-#define PE24_PF_USBOTG_CLK      (GPIO_PORTE | GPIO_PF | GPIO_OUT | 24)
-#define PE25_PF_USBOTG_DATA7    (GPIO_PORTE | GPIO_PF | GPIO_OUT | 25)
-
 /*
  * Definitions for the clocksource driver
  */
diff --git a/arch/arm/mach-imx/include/mach/iomux-mx21.h b/arch/arm/mach-imx/include/mach/iomux-mx21.h
new file mode 100644
index 0000000..c7218bc
--- /dev/null
+++ b/arch/arm/mach-imx/include/mach/iomux-mx21.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2009 by Holger Schurig <hs4233 at mail.mn-solutions.de>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+#ifndef __MACH_IOMUX_MX21_H__
+#define __MACH_IOMUX_MX21_H__
+
+#include <mach/iomux-mx2x.h>
+
+/* Primary GPIO pin functions */
+
+#define PB22_PF_USBH1_BYP	(GPIO_PORTB | GPIO_PF | 22)
+#define PB25_PF_USBH1_ON	(GPIO_PORTB | GPIO_PF | 25)
+#define PC5_PF_USBOTG_SDA	(GPIO_PORTC | GPIO_PF | 5)
+#define PC6_PF_USBOTG_SCL	(GPIO_PORTC | GPIO_PF | 6)
+#define PC7_PF_USBOTG_ON	(GPIO_PORTC | GPIO_PF | 7)
+#define PC8_PF_USBOTG_FS	(GPIO_PORTC | GPIO_PF | 8)
+#define PC9_PF_USBOTG_OE	(GPIO_PORTC | GPIO_PF | 9)
+#define PC10_PF_USBOTG_TXDM	(GPIO_PORTC | GPIO_PF | 10)
+#define PC11_PF_USBOTG_TXDP	(GPIO_PORTC | GPIO_PF | 11)
+#define PC12_PF_USBOTG_RXDM	(GPIO_PORTC | GPIO_PF | 12)
+#define PC13_PF_USBOTG_RXDP	(GPIO_PORTC | GPIO_PF | 13)
+#define PC16_PF_SAP_FS		(GPIO_PORTC | GPIO_PF | 16)
+#define PC17_PF_SAP_RXD		(GPIO_PORTC | GPIO_PF | 17)
+#define PC18_PF_SAP_TXD		(GPIO_PORTC | GPIO_PF | 18)
+#define PC19_PF_SAP_CLK		(GPIO_PORTC | GPIO_PF | 19)
+#define PE0_PF_TEST_WB2		(GPIO_PORTE | GPIO_PF | 0)
+#define PE1_PF_TEST_WB1		(GPIO_PORTE | GPIO_PF | 1)
+#define PE2_PF_TEST_WB0		(GPIO_PORTE | GPIO_PF | 2)
+#define PF1_PF_NFCE		(GPIO_PORTF | GPIO_PF | 1)
+#define PF3_PF_NFCLE		(GPIO_PORTF | GPIO_PF | 3)
+#define PF7_PF_NFIO0		(GPIO_PORTF | GPIO_PF | 7)
+#define PF8_PF_NFIO1		(GPIO_PORTF | GPIO_PF | 8)
+#define PF9_PF_NFIO2		(GPIO_PORTF | GPIO_PF | 9)
+#define PF10_PF_NFIO3		(GPIO_PORTF | GPIO_PF | 10)
+#define PF11_PF_NFIO4		(GPIO_PORTF | GPIO_PF | 11)
+#define PF12_PF_NFIO5		(GPIO_PORTF | GPIO_PF | 12)
+#define PF13_PF_NFIO6		(GPIO_PORTF | GPIO_PF | 13)
+#define PF14_PF_NFIO7		(GPIO_PORTF | GPIO_PF | 14)
+#define PF16_PF_RES		(GPIO_PORTF | GPIO_PF | 16)
+
+/* Alternate GPIO pin functions */
+
+#define PA5_AF_BMI_CLK_CS	(GPIO_PORTA | GPIO_AF | 5)
+#define PA6_AF_BMI_D0		(GPIO_PORTA | GPIO_AF | 6)
+#define PA7_AF_BMI_D1		(GPIO_PORTA | GPIO_AF | 7)
+#define PA8_AF_BMI_D2		(GPIO_PORTA | GPIO_AF | 8)
+#define PA9_AF_BMI_D3		(GPIO_PORTA | GPIO_AF | 9)
+#define PA10_AF_BMI_D4		(GPIO_PORTA | GPIO_AF | 10)
+#define PA11_AF_BMI_D5		(GPIO_PORTA | GPIO_AF | 11)
+#define PA12_AF_BMI_D6		(GPIO_PORTA | GPIO_AF | 12)
+#define PA13_AF_BMI_D7		(GPIO_PORTA | GPIO_AF | 13)
+#define PA14_AF_BMI_D8		(GPIO_PORTA | GPIO_AF | 14)
+#define PA15_AF_BMI_D9		(GPIO_PORTA | GPIO_AF | 15)
+#define PA16_AF_BMI_D10		(GPIO_PORTA | GPIO_AF | 16)
+#define PA17_AF_BMI_D11		(GPIO_PORTA | GPIO_AF | 17)
+#define PA18_AF_BMI_D12		(GPIO_PORTA | GPIO_AF | 18)
+#define PA19_AF_BMI_D13		(GPIO_PORTA | GPIO_AF | 19)
+#define PA20_AF_BMI_D14		(GPIO_PORTA | GPIO_AF | 20)
+#define PA21_AF_BMI_D15		(GPIO_PORTA | GPIO_AF | 21)
+#define PA22_AF_BMI_READ_REQ	(GPIO_PORTA | GPIO_AF | 22)
+#define PA23_AF_BMI_WRITE	(GPIO_PORTA | GPIO_AF | 23)
+#define PA29_AF_BMI_RX_FULL	(GPIO_PORTA | GPIO_AF | 29)
+#define PA30_AF_BMI_READ	(GPIO_PORTA | GPIO_AF | 30)
+
+/* AIN GPIO pin functions */
+
+#define PC14_AIN_SYS_CLK	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 14)
+#define PD21_AIN_USBH2_FS	(GPIO_PORTD | GPIO_AIN | GPIO_OUT | 21)
+#define PD22_AIN_USBH2_OE	(GPIO_PORTD | GPIO_AIN | GPIO_OUT | 22)
+#define PD23_AIN_USBH2_TXDM	(GPIO_PORTD | GPIO_AIN | GPIO_OUT | 23)
+#define PD24_AIN_USBH2_TXDP	(GPIO_PORTD | GPIO_AIN | GPIO_OUT | 24)
+#define PE8_AIN_IR_TXD		(GPIO_PORTE | GPIO_AIN | GPIO_OUT | 8)
+#define PF0_AIN_PC_RST		(GPIO_PORTF | GPIO_AIN | GPIO_OUT | 0)
+#define PF1_AIN_PC_CE1		(GPIO_PORTF | GPIO_AIN | GPIO_OUT | 1)
+#define PF2_AIN_PC_CE2		(GPIO_PORTF | GPIO_AIN | GPIO_OUT | 2)
+#define PF3_AIN_PC_POE		(GPIO_PORTF | GPIO_AIN | GPIO_OUT | 3)
+#define PF4_AIN_PC_OE		(GPIO_PORTF | GPIO_AIN | GPIO_OUT | 4)
+#define PF5_AIN_PC_RW		(GPIO_PORTF | GPIO_AIN | GPIO_OUT | 5)
+
+/* BIN GPIO pin functions */
+
+#define PC14_BIN_SYS_CLK	(GPIO_PORTC | GPIO_BIN | GPIO_OUT | 14)
+#define PD27_BIN_EXT_DMA_GRANT	(GPIO_PORTD | GPIO_BIN | GPIO_OUT | 27)
+
+/* CIN GPIO pin functions */
+
+#define PB26_CIN_USBH1_RXDAT	(GPIO_PORTB | GPIO_CIN | GPIO_OUT | 26)
+
+/* AOUT GPIO pin functions */
+
+#define PA29_AOUT_BMI_WAIT	(GPIO_PORTA | GPIO_AOUT | GPIO_IN | 29)
+#define PD19_AOUT_USBH2_RXDM	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 19)
+#define PD20_AOUT_USBH2_RXDP	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 20)
+#define PD25_AOUT_EXT_DMAREQ	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 25)
+#define PD26_AOUT_USBOTG_RXDAT	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 26)
+#define PE9_AOUT_IR_RXD		(GPIO_PORTE | GPIO_AOUT | GPIO_IN | 9)
+#define PF6_AOUT_PC_BVD2	(GPIO_PORTF | GPIO_AOUT | GPIO_IN | 6)
+#define PF7_AOUT_PC_BVD1	(GPIO_PORTF | GPIO_AOUT | GPIO_IN | 7)
+#define PF8_AOUT_PC_VS2		(GPIO_PORTF | GPIO_AOUT | GPIO_IN | 8)
+#define PF9_AOUT_PC_VS1		(GPIO_PORTF | GPIO_AOUT | GPIO_IN | 9)
+#define PF10_AOUT_PC_WP		(GPIO_PORTF | GPIO_AOUT | GPIO_IN | 10)
+#define PF11_AOUT_PC_READY	(GPIO_PORTF | GPIO_AOUT | GPIO_IN | 11)
+#define PF12_AOUT_PC_WAIT	(GPIO_PORTF | GPIO_AOUT | GPIO_IN | 12)
+#define PF13_AOUT_PC_CD2	(GPIO_PORTF | GPIO_AOUT | GPIO_IN | 13)
+#define PF14_AOUT_PC_CD1	(GPIO_PORTF | GPIO_AOUT | GPIO_IN | 14)
+
+#endif /* ifndef __MACH_IOMUX_MX21_H__ */
diff --git a/arch/arm/mach-imx/include/mach/iomux-mx27.h b/arch/arm/mach-imx/include/mach/iomux-mx27.h
new file mode 100644
index 0000000..993b141
--- /dev/null
+++ b/arch/arm/mach-imx/include/mach/iomux-mx27.h
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2008 by Sascha Hauer <kernel at pengutronix.de>
+ * Copyright (C) 2009 by Holger Schurig <hs4233 at mail.mn-solutions.de>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+#ifndef __MACH_IOMUX_MX27_H__
+#define __MACH_IOMUX_MX27_H__
+
+#include <mach/iomux-mx2x.h>
+
+/* Primary GPIO pin functions */
+
+#define PA0_PF_USBH2_CLK	(GPIO_PORTA | GPIO_PF | 0)
+#define PA1_PF_USBH2_DIR	(GPIO_PORTA | GPIO_PF | 1)
+#define PA2_PF_USBH2_DATA7	(GPIO_PORTA | GPIO_PF | 2)
+#define PA3_PF_USBH2_NXT	(GPIO_PORTA | GPIO_PF | 3)
+#define PA4_PF_USBH2_STP	(GPIO_PORTA | GPIO_PF | 4)
+#define PB22_PF_USBH1_SUSP	(GPIO_PORTB | GPIO_PF | 22)
+#define PB25_PF_USBH1_RCV	(GPIO_PORTB | GPIO_PF | 25)
+#define PC5_PF_I2C2_SDA		(GPIO_PORTC | GPIO_PF | GPIO_IN | 5)
+#define PC6_PF_I2C2_SCL		(GPIO_PORTC | GPIO_PF | GPIO_IN | 6)
+#define PC7_PF_USBOTG_DATA5	(GPIO_PORTC | GPIO_PF | GPIO_OUT | 7)
+#define PC8_PF_USBOTG_DATA6	(GPIO_PORTC | GPIO_PF | GPIO_OUT | 8)
+#define PC9_PF_USBOTG_DATA0	(GPIO_PORTC | GPIO_PF | GPIO_OUT | 9)
+#define PC10_PF_USBOTG_DATA2	(GPIO_PORTC | GPIO_PF | GPIO_OUT | 10)
+#define PC11_PF_USBOTG_DATA1	(GPIO_PORTC | GPIO_PF | GPIO_OUT | 11)
+#define PC12_PF_USBOTG_DATA4	(GPIO_PORTC | GPIO_PF | GPIO_OUT | 12)
+#define PC13_PF_USBOTG_DATA3	(GPIO_PORTC | GPIO_PF | GPIO_OUT | 13)
+#define PC16_PF_SSI4_FS		(GPIO_PORTC | GPIO_PF | GPIO_IN | 16)
+#define PC17_PF_SSI4_RXD	(GPIO_PORTC | GPIO_PF | GPIO_IN | 17)
+#define PC18_PF_SSI4_TXD	(GPIO_PORTC | GPIO_PF | GPIO_IN | 18)
+#define PC19_PF_SSI4_CLK	(GPIO_PORTC | GPIO_PF | GPIO_IN | 19)
+#define PD0_PF_SD3_CMD		(GPIO_PORTD | GPIO_PF | 0)
+#define PD1_PF_SD3_CLK		(GPIO_PORTD | GPIO_PF | 1)
+#define PD2_PF_ATA_DATA0	(GPIO_PORTD | GPIO_PF | 2)
+#define PD3_PF_ATA_DATA1	(GPIO_PORTD | GPIO_PF | 3)
+#define PD4_PF_ATA_DATA2	(GPIO_PORTD | GPIO_PF | 4)
+#define PD5_PF_ATA_DATA3	(GPIO_PORTD | GPIO_PF | 5)
+#define PD6_PF_ATA_DATA4	(GPIO_PORTD | GPIO_PF | 6)
+#define PD7_PF_ATA_DATA5	(GPIO_PORTD | GPIO_PF | 7)
+#define PD8_PF_ATA_DATA6	(GPIO_PORTD | GPIO_PF | 8)
+#define PD9_PF_ATA_DATA7	(GPIO_PORTD | GPIO_PF | 9)
+#define PD10_PF_ATA_DATA8	(GPIO_PORTD | GPIO_PF | 10)
+#define PD11_PF_ATA_DATA9	(GPIO_PORTD | GPIO_PF | 11)
+#define PD12_PF_ATA_DATA10	(GPIO_PORTD | GPIO_PF | 12)
+#define PD13_PF_ATA_DATA11	(GPIO_PORTD | GPIO_PF | 13)
+#define PD14_PF_ATA_DATA12	(GPIO_PORTD | GPIO_PF | 14)
+#define PD15_PF_ATA_DATA13	(GPIO_PORTD | GPIO_PF | 15)
+#define PD16_PF_ATA_DATA14	(GPIO_PORTD | GPIO_PF | 16)
+#define PE0_PF_USBOTG_NXT	(GPIO_PORTE | GPIO_PF | GPIO_OUT | 0)
+#define PE1_PF_USBOTG_STP	(GPIO_PORTE | GPIO_PF | GPIO_OUT | 1)
+#define PE2_PF_USBOTG_DIR	(GPIO_PORTE | GPIO_PF | GPIO_OUT | 2)
+#define PE24_PF_USBOTG_CLK	(GPIO_PORTE | GPIO_PF | GPIO_OUT | 24)
+#define PE25_PF_USBOTG_DATA7	(GPIO_PORTE | GPIO_PF | GPIO_OUT | 25)
+#define PF1_PF_NFCLE		(GPIO_PORTF | GPIO_PF | 1)
+#define PF3_PF_NFCE		(GPIO_PORTF | GPIO_PF | 3)
+#define PF7_PF_PC_POE		(GPIO_PORTF | GPIO_PF | 7)
+#define PF8_PF_PC_RW		(GPIO_PORTF | GPIO_PF | 8)
+#define PF9_PF_PC_IOIS16	(GPIO_PORTF | GPIO_PF | 9)
+#define PF10_PF_PC_RST		(GPIO_PORTF | GPIO_PF | 10)
+#define PF11_PF_PC_BVD2		(GPIO_PORTF | GPIO_PF | 11)
+#define PF12_PF_PC_BVD1		(GPIO_PORTF | GPIO_PF | 12)
+#define PF13_PF_PC_VS2		(GPIO_PORTF | GPIO_PF | 13)
+#define PF14_PF_PC_VS1		(GPIO_PORTF | GPIO_PF | 14)
+#define PF16_PF_PC_PWRON	(GPIO_PORTF | GPIO_PF | 16)
+#define PF17_PF_PC_READY	(GPIO_PORTF | GPIO_PF | 17)
+#define PF18_PF_PC_WAIT		(GPIO_PORTF | GPIO_PF | 18)
+#define PF19_PF_PC_CD2		(GPIO_PORTF | GPIO_PF | 19)
+#define PF20_PF_PC_CD1		(GPIO_PORTF | GPIO_PF | 20)
+#define PF23_PF_ATA_DATA15	(GPIO_PORTF | GPIO_PF | 23)
+
+/* Alternate GPIO pin functions */
+
+#define PB4_AF_MSHC_DATA0	(GPIO_PORTB | GPIO_AF | GPIO_OUT | 4)
+#define PB5_AF_MSHC_DATA1	(GPIO_PORTB | GPIO_AF | GPIO_OUT | 5)
+#define PB6_AF_MSHC_DATA2	(GPIO_PORTB | GPIO_AF | GPIO_OUT | 6)
+#define PB7_AF_MSHC_DATA4	(GPIO_PORTB | GPIO_AF | GPIO_OUT | 7)
+#define PB8_AF_MSHC_BS		(GPIO_PORTB | GPIO_AF | GPIO_OUT | 8)
+#define PB9_AF_MSHC_SCLK	(GPIO_PORTB | GPIO_AF | GPIO_OUT | 9)
+#define PB10_AF_UART6_TXD	(GPIO_PORTB | GPIO_AF | GPIO_OUT | 10)
+#define PB11_AF_UART6_RXD	(GPIO_PORTB | GPIO_AF | GPIO_IN | 11)
+#define PB12_AF_UART6_CTS	(GPIO_PORTB | GPIO_AF | GPIO_OUT | 12)
+#define PB13_AF_UART6_RTS	(GPIO_PORTB | GPIO_AF | GPIO_IN | 13)
+#define PB18_AF_UART5_TXD	(GPIO_PORTB | GPIO_AF | GPIO_OUT | 18)
+#define PB19_AF_UART5_RXD	(GPIO_PORTB | GPIO_AF | GPIO_IN | 19)
+#define PB20_AF_UART5_CTS	(GPIO_PORTB | GPIO_AF | GPIO_OUT | 20)
+#define PB21_AF_UART5_RTS	(GPIO_PORTB | GPIO_AF | GPIO_IN | 21)
+#define PC8_AF_FEC_MDIO		(GPIO_PORTC | GPIO_AF | GPIO_IN | 8)
+#define PC24_AF_GPT5_TOUT	(GPIO_PORTC | GPIO_AF | 24)
+#define PC25_AF_GPT5_TIN	(GPIO_PORTC | GPIO_AF | 25)
+#define PC26_AF_GPT4_TOUT	(GPIO_PORTC | GPIO_AF | 26)
+#define PC27_AF_GPT4_TIN	(GPIO_PORTC | GPIO_AF | 27)
+#define PD1_AF_ETMTRACE_PKT15	(GPIO_PORTD | GPIO_AF | 1)
+#define PD6_AF_ETMTRACE_PKT14	(GPIO_PORTD | GPIO_AF | 6)
+#define PD7_AF_ETMTRACE_PKT13	(GPIO_PORTD | GPIO_AF | 7)
+#define PD9_AF_ETMTRACE_PKT12	(GPIO_PORTD | GPIO_AF | 9)
+#define PD2_AF_SD3_D0		(GPIO_PORTD | GPIO_AF | 2)
+#define PD3_AF_SD3_D1		(GPIO_PORTD | GPIO_AF | 3)
+#define PD4_AF_SD3_D2		(GPIO_PORTD | GPIO_AF | 4)
+#define PD5_AF_SD3_D3		(GPIO_PORTD | GPIO_AF | 5)
+#define PD8_AF_FEC_MDIO		(GPIO_PORTD | GPIO_AF | GPIO_IN | 8)
+#define PD10_AF_ETMTRACE_PKT11	(GPIO_PORTD | GPIO_AF | 10)
+#define PD11_AF_ETMTRACE_PKT10	(GPIO_PORTD | GPIO_AF | 11)
+#define PD12_AF_ETMTRACE_PKT9	(GPIO_PORTD | GPIO_AF | 12)
+#define PD13_AF_ETMTRACE_PKT8	(GPIO_PORTD | GPIO_AF | 13)
+#define PD14_AF_ETMTRACE_PKT7	(GPIO_PORTD | GPIO_AF | 14)
+#define PD15_AF_ETMTRACE_PKT6	(GPIO_PORTD | GPIO_AF | 15)
+#define PD16_AF_ETMTRACE_PKT5	(GPIO_PORTD | GPIO_AF | 16)
+#define PF1_AF_ETMTRACE_PKT0	(GPIO_PORTF | GPIO_AF | 1)
+#define PF3_AF_ETMTRACE_PKT2	(GPIO_PORTF | GPIO_AF | 3)
+#define PF5_AF_ETMPIPESTAT11	(GPIO_PORTF | GPIO_AF | 5)
+#define PF7_AF_ATA_BUFFER_EN	(GPIO_PORTF | GPIO_AF | 7)
+#define PF8_AF_ATA_IORDY	(GPIO_PORTF | GPIO_AF | 8)
+#define PF9_AF_ATA_INTRQ	(GPIO_PORTF | GPIO_AF | 9)
+#define PF10_AF_ATA_RESET	(GPIO_PORTF | GPIO_AF | 10)
+#define PF11_AF_ATA_DMACK	(GPIO_PORTF | GPIO_AF | 11)
+#define PF12_AF_ATA_DMAREQ	(GPIO_PORTF | GPIO_AF | 12)
+#define PF13_AF_ATA_DA0		(GPIO_PORTF | GPIO_AF | 13)
+#define PF14_AF_ATA_DA1		(GPIO_PORTF | GPIO_AF | 14)
+#define PF15_AF_ETMTRACE_SYNC	(GPIO_PORTF | GPIO_AF | 15)
+#define PF16_AF_ATA_DA2		(GPIO_PORTF | GPIO_AF | 16)
+#define PF17_AF_ATA_CS0		(GPIO_PORTF | GPIO_AF | 17)
+#define PF18_AF_ATA_CS1		(GPIO_PORTF | GPIO_AF | 18)
+#define PF19_AF_ATA_DIOW	(GPIO_PORTF | GPIO_AF | 19)
+#define PF20_AF_ATA_DIOR	(GPIO_PORTF | GPIO_AF | 20)
+#define PF22_AF_ETMTRACE_CLK	(GPIO_PORTF | GPIO_AF | 22)
+#define PF23_AF_ETMTRACE_PKT4	(GPIO_PORTF | GPIO_AF | 23)
+
+/* AIN GPIO pin functions */
+
+#define PC14_AIN_SSI1_MCLK	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 14)
+#define PC15_AIN_GPT6_TOUT	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 15)
+#define PD0_AIN_FEC_TXD0	(GPIO_PORTD | GPIO_AIN | GPIO_OUT | 0)
+#define PD1_AIN_FEC_TXD1	(GPIO_PORTD | GPIO_AIN | GPIO_OUT | 1)
+#define PD2_AIN_FEC_TXD2	(GPIO_PORTD | GPIO_AIN | GPIO_OUT | 2)
+#define PD3_AIN_FEC_TXD3	(GPIO_PORTD | GPIO_AIN | GPIO_OUT | 3)
+#define PD9_AIN_FEC_MDC		(GPIO_PORTD | GPIO_AIN | GPIO_OUT | 9)
+#define PD16_AIN_FEC_TX_ER	(GPIO_PORTD | GPIO_AIN | GPIO_OUT | 16)
+#define PD27_AIN_EXT_DMA_GRANT	(GPIO_PORTD | GPIO_AIN | GPIO_OUT | 27)
+#define PF23_AIN_FEC_TX_EN	(GPIO_PORTF | GPIO_AIN | GPIO_OUT | 23)
+
+/* BIN GPIO pin functions */
+
+#define PC14_BIN_SSI2_MCLK	(GPIO_PORTC | GPIO_BIN | GPIO_OUT | 14)
+
+/* CIN GPIO pin functions */
+
+#define PD2_CIN_SLCDC1_DAT0	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 2)
+#define PD3_CIN_SLCDC1_DAT1	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 3)
+#define PD4_CIN_SLCDC1_DAT2	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 4)
+#define PD5_CIN_SLCDC1_DAT3	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 5)
+#define PD6_CIN_SLCDC1_DAT4	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 6)
+#define PD7_CIN_SLCDC1_DAT5	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 7)
+#define PD8_CIN_SLCDC1_DAT6	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 8)
+#define PD9_CIN_SLCDC1_DAT7	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 9)
+#define PD10_CIN_SLCDC1_DAT8	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 10)
+#define PD11_CIN_SLCDC1_DAT9	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 11)
+#define PD12_CIN_SLCDC1_DAT10	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 12)
+#define PD13_CIN_SLCDC1_DAT11	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 13)
+#define PD14_CIN_SLCDC1_DAT12	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 14)
+#define PD15_CIN_SLCDC1_DAT13	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 15)
+#define PD16_CIN_SLCDC1_DAT14	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 16)
+#define PD23_CIN_SLCDC1_DAT15	(GPIO_PORTD | GPIO_CIN | GPIO_OUT | 23)
+#define PF27_CIN_EXT_DMA_GRANT	(GPIO_PORTF | GPIO_CIN | GPIO_OUT | 27)
+/* LCDC_TESTx on PBxx omitted, because it's not clear what they do */
+
+/* AOUT GPIO pin functions */
+
+#define PC14_AOUT_GPT6_TIN	(GPIO_PORTC | GPIO_AOUT | GPIO_IN | 14)
+#define PD4_AOUT_FEC_RX_ER	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 4)
+#define PD5_AOUT_FEC_RXD1	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 5)
+#define PD6_AOUT_FEC_RXD2	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 6)
+#define PD7_AOUT_FEC_RXD3	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 7)
+#define PD10_AOUT_FEC_CRS	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 10)
+#define PD11_AOUT_FEC_TX_CLK	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 11)
+#define PD12_AOUT_FEC_RXD0	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 12)
+#define PD13_AOUT_FEC_RX_DV	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 13)
+#define PD14_AOUT_FEC_RX_CLK	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 14)
+#define PD15_AOUT_FEC_COL	(GPIO_PORTD | GPIO_AOUT | GPIO_IN | 15)
+
+/* BOUT GPIO pin functions */
+
+#define PC17_BOUT_PC_IOIS16	(GPIO_PORTC | GPIO_BOUT | GPIO_IN | 17)
+#define PC18_BOUT_PC_BVD2	(GPIO_PORTC | GPIO_BOUT | GPIO_IN | 18)
+#define PC19_BOUT_PC_BVD1	(GPIO_PORTC | GPIO_BOUT | GPIO_IN | 19)
+#define PC28_BOUT_PC_BVD2	(GPIO_PORTC | GPIO_BOUT | GPIO_IN | 28)
+#define PC29_BOUT_PC_VS1	(GPIO_PORTC | GPIO_BOUT | GPIO_IN | 29)
+#define PC30_BOUT_PC_READY	(GPIO_PORTC | GPIO_BOUT | GPIO_IN | 30)
+#define PC31_BOUT_PC_WAIT	(GPIO_PORTC | GPIO_BOUT | GPIO_IN | 31)
+
+#endif /* __MACH_IOMUX_MX27_H__ */
diff --git a/arch/arm/mach-imx/include/mach/iomux-mx2x.h b/arch/arm/mach-imx/include/mach/iomux-mx2x.h
new file mode 100644
index 0000000..c4f116d
--- /dev/null
+++ b/arch/arm/mach-imx/include/mach/iomux-mx2x.h
@@ -0,0 +1,230 @@
+/*
+ * Copyright (C) 2008 by Sascha Hauer <kernel at pengutronix.de>
+ * Copyright (C) 2009 by Holger Schurig <hs4233 at mail.mn-solutions.de>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+#ifndef __MACH_IOMUX_MX2x_H__
+#define __MACH_IOMUX_MX2x_H__
+
+/* Primary GPIO pin functions */
+
+#define PA5_PF_LSCLK		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 5)
+#define PA6_PF_LD0		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 6)
+#define PA7_PF_LD1		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 7)
+#define PA8_PF_LD2		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 8)
+#define PA9_PF_LD3		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 9)
+#define PA10_PF_LD4		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 10)
+#define PA11_PF_LD5		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 11)
+#define PA12_PF_LD6		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 12)
+#define PA13_PF_LD7		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 13)
+#define PA14_PF_LD8		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 14)
+#define PA15_PF_LD9		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 15)
+#define PA16_PF_LD10		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 16)
+#define PA17_PF_LD11		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 17)
+#define PA18_PF_LD12		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 18)
+#define PA19_PF_LD13		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 19)
+#define PA20_PF_LD14		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 20)
+#define PA21_PF_LD15		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 21)
+#define PA22_PF_LD16		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 22)
+#define PA23_PF_LD17		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 23)
+#define PA24_PF_REV		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 24)
+#define PA25_PF_CLS		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 25)
+#define PA26_PF_PS		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 26)
+#define PA27_PF_SPL_SPR		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 27)
+#define PA28_PF_HSYNC		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 28)
+#define PA29_PF_VSYNC		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 29)
+#define PA30_PF_CONTRAST	(GPIO_PORTA | GPIO_PF | GPIO_OUT | 30)
+#define PA31_PF_OE_ACD		(GPIO_PORTA | GPIO_PF | GPIO_OUT | 31)
+#define PB4_PF_SD2_D0		(GPIO_PORTB | GPIO_PF | 4)
+#define PB5_PF_SD2_D1		(GPIO_PORTB | GPIO_PF | 5)
+#define PB6_PF_SD2_D2		(GPIO_PORTB | GPIO_PF | 6)
+#define PB7_PF_SD2_D3		(GPIO_PORTB | GPIO_PF | 7)
+#define PB8_PF_SD2_CMD		(GPIO_PORTB | GPIO_PF | 8)
+#define PB9_PF_SD2_CLK		(GPIO_PORTB | GPIO_PF | 9)
+#define PB10_PF_CSI_D0		(GPIO_PORTB | GPIO_PF | GPIO_OUT | 10)
+#define PB11_PF_CSI_D1		(GPIO_PORTB | GPIO_PF | GPIO_OUT | 11)
+#define PB12_PF_CSI_D2		(GPIO_PORTB | GPIO_PF | GPIO_OUT | 12)
+#define PB13_PF_CSI_D3		(GPIO_PORTB | GPIO_PF | GPIO_OUT | 13)
+#define PB14_PF_CSI_D4		(GPIO_PORTB | GPIO_PF | GPIO_OUT | 14)
+#define PB15_PF_CSI_MCLK	(GPIO_PORTB | GPIO_PF | GPIO_OUT | 15)
+#define PB16_PF_CSI_PIXCLK	(GPIO_PORTB | GPIO_PF | GPIO_OUT | 16)
+#define PB17_PF_CSI_D5		(GPIO_PORTB | GPIO_PF | GPIO_OUT | 17)
+#define PB18_PF_CSI_D6		(GPIO_PORTB | GPIO_PF | GPIO_OUT | 18)
+#define PB19_PF_CSI_D7		(GPIO_PORTB | GPIO_PF | GPIO_OUT | 19)
+#define PB20_PF_CSI_VSYNC	(GPIO_PORTB | GPIO_PF | GPIO_OUT | 20)
+#define PB21_PF_CSI_HSYNC	(GPIO_PORTB | GPIO_PF | GPIO_OUT | 21)
+#define PB23_PF_USB_PWR		(GPIO_PORTB | GPIO_PF | 23)
+#define PB24_PF_USB_OC		(GPIO_PORTB | GPIO_PF | 24)
+#define PB26_PF_USBH1_FS	(GPIO_PORTB | GPIO_PF | 26)
+#define PB27_PF_USBH1_OE	(GPIO_PORTB | GPIO_PF | 27)
+#define PB28_PF_USBH1_TXDM	(GPIO_PORTB | GPIO_PF | 28)
+#define PB29_PF_USBH1_TXDP	(GPIO_PORTB | GPIO_PF | 29)
+#define PB30_PF_USBH1_RXDM	(GPIO_PORTB | GPIO_PF | 30)
+#define PB31_PF_USBH1_RXDP	(GPIO_PORTB | GPIO_PF | 31)
+#define PC14_PF_TOUT		(GPIO_PORTC | GPIO_PF | 14)
+#define PC15_PF_TIN		(GPIO_PORTC | GPIO_PF | 15)
+#define PC20_PF_SSI1_FS		(GPIO_PORTC | GPIO_PF | GPIO_IN | 20)
+#define PC21_PF_SSI1_RXD	(GPIO_PORTC | GPIO_PF | GPIO_IN | 21)
+#define PC22_PF_SSI1_TXD	(GPIO_PORTC | GPIO_PF | GPIO_IN | 22)
+#define PC23_PF_SSI1_CLK	(GPIO_PORTC | GPIO_PF | GPIO_IN | 23)
+#define PC24_PF_SSI2_FS		(GPIO_PORTC | GPIO_PF | GPIO_IN | 24)
+#define PC25_PF_SSI2_RXD	(GPIO_PORTC | GPIO_PF | GPIO_IN | 25)
+#define PC26_PF_SSI2_TXD	(GPIO_PORTC | GPIO_PF | GPIO_IN | 26)
+#define PC27_PF_SSI2_CLK	(GPIO_PORTC | GPIO_PF | GPIO_IN | 27)
+#define PC28_PF_SSI3_FS		(GPIO_PORTC | GPIO_PF | GPIO_IN | 28)
+#define PC29_PF_SSI3_RXD	(GPIO_PORTC | GPIO_PF | GPIO_IN | 29)
+#define PC30_PF_SSI3_TXD	(GPIO_PORTC | GPIO_PF | GPIO_IN | 30)
+#define PC31_PF_SSI3_CLK	(GPIO_PORTC | GPIO_PF | GPIO_IN | 31)
+#define PD17_PF_I2C_DATA	(GPIO_PORTD | GPIO_PF | GPIO_OUT | 17)
+#define PD18_PF_I2C_CLK		(GPIO_PORTD | GPIO_PF | GPIO_OUT | 18)
+#define PD19_PF_CSPI2_SS2	(GPIO_PORTD | GPIO_PF | 19)
+#define PD20_PF_CSPI2_SS1	(GPIO_PORTD | GPIO_PF | 20)
+#define PD21_PF_CSPI2_SS0	(GPIO_PORTD | GPIO_PF | 21)
+#define PD22_PF_CSPI2_SCLK	(GPIO_PORTD | GPIO_PF | 22)
+#define PD23_PF_CSPI2_MISO	(GPIO_PORTD | GPIO_PF | 23)
+#define PD24_PF_CSPI2_MOSI	(GPIO_PORTD | GPIO_PF | 24)
+#define PD25_PF_CSPI1_RDY	(GPIO_PORTD | GPIO_PF | GPIO_OUT | 25)
+#define PD26_PF_CSPI1_SS2	(GPIO_PORTD | GPIO_PF | GPIO_OUT | 26)
+#define PD27_PF_CSPI1_SS1	(GPIO_PORTD | GPIO_PF | GPIO_OUT | 27)
+#define PD28_PF_CSPI1_SS0	(GPIO_PORTD | GPIO_PF | GPIO_OUT | 28)
+#define PD29_PF_CSPI1_SCLK	(GPIO_PORTD | GPIO_PF | GPIO_OUT | 29)
+#define PD30_PF_CSPI1_MISO	(GPIO_PORTD | GPIO_PF | GPIO_IN | 30)
+#define PD31_PF_CSPI1_MOSI	(GPIO_PORTD | GPIO_PF | GPIO_OUT | 31)
+#define PE3_PF_UART2_CTS	(GPIO_PORTE | GPIO_PF | GPIO_OUT | 3)
+#define PE4_PF_UART2_RTS	(GPIO_PORTE | GPIO_PF | GPIO_IN | 4)
+#define PE5_PF_PWMO		(GPIO_PORTE | GPIO_PF | 5)
+#define PE6_PF_UART2_TXD	(GPIO_PORTE | GPIO_PF | GPIO_OUT | 6)
+#define PE7_PF_UART2_RXD	(GPIO_PORTE | GPIO_PF | GPIO_IN | 7)
+#define PE8_PF_UART3_TXD	(GPIO_PORTE | GPIO_PF | GPIO_OUT | 8)
+#define PE9_PF_UART3_RXD	(GPIO_PORTE | GPIO_PF | GPIO_IN | 9)
+#define PE10_PF_UART3_CTS	(GPIO_PORTE | GPIO_PF | GPIO_OUT | 10)
+#define PE11_PF_UART3_RTS	(GPIO_PORTE | GPIO_PF | GPIO_IN | 11)
+#define PE12_PF_UART1_TXD	(GPIO_PORTE | GPIO_PF | GPIO_OUT | 12)
+#define PE13_PF_UART1_RXD	(GPIO_PORTE | GPIO_PF | GPIO_IN | 13)
+#define PE14_PF_UART1_CTS	(GPIO_PORTE | GPIO_PF | GPIO_OUT | 14)
+#define PE15_PF_UART1_RTS	(GPIO_PORTE | GPIO_PF | GPIO_IN | 15)
+#define PE16_PF_RTCK		(GPIO_PORTE | GPIO_PF | GPIO_OUT | 16)
+#define PE17_PF_RESET_OUT	(GPIO_PORTE | GPIO_PF | 17)
+#define PE18_PF_SD1_D0		(GPIO_PORTE | GPIO_PF | 18)
+#define PE19_PF_SD1_D1		(GPIO_PORTE | GPIO_PF | 19)
+#define PE20_PF_SD1_D2		(GPIO_PORTE | GPIO_PF | 20)
+#define PE21_PF_SD1_D3		(GPIO_PORTE | GPIO_PF | 21)
+#define PE22_PF_SD1_CMD		(GPIO_PORTE | GPIO_PF | 22)
+#define PE23_PF_SD1_CLK		(GPIO_PORTE | GPIO_PF | 23)
+#define PF0_PF_NRFB		(GPIO_PORTF | GPIO_PF | 0)
+#define PF2_PF_NFWP		(GPIO_PORTF | GPIO_PF | 2)
+#define PF4_PF_NFALE		(GPIO_PORTF | GPIO_PF | 4)
+#define PF5_PF_NFRE		(GPIO_PORTF | GPIO_PF | 5)
+#define PF6_PF_NFWE		(GPIO_PORTF | GPIO_PF | 6)
+#define PF15_PF_CLKO		(GPIO_PORTF | GPIO_PF | 15)
+#define PF21_PF_CS4		(GPIO_PORTF | GPIO_PF | 21)
+#define PF22_PF_CS5		(GPIO_PORTF | GPIO_PF | 22)
+
+/* Alternate GPIO pin functions */
+
+#define PB26_AF_UART4_RTS	(GPIO_PORTB | GPIO_AF | GPIO_IN | 26)
+#define PB28_AF_UART4_TXD	(GPIO_PORTB | GPIO_AF | GPIO_OUT | 28)
+#define PB29_AF_UART4_CTS	(GPIO_PORTB | GPIO_AF | GPIO_OUT | 29)
+#define PB31_AF_UART4_RXD	(GPIO_PORTB | GPIO_AF | GPIO_IN | 31)
+#define PC28_AF_SLCDC2_D0	(GPIO_PORTC | GPIO_AF | 28)
+#define PC29_AF_SLCDC2_RS	(GPIO_PORTC | GPIO_AF | 29)
+#define PC30_AF_SLCDC2_CS	(GPIO_PORTC | GPIO_AF | 30)
+#define PC31_AF_SLCDC2_CLK	(GPIO_PORTC | GPIO_AF | 31)
+#define PD19_AF_USBH2_DATA4	(GPIO_PORTD | GPIO_AF | 19)
+#define PD20_AF_USBH2_DATA3	(GPIO_PORTD | GPIO_AF | 20)
+#define PD21_AF_USBH2_DATA6	(GPIO_PORTD | GPIO_AF | 21)
+#define PD22_AF_USBH2_DATA0	(GPIO_PORTD | GPIO_AF | 22)
+#define PD23_AF_USBH2_DATA2	(GPIO_PORTD | GPIO_AF | 23)
+#define PD24_AF_USBH2_DATA1	(GPIO_PORTD | GPIO_AF | 24)
+#define PD26_AF_USBH2_DATA5	(GPIO_PORTD | GPIO_AF | 26)
+#define PE0_AF_KP_COL6		(GPIO_PORTE | GPIO_AF | 0)
+#define PE1_AF_KP_ROW6		(GPIO_PORTE | GPIO_AF | 1)
+#define PE2_AF_KP_ROW7		(GPIO_PORTE | GPIO_AF | 2)
+#define PE3_AF_KP_COL7		(GPIO_PORTE | GPIO_AF | 3)
+#define PE4_AF_KP_ROW7		(GPIO_PORTE | GPIO_AF | 4)
+#define PE6_AF_KP_COL6		(GPIO_PORTE | GPIO_AF | 6)
+#define PE7_AF_KP_ROW6		(GPIO_PORTE | GPIO_AF | 7)
+#define PE16_AF_OWIRE		(GPIO_PORTE | GPIO_AF | 16)
+#define PE18_AF_CSPI3_MISO	(GPIO_PORTE | GPIO_AF | GPIO_IN | 18)
+#define PE21_AF_CSPI3_SS	(GPIO_PORTE | GPIO_AF | GPIO_OUT | 21)
+#define PE22_AF_CSPI3_MOSI	(GPIO_PORTE | GPIO_AF | GPIO_OUT | 22)
+#define PE23_AF_CSPI3_SCLK	(GPIO_PORTE | GPIO_AF | GPIO_OUT | 23)
+
+/* AIN GPIO pin functions */
+
+#define PA6_AIN_SLCDC1_DAT0	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 6)
+#define PA7_AIN_SLCDC1_DAT1	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 7)
+#define PA8_AIN_SLCDC1_DAT2	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 8)
+#define PA0_AIN_SLCDC1_DAT3	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 0)
+#define PA11_AIN_SLCDC1_DAT5	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 11)
+#define PA13_AIN_SLCDC1_DAT7	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 13)
+#define PA15_AIN_SLCDC1_DAT9	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 15)
+#define PA17_AIN_SLCDC1_DAT11	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 17)
+#define PA19_AIN_SLCDC1_DAT13	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 19)
+#define PA21_AIN_SLCDC1_DAT15	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 21)
+#define PA22_AIN_EXT_DMAGRANT	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 22)
+#define PA24_AIN_SLCDC1_D0	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 24)
+#define PA25_AIN_SLCDC1_RS	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 25)
+#define PA26_AIN_SLCDC1_CS	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 26)
+#define PA27_AIN_SLCDC1_CLK	(GPIO_PORTA | GPIO_AIN | GPIO_OUT | 27)
+#define PB6_AIN_SLCDC1_D0	(GPIO_PORTB | GPIO_AIN | GPIO_OUT | 6)
+#define PB7_AIN_SLCDC1_RS	(GPIO_PORTB | GPIO_AIN | GPIO_OUT | 7)
+#define PB8_AIN_SLCDC1_CS	(GPIO_PORTB | GPIO_AIN | GPIO_OUT | 8)
+#define PB9_AIN_SLCDC1_CLK	(GPIO_PORTB | GPIO_AIN | GPIO_OUT | 9)
+#define PB25_AIN_SLCDC1_DAT0	(GPIO_PORTB | GPIO_AIN | GPIO_OUT | 25)
+#define PB26_AIN_SLCDC1_DAT1	(GPIO_PORTB | GPIO_AIN | GPIO_OUT | 26)
+#define PB27_AIN_SLCDC1_DAT2	(GPIO_PORTB | GPIO_AIN | GPIO_OUT | 27)
+#define PB28_AIN_SLCDC1_DAT3	(GPIO_PORTB | GPIO_AIN | GPIO_OUT | 28)
+#define PB29_AIN_SLCDC1_DAT4	(GPIO_PORTB | GPIO_AIN | GPIO_OUT | 29)
+#define PB30_AIN_SLCDC1_DAT5	(GPIO_PORTB | GPIO_AIN | GPIO_OUT | 30)
+#define PB31_AIN_SLCDC1_DAT6	(GPIO_PORTB | GPIO_AIN | GPIO_OUT | 31)
+#define PC5_AIN_SLCDC1_DAT7	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 5)
+#define PC6_AIN_SLCDC1_DAT8	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 6)
+#define PC7_AIN_SLCDC1_DAT9	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 7)
+#define PC8_AIN_SLCDC1_DAT10	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 8)
+#define PC9_AIN_SLCDC1_DAT11	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 9)
+#define PC10_AIN_SLCDC1_DAT12	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 10)
+#define PC11_AIN_SLCDC1_DAT13	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 11)
+#define PC12_AIN_SLCDC1_DAT14	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 12)
+#define PC13_AIN_SLCDC1_DAT15	(GPIO_PORTC | GPIO_AIN | GPIO_OUT | 13)
+#define PE5_AIN_PC_SPKOUT	(GPIO_PORTE | GPIO_AIN | GPIO_OUT | 5)
+
+/* BIN GPIO pin functions */
+
+#define PE5_BIN_TOUT2		(GPIO_PORTE | GPIO_BIN | GPIO_OUT | 5)
+
+/* CIN GPIO pin functions */
+
+#define PA14_CIN_SLCDC1_DAT0	(GPIO_PORTA | GPIO_CIN | GPIO_OUT | 14)
+#define PA15_CIN_SLCDC1_DAT1	(GPIO_PORTA | GPIO_CIN | GPIO_OUT | 15)
+#define PA16_CIN_SLCDC1_DAT2	(GPIO_PORTA | GPIO_CIN | GPIO_OUT | 16)
+#define PA17_CIN_SLCDC1_DAT3	(GPIO_PORTA | GPIO_CIN | GPIO_OUT | 17)
+#define PA18_CIN_SLCDC1_DAT4	(GPIO_PORTA | GPIO_CIN | GPIO_OUT | 18)
+#define PA19_CIN_SLCDC1_DAT5	(GPIO_PORTA | GPIO_CIN | GPIO_OUT | 19)
+#define PA20_CIN_SLCDC1_DAT6	(GPIO_PORTA | GPIO_CIN | GPIO_OUT | 20)
+#define PA21_CIN_SLCDC1_DAT7	(GPIO_PORTA | GPIO_CIN | GPIO_OUT | 21)
+#define PB30_CIN_UART4_CTS	(GPIO_PORTB | GPIO_CIN | GPIO_OUT | 30)
+#define PE5_CIN_TOUT3		(GPIO_PORTE | GPIO_CIN | GPIO_OUT | 5)
+
+/* AOUT GPIO pin functions */
+
+#define PB29_AOUT_UART4_RXD	(GPIO_PORTB | GPIO_AOUT | GPIO_IN | 29)
+#define PB31_AOUT_UART4_RTS	(GPIO_PORTB | GPIO_AOUT | GPIO_IN | 31)
+#define PC8_AOUT_USBOTG_TXR_INT (GPIO_PORTC | GPIO_AOUT | GPIO_IN | 8)
+#define PC15_AOUT_WKGD		(GPIO_PORTC | GPIO_AOUT | GPIO_IN | 15)
+#define PF21_AOUT_DTACK		(GPIO_PORTF | GPIO_AOUT | GPIO_IN | 21)
+
+#endif /* ifndef __MACH_IOMUX_MX2x_H__ */
diff --git a/board/eukrea_cpuimx27/eukrea_cpuimx27.c b/board/eukrea_cpuimx27/eukrea_cpuimx27.c
index e40c260..1937d21 100644
--- a/board/eukrea_cpuimx27/eukrea_cpuimx27.c
+++ b/board/eukrea_cpuimx27/eukrea_cpuimx27.c
@@ -45,6 +45,7 @@
 #include <asm/mmu.h>
 #include <i2c/i2c.h>
 #include <i2c/lp3972.h>
+#include <mach/iomux-mx27.h>
 
 static struct device_d cfi_dev = {
 	.name     = "cfi_flash",
@@ -230,7 +231,7 @@ static int eukrea_cpuimx27_devices_init(void)
 		PD11_AOUT_FEC_TX_CLK,
 		PD12_AOUT_FEC_RXD0,
 		PD13_AOUT_FEC_RX_DV,
-		PD14_AOUT_FEC_CLR,
+		PD14_AOUT_FEC_RX_CLK,
 		PD15_AOUT_FEC_COL,
 		PD16_AIN_FEC_TX_ER,
 		PF23_AIN_FEC_TX_EN,
diff --git a/board/imx21ads/imx21ads.c b/board/imx21ads/imx21ads.c
index 9eba19a..5e88af4 100644
--- a/board/imx21ads/imx21ads.c
+++ b/board/imx21ads/imx21ads.c
@@ -35,6 +35,7 @@
 #include <asm/mach-types.h>
 #include <mach/imx-nand.h>
 #include <mach/imxfb.h>
+#include <mach/iomux-mx21.h>
 
 #define MX21ADS_IO_REG    0xCC800000
 #define MX21ADS_IO_LCDON  (1 << 9)
diff --git a/board/imx27ads/imx27ads.c b/board/imx27ads/imx27ads.c
index 3512ed3..6f31520 100644
--- a/board/imx27ads/imx27ads.c
+++ b/board/imx27ads/imx27ads.c
@@ -31,6 +31,7 @@
 #include <fs.h>
 #include <fcntl.h>
 #include <asm/mach-types.h>
+#include <mach/iomux-mx27.h>
 
 static struct device_d cfi_dev = {
 	.name     = "cfi_flash",
@@ -114,7 +115,7 @@ static int mx27ads_devices_init(void)
 		PD11_AOUT_FEC_TX_CLK,
 		PD12_AOUT_FEC_RXD0,
 		PD13_AOUT_FEC_RX_DV,
-		PD14_AOUT_FEC_CLR,
+		PD14_AOUT_FEC_RX_CLK,
 		PD15_AOUT_FEC_COL,
 		PD16_AIN_FEC_TX_ER,
 		PF23_AIN_FEC_TX_EN,
diff --git a/board/pcm038/pcm038.c b/board/pcm038/pcm038.c
index fbd53a5..03794fc 100644
--- a/board/pcm038/pcm038.c
+++ b/board/pcm038/pcm038.c
@@ -42,6 +42,7 @@
 #include <asm/mmu.h>
 #include <usb/isp1504.h>
 #include <mach/spi.h>
+#include <mach/iomux-mx27.h>
 
 static struct device_d cfi_dev = {
 	.name     = "cfi_flash",
@@ -229,7 +230,7 @@ static int pcm038_devices_init(void)
 		PD11_AOUT_FEC_TX_CLK,
 		PD12_AOUT_FEC_RXD0,
 		PD13_AOUT_FEC_RX_DV,
-		PD14_AOUT_FEC_CLR,
+		PD14_AOUT_FEC_RX_CLK,
 		PD15_AOUT_FEC_COL,
 		PD16_AIN_FEC_TX_ER,
 		PF23_AIN_FEC_TX_EN,
diff --git a/board/phycard-i.MX27/pca100.c b/board/phycard-i.MX27/pca100.c
index 2fb1e35..ce59960 100644
--- a/board/phycard-i.MX27/pca100.c
+++ b/board/phycard-i.MX27/pca100.c
@@ -38,6 +38,7 @@
 #include <gpio.h>
 #include <asm/mmu.h>
 #include <usb/isp1504.h>
+#include <mach/iomux-mx27.h>
 
 static struct memory_platform_data ram_pdata = {
 	.name = "ram0",
@@ -147,7 +148,7 @@ static int pca100_devices_init(void)
 		PD11_AOUT_FEC_TX_CLK,
 		PD12_AOUT_FEC_RXD0,
 		PD13_AOUT_FEC_RX_DV,
-		PD14_AOUT_FEC_CLR,
+		PD14_AOUT_FEC_RX_CLK,
 		PD15_AOUT_FEC_COL,
 		PD16_AIN_FEC_TX_ER,
 		PF23_AIN_FEC_TX_EN,
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:45:47 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:45:47 +0200
Subject: [PATCH 2/6] ehci: Handle hub port reset properly
In-Reply-To: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372751-15797-3-git-send-email-s.hauer@pengutronix.de>

This has been copied from the U-Boot ehci driver.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/usb_ehci_core.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/usb_ehci_core.c b/drivers/usb/usb_ehci_core.c
index f3611cd..c5d4da3 100644
--- a/drivers/usb/usb_ehci_core.c
+++ b/drivers/usb/usb_ehci_core.c
@@ -676,6 +676,8 @@ ehci_submit_root(struct usb_device *dev, unsigned long pipe, void *buffer,
 				ehci_writel(status_reg, reg);
 				break;
 			} else {
+				int ret;
+
 				reg |= EHCI_PS_PR;
 				reg &= ~EHCI_PS_PE;
 				ehci_writel(status_reg, reg);
@@ -686,6 +688,22 @@ ehci_submit_root(struct usb_device *dev, unsigned long pipe, void *buffer,
 				 */
 				wait_ms(50);
 				ehci->portreset |= 1 << le16_to_cpu(req->index);
+				/* terminate the reset */
+				ehci_writel(status_reg, reg & ~EHCI_PS_PR);
+				/*
+				 * A host controller must terminate the reset
+				 * and stabilize the state of the port within
+				 * 2 milliseconds
+				 */
+				ret = handshake(status_reg, EHCI_PS_PR, 0,
+						2 * 1000);
+				if (!ret)
+					ehci->portreset |=
+						1 << le16_to_cpu(req->index);
+				else
+					printf("port(%d) reset error\n",
+						le16_to_cpu(req->index) - 1);
+
 			}
 			break;
 		default:
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:45:48 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:45:48 +0200
Subject: [PATCH 3/6] usb: Check return value of host controller init
In-Reply-To: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372751-15797-4-git-send-email-s.hauer@pengutronix.de>

And do not scan the bus if initialization failed.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/usb.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/usb.c b/drivers/usb/usb.c
index 1ad4bab..76e033e 100644
--- a/drivers/usb/usb.c
+++ b/drivers/usb/usb.c
@@ -453,6 +453,7 @@ static int __usb_init(void)
 {
 	struct usb_device *dev, *tmp;
 	struct usb_host *host;
+	int ret;
 
 	list_for_each_entry_safe(dev, tmp, &usb_device_list, list) {
 		list_del(&dev->list);
@@ -466,7 +467,9 @@ static int __usb_init(void)
 	dev_index = 0;
 
 	list_for_each_entry(host, &host_list, list) {
-		host->init(host);
+		ret = host->init(host);
+		if (ret)
+			continue;
 
 		dev = usb_alloc_new_device();
 		dev->host = host;
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:45:51 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:45:51 +0200
Subject: [PATCH 6/6] ehci: remove unused code
In-Reply-To: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372751-15797-7-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/usb_ehci.h      |    4 ----
 drivers/usb/usb_ehci_core.c |    5 -----
 2 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/usb_ehci.h b/drivers/usb/usb_ehci.h
index b3c1d5d..af49249 100644
--- a/drivers/usb/usb_ehci.h
+++ b/drivers/usb/usb_ehci.h
@@ -187,8 +187,4 @@ struct QH {
 	uint8_t fill[16];
 };
 
-/* Low level init functions */
-int ehci_hcd_init(void);
-int ehci_hcd_stop(void);
-
 #endif /* USB_EHCI_H */
diff --git a/drivers/usb/usb_ehci_core.c b/drivers/usb/usb_ehci_core.c
index fe988c3..af066de 100644
--- a/drivers/usb/usb_ehci_core.c
+++ b/drivers/usb/usb_ehci_core.c
@@ -801,11 +801,6 @@ static int ehci_init(struct usb_host *host)
 	if (ehci_reset(ehci) != 0)
 		return -1;
 
-#if defined(CONFIG_EHCI_HCD_INIT_AFTER_RESET)
-	if (ehci_hcd_init() != 0)
-		return -1;
-#endif
-
 	/* Set head of reclaim list */
 	ehci->qhp = xzalloc(sizeof(struct QH) + 32);
 	ehci->qh_list = (struct QH *)(((unsigned long)ehci->qhp + 32) & ~31);
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:45:46 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:45:46 +0200
Subject: [PATCH 1/6] ehci: Make has_tt configurable via platform data
In-Reply-To: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372751-15797-2-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/usb_ehci_core.c |   18 ++++++++++++------
 include/usb/ehci.h          |   10 ++++++++++
 2 files changed, 22 insertions(+), 6 deletions(-)
 create mode 100644 include/usb/ehci.h

diff --git a/drivers/usb/usb_ehci_core.c b/drivers/usb/usb_ehci_core.c
index d7efaad..f3611cd 100644
--- a/drivers/usb/usb_ehci_core.c
+++ b/drivers/usb/usb_ehci_core.c
@@ -31,6 +31,7 @@
 #include <xfuncs.h>
 #include <clock.h>
 #include <errno.h>
+#include <usb/ehci.h>
 #include <asm/mmu.h>
 
 #include "usb_ehci.h"
@@ -43,6 +44,7 @@ struct ehci_priv {
 	struct QH *qh_list;
 	void *qhp;
 	int portreset;
+	unsigned long flags;
 };
 
 #define to_ehci(ptr) container_of(ptr, struct ehci_priv, host)
@@ -112,13 +114,8 @@ static struct descriptor {
 		255		/* bInterval */
 	},
 };
-#define CONFIG_EHCI_IS_TDI // FIXME
 
-#if defined(CONFIG_EHCI_IS_TDI)
-#define ehci_is_TDI()	(1)
-#else
-#define ehci_is_TDI()	(0)
-#endif
+#define ehci_is_TDI()	(ehci->flags & EHCI_HAS_TT)
 
 #ifdef CONFIG_MMU
 /*
@@ -861,10 +858,19 @@ static int ehci_probe(struct device_d *dev)
 	struct usb_host *host;
 	struct ehci_priv *ehci;
 	uint32_t reg;
+	struct ehci_platform_data *pdata = dev->platform_data;
 
 	ehci = xmalloc(sizeof(struct ehci_priv));
 	host = &ehci->host;
 
+	if (pdata)
+		ehci->flags = pdata->flags;
+	else
+		/* default to EHCI_HAS_TT to not change behaviour of boards
+		 * with platform_data
+		 */
+		ehci->flags = EHCI_HAS_TT;
+
 	host->init = ehci_init;
 	host->submit_int_msg = submit_int_msg;
 	host->submit_control_msg = submit_control_msg;
diff --git a/include/usb/ehci.h b/include/usb/ehci.h
new file mode 100644
index 0000000..3304b60
--- /dev/null
+++ b/include/usb/ehci.h
@@ -0,0 +1,10 @@
+#ifndef __USB_EHCI_H
+#define __USB_EHCI_H
+
+#define EHCI_HAS_TT	(1 << 0)
+
+struct ehci_platform_data {
+	unsigned long flags;
+};
+
+#endif  /* __USB_EHCI_H */
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:45:45 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:45:45 +0200
Subject: USB related patches
Message-ID: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>


The following changes since commit 334fe1dc8a1b866d1f0f4ccf82ff7b06589ec022:

  pca100: use generic default env (2010-06-22 15:44:45 +0200)

are available in the git repository at:
  git://git.pengutronix.de/git/barebox.git usb-pu

Sascha Hauer (6):
      ehci: Make has_tt configurable via platform data
      ehci: Handle hub port reset properly
      usb: Check return value of host controller init
      ehci: use is_timeout for timeout instead of udelay counter
      ehci: Force a ehci_halt before trying to reset
      ehci: remove unused code

 drivers/usb/usb.c           |    5 ++-
 drivers/usb/usb_ehci.h      |    4 --
 drivers/usb/usb_ehci_core.c |   74 +++++++++++++++++++++++++++++++++---------
 include/usb/ehci.h          |   10 ++++++
 4 files changed, 72 insertions(+), 21 deletions(-)
 create mode 100644 include/usb/ehci.h



From s.hauer at pengutronix.de  Thu Jun 24 05:45:49 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:45:49 +0200
Subject: [PATCH 4/6] ehci: use is_timeout for timeout instead of udelay counter
In-Reply-To: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372751-15797-5-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/usb_ehci_core.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/usb_ehci_core.c b/drivers/usb/usb_ehci_core.c
index c5d4da3..e70e871 100644
--- a/drivers/usb/usb_ehci_core.c
+++ b/drivers/usb/usb_ehci_core.c
@@ -213,18 +213,20 @@ static inline void ehci_invalidate_dcache(struct QH *qh)
 static int handshake(uint32_t *ptr, uint32_t mask, uint32_t done, int usec)
 {
 	uint32_t result;
+	uint64_t start;
 
-	do {
+	start = get_time_ns();
+
+	while (1) {
 		result = ehci_readl(ptr);
 		if (result == ~(uint32_t)0)
 			return -1;
 		result &= mask;
 		if (result == done)
 			return 0;
-		udelay(1);
-		usec--;
-	} while (usec > 0);
-	return -1;
+		if (is_timeout(start, usec * USECOND))
+			return -ETIMEDOUT;
+	}
 }
 
 static int ehci_reset(struct ehci_priv *ehci)
-- 
1.7.1



From s.hauer at pengutronix.de  Thu Jun 24 05:45:50 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 11:45:50 +0200
Subject: [PATCH 5/6] ehci: Force a ehci_halt before trying to reset
In-Reply-To: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372751-15797-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1277372751-15797-6-git-send-email-s.hauer@pengutronix.de>

As observed on OMAP some controllers do not like being
resetted when running.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/usb_ehci_core.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/usb_ehci_core.c b/drivers/usb/usb_ehci_core.c
index e70e871..fe988c3 100644
--- a/drivers/usb/usb_ehci_core.c
+++ b/drivers/usb/usb_ehci_core.c
@@ -770,12 +770,33 @@ unknown:
 	return -1;
 }
 
+/* force HC to halt state from unknown (EHCI spec section 2.3) */
+static int ehci_halt(struct ehci_priv *ehci)
+{
+	u32	temp = ehci_readl(&ehci->hcor->or_usbsts);
+
+	/* disable any irqs left enabled by previous code */
+	ehci_writel(&ehci->hcor->or_usbintr, 0);
+
+	if (temp & STS_HALT)
+		return 0;
+
+	temp = ehci_readl(&ehci->hcor->or_usbcmd);
+	temp &= ~CMD_RUN;
+	ehci_writel(&ehci->hcor->or_usbcmd, temp);
+
+	return handshake(&ehci->hcor->or_usbsts,
+			  STS_HALT, STS_HALT, 16 * 125);
+}
+
 static int ehci_init(struct usb_host *host)
 {
 	struct ehci_priv *ehci = to_ehci(host);
 	uint32_t reg;
 	uint32_t cmd;
 
+	ehci_halt(ehci);
+
 	/* EHCI spec section 4.1 */
 	if (ehci_reset(ehci) != 0)
 		return -1;
-- 
1.7.1



From eric at eukrea.com  Thu Jun 24 05:49:55 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Thu, 24 Jun 2010 11:49:55 +0200
Subject: [PATCH 1/3] fix command loadb
Message-ID: <1277372997-6472-1-git-send-email-eric@eukrea.com>

which was broken after commit c3789cd49b43ec1c414ba1b0e9f48e8ccc19f8e1

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 commands/loadb.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/commands/loadb.c b/commands/loadb.c
index 6740ef4..437b60f 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -724,7 +724,7 @@ static int do_load_serial_bin(struct command *cmdtp, int argc, char *argv[])
 		printf("%s:No console device with STDIN and STDOUT\n", argv[0]);
 		return -ENODEV;
 	}
-	current_baudrate = simple_strtoul(cdev->baudrate_string, NULL, 10);
+	current_baudrate = (int)simple_strtoul(dev_get_param(cdev->dev, "baudrate"), NULL, 10);
 
 	/* Load Defaults */
 	if (load_baudrate == 0)
-- 
1.6.3.3



From eric at eukrea.com  Thu Jun 24 05:49:56 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Thu, 24 Jun 2010 11:49:56 +0200
Subject: [PATCH 2/3] unbreak imx-ipu-fb
In-Reply-To: <1277372997-6472-1-git-send-email-eric@eukrea.com>
References: <1277372997-6472-1-git-send-email-eric@eukrea.com>
Message-ID: <1277372997-6472-2-git-send-email-eric@eukrea.com>

commit c3789cd49b43ec1c414ba1b0e9f48e8ccc19f8e1 set fb0.enable to 0
as a default. Re-enabling the display doesn't work after this.
Removing sdc_enable_channel from imxfb_probe fix this problem.

This patch also remove verbose log from ipu_fb_disable.

Patch tested on i.MX35.

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 drivers/video/imx-ipu-fb.c |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/drivers/video/imx-ipu-fb.c b/drivers/video/imx-ipu-fb.c
index 0bd86b2..6d1eb5e 100644
--- a/drivers/video/imx-ipu-fb.c
+++ b/drivers/video/imx-ipu-fb.c
@@ -835,8 +835,6 @@ static void ipu_fb_disable(struct fb_info *info)
 	struct ipu_fb_info *fbi = info->priv;
 	u32 reg;
 
-	printf("%s\n", __func__);
-
 	reg = reg_read(fbi, SDC_COM_CONF);
 	reg &= ~SDC_COM_BG_EN;
 	reg_write(fbi, reg, SDC_COM_CONF);
@@ -883,8 +881,6 @@ static int imxfb_probe(struct device_d *dev)
 			return -ENOMEM;
 	}
 
-	sdc_enable_channel(fbi, info->screen_base);
-
 	ret = register_framebuffer(&fbi->info);
 	if (ret < 0) {
 		dev_err(dev, "failed to register framebuffer\n");
-- 
1.6.3.3



From eric at eukrea.com  Thu Jun 24 05:49:57 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Thu, 24 Jun 2010 11:49:57 +0200
Subject: [PATCH 3/3] eukrea_cpuimx35: better handling of backlight
In-Reply-To: <1277372997-6472-2-git-send-email-eric@eukrea.com>
References: <1277372997-6472-1-git-send-email-eric@eukrea.com>
	<1277372997-6472-2-git-send-email-eric@eukrea.com>
Message-ID: <1277372997-6472-3-git-send-email-eric@eukrea.com>

start with backlight disabled and enable it if the logo is
displayed.

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 board/eukrea_cpuimx35/env/bin/init      |    2 ++
 board/eukrea_cpuimx35/eukrea_cpuimx35.c |   11 +++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/board/eukrea_cpuimx35/env/bin/init b/board/eukrea_cpuimx35/env/bin/init
index 49e54c5..4610213 100644
--- a/board/eukrea_cpuimx35/env/bin/init
+++ b/board/eukrea_cpuimx35/env/bin/init
@@ -14,9 +14,11 @@ fi
 
 if [ -f /env/logo.bmp ]; then
 	bmp /env/logo.bmp
+	gpio_direction_output 1 1
 elif [ -f /env/logo.bmp.lzo ]; then
 	unlzo /env/logo.bmp.lzo /logo.bmp
 	bmp /logo.bmp
+	gpio_direction_output 1 1
 fi
 
 if [ -z $eth0.ethaddr ]; then
diff --git a/board/eukrea_cpuimx35/eukrea_cpuimx35.c b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
index 7f1c782..f358f51 100644
--- a/board/eukrea_cpuimx35/eukrea_cpuimx35.c
+++ b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
@@ -166,8 +166,10 @@ device_initcall(eukrea_cpuimx35_devices_init);
 
 static int eukrea_cpuimx35_enable_display(void)
 {
-	gpio_direction_output(1, 1);
-	gpio_direction_output(0, 0);
+	/* default : backlight OFF */
+	gpio_direction_output(1, 0);
+	gpio_direction_output(4, 1);
+
 	return 0;
 }
 
@@ -205,14 +207,19 @@ static struct pad_desc eukrea_cpuimx35_pads[] = {
 	MX35_PAD_TXD1__UART1_TXD_MUX,
 	MX35_PAD_RTS1__UART1_RTS,
 	MX35_PAD_CTS1__UART1_CTS,
+
+	MX35_PAD_CONTRAST__GPIO1_1,
+	MX35_PAD_D3_CLS__GPIO1_4,
 };
 
+
 static int eukrea_cpuimx35_console_init(void)
 {
 	mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx35_pads,
 		ARRAY_SIZE(eukrea_cpuimx35_pads));
 
 	register_device(&eukrea_cpuimx35_serial_device);
+
 	return 0;
 }
 
-- 
1.6.3.3



From eric at eukrea.com  Thu Jun 24 05:53:40 2010
From: eric at eukrea.com (=?UTF-8?B?RXJpYyBCw6luYXJk?=)
Date: Thu, 24 Jun 2010 11:53:40 +0200
Subject: [PATCH 1/3] fix command loadb
In-Reply-To: <1277372997-6472-1-git-send-email-eric@eukrea.com>
References: <1277372997-6472-1-git-send-email-eric@eukrea.com>
Message-ID: <4C232B24.6050105@eukrea.com>

Le 24/06/2010 11:49, Eric B?nard a ?crit :
> which was broken after commit c3789cd49b43ec1c414ba1b0e9f48e8ccc19f8e1
>
this patch is only compile tested so the fix may be wrong.

Eric

> Signed-off-by: Eric B?nard<eric at eukrea.com>
> ---
>   commands/loadb.c |    2 +-
>   1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/commands/loadb.c b/commands/loadb.c
> index 6740ef4..437b60f 100644
> --- a/commands/loadb.c
> +++ b/commands/loadb.c
> @@ -724,7 +724,7 @@ static int do_load_serial_bin(struct command *cmdtp, int argc, char *argv[])
>   		printf("%s:No console device with STDIN and STDOUT\n", argv[0]);
>   		return -ENODEV;
>   	}
> -	current_baudrate = simple_strtoul(cdev->baudrate_string, NULL, 10);
> +	current_baudrate = (int)simple_strtoul(dev_get_param(cdev->dev, "baudrate"), NULL, 10);
>
>   	/* Load Defaults */
>   	if (load_baudrate == 0)



From s.hauer at pengutronix.de  Thu Jun 24 06:34:55 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 12:34:55 +0200
Subject: [PATCH 2/3] unbreak imx-ipu-fb
In-Reply-To: <1277372997-6472-2-git-send-email-eric@eukrea.com>
References: <1277372997-6472-1-git-send-email-eric@eukrea.com>
	<1277372997-6472-2-git-send-email-eric@eukrea.com>
Message-ID: <20100624103455.GT12115@pengutronix.de>

On Thu, Jun 24, 2010 at 11:49:56AM +0200, Eric B?nard wrote:
> commit c3789cd49b43ec1c414ba1b0e9f48e8ccc19f8e1 set fb0.enable to 0
> as a default. Re-enabling the display doesn't work after this.
> Removing sdc_enable_channel from imxfb_probe fix this problem.
> 
> This patch also remove verbose log from ipu_fb_disable.

I already stumbled upon this. I prefer the following patch which fixes
the enabling/disabling of the framebuffer.

Sascha

    imx ipu fb: remove checking of IPU_CHA_BUF0_RDY
    
    This check prevents the driver from successfully enabling/disabling
    the controller more than once, because the second time we get
    here the check fails and the drivers bails out. We do not need this
    check at all, so remove it.
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

diff --git a/drivers/video/imx-ipu-fb.c b/drivers/video/imx-ipu-fb.c
index 0bd86b2..d9b94e4 100644
--- a/drivers/video/imx-ipu-fb.c
+++ b/drivers/video/imx-ipu-fb.c
@@ -664,12 +664,6 @@ static int ipu_enable_channel(struct ipu_fb_info *fbi, enum ipu_channel channel)
 static int ipu_update_channel_buffer(struct ipu_fb_info *fbi,
 		enum ipu_channel channel, void *buf)
 {
-	u32 reg;
-
-	reg = reg_read(fbi, IPU_CHA_BUF0_RDY);
-	if (reg & (1UL << channel))
-		return -EACCES;
-
 	/* 44.3.3.1.9 - Row Number 1 (WORD1, offset 0) */
 	reg_write(fbi, dma_param_addr(channel) + 0x0008UL, IPU_IMA_ADDR);
 	reg_write(fbi, (u32)buf, IPU_IMA_DATA);

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 24 06:38:21 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 12:38:21 +0200
Subject: [PATCH 1/3] fix command loadb
In-Reply-To: <4C232B24.6050105@eukrea.com>
References: <1277372997-6472-1-git-send-email-eric@eukrea.com>
	<4C232B24.6050105@eukrea.com>
Message-ID: <20100624103821.GU12115@pengutronix.de>

On Thu, Jun 24, 2010 at 11:53:40AM +0200, Eric B?nard wrote:
> Le 24/06/2010 11:49, Eric B?nard a ?crit :
>> which was broken after commit c3789cd49b43ec1c414ba1b0e9f48e8ccc19f8e1
>>
> this patch is only compile tested so the fix may be wrong.

Looks sane. Applied.

Sascha

>
> Eric
>
>> Signed-off-by: Eric B?nard<eric at eukrea.com>
>> ---
>>   commands/loadb.c |    2 +-
>>   1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/commands/loadb.c b/commands/loadb.c
>> index 6740ef4..437b60f 100644
>> --- a/commands/loadb.c
>> +++ b/commands/loadb.c
>> @@ -724,7 +724,7 @@ static int do_load_serial_bin(struct command *cmdtp, int argc, char *argv[])
>>   		printf("%s:No console device with STDIN and STDOUT\n", argv[0]);
>>   		return -ENODEV;
>>   	}
>> -	current_baudrate = simple_strtoul(cdev->baudrate_string, NULL, 10);
>> +	current_baudrate = (int)simple_strtoul(dev_get_param(cdev->dev, "baudrate"), NULL, 10);
>>
>>   	/* Load Defaults */
>>   	if (load_baudrate == 0)
>
>
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 24 06:48:01 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 12:48:01 +0200
Subject: [PATCH 3/3] eukrea_cpuimx35: better handling of backlight
In-Reply-To: <1277372997-6472-3-git-send-email-eric@eukrea.com>
References: <1277372997-6472-1-git-send-email-eric@eukrea.com>
	<1277372997-6472-2-git-send-email-eric@eukrea.com>
	<1277372997-6472-3-git-send-email-eric@eukrea.com>
Message-ID: <20100624104801.GV12115@pengutronix.de>

Hi Eric,

On Thu, Jun 24, 2010 at 11:49:57AM +0200, Eric B?nard wrote:
> start with backlight disabled and enable it if the logo is
> displayed.

I just posted a patch which starts up the imxfb driver disabled and
another patch which adds a board specific enable/disable hook. Would
this be a solution for you? The only thing missing then is a patch
which initializes the ipu fb driver with the display disabled.

Sascha

> 
> Signed-off-by: Eric B?nard <eric at eukrea.com>
> ---
>  board/eukrea_cpuimx35/env/bin/init      |    2 ++
>  board/eukrea_cpuimx35/eukrea_cpuimx35.c |   11 +++++++++--
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/board/eukrea_cpuimx35/env/bin/init b/board/eukrea_cpuimx35/env/bin/init
> index 49e54c5..4610213 100644
> --- a/board/eukrea_cpuimx35/env/bin/init
> +++ b/board/eukrea_cpuimx35/env/bin/init
> @@ -14,9 +14,11 @@ fi
>  
>  if [ -f /env/logo.bmp ]; then
>  	bmp /env/logo.bmp
> +	gpio_direction_output 1 1
>  elif [ -f /env/logo.bmp.lzo ]; then
>  	unlzo /env/logo.bmp.lzo /logo.bmp
>  	bmp /logo.bmp
> +	gpio_direction_output 1 1
>  fi
>  
>  if [ -z $eth0.ethaddr ]; then
> diff --git a/board/eukrea_cpuimx35/eukrea_cpuimx35.c b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
> index 7f1c782..f358f51 100644
> --- a/board/eukrea_cpuimx35/eukrea_cpuimx35.c
> +++ b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
> @@ -166,8 +166,10 @@ device_initcall(eukrea_cpuimx35_devices_init);
>  
>  static int eukrea_cpuimx35_enable_display(void)
>  {
> -	gpio_direction_output(1, 1);
> -	gpio_direction_output(0, 0);
> +	/* default : backlight OFF */
> +	gpio_direction_output(1, 0);
> +	gpio_direction_output(4, 1);
> +
>  	return 0;
>  }
>  
> @@ -205,14 +207,19 @@ static struct pad_desc eukrea_cpuimx35_pads[] = {
>  	MX35_PAD_TXD1__UART1_TXD_MUX,
>  	MX35_PAD_RTS1__UART1_RTS,
>  	MX35_PAD_CTS1__UART1_CTS,
> +
> +	MX35_PAD_CONTRAST__GPIO1_1,
> +	MX35_PAD_D3_CLS__GPIO1_4,
>  };
>  
> +
>  static int eukrea_cpuimx35_console_init(void)
>  {
>  	mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx35_pads,
>  		ARRAY_SIZE(eukrea_cpuimx35_pads));
>  
>  	register_device(&eukrea_cpuimx35_serial_device);
> +
>  	return 0;
>  }
>  
> -- 
> 1.6.3.3
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 24 07:10:30 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 13:10:30 +0200
Subject: [PATCH] envfs: fix build warning
In-Reply-To: <60663606c7efe2aaede86326339cb620c0a6bf8a.1277370124.git.baruch@tkos.co.il>
References: <60663606c7efe2aaede86326339cb620c0a6bf8a.1277370124.git.baruch@tkos.co.il>
Message-ID: <20100624111030.GZ12115@pengutronix.de>

On Thu, Jun 24, 2010 at 12:04:59PM +0300, Baruch Siach wrote:
> __LITTLE_ENDIAN or __BIG_ENDIAN are not always defined. E.g. the CodeSourcery
> G++ Lite 2010q1 for ARM (4.4.1) does not define __BIG_ENDIAN. This causes a
> compile time warning.

Maybe we should rather define __LITTLE_ENDIAN and __BIG_ENDIAN
in include/linux/byteorder.h. We do not seem to have any
#ifdef __XX_ENDIAN left in the code.

Sascha

> 
> Signed-off-by: Baruch Siach <baruch at tkos.co.il>
> ---
>  include/envfs.h |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/envfs.h b/include/envfs.h
> index b5849d9..0dd4e6a 100644
> --- a/include/envfs.h
> +++ b/include/envfs.h
> @@ -36,7 +36,7 @@ struct envfs_super {
>  #error "No byte order defined in __BYTE_ORDER"
>  #endif
>  
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN
>  #define ENVFS_16(x)	(x)
>  #define ENVFS_24(x)	(x)
>  #define ENVFS_32(x)	(x)
> @@ -44,7 +44,7 @@ struct envfs_super {
>  #define ENVFS_GET_OFFSET(x)	((x)->offset)
>  #define ENVFS_SET_OFFSET(x,y)	((x)->offset = (y))
>  #define ENVFS_SET_NAMELEN(x,y) ((x)->namelen = (y))
> -#elif __BYTE_ORDER == __BIG_ENDIAN
> +#elif defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN
>  #ifdef __KERNEL__
>  #define ENVFS_16(x)	swab16(x)
>  #define ENVFS_24(x)	((swab32(x)) >> 8)
> -- 
> 1.7.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From baruch at tkos.co.il  Thu Jun 24 07:19:17 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Thu, 24 Jun 2010 14:19:17 +0300
Subject: [PATCH] envfs: fix build warning
In-Reply-To: <20100624111030.GZ12115@pengutronix.de>
References: <60663606c7efe2aaede86326339cb620c0a6bf8a.1277370124.git.baruch@tkos.co.il>
	<20100624111030.GZ12115@pengutronix.de>
Message-ID: <20100624111917.GE27906@jasper.tkos.co.il>

Hi Sascha,

On Thu, Jun 24, 2010 at 01:10:30PM +0200, Sascha Hauer wrote:
> On Thu, Jun 24, 2010 at 12:04:59PM +0300, Baruch Siach wrote:
> > __LITTLE_ENDIAN or __BIG_ENDIAN are not always defined. E.g. the CodeSourcery
> > G++ Lite 2010q1 for ARM (4.4.1) does not define __BIG_ENDIAN. This causes a
> > compile time warning.
> 
> Maybe we should rather define __LITTLE_ENDIAN and __BIG_ENDIAN
> in include/linux/byteorder.h.

You mean include/linux/byteorder/generic.h? I now see that __LITTLE_ENDIAN and 
__BIG_ENDIAN are defined in include/linux/byteorder/little_endian.h and 
include/linux/byteorder/big_endian.h respectively. Should we add their 
complement?

baruch

> We do not seem to have any
> #ifdef __XX_ENDIAN left in the code.
> 
> Sascha
> 
> > 
> > Signed-off-by: Baruch Siach <baruch at tkos.co.il>
> > ---
> >  include/envfs.h |    4 ++--
> >  1 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/include/envfs.h b/include/envfs.h
> > index b5849d9..0dd4e6a 100644
> > --- a/include/envfs.h
> > +++ b/include/envfs.h
> > @@ -36,7 +36,7 @@ struct envfs_super {
> >  #error "No byte order defined in __BYTE_ORDER"
> >  #endif
> >  
> > -#if __BYTE_ORDER == __LITTLE_ENDIAN
> > +#if defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN
> >  #define ENVFS_16(x)	(x)
> >  #define ENVFS_24(x)	(x)
> >  #define ENVFS_32(x)	(x)
> > @@ -44,7 +44,7 @@ struct envfs_super {
> >  #define ENVFS_GET_OFFSET(x)	((x)->offset)
> >  #define ENVFS_SET_OFFSET(x,y)	((x)->offset = (y))
> >  #define ENVFS_SET_NAMELEN(x,y) ((x)->namelen = (y))
> > -#elif __BYTE_ORDER == __BIG_ENDIAN
> > +#elif defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN
> >  #ifdef __KERNEL__
> >  #define ENVFS_16(x)	swab16(x)
> >  #define ENVFS_24(x)	((swab32(x)) >> 8)
> > -- 
> > 1.7.1
> > 
> > 
> > _______________________________________________
> > barebox mailing list
> > barebox at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -


From s.hauer at pengutronix.de  Thu Jun 24 07:35:27 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 13:35:27 +0200
Subject: [PATCH] envfs: fix build warning
In-Reply-To: <20100624111917.GE27906@jasper.tkos.co.il>
References: <60663606c7efe2aaede86326339cb620c0a6bf8a.1277370124.git.baruch@tkos.co.il>
	<20100624111030.GZ12115@pengutronix.de>
	<20100624111917.GE27906@jasper.tkos.co.il>
Message-ID: <20100624113527.GA12115@pengutronix.de>

On Thu, Jun 24, 2010 at 02:19:17PM +0300, Baruch Siach wrote:
> Hi Sascha,
> 
> On Thu, Jun 24, 2010 at 01:10:30PM +0200, Sascha Hauer wrote:
> > On Thu, Jun 24, 2010 at 12:04:59PM +0300, Baruch Siach wrote:
> > > __LITTLE_ENDIAN or __BIG_ENDIAN are not always defined. E.g. the CodeSourcery
> > > G++ Lite 2010q1 for ARM (4.4.1) does not define __BIG_ENDIAN. This causes a
> > > compile time warning.
> > 
> > Maybe we should rather define __LITTLE_ENDIAN and __BIG_ENDIAN
> > in include/linux/byteorder.h.
> 
> You mean include/linux/byteorder/generic.h? I now see that __LITTLE_ENDIAN and 
> __BIG_ENDIAN are defined in include/linux/byteorder/little_endian.h and 
> include/linux/byteorder/big_endian.h respectively. Should we add their 
> complement?

Yes.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From eric at eukrea.com  Thu Jun 24 07:48:01 2010
From: eric at eukrea.com (=?ISO-8859-15?Q?Eric_B=E9nard?=)
Date: Thu, 24 Jun 2010 13:48:01 +0200
Subject: [PATCH 3/3] eukrea_cpuimx35: better handling of backlight
In-Reply-To: <20100624104801.GV12115@pengutronix.de>
References: <1277372997-6472-1-git-send-email-eric@eukrea.com>
	<1277372997-6472-2-git-send-email-eric@eukrea.com>
	<1277372997-6472-3-git-send-email-eric@eukrea.com>
	<20100624104801.GV12115@pengutronix.de>
Message-ID: <4C2345F1.9060003@eukrea.com>

Hi Sascha,

Le 24/06/2010 12:48, Sascha Hauer a ?crit :
> On Thu, Jun 24, 2010 at 11:49:57AM +0200, Eric B?nard wrote:
>> start with backlight disabled and enable it if the logo is
>> displayed.
>
> I just posted a patch which starts up the imxfb driver disabled and
> another patch which adds a board specific enable/disable hook. Would
> this be a solution for you? The only thing missing then is a patch
> which initializes the ipu fb driver with the display disabled.
>
yes I saw your patch after sending this one and it's clearly the right 
way to do this.
I'll update ipu_fb to add the enable/disable hook.

Thanks,
Eric



From baruch at tkos.co.il  Thu Jun 24 09:26:16 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Thu, 24 Jun 2010 16:26:16 +0300
Subject: [PATCH net-pu] tftp: fix get
Message-ID: <ed04cb68b50f6426c0f154e489cf6436877e4b7a.1277385845.git.baruch@tkos.co.il>

With this patch tftp start requesting block 0 instead of 1. This fixes
tftp get on i.MX25 based board with tftpd-hpa server.

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---

tftp push isn't working though. I get:

error frame: 0x83705178 0x00000882

from the fec driver. I'll investigate this if I have time.

 net/tftp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index c0d3278..14d9b5e 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -320,7 +320,7 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 
 	tftp_timer_start = get_time_ns();
 	tftp_state = tftp_put ? STATE_WRQ : STATE_RRQ;
-	tftp_block = 1;
+	tftp_block = 0;
 
 	tftp_err = tftp_send();
 	if (tftp_err)
-- 
1.7.1



From eric at eukrea.com  Thu Jun 24 11:03:04 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Thu, 24 Jun 2010 17:03:04 +0200
Subject: [PATCH 1/2] imx-ipu-fb: Add board specific hook to enable display
Message-ID: <1277391785-15380-1-git-send-email-eric@eukrea.com>

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 arch/arm/mach-imx/include/mach/imx-ipu-fb.h |    2 ++
 drivers/video/imx-ipu-fb.c                  |    8 ++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-imx/include/mach/imx-ipu-fb.h b/arch/arm/mach-imx/include/mach/imx-ipu-fb.h
index 53c6d26..dd65b04 100644
--- a/arch/arm/mach-imx/include/mach/imx-ipu-fb.h
+++ b/arch/arm/mach-imx/include/mach/imx-ipu-fb.h
@@ -28,6 +28,8 @@ struct imx_ipu_fb_platform_data {
 	const struct fb_videomode	*mode;
 	unsigned char		bpp;
 	void __iomem		*framebuffer;
+	/** hook to enable backlight and stuff */
+	void			(*enable)(int enable);
 };
 
 #endif /* __MACH_IMX_IPU_FB_H__ */
diff --git a/drivers/video/imx-ipu-fb.c b/drivers/video/imx-ipu-fb.c
index 6d1eb5e..8994da4 100644
--- a/drivers/video/imx-ipu-fb.c
+++ b/drivers/video/imx-ipu-fb.c
@@ -36,6 +36,8 @@
 struct ipu_fb_info {
 	void __iomem		*regs;
 
+	void			(*enable)(int enable);
+
 	struct fb_info		info;
 	struct device_d		*dev;
 };
@@ -828,6 +830,8 @@ static void ipu_fb_enable(struct fb_info *info)
 	 * Linux driver calls sdc_set_brightness() here again,
 	 * once is enough for us
 	 */
+	if (fbi->enable)
+		fbi->enable(1);
 }
 
 static void ipu_fb_disable(struct fb_info *info)
@@ -835,6 +839,9 @@ static void ipu_fb_disable(struct fb_info *info)
 	struct ipu_fb_info *fbi = info->priv;
 	u32 reg;
 
+	if (fbi->enable)
+		fbi->enable(0);
+
 	reg = reg_read(fbi, SDC_COM_CONF);
 	reg &= ~SDC_COM_BG_EN;
 	reg_write(fbi, reg, SDC_COM_CONF);
@@ -866,6 +873,7 @@ static int imxfb_probe(struct device_d *dev)
 	info->yres = pdata->mode->yres;
 	info->bits_per_pixel = pdata->bpp;
 	info->fbops = &imxfb_ops;
+	fbi->enable = pdata->enable;
 
 	dev_info(dev, "i.MX Framebuffer driver\n");
 
-- 
1.6.3.3



From eric at eukrea.com  Thu Jun 24 11:03:05 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Thu, 24 Jun 2010 17:03:05 +0200
Subject: [PATCH 2/2] imx-ipu-fb: do not enable framebuffer on startup
In-Reply-To: <1277391785-15380-1-git-send-email-eric@eukrea.com>
References: <1277391785-15380-1-git-send-email-eric@eukrea.com>
Message-ID: <1277391785-15380-2-git-send-email-eric@eukrea.com>

The board code or startup script should enable it when
it actually wants to.

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 drivers/video/imx-ipu-fb.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/drivers/video/imx-ipu-fb.c b/drivers/video/imx-ipu-fb.c
index 8994da4..45f2215 100644
--- a/drivers/video/imx-ipu-fb.c
+++ b/drivers/video/imx-ipu-fb.c
@@ -895,8 +895,6 @@ static int imxfb_probe(struct device_d *dev)
 		return ret;
 	}
 
-	ipu_fb_enable(info);
-
 	return 0;
 }
 
-- 
1.6.3.3



From eric at eukrea.com  Thu Jun 24 11:03:22 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Thu, 24 Jun 2010 17:03:22 +0200
Subject: [PATCH] eukrea_cpuimx35: better usage of LCD enable pins
Message-ID: <1277391802-15423-1-git-send-email-eric@eukrea.com>

Use the enable hook to driver the LCD's enable pin.
Unfortunalty, because of the time the LCD takes to come out of
reset, I have to use a GPIO in order to turn on/off the backlight
instead of driving it from the enable function, else we get a
flicker at power on.

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 board/eukrea_cpuimx35/env/bin/init      |    2 ++
 board/eukrea_cpuimx35/eukrea_cpuimx35.c |   22 +++++++++++++---------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/board/eukrea_cpuimx35/env/bin/init b/board/eukrea_cpuimx35/env/bin/init
index 49e54c5..ff7c2d7 100644
--- a/board/eukrea_cpuimx35/env/bin/init
+++ b/board/eukrea_cpuimx35/env/bin/init
@@ -13,9 +13,11 @@ if [ -e /dev/nand0 ]; then
 fi
 
 if [ -f /env/logo.bmp ]; then
+	fb0.enable=1
 	bmp /env/logo.bmp
 elif [ -f /env/logo.bmp.lzo ]; then
 	unlzo /env/logo.bmp.lzo /logo.bmp
+	fb0.enable=1
 	bmp /logo.bmp
 fi
 
diff --git a/board/eukrea_cpuimx35/eukrea_cpuimx35.c b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
index 6eeb4a3..756546a 100644
--- a/board/eukrea_cpuimx35/eukrea_cpuimx35.c
+++ b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
@@ -104,9 +104,15 @@ static struct fb_videomode imxfb_mode = {
 	.flag		= 0,
 };
 
+static void eukrea_cpuimx35_enable_display(int enable)
+{
+	gpio_direction_output(4, enable);
+}
+
 static struct imx_ipu_fb_platform_data ipu_fb_data = {
 	.mode		= &imxfb_mode,
 	.bpp		= 16,
+	.enable		= eukrea_cpuimx35_enable_display,
 };
 
 static struct device_d imxfb_dev = {
@@ -153,6 +159,7 @@ static int eukrea_cpuimx35_devices_init(void)
 	register_device(&fec_dev);
 
 	register_device(&sdram_dev);
+
 	register_device(&imxfb_dev);
 
 	armlinux_add_dram(&sdram_dev);
@@ -164,15 +171,6 @@ static int eukrea_cpuimx35_devices_init(void)
 
 device_initcall(eukrea_cpuimx35_devices_init);
 
-static int eukrea_cpuimx35_enable_display(void)
-{
-	gpio_direction_output(1, 1);
-	gpio_direction_output(0, 0);
-	return 0;
-}
-
-late_initcall(eukrea_cpuimx35_enable_display);
-
 static struct device_d eukrea_cpuimx35_serial_device = {
 	.name		= "imx_serial",
 	.map_base	= IMX_UART1_BASE,
@@ -207,6 +205,8 @@ static struct pad_desc eukrea_cpuimx35_pads[] = {
 	MX35_PAD_CTS1__UART1_CTS,
 
 	MX35_PAD_LD23__GPIO3_29,
+	MX35_PAD_CONTRAST__GPIO1_1,
+	MX35_PAD_D3_CLS__GPIO1_4,
 };
 
 static int eukrea_cpuimx35_console_init(void)
@@ -214,6 +214,10 @@ static int eukrea_cpuimx35_console_init(void)
 	mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx35_pads,
 		ARRAY_SIZE(eukrea_cpuimx35_pads));
 
+	/* screen default on to prevent flicker */
+	gpio_direction_output(4, 1);
+	/* backlight default off */
+	gpio_direction_output(1, 0);
 	/* led default off */
 	gpio_direction_output(32 * 2 + 29, 1);
 
-- 
1.6.3.3



From eric at eukrea.com  Thu Jun 24 11:04:01 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Thu, 24 Jun 2010 17:04:01 +0200
Subject: [PATCH] eukrea_cpuimx35: boot update
Message-ID: <1277391841-15529-1-git-send-email-eric@eukrea.com>

internal boot : dcd update for mDDR init (relaxed timings)

NAND boot update : mDDR init updated (optimized timings)

configure led's IOMUX and set it off at boot

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
 board/eukrea_cpuimx35/eukrea_cpuimx35.c |    4 ++
 board/eukrea_cpuimx35/flash_header.c    |   24 ++---------
 board/eukrea_cpuimx35/lowlevel.c        |   67 ++++--------------------------
 3 files changed, 17 insertions(+), 78 deletions(-)

diff --git a/board/eukrea_cpuimx35/eukrea_cpuimx35.c b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
index f358f51..06e5448 100644
--- a/board/eukrea_cpuimx35/eukrea_cpuimx35.c
+++ b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
@@ -210,6 +210,7 @@ static struct pad_desc eukrea_cpuimx35_pads[] = {
 
 	MX35_PAD_CONTRAST__GPIO1_1,
 	MX35_PAD_D3_CLS__GPIO1_4,
+	MX35_PAD_LD23__GPIO3_29,
 };
 
 
@@ -218,6 +219,9 @@ static int eukrea_cpuimx35_console_init(void)
 	mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx35_pads,
 		ARRAY_SIZE(eukrea_cpuimx35_pads));
 
+	/* led default off */
+	gpio_direction_output(32 * 2 + 29, 1);
+
 	register_device(&eukrea_cpuimx35_serial_device);
 
 	return 0;
diff --git a/board/eukrea_cpuimx35/flash_header.c b/board/eukrea_cpuimx35/flash_header.c
index a0ccf5c..05104d4 100644
--- a/board/eukrea_cpuimx35/flash_header.c
+++ b/board/eukrea_cpuimx35/flash_header.c
@@ -9,37 +9,21 @@ void __naked __flash_header_start go(void)
 }
 
 struct imx_dcd_entry __dcd_entry_0x400 dcd_entry[] = {
+	{ .ptr_type = 4, .addr = 0x53F80004, .val = 0x00821000, },
+	{ .ptr_type = 4, .addr = 0x53F80004, .val = 0x00821000, },
 	{ .ptr_type = 4, .addr = 0xB8001010, .val = 0x00000004, },
 	{ .ptr_type = 4, .addr = 0xB8001010, .val = 0x0000000C, },
 	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc3f, },
 	{ .ptr_type = 4, .addr = 0xB8001000, .val = 0x92220000, },
-	{ .ptr_type = 1, .addr = 0x80000400, .val = 0x12345678, },
+	{ .ptr_type = 1, .addr = 0x80000400, .val = 0xda, },
 	{ .ptr_type = 4, .addr = 0xB8001000, .val = 0xA2220000, },
 	{ .ptr_type = 1, .addr = 0x80000000, .val = 0x87654321, },
 	{ .ptr_type = 1, .addr = 0x80000000, .val = 0x87654321, },
 	{ .ptr_type = 4, .addr = 0xB8001000, .val = 0xB2220000, },
 	{ .ptr_type = 1, .addr = 0x80000033, .val = 0xda, },
 	{ .ptr_type = 1, .addr = 0x82000000, .val = 0xda, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001004, .val = 0x007ffc2f, },
-	{ .ptr_type = 4, .addr = 0xB8001000, .val = 0x82220080, },
 	{ .ptr_type = 4, .addr = 0xB8001000, .val = 0x82228080, },
-	{ .ptr_type = 4, .addr = 0xB8001020, .val = 0x80000028, },
-	{ .ptr_type = 4, .addr = 0xB8001024, .val = 0x80000028, },
-	{ .ptr_type = 4, .addr = 0xB8001028, .val = 0x80000028, },
-	{ .ptr_type = 4, .addr = 0xB800102c, .val = 0x80000028, },
-	{ .ptr_type = 4, .addr = 0xB8001030, .val = 0x80000028, },
+	{ .ptr_type = 4, .addr = 0xB8001010, .val = 0x00000004, },
 };
 
 #define APP_DEST	0x80000000
diff --git a/board/eukrea_cpuimx35/lowlevel.c b/board/eukrea_cpuimx35/lowlevel.c
index 44f3cf0..275bfb2 100644
--- a/board/eukrea_cpuimx35/lowlevel.c
+++ b/board/eukrea_cpuimx35/lowlevel.c
@@ -62,7 +62,6 @@ void __bare_init __naked board_init_lowlevel(void)
 {
 	uint32_t r, s;
 	unsigned long ccm_base = IMX_CCM_BASE;
-	unsigned long iomuxc_base = IMX_IOMUXC_BASE;
 #ifdef CONFIG_NAND_IMX_BOOT
 	unsigned int *trg, *src;
 	int i;
@@ -132,68 +131,20 @@ void __bare_init __naked board_init_lowlevel(void)
 	if (r > 0x80000000 && r < 0x90000000)
 		board_init_lowlevel_return();
 
-	/* Set DDR Type to SDRAM, drive strength workaround	*
-	 * 0x00000000	MDDR					*
-	 * 0x00000800	3,3V SDRAM				*/
-
-	r = 0x00000800;
-	writel(r, iomuxc_base + 0x794);
-	writel(r, iomuxc_base + 0x798);
-	writel(r, iomuxc_base + 0x79c);
-	writel(r, iomuxc_base + 0x7a0);
-	writel(r, iomuxc_base + 0x7a4);
-
-	/* MDDR init, enable mDDR*/
-	writel(0x00000304, ESDMISC); /* was 0x00000004 */
-
-	/* set timing paramters */
-	writel(0x00255417, ESDCFG0);
-	/* select Precharge-All mode */
+	/* Init Mobile DDR */
+	writel(0x00000004, ESDMISC);
+	writel(0x0000000C, ESDMISC);
+	writel(0x00295729, ESDCFG0);
 	writel(0x92220000, ESDCTL0);
-	/* Precharge-All */
-	writel(0x12345678, IMX_SDRAM_CS0 + 0x400);
-
-	/* select Load-Mode-Register mode */
-	writel(0xB8001000, ESDCTL0);
-	/* Load reg EMR2 */
-	writeb(0xda, 0x84000000);
-	/* Load reg EMR3 */
-	writeb(0xda, 0x86000000);
-	/* Load reg EMR1 -- enable DLL */
-	writeb(0xda, 0x82000400);
-	/* Load reg MR -- reset DLL */
-	writeb(0xda, 0x80000333);
-
-	/* select Precharge-All mode */
-	writel(0x92220000, ESDCTL0);
-	/* Precharge-All */
-	writel(0x12345678, IMX_SDRAM_CS0 + 0x400);
-
-	/* select Manual-Refresh mode */
+	writeb(0xda, IMX_SDRAM_CS0 + 0x400);
 	writel(0xA2220000, ESDCTL0);
-	/* Manual-Refresh 2 times */
 	writel(0x87654321, IMX_SDRAM_CS0);
 	writel(0x87654321, IMX_SDRAM_CS0);
-
-	/* select Load-Mode-Register mode */
 	writel(0xB2220000, ESDCTL0);
-	/* Load reg MR -- CL3, BL8, end DLL reset */
-	writeb(0xda, 0x80000233);
-	/* Load reg EMR1 -- OCD default */
-	writeb(0xda, 0x82000780);
-	/* Load reg EMR1 -- OCD exit */
-	writeb(0xda, 0x82000400);
-
-	/* select normal-operation mode
-	 * DSIZ32-bit, BL8, COL10-bit, ROW13-bit
-	 * disable PWT & PRCT
-	 * disable Auto-Refresh */
-	writel(0x82220080, ESDCTL0);
-
-	/* enable Auto-Refresh */
-	writel(0x82228080, ESDCTL0);
-	/* enable Auto-Refresh */
-	writel(0x00002000, ESDCTL1);
+	writeb(0xda, IMX_SDRAM_CS0 + 0x33);
+	writeb(0xda, IMX_SDRAM_CS0 + 0x2000000);
+	writel(0x82224080, ESDCTL0);
+	writel(0x00000004, ESDMISC);
 
 #ifdef CONFIG_NAND_IMX_BOOT
 	/* skip NAND boot if not running from NFC space */
-- 
1.6.3.3



From eric at eukrea.com  Thu Jun 24 11:05:48 2010
From: eric at eukrea.com (=?ISO-8859-1?Q?Eric_B=E9nard?=)
Date: Thu, 24 Jun 2010 17:05:48 +0200
Subject: assorted patches
In-Reply-To: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <4C23744C.1010707@eukrea.com>

Hi Sascha,

Le 24/06/2010 11:39, Sascha Hauer a ?crit :
>
> The following changes since commit 334fe1dc8a1b866d1f0f4ccf82ff7b06589ec022:
>
>    pca100: use generic default env (2010-06-22 15:44:45 +0200)
>
> are available in the git repository at:
>    git://git.pengutronix.de/git/barebox.git assorted-pu
>
> Sascha Hauer (11):
>        i.MX27: merge iomux pim definitions from kernel
>        imxfb: Add board specific hook to enable display
>        imxfb: do not enable framebuffer on startup
>        memcpy cmd: Do not expect to read/write the whole chunk at once
>        armlinux: reorder tag setup
>        remove eco920 board support
>        usbnet: remove unused dev member in struct usbnet
>        i.MX serial: Use readl/writel instead of pointer deref
>        i.MX clocksource: Use readl/writel instead of pointer deref
>        i.MX27: Add some missing device base addresses
>        fb: add a usage counter to prevent double enable/disable
>
patche serie tested on i.MX35 : no problem found

Eric


From eric at eukrea.com  Thu Jun 24 11:21:14 2010
From: eric at eukrea.com (=?ISO-8859-1?Q?Eric_B=E9nard?=)
Date: Thu, 24 Jun 2010 17:21:14 +0200
Subject: [PATCH 13/13] add netconsole support
In-Reply-To: <1275645309-9756-14-git-send-email-s.hauer@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
	<1275645309-9756-14-git-send-email-s.hauer@pengutronix.de>
Message-ID: <4C2377EA.3000608@eukrea.com>

Hi Sascha,

Le 04/06/2010 11:55, Sascha Hauer a ?crit :
> +
> +On the remote host call scripts/netconsole with bareboxes ip and port as
> +parameters. port is initialized to 6666 by default.
> +
it seems scripts/netconsol is missing from the tree and the netconsole 
patche.

Eric


From eric at eukrea.com  Thu Jun 24 11:27:47 2010
From: eric at eukrea.com (=?ISO-8859-1?Q?Eric_B=E9nard?=)
Date: Thu, 24 Jun 2010 17:27:47 +0200
Subject: [PATCH 13/13] add netconsole support
In-Reply-To: <4C2377EA.3000608@eukrea.com>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>	<1275645309-9756-14-git-send-email-s.hauer@pengutronix.de>
	<4C2377EA.3000608@eukrea.com>
Message-ID: <4C237973.3020309@eukrea.com>

Le 24/06/2010 17:21, Eric B?nard a ?crit :
>> +On the remote host call scripts/netconsole with bareboxes ip and port as
>> +parameters. port is initialized to 6666 by default.
>> +
> it seems scripts/netconsol is missing from the tree and the netconsole
> patche.
>
OK this seems to work :
netcat -p 6666 -l -u IP_OF_BAREBOX

Eric


From s.hauer at pengutronix.de  Thu Jun 24 11:37:57 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 17:37:57 +0200
Subject: [PATCH 13/13] add netconsole support
In-Reply-To: <4C2377EA.3000608@eukrea.com>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
	<1275645309-9756-14-git-send-email-s.hauer@pengutronix.de>
	<4C2377EA.3000608@eukrea.com>
Message-ID: <20100624153757.GB12115@pengutronix.de>

On Thu, Jun 24, 2010 at 05:21:14PM +0200, Eric B?nard wrote:
> Hi Sascha,
>
> Le 04/06/2010 11:55, Sascha Hauer a ?crit :
>> +
>> +On the remote host call scripts/netconsole with bareboxes ip and port as
>> +parameters. port is initialized to 6666 by default.
>> +
> it seems scripts/netconsol is missing from the tree and the netconsole  
> patche.

Oh, I had it in my tree and forgot to commit. Did now.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 24 11:41:41 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 17:41:41 +0200
Subject: Regression: not booting anymore on OMAP35xx
In-Reply-To: <L4IQU1$4731D5E42E435C795207D3BFB302BAD3@aruba.it>
References: <L4IQU1$4731D5E42E435C795207D3BFB302BAD3@aruba.it>
Message-ID: <20100624154141.GC12115@pengutronix.de>

On Thu, Jun 24, 2010 at 02:32:25PM +0200, Luca Ceresoli wrote:
> Sascha Hauer wrote:
> > On Tue, Jun 22, 2010 at 04:04:52PM +0200, Luca Ceresoli wrote:
> > > Sascha Hauer wrote:
> > > > Hi Luca,
> > > > 
> > > > On Tue, Jun 22, 2010 at 02:26:11PM +0200, Luca Ceresoli wrote:
> > > > > Hi,
> > > > > 
> > > > 
> > > > Seems that I lost the call to arch_init_lowlevel. Does the following
> > > > patch help?
> > > 
> > > I'm afraid it doesn't seem to.
> > > It fails with the same symptoms.
> > > 
> > > Luca
> > > 
> > > > 
> > > > 
> > > > diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
> > > > index eea7dcf..91d2ccd 100644
> > > > --- a/arch/arm/cpu/start.c
> > > > +++ b/arch/arm/cpu/start.c
> > > > @@ -50,6 +50,8 @@ void __naked __bare_init reset(void)
> > > >  {
> > > >  	uint32_t r;
> > > >  
> > > > +	arch_init_lowlevel();
> > > > +
> > 
> > Ok, this has to be done *after* switching the cpu to SVC32 mode.
> > 
> > I tested this on my beagle board and now it works again. I pushed
> > a patch to the master repository.
> 
> Sascha, thank you for the prompt response.
> Unfortunately the new version works only partially with my Beagle
> Board (rev. C4).
> 
> I tested commit:
>  46976f7 OMAP: fix compilation
> 
> - Test 1: the board is always powered.
>   Press RESET with the USER key pressed.
>   10 tests, 10 passed.
> 
> - Test 2: the board is not powered.
>   Turn turn it on with the USER key pressed.
>   Turn turn it off again at the end of the test.
>   10 tests, 5 passed, 5 failed.
> 
> During all of the 20 tests, barebox.bin was always the same.
> I didn't recompile it.
> 
> OTOH the commit before the "reimplement in C" passes also test 2.
> 
> I hope this gives enough hints to solve the problem.

Ok, I'll try to reproduce this.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 24 11:59:07 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 24 Jun 2010 17:59:07 +0200
Subject: [PATCH net-pu] tftp: fix get
In-Reply-To: <ed04cb68b50f6426c0f154e489cf6436877e4b7a.1277385845.git.baruch@tkos.co.il>
References: <ed04cb68b50f6426c0f154e489cf6436877e4b7a.1277385845.git.baruch@tkos.co.il>
Message-ID: <20100624155907.GD12115@pengutronix.de>

Hi Baruch,

On Thu, Jun 24, 2010 at 04:26:16PM +0300, Baruch Siach wrote:
> With this patch tftp start requesting block 0 instead of 1. This fixes
> tftp get on i.MX25 based board with tftpd-hpa server.

This is strange. In case of tftp get this variable is not used for
sending packets. We do not request blocks with a certain number, we only
request a file and ack incoming packets. If you look at 'case TFTP_DATA'
in tftp_handler(), you'll see tftp_block getting overwritten by the
block number of the incoming packet.

The initialization of tftp_block is only used for tftp push. For tftp
push RFC1350 says that the first packet we send has to have block number
one (not zero). 

> 
> tftp push isn't working though. I get:
> 
> error frame: 0x83705178 0x00000882
> 
> from the fec driver. I'll investigate this if I have time.

I also see this message sometimes, but usually this is not a problem.
The transfer continues once the timeout handler triggers and the packet
is resent.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From eric at eukrea.com  Fri Jun 25 02:58:14 2010
From: eric at eukrea.com (=?ISO-8859-15?Q?Eric_B=E9nard?=)
Date: Fri, 25 Jun 2010 08:58:14 +0200
Subject: [PATCH 13/13] add netconsole support
In-Reply-To: <20100624153757.GB12115@pengutronix.de>
References: <1275645309-9756-1-git-send-email-s.hauer@pengutronix.de>
	<1275645309-9756-14-git-send-email-s.hauer@pengutronix.de>
	<4C2377EA.3000608@eukrea.com>
	<20100624153757.GB12115@pengutronix.de>
Message-ID: <4C245386.2000607@eukrea.com>

Hi Sascha,

Le 24/06/2010 17:37, Sascha Hauer a ?crit :
> On Thu, Jun 24, 2010 at 05:21:14PM +0200, Eric B?nard wrote:
>> it seems scripts/netconsol is missing from the tree and the netconsole
>> patche.
>
> Oh, I had it in my tree and forgot to commit. Did now.
>
thanks works fine, this netconsole is really a nice feature.

Eric


From jacmet at sunsite.dk  Fri Jun 25 03:17:44 2010
From: jacmet at sunsite.dk (Peter Korsgaard)
Date: Fri, 25 Jun 2010 09:17:44 +0200
Subject: [PATCH 04/11] memcpy cmd: Do not expect to read/write the whole
	chunk at once
In-Reply-To: <1277372356-32370-5-git-send-email-s.hauer@pengutronix.de>
	(Sascha Hauer's message of "Thu, 24 Jun 2010 11:39:09 +0200")
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
	<1277372356-32370-5-git-send-email-s.hauer@pengutronix.de>
Message-ID: <878w634m3r.fsf@macbook.be.48ers.dk>

>>>>> "Sascha" == Sascha Hauer <s.hauer at pengutronix.de> writes:

Hi,

 Sascha> read() does not necessarily return the number of bytes
 Sascha> we want to read, so deal with less bytes.

 Sascha> -		if ((w = write(destfd, rw_buf, r)) < 0) {
 Sascha> -			perror("write");
 Sascha> -			goto out;
 Sascha> -		}
 Sascha> -
 Sascha> -		if (r < now)
 Sascha> +		if (!r)
 Sascha>  			break;
 
 Sascha> -		if (w < r)
 Sascha> -			break;
 Sascha> +		tmp = 0;
 Sascha> +		now = r;
 Sascha> +		while (now) {
 Sascha> +			w = write(destfd, rw_buf + tmp, now);
 Sascha> +			if (w < 0) {
 Sascha> +				perror("write");
 Sascha> +				goto out;
 Sascha> +			}
 Sascha> +	                if (!w)
 Sascha> +			        break;
 
 Sascha> -		count -= now;
 Sascha> +			now -= w;
 Sascha> +			tmp += w;
 Sascha> +		}
 Sascha> +

This is probably not the only place we need this. What about moving this
to a helper function like busybox' full_write()?

-- 
Bye, Peter Korsgaard


From marek.belisko at gmail.com  Fri Jun 25 05:31:49 2010
From: marek.belisko at gmail.com (Belisko Marek)
Date: Fri, 25 Jun 2010 11:31:49 +0200
Subject: testing barebox on calao sbc35-a9260 board
Message-ID: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>

Hi,

I have a calao board sbc35-a9260 with u-boot pre-installed on it.
I would like to try barebox running on that board (also make some development).
I build at91sam9260ek_defconfig to try it out. I became to situation
that I don't know how to load image to board :)

I try via tftp but u-boot automatically try to boot it and I got some
error about magic number.
I think about possibility just download binary to some RAM address and
then use go command in u-boot
to test if barebox binary will work.

There exist some how-to or example how to do this?

Thanks in advance,

Marek

-- 
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
icq: 290551086
web: http://open-nandra.com


From baruch at tkos.co.il  Sun Jun 27 01:14:46 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Sun, 27 Jun 2010 08:14:46 +0300
Subject: [PATCH net-pu] tftp: fix get
In-Reply-To: <20100624155907.GD12115@pengutronix.de>
References: <ed04cb68b50f6426c0f154e489cf6436877e4b7a.1277385845.git.baruch@tkos.co.il>
	<20100624155907.GD12115@pengutronix.de>
Message-ID: <20100627051445.GA26474@jasper.tkos.co.il>

Hi Sascha,

On Thu, Jun 24, 2010 at 05:59:07PM +0200, Sascha Hauer wrote:
> On Thu, Jun 24, 2010 at 04:26:16PM +0300, Baruch Siach wrote:
> > With this patch tftp start requesting block 0 instead of 1. This fixes
> > tftp get on i.MX25 based board with tftpd-hpa server.
> 
> This is strange. In case of tftp get this variable is not used for
> sending packets. We do not request blocks with a certain number, we only
> request a file and ack incoming packets. If you look at 'case TFTP_DATA'
> in tftp_handler(), you'll see tftp_block getting overwritten by the
> block number of the incoming packet.

The code that sends the first acknowledgement (in my case, i.e. tftpd-hpa) is 
at 'case STATE_OACK', in response to the "Option Acknowledgement" of the 
'timeout=5' option. This code does not initialize tftp_block.

> The initialization of tftp_block is only used for tftp push. For tftp
> push RFC1350 says that the first packet we send has to have block number
> one (not zero). 

I'll send a patch fixing push along the same line (for me) shortly.

> > tftp push isn't working though. I get:
> > 
> > error frame: 0x83705178 0x00000882
> > 
> > from the fec driver. I'll investigate this if I have time.
> 
> I also see this message sometimes, but usually this is not a problem.
> The transfer continues once the timeout handler triggers and the packet
> is resent.

I see. Thanks for the info.

baruch

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -


From baruch at tkos.co.il  Sun Jun 27 01:17:16 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Sun, 27 Jun 2010 08:17:16 +0300
Subject: [PATCH net-pu] tftp: fix push for servers supporting 'option
	acknowledgement'
Message-ID: <e049fe5636cc213f485e3d24a3dcbd6c246e8ee5.1277615744.git.baruch@tkos.co.il>

When doing push receiving 'option acknowledgement' should move the protocol to
state WDATA, and set block number to 1.

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 net/tftp.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 14d9b5e..20fab78 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -186,6 +186,10 @@ static void tftp_handler(char *packet, unsigned len)
 	case TFTP_OACK:
 		debug("Got OACK: %s %s\n", pkt, pkt + strlen(pkt) + 1);
 		tftp_state = STATE_OACK;
+		if (tftp_put) {
+			tftp_block = 1;
+			tftp_state = STATE_WDATA;
+		}
 		tftp_server_port = ntohs(udp->uh_sport);
 		tftp_con->udp->uh_dport = udp->uh_sport;
 		tftp_send(); /* Send ACK */
-- 
1.7.1



From baruch at tkos.co.il  Sun Jun 27 01:46:05 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Sun, 27 Jun 2010 08:46:05 +0300
Subject: [PATCH] byteorder: add missing {BIG,LITTLE}_ENDIAN defines
In-Reply-To: <20100624113527.GA12115@pengutronix.de>
References: <20100624113527.GA12115@pengutronix.de>
Message-ID: <01b92fe3c69bda4a61e0376ea352fcd519ef756c.1277617440.git.baruch@tkos.co.il>

This fixes build warnings when testing __BYTE_ORDER of the other kind.

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 include/linux/byteorder/generic.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/include/linux/byteorder/generic.h b/include/linux/byteorder/generic.h
index cff850f..aab8f4b 100644
--- a/include/linux/byteorder/generic.h
+++ b/include/linux/byteorder/generic.h
@@ -78,6 +78,12 @@
  *
  */
 
+#ifndef __LITTLE_ENDIAN
+#define __LITTLE_ENDIAN	1234
+#endif
+#ifndef __BIG_ENDIAN
+#define __BIG_ENDIAN	4321
+#endif
 
 #if defined(__KERNEL__)
 /*
-- 
1.7.1



From w.sang at pengutronix.de  Mon Jun 28 00:21:37 2010
From: w.sang at pengutronix.de (Wolfram Sang)
Date: Mon, 28 Jun 2010 06:21:37 +0200
Subject: [PATCH] nor: don't use sector for ERASE_START
Message-ID: <1277698897-5655-1-git-send-email-w.sang@pengutronix.de>

Similar to ac2d4d71ba493fd638ae0bf1a530a51c76d3c53d, copy the behaviour
from Linux which does:

cfi_send_gen_cmd(0x80, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);

Notice the third parameter which is simply chip->start. Needed for some
SST-flashes.

Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig at pengutronix.de>
Signed-off-by: Wolfram Sang <w.sang at pengutronix.de>
---
 drivers/nor/cfi_flash_amd.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/nor/cfi_flash_amd.c b/drivers/nor/cfi_flash_amd.c
index 411d8e6..ea4c2c9 100644
--- a/drivers/nor/cfi_flash_amd.c
+++ b/drivers/nor/cfi_flash_amd.c
@@ -74,8 +74,7 @@ static int amd_flash_is_busy (flash_info_t * info, flash_sect_t sect)
 static int amd_flash_erase_one (flash_info_t * info, long sect)
 {
 	flash_unlock_seq(info);
-	flash_write_cmd (info, sect, AMD_ADDR_ERASE_START,
-				AMD_CMD_ERASE_START);
+	flash_write_cmd (info, 0, AMD_ADDR_ERASE_START, AMD_CMD_ERASE_START);
 	flash_unlock_seq(info);
 	flash_write_cmd (info, sect, 0, AMD_CMD_ERASE_SECTOR);
 
-- 
1.7.1



From s.hauer at pengutronix.de  Mon Jun 28 03:55:01 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 28 Jun 2010 09:55:01 +0200
Subject: [PATCH net-pu] tftp: fix get
In-Reply-To: <20100627051445.GA26474@jasper.tkos.co.il>
References: <ed04cb68b50f6426c0f154e489cf6436877e4b7a.1277385845.git.baruch@tkos.co.il>
	<20100624155907.GD12115@pengutronix.de>
	<20100627051445.GA26474@jasper.tkos.co.il>
Message-ID: <20100628075500.GG12115@pengutronix.de>

On Sun, Jun 27, 2010 at 08:14:46AM +0300, Baruch Siach wrote:
> Hi Sascha,
> 
> On Thu, Jun 24, 2010 at 05:59:07PM +0200, Sascha Hauer wrote:
> > On Thu, Jun 24, 2010 at 04:26:16PM +0300, Baruch Siach wrote:
> > > With this patch tftp start requesting block 0 instead of 1. This fixes
> > > tftp get on i.MX25 based board with tftpd-hpa server.
> > 
> > This is strange. In case of tftp get this variable is not used for
> > sending packets. We do not request blocks with a certain number, we only
> > request a file and ack incoming packets. If you look at 'case TFTP_DATA'
> > in tftp_handler(), you'll see tftp_block getting overwritten by the
> > block number of the incoming packet.
> 
> The code that sends the first acknowledgement (in my case, i.e. tftpd-hpa) is 
> at 'case STATE_OACK', in response to the "Option Acknowledgement" of the 
> 'timeout=5' option. This code does not initialize tftp_block.

How about the following. This works for me with the hpa server in get
and push mode.


diff --git a/net/tftp.c b/net/tftp.c
index c0d3278..4b74dca 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -185,10 +185,21 @@ static void tftp_handler(char *packet, unsigned len)
 
 	case TFTP_OACK:
 		debug("Got OACK: %s %s\n", pkt, pkt + strlen(pkt) + 1);
-		tftp_state = STATE_OACK;
 		tftp_server_port = ntohs(udp->uh_sport);
 		tftp_con->udp->uh_dport = udp->uh_sport;
-		tftp_send(); /* Send ACK */
+
+		if (tftp_put) {
+			/* send first block */
+			tftp_state = STATE_WDATA;
+			tftp_block = 1;
+		} else {
+			/* send ACK */
+			tftp_state = STATE_OACK;
+			tftp_block = 0;
+		}
+
+		tftp_send();
+
 		break;
 	case TFTP_DATA:
 		if (len < 2)

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun 28 04:04:42 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 28 Jun 2010 10:04:42 +0200
Subject: testing barebox on calao sbc35-a9260 board
In-Reply-To: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>
References: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>
Message-ID: <20100628080442.GH12115@pengutronix.de>

Hi Marek,

On Fri, Jun 25, 2010 at 11:31:49AM +0200, Belisko Marek wrote:
> Hi,
> 
> I have a calao board sbc35-a9260 with u-boot pre-installed on it.
> I would like to try barebox running on that board (also make some development).
> I build at91sam9260ek_defconfig to try it out. I became to situation
> that I don't know how to load image to board :)
> 
> I try via tftp but u-boot automatically try to boot it and I got some
> error about magic number.
> I think about possibility just download binary to some RAM address and
> then use go command in u-boot
> to test if barebox binary will work.
> 
> There exist some how-to or example how to do this?

It's perfectly fine to start barebox from U-Boot with the 'go' command.
Try 'setenv autostart no' in U-Boot to stop U-Boot from autostarting
images.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From baruch at tkos.co.il  Mon Jun 28 04:22:02 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Mon, 28 Jun 2010 11:22:02 +0300
Subject: [PATCH net-pu] tftp: fix get
In-Reply-To: <20100628075500.GG12115@pengutronix.de>
References: <ed04cb68b50f6426c0f154e489cf6436877e4b7a.1277385845.git.baruch@tkos.co.il>
	<20100624155907.GD12115@pengutronix.de>
	<20100627051445.GA26474@jasper.tkos.co.il>
	<20100628075500.GG12115@pengutronix.de>
Message-ID: <20100628082202.GE2681@jasper.tkos.co.il>

Hi Sascha,

On Mon, Jun 28, 2010 at 09:55:01AM +0200, Sascha Hauer wrote:
> On Sun, Jun 27, 2010 at 08:14:46AM +0300, Baruch Siach wrote:
> > On Thu, Jun 24, 2010 at 05:59:07PM +0200, Sascha Hauer wrote:
> > > On Thu, Jun 24, 2010 at 04:26:16PM +0300, Baruch Siach wrote:
> > > > With this patch tftp start requesting block 0 instead of 1. This fixes
> > > > tftp get on i.MX25 based board with tftpd-hpa server.
> > > 
> > > This is strange. In case of tftp get this variable is not used for
> > > sending packets. We do not request blocks with a certain number, we only
> > > request a file and ack incoming packets. If you look at 'case TFTP_DATA'
> > > in tftp_handler(), you'll see tftp_block getting overwritten by the
> > > block number of the incoming packet.
> > 
> > The code that sends the first acknowledgement (in my case, i.e. tftpd-hpa) is 
> > at 'case STATE_OACK', in response to the "Option Acknowledgement" of the 
> > 'timeout=5' option. This code does not initialize tftp_block.
> 
> How about the following. This works for me with the hpa server in get
> and push mode.

Works for me too. Tested get and push.

BTW, why not s/tftp_put/tftp_push/?

baruch

> diff --git a/net/tftp.c b/net/tftp.c
> index c0d3278..4b74dca 100644
> --- a/net/tftp.c
> +++ b/net/tftp.c
> @@ -185,10 +185,21 @@ static void tftp_handler(char *packet, unsigned len)
>  
>  	case TFTP_OACK:
>  		debug("Got OACK: %s %s\n", pkt, pkt + strlen(pkt) + 1);
> -		tftp_state = STATE_OACK;
>  		tftp_server_port = ntohs(udp->uh_sport);
>  		tftp_con->udp->uh_dport = udp->uh_sport;
> -		tftp_send(); /* Send ACK */
> +
> +		if (tftp_put) {
> +			/* send first block */
> +			tftp_state = STATE_WDATA;
> +			tftp_block = 1;
> +		} else {
> +			/* send ACK */
> +			tftp_state = STATE_OACK;
> +			tftp_block = 0;
> +		}
> +
> +		tftp_send();
> +
>  		break;
>  	case TFTP_DATA:
>  		if (len < 2)

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -


From baruch at tkos.co.il  Mon Jun 28 04:32:15 2010
From: baruch at tkos.co.il (Baruch Siach)
Date: Mon, 28 Jun 2010 11:32:15 +0300
Subject: testing barebox on calao sbc35-a9260 board
In-Reply-To: <20100628080442.GH12115@pengutronix.de>
References: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>
	<20100628080442.GH12115@pengutronix.de>
Message-ID: <20100628083215.GF2681@jasper.tkos.co.il>

Hi Sascha,

On Mon, Jun 28, 2010 at 10:04:42AM +0200, Sascha Hauer wrote:
> On Fri, Jun 25, 2010 at 11:31:49AM +0200, Belisko Marek wrote:
> > I have a calao board sbc35-a9260 with u-boot pre-installed on it.
> > I would like to try barebox running on that board (also make some development).
> > I build at91sam9260ek_defconfig to try it out. I became to situation
> > that I don't know how to load image to board :)
> > 
> > I try via tftp but u-boot automatically try to boot it and I got some
> > error about magic number.
> > I think about possibility just download binary to some RAM address and
> > then use go command in u-boot
> > to test if barebox binary will work.
> > 
> > There exist some how-to or example how to do this?
> 
> It's perfectly fine to start barebox from U-Boot with the 'go' command.
> Try 'setenv autostart no' in U-Boot to stop U-Boot from autostarting
> images.

Is there a way to do the same on Barebox? Currently 'go barebox.bin' in ramfs 
returns -EINVAL from memmap.

baruch

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -


From s.hauer at pengutronix.de  Mon Jun 28 04:37:46 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 28 Jun 2010 10:37:46 +0200
Subject: [PATCH 04/11] memcpy cmd: Do not expect to read/write the
	whole chunk at once
In-Reply-To: <878w634m3r.fsf@macbook.be.48ers.dk>
References: <1277372356-32370-1-git-send-email-s.hauer@pengutronix.de>
	<1277372356-32370-5-git-send-email-s.hauer@pengutronix.de>
	<878w634m3r.fsf@macbook.be.48ers.dk>
Message-ID: <20100628083746.GI12115@pengutronix.de>

On Fri, Jun 25, 2010 at 09:17:44AM +0200, Peter Korsgaard wrote:
> >>>>> "Sascha" == Sascha Hauer <s.hauer at pengutronix.de> writes:
> 
> Hi,
> 
>  Sascha> read() does not necessarily return the number of bytes
>  Sascha> we want to read, so deal with less bytes.
> 
>  Sascha> -		if ((w = write(destfd, rw_buf, r)) < 0) {
>  Sascha> -			perror("write");
>  Sascha> -			goto out;
>  Sascha> -		}
>  Sascha> -
>  Sascha> -		if (r < now)
>  Sascha> +		if (!r)
>  Sascha>  			break;
>  
>  Sascha> -		if (w < r)
>  Sascha> -			break;
>  Sascha> +		tmp = 0;
>  Sascha> +		now = r;
>  Sascha> +		while (now) {
>  Sascha> +			w = write(destfd, rw_buf + tmp, now);
>  Sascha> +			if (w < 0) {
>  Sascha> +				perror("write");
>  Sascha> +				goto out;
>  Sascha> +			}
>  Sascha> +	                if (!w)
>  Sascha> +			        break;
>  
>  Sascha> -		count -= now;
>  Sascha> +			now -= w;
>  Sascha> +			tmp += w;
>  Sascha> +		}
>  Sascha> +
> 
> This is probably not the only place we need this. What about moving this
> to a helper function like busybox' full_write()?

I merged this for now, but I'll remember it for next time I implement
such a loop.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From marek.belisko at gmail.com  Mon Jun 28 05:08:36 2010
From: marek.belisko at gmail.com (Belisko Marek)
Date: Mon, 28 Jun 2010 11:08:36 +0200
Subject: testing barebox on calao sbc35-a9260 board
In-Reply-To: <20100628080442.GH12115@pengutronix.de>
References: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>
	<20100628080442.GH12115@pengutronix.de>
Message-ID: <AANLkTila-9RsB4fiMy35ZDW0NHUckd4fj5kELB8R7VX-@mail.gmail.com>

Hi Sascha,

On Mon, Jun 28, 2010 at 10:04 AM, Sascha Hauer <s.hauer at pengutronix.de> wrote:
> Hi Marek,
>
> On Fri, Jun 25, 2010 at 11:31:49AM +0200, Belisko Marek wrote:
>> Hi,
>>
>> I have a calao board sbc35-a9260 with u-boot pre-installed on it.
>> I would like to try barebox running on that board (also make some development).
>> I build at91sam9260ek_defconfig to try it out. I became to situation
>> that I don't know how to load image to board :)
>>
>> I try via tftp but u-boot automatically try to boot it and I got some
>> error about magic number.
>> I think about possibility just download binary to some RAM address and
>> then use go command in u-boot
>> to test if barebox binary will work.
>>
>> There exist some how-to or example how to do this?
>
> It's perfectly fine to start barebox from U-Boot with the 'go' command.
> Try 'setenv autostart no' in U-Boot to stop U-Boot from autostarting
> images.

I disable autostart and download barebox image to 0x8000 with
tftp 0x8000 barebox.bin and then jut go 0x8000 ended with:
## Starting application at 0x00008000 ...

Same I got when load latest compiled u-boot binary.

For compilation I used Codesourcery eabi toolchain arm-2009q3
with at91sam9260ek_defconfig.

Could I somehow check (without JTAG :)) if image is compiled OK
and could start on board?

>
> Sascha
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>

Thanks,

Marek

-- 
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
icq: 290551086
web: http://open-nandra.com


From eric at eukrea.com  Mon Jun 28 05:17:26 2010
From: eric at eukrea.com (=?UTF-8?B?RXJpYyBCw6luYXJk?=)
Date: Mon, 28 Jun 2010 11:17:26 +0200
Subject: testing barebox on calao sbc35-a9260 board
In-Reply-To: <AANLkTila-9RsB4fiMy35ZDW0NHUckd4fj5kELB8R7VX-@mail.gmail.com>
References: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>	<20100628080442.GH12115@pengutronix.de>
	<AANLkTila-9RsB4fiMy35ZDW0NHUckd4fj5kELB8R7VX-@mail.gmail.com>
Message-ID: <4C2868A6.7010600@eukrea.com>

Hi Marek,

Le 28/06/2010 11:08, Belisko Marek a ?crit :
> I disable autostart and download barebox image to 0x8000 with
> tftp 0x8000 barebox.bin and then jut go 0x8000 ended with:
> ## Starting application at 0x00008000 ...
>
if I remember well, on AT91 SDRAM is at 0x20000000 so actually you don't 
seem to load it in SDRAM.
For the binary to execute properly, you should load it at the right 
target address in SDRAM.

Eric


From jbe at pengutronix.de  Mon Jun 28 05:36:10 2010
From: jbe at pengutronix.de (Juergen Beisert)
Date: Mon, 28 Jun 2010 11:36:10 +0200
Subject: testing barebox on calao sbc35-a9260 board
In-Reply-To: <4C2868A6.7010600@eukrea.com>
References: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>
	<AANLkTila-9RsB4fiMy35ZDW0NHUckd4fj5kELB8R7VX-@mail.gmail.com>
	<4C2868A6.7010600@eukrea.com>
Message-ID: <201006281136.10750.jbe@pengutronix.de>

Eric B?nard wrote:
> Hi Marek,
>
> Le 28/06/2010 11:08, Belisko Marek a ?crit :
> > I disable autostart and download barebox image to 0x8000 with
> > tftp 0x8000 barebox.bin and then jut go 0x8000 ended with:
> > ## Starting application at 0x00008000 ...
>
> if I remember well, on AT91 SDRAM is at 0x20000000 so actually you don't
> seem to load it in SDRAM.
> For the binary to execute properly, you should load it at the right
> target address in SDRAM.

If barebox detects its current runtime address differs from the link address 
it copies itself to the link address first.

So writing it anywhere into sdram should work. But only, if also the link 
address is in the sdram area...

jbe

-- 
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | Phone: +49-8766-939 228     |
Vertretung Sued/Muenchen, Germany             | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686              | http://www.pengutronix.de/  |


From marek.belisko at gmail.com  Mon Jun 28 06:37:06 2010
From: marek.belisko at gmail.com (Belisko Marek)
Date: Mon, 28 Jun 2010 12:37:06 +0200
Subject: testing barebox on calao sbc35-a9260 board
In-Reply-To: <201006281136.10750.jbe@pengutronix.de>
References: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>
	<AANLkTila-9RsB4fiMy35ZDW0NHUckd4fj5kELB8R7VX-@mail.gmail.com>
	<4C2868A6.7010600@eukrea.com>
	<201006281136.10750.jbe@pengutronix.de>
Message-ID: <AANLkTinS3Lx8V5gZ17iJfRuoQuz_GU0WR7PSAUwhe2x1@mail.gmail.com>

Hi,

On Mon, Jun 28, 2010 at 11:36 AM, Juergen Beisert <jbe at pengutronix.de> wrote:
> Eric B?nard wrote:
>> Hi Marek,
>>
>> Le 28/06/2010 11:08, Belisko Marek a ?crit :
>> > I disable autostart and download barebox image to 0x8000 with
>> > tftp 0x8000 barebox.bin and then jut go 0x8000 ended with:
>> > ## Starting application at 0x00008000 ...
>>
>> if I remember well, on AT91 SDRAM is at 0x20000000 so actually you don't
>> seem to load it in SDRAM.
>> For the binary to execute properly, you should load it at the right
>> target address in SDRAM.
>
> If barebox detects its current runtime address differs from the link address
> it copies itself to the link address first.
>
> So writing it anywhere into sdram should work. But only, if also the link
> address is in the sdram area...
Seems it's not working in my case. U-boot code just jump to address which
is taken as argument according code. If barebox is copied to correct link
address and started it should work. Is there any possibility to check
link address from binary
or it's not necessary to use mkimage tool from u-boot?

>
> jbe
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| Juergen Beisert ? ? ? ? ? ? |
> Linux Solutions for Science and Industry ? ? ?| Phone: +49-8766-939 228 ? ? |
> Vertretung Sued/Muenchen, Germany ? ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? ? ?| http://www.pengutronix.de/ ?|
>

Marek

-- 
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
icq: 290551086
web: http://open-nandra.com


From m.grzeschik at pengutronix.de  Tue Jun 29 08:32:00 2010
From: m.grzeschik at pengutronix.de (Michael Grzeschik)
Date: Tue, 29 Jun 2010 14:32:00 +0200
Subject: [PATCH] omap/devices-gpmc-nand.c remove repeating words
Message-ID: <1277814720-1717-1-git-send-email-m.grzeschik@pengutronix.de>

Signed-off-by: Michael Grzeschik <m.grzeschik at pengutronix.de>
---
 board/omap/devices-gpmc-nand.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/board/omap/devices-gpmc-nand.c b/board/omap/devices-gpmc-nand.c
index bbcceaf..a25933f 100644
--- a/board/omap/devices-gpmc-nand.c
+++ b/board/omap/devices-gpmc-nand.c
@@ -95,7 +95,7 @@ static struct gpmc_config nand_cfg = {
 	.size = GPMC_SIZE_16M,
 };
 
-/** NAND platform specific settings settings */
+/** NAND platform specific settings */
 static struct gpmc_nand_platform_data nand_plat = {
 	.cs = CONFIG_MACH_OMAP_CS,
 	.device_width = GPMC_NAND_DEV_WIDTH,
@@ -111,7 +111,7 @@ static struct gpmc_nand_platform_data nand_plat = {
 };
 
 /** NAND device definition */
-static struct device_d gpmc_generic_nand_nand_device = {
+static struct device_d gpmc_generic_nand_device = {
 	.name = "gpmc_nand",
 	.map_base = OMAP_GPMC_BASE,
 	.size = 1024 * 4,	/* GPMC size */
@@ -127,7 +127,7 @@ static int gpmc_generic_nand_devices_init(void)
 {
 	/* Configure GPMC CS before register */
 	gpmc_cs_config(nand_plat.cs, &nand_cfg);
-	return register_device(&gpmc_generic_nand_nand_device);
+	return register_device(&gpmc_generic_nand_device);
 }
 
 device_initcall(gpmc_generic_nand_devices_init);
-- 
1.7.1



From eric at eukrea.com  Tue Jun 29 12:25:36 2010
From: eric at eukrea.com (=?utf-8?q?Eric=20B=C3=A9nard?=)
Date: Tue, 29 Jun 2010 18:25:36 +0200
Subject: [PATCH] eukrea_cpuimx35: better usage of LCD enable pins
Message-ID: <1277828736-13940-1-git-send-email-eric@eukrea.com>

Use the enable hook to driver the LCD's enable pin.
Unfortunalty, because of the time the LCD takes to come out of
reset, I have to use a GPIO in order to turn on/off the backlight
instead of driving it from the enable function, else we get a
flicker at power on.

Signed-off-by: Eric B?nard <eric at eukrea.com>
---
v2 :
	update init script to turn backlight on (gpio 1)

 board/eukrea_cpuimx35/env/bin/init      |    4 ++++
 board/eukrea_cpuimx35/eukrea_cpuimx35.c |   22 +++++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/board/eukrea_cpuimx35/env/bin/init b/board/eukrea_cpuimx35/env/bin/init
index 49e54c5..90007cd 100644
--- a/board/eukrea_cpuimx35/env/bin/init
+++ b/board/eukrea_cpuimx35/env/bin/init
@@ -13,10 +13,14 @@ if [ -e /dev/nand0 ]; then
 fi
 
 if [ -f /env/logo.bmp ]; then
+	fb0.enable=1
 	bmp /env/logo.bmp
+	gpio_direction_out 1 1
 elif [ -f /env/logo.bmp.lzo ]; then
 	unlzo /env/logo.bmp.lzo /logo.bmp
+	fb0.enable=1
 	bmp /logo.bmp
+	gpio_direction_out 1 1
 fi
 
 if [ -z $eth0.ethaddr ]; then
diff --git a/board/eukrea_cpuimx35/eukrea_cpuimx35.c b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
index 6eeb4a3..756546a 100644
--- a/board/eukrea_cpuimx35/eukrea_cpuimx35.c
+++ b/board/eukrea_cpuimx35/eukrea_cpuimx35.c
@@ -104,9 +104,15 @@ static struct fb_videomode imxfb_mode = {
 	.flag		= 0,
 };
 
+static void eukrea_cpuimx35_enable_display(int enable)
+{
+	gpio_direction_output(4, enable);
+}
+
 static struct imx_ipu_fb_platform_data ipu_fb_data = {
 	.mode		= &imxfb_mode,
 	.bpp		= 16,
+	.enable		= eukrea_cpuimx35_enable_display,
 };
 
 static struct device_d imxfb_dev = {
@@ -153,6 +159,7 @@ static int eukrea_cpuimx35_devices_init(void)
 	register_device(&fec_dev);
 
 	register_device(&sdram_dev);
+
 	register_device(&imxfb_dev);
 
 	armlinux_add_dram(&sdram_dev);
@@ -164,15 +171,6 @@ static int eukrea_cpuimx35_devices_init(void)
 
 device_initcall(eukrea_cpuimx35_devices_init);
 
-static int eukrea_cpuimx35_enable_display(void)
-{
-	gpio_direction_output(1, 1);
-	gpio_direction_output(0, 0);
-	return 0;
-}
-
-late_initcall(eukrea_cpuimx35_enable_display);
-
 static struct device_d eukrea_cpuimx35_serial_device = {
 	.name		= "imx_serial",
 	.map_base	= IMX_UART1_BASE,
@@ -207,6 +205,8 @@ static struct pad_desc eukrea_cpuimx35_pads[] = {
 	MX35_PAD_CTS1__UART1_CTS,
 
 	MX35_PAD_LD23__GPIO3_29,
+	MX35_PAD_CONTRAST__GPIO1_1,
+	MX35_PAD_D3_CLS__GPIO1_4,
 };
 
 static int eukrea_cpuimx35_console_init(void)
@@ -214,6 +214,10 @@ static int eukrea_cpuimx35_console_init(void)
 	mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx35_pads,
 		ARRAY_SIZE(eukrea_cpuimx35_pads));
 
+	/* screen default on to prevent flicker */
+	gpio_direction_output(4, 1);
+	/* backlight default off */
+	gpio_direction_output(1, 0);
 	/* led default off */
 	gpio_direction_output(32 * 2 + 29, 1);
 
-- 
1.6.3.3



From eric at eukrea.com  Tue Jun 29 12:30:12 2010
From: eric at eukrea.com (=?ISO-8859-1?Q?Eric_B=E9nard?=)
Date: Tue, 29 Jun 2010 18:30:12 +0200
Subject: Pending patches for 2010.07
Message-ID: <4C2A1F94.8030808@eukrea.com>

Hi Sascha,

the following patches are needed to get good support of cpuimx35 for 
2010.07 :

[PATCH 1/2] imx-ipu-fb: Add board specific hook to enable display
http://lists.infradead.org/pipermail/barebox/2010-June/001068.html
[PATCH 2/2] imx-ipu-fb: do not enable framebuffer on startup
http://lists.infradead.org/pipermail/barebox/2010-June/001069.html

[PATCH] eukrea_cpuimx35: boot update
http://lists.infradead.org/pipermail/barebox/2010-June/001071.html

[PATCH] eukrea_cpuimx35: better usage of LCD enable pins
http://lists.infradead.org/pipermail/barebox/2010-June/001095.html
(for this last one, please take the patch sent today, I forget to put v2 
in the subject)

Is there something to rework in theses patches to get them into 
thursday's release (I can do it tomorrow if necessary) ?

Thanks
Eric


From s.hauer at pengutronix.de  Wed Jun 30 02:57:57 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 30 Jun 2010 08:57:57 +0200
Subject: testing barebox on calao sbc35-a9260 board
In-Reply-To: <AANLkTinS3Lx8V5gZ17iJfRuoQuz_GU0WR7PSAUwhe2x1@mail.gmail.com>
References: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>
	<AANLkTila-9RsB4fiMy35ZDW0NHUckd4fj5kELB8R7VX-@mail.gmail.com>
	<4C2868A6.7010600@eukrea.com>
	<201006281136.10750.jbe@pengutronix.de>
	<AANLkTinS3Lx8V5gZ17iJfRuoQuz_GU0WR7PSAUwhe2x1@mail.gmail.com>
Message-ID: <20100630065757.GO12115@pengutronix.de>

On Mon, Jun 28, 2010 at 12:37:06PM +0200, Belisko Marek wrote:
> Hi,
> 
> On Mon, Jun 28, 2010 at 11:36 AM, Juergen Beisert <jbe at pengutronix.de> wrote:
> > Eric B?nard wrote:
> >> Hi Marek,
> >>
> >> Le 28/06/2010 11:08, Belisko Marek a ?crit :
> >> > I disable autostart and download barebox image to 0x8000 with
> >> > tftp 0x8000 barebox.bin and then jut go 0x8000 ended with:
> >> > ## Starting application at 0x00008000 ...
> >>
> >> if I remember well, on AT91 SDRAM is at 0x20000000 so actually you don't
> >> seem to load it in SDRAM.
> >> For the binary to execute properly, you should load it at the right
> >> target address in SDRAM.
> >
> > If barebox detects its current runtime address differs from the link address
> > it copies itself to the link address first.
> >
> > So writing it anywhere into sdram should work. But only, if also the link
> > address is in the sdram area...
> Seems it's not working in my case. U-boot code just jump to address which
> is taken as argument according code. If barebox is copied to correct link
> address and started it should work. Is there any possibility to check
> link address from binary
> or it's not necessary to use mkimage tool from u-boot?

Here are the necessary steps to run the barebox.bin file from U-Boot:

tftp 0x20000000 barebox.bin
go 0x20000000

As Eric stated the 9260 has SDRAM at 0x20000000, so this would be an
appropriate load address. barebox then relocates itself to 0x23f00000
according to the link address which you can check by doing 'make
barebox.S' and looking at barebox.S.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun 30 03:02:14 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 30 Jun 2010 09:02:14 +0200
Subject: testing barebox on calao sbc35-a9260 board
In-Reply-To: <20100628083215.GF2681@jasper.tkos.co.il>
References: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>
	<20100628080442.GH12115@pengutronix.de>
	<20100628083215.GF2681@jasper.tkos.co.il>
Message-ID: <20100630070214.GP12115@pengutronix.de>

On Mon, Jun 28, 2010 at 11:32:15AM +0300, Baruch Siach wrote:
> Hi Sascha,
> 
> On Mon, Jun 28, 2010 at 10:04:42AM +0200, Sascha Hauer wrote:
> > On Fri, Jun 25, 2010 at 11:31:49AM +0200, Belisko Marek wrote:
> > > I have a calao board sbc35-a9260 with u-boot pre-installed on it.
> > > I would like to try barebox running on that board (also make some development).
> > > I build at91sam9260ek_defconfig to try it out. I became to situation
> > > that I don't know how to load image to board :)
> > > 
> > > I try via tftp but u-boot automatically try to boot it and I got some
> > > error about magic number.
> > > I think about possibility just download binary to some RAM address and
> > > then use go command in u-boot
> > > to test if barebox binary will work.
> > > 
> > > There exist some how-to or example how to do this?
> > 
> > It's perfectly fine to start barebox from U-Boot with the 'go' command.
> > Try 'setenv autostart no' in U-Boot to stop U-Boot from autostarting
> > images.
> 
> Is there a way to do the same on Barebox? Currently 'go barebox.bin' in ramfs 
> returns -EINVAL from memmap.

If stored in a file it is indeed not runnable as the file is fragmented
in memory. It would be possible to copy it to a linear memory to memmap
it, but currently this is not implemented and I'm not sure this is a
good idea. It's possible to do a 'tftp barebox.bin /dev/ram0; go
/dev/ram0' instead. (or 'memcpy -s barebox.bin <sdramadr> 0x0 <size>; go
<sdramadr> if the file is already in the filesystem)

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun 30 03:03:55 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 30 Jun 2010 09:03:55 +0200
Subject: testing barebox on calao sbc35-a9260 board
In-Reply-To: <AANLkTila-9RsB4fiMy35ZDW0NHUckd4fj5kELB8R7VX-@mail.gmail.com>
References: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>
	<20100628080442.GH12115@pengutronix.de>
	<AANLkTila-9RsB4fiMy35ZDW0NHUckd4fj5kELB8R7VX-@mail.gmail.com>
Message-ID: <20100630070355.GQ12115@pengutronix.de>

On Mon, Jun 28, 2010 at 11:08:36AM +0200, Belisko Marek wrote:
> Hi Sascha,
> 
> 
> I disable autostart and download barebox image to 0x8000 with
> tftp 0x8000 barebox.bin and then jut go 0x8000 ended with:
> ## Starting application at 0x00008000 ...
> 
> Same I got when load latest compiled u-boot binary.

U-Boot binaries compiled for starting from flash are usually not
suitable to be run as second stage from SDRAM. Most of the time
it requires at least a include/config.h tweaking.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun 30 03:17:07 2010
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 30 Jun 2010 09:17:07 +0200
Subject: Pending patches for 2010.07
In-Reply-To: <4C2A1F94.8030808@eukrea.com>
References: <4C2A1F94.8030808@eukrea.com>
Message-ID: <20100630071707.GR12115@pengutronix.de>

Hi Eric,

On Tue, Jun 29, 2010 at 06:30:12PM +0200, Eric B?nard wrote:
> Hi Sascha,
>
> the following patches are needed to get good support of cpuimx35 for  
> 2010.07 :

What's missing first is the board support. It's currently sitting in
-next.

>
> [PATCH 1/2] imx-ipu-fb: Add board specific hook to enable display
> http://lists.infradead.org/pipermail/barebox/2010-June/001068.html
> [PATCH 2/2] imx-ipu-fb: do not enable framebuffer on startup
> http://lists.infradead.org/pipermail/barebox/2010-June/001069.html

I applied these to next a few moments ago.

>
> [PATCH] eukrea_cpuimx35: boot update
> http://lists.infradead.org/pipermail/barebox/2010-June/001071.html
>
> [PATCH] eukrea_cpuimx35: better usage of LCD enable pins
> http://lists.infradead.org/pipermail/barebox/2010-June/001095.html
> (for this last one, please take the patch sent today, I forget to put v2  
> in the subject)

These do not apply. I haven't looked into it though.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From eric at eukrea.com  Wed Jun 30 03:49:24 2010
From: eric at eukrea.com (=?ISO-8859-15?Q?Eric_B=E9nard?=)
Date: Wed, 30 Jun 2010 09:49:24 +0200
Subject: Pending patches for 2010.07
In-Reply-To: <20100630071707.GR12115@pengutronix.de>
References: <4C2A1F94.8030808@eukrea.com>
	<20100630071707.GR12115@pengutronix.de>
Message-ID: <4C2AF704.10301@eukrea.com>

Hi Sascha,

Le 30/06/2010 09:17, Sascha Hauer a ?crit :
> On Tue, Jun 29, 2010 at 06:30:12PM +0200, Eric B?nard wrote:
>> Hi Sascha,
>>
>> the following patches are needed to get good support of cpuimx35 for
>> 2010.07 :
>
> What's missing first is the board support. It's currently sitting in
> -next.
>
OK sorry, I forget that next is 2010.08 ;-)
>>
>> [PATCH 1/2] imx-ipu-fb: Add board specific hook to enable display
>> http://lists.infradead.org/pipermail/barebox/2010-June/001068.html
>> [PATCH 2/2] imx-ipu-fb: do not enable framebuffer on startup
>> http://lists.infradead.org/pipermail/barebox/2010-June/001069.html
>
> I applied these to next a few moments ago.
>
git says 33 min ago ;-)

>>
>> [PATCH] eukrea_cpuimx35: boot update
>> http://lists.infradead.org/pipermail/barebox/2010-June/001071.html
>>
>> [PATCH] eukrea_cpuimx35: better usage of LCD enable pins
>> http://lists.infradead.org/pipermail/barebox/2010-June/001095.html
>> (for this last one, please take the patch sent today, I forget to put v2
>> in the subject)
>
> These do not apply. I haven't looked into it though.
>
ok strange, I'm rebasing and resending.

Thanks,
Eric


From eric at eukrea.com  Wed Jun 30 04:14:49 2010
From: eric at eukrea.com (=?ISO-8859-15?Q?Eric_B=E9nard?=)
Date: Wed, 30 Jun 2010 10:14:49 +0200
Subject: Pending patches for 2010.07
In-Reply-To: <20100630071707.GR12115@pengutronix.de>
References: <4C2A1F94.8030808@eukrea.com>
	<20100630071707.GR12115@pengutronix.de>
Message-ID: <4C2AFCF9.70707@eukrea.com>

Hi Sascha,

Le 30/06/2010 09:17, Sascha Hauer a ?crit :
>> [PATCH] eukrea_cpuimx35: boot update
>> http://lists.infradead.org/pipermail/barebox/2010-June/001071.html
>>
>> [PATCH] eukrea_cpuimx35: better usage of LCD enable pins
>> http://lists.infradead.org/pipermail/barebox/2010-June/001095.html
>> (for this last one, please take the patch sent today, I forget to put v2
>> in the subject)
>
> These do not apply. I haven't looked into it though.
>
in fact I think these should apply to next I think, sorry I mixed next & 
master !

Thanks,
Eric


From marek.belisko at gmail.com  Wed Jun 30 07:39:51 2010
From: marek.belisko at gmail.com (Belisko Marek)
Date: Wed, 30 Jun 2010 13:39:51 +0200
Subject: testing barebox on calao sbc35-a9260 board
In-Reply-To: <20100630065757.GO12115@pengutronix.de>
References: <AANLkTimjBoeR8qBpdmbcuRgxr6o7xNRKaYQ6OdyDi_Fu@mail.gmail.com>
	<AANLkTila-9RsB4fiMy35ZDW0NHUckd4fj5kELB8R7VX-@mail.gmail.com>
	<4C2868A6.7010600@eukrea.com>
	<201006281136.10750.jbe@pengutronix.de>
	<AANLkTinS3Lx8V5gZ17iJfRuoQuz_GU0WR7PSAUwhe2x1@mail.gmail.com>
	<20100630065757.GO12115@pengutronix.de>
Message-ID: <AANLkTimNUQvQohAOv2pyKsPXWgDg12AnIyrJr5A52js5@mail.gmail.com>

On Wed, Jun 30, 2010 at 8:57 AM, Sascha Hauer <s.hauer at pengutronix.de> wrote:
> On Mon, Jun 28, 2010 at 12:37:06PM +0200, Belisko Marek wrote:
>> Hi,
>>
>> On Mon, Jun 28, 2010 at 11:36 AM, Juergen Beisert <jbe at pengutronix.de> wrote:
>> > Eric B?nard wrote:
>> >> Hi Marek,
>> >>
>> >> Le 28/06/2010 11:08, Belisko Marek a ?crit :
>> >> > I disable autostart and download barebox image to 0x8000 with
>> >> > tftp 0x8000 barebox.bin and then jut go 0x8000 ended with:
>> >> > ## Starting application at 0x00008000 ...
>> >>
>> >> if I remember well, on AT91 SDRAM is at 0x20000000 so actually you don't
>> >> seem to load it in SDRAM.
>> >> For the binary to execute properly, you should load it at the right
>> >> target address in SDRAM.
>> >
>> > If barebox detects its current runtime address differs from the link address
>> > it copies itself to the link address first.
>> >
>> > So writing it anywhere into sdram should work. But only, if also the link
>> > address is in the sdram area...
>> Seems it's not working in my case. U-boot code just jump to address which
>> is taken as argument according code. If barebox is copied to correct link
>> address and started it should work. Is there any possibility to check
>> link address from binary
>> or it's not necessary to use mkimage tool from u-boot?
>
> Here are the necessary steps to run the barebox.bin file from U-Boot:
>
> tftp 0x20000000 barebox.bin
> go 0x20000000

Following steps give me the also only Starting application at
0x20000000 and nothing more.
>
> As Eric stated the 9260 has SDRAM at 0x20000000, so this would be an
> appropriate load address. barebox then relocates itself to 0x23f00000
> according to the link address which you can check by doing 'make
> barebox.S' and looking at barebox.S.
Yes it seems link address ( 0x23f00000) is correct according barebox.S file.
Strange.

Anyway thanks for support and advices.
>
> Sascha
>
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>



-- 
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
icq: 290551086
web: http://open-nandra.com


From list at lucaceresoli.net  Thu Jun 24 08:32:25 2010
From: list at lucaceresoli.net (Luca Ceresoli)
Date: Thu, 24 Jun 2010 14:32:25 +0200
Subject: Regression: not booting anymore on OMAP35xx
Message-ID: <L4IQU1$4731D5E42E435C795207D3BFB302BAD3@aruba.it>

Sascha Hauer wrote:
> On Tue, Jun 22, 2010 at 04:04:52PM +0200, Luca Ceresoli wrote:
> > Sascha Hauer wrote:
> > > Hi Luca,
> > > 
> > > On Tue, Jun 22, 2010 at 02:26:11PM +0200, Luca Ceresoli wrote:
> > > > Hi,
> > > > 
> > > 
> > > Seems that I lost the call to arch_init_lowlevel. Does the following
> > > patch help?
> > 
> > I'm afraid it doesn't seem to.
> > It fails with the same symptoms.
> > 
> > Luca
> > 
> > > 
> > > 
> > > diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
> > > index eea7dcf..91d2ccd 100644
> > > --- a/arch/arm/cpu/start.c
> > > +++ b/arch/arm/cpu/start.c
> > > @@ -50,6 +50,8 @@ void __naked __bare_init reset(void)
> > >  {
> > >  	uint32_t r;
> > >  
> > > +	arch_init_lowlevel();
> > > +
> 
> Ok, this has to be done *after* switching the cpu to SVC32 mode.
> 
> I tested this on my beagle board and now it works again. I pushed
> a patch to the master repository.

Sascha, thank you for the prompt response.
Unfortunately the new version works only partially with my Beagle
Board (rev. C4).

I tested commit:
 46976f7 OMAP: fix compilation

- Test 1: the board is always powered.
  Press RESET with the USER key pressed.
  10 tests, 10 passed.

- Test 2: the board is not powered.
  Turn turn it on with the USER key pressed.
  Turn turn it off again at the end of the test.
  10 tests, 5 passed, 5 failed.

During all of the 20 tests, barebox.bin was always the same.
I didn't recompile it.

OTOH the commit before the "reimplement in C" passes also test 2.

I hope this gives enough hints to solve the problem.

Luca




