Archive

Archive for the ‘Embedded’ Category

安装tftp,ftp,samba,nfs

November 24th, 2009 BianJiang No comments

tftp,ftp和nfs是在嵌入式linux开发环境中经常要用到的传输工具,samba则是在linux和windows下的文件传输工具。

一. tftp安装

1.安装

sudo apt-get install tftpd tftp openbsd-inetd

2.建立tftp主目录
其中用户名和组是你平时使用的主要用户,请不要用root用户作为你的主要操作用户,因为那样很容易把系统搞乱。

sudo mkdir /tftpboot
sudo chown -R tan:tan /tftpboot

3.配置
修改文件:/etc/inetd.conf, 确认文件中包含有类似下面这一行内容:

#emacs /etc/inetd.conf
tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot

4.启动tftp
可以重启动电脑,或者执行:

sudo /etc/init.d/openbsd-inetd reload

5.测试
测试从Tftp服务器传入/传出文件:

tftp localhost

二. ftp安装

1.安装

sudo apt-get install vsftpd

2.配置 修改文件“etc/vsftpd.conf”

#不允许匿名登录
anonymous_enable=NO

#本地用户可用
local_enable=YES

#可写
write_enable=YES

#不需要显示某目录下文件信息
#dirmessage_enable=YES

#登录消息
ftpd_banner=Hello~~

#最大连接用户数
max_clients=10

#限制每个IP的进程
max_per_ip=5

#最大传输速率(bit/s)
local_max_rate=256000

#隐藏帐号
hide_ids=YES

3.启动ftp

sudo /etc/init.d/vsftpd restart

4.安装ftp client
系统自带的ftp client中文乱码。

sudo apt-get install filezilla

三. samba安装

1.安装

sudo apt-get install samba smbfs

2.配置
修改文件“/etc/samba/smb.conf”
配置例子(建立一个共享名称为“share”的samba资源):

[share]
comment = linux share
#共享目录
path = /opt
guest ok = yes

#写权限用户名
write list = tan

printable = no
directory mask 0775
create mask 0775
wide links = no

3.写权限用户口令
如果定义了写特权用户,则该用户必须有samba口令,samba口令与系统用户口令是不同的。

smbpasswd -a 用户名

4.启动

sudo /etc/init.d/samba restart

5.在xp上的共享连接问题处理
在XP上连接samba资源时,出现以下提示的处理:

指定的网络文件夹目前是以其它用户名和密码进行映射的。
要用其他用户名和密码进行连接,首先请断开所有现有连接到该网络共享的映射。

处理:

  1. 断开连接
    找到该共享连接名称

    net use

    删除该连接(共享连接名可以是“\\”“开头的全名,也可以是映射的盘符)

    net use /delete <共享连接名>

    然后重新连接即可。

四. NFS

NFS(Network File System, 网络文件系统)可以通过网络将分享不同主机(不同的OS)的目录——可以通过NFS挂载远程主机的目录, 访问该目录就像访问本地目录一样!

一般而言, 使用nfs能够方便地使各unix-like系统之间实现共享. 但如果需要在unix-like和windows系统之间共享, 就得使用samba了!

NFS运行在SUN的RPC(Remote Procedure Call, 远程过程调用)基础上, RPC定义了一种与系统无关的方法来实现进程间通信. 由此, NFS server也可以看作是RPC server.

正因为NFS是一个RPC服务程序, 所以在使用它之前, 先要映射好端口——通过portmap设定. 比如: 某个NFS client发起NFS服务请求时, 它需要先得到一个端口(port). 所以它先通过portmap得到port number. (不仅NFS, 所有的RPC服务程序启动之前, 都需要设定好portmap)

与NFS相关的几个文件, 命令:
1. /etc/exports

对NFS卷的访问是由exports来批准, 它枚举了若干有权访问NFS服务器上文件系统的主机名.

2. /sbin/exportfs

维护NFS的资源共享. 可以通过它重新设定 /etc/exports 的共享目录, 卸载NFS Server共享的目录或者重新共享等.

3. /usr/sbin/showmount

用在 NFS Server 端,而 showmount 则主要用在 Client 端. showmount 可以用來查看 NFS 共享的目录资源.

4. /var/lib/nfs/xtab

NFS的记录文档: 通过它可以查看有哪些Client 连接到NFS主机的记录.

下面这几个并不直接负责NFS, 实际上它们负责所有的RPC
5. /etc/default/portmap

实际上, portmap负责映射所有的RPC服务端口, 它的内容非常非常之简单(后面详述)

