This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Some simple questitions


Dmitry Varakin wrote:
Hello!

I have questitions about eCos:
1. Is it possible to change MAC and IP addresses "on the fly". For
example, function like "set_mac_addr (eth0, my_mac)".
yes, I do it.
Please search through the mailing list. It was not that easy to find, but I did find it: see attach ims_eth.c; and in the comments you can find a link to the original contribution from Sébastien Couret



2. Can I have direct access to processor's registers from my user
application? Linux has "mmap()" function for that purpose.
3. Is it possible to unload RedBoot from RAM when my user application
is starting (to increase amount of free RAM)?
yes, I do.
As Bob K also says, I use romram mode because my resources are indeed that scarce.
for safety, I always start up with redboot, and then jump to the application that is compiled in romram mode; I only needed to do some changes in hal_platform_setup not to initialize the hardware again (define out that assembly code for that specific startup)


4. Where can I download the toolchain to compile eCos with cygwin?

Thanks for all answers!

--
Dmitry.


-- Jürgen Lambrecht Diksmuidse Heerweg 338 8200 Sint-Andries Tel: +32 (0)50 842901 GSM: +32 (0)476 313389
/* #include <pkgconf/system.h> */
/* #ifdef CYGBLD_DEVS_ETH_DEVICE_H    // Get the device config if it exists */
/* #include CYGBLD_DEVS_ETH_DEVICE_H */
/* #endif */


#include <errno.h>
#include <network.h>
#include <netinet/if_ether.h>
#include <arpa/inet.h> //inet_addr
#include <sys/param.h>
#include <cyg/infra/diag.h>			// diag_snprintf

/* #include <cyg/hal/hal_arch.h> */
/* #include <cyg/io/eth/eth_drv.h> //eth defines */
#include "../inc/ims_logging.h" //debug_printf
#include "../inc/ims_global.h" //debug defines, tlv types, ..

#define MACSTRING 18


//struct	ifreq {
//#define IFHWADDRLEN  6
//	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
//	union {
//		struct	sockaddr ifru_addr;
//		struct	sockaddr ifru_dstaddr;
//		struct	sockaddr ifru_broadaddr;
//		struct	sockaddr ifru_hwaddr;
//		short	ifru_flags[2];
//		int	ifru_metric;
//		int	ifru_mtu;
//		int	ifru_phys;
//		int	ifru_media;
//		caddr_t	ifru_data;
//	} ifr_ifru;
//#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
//#define	ifr_hwaddr	ifr_ifru.ifru_hwaddr	/* MAC address */
//#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
//#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
//#define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags */
//#define	ifr_prevflags	ifr_ifru.ifru_flags[1]	/* flags */
//#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
//#define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
//#define ifr_phys	ifr_ifru.ifru_phys	/* physical wire */
//#define ifr_media	ifr_ifru.ifru_media	/* physical media */
//#define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
//};

/* extern struct bootp eth0_bootp_data; */
/* extern cyg_bool_t   eth0_up; */
/* extern const char  *eth0_name; */

