天天看点

HI3518EV200初体验

Chap1 SDK初探

step1.1 解压<Hi3518E_SDK_V1.0.4.0.tgz>到自己的工作目录

进入解压后的目录Hi3518E_SDK_V1.0.4.0可以看到4个文件(linux下一切皆文件?)

package  scripts  sdk.cleanup  sdk.unpack

目录说明:
package     :存放SDK各种压缩包的目录
scripts     :存放shell脚本的目录
sdk.cleanup : SDK清理脚本,运行后整个目录将恢复到解压后的初始状态,请注意自己的修改内容,谨慎运行
sdk.unpack  : SDK展开脚本,用以快速展开基本的SDK包
           

step1.2 运行./sdk.unpack解压SDK包

期间可能会有报错:

./sdk.unpack: 2: ./sdk.unpack: source: not found

./sdk.unpack: 4: ./sdk.unpack: ECHO: not found

./sdk.unpack: 6: ./sdk.unpack: WARN: not found

./sdk.unpack: 7: ./sdk.unpack: WARN: not found

./sdk.unpack: 8: ./sdk.unpack: ECHO: not found

./sdk.unpack: 20: ./sdk.unpack: ECHO: not found

./sdk.unpack: 22: ./sdk.unpack: run_command_progress_float: not found

./sdk.unpack: 24: ./sdk.unpack: ECHO: not found

./sdk.unpack: 26: ./sdk.unpack: run_command_progress_float: not found

./sdk.unpack: 37: ./sdk.unpack: ECHO: not found

./sdk.unpack: 39: ./sdk.unpack: run_command_progress_float: not found

./sdk.unpack: 42: ./sdk.unpack: ECHO: not found

./sdk.unpack: 44: ./sdk.unpack: run_command_progress_float: not found

解决方法:修改系统默认shell为bash

sudo dpkg-reconfigure dash

选择:否/no,重新运行脚本即可

运行后可以看到当前目录下的文件结构: 

drv  mpp  osdrv  package  scripts  sdk.cleanup  sdk.unpack

新增目录说明:
drv    :driver相关
mpp    :媒体处理软件平台(Media Process Platform)相关
osdrv  :操作系统及相关驱动<uboot, kernerl, rootfs,tools...>
           

Chap2.SDK整体编译

step2.1 编译链的安装与选择

    040SDK包中提供两种编译工具链 arm-hisiv300-linux 和 arm-hisiv400-linux在osdrv/opensource/toolchain目录下,其中 arm-hisiv300-linux 为基于 uclibc 的工具链, arm-hisiv400-linux 为基于 glibc 的工具链。请注意uboot,kernel,rootfs,和我们的app要统一使用某一个交叉编译链编译,不要两个编译链混用,否则系统运行的时候可能出现奇奇怪怪的错误,安装方法如下(注意,需要有sudo权限或者root权限):

    1)安装v300编译链:

       进入arm-hisiv300-linux目录,然后运行./cross.install即可。

    2)安装v400编译链:

       进入arm-hisiv400-linux目录,运行chmod +x cross.install,然后运行./cross.install即可。

    3)生效环境变量:

       编辑 /etc/environment,在""内加入[ /opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/bin/:/opt/hisi-linux/x86-arm/arm-hisiv400-linux/target/bin ](注意用:分隔),然后souce /etc/environment即可

    4)编译链的选取:

       由于单板资源有限,而ulibc比glibc要小很多,所以后续正常情况下选择arm-hisiv300-linux作为我的编译链

step2.2 整体编译

    进入目录<Hi3518E_SDK_V1.0.4.0/osdrv>,make OSDRV_CROSS=arm-hisiv300-linux CHIP=hi3518ev200 all,整体编译。编译期间可能会遇到若干错误,关键字摘录如下:

    错误1:

Hi3518E_SDK_V1.0.4.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.2/lib/libmtd.a(libmtd.o): in function `dev_node2num':
Hi3518E_SDK_V1.0.4.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.2/lib/libmtd.c:446: undefined reference to `major'
Hi3518E_SDK_V1.0.4.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.2/lib/libmtd.c:447: undefined reference to `minor'
Hi3518E_SDK_V1.0.4.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.2/lib/libmtd.a(libmtd.o): in function `mtd_probe_node':
Hi3518E_SDK_V1.0.4.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.2/lib/libmtd.c:1395: undefined reference to `major'
Hi3518E_SDK_V1.0.4.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.2/lib/libmtd.c:1396: undefined reference to `minor'
Hi3518E_SDK_V1.0.4.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.2/lib/libmtd.a(libmtd_legacy.o): in function `legacy_get_dev_info':
Hi3518E_SDK_V1.0.4.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.2/lib/libmtd_legacy.c:254: undefined reference to `major'
Hi3518E_SDK_V1.0.4.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.2/lib/libmtd_legacy.c:255: undefined reference to `minor'
collect2: error: ld returned 1 exit status
           

   错误2:

mkfs.jffs2.c:70:10: fatal error: sys/acl.h: 没有那个文件或目录
           

    错误3:

compr_zlib.c:39:10: fatal error: zlib.h: 没有那个文件或目录
           

    错误4:

mkfs.ubifs/mkfs.ubifs.h:46:10: fatal error: uuid/uuid.h: 没有那个文件或目录
           

    错误5:

/usr/bin/ld: misc-utils/lslocks.o: in function `get_dev_inode':
Hi3518E_SDK_V1.0.4.0/osdrv/tools/pc/cramfs_tool/tmp/util-linux-2.22-rc2/misc-utils/lslocks.c:223: undefined reference to `makedev'
/usr/bin/ld: misc-utils/lslocks.o: in function `get_fallback_filename':
Hi3518E_SDK_V1.0.4.0/osdrv/tools/pc/cramfs_tool/tmp/util-linux-2.22-rc2/misc-utils/lslocks.c:142: undefined reference to `makedev'
collect2: error: ld returned 1 exit status
           

    错误6:其他

step2.3 错误分析及解决

    产生这些错误的原因在于我们的环境搭建不完全,无论是pc还是交叉编译链。处理方法有如下两种。

    Action1.  修改顶层Makefile:删除目标 all的依赖,hipctools hiboardtools,这样一来不再编译这些工具,可以自己安装代替,同时也需要修改Makefile中使用这些工具的地方,如:

pushd $(OSDRV_DIR)/pub/bin/pc;./mkfs.jffs2 -d $(OSDRV_DIR)/pub/$(PUB_ROOTFS) -l -e 0x40000 -o $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(JFFS2_IMAGE_BIN_256K);popd
pushd $(OSDRV_DIR)/pub/bin/pc;./mkfs.jffs2 -d $(OSDRV_DIR)/pub/$(PUB_ROOTFS) -l -e 0x20000 -o $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(JFFS2_IMAGE_BIN_128K);popd
pushd $(OSDRV_DIR)/pub/bin/pc;./mkfs.jffs2 -d $(OSDRV_DIR)/pub/$(PUB_ROOTFS) -l -e 0x10000 -o $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(JFFS2_IMAGE_BIN_64K);popd
pushd $(OSDRV_DIR)/pub/bin/pc;./mkfs.ubifs -d $(OSDRV_DIR)/pub/$(PUB_ROOTFS) -m 2KiB -e 126976 -o ./$(UBIFS_UBI_IMAGE_BIN) -c 256 -F;popd
pushd $(OSDRV_DIR)/pub/bin/pc;./ubinize -m 2KiB -p 128KiB -o $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(UBIFS_IMAGE_BIN) ubi.cfg;popd
pushd $(OSDRV_DIR)/pub/bin/pc;rm ./$(UBIFS_UBI_IMAGE_BIN) ubi.cfg -rf;popd
           

   Action2: 给SDK打补丁。针对以上错误,我给SDK做了一份补丁,补丁脚本内容如下:

#!/bin/bash

#Author:	Lucas
#Email:		[email protected]
#QQ:		2302457646
#Notice:
#	1. you must have runned the script [sdk.unpack] to unpack the sdk
#	2. you must have runned the script [cross.install.v300] or others to install the compiler
#	3. you may should adapt for another compiler firstly, 
#		this patch is for arm-hisiv300-linux, others may be will get some errors.

if [ $UID -ne 0 ]; then
    echo -e "${PURPLE}\n Superuser privileges are required to run this script. ${NC}"
    echo -e "${PURPLE}\n e.g. \"sudo $0\" ${NC}"
    exit 1
fi

COMPILER_TARGET="/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/usr"
SDK_DIR="../Hi3518E_SDK_V1.0.4.0"

MTD_UTILS_FILE="mtd-utils-1.5.2.tar.bz2"
SQUASHFS_FILE="squashfs4.2.tar.bz2"
UTILS_FILE="util-linux-2.22-rc2.tar.bz2"

#patch for pc tool build
if [ -z "`dpkg -l |grep -i libacl1-dev`" ];then
sudo apt-get install  libacl1-dev
fi

if [ -z "`dpkg -l |grep -i zlib1g-dev`" ];then
sudo apt install zlib1g-dev 
fi

if [ -z "`dpkg -l |grep -i zlib1g-dev:i386`" ];then
sudo apt install zlib1g-dev:i386
fi

if [ -z "`dpkg -l |grep -i libuuid`" ];then
sudo apt-get install uuid-dev
fi

echo "patch of install done..."

sudo cp packages/${MTD_UTILS_FILE} ${SDK_DIR}/osdrv/tools/board/mtd-utils/
sudo cp packages/${MTD_UTILS_FILE} ${SDK_DIR}/osdrv/tools/pc/jffs2_tool/
sudo cp packages/${SQUASHFS_FILE} ${SDK_DIR}/osdrv/tools/pc/squashfs4.2/
sudo cp packages/${UTILS_FILE} ${SDK_DIR}/osdrv/tools/pc/cramfs_tool/

echo "patch of replace source file done..."

sed -i "s/mtd-utils-1.5.0/mtd-utils-1.5.2/g" ${SDK_DIR}/osdrv/tools/board/mtd-utils/Makefile
sed -i "s/mtd-utils-1.5.0/mtd-utils-1.5.2/g" ${SDK_DIR}/osdrv/tools/pc/jffs2_tool/Makefile

#Those two lines don't work well without [ nproc=$(nproc) ] when compile sdk, such as:
#"make OSDRV_CROSS=arm-hisiv300-linux CHIP=hi3518ev200 nproc=$(($(nproc)-1)) all"
#if your cpu isn't one core signle thread, it's better to use '+' instead '-' . 
sed -i "s/-j 20 /-j\$(nproc) /g" `grep "\-j 20 " -rl ${SDK_DIR}`
sed -i "s/-j 16 /-j\$(nproc) /g" `grep "\-j 16 " -rl ${SDK_DIR}`
echo "patch of adapt makefile done..."

#patch for board
sudo cp -rf include/* ${COMPILER_TARGET}/include/

echo "patch of add include done..."

#notice: libs just for arm-hisiv300-linux, if you use another compiler,
#        make sure libs are useful at first.
sudo cp -d lib/* ${COMPILER_TARGET}/lib/

echo "patch of add libs done..."

echo "patch for ${SDK_DIR} done... Enjoy it"
           

   运行该补丁后再编译即可。补丁内容不再赘述。

附:完整补丁包 https://download.csdn.net/download/qq_36160497/11217057

step2.4  再编译

    打完补丁后,运行 make OSDRV_CROSS=arm-hisiv300-linux CHIP=hi3518ev200 nproc=$(($(nproc)-1)) all,耐心等待几分钟后,提示编译成功

HI3518EV200初体验

结尾:

    经过一顿疯狂的操作后,SDK编译成功,HI3518E的开发环境算是搭建成功啦,后续可以开启海思的基本学习了,如有问题或错漏,欢迎大家留言指出,同时补丁脚本中也包含联系方式?