6. /etc/hosts.deny

设定拒绝portmap服务的主机

7. /etc/hosts.allow

设定允许portmap服务的主机

安装NFS
Debian/Ubuntu上默认是没有安装NFS服务器的,首先要安装NFS服务程序:

sudo apt-get install nfs-kernel-server

安装nfs-kernel-server时,apt会自动安装nfs-common和portmap,服务端和客户程序都一块安装了。

客户端需要安装客户端程序。如果是Debian/Ubuntu系统,客户端包名称是“nfs-common”:

sudo apt-get install nfs-commmon

nfs-common和nfs-kernel-server都依赖于portmap!

配置NFS
配置portmap

方法1: 编辑/etc/default/portmap, 将 -i 127.0.0.1 去掉.

方法2: 执行

sudo dpkg-reconfigure portmap

对Should portmap be bound to the loopback address? 选N.

配置/etc/hosts.deny
(禁止任何host(主机)能和你的NFS服务器进行NFS连接),加入:

### NFS DAEMONS
portmap:ALL
lockd:ALL
mountd:ALL
rquotad:ALL
statd:ALL

配 置/etc/hosts.allow
允许那些你想要的主机和你的NFS服务器建立连接。下列步骤将允许任何IP地址以192.168.2开头的主机(连 接到NFS服务器上),也可以指定特定的IP地址。参看man页 hosts_access(5), hosts_options(5)。加入:

### NFS DAEMONS
portmap: 192.168.2.
lockd: 192.168.2.
rquotad: 192.168.2.
mountd: 192.168.2.
statd: 192.168.2.

/etc/hosts.deny 和 /etc/hosts.allow 设置对portmap的访问. 采用这两个配置文件有点类似”mask”的意思. 现在/etc/hosts.deny中禁止所有用户对portmap的访问. 再在/etc/hosts.allow 中允许某些用户对portmap的访问. 运行

sudo /etc/init.d/portmap restart

重启portmap daemon.

配置/etc/exports
NFS挂载目录及权限由/etc/exports文件定义

比如我要将将我的home目录中的/home/zp/share目录让192.168.2.*的IP共享, 则在该文件末尾添加下列语句:

/home/zp/share 192.168.2.*(rw,sync,no_root_squash)

或者:

/home/zp/share 192.168.2.0/24(rw,sync,no_root_squash)

192.168.2.* 网段内的NFS客户端能够共享NFS服务器/home/zp/share目录内容.且有读,写权限, 并且该用户进入/home/zp/share目录后的身份为root

最好加上sync, 否则 “sudo exportfs -r” 时会给出警告, sync是NFS的默认选项.

运行

showmount -e

查看NFS server的export list.

若更改了/etc/exports, 运行

sudo exportfs -r

更新

运行

sudo /etc/init.d/nfs-kernel-server restart

重启nfs服务

/etc/exports实际上就是nfs服务器的核心配置文件了.

测试NFS
可以尝试一下挂载本地磁盘(假设NFS服务器IP地址为:192.128.2.1,NFS目录为“/home/zp/share”)

sudo mount 192.168.2.1:/home/zp/share /mnt

运行

df

看看结果.

卸载NFS目录

sudo umount /mnt

注意被拷贝文件的读/写权限!
另外, 可以使用一定的参数:
使用加参数的办法:

mount -o nolock,rsize=1024,wsize=1024,timeo=15 192.168.2.130:/tmp/ /tmp/

--EOF--
Categories: Embedded, Tech.Notes Tags: , , , , ,

在ARM上移植openssl

November 21st, 2008 BianJiang No comments

移植过程如下:

wget http://www.openssl.org/source/openssl-0.9.8h.tar.gz
tar zxvf openssl-0.9.8h.tar.gz
cd openssl-0.9.8h/
./Configure --prefix=/opt/rootfs/arm/openssl/ os/compiler:arm-linux-gcc

修改Makefile:
把: AR=ar $(ARFLAGS) r 改为:
AR=arm-linux-ar $(ARFLAGS) r

make
make install
border@ubuntu:/opt/rootfs/arm/openssl/bin$ file openssl
openssl: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.4.17, dynamically linked (uses shared libs), not stripped

-Bian Jiang

参考:
  1. http://newinfo.sysu.edu.cn/Snowwaft/?p=70

– EOF –

Categories: Embedded Tags: , ,

cross compile net-snmp for mips

November 17th, 2008 BianJiang 1 comment

I’m trying to cross-compile NetSNMP 5.4.2 for running on an embedded system (mips).

由于我使用的CPU是little endian 交叉编译工具是 mipsel-linux

