Skip to contentSkip to conversation

dnet: Dave DNET ethernet controller driver

PATCH In review Ilya Yanok 15 participants 58 messages Mar 11, 2009 – Mar 13, 2009

Subsystems (2)
lore
Share & tools
lore

Ilya Yanok

author
#0 lore raw

PATCH 1/1 dnet: Dave DNET ethernet controller driver

Driver for Dave DNET ethernet controller found on Dave/DENX QongEVB-LITE FPGA. Heavily based on Dave sources, I've just adopted it to current kernel version and done some code cleanup.

---
 drivers/net/Kconfig  |   11 +
 drivers/net/Makefile |    1 +
 drivers/net/dnet.c   | 1019 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/dnet.h   |  226 +++++++++++
 4 files changed, 1257 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/dnet.c
 create mode 100644 drivers/net/dnet.h
drivers/net/Kconfig +11 -0
index a2f185f..5c28b06 100644
@@ -1040,6 +1040,17 @@ config NI65
 	  To compile this driver as a module, choose M here. The module
 	  will be called ni65.
 
+config DNET
+	tristate "Dave ethernet support (DNET)"
+	depends on NET_ETHERNET
+	select PHYLIB
+	help
+	  The Dave ethernet interface (DNET) is found on Qong Board FPGA.
+	  Say Y to include support for the DNET chip.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called dnet.
+
 source "drivers/net/tulip/Kconfig"
 
 config AT1700
drivers/net/Makefile +1 -0
index aca8492..6d9bba5 100644
@@ -231,6 +231,7 @@ obj-$(CONFIG_ENC28J60) += enc28j60.o
 
 obj-$(CONFIG_XTENSA_XT2000_SONIC) += xtsonic.o
 
+obj-$(CONFIG_DNET) += dnet.o
 obj-$(CONFIG_MACB) += macb.o
 
 obj-$(CONFIG_ARM) += arm/
drivers/net/dnet.c new file +1019 -0

1,019 lines not on this page · raw message

drivers/net/dnet.h new file +226 -0

226 lines not on this page · raw message

Signature · 7 lines
1.6.0.6


-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php
#1 lore raw

drivers/net/dnet.c line 448

Quoted 11 lines · Ilya Yanok

Driver for Dave DNET ethernet controller found on Dave/DENX QongEVB-LITE FPGA. Heavily based on Dave sources, I've just adopted it to current kernel version and done some code cleanup.

drivers/net/dnet.c new file +3 -0
+		skb = dev_alloc_skb(pkt_len + 5);
+		if (skb != NULL) {
 
 
+			skb->dev = dev;

minor nit : This is not necessary anymore

	eth_type_trans(skb, dev) does the skb->dev = dev; initialization

in recent kernels.

commit 4c13eb6657fe9ef7b4dc8f1a405c902e9e5234e0

Author: Arnaldo Carvalho de Melo <[email protected]>
Date:   Wed Apr 25 17:40:23 2007 -0700

[ETH]: Make eth_type_trans set skb->dev like the other *_type_trans

One less thing for drivers writers to worry about.

drivers/net/dnet.c line 460

Quoted 12 lines
drivers/net/dnet.c new file +12 -0
+			/* Align IP on 16 byte boundaries */
+			skb_reserve(skb, 2);
+			/*
+			 * 'skb_put()' points to the start of sk_buff
+			 * data area.
+			 */
+			data_ptr = (unsigned int *)skb_put(skb, pkt_len);
+			for (i = 0; i < (pkt_len + 3) >> 2; i++)
+				*data_ptr++ = dnet_readl(bp, RX_DATA_FIFO);
+			skb->protocol = eth_type_trans(skb, dev);
+			netif_receive_skb(skb);
+			bp->dev->last_rx = jiffies;

This last_rx init is not anymore needed :

commit babcda74e9d96bb58fd9c6c5112dbdbff169e695

Author: David S. Miller <[email protected]>
Date:   Mon Nov 3 21:11:17 2008 -0800

drivers/net: Kill now superfluous ->last_rx stores.

The generic packet receive code takes care of setting netdev->last_rx when necessary, for the sake of the bonding ARP monitor.

Drivers need not do it any more.

Some cases had to be skipped over because the drivers were making use of the ->last_rx value themselves.

drivers/net/dnet.c line 465

Quoted 5 lines
drivers/net/dnet.c new file +5 -0
+			npackets++;
+		} else
+			printk(KERN_NOTICE
+			       "%s: No memory to allocate a sk_buff of "
+			       "size %d.\n", dev->name, pkt_len);

pkt_len is an "unsigned int", so please use %u

Review

Quoted 2 lines
(quoted diff) +2 -0
+	}
+

+static struct ethtool_ops dnet_ethtool_ops = {
+ .get_settings = dnet_get_settings,
+ .set_settings = dnet_set_settings,
+ .get_drvinfo = dnet_get_drvinfo,
+ .get_link = ethtool_op_get_link,
+};
+

Please add a const qualifier to this.

struct dnet {
+ void __iomem *regs;
+ spinlock_t lock;
+ struct platform_device *pdev;
+ struct net_device *dev;
+ struct net_device_stats stats;
+ struct dnet_stats hw_stats;
+ unsigned int capabilities; /* read from FPGA */
+ struct napi_struct napi;

Are you sure you need a "struct net_device_stats stats;" in "struct dnet" ? One is already included in "struct net_device", you probably can use it.

Thank you

author
#2 lore raw

PATCH 1/1 dnet: Dave DNET ethernet controller driver (updated)

Driver for Dave DNET ethernet controller found on Dave/DENX QongEVB-LITE FPGA. Heavily based on Dave sources, I've just adopted it to current kernel version and done some code cleanup.

---
 drivers/net/Kconfig  |   11 +
 drivers/net/Makefile |    1 +
 drivers/net/dnet.c   |  994 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/dnet.h   |  225 ++++++++++++
 4 files changed, 1231 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/dnet.c
 create mode 100644 drivers/net/dnet.h
drivers/net/Kconfig +11 -0
index a2f185f..5c28b06 100644
@@ -1040,6 +1040,17 @@ config NI65
 	  To compile this driver as a module, choose M here. The module
 	  will be called ni65.
 
+config DNET
+	tristate "Dave ethernet support (DNET)"
+	depends on NET_ETHERNET
+	select PHYLIB
+	help
+	  The Dave ethernet interface (DNET) is found on Qong Board FPGA.
+	  Say Y to include support for the DNET chip.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called dnet.
+
 source "drivers/net/tulip/Kconfig"
 
 config AT1700
drivers/net/Makefile +1 -0
index aca8492..6d9bba5 100644
@@ -231,6 +231,7 @@ obj-$(CONFIG_ENC28J60) += enc28j60.o
 
 obj-$(CONFIG_XTENSA_XT2000_SONIC) += xtsonic.o
 
+obj-$(CONFIG_DNET) += dnet.o
 obj-$(CONFIG_MACB) += macb.o
 
 obj-$(CONFIG_ARM) += arm/
drivers/net/dnet.c new file +994 -0

994 lines not on this page · raw message

drivers/net/dnet.h new file +225 -0

225 lines not on this page · raw message

Signature · 1 line
1.6.0.6
maintainer Applied
#3 lore raw

Re: [PATCH] dnet: Dave DNET ethernet controller driver (updated)

From: Ilya Yanok <[email protected]>
Date: Thu, 12 Mar 2009 02:33:07 +0300

Quoted 5 lines

Driver for Dave DNET ethernet controller found on Dave/DENX QongEVB-LITE FPGA. Heavily based on Dave sources, I've just adopted it to current kernel version and done some code cleanup.

Applied, but I had to add the following patch to fix warnings and actual errors on 64-bit.

dnet: Fix warnings on 64-bit.

---
 drivers/net/dnet.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/dnet.c +5 -5
index 92c3bd3..4b96974 100644
@@ -553,8 +553,8 @@ static int dnet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	tx_status = dnet_readl(bp, TX_STATUS);
 
-	pr_debug("start_xmit: len %u head %p data %p tail %p end %p\n",
-	       skb->len, skb->head, skb->data, skb->tail, skb->end);
+	pr_debug("start_xmit: len %u head %p data %p\n",
+	       skb->len, skb->head, skb->data);
 	dnet_print_skb(skb);
 
 	/* frame size (words) */
@@ -564,11 +564,11 @@ static int dnet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	tx_status = dnet_readl(bp, TX_STATUS);
 
-	bufp = (unsigned int *)(((u32) skb->data) & 0xFFFFFFFC);
+	bufp = (unsigned int *)(((unsigned long) skb->data) & ~0x3UL);
 	wrsz = (u32) skb->len + 3;
-	wrsz += ((u32) skb->data) & 0x3;
+	wrsz += ((unsigned long) skb->data) & 0x3;
 	wrsz >>= 2;
-	tx_cmd = ((((unsigned int)(skb->data)) & 0x03) << 16) | (u32) skb->len;
+	tx_cmd = ((((unsigned long)(skb->data)) & 0x03) << 16) | (u32) skb->len;
 
