meta-xiangshan的编译和使用

本章介绍如何在香山开发板编译和集成应用示例。 具体内容如下:

1.构建镜像

build_portal环境搭建及使用

2.烧录镜像

下载flash编程器

https://www.sflytech.com/html/7812591720.html

烧录镜像

下载 bbl.bin 文件,并将其重名为 linux.bin

双击打开FlyPRO

选择芯片型号

点击菜单栏中的“芯片”——>下拉菜单,点击“选择芯片”——> 选择:MT25QL512ABB——>点击“确定”

../../_images/xiangshan_xuanxing.jpg

香山的芯片选型

擦除Flash芯片信息

点击菜单栏中的“擦除”选项,即可将上一次残留在芯片中的信息删除掉

烧录芯片

点击菜单栏中的“加载”选项,选择 linux.bin 。再点击菜单栏中的“编程”选项,可完成芯片的烧录。

3.下载CH340串口驱动

https://sparks.gogo.co.nz/assets/_site_/downloads/CH34x_Install_Windows_v3_4.zip

4.增加AI框架

由于香山开发板对内存有着严格的限制,因此,在生成 bbl.bin (linux.bin)时,文件大小不应超过64MB。使用 meta-raios 集成AI框架时,需分别对MNN框架和NCNN框架进行修改,修改如下:

MNN框架

cd  existing_repo

cd meta-raios/recipes-support/mnn

vim mnn_0.1.bb
# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://README.md;md5=befec2cd231da610047e2062b1f3d3b9"

DEPENDS = "protobuf"

SRC_URI = "git://github.com/alibaba/MNN.git;protocol=https;branch=master  \
             file://0001-change-compile-err.patch \
             file://gesture.jpg   \
             file://pos.mnn   \
             file://mobilenet_v2.caffe.mnn \
             file://Test.jpg  \
             file://input.jpg  \
             file://model.mnn"

SRCREV = "47d6fc5adcdff3658d2e4c69e854f28f7debc888"

# Modify these as desired
PV = "0.1+git${SRCPV}"

S = "${WORKDIR}/git"

inherit cmake pkgconfig


do_compile() {
        echo  $PWD
        cd  ../git
        mkdir build
        cd build
        cmake ..  \
        -DCMAKE_BUILD_TYPE=Release  \
        -DCMAKE_SYSTEM_NAME=Linux \
        -DCMAKE_SYSTEM_VERSION=1 \
        -DCMAKE_SYSTEM_PROCESSOR=riscv64 \
        -DCMAKE_C_COMPILER=riscv64-oe-linux-gcc \
        -DCMAKE_CXX_COMPILER=riscv64-oe-linux-g++ \
        -DMNN_BUILD_CONVERTER=true  \
        -DMNN_BUILD_DEMO=ON  \
        -DCMAKE_SKIP_RPATH=TRUE  \
        -DCMAKE_SKIP_INSTALL_RPATH=TRUE

        make -j16
}

INSANE_SKIP:${PN} = "ldflags"
SOLIBS = ".so"
FILES_SOLIBSDEV = ""

do_install()  {
        install -d ${D}${libdir}
        install -d ${D}${datadir}/mnn/
        install -d ${D}${datadir}/mnn/multiPose
        install -d ${D}${datadir}/mnn/pictureRecognition
        install -d ${D}${datadir}/mnn/segment
        install -d ${D}${includedir}/

        cd  ${WORKDIR}/git/build
        install -m 0755 libMNN.so  ${D}${libdir}
        cd  express
        install -m 0755 libMNN_Express.so  ${D}${libdir}
        cd  ../tools/converter
        install -m 0755 libMNNConvertDeps.so  ${D}${libdir}
        cd  ../..
        install -m 0755 segment.out  ${D}${datadir}/mnn/segment

        cd  ../..
        install -m 0755 input.jpg  ${D}${datadir}/mnn/segment
        install -m 0755 model.mnn  ${D}${datadir}/mnn/segment

        cp -r  git/include/*        ${D}${includedir}/
}

FILES:${PN} += "${datadir}/mnn/ ${datadir}/mnn/multiPose ${datadir}/mnn/segment ${datadir}/mnn/pictureRecognition "
FILES:${PN}-dev += "${includedir}/  ${libdir}/libMNN*.so.*"

NCNN框架

cd  existing_repo

cd meta-raios/recipes-support/ncnn

vim ncnn_0.1.bb
# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE.txt

LICENSE = "BSD-3-Clause"
LIC_FILES_CHKSUM = "file://LICENSE.txt;md5=8c8b5b19ef89ee9cfa47e768aa904935"

DEPENDS = "protobuf"
#DEPENDS = "opencv"

SRC_URI = "git://github.com/Tencent/ncnn.git;protocol=git;branch=master \
           file://0001-Add-install-examples-dir.patch \
           file://cat.jpg \
           file://dog.jpg \
           file://seagull.jpg \
           file://tiger.jpg \
           file://car.jpg \
           file://mobilenet_ssd_voc_ncnn.param \
           file://mobilenet_ssd_voc_ncnn.bin \
           file://pose.param \
           file://pose.bin \
 "

SRCREV = "a692a8fce746844d9a0c1613faaa17eaca62963a"

# Modify these as desired
PV = "0.1+git${SRCPV}"

S = "${WORKDIR}/git"

# NOTE: unable to map the following CMake package dependencies: OpenCV Vulkan Protobuf
inherit cmake pkgconfig

# Specify any options you want to pass to cmake using EXTRA_OECMAKE:
EXTRA_OECMAKE = ""

INSANE_SKIP:${PN} = "ldflags"
SOLIBS = ".so.*"
FILES_SOLIBSDEV = ""

do_install()  {
        install -d ${D}${libdir}
        install -d ${D}${datadir}/ncnn/
        install -d ${D}${datadir}/ncnn/testpic
        install -d ${D}${datadir}/ncnn/squeezenet
        install -d ${D}${datadir}/ncnn/mobilenetssd
        install -d ${D}${datadir}/ncnn/simplepose

        cd  ${WORKDIR}/build/src
        install -m 0755 libncnn.so.1 ${D}${libdir}

        cd  ${WORKDIR}/git/examples
        install -m 0755 synset_words.txt  ${D}${datadir}/ncnn/
        install -m 0755 squeezenet_v1.1.param  ${D}${datadir}/ncnn/squeezenet
        install -m 0755 squeezenet_v1.1.bin  ${D}${datadir}/ncnn/squeezenet

        cd  ${WORKDIR}
        install -m 0755 tiger.jpg  ${D}${datadir}/ncnn/testpic

        cd  ${WORKDIR}/build/examples
        install -m 0755 squeezenet ${D}${datadir}/ncnn/squeezenet
}

FILES_${PN} += "${datadir}/ncnn/ ${datadir}/ncnn/testpic ${datadir}/ncnn/squeezenet ${datadir}/ncnn/mobilenetssd  ${datadir}/ncnn/simplepose  ${libdir}/lib${PN}_*.so"