Week-4 @RTEMS-GSoC-2025
Published on 20 Jun 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
-
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()
ingreth_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 andgreth_hw_set_addr()
for setting GRETH MAC Address, all ingreh_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()
ingreth_emac.h
for setting GRETH MAC Address. - Added
leon3.json
file which will help building RTEMS lwIP Package for sparc/leon3 BSP.
- 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
andnum_rx_bd
in structgreth_netif_struct
for setting the number of transmit and receive buffer descriptors separately. - Set size of
buffptr
field inemac_bd
to 32 bits. - Moved struct
phy_dev_info
and GRETH MII Register Macros fromgreth.h
togreth_phy.h
- Added few related filds like PHY address, PHY status and PHY control variables to struct
phy_dev_info
.
- Used same struct
- 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 interfacetap0
which connects tolxcbr0
. To complete the network, I created a virtual ethernet cable having 2 ends (virtual network interfaces) :veth-lxc
connected tolxcbr0
andveth-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) - For investigating why the trap occured, I checked using
>>> sparc-rtems7-objdump -d telnetd01.exe | grep 40017694
(because at that time Program Counter was at0x40017694
) 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
contained0x400d800e
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 (inwscript
file for RTEMS repository) for resolvng the memory alignment issues and rebuiltsparc/leon3
BSP, but the error persisted. - Next I used
addr2line
as
>>> addr2line -e telnetd01.exe 0x40017694
which translates program address0x40017694
in the executabletelnetd01.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 usingRTEMS_POSIX_API = True
option inconfig.ini
in RTEMS repository and rebuildingsparc/leon3
BSP
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 aprintf("legacy stack initialization successful\n");
statement for verifying if legacy networking stack was initialized correctly in correspondingnet_start()
function atrtems-net-services/net/legacy/net_adapter.c
, and it was initialized correctly.
- I had a virtual bridge (network switch)
Plans for next week
- Debug Telnet Server-Client connection issue for GRETH Legacy Driver
- Continue on GRETH lwIP Code
- Create blogs till Week-5