Moxa Technologies W311, W321, W341 User Manual

ThinkCore W311/321/341 Linux User’s Manual
Second Edition, March 2007
www.moxa.com/product
MOXA Systems Co., Ltd.
Tel: +886-2-2910-1230 Fax: +886-2-2910-1231
www.moxa.com
MOXA Technical Support
Worldwide:
support@moxa.com
ThinkCore W311/321/341 Linux User’s Manual
The software described in this manual is furnished under a license agreement and may be used only in
accordance with the terms of that agreement.
Copyright Notice
Copyright © 2007 Moxa Systems Co., Ltd.
All rights reserved.
Reproduction without permi ssi on is pr ohibited.
Trademarks
MOXA is a registered trademark of The Moxa Group.
All other trademarks or registered marks in this manual belong to their respective manufacturers.
Disclaimer
Information in this document is subject to change without notice and does not represent a commitment on the part of MOXA.
MOXA provides this document “as is,” without warranty of any kind, either expressed or implied, including, but not limited to, its particular purpose. MOXA reserves the right to make improvements and/or changes to this manual, or to the products and/or the programs described in this manual, at any time.
Information provided in this manual is intended to be accurate and reliable. However, MOXA assumes no responsibility for its use, or for any infringements on the rights of third parties that may result from its use.
This product might include unintentional technical or typographical errors. Changes are periodically made to the information herein to correct such errors, and these changes are incorporated into new editions of the publication.
Table of Contents
Chapter 1 Introduction..................................................................................................1-1
Overview.................................................................................................................................. 1-2
Software Architecture..............................................................................................................1-2
Journaling Flash File System (JFFS2)........................................................................ 1-3
Software Package....................................................................................................... 1-4
Chapter 2 Getting Started.............................................................................................2-1
Powering on the W311/321/341............................................................................................... 2-2
Connecting the W311/321/341 to a PC.................................................................................... 2-2
Serial Console ............................................................................................................ 2-2
Telnet Console............................................................................................................ 2-3
SSH Console .............................................................................................................. 2-4
Configuring the Ethernet Interface .......................................................................................... 2-5
Modifying Network Settings with the Serial Console................................................ 2-5
Modifying Network Settings over the Network ......................................................... 2-6
Configuring the WLAN...........................................................................................................2-6
IEEE802.11a/b/g ........................................................................................................ 2-6
Using WPA_SUPPLICANT to Support WPA and WPA2.......................................................2-11
SD Slot and USB for Storage Expansion................................................................................2-11
Test Program—Developing Hello.c....................................................................................... 2-13
Installing the Tool Chain (Linux)............................................................................. 2-13
Checking the Flash Memory Space.......................................................................... 2-13
Compiling Hello.c.................................................................................................... 2-14
Uploading and Running the “Hello” Program.......................................................... 2-15
Developing Your First Application........................................................................................2-15
Testing Environment ................................................................................................ 2-16
Compiling tcps2.c..................................................................................................... 2-17
Uploading and Running the “tcps2-release” Program.............................................. 2-18
Testing Procedure Summary....................................................................................2-20
Chapter 3 Managing Embedded Linux ........................................................................3-1
System Version Information..................................................................................................... 3-2
System Image Backup.............................................................................................................. 3-2
Upgrading the Firmware.............................................................................................3-2
Loading Factory Defaults........................................................................................... 3-5
Backing Up the User Directory.................................................................................. 3-5
Deploying the User Directory to Additional W311/321/341 Units ............................ 3-6
Enabling and Disabling Daemons............................................................................................ 3-6
Setting the Run-Level.............................................................................................................. 3-8
Adjusting the System T ime...................................................................................................... 3-9
Setting the Time Manually ......................................................................................... 3-9
NTP Client................................................................................................................ 3-10
Updating the Time Automatically............................................................................. 3-10
Cron—Daemon to Execute Scheduled Commands................................................................3-11
Chapter 4 Managing Communications........................................................................4-1
Telnet / FTP ............................................................................................................................. 4-2
DNS ......................................................................................................................................... 4-2
Web Service—Apache............................................................................................................. 4-2
Installing PHP for Apache Web Server ....................................................................................4-4
IPTABLES............................................................................................................................... 4-7
NAT.........................................................................................................................................4-11
NAT Example........................................................................................................... 4-11
Enabling NAT at Bootup.......................................................................................... 4-12
Dial-up Service—PPP............................................................................................................ 4-12
PPPoE....................................................................................................................................4-15
NFS (Network File System)................................................................................................... 4-17
Setting up the W311/321/341 as an NFS Client.......................................................4-18
Mail........................................................................................................................................ 4-18
SNMP .................................................................................................................................... 4-18
OpenVPN............................................................................................................................... 4-27
Chapter 5 Tool Chains for Application Development.................................................5-1
Linux T ool Chain..................................................................................................................... 5-2
Steps for Installing the Linux Tool Chain................................................................... 5-2
Compilation for Applications..................................................................................... 5-2
On-Line Debugging with GDB..................................................................................5-3
Windows Tool Chain................................................................................................................ 5-4
System Requirements for Windows T ool Chain......................................................... 5-4
Steps for Installing Windows Tool Chain................................................................... 5-4
Using the BASH Shell................................................................................................ 5-9
Compilation for Applications................................................................................... 5-10
On-Line Debugging with Insight.............................................................................. 5-12
Chapter 6 Programmer’s Guide....................................................................................6-1
Flash Memory Map.................................................................................................................. 6-2
Device API............................................................................................................................... 6-2
RTC (Real Time Clock)........................................................................................................... 6-2
Buzzer...................................................................................................................................... 6-3
WDT (Watch Dog Timer) ........................................................................................................ 6-3
UART.......................................................................................................................................6-7
DO ........................................................................................................................................... 6-8
Chapter 7 Software Lock...............................................................................................7-1
Chapter 8 UC Finder......................................................................................................8-1
Windows UC Finder................................................................................................................ 8-2
Installing the Software................................................................................................ 8-2
Broadcast Search........................................................................................................ 8-3
Linux ucfinder.......................................................................................................................... 8-4
Appendix A System Commands.....................................................................................A-1
busybox (V0.60.4): Linux normal command utility collection............................................... A-1
File manager.............................................................................................................. A-1
Editor......................................................................................................................... A-1
Network..................................................................................................................... A-1
Process....................................................................................................................... A-2
Other.......................................................................................................................... A-2
MOXA special utilities.............................................................................................. A-2
Appendix B Service Information.....................................................................................B-1
MOXA Internet Services..........................................................................................................B-2
Problem Report Form ..............................................................................................................B-3
Product Return Procedure........................................................................................................B-4
1
1

