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 <[email protected]>
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/下面

 

 

参考:https://blog.csdn.net/u013286409/article/details/51355433

WiFi模块经常用到hostapd启软AP,换个平台,又得重新编译一遍,所以自己整理下,下次找也方便。借鉴了上述文章,还请不吝赐教,若侵权,联系即删。

 

 

猜你喜欢

转载自www.cnblogs.com/TiddlerYu/p/12643041.html