hostapd移植(2.6版本为例)
Hostapd的移植,依赖:libnl openssl
下载地址:
Hostapd-2.6:http://w1.fi/releases/hostapd-2.6.tar.gz
Libnl: http://www.infradead.org/~tgr/libnl/files/
Openssl: https://www.openssl.org/source/old/1.0.1/
Libnl: 交叉编译 (选择的版本是libnl-1.1.tar.gz)
解压安装包,建一个__install文件夹用来保存安装的库文件
# mkdir __install
#./configure CC=arm-fullhan-linux-uclibcgnueabi-gcc --prefix=$PWD/__install --host=arm
#make & make install
可以看到__install/lib/ 下面有生成的libnl动态库
如果希望能生成静态库,对lib/Makefile做如下修改:
#vim lib/Makefile
修改好的 lib/Makefile
1 # 2 # lib/Makefile 3 # 4 # This library is free software; you can redistribute it and/or 5 # modify it under the terms of the GNU Lesser General Public 6 # License as published by the Free Software Foundation version 2.1 7 # of the License. 8 # 9 # Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch> 10 # 11 12 ifeq ($(shell [ ! -r ../Makefile.opts ] && echo 1),) 13 include ../Makefile.opts 14 endif 15 16 # Core 17 CIN := $(wildcard *.c) 18 # NETLINK_ROUTE 19 CIN += $(wildcard route/*.c) 20 # Schedulers 21 CIN += $(wildcard route/sch/*.c) 22 # Classifiers 23 CIN += $(wildcard route/cls/*.c) 24 # Link Info Modules 25 CIN += $(wildcard route/link/*.c) 26 # NETLINK_GENERIC 27 CIN += $(wildcard genl/*.c) 28 # fib lookup 29 CIN += $(wildcard fib_lookup/*.c) 30 # Netfilter 31 CIN += $(wildcard netfilter/*.c) 32 33 DEPS := $(CIN:%.c=%.d) 34 OBJ := $(CIN:%.c=%.o) 35 CFLAGS += -fPIC 36 OUT_LIB := $(PACKAGE_NAME).a 37 OUT_SLIB := $(PACKAGE_NAME).so.$(PACKAGE_VERSION) 38 LN_SLIB := $(PACKAGE_NAME).so 39 LN1_SLIB := $(LN_SLIB).1 40 41 export 42 43 .PHONY: all clean install librtn.a $(OUT_SLIB) 44 45 46 all: 47 @echo " MAKE $(OUT_LIB)"; \ 48 $(MAKE) $(OUT_LIB) 49 @echo " MAKE $(OUT_SLIB)"; \ 50 $(MAKE) $(OUT_SLIB) 51 52 $(OUT_LIB): ../Makefile.opts $(OBJ) 53 @echo " LD $(OUT_LIB)"; \ 54 echo $(AR) rs $(OUT_LIB) $(OBJ) 55 $(AR) rs $(OUT_LIB) $(OBJ) 56 57 $(OUT_SLIB): ../Makefile.opts $(OBJ) 58 @echo " LD $(OUT_SLIB)"; \ 59 $(CC) -shared -Wl,-soname,libnl.so.1 -o $(OUT_SLIB) $(OBJ) $(LIBNL_LIB) -lc 60 @echo " LN $(OUT_SLIB) $(LN1_SLIB)"; \ 61 rm -f $(LN1_SLIB) ; $(LN) -s $(OUT_SLIB) $(LN1_SLIB) 62 @echo " LN $(LN1_SLIB) $(LN_SLIB)"; \ 63 rm -f $(LN_SLIB) ; $(LN) -s $(LN1_SLIB) $(LN_SLIB) 64 65 clean: 66 @echo " CLEAN lib"; \ 67 $(RM) -f $(OBJ) $(OUT_LIB) $(OUT_SLIB) $(LN_SLIB) $(LN1_SLIB); \ 68 $(RM) -f $(DEPS) $(OUT_LIB) $(OUT_SLIB) $(LN_SLIB) $(LN1_SLIB) 69 70 distclean: 71 @echo " DISTCLEAN lib"; \ 72 $(RM) -f $(DEPS) 73 74 install: 75 mkdir -p $(DESTDIR)$(libdir)/ 76 install -m 0644 $(OUT_SLIB) $(DESTDIR)$(libdir) 77 install -m 0644 $(OUT_LIB) $(DESTDIR)$(libdir) 78 rm -f $(DESTDIR)$(libdir)/$(LN1_SLIB) 79 $(LN) -s $(OUT_SLIB) $(DESTDIR)$(libdir)/$(LN1_SLIB) 80 rm -f $(DESTDIR)$(libdir)/$(LN_SLIB) 81 $(LN) -s $(LN1_SLIB) $(DESTDIR)$(libdir)/$(LN_SLIB) 82 83 $(DEPS): ../Makefile.opts 84 85 include ../Makefile.rules
保存退出,make& make install 就可以生成libnl.a 静态库了。
Openssl交叉编译:(选择的版本是openssl-1.1.1.tar.gz)
解压安装包,建一个__install文件夹用来保存安装的库文件
# mkdir __install
# ./config no-asm no-shared no-async --prefix=$PWD/__install
注意:如果不加入no-async,会出现以下错误:
./libcrypto.a(b_sock.o): In function `BIO_gethostbyname':
b_sock.c:(.text+0x4a8): warning: gethostbyname is obsolescent, use getnameinfo() instead.
./libcrypto.a(async_posix.o): In function `ASYNC_is_capable':
async_posix.c:(.text+0x48): undefined reference to `getcontext'
./libcrypto.a(async_posix.o): In function `async_fibre_makecontext':
async_posix.c:(.text+0x7c): undefined reference to `getcontext'
async_posix.c:(.text+0xec): undefined reference to `makecontext'
./libcrypto.a(async.o): In function `async_fibre_swapcontext':
async.c:(.text+0x28c): undefined reference to `setcontext'
collect2: ld returned 1 exit status
make[1]: *** [apps/openssl] Error 1
make[1]: Leaving directory `/test/hostapd_test/openssl-1.1.1'
make: *** [all] Error 2
修改Makefile
#PLATFORM=linux-x86
PLATFORM=linux-armv7
#CROSS_COMPILE
CROSS_COMPILE=arm-fullhan-linux-uclibcgnueabi-
删除所有的 -m32 -m64选项
保存退出,make clean
Make & make install
在__install 里面就可以看到静态库了:
Hostapd的编译:(选择的版本是hostapd-2.6.tar.gz)
解压hostapd-2.6安装包,进入
# cp defconfig .config
修改Makefile
CC=arm-fullhan-linux-uclibcgnueabi-gcc
CFLAGS += -I /test/hostapd_test/libnl-1.1/__install/include
LIBS += -L /test/hostapd_test/libnl-1.1/__install/lib -lnl
CFLAGS += -I /test/hostapd_test/openssl-1.1.1/__install/include
LIBS += -L /test/hostapd_test/openssl-1.1.1/__install/lib -lcrypto -lssl
BINDIR := ./__install/bin
LDFLAGS += -lpthread
LDFLAGS += -lm
注意:
Libnl 和 libopenssl 为上述步骤编译生成的。此处的包含路径可以选择绝对路径。
如果不加入LDFLAGS += -lpthread ,LDFLAGS += -lm 两个选项会出现如下错误:
install/lib/libnl-1.1.a(utils.o): In function `nl_prob2int':
libnl-1.1.1/lib/utils.c:392: undefined reference to `rint'
collect2: ld returned 1 exit status
保存;
#make & make install
就可以在__install/bin 下面生成hostapd命令了。
注意:因为libnl和libopenssl都是编译成静态库形式,所以hostapd在开发板上可以直接运行,不需要将libxxx.so 拷贝到/lib/下面。
上述编译是在fuhan平台的;
海思平台遇到的问题:
1. /test/hostapd_test/openssl-1.1.1/__install/lib/libcrypto.a(b_sock.o): In function `BIO_gethostbyname':
b_sock.c:(.text+0x54): warning: gethostbyname is obsolescent, use getnameinfo() instead.
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../lib/gcc/arm-linux-uclibceabi/6.3.0/../../../../arm-linux-uclibceabi/bin/ld: /opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/lib/libpthread.so.0: undefined reference to symbol 'dlclose'
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/lib/libdl.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:1077: recipe for target 'hostapd' failed
make: *** [hostapd] Error 1
解决方法:
在hostapd的Makefile 中加入:LDFLAGS += -ldl
2. 另外hostapd2.5版本,在编译的时候,出现如下错误:
CC ../src/crypto/tls_openssl.c
../src/crypto/crypto_openssl.c: In function 'openssl_digest_vector':
../src/crypto/crypto_openssl.c:68:13: error: storage size of 'ctx' isn't known
EVP_MD_CTX ctx;
^~~
../src/crypto/crypto_openssl.c: In function 'rc4_skip':
../src/crypto/crypto_openssl.c:132:17: error: storage size of 'ctx' isn't known
EVP_CIPHER_CTX ctx;
^~~
In file included from /test/hostapd_test/hostapd-2.5/src/utils/common.h:12:0,
from ../src/crypto/crypto_openssl.c:26:
../src/crypto/crypto_openssl.c: In function 'aes_encrypt_init':
../src/crypto/crypto_openssl.c:213:25: error: dereferencing pointer to incomplete type 'EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}'
ctx = os_malloc(sizeof(*ctx));
^~
/test/hostapd_test/hostapd-2.5/src/utils/os.h:485:30: note: in definition of macro 'os_malloc'
#define os_malloc(s) malloc((s))
^
../src/crypto/crypto_openssl.c: In function 'aes_128_cbc_encrypt':
../src/crypto/crypto_openssl.c:341:17: error: storage size of 'ctx' isn't known
EVP_CIPHER_CTX ctx;
^~~
../src/crypto/crypto_openssl.c: In function 'aes_128_cbc_decrypt':
../src/crypto/crypto_openssl.c:366:17: error: storage size of 'ctx' isn't known
EVP_CIPHER_CTX ctx;
^~~
../src/crypto/crypto_openssl.c: At top level:
../src/crypto/crypto_openssl.c:428:17: error: field 'enc' has incomplete type
EVP_CIPHER_CTX enc;
^~~
../src/crypto/crypto_openssl.c:429:17: error: field 'dec' has incomplete type
EVP_CIPHER_CTX dec;
解决方法:
降低openssl的版本,因为openssl1.1.1的版本中,ctx结构体的定义有改变,导致出错。建议降低至openssl1.0.1c。
另加上openssl1.0.1c的编译过程:
版本是openssl1.0.1c.tar.gz
解压安装包,建一个__install文件夹用来保存安装的库文件
# mkdir __install
# ./config no-asm no-shared no-async --prefix=$PWD/__install
修改Makefile
#CC= gcc
CC= arm-himix100-linux-gcc
#CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -DTERMIO -O3 -Wall
#DEPFLAG= -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SCTP -DOPENSSL_NO_STORE
CFLAG= -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -march=armv5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall
DEPFLAG= -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SCTP -DOPENSSL_NO_STORE
PEX_LIBS=
EX_LIBS= -ldl
EXE_EXT=
ARFLAGS=
#AR= ar $(ARFLAGS) r
AR= arm-himix100-linux-ar $(ARFLAGS) r
#RANLIB= /usr/bin/ranlib
RANLIB= arm-himix100-linux-ranlib
#NM= nm
NM= arm-himix100-linux-nm
PERL= /usr/bin/perl
TAR= tar
TARFLAGS= --no-recursion
MAKEDEPPROG= gcc
LIBDIR=lib
保存退出,make clean
Make & make install
在__install 里面就可以看到静态库了:
参考:https://blog.csdn.net/u013286409/article/details/51355433
WiFi模块经常用到hostapd启软AP,换个平台,又得重新编译一遍,所以自己整理下,下次找也方便。借鉴了上述文章,还请不吝赐教,若侵权,联系即删。