 	/* check if there is enough room for the current frame */
 	if (wrsz < (DNET_FIFO_SIZE - dnet_readl(bp, TX_FIFO_WCNT))) {
Signature · 1 line
1.6.2
#4 lore raw
In reply to Ilya Yanok
Quoted 11 lines · On Wed, 11 Mar 2009 05:29:09 +0300 Ilya Yanok <[email protected]> wrote:
drivers/net/dnet.c new file +11 -0
+static char ethaddr[18];
+
+module_param_string(ethaddr, ethaddr, sizeof(ethaddr), 0);
+
+static void get_mac_addr(struct net_device *nd, unsigned char *pmac)
+{
+	int i;
+	char *p = ethaddr;
+
+	ethaddr[17] = 0;
+	for (i = 0; i < ETH_ALEN; i++, p++) {

drivers/net/dnet.c line 50

Quoted 10 lines
drivers/net/dnet.c new file +10 -0
+		pmac[i] = simple_strtoul(p, &p, 16);
+		if (*p != ':')
+			break;
+	}
+	if (i != ETH_ALEN - 1) {
+		pr_err("Wrong MAC address format!\n");
+		memset(pmac, 0, ETH_ALEN);
+	}
+}
+

Do you still need this? Only works with one board, configuration via module parameters is discouraged. Same effect can be done by setting mac address with regular tools.

#5 lore raw

Hi,

Quoted 20 lines · Stephen Hemminger
Quoted 17 lines · On Wed, 11 Mar 2009 05:29:09 +0300 Ilya Yanok <[email protected]> wrote:
drivers/net/dnet.c new file +17 -0
+static char ethaddr[18];
+
+module_param_string(ethaddr, ethaddr, sizeof(ethaddr), 0);
+
+static void get_mac_addr(struct net_device *nd, unsigned char *pmac)
+{
+	int i;
+	char *p = ethaddr;
+
+	ethaddr[17] = 0;
+	for (i = 0; i < ETH_ALEN; i++, p++) {
+		pmac[i] = simple_strtoul(p, &p, 16);
+		if (*p != ':')
+			break;
+	}
+	if (i != ETH_ALEN - 1) {
+		pr_err("Wrong MAC address format!\n");
Quoted 8 lines

drivers/net/dnet.c line 50

Quoted 4 lines
drivers/net/dnet.c new file +4 -0
+		memset(pmac, 0, ETH_ALEN);
+	}
+}
+

Do you still need this? Only works with one board, configuration via module parameters is discouraged. Same effect can be done by setting mac address with regular tools.

Except for root over nfs. Ok, the answer to this is usually 'use initrd', but this is still a pita on embedded systems.

Sascha

Signature · 4 lines
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 |
maintainer
#6 lore raw

From: Sascha Hauer <[email protected]>
Date: Wed, 11 Mar 2009 09:44:30 +0100

Quoted 7 lines · Stephen Hemminger
Quoted 3 lines

Do you still need this? Only works with one board, configuration via module parameters is discouraged. Same effect can be done by setting mac address with regular tools.

Except for root over nfs. Ok, the answer to this is usually 'use initrd', but this is still a pita on embedded systems.

Please remove this code. If we let you do it, we have to let everyone else do it too, and that's something we don't want to do.

There are other ways you can handle this, for example have your board firmware properly program the MAC address into the card at power-on, and then have the driver here look in the MAC address registers to see if a valid ethernet address has been left there.

#7 lore raw
Quoted 11 lines · David Miller

From: Sascha Hauer <[email protected]>
Date: Wed, 11 Mar 2009 09:44:30 +0100

Quoted 7 lines · Stephen Hemminger
Quoted 3 lines

Do you still need this? Only works with one board, configuration via module parameters is discouraged. Same effect can be done by setting mac address with regular tools.

Except for root over nfs. Ok, the answer to this is usually 'use initrd', but this is still a pita on embedded systems.

Quoted 7 lines

Please remove this code. If we let you do it, we have to let everyone else do it too, and that's something we don't want to do.

There are other ways you can handle this, for example have your board firmware properly program the MAC address into the card at power-on, and then have the driver here look in the MAC address registers to see if a valid ethernet address has been left there.

Cool, that's how I do it on many boards I have, but I always had the feeling I was flying under the radar with it.

Sascha

Signature · 4 lines
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 |
#8 lore raw

Dear David,

Quoted 11 lines · David Miller

From: Sascha Hauer <[email protected]>
Date: Wed, 11 Mar 2009 09:44:30 +0100

Quoted 7 lines · Stephen Hemminger
Quoted 3 lines

Do you still need this? Only works with one board, configuration via module parameters is discouraged. Same effect can be done by setting mac address with regular tools.

Except for root over nfs. Ok, the answer to this is usually 'use initrd', but this is still a pita on embedded systems.

Quoted 7 lines

Please remove this code. If we let you do it, we have to let everyone else do it too, and that's something we don't want to do.

There are other ways you can handle this, for example have your board firmware properly program the MAC address into the card at power-on, and then have the driver here look in the MAC address registers to see if a valid ethernet address has been left there.

How do you then handle situations where this is impossible? Say, when the firmware cannot write to those registers for example because the ethernet controller is not even powered on (to reduce power consump- tion), but will get powered on only in Linux when the driver gets loaded (i. e. on demand only, not always)?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected]
"If God had wanted us to use the metric system, Jesus would have  had
10 apostles."
#9 lore raw

Hi Wolfgang,

Quoted 22 lines · Wolfgang Denk

Dear David,

Quoted 11 lines · David Miller

From: Sascha Hauer <[email protected]>
Date: Wed, 11 Mar 2009 09:44:30 +0100

Quoted 7 lines · Stephen Hemminger
Quoted 3 lines

Do you still need this? Only works with one board, configuration via module parameters is discouraged. Same effect can be done by setting mac address with regular tools.

Except for root over nfs. Ok, the answer to this is usually 'use initrd', but this is still a pita on embedded systems.

Quoted 7 lines

Please remove this code. If we let you do it, we have to let everyone else do it too, and that's something we don't want to do.

There are other ways you can handle this, for example have your board firmware properly program the MAC address into the card at power-on, and then have the driver here look in the MAC address registers to see if a valid ethernet address has been left there.

Quoted 5 lines

How do you then handle situations where this is impossible? Say, when the firmware cannot write to those registers for example because the ethernet controller is not even powered on (to reduce power consump- tion), but will get powered on only in Linux when the driver gets loaded (i. e. on demand only, not always)?

I never had this situation, but I guess in this case I have a working userspace and can use ifconfig to set the MAC address.

Sascha

Signature · 4 lines
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 |
maintainer
#10 lore raw
In reply to Wolfgang Denk

From: Wolfgang Denk <[email protected]>
Date: Wed, 11 Mar 2009 10:09:38 +0100

Quoted 5 lines

How do you then handle situations where this is impossible? Say, when the firmware cannot write to those registers for example because the ethernet controller is not even powered on (to reduce power consump- tion), but will get powered on only in Linux when the driver gets loaded (i. e. on demand only, not always)?

That's what NVRAM, CMOS, EEPROM's and other writable long-term storage areas are for.

To be quite honest with you, any ethernet device that doesn't have an EEPROM where the chip instance's ethernet address is stored is completely broken.

#11 lore raw
Quoted 9 lines · David Miller

From: Wolfgang Denk <[email protected]>
Date: Wed, 11 Mar 2009 10:09:38 +0100

Quoted 5 lines

How do you then handle situations where this is impossible? Say, when the firmware cannot write to those registers for example because the ethernet controller is not even powered on (to reduce power consump- tion), but will get powered on only in Linux when the driver gets loaded (i. e. on demand only, not always)?

Quoted 6 lines

That's what NVRAM, CMOS, EEPROM's and other writable long-term storage areas are for.

To be quite honest with you, any ethernet device that doesn't have an EEPROM where the chip instance's ethernet address is stored is completely broken.

Not having persistent MAC storage makes it quite hard from userspace to tie specific network configuration to a specific device, because (rightly so) kernel network interface names are *not* stable. And since most manufacturers don't bother to put serial numbers into things like the USB descriptors, there is now way to uniquely identify if you plug two in. LOSE.

Save a kitten. Add an EEPROM.

Dan

#12 lore raw
In reply to David Miller
Quoted 9 lines · David Miller

From: Wolfgang Denk <[email protected]>
Date: Wed, 11 Mar 2009 10:09:38 +0100

Quoted 5 lines

How do you then handle situations where this is impossible? Say, when the firmware cannot write to those registers for example because the ethernet controller is not even powered on (to reduce power consump- tion), but will get powered on only in Linux when the driver gets loaded (i. e. on demand only, not always)?

Quoted 6 lines

That's what NVRAM, CMOS, EEPROM's and other writable long-term storage areas are for.

To be quite honest with you, any ethernet device that doesn't have an EEPROM where the chip instance's ethernet address is stored is completely broken.

However, it's quite common in embedded systems where eeprom chips cost money and high quantity projects are cost optimized. So we cannot neglect reality here. I know almost no ARM board that has a separate eeprom for the network chip, and especially SoC-integrated MAC units don't even have hardware interfaces for that.

rsc

Signature · 4 lines
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 |
#13 lore raw
In reply to David Miller
Quoted 6 lines · David Miller

That's what NVRAM, CMOS, EEPROM's and other writable long-term storage areas are for.

To be quite honest with you, any ethernet device that doesn't have an EEPROM where the chip instance's ethernet address is stored is completely broken.

If that is the case, pretty much every SOHO NAS device (running linux + samba) being sold in your nearest IT shop is completly broken.

In such machines, typically the mac address is stored in bootloader's configuration area in NOR/NAND flash.

Signature · 1 line
"rm -rf" only sounds scary if you don't have backups

-------------------------------------------------------------------

List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php
maintainer
#14 lore raw

From: Riku Voipio <[email protected]>
Date: Wed, 11 Mar 2009 21:15:30 +0200

Quoted 2 lines

In such machines, typically the mac address is stored in bootloader's configuration area in NOR/NAND flash.

That's a perfectly fine solution as well.

Anything that specifies a unique MAC address somewhere on the board is OK.

It's this "generate a random MAC address every bootup" that I am totally against. A situation where there is no permanent MAC address stored anywhere.

#15 lore raw
In reply to David Miller
Quoted 5 lines · David Miller

From: Sascha Hauer <[email protected]>
Date: Wed, 11 Mar 2009 09:44:30 +0100

Quoted 1 line

[some code to pass the MAC address as module parameters]

Quoted 7 lines

Please remove this code. If we let you do it, we have to let everyone else do it too, and that's something we don't want to do.

There are other ways you can handle this, for example have your board firmware properly program the MAC address into the card at power-on, and then have the driver here look in the MAC address registers to see if a valid ethernet address has been left there.

It's still a pain to have to do this. Many embedded systems that I have seen have a bootloader which I can't modify to do that, but the bootloader allows me to save the kernel command line into some kind of volatile storage. Så being able to set the MAC address with a:

setenv cmdline foo.hwaddr=00:de:ad:be:ef:ed

is very nice because it allows me to use a NFS root without having to jump through hoops with initrds an such.

Actually, I wish we had a generic way of doing that, so that could set the mac address of any ethernet interface from the kernel command in a nice and supported way.

/Christer

#16 lore raw
Quoted 3 lines · Christer Weinigel

Actually, I wish we had a generic way of doing that, so that could set the mac address of any ethernet interface from the kernel command in a nice and supported way.

You're not the first to suggest that; that's precisely what I've suggested in the past (though I probably couldn't find the postings if I tried now.) I've seen it all, from people trying to invent ATAGs to pass ethernet addresses to the kernel, driver specific command lines, and hard coded ethernet addresses in drivers.

I'm sure David would give full and proper consideration to a clean patch adding such support in a generic way (even if the resulting answer is still a 'no'.)

#17 lore raw
In reply to Christer Weinigel
Quoted 23 lines · On Wed, 11 Mar 2009 21:56:06 +0100 Christer Weinigel <[email protected]>…
Quoted 5 lines · David Miller

