Avatar Blogs during GSoC-2025 period at RTEMS for the project - Providing SPARC GRETH Network Drivers for lwIP

Week-4 @RTEMS-GSoC-2025

Overview


This week, I completed the following tasks :

  • Worked on coding for various sections of Initilaization of GRETH lwIP Driver
  • Worked on testing Telnet from RTEMS Net Services on SIS for testing Legacy GRETH Driver functionality

Work completed this week


  1. Worked on coding for various sections of Initilaization of GRETH lwIP Driver.

    • Added Draft MR for the code I create for GRETH lwIP Port for GSoC 2025
    • Added functions for MDIO Read, MDIO Write and MDIO Initialization in greth_mdio.h
    • Added function for GRETH Driver Initialization EMACInit() in greth_emac.h
    • Added fucntion greth_init_buffer_descriptors() for initializing buffer descriptors used in the communication process, almalloc() for allocation of memory aligned to a specific value, greth_rx_buffer_refill() for amking packet buffers available for packet reception and greth_hw_set_addr() for setting GRETH MAC Address, all in greh_netif.c.
    • Added fucntions for PHY Reset, and Autonegotiation in greth_phy.c
    • Added a new file greth_netif.h which has function declarations which are useful for debugging purposes.
    • Added function EMACMACSrcAddrSet() in greth_emac.h for setting GRETH MAC Address.
    • Added leon3.json file which will help building RTEMS lwIP Package for sparc/leon3 BSP.
  2. New approaches considered in GRETH lwIP Driver as compared to GRETH Legacy Driver as well as TMS570 lwIP Driver considered as example:
    • Used same struct emac_bd for both transmit and receive buffer descriptors, since they share the same fields
    • Added fields num_tx_bd and num_rx_bd in struct greth_netif_struct for setting the number of transmit and receive buffer descriptors separately.
    • Set size of buffptr field in emac_bd to 32 bits.
    • Moved struct phy_dev_info and GRETH MII Register Macros from greth.h to greth_phy.h
    • Added few related filds like PHY address, PHY status and PHY control variables to struct phy_dev_info.
  3. Tried testing Telnet on RTEMS SIS for simulation of GRETH Legacy Driver
    • I had a virtual bridge (network switch) lxcbr0 and when SIS starts it creates a virtual GRETH ethernet network interface tap0 which connects to lxcbr0. To complete the network, I created a virtual ethernet cable having 2 ends (virtual network interfaces) : veth-lxc connected to lxcbr0 and veth-prithvi connected to the host.
    • However, using telnetd01.exe from RTEMS Net Services, and on running
      >>> sudo ./sis -leon3 -bridge lxcbr0 ./telnetd01.exe -v
      I got an error indicating Trap 7 (memory address not aligned) Trap_7_Error
    • For investigating why the trap occured, I checked using
      >>> sparc-rtems7-objdump -d telnetd01.exe | grep 40017694
      (because at that time Program Counter was at 0x40017694) and got
      >>> 40017694: c2 00 80 00 ld [ %g2 ], %g1
      which indicates loading a 32-bit word from memory address at register %g2, to register %g1. Register %g2 contained 0x400d800e which is not a 4-byte aligned address, causing the trap error. This error occured as soon as I started telnet client on my host.
    • So I tried using -Wcast-align -Wstrict-aliasing flags in the waf build system (in wscript file for RTEMS repository) for resolvng the memory alignment issues and rebuilt sparc/leon3 BSP, but the error persisted.
    • Next I used addr2line as
      >>> addr2line -e telnetd01.exe 0x40017694
      which translates program address 0x40017694 in the executable telnetd01.exe to corresponding source file name and line number; from this I obtained
      >>> ~/quick-start/rtems/7/sparc-rtems7/leon3/rtems-net-legacy/machine/in_cksum.h:193
      The code was related to a fucntion for calculating IP Header checksum for IPv4 packet on SPARC Architecture; however the IP Header used was not at a 4-byte aligned memory location causing the trap error.
    • For this I used posix_memalign((void**)&ip, 4, sizeof(struct ip)) by using RTEMS_POSIX_API = True option in config.ini in RTEMS repository and rebuilding sparc/leon3 BSP Using posix_memalign()
      to allocate a block of 4-byte aligned block of memory for the IP header and this resolved the trap 7 error and hence, now SIS and the telnet server on it didn’t crash.
    • However, now, upon running this command
      >>> telnet 10.0.3.2 23
      which means create a Telnet Client session to connect to de10.0.3.2 on TCP Port 23 (default telnet port); however, the client just kept trying until it closed the session due to timeout.
    • To verify if correct IP Address was being used to connect to in the telnet client I printed the IP address being used using the function
      void print_ip1(void) {
          printf("RTEMS IP address: %s\n", ifcfg.ip_address);
      }
    • This gave me the IP address which I had configured for GRETH while building RTEMS Net Services : 10.0.3.2; also, I added a printf("legacy stack initialization successful\n"); statement for verifying if legacy networking stack was initialized correctly in corresponding net_start() function at rtems-net-services/net/legacy/net_adapter.c, and it was initialized correctly. greth_self_ip_chk

Plans for next week


  1. Debug Telnet Server-Client connection issue for GRETH Legacy Driver
  2. Continue on GRETH lwIP Code
  3. Create blogs till Week-5