Environment variables in startup scripts. (.script)

Is there a way to pass data through environment variables from a
previous command in a startup script?

I’m wondering because our Ethernet chip does not have an EEPROM, but we
have the MAC address stored on flash that can be retrieved by another
program, so I’d want to do something like this:


RTMIO_MAC=000102030405 # default address

get_mac_program # get the stored MAC address and set RTMIO_MAC

io-net -d speedo mac=$RTMIO_MAC,speed=100,duplex=1 -p tcpip


Thanks in advance,

John.

John Kiernan wrote:

Is there a way to pass data through environment variables from a
previous command in a startup script?

I’m wondering because our Ethernet chip does not have an EEPROM, but we
have the MAC address stored on flash that can be retrieved by another
program, so I’d want to do something like this:

RTMIO_MAC=000102030405 # default address

get_mac_program # get the stored MAC address and set RTMIO_MAC

io-net -d speedo mac=$RTMIO_MAC,speed=100,duplex=1 -p tcpip

I’m not 100% sure about the behaviour of environment variables in build
files; the only examples I can find have the environment variable being
set on the same line as the command, so I assume they’re not carried over.

You could move those commands that need the environment variable into a
shell script, and then include esh (for example) in your startup script…


Chris Herborth (cherborth@qnx.com)
Never send a monster to do the work of an evil scientist.

Chris Herborth wrote:

I’m not 100% sure about the behaviour of environment variables in build
files; the only examples I can find have the environment variable being
set on the same line as the command, so I assume they’re not carried over.

You could move those commands that need the environment variable into a
shell script, and then include esh (for example) in your startup script…

Thanks Chris,

That gave me an idea, this works: (no other script files necessary :slight_smile:

RTMIO_MAC=000102030405 # default address

get_mac_program # get the stored MAC address and set RTMIO_MAC

esh -c “io-net -d speedo mac=$RTMIO_MAC,speed=100,duplex=1 -p tcpip”


Thanks for your help,

John

John Kiernan <jkiernan@birinc.com> wrote:

Chris Herborth wrote:

I’m not 100% sure about the behaviour of environment variables in build
files; the only examples I can find have the environment variable being
set on the same line as the command, so I assume they’re not carried over.

You could move those commands that need the environment variable into a
shell script, and then include esh (for example) in your startup script…


Thanks Chris,

That gave me an idea, this works: (no other script files necessary > :slight_smile:

RTMIO_MAC=000102030405 # default address

get_mac_program # get the stored MAC address and set RTMIO_MAC

esh -c “io-net -d speedo mac=$RTMIO_MAC,speed=100,duplex=1 -p tcpip”



Thanks for your help,

John

John,

Newer versions of the network drivers support a mechanism for reading
the MAC address from the system page, if it is not specified on the command
line. In order to populate the system page with the MAC address, you would
need to modify the startup code for your board (normally, the init_hwinfo()
routine), similar to the following:


uint8_t mac_buf[6];
uintptr_t flash_ptr;

flash_ptr = startup_io_map(flash_size,flash_addr);


/*

  • read MAC address from flash and program it into the syspage
    */

for(i=0; i < 6; i++)
mac_buf = in8(flash_ptr + offset_to_mac_addr + i);

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

hwi_add_nicaddr(mac_buf,6);

startup_io_unmap(flash_ptr);


To verify if the address is getting put in the syspage correctly, you can run
the following stand-alone program, after the board has booted:

#include <sys/mman.h>
#include <errno.h>
#include <sys/syspage.h>
#include <hw/sysinfo.h>
#include <sys/neutrino.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{

unsigned start,i;
struct hwi_nicaddr *tag;
unsigned off=0;

if ((start = hwi_find_item (HWI_NULL_OFF, “network”, NULL)) == HWI_NULL_OFF)
return (-1);

if ((start = hwi_find_tag(start,0,“nicaddr”)) == HWI_NULL_OFF)
return (-1);

tag = hwi_off2tag(start);

printf(“mac address = 0x”);
for(i=0;i<6;i++)
printf("%2.2X",tag->addr);
printf("\n");

return(0);
}




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

Dave Green wrote:

Newer versions of the network drivers support a mechanism for reading
the MAC address from the system page, if it is not specified on the command
line. In order to populate the system page with the MAC address, you would
need to modify the startup code for your board (normally, the init_hwinfo()
routine), similar to the following:
snip

Thanks Dave, I didn’t realize that. This will do exactly what we need.

Thanks!

John