From: Sascha Hauer <[email protected]>
Date: Wed, 11 Mar 2009 09:44:30 +0100

Quoted 1 line

[some code to pass the MAC address as module parameters]

Quoted 7 lines

Please remove this code. If we let you do it, we have to let everyone else do it too, and that's something we don't want to do.

There are other ways you can handle this, for example have your board firmware properly program the MAC address into the card at power-on, and then have the driver here look in the MAC address registers to see if a valid ethernet address has been left there.

It's still a pain to have to do this. Many embedded systems that I have seen have a bootloader which I can't modify to do that, but the bootloader allows me to save the kernel command line into some kind of volatile storage. Så being able to set the MAC address with a:

setenv cmdline foo.hwaddr=00:de:ad:be:ef:ed

Quoted 8 lines

is very nice because it allows me to use a NFS root without having to jump through hoops with initrds an such.

Actually, I wish we had a generic way of doing that, so that could set the mac address of any ethernet interface from the kernel command in a nice and supported way.

/Christer

The problem is that usually users end up with all devices with the same address, unless there is some other procedure to hand out addresses during configuration. That is why the random_ether_addr is safer.

#18 lore raw
Quoted 6 lines · Stephen Hemminger
Quoted 4 lines · On Wed, 11 Mar 2009 21:56:06 +0100 Christer Weinigel <[email protected]>…

It's still a pain to have to do this. Many embedded systems that I have seen have a bootloader which I can't modify to do that, but the bootloader allows me to save the kernel command line into some kind of volatile storage. Så being able to set the MAC address with a:

setenv cmdline foo.hwaddr=00:de:ad:be:ef:ed

Quoted 7 lines
Quoted 3 lines

is very nice because it allows me to use a NFS root without having to jump through hoops with initrds an such.

Actually, I wish we had a generic way of doing that, so that could set the mac address of any ethernet interface from the kernel command in a nice and supported way.

The problem is that usually users end up with all devices with the same address, unless there is some other procedure to hand out addresses during configuration. That is why the random_ether_addr is safer.

Random mac addresses, yuk! :-) I'd much rather have something that I can make "do the right thing" than something I can't. And as I said, what I've encountered many times is a reference board from some manufacturer where the following conditions are present:

1. The bootloader can pass a command line to the kernel and it is saved in non-volatile storage that can be changed from the bootloader

2. I can not modify the bootloader

3. I can modify the Linux kernel

4. The manufacturer has hardcoded a MAC address in the ethernet driver

5. I want to use NFS root to make it easy to develop on the platform

6. We get a second board so the hardcoded MAC addresses collide

In this situation I usually hack a hwaddr module param into the ethernet driver, so that I can actually make the devices have different, but stable, MAC addresses. The alternatives are to hardcode the MAC address into the kernel and run different kernels on different boards, or to create an initrd with a tools that parses the kernel command line to extract the MAC address and then do ifconfig eth0 hwaddr $HWADDR, and then add a DCHP client which gets the NFS root from the DCHP response and finally mounts the NFS root and switches too it. But I'm lazy so as I said usually just hack the driver.

/Christer

maintainer
#19 lore raw

From: Christer Weinigel <[email protected]>
Date: Thu, 12 Mar 2009 11:41:24 +0100

Quoted 11 lines

1. The bootloader can pass a command line to the kernel and it is saved in non-volatile storage that can be changed from the bootloader

2. I can not modify the bootloader

3. I can modify the Linux kernel

4. The manufacturer has hardcoded a MAC address in the ethernet driver

5. I want to use NFS root to make it easy to develop on the platform

6. We get a second board so the hardcoded MAC addresses collide

This is getting rediculious.

If you can modify the kernel, you can have the kernel look in the non-volatile storage for the MAC address and export that information to the ethernet driver.

Or, you can parse the command line in your platform specific code and program the MAC address into the chip.

In fact there are many reasonable ways to solve the problem in your scenerio, and none of them require device driver command line option handler.

None.

#20 lore raw
Quoted 9 lines · David Miller

From: Christer Weinigel <[email protected]>
Date: Thu, 12 Mar 2009 11:41:24 +0100

Quoted 6 lines

1. The bootloader can pass a command line to the kernel and it is saved in non-volatile storage that can be changed from the bootloader

2. I can not modify the bootloader

3. I can modify the Linux kernel

Quoted 7 lines
Quoted 5 lines

4. The manufacturer has hardcoded a MAC address in the ethernet driver

5. I want to use NFS root to make it easy to develop on the platform

6. We get a second board so the hardcoded MAC addresses collide

This is getting rediculious.

Yes, ridiculous in the complexity of the workarounds for not having a generic way to set the mac address from the command line. :-/

Quoted 3 lines

If you can modify the kernel, you can have the kernel look in the non-volatile storage for the MAC address and export that information to the ethernet driver.

Which means that the non-volatile storage must be available through a Linux driver before the MAC address is set. AFAIK there is no guarantee that the MTD layer will be ready to use by that time. And that is assuming that there actually is a MTD driver available, usually when I work on a Linux port for a reference board, the first thing I do is to get a NFS root up and running, then I can put a have a complete Debian system with all nice debugging tools available. When I have that up and running I start porting the other drivers, such as the MTD driver.

Also, I don't really want to spend time on reverse engineering some random non-volatile storage format, that's quite fragile.

Quoted 2 lines

Or, you can parse the command line in your platform specific code and program the MAC address into the chip.

Which is actually what I'm doing, except that it's easier to hack that into the ethernet driver each time it is needed.

Quoted 3 lines

In fact there are many reasonable ways to solve the problem in your scenerio, and none of them require device driver command line option handler.

Yes, that why I'd want that in a generic piece of code instead of having to hack it into each device driver. Would a generic command line option, something like "ethaddrs=eth0=00:de:ad:be:ef:01" which assigns addresses to network cards be acceptable?

Next time I have to port something to an embedded platform with this kind of problem, I might try to do something more generic instead of the simple hack I usually do now.

/Christer

#21 lore raw
Quoted 43 lines · Christer Weinigel
Quoted 9 lines · David Miller

From: Christer Weinigel <[email protected]>
Date: Thu, 12 Mar 2009 11:41:24 +0100

Quoted 6 lines

1. The bootloader can pass a command line to the kernel and it is saved in non-volatile storage that can be changed from the bootloader

2. I can not modify the bootloader

3. I can modify the Linux kernel

Quoted 7 lines
Quoted 5 lines

4. The manufacturer has hardcoded a MAC address in the ethernet driver

5. I want to use NFS root to make it easy to develop on the platform

6. We get a second board so the hardcoded MAC addresses collide

This is getting rediculious.

Yes, ridiculous in the complexity of the workarounds for not having a generic way to set the mac address from the command line. :-/

Quoted 3 lines

If you can modify the kernel, you can have the kernel look in the non-volatile storage for the MAC address and export that information to the ethernet driver.

Which means that the non-volatile storage must be available through a Linux driver before the MAC address is set. AFAIK there is no guarantee that the MTD layer will be ready to use by that time. And that is assuming that there actually is a MTD driver available, usually when I work on a Linux port for a reference board, the first thing I do is to get a NFS root up and running, then I can put a have a complete Debian system with all nice debugging tools available. When I have that up and running I start porting the other drivers, such as the MTD driver.

Also, I don't really want to spend time on reverse engineering some random non-volatile storage format, that's quite fragile.

Quoted 2 lines

Or, you can parse the command line in your platform specific code and program the MAC address into the chip.

Which is actually what I'm doing, except that it's easier to hack that into the ethernet driver each time it is needed.

Quoted 8 lines
Quoted 3 lines

In fact there are many reasonable ways to solve the problem in your scenerio, and none of them require device driver command line option handler.

Yes, that why I'd want that in a generic piece of code instead of having to hack it into each device driver. Would a generic command line option, something like "ethaddrs=eth0=00:de:ad:be:ef:01" which assigns addresses to network cards be acceptable?

Unfortunately it isn't this simple because network device names are not stable (i.e. eth0 can become eth1 when you plug another network card) Someone has already mentioned this and I think this is the real problem why we still don't have such a mechanism.

Sascha

Signature · 4 lines
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 |
maintainer
#22 lore raw
In reply to Christer Weinigel

From: Christer Weinigel <[email protected]>
Date: Thu, 12 Mar 2009 15:21:47 +0100

Quoted 4 lines

Yes, that why I'd want that in a generic piece of code instead of having to hack it into each device driver. Would a generic command line option, something like "ethaddrs=eth0=00:de:ad:be:ef:01" which assigns addresses to network cards be acceptable?

Yep, and you can parse that and execute the appropriate ifconfig command from userspace in your initial ramdisk.

#23 lore raw
In reply to Christer Weinigel
Quoted 12 lines · Christer Weinigel
Quoted 11 lines · David Miller

From: Christer Weinigel <[email protected]>
Date: Thu, 12 Mar 2009 11:41:24 +0100

Quoted 8 lines

1. The bootloader can pass a command line to the kernel and it is saved in non-volatile storage that can be changed from the bootloader

2. I can not modify the bootloader

3. I can modify the Linux kernel

4. The manufacturer has hardcoded a MAC address in the ethernet driver

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

5. I want to use NFS root to make it easy to develop on the platform

6. We get a second board so the hardcoded MAC addresses collide

This is getting rediculious.

Yes, ridiculous in the complexity of the workarounds for not having a generic way to set the mac address from the command line. :-/

You do have a generic way, via the initramfs. Works great, every time.

Quoted 4 lines
Quoted 3 lines

If you can modify the kernel, you can have the kernel look in the non-volatile storage for the MAC address and export that information to the ethernet driver.

Quoted 9 lines

Which means that the non-volatile storage must be available through a Linux driver before the MAC address is set. AFAIK there is no guarantee that the MTD layer will be ready to use by that time. And that is assuming that there actually is a MTD driver available, usually when I work on a Linux port for a reference board, the first thing I do is to get a NFS root up and running, then I can put a have a complete Debian system with all nice debugging tools available. When I have that up and running I start porting the other drivers, such as the MTD driver.

If you have an MTD driver ported, then it is available if you use an initramfs. If you don't have an initramfs, you can still use your kernel command line mechanism to set your network interface MAC address.

Quoted 3 lines

Also, I don't really want to spend time on reverse engineering some random non-volatile storage format, that's quite fragile.

Then dont, if you are only guaranteed one interface, use the kernel command line to specify the mac and set it with ifconfig from an initramfs.

Quoted 6 lines
Quoted 2 lines

