With uClinux running on the Kinetis, 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 Kinetis. The device driver is linux/drivers/net/fec.c configured in the kernel using the CONFIG_FEC build time option in Device Drivers -> Network device support -> Ethernet (10 or 100Mbit):
Once you have enabled CONFIG_FEC, go to System Type -> Freescale Kinetis I/O interfaces and enable Freescale Kinetis Ethernet port (CONFIG_KINETIS_MAC). This will register a platform device for the Kinetis Ethernet controller with the Ethernet driver:
Emcraft provides a sample Linux project called networking that demonstrates TCP/IP over Ethernet on the Kinetis SOM. In the Emcraft Linux distribution, the project can be found at projects/networking. Here is how you run that project on the Kinetis SOM.
The bootable Linux image ready to be installed to the Kinetis SOM (networking.uImage) is about 2.3 MBytes in size. It easily fits into the on-module Flash of the Kinetis SOM with plenty of room for custom enhancements. Refer to Installing Linux Images to Flash for information on how to install the image to the Kinetis SOM.
When booted to the Kinetis target, kernel performance is fast (140 BogoMIPS) and boot time to the shell is about 2 seconds from power-on / reset. In other words, in 2 seconds from power-on you have your unit running shell with the TCP/IP stack and Ethernet interface fully configured and connected to the network:
U-Boot 2010.03-linux-cortexm-1.11.0 (Jul 08 2013 - 15:11:51)
CPU : Freescale Kinetis series (Cortex-M4)
Freqs: SYSTICK=150MHz,CCLK=150MHz,PCLK=75MHz,MACCLK=50MHz
Board: K70-SOM Rev 1.A, www.emcraft.com
DRAM: 64 MB
NAND: 128 MiB
...
Linux version 2.6.33-arm1 (vlad@ ocean.emcraft.com) (gcc version 4.4.1 (Sourcery G++ Lite 2010q1-189) ) #2 Mon Apr 21 11:58:10 +0400 2014
CPU: ARMv7-M Processor [410fc241] revision 1 (ARMv7M)
CPU: WRITE-BACK data cache, WRITE-THROUGH instruction cache
Machine: Freescale Kinetis
...
Calibrating delay loop... 140.49 BogoMIPS (lpj=702464)
...
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
...
fec: PHY @ 0x0, ID 0x00221556 -- KSZ8081RNL
...
eth0: config: auto-negotiation on, 100FDX, 100HDX, 10FDX, 10HDX.
IP-Config: Guessing netmask 255.255.0.0
IP-Config: Complete:
device=eth0, addr=172.17.6.46, mask=255.255.0.0, gw=255.255.255.255,
host=k70-som, domain=, nis-domain=(none),
bootserver=172.17.0.1, rootserver=172.17.0.1, rootpath=
Freeing init memory: 952K
init started: BusyBox v1.17.0 (2014-04-18 13:39:00 +0400)
~ #
Let's test the TCP/IP stack on the Kinetis.
From a development host validate that the Kinetis is visible using ping:
-bash-3.2$ ping 172.17.6.46
PING 172.17.6.46 (172.17.6.46) 56(84) bytes of data.
64 bytes from 172.17.6.46: icmp_seq=1 ttl=64 time=1.04 ms
64 bytes from 172.17.6.46: icmp_seq=2 ttl=64 time=0.262 ms
64 bytes from 172.17.6.46: icmp_seq=3 ttl=64 time=0.270 ms
64 bytes from 172.17.6.46: icmp_seq=4 ttl=64 time=0.257 ms
^C
--- 172.17.6.46 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3388ms
rtt min/avg/max/mdev = 0.257/0.458/1.046/0.340 ms
-bash-3.2$
Ping the development host from the Kinetis:
~ # 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=0.745 ms
64 bytes from 172.17.0.1: seq=1 ttl=64 time=0.384 ms
64 bytes from 172.17.0.1: seq=2 ttl=64 time=0.360 ms
64 bytes from 172.17.0.1: seq=3 ttl=64 time=0.357 ms
64 bytes from 172.17.0.1: seq=4 ttl=64 time=0.361 ms
^C
--- 172.17.0.1 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 0.357/0.441/0.745 ms
~ #
On the target, start the telnetd daemon to allow connections to the Kinetis:
~ # 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-3.2$ telnet 172.17.6.46
Trying 172.17.6.46...
Connected to 172.17.6.46.
Escape character is '^]'.
k70-som login: root
Password:
~ # ls
bin dev etc httpd init mnt proc root sys usr var
~ # exit
Connection closed by foreign host.
-bash-3.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 a couple of seconds to establish as the Kinetis runs computation-extensive key calculations. Again, hit Enter on the password prompt:
-bash-3.2$ ssh
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
's password:
~ # ls
bin dev etc httpd init mnt proc root sys usr var
~ # exit
Connection to 172.17.6.46 closed.
-bash-3.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
Mon Apr 21 08:09:22 UTC 2014
~ #
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 Kinetis and watch the demo web page provided by the target. The Kinetis shows the current time and date as well as the list of the currently running processes: