Running TCP/IP Stack in Linux Print


With uClinux running on the LPC4357, you get the full Linux TCP/IP stack (kernel version 2.6.33). Userspace POSIX APIs are provided by the uClibc library. Key user-space networking tools and utilities are available from the multi-call busybox utility. Additional tools and packages, such as for instance the SSH dropbear server, can be built specifically for uClinux. All in all, you have the powerful Linux TCP/IP stack at your disposal.

There is a full-functioning Ethernet device driver available in the kernel tree for the LPC4357. The device driver is linux/drivers/net/arm/stm32_eth.c configured in the kernel using the CONFIG_STM32_ETHER build time option in Device Drivers -> Network device support -> Ethernet (10 or 100Mbit):

Once you have enabled CONFIG_STM32_ETHER, go to System Type -> LPC18XX I/O interfaces and enable LPC18XX Ethernet port (CONFIG_LPC187XX_MAC). This will register a platform device for the LPC4357 Ethernet controller with the Ethernet driver:

Emcraft provides a sample Linux project called networking that demonstrates TCP/IP over Ethernet on the LPC4357. In the Emcraft Linux distribution, the project can be found at projects/networking. Here is how you run that project on the LPC4357.

The bootable Linux image ready to be installed to the LPC4357 (networking.uImage) is about 1.7 MBytes in size. Refer to Installing Linux images to Flash for information on how to install the image to Flash.

Here is a snapshot of the serial console for the networking bootstrap sequence:

Starting kernel ...