Or, you can parse the command line in your platform specific code and program the MAC address into the chip.

Which is actually what I'm doing, except that it's easier to hack that into the ethernet driver each time it is needed.

What exactly is so difficult about cpio-ing up an initramfs to do this work with sed and ifconfig? You make it sound like its an impossible barrier. Its really quite simple

Quoted 4 lines
Quoted 3 lines

In fact there are many reasonable ways to solve the problem in your scenerio, and none of them require device driver command line option handler.

Quoted 9 lines

Yes, that why I'd want that in a generic piece of code instead of having to hack it into each device driver. Would a generic command line option, something like "ethaddrs=eth0=00:de:ad:be:ef:01" which assigns addresses to network cards be acceptable?

Next time I have to port something to an embedded platform with this kind of problem, I might try to do something more generic instead of the simple hack I usually do now.

You've convinced yourself that theres no other way to do this. What exactly is your opposition to an initramfs? I just built busybox with ifconfig, sed and ash in a static binary. The whole thing comes out at 800kb, and is compressed to 400kb. You could probably save an extra hundred kb or so if you went with msh instead or something. Are you quite sure that your NV storage for your kernel doesn't have an extra 400kb to spare for an initramfs? I assume that it must, since eventually you'll need an initramfs anyway to run the production variant of the system your building (I imagine they won't all ship with an NFS server in tow :) ).

Neil

Quoted 7 lines

/Christer

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#24 lore raw
Quoted 3 lines · Neil Horman

What exactly is so difficult about cpio-ing up an initramfs to do this work with sed and ifconfig? You make it sound like its an impossible barrier. Its really quite simple

In theory, nothing. In practice, well, where do I find an example initrd that I can build on that has a DHCP client that hands over the NFS root information from the DHCP response to a tool that mounts the NFS root file system? So far I haven't seen anything like that and the infrastructure to build initrds (such as klibc) is still hard to find and use. Every time I've tried to build an initrd that can do DCHP+NFS root it has turned out to be too much trouble and I've had to drop it as deadlines come closer.

Quoted 9 lines

You've convinced yourself that theres no other way to do this. What exactly is your opposition to an initramfs? I just built busybox with ifconfig, sed and ash in a static binary. The whole thing comes out at 800kb, and is compressed to 400kb. You could probably save an extra hundred kb or so if you went with msh instead or something. Are you quite sure that your NV storage for your kernel doesn't have an extra 400kb to spare for an initramfs? I assume that it must, since eventually you'll need an initramfs anyway to run the production variant of the system your building (I imagine they won't all ship with an NFS server in tow :) ).

No, I'm quite aware that there are other ways of doing this, it's just that all the other ways are _much_ more work for me. The harsh reality is that if I can get a board working using a hack in the driver in half an hour, I'll do that rather than fussing around with an initrd. Patching the driver is no big deal, it's quick and fairly painless for me, it would just be nice if the kernel had a generic way of doing this so that I don't have to. The kernel requires no userspace, no C library and all I have to be able to do is to compile the kernel itself.

It's exactly the same reason why people are still using the in kernel DHCP client and NFS root code instead of writing and initrd for it, it's
much easier to use and why spend time on something that is much more
complicated for no gain since the in kernel code is sufficient?

I much prefer to spend time on working on the device drivers that I'm paid to work on (and spend more time to try try to get those patches into the kernel) than to spend time on rewriting everything for an initrd. And the final product usually won't even have ethernet, so from a product perspective it would be wasted time. Anyway, getting the system to boot from NFS is usually the absolutely first thing I have to do. Making a product out of it comes months later, and only if we're able to do a proof-of-concept demo on a couple of reference platforms at an early stage.

Regarding the flash space, if I have a 1.6MByte kernel image (the size of a compressed Linux 2.6.24 kernel for a Samsung S3C24A0 platform I'm working on), those 400kBytes can make the difference between things fitting into the 2MByte flash partition the bootloader has reserved for the kernel or not.

So it mostly boils down to me being lazy and not wanting to spend a lot of time on building new infrastructure. I'd like something which is a bit better than what we have now and can spend some time on it, but I don't want to spend a lot of time on it since patching the driver works just fine for my purposes. Perfect is the enemy of good.

/Christer

-------------------------------------------------------------------

List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php
maintainer
#25 lore raw

From: Christer Weinigel <[email protected]>
Date: Thu, 12 Mar 2009 17:25:27 +0100

Quoted 8 lines

In theory, nothing. In practice, well, where do I find an example initrd that I can build on that has a DHCP client that hands over the NFS root information from the DHCP response to a tool that mounts the NFS root file system? So far I haven't seen anything like that and the infrastructure to build initrds (such as klibc) is still hard to find and use. Every time I've tried to build an initrd that can do DCHP+NFS root it has turned out to be too much trouble and I've had to drop it as deadlines come closer.

Just about every single distribution has to build a initrd that has to be able to setup a network, and have the necessary infrastructure to access things over NFS in order to implement their installer.

You can start with the debian installer, that's probably the easiest to hack on and extend.

Or you can just continue to list excuses, that might be easier.

#26 lore raw
Quoted 9 lines · David Miller

Just about every single distribution has to build a initrd that has to be able to setup a network, and have the necessary infrastructure to access things over NFS in order to implement their installer.

You can start with the debian installer, that's probably the easiest to hack on and extend.

Or you can just continue to list excuses, that might be easier.

Or I can keep patching the drivers, that's even easier. No it's not something I expect to see in the official kernel, but who cares, I always have loads of debug patches that won't get into the official kernel either. Keep the status quo.

/Christer

#27 lore raw
Quoted 10 lines · Christer Weinigel
Quoted 4 lines · David Miller

You can start with the debian installer, that's probably the easiest to hack on and extend.

Or you can just continue to list excuses, that might be easier.

Or I can keep patching the drivers, that's even easier. No it's not something I expect to see in the official kernel, but who cares, I always have loads of debug patches that won't get into the official kernel either. Keep the status quo.

Yes. Patching your own initrd or your own modified Debian initrd is _also_ not in the official trees, so I can't see any reason why anybody would follow Dave's suggestion. Much more work, different private tree, same behaviour, probably more bloated, probably Debian's initrd doesn't work on nommu anyway.

However there was some attempt to get a reference initrd build into the kernel. Did that go anywhere? It would actually be good to use that if it exists.

-- Jamie

#28 lore raw
Quoted 18 lines · Jamie Lokier
Quoted 10 lines · Christer Weinigel
Quoted 4 lines · David Miller

You can start with the debian installer, that's probably the easiest to hack on and extend.

Or you can just continue to list excuses, that might be easier.

Or I can keep patching the drivers, that's even easier. No it's not something I expect to see in the official kernel, but who cares, I always have loads of debug patches that won't get into the official kernel either. Keep the status quo.

Yes. Patching your own initrd or your own modified Debian initrd is _also_ not in the official trees, so I can't see any reason why anybody would follow Dave's suggestion. Much more work, different private tree, same behaviour, probably more bloated, probably Debian's initrd doesn't work on nommu anyway.

Quoted 3 lines

However there was some attempt to get a reference initrd build into the kernel. Did that go anywhere? It would actually be good to use that if it exists.

dracut : http://lwn.net/Articles/317793/

Dan

#29 lore raw
In reply to Jamie Lokier
Quoted 3 lines · Jamie Lokier

However there was some attempt to get a reference initrd build into the kernel. Did that go anywhere? It would actually be good to use that if it exists.

That would be a very worthwhile project actually. Create a package that uses klibc, does BOOTP/DCHP/NFS and parses the the ip=foo,bar options the same way the kernel does so that we can finally get rid of the in kernel stuff. That, the code that reads an initrd from a floppy disk (nobody can really be using that code anymore, can they?), and the md setup are probably the last obstacles to doing a nice little cleanup of the mount_root code in the kernel.

I just wish I had more time.

/Christer

#30 lore raw
Quoted 9 lines · Christer Weinigel
Quoted 3 lines · Jamie Lokier

However there was some attempt to get a reference initrd build into the kernel. Did that go anywhere? It would actually be good to use that if it exists.

That would be a very worthwhile project actually. Create a package that uses klibc, does BOOTP/DCHP/NFS and parses the the ip=foo,bar options the same way the kernel does so that we can finally get rid of the in kernel stuff.

Great, but how does this help in setting the MAC address? This would just move this exact discussion to the dracut or whatever mailing list, but we would still be searching for a generic way to say eth0addr=00:01:02:03:04:05 and I bet the arguments stay the same.

Sascha

Signature · 4 lines
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 |
#31 lore raw
Quoted 4 lines · Sascha Hauer

Great, but how does this help in setting the MAC address? This would just move this exact discussion to the dracut or whatever mailing list, but we would still be searching for a generic way to say eth0addr=00:01:02:03:04:05 and I bet the arguments stay the same.

The objection "we're not taking that because it should go in initrd" would go away.

-- Jamie

#32 lore raw
In reply to Sascha Hauer
Quoted 11 lines · Sascha Hauer
Quoted 9 lines · Christer Weinigel
Quoted 3 lines · Jamie Lokier

However there was some attempt to get a reference initrd build into the kernel. Did that go anywhere? It would actually be good to use that if it exists.

That would be a very worthwhile project actually. Create a package that uses klibc, does BOOTP/DCHP/NFS and parses the the ip=foo,bar options the same way the kernel does so that we can finally get rid of the in kernel stuff.

Quoted 5 lines

Great, but how does this help in setting the MAC address? This would just move this exact discussion to the dracut or whatever mailing list, but we would still be searching for a generic way to say eth0addr=00:01:02:03:04:05 and I bet the arguments stay the same.

You need to do that yourself. the initramfs is where all your platform specific bits go. You're assuming that some tool is automatically going to do this thing for you that is by definition non-standard. Non-standard stuff needs manually process to implement.
Neil

Quoted 8 lines

Sascha

Signature · 4 lines
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 |
#33 lore raw
In reply to Sascha Hauer
Quoted 6 lines · Sascha Hauer
Quoted 1 line

That would be a very worthwhile project actually. Create a package that uses klibc, does BOOTP/DCHP/NFS and parses the the ip=foo,bar options the same way the kernel does so that we can finally get rid of the in kernel stuff.

Great, but how does this help in setting the MAC address? This would just move this exact discussion to the dracut or whatever mailing list, but we would still be searching for a generic way to say eth0addr=00:01:02:03:04:05 and I bet the arguments stay the same.

Alternate answers:

a) It wouldn't. But that doesn't stop me from liking the idea of actually having a working initrd/initramfs that people can build on.

