天天看點

Hi35xx web環境搭建一. 編譯appweb arm版二. 安裝ESP(我的版本為6.2.1)三. 進入appweb的目錄appweb-6.1.1

一. 編譯appweb arm版

Appweb交叉編譯

我們對Markdown編輯器進行了一些功能拓展與文法支援,除了标準的Markdown編輯器功能,我們增加了如下幾點新功能,幫助你用它寫部落格:

  1. 編譯環境:ubuntu-18.04 x64
  2. 開發平台:Hi3539AV100 arm版
  3. 編譯版本:appweb-6.1.1.zip
  4. 下載下傳位址(我的版本為6.1.1):

    Appweb 官網: https://www.embedthis.com/appweb/download.html

    Appweb GitHub: https://github.com/embedthis/appweb/releases/tag/v6.1.1

1. 配置appweb編譯環境

① 解壓以後進入appweb-6.1.1,看到類似如下目錄結構:

[email protected]:~/Appweb/appweb-6.1.1$ ls
        LICENSE.md  README.md  configure      dist  installs  make.bat      paks      samples  test
        Makefile    build      configure.bat  doc   main.me   package.json  projects  src
           

② vi 打開projects/appweb-linux-default.mk檔案(簡單說明下配置,ARCH選擇的硬體架構是arm的,OS作業系統是linux,CC為arm交叉編譯工具aarch64-himix100-linux-gcc)

我的配置如下:

#
    #   appweb-linux-default.mk -- Makefile to build Embedthis Appweb for linux
    #

    NAME                  := appweb
    VERSION               := 6.1.1
    PROFILE               := release
    ARCH                  := arm
    CC_ARCH               := arm
    OS                    := linux
    CC                    := aarch64-himix100-linux-gcc
    CONFIG                ?= $(OS)-$(ARCH)-$(PROFILE)
    BUILD                 ?= build/$(CONFIG)
    LBIN                  ?= $(BUILD)/bin
    PATH                  := $(LBIN):$(PATH)
           

2.make編譯appweb arm版本

make -f projects/appweb-linux-default.mk
           

此時可能會報錯:

[email protected]:~/Appweb/appweb-6.1.1$ make -f projects/appweb-linux-default.mk
     [Info] Use make SHOW=1 to trace executed commands.
      [Copy] build/linux-arm-release/inc/osdep.h
   [Compile] build/linux-arm-release/obj/mbedtls.o
In file included from src/mbedtls/embedtls.h:10:0,
                 from src/mbedtls/mbedtls.h:2475,
                 from src/mbedtls/mbedtls.c:5:
build/linux-arm-release/inc/osdep.h:106:6: error: #error "Cannot determine CPU type in osdep.h"
     #error "Cannot determine CPU type in osdep.h"
      ^~~~~
projects/appweb-linux-default.mk:448: recipe for target 'build/linux-arm-release/obj/mbedtls.o' failed
make: *** [build/linux-arm-release/obj/mbedtls.o] Error 1
           

原因可能是無法定位目前cpu類型解決辦法如下:

修改此檔案内容/home/sss/Appweb/appweb-6.1.1/src/osdep/osdep.h 50行左右

(報的錯是build/linux-arm-release/inc/osdep.h修改的是這個檔案的原因是報錯的檔案是此檔案生成的),

這一段代碼的功能是定義cpu類型,可能因為Hi3559是64位的

本來沒有#elif defined(arm64) || defined(aarch64)這一選項,加上就好了.

/*
            Use compiler definitions to determine the CPU type. 
            The default endianness can be overridden by configure --endian big|little.
         */
        #if defined(__alpha__)
            #define ME_CPU "alpha"
            #define ME_CPU_ARCH ME_CPU_ALPHA
            #define CPU_ENDIAN ME_LITTLE_ENDIAN

        #elif defined(__arm__)
            #define ME_CPU "arm"
            #define ME_CPU_ARCH ME_CPU_ARM
            #define CPU_ENDIAN ME_LITTLE_ENDIAN

        #elif defined(__arm64__) || defined(__aarch64__)
            #define ME_CPU "arm"
            #define ME_CPU_ARCH ME_CPU_ARM
            #define CPU_ENDIAN ME_LITTLE_ENDIAN

        #elif defined(__x86_64__) || defined(_M_AMD64)
            #define ME_CPU "x64"
            #define ME_CPU_ARCH ME_CPU_X64
            #define CPU_ENDIAN ME_LITTLE_ENDIAN

        #elif defined(__i386__) || defined(__i486__) || defined(__i585__) || defined(__i686__) || defined(_M_IX86)
            #define ME_CPU "x86"
            #define ME_CPU_ARCH ME_CPU_X86
            #define CPU_ENDIAN ME_LITTLE_ENDIAN

        #elif defined(_M_IA64)
            #define ME_CPU "ia64"
            #define ME_CPU_ARCH ME_CPU_ITANIUM
            #define CPU_ENDIAN ME_LITTLE_ENDIAN

        #elif defined(__mips__) || defined(__mips64)
            #define ME_CPU "mips"
            #define ME_CPU_ARCH ME_CPU_MIPS
            #define CPU_ENDIAN ME_BIG_ENDIAN

        #elif defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__ppc)
            #define ME_CPU "ppc"
            #define ME_CPU_ARCH ME_CPU_PPC
            #define CPU_ENDIAN ME_BIG_ENDIAN

        #elif defined(__sparc__)
            #define ME_CPU "sparc"
            #define ME_CPU_ARCH ME_CPU_SPARC
            #define CPU_ENDIAN ME_BIG_ENDIAN

        #elif defined(_TMS320C6X)
            #define TIDSP 1
            #define ME_CPU "tidsp"
            #define ME_CPU_ARCH ME_CPU_SPARC
            #define CPU_ENDIAN ME_LITTLE_ENDIAN

        #elif defined(__sh__)
            #define ME_CPU "sh"
            #define ME_CPU_ARCH ME_CPU_SH
            #define CPU_ENDIAN ME_LITTLE_ENDIAN

        #else
            #error "Cannot determine CPU type in osdep.h"
        #endif
           

問題解決後再次編譯:

[email protected]:~/Appweb/appweb-6.1.1$ make -f projects/appweb-linux-default.mk
              [Info] Use make SHOW=1 to trace executed commands.
              [Copy] build/linux-arm-release/inc/osdep.h
           [Compile] build/linux-arm-release/obj/mbedtls.o
              [Link] build/linux-arm-release/bin/libmbedtls.a
              [Copy] build/linux-arm-release/inc/mpr.h
           [Compile] build/linux-arm-release/obj/mpr-mbedtls.o
              [Link] build/linux-arm-release/bin/libmpr-mbedtls.a
           [Compile] build/linux-arm-release/obj/mprLib.o
              [Link] build/linux-arm-release/bin/libmpr.so
           [Compile] build/linux-arm-release/obj/pcre.o
              [Link] build/linux-arm-release/bin/libpcre.so
              [Copy] build/linux-arm-release/inc/http.h
           [Compile] build/linux-arm-release/obj/httpLib.o
              [Link] build/linux-arm-release/bin/libhttp.so
              [Copy] build/linux-arm-release/inc/mpr-version.h
           [Compile] build/linux-arm-release/obj/mpr-version.o
              [Link] build/linux-arm-release/bin/libmpr-version.a
              [Copy] build/linux-arm-release/inc/esp.h
           [Compile] build/linux-arm-release/obj/espLib.o
              [Link] build/linux-arm-release/bin/libesp.so
              [Copy] build/linux-arm-release/inc/appweb.h
           [Compile] build/linux-arm-release/obj/config.o
           [Compile] build/linux-arm-release/obj/convenience.o
           [Compile] build/linux-arm-release/obj/romFiles.o
           [Compile] build/linux-arm-release/obj/cgiHandler.o
           [Compile] build/linux-arm-release/obj/espHandler.o
              [Link] build/linux-arm-release/bin/libappweb.so
           [Compile] build/linux-arm-release/obj/appweb.o
              [Link] build/linux-arm-release/bin/appweb
           [Compile] build/linux-arm-release/obj/authpass.o
              [Link] build/linux-arm-release/bin/authpass
           [Compile] build/linux-arm-release/obj/esp.o
              [Link] build/linux-arm-release/bin/appweb-esp
              [Copy] build/linux-arm-release/bin
           [Compile] build/linux-arm-release/obj/http.o
              [Link] build/linux-arm-release/bin/http
              [Copy] build/linux-arm-release/bin
           [Compile] build/linux-arm-release/obj/watchdog.o
              [Link] build/linux-arm-release/bin/appman
           

編譯成功會在目前目錄下生成一個build目錄, 目錄結構如下:

[email protected]:~/Appweb/appweb-6.1.1$ tree ./build/
        ./build/
        `-- linux-arm-release
            |-- bin
            |   |-- appman
            |   |-- appweb
            |   |-- appweb-esp
            |   |-- authpass
            |   |-- ca.crt
            |   |-- ca.key
            |   |-- ec.crt
            |   |-- ec.key
            |   |-- esp-compile.json
            |   |-- http
            |   |-- libappweb.so
            |   |-- libesp.so
            |   |-- libhttp.so
            |   |-- libmbedtls.a
            |   |-- libmpr-mbedtls.a
            |   |-- libmpr-version.a
            |   |-- libmpr.so
            |   |-- libpcre.so
            |   |-- roots.crt
            |   |-- self.crt
            |   |-- self.key
            |   |-- test.crt
            |   |-- test.key
            |   `-- vcvars.bat
            |-- inc
            |   |-- appweb.h
            |   |-- customize.h
            |   |-- embedtls.h
            |   |-- esp.h
            |   |-- http.h
            |   |-- mbedtls.h
            |   |-- me.h
            |   |-- mpr-version.h
            |   |-- mpr.h
            |   |-- osdep.h
            |   `-- pcre.h
            `-- obj
                |-- appweb.o
                |-- authpass.o
                |-- cgiHandler.o
                |-- config.o
                |-- convenience.o
                |-- esp.o
                |-- espHandler.o
                |-- espLib.o
                |-- http.o
                |-- httpLib.o
                |-- mbedtls.o
                |-- mpr-mbedtls.o
                |-- mpr-version.o
                |-- mprLib.o
                |-- pcre.o
                |-- romFiles.o
                `-- watchdog.o

        4 directories, 52 files
           

3.将編譯好的appweb arm版本複制到開發版上或者nfs共享檔案中

[email protected]:~/Appweb/appweb-6.1.1$ cp -r build/linux-arm-release/ ~/3559/Appweb/
           

4.然後在闆子的終端中将linux-arm-release/bin中的lib*檔案拷到/usr/lib中就是能讓程式運作找到這些庫就可以并把linux-arm-release/bin加入環境變量

5.運作appweb,然後可能會出現段錯誤:

此時在海思3559的開發版上:
    ~/hzs/Appweb/test/linux-arm-release/bin # ./appweb --version
    This is appweb main! -add by hzs!
    test for call func!
    appweb[1645]: unhandled level 3 translation fault (11) at 0x7f7edfbfe8, esr 0x92000007
    pgd = ffffffc07e84f000
    [7f7edfbfe8] *pgd=00000000bf75a003, *pud=00000000bf75a003
    , *pmd=00000000bf32c003, *pte=0000000000000000


    CPU: 1 PID: 1645 Comm: appweb Not tainted 4.9.37 #3
    Hardware name: Hisilicon HI3559AV100 DEMO Board (DT)
    task: ffffffc07e9f6000 task.stack: ffffffc07e9dc000
    PC is at 0x7f7eb93d48
    LR is at 0x7f7ed14d14
    pc : [<0000007f7eb93d48>] lr : [<0000007f7ed14d14>] pstate: 80000000
    sp : 0000007fe23774c0
    x29: 0000007fe23774d0 x28: 0000000000000000 
    x27: 0000000000000000 x26: 0000000000000000 
    x25: 0000000000000000 x24: 0000000000000000 
    x23: 0000000000000000 x22: 0000000000000000 
    x21: 0000000000401db0 x20: 0000000000000000 
    x19: 0000000000000000 x18: 0000000000000001 
    x17: 0000007f7eb93d40 x16: 0000007f7edd57c0 
    x15: 000000000000027f x14: 0000000000000000 
    x13: 00000003e8000000 x12: 0000000000000018 
    x11: 0000000000000012 x10: 0101010101010101 
    x9 : 00000000000041a7 x8 : 0101010101010101 
    x7 : 7f7f7f7f7f7f7f7f x6 : feff42465e444b41 
    x5 : 8080000000000000 x4 : 0000000000000001 
    x3 : 0000000000000000 x2 : 0000000000000001 
    x1 : ffffffffffffffff x0 : 0000007f7edfbfe8 

    Segmentation fault
           
錯誤的原因可能是在編譯appweb是/home/sss/Appweb/appweb-6.1.1/src/mpr/mprLib.c檔案中,
函數allocMem配置設定記憶體時出現問題函數allocMem調用的函數findFirstBit,
應該是此檔案中定義的findFirstBit,由于不能重複定義是以此檔案中定義的這個方法沒有生效
在2242行左右可以看出

#ifndef findFirstBit
static ME_INLINE int findFirstBit(size_t word)
{
    int     b;
    for (b = 0; word; word >>= 1, b++) {
        if (word & 0x1) {
            b++;
            break;
        }
    }
    return b;
}
#endif
我的解決辦法是:
在此出下方重新定義一邊
ME_INLINE int hzsFindFirstBit(size_t word);
ME_INLINE int hzsFindFirstBit(size_t word)
{
    int     b;
    for (b = 0; word; word >>= 1, b++) {
        if (word & 0x1) {
            b++;
            break;
        }
    }
    return b;
}
然後在函數allocMem調用的函數findFirstBit替換為我們剛才自定義的函數,重新編譯一邊appweb就好了
在PC機上:
           
[email protected]:~/Appweb/appweb-6.1.1$ make -f projects/appweb-linux-default.mk
      [Info] Use make SHOW=1 to trace executed commands.
   [Compile] build/linux-arm-release/obj/mbedtls.o
      [Link] build/linux-arm-release/bin/libmbedtls.a
   [Compile] build/linux-arm-release/obj/mpr-mbedtls.o
      [Link] build/linux-arm-release/bin/libmpr-mbedtls.a
   [Compile] build/linux-arm-release/obj/mprLib.o
      [Link] build/linux-arm-release/bin/libmpr.so
   [Compile] build/linux-arm-release/obj/pcre.o
      [Link] build/linux-arm-release/bin/libpcre.so
   [Compile] build/linux-arm-release/obj/httpLib.o
      [Link] build/linux-arm-release/bin/libhttp.so
   [Compile] build/linux-arm-release/obj/mpr-version.o
      [Link] build/linux-arm-release/bin/libmpr-version.a
   [Compile] build/linux-arm-release/obj/espLib.o
      [Link] build/linux-arm-release/bin/libesp.so
   [Compile] build/linux-arm-release/obj/config.o
   [Compile] build/linux-arm-release/obj/convenience.o
   [Compile] build/linux-arm-release/obj/romFiles.o
   [Compile] build/linux-arm-release/obj/cgiHandler.o
   [Compile] build/linux-arm-release/obj/espHandler.o
      [Link] build/linux-arm-release/bin/libappweb.so
   [Compile] build/linux-arm-release/obj/appweb.o
      [Link] build/linux-arm-release/bin/appweb
   [Compile] build/linux-arm-release/obj/authpass.o
      [Link] build/linux-arm-release/bin/authpass
   [Compile] build/linux-arm-release/obj/esp.o
      [Link] build/linux-arm-release/bin/appweb-esp
      [Copy] build/linux-arm-release/bin
   [Compile] build/linux-arm-release/obj/http.o
      [Link] build/linux-arm-release/bin/http
      [Copy] build/linux-arm-release/bin
   [Compile] build/linux-arm-release/obj/watchdog.o
      [Link] build/linux-arm-release/bin/appman
[email protected]:~/Appweb/appweb-6.1.1$ cp -r build/linux-arm-release/ ~/3559/Appweb/
           
在開發版上:
           
~/hzs/Appweb/test/linux-arm-release/bin # ./appweb --version
 6.1.1
           
此時證明arm版Appweb編譯成功

二. 安裝ESP(我的版本為6.2.1)

ESP下載下傳位址:
    ESP web 官網: https://www.embedthis.com/esp/download.html
    ESP GitHub: https://github.com/embedthis/esp/archive/v6.2.1.zip
           

解壓到ubuntu(此時ESP用ubuntu的gcc編譯,不需要使用交叉編譯工具鍊)

進入esp-6.2.1目錄中

執行: make -f projects/esp-linux-default.mk

[email protected]:~/Appweb/esp-6.2.1$ make -f projects/esp-linux-default.mk
      [Info] Use make SHOW=1 to trace executed commands.
   [Compile] build/linux-x64-default/obj/sqlite3.o
      [Link] build/linux-x64-default/bin/libsql.so
   [Compile] build/linux-x64-default/obj/mbedtls.o
      [Link] build/linux-x64-default/bin/libmbedtls.a
   [Compile] build/linux-x64-default/obj/mpr-mbedtls.o
      [Link] build/linux-x64-default/bin/libmpr-mbedtls.a
   [Compile] build/linux-x64-default/obj/mprLib.o
      [Link] build/linux-x64-default/bin/libmpr.so
   [Compile] build/linux-x64-default/obj/pcre.o
      [Link] build/linux-x64-default/bin/libpcre.so
   [Compile] build/linux-x64-default/obj/httpLib.o
      [Link] build/linux-x64-default/bin/libhttp.so
   [Compile] build/linux-x64-default/obj/mpr-version.o
      [Link] build/linux-x64-default/bin/libmpr-version.a
   [Compile] build/linux-x64-default/obj/edi.o
   [Compile] build/linux-x64-default/obj/espAbbrev.o
   [Compile] build/linux-x64-default/obj/espConfig.o
   [Compile] build/linux-x64-default/obj/espFramework.o
   [Compile] build/linux-x64-default/obj/espHtml.o
   [Compile] build/linux-x64-default/obj/espRequest.o
   [Compile] build/linux-x64-default/obj/espTemplate.o
   [Compile] build/linux-x64-default/obj/mdb.o
   [Compile] build/linux-x64-default/obj/sdb.o
      [Link] build/linux-x64-default/bin/libesp.so
   [Compile] build/linux-x64-default/obj/esp.o
      [Link] build/linux-x64-default/bin/esp
      [Copy] build/linux-x64-default/bin
      [Copy] build/linux-x64-default/bin
   [Compile] build/linux-x64-default/obj/watchdog.o
      [Link] build/linux-x64-default/bin/espman
           

安裝到系統目錄: sudo make -f projects/esp-linux-default.mk install

此時esp工具安裝完畢

三. 進入appweb的目錄appweb-6.1.1

将appweb-6.1.1/build/linux-arm-release拷到appweb-6.1.1/samples/esp-hosted中
然後執行(具體編譯鍊路徑為你自己的路徑):
           
[email protected]:~/Appweb/appweb-6.1.1/samples/esp-hosted$ ln -s /opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-gcc gcc
           
然後執行:
           
[email protected]:~/Appweb/test/appweb-6.1.1/samples/esp-hosted$ esp --platform linux-arm-release compile
           [Compile] controllers/post.c
             [Parse] dist/index.esp
           [Compile] cache/view_d061105dfc21da53d5aedd5dcdbbe66e.c
             [Parse] dist/post/edit.esp
           [Compile] cache/view_f7419ec95eccc67cee132bff3ebd63d6.c
             [Parse] dist/post/list.esp
           [Compile] cache/view_96d36fd7e20d9abf20d78c749a656034.c
           
将esp-hosted整個檔案夾拷到開發版上:
           
[email protected]:~/Appweb/test/appweb-6.1.1/samples$ cp -r esp-hosted ~/3559/Appweb/
           
最後在開發闆上将appweb.conf中的ip位址改為0.0.0.0:8080後執行:
           
~/hzs/Appweb/test/a # vi appweb.conf 
        ~/hzs/Appweb/test/a # appweb
        Unknown ErrorLog option append
        01/03/70 02:29:13 2 appweb, Configuration for Embedthis Appweb
        01/03/70 02:29:13 2 appweb, ----------------------------------
        01/03/70 02:29:13 2 appweb, Version:            6.1.1
        01/03/70 02:29:13 2 appweb, BuildType:          Debug
        01/03/70 02:29:13 2 appweb, CPU:                arm
        01/03/70 02:29:13 2 appweb, OS:                 linux
        01/03/70 02:29:13 2 appweb, Host:               (none)
        01/03/70 02:29:13 2 appweb, Configure:          me -d -q -platform linux-x86-default -configure . -gen make
        01/03/70 02:29:13 2 appweb, ----------------------------------
        01/03/70 02:29:13 0 info http, Started HTTP service on 0.0.0.0:8080
           
顯示這樣則表示成功
在同一網段的其他電腦浏覽器中輸入
    192.168.xx.xx:8080/espapp
    192.168.xx.xx:8080/espapp/post
           
Hi35xx web環境搭建一. 編譯appweb arm版二. 安裝ESP(我的版本為6.2.1)三. 進入appweb的目錄appweb-6.1.1
Hi35xx web環境搭建一. 編譯appweb arm版二. 安裝ESP(我的版本為6.2.1)三. 進入appweb的目錄appweb-6.1.1