Archive

Archive for the ‘Embedded’ Category

Cross Compile SDL

August 3rd, 2010 BianJiang No comments

==============================
jpeg-8b

./configure –host=arm-linux –prefix=/opt/rootfs/cross/arm/usr
make
make install

==============================
libpng-1.2.44

./configure –host=arm-linux –prefix=/opt/rootfs/cross/arm/usr/
make
make install

==============================
zlib-1.2.5

export CC=arm-linux-gcc
./configure –shared –prefix=/opt/rootfs/cross/arm/usr
make
make install

==============================
e2fsprogs-1.41.12

./configure –host=arm-linux –prefix=/opt/rootfs/cross/arm/usr
make
make install

==============================
freetype-2.3.12

./configure –host=arm-linux –prefix=/opt/rootfs/cross/arm/usr
make
make install

==============================
DirectFB-1.4.3
依赖: JPEG, libpng, e2fsprogs(uuid), zlib, freetype2
make的时候如果在Makefile里面出现没有相关的头文件就进相关的Makefile修改CFLAGS增加你头文件和库文件的地址, 如果你不是Davinci平台,就进入gfxdrivers/Makefile把”DAVINCI_DIR”相关的东西都屏蔽掉。

./configure –host=arm-linux –prefix=/opt/rootfs/cross/arm/usr
make
make install

==============================
SDL-1.2.14
依赖: JPEG, libpng, e2fsprogs(uuid), zlib,
——

export NM=arm-linux-nm
export LD=arm-linux-ld
export CC=arm-linux-gcc
export CXX=arm-linux-g++
export RANLIB=arm-linux-ranlib
export AR=arm-linux-ar

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/arm/4.2.2-eabi/:/usr/local/arm/4.2.2-eabi/usr/:/opt/rootfs/cross/arm/usr/

如果找不到directfb库,修改Makefile, 在CFLAGS中增加你的相关库文件的路径

CFLAGS = -g -O2 -I/opt/rootfs/cross/arm/usr/include -L/opt/rootfs/cross/arm/usr/lib
LDFLAGS = $(CFLAGS)

./configure –enable-video-qtopia –enable-video-directfb –enable-video-opengl –disable-video-dummy –disable-video-fbcon –disable-video-dga –disable-arts-shared –disable-arts –disable-esd –disable-esd-shared –disable-alsa –disable-cdrom –disable-video-x11 –disable-nasm –disable-diskaudio –disable-mintaudio –disable-video-ps2gs –disable-atari-ldg –disable-video-photon –disable-nas –host=arm-linux –prefix=/opt/rootfs/cross/arm/libsdl

编译sdltest
cd test
修改Makefile增加一些库

CFLAGS = -g -O2 -I/opt/rootfs/cross/arm/libsdl/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -L/opt/rootfs/cross/arm/libsdl/lib -I/opt/rootfs/cross/arm/libsdl/include -I/opt/rootfs/cross/arm/usr/include -L/opt/rootfs/cross/arm/usr/lib -I/opt/rootfs/cross/arm/libsdl/include/SDL
LIBS = -L/opt/rootfs/cross/arm/libsdl/lib -lSDL -lpthread -ldirectfb -ljpeg -lpng -ldirect -lpng12 -lz -lfusion -lfreetype

*****************************************

1. 挂接命令:

mount -o nolock -t nfs 10.0.3.244:/long_nfs /tmp/
mount -o nolock 10.0.3.244:/long_nfs /tmp/

这两个都可以。
2. 可能出现的错误类型
a. 错误类型:

rpcbind: server localhost not responding, timed out
RPC: failed to contact local rpcbind server (errno 5).
lockd_up: makesock failed, error=-5
rpcbind: server localhost not responding, timed out
RPC: failed to contact local rpcbind server (errno 5).
mount: mounting 10.0.3.244:/long_nfs on /tmp/ failed: Input/output error

这个问题是因为挂接命令不对,要加上参数-o nolock就可以了

但是NFS不稳定

nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 not responding, still trying

=============================

Categories: Embedded, Tech.Notes Tags: , ,

安装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: ,