in Embedded, Linux

Embedded Linux S3C2440 Networking

Summary

Embedded S3C2440 Mini2440 system has limited amount of storage available on the board for the application code. We can use the network interface to provide and expansion to the file system by mounting a network file system to the board. And we con use telnet network interface to login into embedded S3C2440 Mini2440 board.

Configuration and build Busybox to support Networking

Busybox can be compiled and linked against to static libraries, but new applications will not be able to use the standard functions like printf() without loading in the shared dynamic libraries, and if loaded the additional library code, the Busybox binary is bigger.

We can compile Busybox to make use of shared dynamic libraries. And we can include the networking utilities like telnetd, tftp, nfs in the Busybox.

[root@localhost ~]# cd /home/iot/mini2440/busybox-1.19.4/
[root@localhost busybox-1.19.4]# pwd
/home/iot/mini2440/busybox-1.19.4
[root@localhost busybox-1.19.4]#
[root@localhost busybox-1.19.4]# make menuconfig

In “Busybox Configuration” –>”Busybox Settings” –> “Build options”
Press space to remove the asterisk before “Build BusyBox as a static binary (no shared libs)” as below shows,

 [ ] Build BusyBox as a static binary (no shared libs)

Exit to the main menu “Busybox Configuration”, then enter into “Networking Utilities” menu,

[*] telnetd
[*]   Support standalone telnetd (not inetd only)
[*] tftp

Exit to the main menu “Busybox Configuration”, enter “Miscellaneous Utilities”, select “mountpoint” as below,

[*] mountpoint

Exit to the main menu “Busybox Configuration”, enter “Linux System Utilities”, select “Support mounting NFS file systems” as below,

[*]   Support mounting NFS file systems

Exit to the main menu “Busybox Configuration”, enter “Login/Password Management Utilities”, select below items,

 [*] login
 [*] su
 [*]   Enable su to write to syslog (NEW)
 [*] sulogin

Select “Yes” when asking “Do you wish to save your new configuration?”.

Make and Make install

[root@localhost busybox-1.19.4]# make
[root@localhost busybox-1.19.4]# make install

You can find telnetd installed installed in directory usr/sbin,

[root@localhost sbin]# ls
popmaildir  sendmail  telnetd
[root@localhost sbin]# pwd
/home/iot/mini2440/busybox-1.19.4/_install/usr/sbin
[root@localhost sbin]#

Configure Password file, RCS and Inittab file

Change the Linux configuration files to setup the networking on the S3C2440 Mini2440 target board.

[root@localhost ~]# cd /home/iot/mini2440/rootfilesystem/rootfs-base/etc/
[root@localhost etc]# pwd
/home/iot/mini2440/rootfilesystem/rootfs-base/etc
[root@localhost etc]#
[root@localhost etc]# vim passwd

Change to below,

root::0:0:root:/root:/bin/sh

Above has no content between the first colon and the second colon, so no password required to login the S3C2440 Mini2440 target board.

[root@localhost etc]# ls
group  hosts  init.d  inittab  mdev.conf  passwd  profile
[root@localhost etc]# pwd
/home/iot/mini2440/rootfilesystem/rootfs-base/etc
[root@localhost etc]# vim inittab

The inittab shall be as below,

::sysinit:/etc/init.d/rcS
::respawn:-/bin/login
::restart:/sbin/init

::once:/usr/sbin/telnetd -l /bin/login

Edit the Busybox start up script rcS,

[root@localhost etc]# cd init.d/
[root@localhost init.d]# pwd
/home/iot/mini2440/rootfilesystem/rootfs-base/etc/init.d
[root@localhost init.d]# vim rcS

Add below line at the end to startup the Ethernet interface eth0,

echo "eth0 up"
ifconfig eth0 192.168.0.11 netmask 255.255.255.0 broadcast 192.168.0.255 up

Create new initramfs.cpio by running create_rootfs_bash.sh.

[root@localhost init.d]# cd /home/iot/mini2440/rootfilesystem/
[root@localhost rootfilesystem]# ls
create_rootfs_bash.sh  initramfs.cpio  mkyaffs2image-128M  rootfs  rootfs-base  rootfs.img  yaffs2-4e188b0  yaffs2-4e188b0.tar.gz
[root@localhost rootfilesystem]# ./create_rootfs_bash.sh
------Create rootfs --------
/home/iot/mini2440/rootfilesystem/rootfs /home/iot/mini2440/rootfilesystem
--------Create root,dev....----------
---------Copy from busybox, rootfs-base, libs -----------
---------make node dev/console dev/null-----------------
mknod: ‘/dev/ptmx’: File exists
13994 blocks
/home/iot/mini2440/rootfilesystem
[root@localhost rootfilesystem]#

Refer to Embedded Linux S3C2440 Application Development and Debugging for detail on the script “create_rootfs_bash.sh.”.

Configure and build kernel image

Now compile the new initramfs.cpio into the kernel, and generate a new zImage.

Change to Linux kernel source directory and start the Linux configuration editor,

[root@localhost rootfilesystem]# cd /home/iot/mini2440/linux-3.8.7/
[root@localhost linux-3.8.7]# pwd
/home/iot/mini2440/linux-3.8.7
[root@localhost linux-3.8.7]#
[root@localhost linux-3.8.7]# make menuconfig

In “Linux/arm 3.8.7 Kernel Configuration”, enter “File systems”, select below options,

--- Network File Systems
< *>   NFS client support
< *>     NFS client support for NFS version 2
< *>     NFS client support for NFS version 3
[*]       NFS client support for the NFSv3 ACL protocol extension
< *>     NFS client support for NFS version 4
[ ]     Provide swap over NFS support
(kernel.org) NFSv4.1 Implementation ID Domain (NEW)
[ ]   Use the legacy NFS DNS resolver (NEW)
<>   NFS server support
[*]   RPC: Enable dprintk debugging
<>   Ceph distributed file system (EXPERIMENTAL)
...

Build the kernel and download the new zImage into the Linux S3C2440 mini2440 board,

[root@localhost linux-3.8.7]# make clean
[root@localhost linux-3.8.7]# make

The new zImage will be built under folder: “/home/iot/mini2440/linux-3.8.7/arch/arm/boot/zImage”

Refer to Embedded Linux S3C2440 Application Development and Debugging , power on the mini2440 board, key in “k” in the Bootlaoder command and downlaod the new zImage through the USB cable,

[root@localhost linux-3.8.7]# cd /home/iot/mini2440/
[root@localhost mini2440]# ls
buildroot-2013.02  busybox-1.19.4  config-files  download_image.sh  initramfs.cpio  linux-3.8.7  myapp  rootfilesystem  rootfs  s3c2410_boot_usb
[root@localhost mini2440]# ./download_image.sh
csum = 0xbd20
send_file: addr = 0x33f80000, len = 0x00537360

At the mini2440 board, it displays as below,

##### FriendlyARM BIOS 2.0 for 2440 #####
[x] format NAND FLASH for Linux
[v] Download vivi 
[k] Download linux kernel 
[y] Download root_yaffs image 
[a] Absolute User Application
[n] Download Nboot for WinCE 
[l] Download WinCE boot-logo
[w] Download WinCE NK.bin 
[d] Download & Run 
[z] Download zImage into RAM 
[g] Boot linux from RAM 
[f] Format the nand flash 
[b] Boot the system 
[s] Set the boot parameters 
[u] Backup NAND Flash to HOST through USB(upload) 
[r] Restore NAND Flash from HOST through USB 
[q] Goto shell of vivi 
[i] Version: 1026-2K
Enter your selection: k
USB host is connected. Waiting a download.

Now, Downloading [ADDRESS:30000000h,TOTAL:5469034]
RECEIVED FILE SIZE: 5469034 (27KB/S, 196S)
Downloaded file at 0x30000000, size = 5469024 bytes
Found block size = 0x00540000
Erasing...    ... done
Writing...    ... done
Written 5469024 bytes

Start up the mini2440 board, at the login prompt, key in “root”, no password is required.

mini2440 login: root
-sh: can't access tty; job control turned off
[root@mini2440 /root]# 
[root@mini2440 /root]# 
[root@mini2440 /root]# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:90:90:90:90:90  
          inet addr:192.168.0.11  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:51 Base address:0xc300 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

[root@mini2440 /root]# 

From above ifconfig command, we can see eth0 192.168.0.11 is up.

Telnet

As the network has been setup, we can use telnet on the host to login the mini2440 board,

[root@localhost ~]# telnet 192.168.0.11
Trying 192.168.0.11...
Connected to 192.168.0.11.
Escape character is '^]'.

mini2440 login: root
[root@mini2440 /root]#

Login as root, and without using password.

Check the applications generated during the compiling kernel,

[root@mini2440 bin]# ./greeting
The string is hello there
The sring printed backward is ereht olleh
[root@mini2440 bin]#

To disconnect from telnet terminal, type “Ctrl+]”, then key in “q” to quit,

[root@mini2440 bin]#
telnet> q
Connection closed.
[root@localhost ~]#

NFS mount on S3C2440 Mini2440 board

Now mount the NFS onto S3C2440 Mini2440 board, the host was configured as a NFS server and allows 192.168.0.* to access the /home directory.

[root@mini2440 /root]# mount
rootfs on / type rootfs (rw)
/proc on /proc type proc (rw,relatime)
mdev on /dev type tmpfs (rw,relatime)
none on /sys type sysfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
none on /dev/shm type tmpfs (rw,relatime)
[root@mini2440 /root]#

After the mounting, check the status again,

[root@mini2440 /root]# mount -t nfs 192.168.0.1:/home /mnt -otcp, -o nolock
[root@mini2440 /root]# mount
rootfs on / type rootfs (rw)
/proc on /proc type proc (rw,relatime)
mdev on /dev type tmpfs (rw,relatime)
none on /sys type sysfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
none on /dev/shm type tmpfs (rw,relatime)
192.168.0.1:/home on /mnt type nfs (rw,relatime,vers=3,rsize=131072,wsize=131072,namlen=255,hard,nolock,proto=tcp,port=2049,timeo=70,retrans=3,sec=sys,local_lock=all,addr=192.168.0.1)
[root@mini2440 /root]#

The host (192.168.0.1) directory /home has been mounted onto the S3C2440 Mini2440 board directory /mnt. Now check the directory /mnt,

[root@mini2440 /root]# cd /mnt/iot/mini2440/myapp/
[root@mini2440 myapp]# pwd
/mnt/iot/mini2440/myapp
[root@mini2440 myapp]# ./greeting
The string is hello there
The sring printed backward is ereht olleh
[root@mini2440 myapp]#

Now there is no need to download the applications from host to S3C2440 Mini2440 board, you can compile on the host and execute on the Mini2440 board through the mounted NFS file system.

Transfer files with TFTP

The host has been configured as TFTP server, check the status of the TFTP server,

[root@localhost ~]# systemctl status tftp.service
tftp.service - Tftp Server
      Loaded: loaded (/usr/lib/systemd/system/tftp.service; static)
      Active: inactive (dead)
      CGroup: name=systemd:/system/tftp.service

Start the TFTP service,

[root@localhost ~]# systemctl start tftp.socket
[root@localhost ~]# systemctl start tftp.service
[root@localhost ~]# systemctl status tftp.service
tftp.service - Tftp Server
      Loaded: loaded (/usr/lib/systemd/system/tftp.service; static)
      Active: active (running) since Fri, 2019-05-03 16:05:00 SGT; 19s ago
    Main PID: 20389 (in.tftpd)
      CGroup: name=systemd:/system/tftp.service
          └ 20389 /usr/sbin/in.tftpd -s /var/lib/tftpboot

May 03 16:05:00 localhost.localdomain systemd[1]: Starting Tftp Server...
May 03 16:05:00 localhost.localdomain systemd[1]: Started Tftp Server.
[root@localhost ~]#

[root@localhost ~]# vim /etc/xinetd.d/tftp

The configuration is as below, so the host directory is “/var/lib/tftpboot”.

# default: off
# description: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operating systems.
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

The greeting2 is already put into this directory,

[root@localhost ~]# ls /var/lib/tftpboot/
greeting  greeting2  
[root@localhost ~]#

Transfer the file from host to Mini2440 board,

[root@mini2440 /root]# tftp -g -r greeting2 192.168.0.1
greeting2            100% |********************************************************************************************************************************************|  7718   0:00:00 ETA
[root@mini2440 /root]# ls
greeting2
[root@mini2440 /root]# ./greeting2
-sh: ./greeting2: Permission denied
[root@mini2440 /root]# ls -l
-rw-r--r--    1 root     root          7718 Jan  1 00:46 greeting2
[root@mini2440 /root]# chmod 777 greeting2
[root@mini2440 /root]# ls -l
-rwxrwxrwx    1 root     root          7718 Jan  1 00:46 greeting2
[root@mini2440 /root]# ./greeting2
The string is hello there
The string printed backward is ereht olleh
[root@mini2440 /root]#

After transfer the file onto Mini2440 board, greeting2 cannot be executed, because there is no permission to execute, we need to change the file permission by use command “chmod 777 greeting2”.

Reference

Embedded Linux S3C2440 environment setup
Embedded Linux S3C2440 Application Development and Debugging

Write a Comment

Comment