/* extern unsigned char __local_enet_addr[]; */
/* extern struct eth_drv_sc *__local_enet_sc; */
/* struct eth_drv_sc { */
/*     struct eth_hwr_funs *funs; */
/*     void                *driver_private; */
/*     const char          *dev_name; */
/*     int                  state; */
/*     struct arpcom        sc_arpcom; * ethernet common * */
/* }; */
/* struct eth_hwr_funs { */
/*     // Initialize hardware (including startup) */
/*     void (*start)(struct eth_drv_sc *sc, */
/*                   unsigned char *enaddr, */
/*                   int flags); */
/*     // Shut down hardware */
/*     void (*stop)(struct eth_drv_sc *sc); */
/*     // Device control (ioctl pass-thru) */
/*     int  (*control)(struct eth_drv_sc *sc, */
/*                     unsigned long key, */
/*                     void *data, */
/*                     int   data_length); */
/*     // Query - can a packet be sent? */
/*     int  (*can_send)(struct eth_drv_sc *sc); */
/*     // Send a packet of data */
/*     void (*send)(struct eth_drv_sc *sc, */
/*                  struct eth_drv_sg *sg_list, */
/*                  int sg_len, */
/*                  int total_len, */
/*                  unsigned long key); */
/*     // Receive [unload] a packet of data */
/*     void (*recv)(struct eth_drv_sc *sc, */
/*                  struct eth_drv_sg *sg_list, */
/*                  int sg_len); */
/*     // Deliver data to/from device from/to stack memory space */
/*     // (moves lots of memcpy()s out of DSRs into thread) */
/*     void (*deliver)(struct eth_drv_sc *sc); */
/*     // Poll for interrupts/device service */
/*     void (*poll)(struct eth_drv_sc *sc); */
/*     // Get interrupt information from hardware driver */
/*     int (*int_vector)(struct eth_drv_sc *sc); */
/*     // Logical driver interface */
/*     struct eth_drv_funs *eth_drv, *eth_drv_old; */
/* }; */
/* struct bootp { */
/*     unsigned char    bp_op;			* packet opcode type * */
/*     unsigned char    bp_htype;			* hardware addr type * */
/*     unsigned char    bp_hlen;			* hardware addr length * */
/*     unsigned char    bp_hops;			* gateway hops * */
/* #ifdef __ECOS */
/*     u_int32_t        bp_xid;			* transaction ID * */
/* #else */
/*     unsigned int     bp_xid;			* transaction ID * */
/* #endif */
/*     unsigned short   bp_secs;			* seconds since boot began * */
/*     unsigned short   bp_flags;			* RFC1532 broadcast, etc. * */
/*     struct in_addr   bp_ciaddr;			* client IP address * */
/*     struct in_addr   bp_yiaddr;			* 'your' IP address * */
/*     struct in_addr   bp_siaddr;			* server IP address * */
/*     struct in_addr   bp_giaddr;			* gateway IP address * */
/*     unsigned char    bp_chaddr[BP_CHADDR_LEN];	* client hardware address * */
/*     char	     bp_sname[BP_SNAME_LEN];	* server host name * */
/*     char	     bp_file[BP_FILE_LEN];	* boot file name * */
/*     unsigned char    bp_vend[BP_VEND_LEN];	* vendor-specific area * */
/*     // note that bp_vend can be longer, extending to end of packet. */
/* }; */
/* struct bootp eth0_bootp_data; filled in by init_all_network_interfaces*/
/*     diag_printf("BOOTP[%s] op: %s\n", intf, _bootp_op[bp->bp_op]); */
/*     diag_printf("       htype: %s\n", _bootp_hw_type[bp->bp_htype]); */
/*     diag_printf("        hlen: %d\n", bp->bp_hlen ); */
/*     diag_printf("        hops: %d\n", bp->bp_hops ); */
/*     diag_printf("         xid: 0x%x\n", bp->bp_xid ); */
/*     diag_printf("        secs: %d\n", bp->bp_secs ); */
/*     diag_printf("       flags: 0x%x\n", bp->bp_flags ); */
/*     diag_printf("       hw_addr: "); */
/*     for (i = 0;  i < bp->bp_hlen;  i++) { */
/*         diag_printf("%02x", bp->bp_chaddr[i]); */
/*         if (i != (bp->bp_hlen-1)) diag_printf(":"); */
/*     } */
/*     diag_printf("\n"); */
/*     diag_printf("     client IP: %s\n", inet_ntoa(bp->bp_ciaddr)); */
/*     diag_printf("         my IP: %s\n", inet_ntoa(bp->bp_yiaddr)); */
/*     diag_printf("     server IP: %s\n", inet_ntoa(bp->bp_siaddr)); */
/*     diag_printf("    gateway IP: %s\n", inet_ntoa(bp->bp_giaddr)); */

/*     optover = 0; // See whether sname and file are overridden for options */
/*     length = sizeof(optover); */
/*     (void)get_bootp_option( bp, TAG_DHCP_OPTOVER, &optover, &length ); */
/*     if ( !(1 & optover) && bp->bp_sname[0] ) */
/*         diag_printf("        server: %s\n", bp->bp_sname); */
/*     if ( ! (2 & optover) && bp->bp_file[0] ) */
/*         diag_printf("          file: %s\n", bp->bp_file); */
/*     if (bp->bp_vend[0]) { */
/*         diag_printf("  options:\n"); */
/*         op = &bp->bp_vend[4]; */
/*         while (*op != TAG_END) { */
/*             switch (*op) { */
/*             case TAG_PAD: */
/*                 op++; */
/*                 continue; */
/*             case TAG_SUBNET_MASK: */
/*             case TAG_GATEWAY: */
/*             case TAG_IP_BROADCAST: */
/*             case TAG_DOMAIN_SERVER: */
/*                 ap = (char *)&addr[0]; */
/*                 len = *(op+1); */
/*                 for (i = 0;  i < len;  i++) { */
/*                     *ap++ = *(op+i+2); */
/*                 } */
/*                 if (*op == TAG_SUBNET_MASK)   ap =  "  subnet mask"; */
/*                 if (*op == TAG_GATEWAY)       ap =  "      gateway"; */
/*                 if (*op == TAG_IP_BROADCAST)  ap =  " IP broadcast"; */
/*                 if (*op == TAG_DOMAIN_SERVER) ap =  "domain server"; */
/* BOOTP[eth0] op: REPLY */
/*        htype: Ethernet */
/*         hlen: 6 */
/*         hops: 0 */
/*          xid: 0x0 */
/*         secs: 0 */
/*        flags: 0x0 */
/*        hw_addr: 00:0e:3d:02:00:00 */
/*      client IP: 10.0.56.252 */
/*          my IP: 10.0.56.252 */
/*      server IP: 10.0.60.1 */
/*     gateway IP: 0.0.0.0 */
/*   options: */
/*         subnet mask: 255.255.0.0 */
/*        IP broadcast: 10.0.255.255 */
/*             gateway: 0.0.0.0 */

char* ether_print(const char cp[ETHER_ADDR_LEN], char *etheraddr,const unsigned int len)
{
 diag_snprintf(etheraddr,len,"%02x:%02x:%02x:%02x:%02x:%02x",cp[0],cp[1],cp[2],cp[3],cp[4],cp[5]);
 return(etheraddr);
}


#define FPGA_MAC_REG 0x08000050
void std_ims_read_mac(char *esa)
{
  int i;
  cyg_uint16 status;
  //todo: read it from fis
  for (i=0; i<6; i+=2) {
    HAL_READ_UINT16((FPGA_MAC_REG+i), status);
    esa[4-i] = (char)(status>>8);
    esa[5-i] = (char)(status);
  }
#if  NETW_DEBUG
  debug_printf("FPGA Mac addr %02x:%02x:%02x:%02x:%02x:%02x\n",
               esa[0], esa[1], esa[2], esa[3], esa[4], esa[5]);
#endif
}
///net/common/current/tests/set_mac_address.c: not usable for me
//http://sourceware.org/ml/ecos-discuss/2005-08/msg00015.html
//JL: OK, this also changes the fpga mac address register (via ecos eth driver
//ioctl calls)
TLV_BOOL set_mac_address(const char *interface, char *mac_address)
{
  int test_sock=0, i=0;			// Socket PF_INET/SOCK_DGRAM
  struct ifreq ifr;
#if  NETW_DEBUG
  unsigned char display[MACSTRING];
#endif
  test_sock = socket( PF_INET, SOCK_DGRAM, 0 );
  if( test_sock == -1 )
  {
    debug_printf("Cannot obtain socket\n");
    return TLV_FALSE;
  }
  
  memset(&ifr,0,sizeof( struct ifreq ) );
  strncpy(ifr.ifr_name,interface,IFNAMSIZ);
  for (i=0;i<ETHER_ADDR_LEN;i++)
    ifr.ifr_hwaddr.sa_data[i]=mac_address[i];
#if  NETW_DEBUG
  ether_print(mac_address,display,MACSTRING);
#endif
  if( ioctl( test_sock, SIOCSIFHWADDR, &ifr ) == -1 )
  {
    debug_printf("Cannot set MAC adress for %s: %s\n",interface,strerror(errno));
    close(test_sock);
    return TLV_FALSE;
  }
  else 
  {
#if  NETW_DEBUG
    debug_printf("MAC Adress for %s set to %s\n",interface,display);
#endif
    close(test_sock);
    return TLV_TRUE;
  }

/* #if  NETW_DEBUG */
/*   debug_printf( "Mac addr %02x:%02x:%02x:%02x:%02x:%02x\n", */
/*                 ifr.ifr_hwaddr.sa_data[0], */
/*                 ifr.ifr_hwaddr.sa_data[1], */
/*                 ifr.ifr_hwaddr.sa_data[2], */
/*                 ifr.ifr_hwaddr.sa_data[3], */
/*                 ifr.ifr_hwaddr.sa_data[4], */
/*                 ifr.ifr_hwaddr.sa_data[5] ); */
/* #endif */
}

/*   __local_enet_sc->funs->control(__local_enet_sc, */
/*   ETH_DRV_SET_MAC_ADDRESS,new_eth0_addr, 0); */
/*     for (i = 0;  i < bp->bp_hlen;  i++) { */
/*         diag_printf("%02x", bp->bp_chaddr[i]); */
/*         if (i != (bp->bp_hlen-1)) diag_printf(":"); */
/*        hw_addr: 00:0e:3d:02:00:00 */
/* control(struct eth_drv_sc* sc, unsigned long key, void* data, int
   data_length) Only the last 2 bytes are written. */


//http://sourceware.org/ml/ecos-discuss/2005-08/msg00015.html
TLV_BOOL set_ip_address(const char *interface, const char *ip_address)
{
  int test_sock;
  struct sockaddr_in* addr=NULL;
  struct ifreq ifr;

  test_sock = socket( PF_INET, SOCK_DGRAM, 0 );
  if( test_sock == -1 )
  {
    debug_printf("Cannot obtain IP sock\n");
    return TLV_FALSE;
  }

  memset(&ifr,0,sizeof( struct ifreq ) );
  strncpy(ifr.ifr_name,interface,IFNAMSIZ);
  //JL: Delete old IP address, else there will be 2 IP addresses!
  if( ioctl( test_sock, SIOCGIFADDR, &ifr ) == -1 )
  {
    debug_printf("Cannot obtain IP address of %s: %s\n",interface,strerror(errno));
  }
  else
  {
    if( ioctl( test_sock, SIOCDIFADDR, &ifr ) != 0 )
    {
      debug_printf("Cannot suppress old IP for %s: %s\n",interface,strerror(errno));
    }
  }

  memset( &ifr, 0, sizeof( struct ifreq ) );
  addr= (struct sockaddr_in *)&(ifr.ifr_addr);
  memset(addr, 0, sizeof( struct sockaddr_in) );
  addr->sin_len=sizeof(struct sockaddr_in);
  addr->sin_family=AF_INET;
  addr->sin_addr.s_addr=inet_addr(ip_address);
  strncpy(ifr.ifr_name,interface,IFNAMSIZ);

  if( ioctl( test_sock, SIOCSIFADDR, &ifr ) != 0 )
  {
    debug_printf("Cannot set IP address of %s to %s: %s\n",interface,ip_address,strerror(errno));
    close(test_sock);
    return TLV_FALSE;;
  }
  else 
  {
#if  NETW_DEBUG
    debug_printf("IP address for %s set to %s\n",interface,inet_ntoa(addr->sin_addr));
#endif
    close(test_sock);
    return TLV_TRUE;
  }
}

TLV_BOOL read_ip_address(const char *interface, char *ip_address)
{
  int s;
  struct ifreq ifr;
  struct sockaddr_in* addr=NULL;
  
  s = socket(AF_INET, SOCK_DGRAM, 0);
  if (s < 0) 
  {
    debug_printf("Cannot obtain IP socket\n");
    return TLV_FALSE;
  }

  strcpy(ifr.ifr_name, interface);

  if( ioctl( s, SIOCGIFADDR, &ifr ) == -1 )
  {
    debug_printf("Cannot obtain IP address\n");
    return TLV_FALSE;
  }
  else
  {
    addr= (struct sockaddr_in *)&(ifr.ifr_addr);
    strcpy(ip_address,inet_ntoa(addr->sin_addr));
#if  NETW_DEBUG
    debug_printf("IP address for '%s' is '%s'\n",interface,inet_ntoa(addr->sin_addr));
    show_bootp(eth0_name, &eth0_bootp_data);
/*     show_network_tables(); */
#endif
    return TLV_TRUE;
  }
}
-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]