This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Assigning IP Address to Multiple Interfaces in NDK

Other Parts Discussed in Thread: SYSBIOS

Hi,

We are developing NDK drivers of AM335x using,

NDK v2.22.02.16

SYS/BIOS v6.33.04.39

I'm facing issues when trying to assign IP addresses for multiple interfaces on AM335x based IDK(The two interfaces being ICSS based PRU and CPSW). Can you give me an insight on how to assign the IP addresses for both interfaces? Currently both drivers are up and running, but IP Address is assigned to only one IF. Here is the IF info

[CortxA8] EDRV: PDI MAC Address: 00-31-de-00-00-00
[CortxA8] Nimu: EMAC started
[CortxA8] Nimu: Registration of EMAC successful
[CortxA8] Using MAC Address: bc-6a-29-63-a4-a6
[CortxA8] Got packet back, Enabling RXGot packet back, Enabling RXEMAC has been started successfully
[CortxA8] Registeration of the EMAC Successful
[CortxA8] Interface Name: eth1
[CortxA8] Interface Id : 2
[CortxA8] IP Address : 192.168.1.4
[CortxA8] IP Mask : 255.255.254.0
[CortxA8] MTU : 1500 bytes
[CortxA8] MAC Address : 0xbc-0x6a-0x29-0x63-0xa4-0xa6
[CortxA8]
[CortxA8]
[CortxA8] Interface Name: eth0
[CortxA8] Interface Id : 1
[CortxA8] MTU : 1500 bytes
[CortxA8] MAC Address : 0x0-0x31-0xde-0x0-0x0-0x0
[CortxA8]
[CortxA8]
[CortxA8] Network Added: If-2:192.168.1.4
[CortxA8] enter taskPruss()
[CortxA8] Link Status: 100Mb/s Full Duplex on PHY 2

The assigned IP address is taken for *.cfg file. I can toggle the Ip.ifIdx to run the drivers individually.

I tried using the following approach to assign IP address on the first interface, but it results in an exception(probably as those entries are not available)

/* get the current static IP entry */
// CfgGetEntry(hCfg, CFGTAG_IPNET, 1, 1, &hCfgIpAddr);

/* remove the current static IP entry */
// CfgRemoveEntry(hCfg, hCfgIpAddr);

/* add a new static IP entry */
// CfgAddEntry(hCfg, CFGTAG_IPNET, 1, 0,
// sizeof(CI_IPNET), (UINT8 *)&NA, 0);