Chapter 1 Introduction

The MOXA ThinkCore W311/321/341 are RISC-based ready-to-run wireless embedded computers with 802.11a/b/g WLAN, one 10/100 Mbps Ethernet port, an internal SD socket, 1/2/4 RS-232/422/485 serial ports, two USB 2.0 hosts, one relay output channel, and pre-installed Linux operating system. The W311/321/341 offer high performance communication and unlimited storage in a super compact, palm-size ARM9 box. The ThinkCore W300 Series is the right solution for embedded applications that are used in hard-to-wire environments and that require a large amount of memory, but that must be housed in a small space without sacrificing performance.
The following topics are covered in this chapter:
Overview Software Architectur e
¾ Journaling Flash File System (JFFS2) ¾ Software Package
ThinkCore W311/321/341 Linux User’s Manual Introduction

Overview

The ThinkCore W311/321/341 wireless embedded computers support 802.11a/b/g wireless LANs with data encryption functions, including the common WEP and powerful WPA and WPA2, to establish a secure transmission tunnel over a WLAN.
ThinkCore W300 Series Embedded Computers use a MOXA ART 192 Mhz RISC CPU. Unlike the X86 CPU, which uses a CISC design, the RISC architecture and modern semiconductor technology provide these embedded computers with a powerful computing engine and communication functions, but without generating a lot of heat. A 16 MB NOR Flash ROM and on-board SDRAM (64 MB for W341 and 32 MB for W311/321) give you enough memory to install your application software directly on the embedded computer. In addition, dual LAN ports are built right into the RISC CPU. This network capability, in combination with the ability to control serial devices, makes the ThinkCore W300 Series ideal as communication platforms for data acquisition and industrial control applications.
The pre-installed Linux operating system (OS) pr o vi des an open software operating system for your software program development. Software written for desktop PCs can be easily ported to the computer with a GNU cross compiler, without needing to modify the source code. The OS, device drivers (e.g., serial and buzzer control), and your own applications, can all be stored in the NOR Flash memory.

Software Architecture

The Linux operating system that is pre-installed in the W311/321/341 follows the standard Linux architecture, making it easy to accept programs that follow the POSIX standard. Program porting is done with the GNU Tool Chain provided by MOXA. In addition to Standard POSIX APIs, device drivers for the USB storage, buzzer and Network controls, and UART are also included in the Linux OS.
AP
API
Protocol Stack
Device Driver
Microkernel
OS Kernel
Hardware
The W311/321/341’s built-in Flash ROM is partitioned into Boot Loader, Linux Kernel, Root File System, and User directory partitions.
In order to prevent user applications from crashing the Root File System, the W311/321/341 use a specially designed Root File System with Protected Configuration for emergency use. This Root File System comes with serial and Ethernet communication capability for users to load the
User Application
Application Interface (POSIX, Socket, Secure Socket)
TCP, IP, UDP, CMP, ARP, HTTP, SNMP, SMTP
PCMCIA, CF, WLAN, USB, UART, RTC, LCM, Keypad
Memory control, Schedule, Process
RS-232/422/485, Ethernet, PCMCIA, CompactFlash, USB
Daemon (Apache, Telnet, FTPD, SNMP)
File
System
1-2
ThinkCore W311/321/341 Linux User’s Manual Introduction
Factory Default Image file. The user directory saves the user’s settings and application. To improve system reliability, the W311/321/341 have a built-in mechanism that prevents the
system from crashing. When the Linux kernel boots up, the kernel will mount the root file system for read only, and then enable services and daemons. At the same time, the kernel will start searching for system configuration parameters via rc or inittab.
Normally, the kernel uses the Root File System to boot up the system. The Root File System is protected, and cannot be changed by the user. This type of setup creates a “safe” zone.
For more information about the memory map and programming, refer to Chapter 6, Programmer’s Guide.

Journaling Flash File System (JFFS2)