Linux version 2.6.33-arm1 (vlad@ocean.emcraft.com)(gcc version 4.4.1 (Sourcery G++ Lite 2010q1-189) ) #264 Thu May 14 14:02:21 +0400 2015
CPU: ARMv7-M Processor [410fc241] revision 1 (ARMv7M)
CPU: NO data cache, NO instruction cache
Machine: NXP LPC18xx
...
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 1024 (order: 1, 8192 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
TCP reno registered
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
...
blackfin-eth: found MAC at 0x40010000, irq 5
blackfin_mii_bus: probed
found PHY id 0x7c0f1 addr 1
eth0: using MII interface
eth0: attached PHY driver [Generic PHY] (mii_bus:phy_addr=00:01, irq=-1)
TCP cubic registered
NET: Registered protocol family 17
ARMv7-M VFP Extension supported
IP-Config: Guessing netmask 255.255.0.0
IP-Config: Complete:
device=eth0, addr=172.17.6.136, mask=255.255.0.0, gw=255.255.255.255,
host=ea-lpc4357, domain=, nis-domain=(none),
bootserver=172.17.0.1, rootserver=172.17.0.1, rootpath=
PHY: 00:01 - Link is Up - 100/Full
Freeing init memory: 944K
init started: BusyBox v1.17.0 (2015-04-23 14:45:46 +0400)
~ #

Let's test the TCP/IP stack on the LPC4357.

From a development host validate that the LPC4357 is visible using ping:

-bash-4.2$ ping 172.17.6.136
PING 172.17.6.136 (172.17.6.136) 56(84) bytes of data.
64 bytes from 172.17.6.136: icmp_seq=1 ttl=64 time=4.28 ms
64 bytes from 172.17.6.136: icmp_seq=2 ttl=64 time=0.473 ms
64 bytes from 172.17.6.136: icmp_seq=3 ttl=64 time=0.474 ms
^C
--- 172.17.6.136 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2714ms
rtt min/avg/max/mdev = 0.473/1.743/4.284/1.796 ms
-bash-4.2$

Ping the development host from the LPC4357:

~ # ping 172.17.0.1
PING 172.17.0.1 (172.17.0.1): 56 data bytes
64 bytes from 172.17.0.1: seq=0 ttl=64 time=1.388 ms
64 bytes from 172.17.0.1: seq=1 ttl=64 time=1.097 ms
64 bytes from 172.17.0.1: seq=2 ttl=64 time=1.098 ms
64 bytes from 172.17.0.1: seq=3 ttl=64 time=1.097 ms
^C
--- 172.17.0.1 ping statistics --
- 4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 1.097/1.170/1.388 ms
~ #

On the target, start the telnetd daemon to allow connections to the LPC4357:

~ # telnetd
~ # ps
PID USER VSZ STAT COMMAND
1   root 352 S init
2   root 0   SW [kthreadd]
3   root 0   SW [ksoftirqd/0]
4   root 0   SW [events/0]
5   root 0   SW [khelper]
6   root 0   SW [async/mgr]
7   root 0   SW [sync_supers]
8   root 0   SW [bdi-default]
9   root 0   SW [kblockd/0]
10  root 0   SW [khubd]
11  root 0   SW [rpciod/0]
12  root 0   SW [kswapd0]
13  root 0   SW [nfsiod]
14  root 0   SW [mtdblockd]
20  root 367 S /bin/hush -i
23  root 332 S telnetd
24  root 348 R ps
~ #

Connect to the target from the development host using telnet. The target is configured to accept an empty password for root so just hit Enter when asked for password:

-bash-4.2$ telnet 172.17.6.136
Trying 172.17.6.136...
Connected to 172.17.6.136.
Escape character is '^]'.

ea-lpc4357 login: root
Password:
~ # ls
bin dev etc httpd init mnt proc root sys usr var
~ # exit
Connection closed by foreign host.
-bash-4.2$

Start the dropbear SSH daemon to allow secure connections to the target:

~ # dropbear
~ # ps
PID USER VSZ STAT COMMAND
1  root 352 S init
2  root 0   SW [kthreadd]
3  root 0   SW [ksoftirqd/0]
4  root 0   SW [events/0]
5  root 0   SW [khelper]
6  root 0   SW [async/mgr]
7  root 0   SW [sync_supers]
8  root 0   SW [bdi-default]
9  root 0   SW [kblockd/0]
10 root 0   SW [khubd]
11 root 0   SW [rpciod/0]
12 root 0   SW [kswapd0]
13 root 0   SW [nfsiod]
14 root 0   SW [mtdblockd]
20 root 367 S /bin/hush -i
23 root 340 S telnetd
28 root 292 S dropbear
29 root 348 R ps
~ #

Connect to the target from the development host using ssh. The first connection takes several seconds to establish as the LPC4357 runs computation-extensive key calculations. Again, hit Enter on the password prompt:

-bash-4.2$ ssh root@172.17.6.136
root@172.17.6.136's password:
~ # ls
bin dev etc httpd init mnt proc root sys usr var
~ # exit
Connection to 172.17.6.136 closed.
-bash-4.2$

On the target, configure a default gateway and a name resolver. Note how the sample configuration below makes use of the public name server provided by Google. Note also use of vi to edit target files on the target:

~ # route add default gw 172.17.0.1
~ # vi /etc/resolv.conf

nameserver 8.8.8.8
~

Use ntpd to synchronize the time on the target with the time provided by a public server:

~ # date
Thu Jan 1 00:07:44 UTC 1970
~ # ntpd -p 0.fedora.pool.ntp.org
~ # sleep 5
~ # date
Thu May 14 11:44:45 UTC 2015
~ #

Use wget to download a file from a remote server:

~ # wget ftp://ftp.gnu.org/README
Connecting to ftp.gnu.org (208.118.235.20:21)
README 100% |*******************************| 1962 --:--:-- ETA
~ # cat README
This is ftp.gnu.org, the FTP server of the the GNU project.
...

Mount a directory exported by a development host over NFS:

~ # mount -o nolock,rsize=1024 172.17.0.1:/home/vlad /mnt
~ # ls /mnt
...
dot.forward update1.0.0.sh
~ #

Start the HTTP daemon:

~ # httpd -h /httpd/html/
~ #

From a local host, open a Web browser to the LPC4357 and watch the demo web page provided by the target. The LPC4357 shows the current time and date as well as the list of the currently running processes: