嵌入式 linux"/>
嵌入式 linux
首先下载下嵌入式linux服务器资源,linux-ftpd-0.17.tar.gz
下面我们将开始制作嵌入式linux下ftp服务器
1、解压资源
tar xvzf linux-ftpd-0.17.tar.gz
2、修改configure文件
vi configure,内容如下:
- #!/bin/sh
- #
- # This file was generated by confgen version 2.
- # Do not edit.
- #
- PREFIX='/usr'
- #EXECPREFIX='$PREFIX'
- INSTALLROOT=''
- BINMODE='755'
- #DAEMONMODE='$BINMODE'
- MANMODE='644'
- while [ x$1 != x ]; do case $1 in
- --help)
- cat <<EOF
- Usage: configure [options]
- --help Show this message
- --with-debug Enable debugging
- --without-shadow Disable shadow password support
- --prefix=path Prefix for location of files [/usr]
- --exec-prefix=path Location for arch-depedent files [prefix]
- --installroot=root Top of filesystem tree to install in [/]
- --binmode=mode Mode for binaries [755]
- --daemonmode=mode Mode for daemon binaries [same as binmode]
- --manmode=mode Mode for manual pages [644]
- --with-c-compiler=cc Program for compiling C source [guessed]
- EOF
- exit 0;;
- --verbose) ;;
- --quiet) ;;
- --subdir) . ../configure.defs;;
- --with-debug|--debug) DEBUG=1;;
- --prefix=*) PREFIX=`echo $1 | sed 's/^[^=]*=//'` ;;
- --exec-prefix=*) EXECPREFIX=`echo $1 | sed 's/^[^=]*=//'` ;;
- --installroot=*) INSTALLROOT=`echo $1 | sed 's/^[^=]*=//'` ;;
- --binmode=*) BINMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
- --daemonmode=*) DAEMONMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
- --manmode=*) MANMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
- --with-c-compiler=*) CC=`echo $1 | sed 's/^[^=]*=//'` ;;
- --without-shadow|--disable-shadow) WITHOUT_SHADOW=1;;
- *) echo "Unrecognized option: $1"; exit 1;;
- esac
- shift
- done
上面我们能够清晰的看见configure的各个参数及作用,这里我不详细介绍各个参数的作用,这里我们如果想将ftpd服务器移植到嵌入式linux操作系统中,需要关注的主要是三个参数,分别是:prefix,installroot,with-c-compiler,其中prefix为installroot(文件系统根目录)目录下的具体目录,这里为什么需要将其与intallroot变量分开,主要是因为后续安装ftpd服务器时需要传递几个文件,所以需要根文件系统传递几个参数。
prefix:这里的值我们不用修改,一般ftpd被安装到文件系统目录下的/usr/sbin中
intallroot:文件系统的根目录,这里设置为/XXX/rootfs
with-c-compiler:交叉编译器的选择,嵌入式linux肯定是arm-linux-gcc,(在传递交叉编译工具时,如果文件中这样添加WITH-C-COMPILER='arm-linux-gcc',好像会报错,所
以我没直接在文件中传递这个参数,希望有大神能指点下为什么)
这是我们运行./configure --with-c-compiler=arm-linux-gcc尝试配置下,结果出现如下信息:
Directories: /usr/sbin /usr/man
Checking if C compiler works... no
Compiler arm-linux-gcc does not exist or cannot compile C; try another.
分析发现,我们传递的arm-linux-gcc出错,可是我的arm-linux-gcc编译内核都没问题,应该不会少文件,估计时configure文件内有错误,打开configure文件,找到错误信息
比对发现:
$CC __conftest.c -o __conftest || exit 1
./__conftest || exit 1
./__conftest肯定不能再linux下运行啊,所以果断将该文件中的./__conftest全部删除,总共8处。
继续运行./configure --with-c-compiler=arm-linux-gcc,这次输出信息Ok:
- Directories: /usr/sbin /usr/man
- Checking if C compiler works... yes
- Checking if arm-linux-gcc accepts gcc warnings... yes
- Checking if arm-linux-gcc accepts -O2... yes
- Checking for yacc... bison -y
- Checking for BSD signal semantics... yes
- Checking for shadow... yes
- Checking for crypt... -lcrypt
- Checking for socklen_t... yes
- Checking for snprintf declaration... ok
- Checking for snprintf implementation... ok
- Generating MCONFIG...
3、接下来我们开始编译
make,结果还是报错,
- ftpcmd.y:108: error: array type has incomplete element type
- ftpcmd.y:109: error: array type has incomplete element type
- ftpcmd.y: In function 'yylex':
- ftpcmd.y:1055: warning: cast discards qualifiers from pointer target type
- ftpcmd.y:1081: warning: cast discards qualifiers from pointer target type
- make[1]: *** [ftpcmd.o] Error 1
- make[1]: Leaving directory `/GT2440/linux-ftpd-0.17/ftpd'
查看出错文件,vi ftpd/ftpcmd.y
发现这块应该是tab结构体定义文件,将该文件中810行开始的结构体定义放到代码前面,ok。
- extern jmp_buf errcatch;
- #define CMD 0 /* beginning of command */
- #define ARGS 1 /* expect miscellaneous arguments */
- #define STR1 2 /* expect SP followed by STRING */
- #define STR2 3 /* expect STRING */
- #define OSTR 4 /* optional SP then STRING */
- #define ZSTR1 5 /* SP then optional STRING */
- #define ZSTR2 6 /* optional STRING after SP */
- #define SITECMD 7 /* SITE command */
- #define NSTR 8 /* Number followed by a string */
- //static void help __P((struct tab *, char *));
- static struct tab *
- lookup __P((struct tab *, char *));
- static void sizecmd __P((char *));
- static int yylex __P((void));
- struct tab {
- const char *name;
- short token;
- short state;
- short implemented; /* 1 if command is implemented */
- const char *help;
- };
- struct tab cmdtab[] = { /* In order defined in RFC 765 */
- { "USER", USER, STR1, 1, "<sp> username" },
- { "PASS", PASS, ZSTR1, 1, "<sp> password" },
- { "ACCT", ACCT, STR1, 0, "(specify account)" },
- { "SMNT", SMNT, ARGS, 0, "(structure mount)" },
- { "REIN", REIN, ARGS, 0, "(reinitialize server state)" },
- { "QUIT", QUIT, ARGS, 1, "(terminate service)", },
- { "PORT", PORT, ARGS, 1, "<sp> b0, b1, b2, b3, b4" },
- { "PASV", PASV, ARGS, 1, "(set server in passive mode)" },
- { "TYPE", TYPE, ARGS, 1, "<sp> [ A | E | I | L ]" },
- { "STRU", STRU, ARGS, 1, "(specify file structure)" },
- { "MODE", MODE, ARGS, 1, "(specify transfer mode)" },
- { "RETR", RETR, STR1, 1, "<sp> file-name" },
- { "STOR", STOR, STR1, 1, "<sp> file-name" },
- { "APPE", APPE, STR1, 1, "<sp> file-name" },
- { "MLFL", MLFL, OSTR, 0, "(mail file)" },
- { "MAIL", MAIL, OSTR, 0, "(mail to user)" },
- { "MSND", MSND, OSTR, 0, "(mail send to terminal)" },
- { "MSOM", MSOM, OSTR, 0, "(mail send to terminal or mailbox)" },
- { "MSAM", MSAM, OSTR, 0, "(mail send to terminal and mailbox)" },
- { "MRSQ", MRSQ, OSTR, 0, "(mail recipient scheme question)" },
- { "MRCP", MRCP, STR1, 0, "(mail recipient)" },
- { "ALLO", ALLO, ARGS, 1, "allocate storage (vacuously)" },
- { "REST", REST, ARGS, 1, "<sp> offset (restart command)" },
- { "RNFR", RNFR, STR1, 1, "<sp> file-name" },
- { "RNTO", RNTO, STR1, 1, "<sp> file-name" },
- { "ABOR", ABOR, ARGS, 1, "(abort operation)" },
- { "DELE", DELE, STR1, 1, "<sp> file-name" },
- { "CWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
- { "XCWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
- { "LIST", LIST, OSTR, 1, "[ <sp> path-name ]" },
- { "NLST", NLST, OSTR, 1, "[ <sp> path-name ]" },
- { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" },
- { "SYST", SYST, ARGS, 1, "(get type of operating system)" },
- { "STAT", STAT, OSTR, 1, "[ <sp> path-name ]" },
- { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
- { "NOOP", NOOP, ARGS, 1, "" },
- { "MKD", MKD, STR1, 1, "<sp> path-name" },
- { "XMKD", MKD, STR1, 1, "<sp> path-name" },
- { "RMD", RMD, STR1, 1, "<sp> path-name" },
- { "XRMD", RMD, STR1, 1, "<sp> path-name" },
- { "PWD", PWD, ARGS, 1, "(return current directory)" },
- { "XPWD", PWD, ARGS, 1, "(return current directory)" },
- { "CDUP", CDUP, ARGS, 1, "(change to parent directory)" },
- { "XCUP", CDUP, ARGS, 1, "(change to parent directory)" },
- { "STOU", STOU, STR1, 1, "<sp> file-name" },
- { "SIZE", SIZE, OSTR, 1, "<sp> path-name" },
- { "MDTM", MDTM, OSTR, 1, "<sp> path-name" },
- { NULL, 0, 0, 0, 0 }
- };
- struct tab sitetab[] = {
- { "UMASK", UMASK, ARGS, 1, "[ <sp> umask ]" },
- { "IDLE", IDLE, ARGS, 1, "[ <sp> maximum-idle-time ]" },
- { "CHMOD", CHMOD, NSTR, 1, "<sp> mode <sp> file-name" },
- { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
- { NULL, 0, 0, 0, 0 }
- };
4、安装ftpd,直接将ftpd拷贝到根文件系统目录下的/usr/sbin中,然后配置启动文件
在etc目录下的init.d/rcS文件中,添加如下内容:
- # These are standard services.
- #
- <span style="color:#FF0000;">ftp stream tcp nowait root /usr/sbin/ftpd /usr/sbin/ftpd</span>
- #telnet stream tcp nowait root /usr/sbin/telnetd /usr/sbin/telnetd -i
修改/etc/passwd文件,添加如下内容:
- root::0:0:root:/:/bin/sh
- ftp::14:50:FTP User:/var/ftp:
- bin:*:1:1:bin:/bin:
- daemon:*:2:2:daemon:/sbin:
- nobody:*:99:99:Nobody:/:
- plg:$1$wwtsqwnk$sWaEJGcJFTqaCW18sbUK7/:502:502:Linux User,,,:/home/plg:/bin/sh
但是,发现启动ftp服务后,需要挺长时间才能登陆上。因此推荐大家还是使用vsftpd-2.3.4,感觉比ftpd好用。
VSftpd-2.3.4使用:
更多推荐
嵌入式 linux
发布评论