The Root File System and User directory in the flash memory is formatted with the Journaling Flash File System (JFFS2). The formatting process places a compressed file system in the flash
memory. This operation is transparent to the user. The Journaling Flash File System (JFFS2), which was developed by Axis Communications in
Sweden, puts a file system directly on the flash, instead of emulating a block device. It is designed for use on flash-ROM chips and recognizes the special write requirements of a flash-ROM chip. JFFS2 implements wear-leveling to extend the life of the flash disk, and stores the flash directory structure in the RAM. A log-structured file system is maintained at all times. The system is always consistent, even if it encounters crashes or improper power-downs, and does not require fsck (file system check) on boot-up.
JFFS2 is the newest version of JFFS. It provides improved wear-leveling and garbage-collection performance, improved RAM footprint and response to system-memory pressure, improved concurrency and support for suspending flash erases, marking of bad sectors with continued use of the remaining good sectors (enhancing the write-life of the devices), native data compression inside the file system design, and support for hard links.
The key features of JFFS2 are:
y Targets the Flash ROM Directly y Robustness y Consistency across power failures y No integrity scan (fsck) is required at boot time after normal or abnormal shutdown y Explicit wear leveling y Transparent compression
Although JFFS2 is a journaling file system, this does not preclude the loss of data. The file system will remain in a consistent state across power failures and will always be mountable. However, if the board is powered down during a write then the incomplete write will be rolled back on the next boot, but writes that have already been completed will not be affected.
Additional information about JFFS2 is available at:
http://sources.redhat.com/jffs2/jffs2.pdf http://developer.axis.com/software/jffs/ http://www.linux-mtd.infradead.org/
1-3
ThinkCore W311/321/341 Linux User’s Manual Introduction

Software Package

Boot Loader Kernel Protocol Stack
File System OS shell command Busybox Linux normal command utility collection Utilities
tinylogin login and user manager utility telnet telnet client program ftp FTP client program smtpclient email utility scp Secure file transfer Client Program
Daemons
pppd dial in/out over serial port daemon snmpd snmpd agent daemon telnetd telnet server daemon inetd TCP server manager program ftpd ftp server daemon apache web server daemon sshd secure shell server openvpn virtual private network openssl open SSL Linux Tool Chain Gcc (V3.3.2) C/C++ PC Cross Compiler GDB (V5.3) Source Level Debug Server Glibc (V2.2.5) POSIX standard C library Windows Tool Chain Gcc (V3.3.2) C/C++ PC Cross Compiler Glibc(V2.2.5) POSIX standard C library Insight (V6.1) Windows environment source level debug utility
Moxa Boot Loader (v1.2) Linux 2.6.9 ARP, PPP, CHAP, PAP, IPv4, ICMP, TCP, UDP, DHCP, FTP, SNMP V1/V3, HTTP, NTP, NFS, SMTP, SSH 1.0/2.0, SSL, Telnet, PPPoE, OpenVPN JFFS2, NFS, Ext2, Ext3, VFAT/FAT Bash
1-4
2
2

Chapter 2 Getting Started

In this chapter, we explain how to connect the W311/321/341, how to turn on the power, how to get started programming, and how to use the W311/321/341’s other functions.
The following topics are covered in this chapter:
Powering on the W311/321/341 Connecting the W311/321/341 to a PC
¾ Serial Console ¾ Telnet Console ¾ SSH Console
Configuring the Ethernet Interface
¾ Modifying Network Settings with the Serial Console ¾ Modifying Network Settings over the Network
Configuring the WLAN
¾ IEEE802.11a/b/g
Using WPA_SUPPLICANT to Support WPA and WPA2 SD Socket and USB for Storage Expansion Test Progra mDeveloping Hello.c
¾ Installing the Tool Chain (Linux) ¾ Checking the Flash Memory Space ¾ Compiling Hello.c ¾ Uploading and Running the “Hello” Program
Developing Your First Application
¾ Testing Environment ¾ Compiling tcps2.c ¾ Uploading and Running the “tcps2-release” Program ¾ Testing Procedure Summary
ThinkCore W311/321/341 Linux User’s Manual Getting Started

Powering on the W311/321/341

Connect the SG wire to the shielded contact located in the upper lef t corner of the W311/321/341, and then power on the computer by connecting it to the power adaptor. It takes about 30 to 60 seconds for the system to boot up. Once the system is ready, the Ready LED will light up.
NOTE After connecting the W311/321/341 to the power supply, it will take about 30 to 60 seconds for
the operating system to boot up. The green Ready LED will not turn on until the operating system is ready.
ATTENTION
This product is intended to be supplied by a Listed Power Unit with output marked “LPS” and rated for 12-48 VDC, 600 mA (minimum requirements).

Connecting the W311/321/341 to a PC

There are two ways to connect the W311/321/341 to a PC: through the serial console and by Telnet over the network.

Serial Console

The serial console gives users a convenient way of connecting to the W311/321/341. This method is particularly useful when using the computer for the first time. The serial console is useful for connecting the W311/321/341 when you do not know either of the two IP addresses.
Use the serial console port settings shown below.
Baudrate Parity Data bits Stop bits: Flow Control Terminal
115200 bps None 8 1 None VT100
2-2
ThinkCore W311/321/341 Linux User’s Manual Getting Started
The following window will open when a connection has been established.
To log in, type the Login name and password as requested. The default values are both root:
Login: root Password: root

Telnet Console

If you know at least one of the two IP addresses and netmasks, then you can use Telnet to connect to the W311/321/341’s console utility. The default IP address and Netmask for each of the two ports are given below:
LAN 1 WIRLESS LAN
Use a cross-over Ethernet cable to connect directly from your PC to the W311/321/341. You should first modify your PC’s IP address and netmask so that your PC is on the same subnet as one of W311/321/341’s two LAN ports. For example, if you connect to LAN 1, you can set your PC’s IP address to 192.168.3.126 and netmask to 255.255.255.0. If you connect to the WIRLESS LAN, you can set your PC’s IP address to 192.168.4.126 and netmask to 255.255.2 55.0 using a wirless AP router.
Use a straight-through Ethernet cable to connect to a hub or switch that is connected to your local LAN. The default IP addresses and netmasks are shown above. To log in, type the Login name and password as requested. The default values are both root:
Login: root Password: root
Default IP Address Netmask
192.168.3.127 255.255.255.0
192.168.4.127 255.255.255.0
2-3
ThinkCore W311/321/341 Linux User’s Manual Getting Started
You can proceed with configuring the network settings of the target computer when yo u reach the bash command shell. Configuration instructions are given in the next section.
ATTENTION
Serial Console Reminder
Remember to choose VT100 as the terminal type. Use the cable CBL-4PINDB9F-100, which comes with the W311/321/341, to connect to the serial console port.
Telnet Reminder When connecting to the W311/321/341 over a LAN, you must configure your PC’s Ethernet IP
address to be on the same subnet as the W341 that you wish to contact. If you do not get connected on the first try, re-check the serial and IP settings, and then unplug and re-plug the power cord.

