天天看點

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的開發環境算是搭建成功啦,後續可以開啟海思的基本學習了,如有問題或錯漏,歡迎大家留言指出,同時更新檔腳本中也包含聯系方式?