b) It would. With an easy to use initrd/initramfs infrastructure it would be trivial to add a small script that parses /proc/cmdline and runs "ifconfig eth0 hwaddr $FOO" based on it.

c) It would. When the initrd/initramfs runs, it has access to all the normal device driver, so reading the first block of flash and parsing the non-volatile data (assuming there is a mts device driver and that the format is known) and then running ifconfig eth0 hwaddr is also much easier.

And personally, yes, if there was a working initrd+dhcp+nfs combination that doesn't require significantly more memory than the in kernel one, of course I would use it. And that's what DaveM is suggesting, to keep it out of the kernel and move it to user space where it really belongs.

Short therm I'd still like to have the more generic thing in the kernel tough.

/Christer

#34 lore raw
In reply to Sascha Hauer

Dear Sascha Hauer,

Quoted 5 lines · In message <[email protected]> you wrote:

Great, but how does this help in setting the MAC address? This would just move this exact discussion to the dracut or whatever mailing list, but we would still be searching for a generic way to say eth0addr=00:01:02:03:04:05 and I bet the arguments stay the same.

Well, PowerPC uses the device tree for such information. As far as I've been told work is underway to extend the device tree support for ARM, too. [And U-Boot supports the device tree, of course.]

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected]
Any sufficiently advanced technology is indistinguishable from magic.
                                                   - Arthur C. Clarke
#35 lore raw
Quoted 4 lines · Wolfgang Denk

Dear Sascha Hauer,

Quoted 1 line · In message <[email protected]> you wrote:
Quoted 8 lines
Quoted 4 lines

Great, but how does this help in setting the MAC address? This would just move this exact discussion to the dracut or whatever mailing list, but we would still be searching for a generic way to say eth0addr=00:01:02:03:04:05 and I bet the arguments stay the same.

Well, PowerPC uses the device tree for such information. As far as I've been told work is underway to extend the device tree support for ARM, too. [And U-Boot supports the device tree, of course.]

I'm looking forward to the first patches on Linux Arm Kernel. That's gonna be even more fun than this thread ;)

Sascha

Signature · 4 lines
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 |
#36 lore raw
In reply to Wolfgang Denk
Quoted 4 lines · Wolfgang Denk

Dear Sascha Hauer,

Quoted 1 line · In message <[email protected]> you wrote:
Quoted 8 lines
Quoted 4 lines

Great, but how does this help in setting the MAC address? This would just move this exact discussion to the dracut or whatever mailing list, but we would still be searching for a generic way to say eth0addr=00:01:02:03:04:05 and I bet the arguments stay the same.

Well, PowerPC uses the device tree for such information. As far as I've been told work is underway to extend the device tree support for ARM, too.

EWW.

#37 lore raw
In reply to Christer Weinigel
Quoted 7 lines · Christer Weinigel
Quoted 3 lines · Neil Horman

What exactly is so difficult about cpio-ing up an initramfs to do this work with sed and ifconfig? You make it sound like its an impossible barrier. Its really quite simple

In theory, nothing. In practice, well, where do I find an example initrd that I can build on that has a DHCP client that hands over the

Well, for an example of an initrd, you can unpack just about any distribution initramfs that you like. If you want to use busybox, I'd personally recommend either Debian (I think they use busybox normally), or you're welcome to get a copy of the fedora kexec-tools package. I put a script called mkdumprd that generates initramfs files in there based on busybox for the purpose of capturing core dumps. As for the dhcp part of it, that depends on the dhcp client you decide to use. I use the udhcpc applet in busybox, the man page for which describes how to extract the various options out of the dhcpoffer frame. Its pretty straightforward. Other clients do it differently, but that one is both small and easy to use.

Quoted 3 lines

NFS root information from the DHCP response to a tool that mounts the NFS root file system? So far I haven't seen anything like that and the infrastructure to build initrds (such as klibc) is still hard to find

You don't need klibc, you can use regular glibc, and even build statically if you like. You'll have to use dig or host to do name lookups, but thats also pretty easy to do. This really is easier than you think it is :)

Quoted 4 lines

and use. Every time I've tried to build an initrd that can do DCHP+NFS root it has turned out to be too much trouble and I've had to drop it as deadlines come closer.

Seriously, most of what you need to do is embodied in my mkdumprd script. Look at that (or even just start with it an modify it), and you'll be 90% of the way there. After you get it working, you can strip out all the stuff you don't need (which from mkdumprd will likely be substantial).

Quoted 10 lines
Quoted 9 lines

You've convinced yourself that theres no other way to do this. What exactly is your opposition to an initramfs? I just built busybox with ifconfig, sed and ash in a static binary. The whole thing comes out at 800kb, and is compressed to 400kb. You could probably save an extra hundred kb or so if you went with msh instead or something. Are you quite sure that your NV storage for your kernel doesn't have an extra 400kb to spare for an initramfs? I assume that it must, since eventually you'll need an initramfs anyway to run the production variant of the system your building (I imagine they won't all ship with an NFS server in tow :) ).

Quoted 2 lines

No, I'm quite aware that there are other ways of doing this, it's just that all the other ways are _much_ more work for me. The harsh reality

Wheres all the extra work? You've given a few examples here, and they're all things that are easily overcome.

Quoted 7 lines

is that if I can get a board working using a hack in the driver in half an hour, I'll do that rather than fussing around with an initrd. Patching the driver is no big deal, it's quick and fairly painless for me, it would just be nice if the kernel had a generic way of doing this so that I don't have to. The kernel requires no userspace, no C library and all I have to be able to do is to compile the kernel itself.

Well, you've said it there yourself. What you're proposing is a hack in the driver. This really isn't the place for hacks. This is the place for doing things in as consistent and maintainable a way as possible. That way is using an initramfs, which you will need at some point in time anyway, if you want any userspace functionality. So why not create one? The small investment of your time figuring out how to do it will pay off over and over again when you can easily assign unit-specific data using well known and well documented tools to do so.

Quoted 5 lines

It's exactly the same reason why people are still using the in kernel DHCP client and NFS root code instead of writing and initrd for it, it's
much easier to use and why spend time on something that is much more
complicated for no gain since the in kernel code is sufficient?

You're last comment is in direct contradiction to what you are saying here. As you've discovered, the in kernel dhcp and nfs root client are useless unless your ethernet interface has a mac on it, and if you don't have a mac stored in eeprom that the driver can access, you can't assign one without introducing a big hack, which no one here is going to support. The solution is to do things the right way. Save some space in the kernel by turning the in-kernel dhcp client and nfs root code off, and use that space to store an initrd that can do everything you need to and more.

Quoted 10 lines

I much prefer to spend time on working on the device drivers that I'm paid to work on (and spend more time to try try to get those patches into the kernel) than to spend time on rewriting everything for an initrd. And the final product usually won't even have ethernet, so from a product perspective it would be wasted time. Anyway, getting the system to boot from NFS is usually the absolutely first thing I have to do. Making a product out of it comes months later, and only if we're able to do a proof-of-concept demo on a couple of reference platforms at an early stage.

Everyone has to invest some time on a tangent to their goal in order to reach their goal. This is simply a cost of doing business. No one is going to accept a hack to a driver just so that you don't have to learn how to do something a bit differently. And no amount of complaining about how difficult it is is going to change that. Its simply not true. Theres a big document in the kernel tree explaining how to create and use initramfs/initrd files. I'll be happy to help you figure out how to do it if you have questions.

Quoted 6 lines

Regarding the flash space, if I have a 1.6MByte kernel image (the size of a compressed Linux 2.6.24 kernel for a Samsung S3C24A0 platform I'm working on), those 400kBytes can make the difference between things fitting into the 2MByte flash partition the bootloader has reserved for the kernel or not.

It can, is that the the actual case? How much space do you have if you turn off the dhcp client and nfs root code in the kernel? Try hard, I bet you can make it fit without much effort.

Quoted 6 lines

So it mostly boils down to me being lazy and not wanting to spend a lot of time on building new infrastructure. I'd like something which is a bit better than what we have now and can spend some time on it, but I don't want to spend a lot of time on it since patching the driver works just fine for my purposes. Perfect is the enemy of good.

Well, that is your perogative. I had to make those sorts of choices when I did embedded too. I tried to get upstream what was acceptible, and carried the rest myself on occasion. But I promise you, this really isn't hard. Spend some time, and you'll find and onboard initramfs environment can make your life worlds easier long term.
Neil

Quoted 7 lines

/Christer

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#38 lore raw
Quoted 3 lines · Neil Horman

You don't need klibc, you can use regular glibc, and even build statically if you like. You'll have to use dig or host to do name lookups, but thats also pretty easy to do. This really is easier than you think it is :)

Size, size, size. The killer in the embedded world which rules out glibc. And have you tried to link glibc statically with something that uses gethostbyname lately? It is no longer possible since the introduction of all the introduction of the dynamic name lookup crap (ok, it's not really crap, I just feel like it's crap every time I try to link a networking application statically). But that's a bit off topic since I don't need name lookups just to mount a NFS file system. uclibc also seems to have issues with networking and statically linked binaries, but I just haven't had time to figure out why yet.

Quoted 3 lines

Well, you've said it there yourself. What you're proposing is a hack in the driver. This really isn't the place for hacks. This is the place for doing things in as consistent and maintainable a way as possible.

In my opion, having a "hwaddrs=eth0=00:de:ad:be:ef:01" would be consistent and maintainable. But opinions differ.

Quoted 5 lines

You're last comment is in direct contradiction to what you are saying here. As you've discovered, the in kernel dhcp and nfs root client are useless unless your ethernet interface has a mac on it, and if you don't have a mac stored in eeprom that the driver can access, you can't assign one without introducing a big hack, which no one here is going to support.

Once again, in your opinion it is a hack, I don't consider it more a hack than assigning the IP address on the command line. And I wouldn't call the in kernel stuff useless.

Quoted 7 lines

Everyone has to invest some time on a tangent to their goal in order to reach their goal. This is simply a cost of doing business. No one is going to accept a hack to a driver just so that you don't have to learn how to do something a bit differently. And no amount of complaining about how difficult it is is going to change that. Its simply not true. Theres a big document in the kernel tree explaining how to create and use initramfs/initrd files. I'll be happy to help you figure out how to do it if you have questions.

I know how to build initrds and initramfs. I've spent the hard time digging through the code in init/do_mounts.c trying to figure out what it is supposed to do. I have used them for multiple embedded systems, zoo.weinigel.se/trac/public, both the Acer and the DNS323 use them, but those are hobby projects where I haven't had deadlines to meet. It is a luxury I usually don't have when my boss drops an embedded system on my desk and tells me "we have to have our drivers working on this board for a demo next week".