SSH Console

The W311/321/341 support an SSH Console to provide users with be tter security options.
Windows Users
Click on the link http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html to download PuTTY (free software) to set up an SSH console for the W311/321/341 in a Windows environment. The following figure shows a simple example of the configuration that is required.
2-4
ThinkCore W311/321/341 Linux User’s Manual Getting Started
Linux Users
From a Linux machine, use the “ssh” command to access the W311/321/341’s console utility via SSH.
#ssh 192.168.3.127
Select yes to complete the connection.
[root@bee_notebook root]# ssh 192.168.3.127 The authenticity of host ‘192.168.3.127 (192.168.3.127)’ can’t be established. RSA key fingerprint is 8b:ee:ff:84:41:25:fc:cd:2a:f2:92:8f:cb:1f:6b:2f. Are you sure you want to continue connection (yes/no)? yes_
NOTE SSH provides better security compared to Telnet for accessing the W311/321/341’s console
utility over the network.

Configuring the Ethernet Interface

The network settings of the W311/321/ 34 1 can be modi fied with the serial console port, or online over the network.

Modifying Network Settings with the Serial Console

In this section, we use the serial console to configure the network settings of the target computer.
1. Follow the instructions given in a previous section to access the Console Utility of the target computer via the serial console port, and then type
#cd /etc/network
to change directories.
2-5
ThinkCore W311/321/341 Linux User’s Manual Getting Started
2. Type
3. After the boot settings of the LAN interface have been modified, issue the following
#vi interfaces
configure the Ethernet ports of the W341 for static or dynamic (DHCP) IP addresses. Static IP addresses As shown in the table below, 4 network addresses must be modified: address, network,
netmask, and broadcast. The default IP address for LAN1 is 192.168.3.127, with default
netmask of 255.255.255.0.
Dynamic IP addresses
By default, the W311/321/341 are configured for “static” IP addresses. To configure one or both LAN ports to request an IP address dynamically, replace static with dhcp and then delete the address, network, netmask, and broadcast lines.
Default Setting for LAN1 Dynamic Setting using DHCP iface eth0 inet static
address 192.168.3.127 network: 192.168.3.0 netmask 255.255.255.0 broadcast 192.168.3.255
command to activate the LAN settings immediately:
#/etc/init.d/networking restart
to edit the network configuration file with vi editor. You can
iface eth0 inet dhcp
NOTE After changing the IP settings, use the networking restart command to activate the new IP
address.

Modifying Network Settings over the Network

IP settings can be activated over the network, but the new settings will not be saved to the flash ROM without modifying the file
For example, type the command LAN1 to 192.168.1.1.
/etc/network/interfaces
#ifconfig eth0 192.168.1.1
.
to change the IP address of

Configuring the WLAN

IEEE802.11a/b/g

