1. 程式人生 > >海思3536&3798 DHCPv6移植

海思3536&3798 DHCPv6移植

1.原始碼地址

2.交叉編譯

一、libnl 1.1
1.解壓libnl-1.1.tar.gz 到指定目錄下 ../libnl_pro
2.修改libnl_pro內的檔案
    **** .../libnl_pro/lib/route/link/vlan.c ****

    #include <linux/if_vlan.h>
    //找到這裡,新增以下3行程式碼
    #ifndef VLAN_FLAG_REORDER_HDR
    #define VLAN_FLAG_REORDER_HDR 0x01
    #endif
    
3.交叉編譯
    在目錄../libnl_pro下執行,#### /home/user1/hong/smdd/pro/libnl/hi3536/ 為對應存放庫檔案路徑
    ./configure CC=arm-hisiv300-linux-gcc --host=arm --prefix=/home/user1/hong/smdd/pro/libnl/hi3536/
    ./configure CC=arm-histbv310-linux-gcc --host=arm --prefix=/home/user1/hong/smdd/pro/libnl/hi3798/
    make clean
    make
    make install

    

二、DHCPv6
1.解壓dhcpv6-1.2.0.tar.gz 到指定目錄下 ../dhcpv6_pro  【3536和3798需區分開交叉編譯,因此可以複製一個檔案如../dhcpv6_pro_hi3798】
2.交叉編譯:在../dhcpv6_pro路徑下執行, /home/user1/hong/smdd/pro/libnl/hi3798/lib 為上面獲取libnl的路徑
    ./configure LIBNL_CFLAGS=-I/home/user1/hong/smdd/pro/libnl/include LIBNL_LIBS="-L/home/user1/hong/smdd/pro/libnl/hi3798/lib -lnl" CC=arm-histbv310-linux-gcc --host=arm --with-gnu-ld
    ./configure LIBNL_CFLAGS=-I/home/user1/hong/smdd/pro/libnl/include LIBNL_LIBS="-L/home/user1/hong/smdd/pro/libnl/hi3536/lib -lnl" CC=arm-hisiv300-linux-gcc --host=arm --with-gnu-ld
    
3.對專案下的一些檔案必須作出修改
    **** ../dhcpv6_pro/config.h ****
    
    /* Directory for lease databases and DUID files. */

	//#define DB_FILE_PATH "/var/lib/dhcpv6"		//David.Milesight modify 14.07.28

	#define DB_FILE_PATH "/tmp"



	/* Directory for PID files. */

	//#define PID_FILE_PATH "/var/run/dhcpv6"		//David.Milesight modify 14.07.28

	#define PID_FILE_PATH "/tmp"	



	/* Define to rpl_malloc if the replacement function should be used. */

	//#define malloc rpl_malloc						//David			



	/* Define to `int' if <sys/types.h> does not define. */

	/* #undef pid_t */					



	/* Define to rpl_realloc if the replacement function should be used. */

	//#define realloc rpl_realloc					//David
    
    
    
    ***** ../dhcpv6_pro/src/dhcp6c.c *******
    
    在main()函式中。

	#ifndef __DARWIN_DEPRECATED_ATTRIBUTE

	    if (foreground == 0) {

#if 0		//David          //註釋這部分程式碼

        if (daemon(0, 0) < 0) {

            err(1, "daemon");

        }
#endif
    
    
4.編譯獲取可執行檔案
在路徑 ../dhcpv6_pro/src 執行make clean 和make就可以在./src下生成對應的可執行檔案 dhcp6c


備註:libnl路徑修改的話請修改makefile以下兩行
      LIBNL_CFLAGS = -I/home/user1/hong/smdd/pro/libnl/hi3536/include
      LIBNL_LIBS = -L/home/user1/hong/smdd/pro/libnl/hi3536/lib -lnl
      
      

三、使用於NVR上

	首先將../libnl/lib下的libnl.so,libnl.so.1,libnl.so.1.1拷到對應的libs檔案裡,如./targets/hi3536/app/libs/

	然後將../dhcpv6_pro/src下的dhcp6c拷到對應bin檔案裡,如./targets/hi3536/app/bin/

3.執行命令

dhcp6c -f eth0 -p /tmp/dhcp6c_eth0.pid &

會在對應路徑下生成pid檔案,存放當前程序的pid號

多網絡卡時,可執行多個dhcp6c,可以根據pid號來區分對應網絡卡