Thanks,
Vinesh 

  • Vinesh,

    Can you please attach your .cfg file?

    Thanks,
    Scott

  • Scott,

    Attaching the .cfg file. I have commented out initialization of second IP instance.

    Thanks,
    Vinesh

    6888.app.cfg

  • Thanks Vinesh.  The .cfg file looks good. 

    I asked around and this can work, but I think you’ll need to have the addresses on different subnets.  Please see this forum thread: http://e2e.ti.com/support/embedded/bios/f/355/t/237302.aspx

    Thanks,
    Scott

  • Scott, 

    Thanks for the response.

    As suggested, I modified the IP configuration in .cfg file to this 

    Ip.ResolveIP = false;
    Ip.dhcpClientMode = 1;
    Ip.CallByIP = false;
    Ip.autoIp = false;
    Ip.address = "192.168.1.3";
    Ip.gatewayIpAddr = "192.168.1.1";
    Ip.mask = "255.255.0.0";
    Ip.ifIdx = 2;

    IpNew.ResolveIP = false;
    IpNew.dhcpClientMode = 1;
    IpNew.CallByIP = false;
    IpNew.autoIp = false;
    IpNew.address = "192.168.2.3";
    IpNew.gatewayIpAddr = "192.168.2.1";
    IpNew.mask = "255.255.0.0";
    IpNew.ifIdx = 1;

    I believe this configuration meets the requirement of different subnets, but still only one IF gets bound with an IP Address

    Thanks,

    Vinesh

  • Vinesh,

    Unfortunately what you have done above won't work.  The Ip module (from your *cfg file) does not support setting multiple IP addresses, it only supports the setting of a single IP address.

    You have to use the run time configuration APIs (in addition to the *.cfg file configuration) in this case.

    I think what you should try is:

    1. Keep this *.cfg code:

    Ip.ResolveIP = false;
    Ip.dhcpClientMode = 1;
    Ip.CallByIP = false;
    Ip.autoIp = false;
    Ip.address = "192.168.1.3";
    Ip.gatewayIpAddr = "192.168.1.1";
    Ip.mask = "255.255.0.0";
    Ip.ifIdx = 2;

    2. Remove this code from your  *.cfg file:

    IpNew.ResolveIP = false;
    IpNew.dhcpClientMode = 1;
    IpNew.CallByIP = false;
    IpNew.autoIp = false;
    IpNew.address = "192.168.2.3";
    IpNew.gatewayIpAddr = "192.168.2.1";
    IpNew.mask = "255.255.0.0";
    IpNew.ifIdx = 1;

    3. Add the following config code into your *.cfg file:

         var Global = xdc.useModule('ti.ndk.config.Global');

         Global.stackBeginHook = '&stackInitHook';


    4. Create the following hook function to add the IP address for interface 1 to the configuration at run time.  Note that I haven't compiled this or tried it.  You may need to configure the gateway route differently, not sure on that one, this gateway setting may conflict with the one that will be created by the code generated for you by step #1 above.

    /*
     * ======== stackInitHook ========
     * hook called from ti_nkd_config_Global_stackThread() to run user setup code
     */
    stackInitHook(HANDLE hCfg)
    {
        CI_IPNET NA;
        CI_ROUTE RT;

        /* Static IP Address settings for interface 1 */
        char *ipAddr      = "192.168.2.3";
        char *ipMask      = "255.255.0.0";
        char *ipGateway   = "192.168.2.1";

        /* Add IP address for interface 1 */
        NA.IPAddr = inet_addr(ipAddr);
        NA.IPMask = inet_addr(ipMask);
        CfgAddEntry(hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET),
                (UINT8 *)&NA, 0 );

        /*
         * Add gateway for interface 1
         * --> I *think* the below should work but you may need different values ...
         */
        bzero(&RT, sizeof(RT));
        RT.IPDestAddr = 0;
        RT.IPDestMask = 0;
        RT.IPGateAddr = inet_addr(ipGateway);

        CfgAddEntry(hCfg, CFGTAG_ROUTE, 0, 0,
                sizeof(CI_ROUTE), (UINT8 *)&RT, 0);
        
    }


    Steve

  • Thanks a lot for that Steve.

    A small correction though, it's 

    Global.stackInitHook = "&stackInitHook";

    not BeginHook.

    Now the two interfaces have IP addresses assigned, and things look good! But now, one of the interface is showing random ping timeouts(these two drivers work fine individually). Is there something else I should take care of?  (this was a driver issue, fixed now)

    Also, the code mentions setting IP address for interface 1. How can I set the IP address for Interface 2?

    Thanks,
    Vinesh 

  • Glad you resolved that ping timeout.

    Vinesh Balan said:
    Also, the code mentions setting IP address for interface 1. How can I set the IP address for Interface 2?

    Your config code that I show in item #1 above is configuring interface 2:

    Ip.ResolveIP = false;
    Ip.dhcpClientMode = 1;
    Ip.CallByIP = false;
    Ip.autoIp = false;
    Ip.address = "192.168.1.3";
    Ip.gatewayIpAddr = "192.168.1.1";
    Ip.mask = "255.255.0.0";
    Ip.ifIdx = 2;

    Steve

  • Steve,

    I meant assigning the IP Address for interface 2 via code.

    Thanks,
    Vinesh 

  • The code would be very similar, only different IP address and interface arguments.  The trick is you have to override the static IP address setting that's coming out of the configuration.

    Please refer to this forum post for how to override the config generated IP address: http://e2e.ti.com/support/embedded/bios/f/355/t/221215.aspx

    Steve

  • Hello Steven,

         I also tried the test like you provide, But only interface 1 get the ip address set by "stackInitHook" function.  The interface 2 not get the ip address as I set in NDK XCONF tools.

    My CPSW ethernet switch code is take from Sitara ind sdk 2.2.0.5, OS use the TI-RTOS for Sitara 2.00.01.23(SYSBIOS 6.40.1.15, NDK 2.23.01.01)

    code to init the interface 1, called from NDK hook

    stackInitHook(HANDLE hCfg)
    {
    CI_IPNET NA;
    CI_ROUTE RT;

    /* Static IP Address settings for interface 1 */
    char *ipAddr = "192.168.2.3";
    char *ipMask = "255.255.0.0";
    char *ipGateway = "192.168.2.1";

    /* Add IP address for interface 1 */
    NA.IPAddr = inet_addr(ipAddr);
    NA.IPMask = inet_addr(ipMask);
    CfgAddEntry(hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET),
    (UINT8 *)&NA, 0 );

    /*
    * Add gateway for interface 1
    * --> I *think* the below should work but you may need different values ...
    */
    bzero(&RT, sizeof(RT));
    RT.IPDestAddr = 0;
    RT.IPDestMask = 0;
    RT.IPGateAddr = inet_addr(ipGateway);

    CfgAddEntry(hCfg, CFGTAG_ROUTE, 0, 0,
    sizeof(CI_ROUTE), (UINT8 *)&RT, 0);

    }

    and my cfg file is 0407.app.cfg

    regist code is like this:

    Eth_HW_Init();

    config.phyAddr[0] = PHY_ADDRESS_Port0;
    config.phyAddr[1] = PHY_ADDRESS_Port1;
    config.numberPorts = 2;
    config.macModeFlags = CPSW_CONFIG_MODEFLG_GIGABIT| CPSW_CONFIG_MODEFLG_FULLDUPLEX;
    config.resvd = 1;

    SetMacConfiguration(&config);

    if(AddNetifEntryFn(CPSW_NETIF_INIT) == 0)
    BIOS_exit(0);

    Is there somthing that I should change in configure code?

    Thank you!!