Use one of the following options to configure the WLAN for IEEE802.11a/b/g:
1. Using the config file to set up your wireless system The config file is /etc/wireless.conf. The config file is read by the OS when the
W311/321/341 unit boots up. You may also use the load_wlan command to force your wireless to run the config file and set up your wireless LAN card after the W311/321/341 unit is already up and running. The /etc/wireless.conf file format is shown below:
2-6
ThinkCore W311/321/341 Linux User’s Manual Getting Started
/etc/wireless.conf Format: DEVICE=eth1
MODE=managed ESSID=any KEY=any
/etc/wireless.conf Item list: DEVICE Æ indicates your wireless interface
MODE Æ indicates your wireless mode, such as ad-hoc, managed, master ESSID Æ indicates your wireless ESSID NAME KEY Æ indicates your wireless WEP key CHANNEL Æ indicates your wireless channel setting MACMODE Æ indicates your wireless macmode setting, such as 1 (mixed mode), 2 (pure_g_mode), 3 (pure_b_m ode), 4 (pure_a_mode) REGION Æ indicates your wireless country region setting WIRELESS_SUPPLICANT Æ If set to Y, load_wlan will call /etc/init.d/wpa.sh and open wireless WPA and WPA2 MOXA_REPEAT Æ If set to Y, load_wlan will call ipriv eth1 set_moxa_repeat to establish ad-hoc mode using repeat function
If you want to use WPA and WPA2, please refer to the subsection “Using WPA_SUPPLICANT to Support WPA and WPA2” on page 2-11.
2. Use the command
file with vi editor, and then edit the 802.11g network settings Static IP addresses As shown in the table below, 4 network addresses need to be modified: address, network,
netmask, and broadcast. The default WIRLESS LAN IP address is 192.168. 4. 127 . Dynamic IP addresses
By default, the W311/321/341 are configured for “static” IP addresses. To configure one or both LAN ports to request an IP address dynamically, replace static with dhcp and then delete the address, network, netmask, and broadcast lines.
#vi /etc/networking/interfaces
:
:
to open the “interfaces”configuration
2-7
ThinkCore W311/321/341 Linux User’s Manual Getting Started
Default Setting for WIRLESS LAN Dynamic Setting using DHCP iface eth1 inet static
address 192.168.4.127 network: 192.168.4.0 netmask 255.255.255.0 broadcast 192.168.4.255
After the boot settings of the LAN interface have been modified, issue the following command to activate the LAN settings immediately:
#/etc/init.d/networking restart
3. Using iwconfig / iwpriv Utility to set up the wireless configuration Using iwpriv eth1 essid ESSIDNAME iwconfig eth1 essid ESSIDNAME Æ set up wireless essid
iwconfig eth1 key KEYVALUE open Æ set up wireless wep key iwconfig eth1 mode infra Æ set up wireless mode
CountryRegion—Sets the channels for your particular country / region Using iwpriv eth1 set_Region REGION
REGION Explanation
1 (USA) (default) Use 802.11g channels 1 to 11 2 (Taiwan/Europe) Use 802.11g channels 1 to 13 3 (France) Use 802.11g channels 10 to 13 4 (Japan) Use 802.11g channels 1 to 14 5 (Israel) Use 802.11g channels 3 to 9 6 (Mexico) Use 802.11g channels 10 , 11
WirelessMode—Sets the wireless mode Using iwpriv eth1 set_mac_mode Setting
Note: infrastruct just support mixed/a mode; Ad-hoc support b/g/a mode
Setting Explanation
1 (default) 11a/mixed(b. g) 2 11g only 3 11b only 4 11a only
SSID—Sets the softAP SSID Using iwconfig eth1 essid Setting
iface eth1 inet dhcp
Setting
Any 32-byte string
NetworkType—Sets the wireless operation mode Using iwconfig eth1 mode Setting
Setting Explanation
managed Infrastructure mode (uses access points to transmit data) ad-hoc Adhoc mode (transmits data from host to host)
2-8
ThinkCore W311/321/341 Linux User’s Manual Getting Started
Channel—Sets the channel Using iwconfig eth1 channel Setting
Note: Infrastruct couldn’t set channel
Freq—Sets the channel frequence Using iwconfig eth1 freq Setting(G,M,K)
Note: Infrastruct couldn’t set freq
802.11b,g Channel and Frequency Table
Channel Freqence
1 2 3 4 5 6 7 8 9 10 11 12 13 14
802.11a Channel and Frequency Table
Channel Freqence
36 40 44 5220 (K) 48 5240 (K) 52 5260 (K) 56 5280 (K) 60 5300 (K) 64 5320 (K) 100 5500 (K) 104 5520 (K) 108 5540 (K) 112 5560 (K) 116 5580 (K) 120 5600 (K) 124 5620(K) 128 5640 (K) 132 5660 (K) 136 5680 (K)
2412(K) 2417(K) 2422(K) 2427(K) 2432(K) 2437(K) 2442(K) 2447(K) 2452(K) 2457(K) 2462(K) 2467(K) 2472(K) 2484(K)
5180 (K) 5200 (K)
2-9
ThinkCore W311/321/341 Linux User’s Manual Getting Started
140 5700 (K) 184 4920 (K) 188 4940 (K) 192 4960(K) 196 4980 (K) 8 5040 (K) 12 5060 (K) 16 5080 (K) 34 5170 (K) 38 5190 (K) 42 5210 (K) 46 5230 (K) 149 5745 (K) 153 5765 (K) 157 5785 (K) 161 5805 (K) 165 5825 (K)
AuthMode—Sets the authentication mode Using iwpriv eth1 set_auth Setting
Setting Explanation
0 OPEN 1 SHARED 2 AUTO(default)
KeyStr—Sets Key Support string key and hex key EncrypType—Just Support NONE , WEP64 and WEP128 depend on your key length Using iwpriv eth1 key s:KEYVALUE (open) Î support string key Using iwpriv eth1 key KEYVALUE (open) Î support hex key
RTSThreshold—Sets the RTS threshold Using iwpriv eth1 rts Setting
Setting
1 to 2347
FragThreshold—Sets the fragment threshold Using iwpriv eth1 frag Setting
Setting
256 to 2346
Moxa Repeat—Sets the Repeat function through adhoc method Using iwpriv eth1 set_moxa_repeat
2-10
ThinkCore W311/321/341 Linux User’s Manual Getting Started

Using WPA_SUPPLICANT to Support WPA and WPA2

This embedded computer supports the WPA and WPA2 functions using the /bin/wpa_supplicant program. We wrote a shell script to help you use this function:
Step 1:
Edit the
network={ ssid=”12345678901” key_mgmt=WPA-PSK proto=WPA RSN pairwise=TKIP CCMP group=TKIP CCMP psk=”0987654321234”
}
ssid and psk variables in the file etc/wpa_supplicant.conf.
Step 2:
/etc/init.d/wpa.sh eth1 start to enable this function. To stop the function, type
Type
/etc/init.d/wpa.sh eth1 stop

SD Slot and USB for Storage Expansion

The W341 and W321 provide an SD slot for storage expa nsion. MOXA provides an SD flash disk for plug & play expansion that allows users to plug in a Secure Digital (SD) memory card compliant with the SD standard V1.0 for up to 1 GB of additional memory space. The following steps show you how to install SD card into the W341 and W321.
W321
The SD slot is located on the right side of the W321 enclosure. To install an SD card, you must first remove the SD slot’s protective cover to access the slot, and then plug the SD card directly into the slot.
The SD card will be mounted at /mnt/sd. Detailed installation instructions are shown below:
Step 1: Use a screwdriver to remove the screws holding the SD slot’s outer cover.
Step 2: After removing the cover, insert the SD memory card as shown.
2-11
ThinkCore W311/321/341 Linux User’s Manual Getting Started
W341
The SD slot is located on the front panel of the W341. To install an SD card, you must first re
move the SD slot’s protective cover to access the slot, and then plug the SD card directly into the
slot.
The
SD card will be mounted at
p 1: Use a screwdriver to remove the screws holding the SD slot’s outer cover, and then
Ste
re
move the cover.
/mnt/sd. Detailed installation instructions are shown below:
Step 2: Insert the SD memory card as shown.
NOTE: To remove the SD card from the slot, press the SD card in slightly with your finger, and
then
remove your finger to cause the card to spring out partially. You may now grasp the top of the with two fingers and pull it out.
card
ore removing the SD card, remember to type
Bef
/sync to ensure that your data has been written.
In addition to the SD socket, two USB 2.0 ports are located on the W341’s upper panel. The USB host is also designed for storage expansion. To use a USB flash disk to expand the storage space, plug the USB flash disk into the USB port. The flash disk will be detected automatically, and its file
partition will be mounted into the OS. The USB storage will be mounted in one of four
directories: /mnt/usbstorage1, /mnt/usbstorage2, /mnt/usbstorage3, or /mnt/usbstorage4.
2-12
ThinkCore W311/321/341 Linux User’s Manual Getting Started

Test ProgramDeveloping Hello.c

In this section, we use the standard “Hello” programming example to illustrate how to develop a program for the W311/321/341. In general, program development involves the following seven steps.
Step 1:
Connect the W311/321/341 to a Linux PC.
Step 2:
Install Tool Chain (GNU Cross Compiler & glibc).
Step 3:
Set the cross compiler and glibc environment variables.
Step 4:
Code and compile the program.
Step 5:
Download the program to the W311/321/341 using FTP or NFS.
Step 6:
Debug the program
Æ If bugs are found, return to Step 4. Æ If no bugs are found, continue with Step 7.
Step 7:
Back up the user directory (distribute the program to additional W311/321/341 units if needed).
x86
Cross
Compiler

Installing the Tool Chain (Linux)

The Linux Operating System must be pre-installed in the PC before installing the W311/321/341 GNU Tool Chain. Fedora core or compatible versions are recommended. The Tool Chain requires approximately 100 MB of hard disk space on your PC. The W311/321/341 Tool Chain software is located on the W311/321/341 CD. To install the Tool Chain, insert the CD into your PC and then issue the following commands:
#mount /dev/cdrom /mnt/cdrom #sh /mnt/cdrom/tool-chain/linux/install.sh
The Tool Chain will be installed automatically on your Linux PC within a few minutes. Before compiling the program, be sure to set the following path first, since the Tool Chain files, including the compiler, link, library, and include files are located in this directory.
PATH=/usr/local/arm-linux/bin:$PATH
Setting the path allows you to run the compiler from any directory.
NOTE Refer to Appendix B for an introduction to the Windows Tool Chain. In this chapter, we use the
Linux tool chain to illustrate the cross compiling process.

Checking the Flash Memory Space

If the flash memory is full, you will not be able to save data to the Flash ROM. Use the following command to calculate the amount of “Available” flash memory:
/>df –h
2-13
ThinkCore W311/321/341 Linux User’s Manual Getting Started
If there isn’t enough “Available” space for your application, you will need to delete some existing files. To do this, connect your PC to the W311/321/341 with the console cable, and then use the console utility to delete the files from the W311/321/341’s flash memory. To check the amount of free space available, look at the directories in the read/write directory /dev/mtdblock3. Note that the directories /home and /etc are both mounted on the directory /dev/mtdblock3.
NOTE If the flash memory is full, you will need to free up some memory space before saving files to
the Flash ROM.

Compiling Hello.c

The package CD contains several example programs. Here we use Hello.c as an example to show you how to compile and run your applications. Type the following commands from your PC to copy the files used for this example from the CD to your computer’s hard drive:
# cd /tmp/ # mkdir example # cp –r /mnt/cdrom/example/* /tmp/example
To compile the program, go to the Hello subdirectory and issue the following commands:
#cd example/hello #make
You should receive the following response:
[root@localhost hello]# make /usr/local/arm-linux/bin/arm-linux-gcc –o hello-release hello.c /usr/local/arm-linux/bin/arm-linux-strip –s hello-release /usr/local/arm-linux/bin/arm-linux-gcc –ggdb -o hello-debug hello.c [root@localhost hello]# _
Next, execute make to generate hello-release and hello-debug, which are described below: hello-release—an ARM platform execution file (created specifically to run on the W311/321/341) hello-debug—an ARM platform GDB debug server execution file (see Chapter 5 for details about
the GDB debug tool).
2-14
NOTE Since Moxa’s tool chain places a specially designed Makefile in the directory
/tmp/example/hello, be sure to type the #make command from within that directory. This
special Makefile uses the mxscale-gcc compiler to compile the hello.c source code for the Xscale environment. If you type the #make command from within any other directory, Linux will use the x86 compiler (for example, cc or gcc).
Refer to Chapter 5 to see a Makefile example.

Uploading and Running the “Hello” Program

Use the following commands to upload hello-release to the W311/321/341 by FTP.
1. From the PC, type:
#ftp 192.168.3.127
2. Use the bin command to set the transfer mode to Binary mode, and then use the put command to initiate the file transfer:
ftp> bin ftp> cd /home ftp> put hello-release
3. From the W311/321/341, type:
detratS gnitteG launaM s’resU xuniL 143/123/113W eroCknihT
# chmod +x hello-release # ./hello-release
The word Hello will be printed on the screen.
root@Moxa:~# ./hello-release Hello

Developing Your First Application

