Saturday, March 10, 2012

More on multiple ethernet ports

Here is a blog post just detailing David's explanation and perhaps going a little bit more in depth in the steps we took to get where we were at.

The first thing we tried to do was make sure we had our Verilog and sopc files correct. In SOPC, a new TSE_MAC device was added along with two SGDMAs for receiving and transferring. In Verilog, we just made sure both of our ethernet devices were being defined correctly with "arrays".

Next, we started with the Simple Socket Server template given to us from Eclipse. The first problem we encountered was that from just the template, a MAC address was not being assigned. Instead, it would ask for a serial number and when anything was typed in, it would just assign the MAC address to FF:FF:FF:FF:FF:FF. Because of this, we looked into exactly where the ethernet device was initialized at first. We traced it down to the bsp/alt_sys_init.c file and saw that the TSE_MAC device was initialized in the function alt_sys_init(). This wasn't much help at first so we backtracked a bit to look at the all the functions which actually modified the MAC address. We found these in sss/network_utilities.c. The first thing we modified here was to get rid of any calls to a serial number but this didn't really solve anything. The MAC address would still be the same. We didn't want to define the MAC address exactly because we knew that there was at least one MAC address in flash. We spent a while trying to open in flash and ended up giving up for a while on that and instead just assigned a random MAC address to our ethernet port. This meant we just modified one of the function calls inside sss/network_utilities.c such that a random serial number would be generated and a random MAC address would be assigned based off of this random serial number. Once we got this MAC address up, the SSS was working exactly how we wanted it to.

We moved on to starting to work on getting two ethernet devices up. We had already enabled it all in our Verilog code and SOPC builder so we focused on looking through where in our program we should initialize the devices. We studied through where any device was called and ended up at the bsp/alt_sys_init.c file. The way we got here was we traced how alt_inich_init() was called in our main Simple Socket Server task (in sss/iniche_init.c). In the previously mentioned alt_sys_init() function, all the ethernet devices were being initialized. At first, we couldn't exactly figure out why both devices weren't coming up so we looked into how these devices were setup in the iniche drivers. Through Professor Pak Chan's hint, we started using the function alt_tse_system_add_sys(). To use this, we also had to make sure we initiated each device needed to go into the argument fields of this function. This has been previously discussed in depth by David so I will not get into it. At first, we put all of these statements into SSSInitialTask() in the iniche_init.c file because this is where our SSS would start. When we started testing it, we saw your devices would come up, but our DE4 board seemed to no longer function as a DHCP client. With further investigation, we found that our devices were still sending out DHCP discover packets (found through using Wireshark to trace the packets) but would not accept any packets. I have talked about our troubles with this in a previous post so to make a long story short, we figured out we were not accepting packets because we closed the OpenCore Plus IP dialog box when programming. We next just moved the alt_tse_system_add_sys() calls to bsp/alt_sys_init.c, where the rest of the devices were being setup. After a few tests and some fine tuning to the way we acquire a MAC address, we finally got our SSS server with two ethernet ports up.

While it did take us a long time, all our debugging led us to understand more clearly how an ethernet device is setup, how DHCP works in regards to the ethernet device, and how the MAC address is acquired/assigned. Our next task is to investigate into the way MicroCOS looks and interacts with packets. We will be looking at functions that interact with packets, packet headers, and sending. With our two ethernet devices setup, we will be trying to make a simple forwarding router soon. More updates will come as more progress is made.

No comments:

Post a Comment