Hi35xx web环境搭建

一. 编译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,看到类似如下目录结构:

  sss@sss-XPS-8910:~/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

此时可能会报错:

sss@sss-XPS-8910:~/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

问题解决后再次编译:

        sss@sss-XPS-8910:~/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目录, 目录结构如下:

        sss@sss-XPS-8910:~/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共享文件中

    sss@sss-XPS-8910:~/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机上:
sss@sss-XPS-8910:~/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
sss@sss-XPS-8910:~/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

sss@sss-XPS-8910:~/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中
然后执行(具体编译链路径为你自己的路径):
        sss@sss-XPS-8910:~/Appweb/appweb-6.1.1/samples/esp-hosted$ ln -s /opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-gcc gcc
然后执行:
        sss@sss-XPS-8910:~/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整个文件夹拷到开发版上:
        sss@sss-XPS-8910:~/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环境搭建_第1张图片Hi35xx web环境搭建_第2张图片

你可能感兴趣的:(嵌入式,Hi35xx,C++)