但是如果你用的是Big endian,交叉编译用具就可能是 mips-linux

如果你是ARM平台的话,相应的改为 arm-linux

  1. 设置环境变量:

    TOOLCHAIN=mipsel-linux-
    CC=${TOOLCHAIN}gcc
    CPP=${TOOLCHAIN}cpp
    AR=${TOOLCHAIN}ar
    STRIP=${TOOLCHAIN}strip
    RANLIB=${TOOLCHAIN}ranlib
    LD=${TOOLCHAIN}ld
  2. 编译安装:

    ../net-snmp-5.4.2.1/configure --build=i686-linux --host=mipsel-linux --target=mipsel-linux \
    --with-transports="UDP"  --prefix=/opt/rootfs/snmp --with-endianness=little \
    --with-persistent-directory=/var/net-snmp/ --with-default-snmp-version="2" \
    --enable-mini-agent --without-kmem-usage --disable-debugging --disable-embedded-perl \
    --without-perl-modules
    
    make
    make install
    1. 如果你采用的是 Big endian, –with-endianness=little 应该改为 –with-endianness=big
    1. 如果不想对openssl 的支持,用 –without-openssl
  1. 测试:

    border@ubuntu:/opt/rootfs/snmp/sbin$ pwd
    /opt/rootfs/snmp/sbin
    border@ubuntu:/opt/rootfs/snmp/sbin$ file snmpd
    snmpd: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
    border@ubuntu:/opt/rootfs/snmp/sbin$ file snmptrapd
    snmptrapd: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
参考:
  1. http://fixunix.com/snmp/175765-multiple-warning-cross-compiling-net-snmp-mips-linux.html

–Bian Jiang

–EOF–

Categories: Embedded Tags: , ,

Cross Compile SSH Server Dropbear For ARM

August 15th, 2008 BianJiang No comments

编译环境

  • ubuntu 8.04
  • gcc 4.2.3
  • arm_v5t_le-gcc 3.4.3

编译过程

编译zlib:

wget http://www.zlib.net/zlib-1.2.3.tar.gz
tar zxvf zlib-1.2.3.tar.gz
mkdir zlib
cd zlib-1.2.3/
CC=arm_v5t_le-gcc ./configure --prefix=/home/border/work/SMG/build-tools/zlib
make
make install

编译dropbear:

wget http://matt.ucc.asn.au/dropbear/releases/dropbear-0.51.tar.gz
tar zxvf dropbear-0.51.tar.gz
mkdir dropbear-build
cd dropbear-build/
mkdir build
../dropbear-0.51/configure --prefix=/home/border/work/SMG/build-tools/dropbear-build/build/ \
    --with-zlib=/home/border/work/SMG/build-tools/zlib/ CC=arm_v5t_le-gcc --host=arm
make
make scp
sudo make install
sudo cp scp build/bin/

其中的scp需要单独编译,然后用把编译好的scp复制到build/bin目录下。

在交叉编译好的程序要使用 file 之类的工具检查一下是否为目标机器的程序:

border@b0rder:~/work/SMG/build-tools/dropbear-build$ file scp
scp: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.4.17,
dynamically linked (uses shared libs), not stripped

编译好的文件目录结构为:

border@b0rder:~/work/SMG/build-tools/dropbear-build/build$ tree
.
|-- bin
|   |-- dbclient
|   |-- dropbearconvert
|   |-- dropbearkey
|   `-- scp
`-- sbin
    `-- dropbear

生成server key:

cd /etc
mkdir dropbear
cd dropbear
dropbearkey -t rsa -f dropbear_rsa_host_key
dropbearkey -t dss -f dropbear_dss_host_key

启动脚本

把build目录拷贝到ARM机器上, 在启动脚步/etc/init.d/rcS中增加:

dropbear

– EOF –

Categories: Embedded Tags: , , ,

GNU Configure 中的 build target和host 的区别

August 2nd, 2008 BianJiang No comments

这几天在做交叉编译的时候,对configure的build, target和host 一直搞不明白,搜了些资料记录一下:

一、 http://en.wikipedia.org/wiki/Cross_compile

The GNU autotools packages (i.e. autoconf, automake, and libtool) use the notion of a build platform, a host platform, and a target platform.

The build platform is where the code is actually compiled.

The host platform is where the compiled code will execute.

The target platform usually only applies to compilers. It represents what type of object code the package itself will produce (such as cross-compiling a cross-compiler); otherwise the target platform setting is irrelevant. For example, consider cross-compiling a video game that will run on a Dreamcast. The machine where the game is compiled is the build platform while the Dreamcast is the host platform.

二、 http://www.airs.com/ian/configure/configure_5.html#SEC30

When building cross compilation tools, there are two different systems involved: the system on which the tools will run, and the system for which the tools generate code.

The system on which the tools will run is called the host system.

The system for which the tools generate code is called the target system.

For example, suppose you have a compiler which runs on a GNU/Linux system and generates ELF programs for a MIPS embedded system. In this case the GNU/Linux system is the host, and the MIPS ELF system is the target. Such a compiler could be called a GNU/Linux cross MIPS ELF compiler, or, equivalently, a ‘i386-linux-gnu’ cross ‘mips-elf’ compiler.

简单说明一下:

  1. build 就是你现在使用的机器。
  2. host 就是你编译好的程序能够运行的平台。
  3. target 编译程序能够处理的平台。一般都用在构建编译本身的时候(gcc), 才用target, 也就是说平时我们所说的交叉编译用不到target.

Target usually have a meaning for developemt tool only.

比如: 在386的平台上编译可以运行在arm板的程序 ./configure –build=i386-linux,–host=arm-linux就可以了.

因为一般我们都是编译程序而不是编译工具.

如果我们编译工具,比如gcc,这个target就有用了.如果我们需要在一个我们的机器上为arm开发板编译一个可以处理 mips程序的gcc,那么target就是mips了.

比如:

1. ./configure --build=mipsel-linux --host=mipsel-linux
--target=mipsel-linux' will build native mipsel-linux binutils on
mipsel-linux.

2. ./configure --build=i386-linux --host=mipsel-linux
--target=mipsel-linux' will cross-build native mipsel-linux binutils on
i386-linux.

3. ./configure --build=i386-linux --host=i386-linux
--target=mipsel-linux' will build mipsel-linux cross-binutils on
i386-linux.

4. ./configure --build=mipsel-linux --host=i386-linux
--target=mipsel-linux' will cross-build mipsel-linux cross-binutils for
i386-linux on mipsel-linux.

As you see, only if $build != $host a cross-compilation is performed.
参考:
  1. http://en.wikipedia.org/wiki/Cross_compile
  2. http://www.airs.com/ian/configure/configure_5.html#SEC30
  3. http://oss.lzu.edu.cn/blog/blog.php?/do_showone/tid_116.html

– EOF –

Categories: Embedded Tags: ,

Howto-Cross-Compile-Python2.5.2-For-ARM

August 1st, 2008 BianJiang No comments

Cross Compile Python 2.5.2 For ARM

本文排版有问题可以看排版后的: http://wiki.woodpecker.org.cn/moin/Cross_Compile_Python_2.5.2_For_ARM

编译环境:

ubuntu 8.04, gcc 4.2.3, arm_v5t_le-gcc 3.4.3

  1. 下载Python,http://www.python.org/download/ 下载Python源码,我下载的:

    http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tar.bz2
  2. 解压:

    tar jxvf Python-2.5.2.tar.bz2
    cd Python-2.5.2
  3. 编译pc版本的语法解析器

由于在编译python的时候,需要先编译一个叫pgen的程序出来,用于生成语法解析器,所以我们要先生成一个pc版本的pgen:

border@b0rder:~/tools/Python-2.5.2$ mkdir build.pc
border@b0rder:~/tools/Python-2.5.2$ cd build.pc/
border@b0rder:~/tools/Python-2.5.2/build.pc$ ../configure
border@b0rder:~/tools/Python-2.5.2/build.pc$ make Parser/pgen

然后ls Parser一下,应该就能看到有pgen了。

  1. 修改../configure

configure在检测编译器的printf是否支持%zd的时候,如果发现是在cross compile,就直接不干活了。这还了得?

把这一部分的检测代码去掉。这段代码起始于:

echo "$as_me:$LINENO: checking for %zd printf() format support" >&5
echo $ECHO_N "checking for %zd printf() format support... $ECHO_C" >&6
if test "$cross_compiling" = yes; then

结束于:

cat >>confdefs.h <<\_ACEOF
#define PY_FORMAT_SIZE_T "z"
_ACEOF

else
  echo "$as_me: program exited with status $ac_status" >&5
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

( exit $ac_status )
echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi
rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
fi

把这两段以及中间的内容都删除掉就可以了, 我的是从 22496 - 22583 行,不同的版本可能不一样。

  1. 编译arm版本的python

有了语法解析器,就可以开始编译arm版本的python了:

border@b0rder:~/tools/Python-2.5.2/build.pc$ mkdir ../build.arm
border@b0rder:~/tools/Python-2.5.2/build.pc$ cd ../build.arm/
../configure --prefix=/opt/arm-test/rootfs --disable-ipv6 --host=arm_v5t_le --enable-shared

先创建一个用于编译的目录build.arm,再对python做一些配置,如安装目录,不要ipv6,使用arm-linux的编译器,生成动态链接库。

  1. 修改Makefile
  1. 去掉Debug:

    OPT=                -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes

一行中,去掉-g,我们不要debug python,-O3改为-O2,空间紧张O2就可以了。 我的是59行。

  1. 修改PGEN:

    PGEN=           Parser/pgen$(EXE)

一行的下面加上

PGEN_HOST= ../build.pc/Parser/pgen$(EXE)

表明我们在HOST上运行的pgen

c 在要使用PGEN的地方改为PGEN_HOST (494行):

$(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
                -@ mkdir Include
                -$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)

改为:

$(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
                -@ mkdir Include
                -$(PGEN_HOST) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)

d 修改所有使用新生成的python的地方为本机的python绝对地址.
所有如 ./$(BUILDPYTHON) 的地方,都改为python (为本地的python地址,不要使用刚刚编译生成的./python),
在vim里面使用:

:%s/.\/$(BUILDPYTHON)/\/usr\/bin\/python/g

我的是替换了11处。
如:

platform: $(BUILDPYTHON)
        $(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform

改为:

platform: $(BUILDPYTHON)
        $(RUNSHARED)  /usr/bin/python  -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform

这种地方比较多,大家小心修改。

如果出这样的错, 说明替换的有问题:

case $MAKEFLAGS in \
        *-s*) LD_LIBRARY_PATH=/home/border/tools/Python-2.5.2/build.arm: CC='arm_v5t_le-gcc' LDSHARED='arm_v5t_le-gcc -shared' OPT='-DNDEBUG -fwrapv -O2 -Wall -Wstrict-prototypes' ./python -E ../setup.py -q build;; \
        *) LD_LIBRARY_PATH=/home/border/tools/Python-2.5.2/build.arm: CC='arm_v5t_le-gcc' LDSHARED='arm_v5t_le-gcc -shared' OPT='-DNDEBUG -fwrapv -O2 -Wall -Wstrict-prototypes' ./python -E ../setup.py build;; \
        esac
/bin/sh: line 2: ./python:无法执行二进制文件

7. 修改setup.py
setup.py负责编译python的各个扩展模块。但是,由于python完全没有考虑cross compile,所以要做一些修改。

PyBuildExt类:
  1. build_extension函数:

    这个函数在编译了所有的extension后,会去load这些刚编译好的extension, 但我们在i686的电脑上显然不能load,所以要跳过这些操作。 在 build_ext.build_extension(self, ext)下一行直接写一个return,不做load。

  1. detect_modules函数:
    • 函数的前两行是把/usr/local加到搜索目录中,我们的cross compiler一般不会直接安装在 /usr/local里面的,所以这两行去掉:

      add_dir_to_list(self.compiler.library_dirs, ‘/usr/local/lib’)
      add_dir_to_list(self.compiler.include_dirs, ‘/usr/local/include’)

      lib_dirs, inc_dirs的设定中,把中括号里的那些都去掉。 以下所有模块都不要:

      cmath, ctypes, _testcapi, pwd, grp, spwd, mmap, audioop, imageop, rgbimg, readline,
      ssl, openssl, bdb, dbm, termios, nsl, ncurses, bz2, linuxaudiodev, ossaudiodev, tkinter

8 main函数

setup函数调用的时候,把要安装的scripts那一部分去掉

之后就可以make && make install了.

  1. 最后在ARM机上执行时如果遇到:

    root@192.168.0.167:~# python2.5
    Could not find platform dependent libraries <exec_prefix>
    Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
    Python 2.5.2 (r252:60911, Jul 31 2008, 18:05:30)
    [GCC 3.4.3 (MontaVista 3.4.3-25.0.30.0501131 2005-07-23)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

就是没有配置PYTHONHOME,PYTHONPATH:

export PYTHONHOME=/usr/lib/python2.5
export PYTHONPATH=.:$PYTHONHOME:$PYTHONHOME/site-packages
export PATH=$PATH:$PYTHONHOME:$PYTHONPATH

如果出现’import site’ failed错误,就是PYTHONPATH配置出错。

感谢 Len Jay 不厌其烦的指导。

参考:

– EOF –

Categories: Embedded Tags: , , ,