We use the tcps2 example to illustrate how to build an application. The procedure outlined in the following subsections will show you how to build a TCP server program plus serial port communication that runs on the W311/321/341.
2-15
ThinkCore W311/321/341 Linux User’s Manual Getting Started

Testing Environment

The tcps2 example demonstrates a simple application program that delivers transparent, bi-directional data transmission between the W311/321/341’s serial and Ethernet ports. As illustrated in the following figure, the purpose of this application is to transfer data between PC 1 and the W311/321/341 through an RS-232 connection. At the remote site, data can b e transferred between the W311/321/341’s Ethernet port and PC 2 over an Ethernet connection.
PC 2PC 1
RS-232 LAN
tcps2.c
Read serial data
Write data to PC1
Serial Rx
Buffer
LAN Rx
Buffer
Send data to PC2
Receive LAN data
2-16
ThinkCore W311/321/341 Linux User’s Manual Getting Started

Compiling tcps2.c

The source code for the tcps2 example is located on the CD-ROM at CD-ROM://example/TCPServer2/tcps2.c. Use the following commands to copy the file to a specific directory on your PC. We use the direrctory /home/w341/1st_application/. Note that you need to copy 3 filesMakefile, tcps2.c, tcpsp.cfrom the CD-ROM to the target directory.
#mount –t iso9660 /dev/cdrom /mnt/cdrom #cp /mnt/cdrom/example/TCPServer2/tcps2.c/home/w341/1st_application/tcps2.c #cp /mnt/cdrom/example/TCPServer2/tcpsp.c/home/w341/1st_application/tcpsp.c #cp /mnt/cdrom/example/TCPServer2/Makefile.c/home/w341/1st_application/Makefile
Type #make to compile the example code: You will get the following response, indicating that the example program was compiled
successfully.
root@server11:/home/w341/1st_application [root@server11 1st_application]# pwd
/home/w341/1st_application [root@server11 1st_application]# 11 total 20
-rw-r—r-- 1 root root 514 Nov 27 11:52 Makefile
-rw-r—r-- 1 root root 4554 Nov 27 11:52 tcps2.c
-rw-r—r-- 1 root root 6164 Nov 27 11:55 tcps2.c [root@server11 1st_application]# make_ /usr/local/arm-linux/bin/arm-linux-gcc -o tcps2-release tcps2.c /usr/local/arm-linux/bin/arm-linux-strip –s tcps2-release /usr/local/arm-linux/bin/arm-linux-gcc -o tcpsp-release tcpsp.c /usr/local/arm-linux/bin/arm-linux-strip –s tcpsp-release /usr/local/arm-linux/bin/arm-linux-gcc –ggdb -o tcps2-debug tcps2.c /usr/local/arm-linux/bin/arm-linux-gcc –ggdb -o tcpsp-debug tcpsp.c [root@server11 1st_application]# 11 total 92
-rw-r—-r-- 1 root root 514 Nov 27 11:52 Makefile
-rwxr-xr—x 1 root root 25843 Nov 27 12:03 tcps2-debug
-rwxr—xr-x 1 root root 4996 Nov 27 12:03 tcps2-release
-rw-r—-r-- 1 root root 4554 Nov 27 11:52 tcps2.c
-rwxr—xr-x 1 root root 26823 Nov 27 12:03 tcpsp-debug
-rwxr—xr-x 1 root root 5396 Nov 27 12:03 tcpsp-release
-rw-r—-r-- 1 root root 6164 Nov 27 11:55 tcpsp.c [root@server11 1st_application]#
Two executable files, tcps2-release and tcps2-debug, are created. tcps2-release—an ARM platform execution file (created specifically to run on the
W311/321/341). tcps2-debug—an ARM platform GDB debug server execution file (see Chapter 5 for details about
the GDB debug tool).
NOTE If you get an error message at this point, it could be because you neglected to put tcps2.c and
tcpsp.c in the same directory. The example Makefile we provide is set up to compile both tcps2 and tcpsp into the same project Makefile. Alternatively, you could modify the Makefile to suit your particular requirements.
2-17

Uploading and Running the “tcps2-release” Program