Quoted 5 lines
Quoted 2 lines

Regarding the flash space, if I have a 1.6MByte kernel image (the size of a compressed Linux 2.6.24 kernel for a Samsung S3C24A0 platform I'm working on), those 400kBytes can make the difference between things fitting into the 2MByte flash partition the bootloader has reserved for the kernel or not.

It can, is that the the actual case? How much space do you have if you turn off the dhcp client and nfs root code in the kernel? Try hard, I bet you can make it fit without much effort.

Disabling IP_PNP and NFS_ROOT saves less than 8kBytes on an ARM9 (yeah, I just checked). An initrd uses a lot more than that. Maybe with klibc, but investing klibc is something that I've had on my TODO list since hpa first talked about it years ago. I've sort of been putting it off until klibc would get into the kernel, but...

Quoted 7 lines
Quoted 2 lines

So it mostly boils down to me being lazy and not wanting to spend a lot of time on building new infrastructure. I'd like something which is a bit better than what we have now and can spend some time on it, but I don't want to spend a lot of time on it since patching the driver works just fine for my purposes. Perfect is the enemy of good.

Well, that is your perogative. I had to make those sorts of choices when I did embedded too. I tried to get upstream what was acceptible, and carried the rest myself on occasion. But I promise you, this really isn't hard. Spend some time, and you'll find and onboard initramfs environment can make your life worlds easier long term.

Yes, and the next time I would have to fix this on an embedded board, I could probably have spent the time on figure out how to do something slightly more generic, but since it won't have a chance of getting into the kernel, I probably won't.

Anyway, I've spent more time on discussing this now than it would have taken me to hack the device drivers on half a dozen platforms, so I think I'll give up. Maybe I'll take a look at some initrd+klibc+dhcp stuff when I have some free time next Christmas (that's when I usually get to play around with my hobby projects), maybe not. :-)

/Christer

#39 lore raw
Quoted 5 lines · Christer Weinigel
Quoted 3 lines · Neil Horman

You don't need klibc, you can use regular glibc, and even build statically if you like. You'll have to use dig or host to do name lookups, but thats also pretty easy to do. This really is easier than you think it is :)

Quoted 10 lines

Size, size, size. The killer in the embedded world which rules out glibc. And have you tried to link glibc statically with something that uses gethostbyname lately? It is no longer possible since the introduction of all the introduction of the dynamic name lookup crap (ok, it's not really crap, I just feel like it's crap every time I try to link a networking application statically). But that's a bit off topic since I don't need name lookups just to mount a NFS file system. uclibc also seems to have issues with networking and statically linked binaries, but I just haven't had time to figure out why yet.

You didn't read what I wrote very closely, I specifically said you have to dig or host to do name lookups, specifically because of the issues with getXbyY. When I said I built busybox in 800k (400k compressed), That was with glibc statically linked. End of story. You're making up problems here, its not that big a deal. I've not looked at the figures lately, but how much space does the dhcp client and nfs root code take up in the kernel these days? I imagine that what you save there by turning those off will be a good start in offsetting the space you need for an initramfs.

Quoted 7 lines
Quoted 3 lines

Well, you've said it there yourself. What you're proposing is a hack in the driver. This really isn't the place for hacks. This is the place for doing things in as consistent and maintainable a way as possible.

In my opion, having a "hwaddrs=eth0=00:de:ad:be:ef:01" would be consistent and maintainable. But opinions differ.

I never said you can't still use that command line option to implement this solution, you just have to parse it in userspace.

Quoted 10 lines
Quoted 5 lines

You're last comment is in direct contradiction to what you are saying here. As you've discovered, the in kernel dhcp and nfs root client are useless unless your ethernet interface has a mac on it, and if you don't have a mac stored in eeprom that the driver can access, you can't assign one without introducing a big hack, which no one here is going to support.

Once again, in your opinion it is a hack, I don't consider it more a hack than assigning the IP address on the command line. And I wouldn't call the in kernel stuff useless.

You yourself called it a hack in your last note (and I agree). And, as you're finding out, the DHCP and NFS code in the kernel is in fact useless if you can't assign a mac address to your ethernet interface, which in turn you cant do unless you introduce some unacceptable code to the kernel.

Quoted 8 lines
Quoted 7 lines

Everyone has to invest some time on a tangent to their goal in order to reach their goal. This is simply a cost of doing business. No one is going to accept a hack to a driver just so that you don't have to learn how to do something a bit differently. And no amount of complaining about how difficult it is is going to change that. Its simply not true. Theres a big document in the kernel tree explaining how to create and use initramfs/initrd files. I'll be happy to help you figure out how to do it if you have questions.

Quoted 9 lines

I know how to build initrds and initramfs. I've spent the hard time digging through the code in init/do_mounts.c trying to figure out what it is supposed to do. I have used them for multiple embedded systems, zoo.weinigel.se/trac/public, both the Acer and the DNS323 use them, but
those are hobby projects where I haven't had deadlines to meet. It is
a luxury I usually don't have when my boss drops an embedded system on my desk and tells me "we have to have our drivers working on this board for a demo next week".

So, If I read this right:
1) You have undertaken hobby projects for which you have investigated, implemented and learned how to implement an initramfs, and feel comfortable doing so.

2) You have a work project for which an initramfs would be helpful and based on this thread, required (assuming you don't want to carry extra driver patches on your own)

3) Your knoweldge from (1) is insufficient to implement the required initramfs in (2) in (assuming your example time frame) 1 week?

Seriously?

Quoted 10 lines
Quoted 9 lines
Quoted 6 lines

Regarding the flash space, if I have a 1.6MByte kernel image (the size of a compressed Linux 2.6.24 kernel for a Samsung S3C24A0 platform I'm working on), those 400kBytes can make the difference between things fitting into the 2MByte flash partition the bootloader has reserved for the kernel or not.

It can, is that the the actual case? How much space do you have if you turn off the dhcp client and nfs root code in the kernel? Try hard, I bet you can make it fit without much effort.

Quoted 6 lines

Disabling IP_PNP and NFS_ROOT saves less than 8kBytes on an ARM9 (yeah, I just checked). An initrd uses a lot more than that. Maybe with klibc, but investing klibc is something that I've had on my TODO list since hpa first talked about it years ago. I've sort of been putting it off until klibc would get into the kernel, but...

Ok, well, thats a start. Have you considered making some non-essential functions modular, and storing those functions on your NFS root? That would give you the additional space to store an initramfs, which you can use to mout and pivot to your nfs root, which then gives you access to the additional modules. Thats not hard to do at all.

Quoted 18 lines
Quoted 7 lines
Quoted 7 lines

So it mostly boils down to me being lazy and not wanting to spend a lot of time on building new infrastructure. I'd like something which is a bit better than what we have now and can spend some time on it, but I don't want to spend a lot of time on it since patching the driver works just fine for my purposes. Perfect is the enemy of good.

Quoted 5 lines

Well, that is your perogative. I had to make those sorts of choices when I did embedded too. I tried to get upstream what was acceptible, and carried the rest myself on occasion. But I promise you, this really isn't hard. Spend some time, and you'll find and onboard initramfs environment can make your life worlds easier long term.

Yes, and the next time I would have to fix this on an embedded board, I could probably have spent the time on figure out how to do something slightly more generic, but since it won't have a chance of getting into the kernel, I probably won't.

Quoted 6 lines

Anyway, I've spent more time on discussing this now than it would have taken me to hack the device drivers on half a dozen platforms, so I think I'll give up. Maybe I'll take a look at some initrd+klibc+dhcp stuff when I have some free time next Christmas (that's when I usually get to play around with my hobby projects), maybe not. :-)

I sympathize with you. This is exactly what soured me on embedded work a few years back. Embedded shops are forever compromising doing things correctly in the name of time and schedules, never paying any heed to the possibility that taking extra time to do things in an agreed upon, organized and standard fashion might pay off for them in the long run. I encourage you to tell your management that taking the time to develop this would let you save this time over and over again in subsequnt probjects. Track how much time you take keeping up with that mac address assignment patch as you update kernels. I had to do that several times on various projects, and sometimes it helped (although usually it just made me mad :) )
Neil

/Christer

Quoted 2 lines
#40 lore raw
Quoted 17 lines · Neil Horman
Quoted 5 lines · Christer Weinigel
Quoted 3 lines · Neil Horman

You don't need klibc, you can use regular glibc, and even build statically if you like. You'll have to use dig or host to do name lookups, but thats also pretty easy to do. This really is easier than you think it is :)

Quoted 10 lines

Size, size, size. The killer in the embedded world which rules out glibc. And have you tried to link glibc statically with something that uses gethostbyname lately? It is no longer possible since the introduction of all the introduction of the dynamic name lookup crap (ok, it's not really crap, I just feel like it's crap every time I try to link a networking application statically). But that's a bit off topic since I don't need name lookups just to mount a NFS file system. uclibc also seems to have issues with networking and statically linked binaries, but I just haven't had time to figure out why yet.

Quoted 6 lines

You didn't read what I wrote very closely, I specifically said you have to dig or host to do name lookups, specifically because of the issues with getXbyY. When I said I built busybox in 800k (400k compressed), That was with glibc statically linked. End of story. You're making up problems here, its not that big a deal. I've not looked at the figures lately, but how much space does the dhcp client and nfs root code take up in the kernel these days?

just checked: disabling CONFIG_IP_PNP and CONFIG_IP_PNP_DHCP saves me 4456 bytes of zImage size on an ARM/PXA build

Sascha

Signature · 4 lines
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 |
#41 lore raw
In reply to Neil Horman
Quoted 2 lines · Neil Horman

You didn't read what I wrote very closely, I specifically said you have to dig or host to do name lookups, specifically because of the issues with getXbyY.

Did too. :-)

Quoted 4 lines

3) Your knoweldge from (1) is insufficient to implement the required initramfs in (2) in (assuming your example time frame) 1 week?

Seriously?

Yup. A week right now is a luxury I usually don't have right now. I shouldn't even be spending time writing this mail, but I'm eh, right, waiting for a compilation to finish.

Quoted 7 lines
Quoted 2 lines

Anyway, I've spent more time on discussing this now than it would have taken me to hack the device drivers on half a dozen platforms, so I think I'll give up. Maybe I'll take a look at some initrd+klibc+dhcp stuff when I have some free time next Christmas (that's when I usually get to play around with my hobby projects), maybe not. :-)

I sympathize with you. This is exactly what soured me on embedded work a few years back. Embedded shops are forever compromising doing things correctly in the name of time and schedules, never paying any heed to the possibility that taking extra time to do things in an agreed upon, organized and standard fashion might pay off for them in the long run.

Actually, I'm quite happy about work so far. When worked on improving the Samsung S3C24A0 patches Sandeep Patil had made, I got approval from my boss to spend time on making them suitable for submission to the official kernel, so I was able to do a lot more than just "make things work now". But the last few months have been kind of hectic.

/Christer

#42 lore raw
In reply to Neil Horman
Quoted 2 lines · Neil Horman

I've not looked at the figures lately, but how much space does the dhcp client and nfs root code take up in the kernel these days?

About 4k apparently. See the difference from "400k compressed?". Also, uncompressing that may add 0.5 second boot time on a slow CPU :-)

Quoted 6 lines

I sympathize with you. This is exactly what soured me on embedded work a few years back. Embedded shops are forever compromising doing things correctly in the name of time and schedules, never paying any heed to the possibility that taking extra time to do things in an agreed upon, organized and standard fashion might pay off for them in the long run.

I must admit that a solution which makes the effective kernel size 800k larger (your figure) doesn't look like a good standard to me.

If that was the "standard", I'd be tempted to add a MAC address driver hack to the kernel to save the space :-)

-- Jamie

#43 lore raw
Quoted 6 lines · Jamie Lokier
Quoted 2 lines · Neil Horman

I've not looked at the figures lately, but how much space does the dhcp client and nfs root code take up in the kernel these days?

About 4k apparently. See the difference from "400k compressed?". Also, uncompressing that may add 0.5 second boot time on a slow CPU :-)

I just tried to get some actual numbers for the size increase by looking at an actual initrd I had lying around. If I just look at some some of the largest files needed for a initrd, they use 800kBytes:

ls -l bin/busybox lib/ld-uClibc-0.9.28.so lib/libuClibc-0.9.28.so -rwxr-xr-x 1 root root 499804 2007-01-21 18:17 bin/busybox* -rwxr-xr-x 1 root root 19492 2005-12-27 12:15 lib/ld-uClibc-0.9.28.so* -rw-r--r-- 1 root root 312136 2005-12-27 08:46 lib/libuClibc-0.9.28.so

All files are stripped ARM9 binaries and as you can see, the C library is uClibc. And compressed it is roughly about 400kBytes:

tar cvfz - bin/busybox lib/ld-uClibc-0.9.28.so lib/libuClibc-0.9.28.so | wc -c

422789

The in kernel BOOT/DCHP client and NFS root code increases the size of the compressed kernel by slighty less than 8kBytes. The 4k number was just for turning off BOOTP/DHCP (IP_PNP).

Quoted 6 lines

I must admit that a solution which makes the effective kernel size

800k larger (your figure) doesn't look like a good standard to me.

If that was the "standard", I'd be tempted to add a MAC address driver hack to the kernel to save the space :-)

So the numbers aren't quite as bad, but it is a 50 time increase in overhead to do things "right". For a kernel which is 1.5Mbytes it is "only" a 27% increase in total size though.

Of course, using busybox is a bit of an overkill, it should be possible to just port the in kernel BOOTP/DHCP client and NFS root code so that it is statically linked with klibc and put in an initrd. If we assume that the useful parts of the code stay the same size, it should compress to about 8kBytes of initrd instead of 8kBytes of compressed kernel image. But code running from an initrd will need a stdio library with printf and a bunch of other library functions. After taking a quick look at klibc it seems that it would add something like 10-20kBytes compressed size to a normal application. So that would only be a 2-3 time increase in size which is much more acceptable to me.

Actually, just looking at the filenames in the klibc source, it seems that it does have a DHCP client and some NFS root code already. An ARM9 "kinit" binary is about 75kBytes, and I'm not sure if it includes the DHCP client or the NFS root code. But it means that it's probably possible to replace the in kernel code with klibc as is for only an extra 50kBytes or so of increased compressed size.

Looks interesting, any year now...

/Christer

#44 lore raw
Quoted 59 lines · Christer Weinigel
Quoted 6 lines · Jamie Lokier
Quoted 2 lines · Neil Horman

I've not looked at the figures lately, but how much space does the dhcp client and nfs root code take up in the kernel these days?

About 4k apparently. See the difference from "400k compressed?". Also, uncompressing that may add 0.5 second boot time on a slow CPU :-)

I just tried to get some actual numbers for the size increase by looking at an actual initrd I had lying around. If I just look at some some of the largest files needed for a initrd, they use 800kBytes:

ls -l bin/busybox lib/ld-uClibc-0.9.28.so lib/libuClibc-0.9.28.so

(quoted diff) +0 -3
-rwxr-xr-x 1 root root 499804 2007-01-21 18:17 bin/busybox*
-rwxr-xr-x 1 root root  19492 2005-12-27 12:15 lib/ld-uClibc-0.9.28.so*
-rw-r--r-- 1 root root 312136 2005-12-27 08:46 lib/libuClibc-0.9.28.so

All files are stripped ARM9 binaries and as you can see, the C library is uClibc. And compressed it is roughly about 400kBytes:

tar cvfz - bin/busybox lib/ld-uClibc-0.9.28.so lib/libuClibc-0.9.28.so | wc -c

422789

The in kernel BOOT/DCHP client and NFS root code increases the size of the compressed kernel by slighty less than 8kBytes. The 4k number was just for turning off BOOTP/DHCP (IP_PNP).

Quoted 6 lines

I must admit that a solution which makes the effective kernel size

800k larger (your figure) doesn't look like a good standard to me.

If that was the "standard", I'd be tempted to add a MAC address driver hack to the kernel to save the space :-)

So the numbers aren't quite as bad, but it is a 50 time increase in overhead to do things "right". For a kernel which is 1.5Mbytes it is "only" a 27% increase in total size though.

Of course, using busybox is a bit of an overkill, it should be possible to just port the in kernel BOOTP/DHCP client and NFS root code so that it is statically linked with klibc and put in an initrd. If we assume that the useful parts of the code stay the same size, it should compress to about 8kBytes of initrd instead of 8kBytes of compressed kernel image. But code running from an initrd will need a stdio library with printf and a bunch of other library functions. After taking a quick look at klibc it seems that it would add something like 10-20kBytes compressed size to a normal application. So that would only be a 2-3 time increase in size which is much more acceptable to me.

Actually, just looking at the filenames in the klibc source, it seems that it does have a DHCP client and some NFS root code already. An ARM9 "kinit" binary is about 75kBytes, and I'm not sure if it includes the DHCP client or the NFS root code. But it means that it's probably possible to replace the in kernel code with klibc as is for only an extra 50kBytes or so of increased compressed size.

Quoted 4 lines

Looks interesting, any year now...

/Christer

So, I've avoided asking this question, because I didn't want to get off topic, but since it appears we're winding up here, I have to ask what your long term plan is for your final application. I can understand being hesitant to invest in an initramfs when its solely for your intermediate development (even though I think that will pay off for you in the long run), but when your development ends, and you ship a product, how do you plan to implement your application? I would imagine you at least need an initramfs to store, load and run your final application don't you? How do you plan on executing it?

Neil

Quoted 14 lines
#45 lore raw
Quoted 8 lines · Neil Horman

So, I've avoided asking this question, because I didn't want to get off topic, but since it appears we're winding up here, I have to ask what your long term plan is for your final application. I can understand being hesitant to invest in an initramfs when its solely for your intermediate development (even though I think that will pay off for you in the long run), but when your development ends, and you ship a product, how do you plan to implement your application? I would imagine you at least need an initramfs to store, load and run your final application don't you? How do you plan on executing it?

Most probably no ramdisk at all, just the mtd driver and flash file system driver compiled into the kernel and then "root=/dev/mtdblock4".

For one old product the bootloader programs the mac address into the ethernet chip before the kernel boots. For another embedded system thats out in production the bootloader is really dumb and it's up to early userspace to extract the mac address from nonvolatile memory and do ifconfig hwaddr.

And as I wrote in a different post, most systems I'm working on now won't even have ethernet.

/Christer

#46 lore raw
Quoted 11 lines · Christer Weinigel
Quoted 8 lines · Neil Horman

So, I've avoided asking this question, because I didn't want to get off topic, but since it appears we're winding up here, I have to ask what your long term plan is for your final application. I can understand being hesitant to invest in an initramfs when its solely for your intermediate development (even though I think that will pay off for you in the long run), but when your development ends, and you ship a product, how do you plan to implement your application? I would imagine you at least need an initramfs to store, load and run your final application don't you? How do you plan on executing it?

Quoted 3 lines

Most probably no ramdisk at all, just the mtd driver and flash file system driver compiled into the kernel and then "root=/dev/mtdblock4".

Ok, thanks, so you have a place to store user space images. This thread got me wondering what you were going to do long term about user space. I was starting to think as a space saving measure, that you were building your app into the kernel or something.

FWIW, I think Uboot has a pretty robust mtd infrastructure that would allow you to store a initramfs image there for use if you were interested in exploring that route.

Neil

#47 lore raw
In reply to Jamie Lokier
Quoted 14 lines · Jamie Lokier
Quoted 2 lines · Neil Horman

I've not looked at the figures lately, but how much space does the dhcp client and nfs root code take up in the kernel these days?

About 4k apparently. See the difference from "400k compressed?". Also, uncompressing that may add 0.5 second boot time on a slow CPU :-)

Quoted 6 lines

I sympathize with you. This is exactly what soured me on embedded work a few years back. Embedded shops are forever compromising doing things correctly in the name of time and schedules, never paying any heed to the possibility that taking extra time to do things in an agreed upon, organized and standard fashion might pay off for them in the long run.

Quoted 8 lines

I must admit that a solution which makes the effective kernel size 800k larger (your figure) doesn't look like a good standard to me.

If that was the "standard", I'd be tempted to add a MAC address driver hack to the kernel to save the space :-)

-- Jamie

I agree that the simple 8k savings is less than stellar, but if you're setting up a development environment over NFS root, your savings are really unbounded. Need more space? Carve out a config option in the kernel that you don't need immediately, build it as a module, and store it on the NFS root, keeping only the needed functionality for NFS root in the monolithic image. Lather, rinse, repeat until you have enough space.

#48 lore raw
In reply to Christer Weinigel
Quoted 11 lines · Christer Weinigel
Quoted 4 lines

You don't need klibc, you can use regular glibc, and even build statically if you like. You'll have to use dig or host to do name lookups, but thats also pretty easy to do. This really is easier than you think it is :)

Size, size, size. The killer in the embedded world which rules out glibc. And have you tried to link glibc statically with something that uses gethostbyname lately? It is no longer possible since the introduction of all the introduction of the dynamic name lookup crap (ok, it's not really crap, I just feel like it's crap every time I try to link a networking application statically).

In other words, glibc doesn't work on some embedded targets even if you have plenty of room: they don't support dynamic libs.

Quoted 2 lines

uclibc also seems to have issues with networking and statically linked binaries, but I just haven't had time to figure out why yet.

I've never had an issue with uclibc and networking.

Quoted 2 lines

In my opion, having a "hwaddrs=eth0=00:de:ad:be:ef:01" would be consistent and maintainable. But opinions differ.

I believe the party line on such things is "use udev".

Of course, realistically you can't use udev on little embedded systems and you probably wouldn't use it inside initrd either. Oh well!

To fix the device name with udev you often match on MAC address :-)

Quoted 3 lines

Once again, in your opinion it is a hack, I don't consider it more a hack than assigning the IP address on the command line. And I wouldn't call the in kernel stuff useless.

That's a good point.

If assigning the MAC to a particular device "eth0" is dubious - someone said because device names aren't guaranteed. Well, why is assigning the IP address ok?

Quoted 4 lines

Yes, and the next time I would have to fix this on an embedded board, I could probably have spent the time on figure out how to do something slightly more generic, but since it won't have a chance of getting into the kernel, I probably won't.

Another good point: There have been complaints, of a sort, that embedded developers don't feed back enough of their work upstream.

It's not surprising if this is typical of the objections.

I'm totally failing to see why _if_ setting the IP address on the kernel command line, for the kernel to apply, is ok, but the MAC is not. Both or neither. Fair enough that the IP option was put in a long time ago, before policies changed. But as long as that capability is there and used and useful, it's ridiculous that it can't be marginally improved.

-- Jamie

#49 lore raw
Quoted 2 lines · Jamie Lokier

In other words, glibc doesn't work on some embedded targets even if you have plenty of room: they don't support dynamic libs.

It might be possible to build glibc to always use hosts+DNS for name lookup, but since I almost always use uclibc on embedded systems I haven't really tried to do it. If I use glibc, it's on a NFS root and those systems are large enough anyway.

Quoted 3 lines
Quoted 1 line

uclibc also seems to have issues with networking and statically linked binaries, but I just haven't had time to figure out why yet.

I've never had an issue with uclibc and networking.

I'm not sure what is happening, but a statically linked uclibc binary that does TCP networking will work happily with one userspace but not another. It would seem to me that a statically linked binary should only depend on the kernel ABI and not on anything userspace (except the text files in /etc like resolv.conf), but that does not seem to match reality. If I use Unix sockets instead it works fine, so belive it is something related to TCP. But well, this is all very fuzzy because I haven't had time to look more closely at it yet.

/Christer

#50 lore raw
In reply to Neil Horman
Quoted 3 lines · Neil Horman

What exactly is so difficult about cpio-ing up an initramfs to do this work with sed and ifconfig? You make it sound like its an impossible barrier. Its really quite simple

Can you share your scripts and tools for creating an initramfs so easily? I too run into this problem -- I've always used the kernel-provided mechanism to DHCP and do the nfs mount of the rootfs, but if the initramfs is the right way to do that, then I'll be happy to change.

It always looked rather daunting to me, and a lot of extra effort compared to letting the kernel do the job, but if it really is so easy, then I'll be happy to change my practices.

Thanks!
Mike (mwester)

-------------------------------------------------------------------

List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php
#51 lore raw
Quoted 12 lines · Mike (mwester)
Quoted 3 lines · Neil Horman

What exactly is so difficult about cpio-ing up an initramfs to do this work with sed and ifconfig? You make it sound like its an impossible barrier. Its really quite simple

Can you share your scripts and tools for creating an initramfs so easily? I too run into this problem -- I've always used the kernel-provided mechanism to DHCP and do the nfs mount of the rootfs, but if the initramfs is the right way to do that, then I'll be happy to change.

Quoted 6 lines

It always looked rather daunting to me, and a lot of extra effort compared to letting the kernel do the job, but if it really is so easy, then I'll be happy to change my practices.

Thanks!
Mike (mwester)

Sure, you'll find my mkduprd script in the kexec-tools package for fedora, you're welcome to tear it up to suit your needs.

By way of precaution, I'll tell you that the script is much larger than it needs to be, since its purpose is to copy a vmcore to several various locations.

In short summary, all you need to make an initramfs is:

1) create a rootfs directory tree somewhere, call it $INITRD_ROOT
2) populate the initrd with any applications you need for your purpose
3) create an executable file , called $INITRD_ROOT/init
4) $INITRD_ROOT/init should do whatever you want the initramfs to do, in mkdumprd I make it a shell script that does various and sunry things, although you could do something as simple as making it run /bin/sh to give you a shell prompt.
5)cd $INITRD_ROOT; cpio --quiet -c -o /tmp/initramfs; gzip -9 /tmp/initramfs

thats it.
Neil

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#52 lore raw
In reply to Stephen Hemminger
Quoted 20 lines · Stephen Hemminger
Quoted 17 lines · On Wed, 11 Mar 2009 05:29:09 +0300 Ilya Yanok <[email protected]> wrote:
drivers/net/dnet.c new file +17 -0
+static char ethaddr[18];
+
+module_param_string(ethaddr, ethaddr, sizeof(ethaddr), 0);
+
+static void get_mac_addr(struct net_device *nd, unsigned char *pmac)
+{
+	int i;
+	char *p = ethaddr;
+
+	ethaddr[17] = 0;
+	for (i = 0; i < ETH_ALEN; i++, p++) {
+		pmac[i] = simple_strtoul(p, &p, 16);
+		if (*p != ':')
+			break;
+	}
+	if (i != ETH_ALEN - 1) {
+		pr_err("Wrong MAC address format!\n");
Quoted 8 lines

drivers/net/dnet.c line 50

Quoted 4 lines
drivers/net/dnet.c new file +4 -0
+		memset(pmac, 0, ETH_ALEN);
+	}
+}
+

Do you still need this? Only works with one board, configuration via module parameters is discouraged. Same effect can be done by setting mac address with regular tools.

I'm confused by this. If I'm NFS-booting the board then how do I get to those userland tools if I don't have a valid MAC address in place to do the root mount?

-Mike

-------------------------------------------------------------------

List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php
maintainer
#53 lore raw

From: Michael Cashwell <[email protected]>
Date: Thu, 12 Mar 2009 09:41:38 -0400

Quoted 3 lines

I'm confused by this. If I'm NFS-booting the board then how do I get to those userland tools if I don't have a valid MAC address in place to do the root mount?

Initial ramdisk.

#54 lore raw
Quoted 8 lines · David Miller

From: Michael Cashwell <[email protected]>
Date: Thu, 12 Mar 2009 09:41:38 -0400

Quoted 3 lines

I'm confused by this. If I'm NFS-booting the board then how do I get to those userland tools if I don't have a valid MAC address in place to do the root mount?

Initial ramdisk.

+1, the simple fact of the matter is that, when building networkable devices, the design requirements must include:

1) The ability to store unit-unique data, like MAC addresses, in persistent storage, in a manner that can be read at arbitrary times from the OS.

2) The abiltiy to access that data from the OS under all relevant operating conditions.

You have (1) covered, in that the bootloader passes the MAC on the command line to the kernel which can then be read via /proc/cmdline easily.

If you can't accomplish (2) with NFS root built into the kernel, then quite simply using built in NFS root isn't an option, and you need to burn some extra storage to add an initramfs. Its easy to do, and small. Cost minimization is important, but you can't remove what you need, and you need an initramfs. You can build one in just a few hundred kb, if you use busybox with a minimal toolset (you'd probably need the sed, ifconfig, and ash applets). I would make a bet that even if you did need to spring for a bit of extra ram, the incremental cost to that is less than the savings of using linux over something that would required a per seat license, like VxWorks.

Neil

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#55 lore raw
In reply to David Miller
Quoted 5 lines · David Miller
Quoted 3 lines

I'm confused by this. If I'm NFS-booting the board then how do I get to those userland tools if I don't have a valid MAC address in place to do the root mount?

Initial ramdisk.

Aren't you basically implying that the in-kernel DHCP client and NFS mounting should be removed from the kernel too?

I'd agree with that; it's the trend. But it seems pretty harsh to say "you can do DHCP+NFS now, but if you want to set the MAC address too, then you have to reimplement DHCP+NFS a completely different way from scratch first".

-- Jamie

#56 lore raw
In reply to David Miller
Quoted 8 lines · David Miller

From: Michael Cashwell <[email protected]>
Date: Thu, 12 Mar 2009 09:41:38 -0400

Quoted 3 lines

I'm confused by this. If I'm NFS-booting the board then how do I get to those userland tools if I don't have a valid MAC address in place to do the root mount?

Initial ramdisk.

That's maybe the right solution for big machines, but for small embedded systems it's absolutely overkill. We have used Linux on several ten ARM and PowerPC boards, and the only reason we ever needed an initrd was on an IXP425 who needed a strange firmware which had a license.

Embedded boxes are often short on RAM, so wasting megabytes of space on a box that maybe has 8...16 MB RAM just because of a mac address doesn't sound like a good solution.

rsc

Signature · 4 lines
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 |
maintainer
#57 lore raw

From: Robert Schwebel <[email protected]>
Date: Fri, 13 Mar 2009 20:49:41 +0100

Quoted 10 lines · David Miller
Quoted 8 lines

From: Michael Cashwell <[email protected]>
Date: Thu, 12 Mar 2009 09:41:38 -0400

Quoted 3 lines

I'm confused by this. If I'm NFS-booting the board then how do I get to those userland tools if I don't have a valid MAC address in place to do the root mount?

Initial ramdisk.

Quoted 8 lines

That's maybe the right solution for big machines, but for small embedded systems it's absolutely overkill. We have used Linux on several ten ARM and PowerPC boards, and the only reason we ever needed an initrd was on an IXP425 who needed a strange firmware which had a license.

Embedded boxes are often short on RAM, so wasting megabytes of space on a box that maybe has 8...16 MB RAM just because of a mac address doesn't sound like a good solution.

Slipping every odd feature into the kernel on the basis that it might be useful to some small group of people doesn't sound like good system design to me.

And I know for a fact that with all of the effort people have been investing into this stupid thread, they could have implemented the necessary initrd they needed 10 times over.

I can't believe they have so much time, there must not be one of those dreaded "deadline"'s approaching.