Dynamical setting of MAC and IP addresses

Hi

We have got our BSP up and running but I am looking for a way to set the MAC
and IP addresses
dynamically instead of fixing them in the start up script.

Currently I have the two lines:


io-net -c1 -ptcpip cache=1 -dmpc5200 mac=004042012580
ifconfig en0 192.168.1.62

In my startup-script.bsh.

We have the MAC and IP addresses stored at a certain address in the FLASH
and I have written a tool to get them from there. I can call the tool
supplying the address I am interested in as a command line parameter and the
tool will then output the value of the variable:

getaddr ipaddr

10.20.0.210

getaddr ethaddr

0040420125D1

In the normal shell I can use back-apostrophes (or whatever they are
properly called) to use the output of the command as parameter for another
command.
So I can use

ifconfig en0 getaddr ipaddr

to set the ip address to the address stored in FLASH.

I have included my tool in the BSP image that I am building and replaced the
two lines from the script shown above with

io-net -c1 -ptcpip cache=1 -dmpc5200 mac=getaddr ethaddr
ifconfig en0 getaddr ipaddr

but apparently the trick of using back-apostrophes does not work in the
startup script.

I am sure that there is a solution to this problem, can anyone give me a
hin`t?

Thanks
/urs

Hello,

The way we normally do this is to have the startup code read the
MAC address from wherever it is available (in flash, in an i2c eeprom,
etc.), and then populate the syspage with the MAC address. The network
driver will then check to see if a valid MAC address is present in the
syspage. If so, and if no address was specified on the command line,
it will use the address from the syspage. If a command line MAC address
was specified, that will override the one from the syspage. If neither
a syspage or command line MAC address is specified, the driver will then
complain.

To modify the startup code to get the MAC address and populate the syspage,
you can add code similar to the following to the init_hwinfo.c routine
of startup-mgt5200 (note that this code is for a different board - modify
the reading and converting of the MAC address accordingly):


char ser_mac[2];
uint8_t mac_buf[6];

/* read MAC address from VPD area of flash, convert it from ASCII to hex,

  • and program it into the syspage
    */

for(i=0; i < 6; i++) {
ser_mac[0] = in8(VPD_ADDR + MAC_OFFSET + (i2));
ser_mac[1] = in8(VPD_ADDR + MAC_OFFSET + (i
2)+1);
mac_buf = atoh(ser_mac);
}

hwi_add_device(HWI_ITEM_BUS_UNKNOWN, HWI_ITEM_DEVCLASS_NETWORK, “network”, 0);

hwi_add_nicaddr(mac_buf,6);


The devn-mpc5200 network driver will then obtain the MAC address from the syspage.

Dave



Urs Beeli <invalid@unknown.xx> wrote:

Hi

We have got our BSP up and running but I am looking for a way to set the MAC
and IP addresses
dynamically instead of fixing them in the start up script.

Currently I have the two lines:




_io-net -c1 -ptcpip cache=1 -dmpc5200 mac=004042012580
ifconfig en0 192.168.1.62

In my startup-script.bsh.

We have the MAC and IP addresses stored at a certain address in the FLASH
and I have written a tool to get them from there. I can call the tool
supplying the address I am interested in as a command line parameter and the
tool will then output the value of the variable:
\

getaddr ipaddr

10.20.0.210
\

getaddr ethaddr

0040420125D1

In the normal shell I can use back-apostrophes (or whatever they are
properly called) to use the output of the command as parameter for another
command.
So I can use
\

ifconfig en0 getaddr ipaddr\


to set the ip address to the address stored in FLASH.

I have included my tool in the BSP image that I am building and replaced the
two lines from the script shown above with

io-net -c1 -ptcpip cache=1 -dmpc5200 mac=getaddr ethaddr
ifconfig en0 getaddr ipaddr

but apparently the trick of using back-apostrophes does not work in the
startup script.

I am sure that there is a solution to this problem, can anyone give me a
hin`t?

Thanks
/urs_



David Green (dgreen@qnx.com)
QNX Software Systems Ltd.
http://www.qnx.com

“Dave Green” <dgreen@qnx.com> wrote in message
news:dh12vq$1nc$1@inn.qnx.com

Hi Dave

Thanks for your answer. I have tried to play around a little with your
suggestion,
however, I have run up against a few obstacles.

To modify the startup code to get the MAC address and populate the
syspage,
you can add code similar to the following to the init_hwinfo.c routine
of startup-mgt5200 (note that this code is for a different board - modify
the reading and converting of the MAC address accordingly):

I have adapted the reading and converting of the MAC address, that was a
piece of
cake. Where I have problem is for the following lines:

hwi_add_device(HWI_ITEM_BUS_UNKNOWN, HWI_ITEM_DEVCLASS_NETWORK,
“network”, 0);
hwi_add_nicaddr(mac_buf,6);

The compiler complains that I am using implicit declarations for these two
functions.

I have tried searching for them in the online help but got no hit.
Interestingly enough, if I
browse the information on the syspage I get these functions listed. I tried
including

<sys/syspage.h>
<hw/sysinfo.h>

to no avail (they were the headers listed in the online help).

I have also tried a file based search for these two functions but without
success.

Do I have to roll my own? Or should they be offered by the BSP?

The devn-mpc5200 network driver will then obtain the MAC address from the
syspage.

Assuming I manage to get this to work, I then still have the issue of the IP
address. Is
there a similar method for providing iofconfig with a default ip-address?

Cheers
/urs

Urs Beeli <invalid@unknown.xx> wrote:

“Dave Green” <> dgreen@qnx.com> > wrote in message
news:dh12vq$1nc$> 1@inn.qnx.com> …

Hi Dave

Thanks for your answer. I have tried to play around a little with your
suggestion,
however, I have run up against a few obstacles.

To modify the startup code to get the MAC address and populate the
syspage,
you can add code similar to the following to the init_hwinfo.c routine
of startup-mgt5200 (note that this code is for a different board - modify
the reading and converting of the MAC address accordingly):

I have adapted the reading and converting of the MAC address, that was a
piece of
cake. Where I have problem is for the following lines:

hwi_add_device(HWI_ITEM_BUS_UNKNOWN, HWI_ITEM_DEVCLASS_NETWORK,
“network”, 0);
hwi_add_nicaddr(mac_buf,6);

The compiler complains that I am using implicit declarations for these two
functions.

These functions are part of the startup library; all you should need
in your init_hwinfo.c is:

#include “startup.h”


I have tried searching for them in the online help but got no hit.
Interestingly enough, if I
browse the information on the syspage I get these functions listed. I tried
including

sys/syspage.h
hw/sysinfo.h

to no avail (they were the headers listed in the online help).

I have also tried a file based search for these two functions but without
success.

Do I have to roll my own? Or should they be offered by the BSP?

The devn-mpc5200 network driver will then obtain the MAC address from the
syspage.

Assuming I manage to get this to work, I then still have the issue of the IP
address. Is
there a similar method for providing iofconfig with a default ip-address?

No, I don’t believe so…


Cheers
/urs

David Green (dgreen@qnx.com)
QNX Software Systems Ltd.
http://www.qnx.com