Use the following commands to upload tcps2-release to the W311/321/341 through an FTP connection.
1. From the PC, type:
#ftp 192.168.3.127
2. Next, use the bin command to set the transfer mode to Binary, and the put command to initiate the file transfer:
ftp> bin ftp> cd /home
ftp> put tcps2-release
root@server11:/home/w341/1st_application
[root@server11 1st_application]# ftp 192.168.3.127 Connected to 192.168.3.127 220 Moxa FTP server (Version wu-2.6.1(2) Mon Nov 24 12:17:04 CST 2003) ready. 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (192.168.3.127:root): root 331 Password required for root. Password: 230 User root logged in. Remote system type is UNIX. Using binary mode to transfer files. ftp> bin 200 Type set to I. ftp> put tcps2-release local: tcps2-release remote: tcps2-release 277 Entering Passive Mode (192.168.3.127.82.253) 150 Opening BINARY mode data connection for tcps2-release. 226 Transfer complete 4996 bytes sent in 0.00013 seconds (3.9e+04 Kbytes/s) ftp> ls 227 Entering Passive Mode (192.168.3.127.106.196) 150 Opening ASCII mode data connection for /bin/ls.
-rw------- 1 root root 899 Jun 10 08:11 bash_history
-rw-r--r-- 1 root root 4996 Jun 12 02:15 tcps2-release 226 Transfer complete ftp>
detratS gnitteG launaM s’resU xuniL 143/123/113W eroCknihT
3. From the W311/321/341, type:
# chmod +x tcps2-release # ./tcps2-release &
192.168.3.127 – PuTTY
root@Moxa:~# ls –al drwxr—xr-x 2 root root 0 Jun 12 02:14 drwxr—xr-x 15 root root 0 Jan 1 1970
-rw------- 1 root root 899 Jun 10 08:11 .bash_history
-rw-r--r-- 1 root root 4996 Jun 12 02:15 tcps2-release root@Moxa:~# chmod +x tcps2-release root@Moxa:~# ls -al drwxr—xr-x 2 root root 0 Jun 12 02:14 drwxr—xr-x 15 root root 0 Jan 1 1970
-rw------- 1 root root 899 Jun 10 08:11 .bash_history
-rwxr-xr-x 1 root root 4996 Jun 12 02:15 tcps2-release root@Moxa:~#
2-18
ThinkCore W311/321/341 Linux User’s Manual Getting Started
4. The program should start running in the background. Use the the tcps2 program is actually running in the background.
#ps // use this command to check if the program is running
192.168.3.127 – PuTTY root@Moxa:~# ls –al
drwxr—xr-x 2 root root 0 Jun 12 02:14 drwxr—xr-x 15 root root 0 Jan 1 1970
-rw------- 1 root root 899 Jun 10 08:11 .bash_history
-rw-r--r-- 1 root root 4996 Jun 12 02:15 tcps2-release root@Moxa:~# chmod +x tcps2-release root@Moxa:~# ls -al drwxr—xr-x 2 root root 0 Jun 12 02:14 drwxr—xr-x 15 root root 0 Jan 1 1970
-rw------- 1 root root 899 Jun 10 08:11 .bash_history
-rwxr-xr-x 1 root root 4996 Jun 12 02:15 tcps2-release root@Moxa:~# ./tcps2-release & [1] 187 start root@Moxa:~# ps [1]+ Running ./tcps2-release & root@Moxa:~#
NOTE Use the
#ps -ef // use this command to check if the program is running
192.168.3.127 – PuTTY [1]+ Running ./tcps2-release &
root@Moxa:~# ps -ef
728 root 1264 S ./tcps2-release 729 root 1592 S ps -ef root@Moxa:~#
#ps –ef
kill
command for job number 1 to terminate this program:
PID Uid VmSize Stat Command
1 root 532 S init [3] 2 root SWN [ksoftirqd/0] 3 root SW< [events/0]
4 root SW< [khelper] 13 root SW< [kblockd/0] 14 root SW [khubd] 24 root SW [pdflush] 25 root SW [pdflush] 27 root SW< [aio/0] 26 root SW [kswapd0]
604 root SW [mtdblockd] 609 root SW [pccardd] 611 root SW [pccardd] 625 root SWN [jffs2_gcd_mtd3] 673 root 500 S /bin/inetd 679 root 3004 S /usr/bin/httpd -k start -d /etc/apache 682 bin 380 S /bin/portmap 685 root 1176 S /bin/sh --login 690 root 464 S /bin/snmpd 694 nobody 3012 S /usr/bin/httpd -k start -d /etc/apache 695 nobody 3012 S /usr/bin/httpd -k start -d /etc/apache 696 nobody 3012 S /usr/bin/httpd -k start -d /etc/apache 697 nobody 3012 S /usr/bin/httpd -k start -d /etc/apache 698 nobody 3012 S /usr/bin/httpd -k start -d /etc/apache 701 root 352 S /bin/reportip 714 root 1176 S -bash 726 root 436 S /bin/telnetd 727 root 1164 S -bash
#kill %1
command to check if
2-19
ThinkCore W311/321/341 Linux User’s Manual Getting Started
NOTE Use the
kill -9
command for PID 728 to terminate this program:

Testing Procedure Summary

1. Compile tcps2.c
2. Upload and run tcps2-release in the background
3. Check that the process is running
4. Use a serial cable to connect PC1 to the W311/321/341’s serial port 1.
5. Use an Ethernet cable to connect PC2 to the W311/321/341.
6. On PC1: If running Windows, use HyperTerminal (38400, n, 8, 1) to open COMn.
7. On PC2: Type
8. On PC1: Type some text on the keyboard and then press Enter.
9. On PC2: The text you typed on PC1 will appear on PC2’s screen. The testing environment is illustrated in the following figure. However, note that there are
limitations to the example program tcps2.c.
(#make
).
#telnet 192.168.3.127 4001
RS-232 LAN
(#./tcps2-release &)
(#jobs or #ps -ef)
.
#kill -9 %728
.
.
PC 2PC 1
tcps2.c
Read serial data
Serial Rx
Send data to PC2
Buffer
LAN Rx
Write data to PC1
NOTE The tcps2.c application is a simple example designed to give users a basic understanding of the
concepts involved in combining Ethernet communication and serial port communication. However, the example program has some limitations that make it unsuitable for real-life applications.
1. The serial port is in canonical mode and block mode, making it impossible to send data from
the Ethernet side to the serial side (i.e., from PC 2 to PC 1 in the above example).
2. The Ethernet side will not accept multiple connections.
Buffer
Receive LAN data
2-20
3

Chapter 3 Managing Embedded Linux

This chapter includes information about version control, deployment, updates, and peripherals. The information in this chapter will be particularly useful when you need to run the same application on several W311/321/341 units.
The following topics are covered in this chapter:
System Version Information System Image Backup
¾ Upgrading the Firmware ¾ Loading Factory Defaults ¾ Backing Up the User Directory
¾ Deploying the User Directory to Additional W311/321/341 Units Enabling and Disabling Daemons Setting the Run-Level Adjusting the System Time
¾ Setting the Time Manually
¾ NTP Client
¾ Updating the Time Automatically Crondaemon to Execute Scheduled Commands
3
Loading...
+ 74 hidden pages