前言

如果您之前编译过EV200的SDK,那么您会发现,编译DV300的过程很类似,软件包直接拷贝,无需重新下载,通常在1-2个小时内能搞定SDK的编译。
DV300的入门只简洁介绍,如果遇到编译错误,请你阅读EV200的编译过程和相应目录下的readme查询解决方法。

重要提示:此文是Hi3516DV300 + nor Flash为基础,演示的SDK编译流程,我们实际开发板配置是eMMC,请熟知!

环境

  1. ubuntu18.04 amd64

    dopi@ubuntu:~$ cat /proc/version
    Linux version 5.3.0-62-generic (buildd@lcy01-amd64-004) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #56~18.04.1-Ubuntu SMP Wed Jun 24 16:17:03 UTC 2020
  2. 海思官方dv300 Linux SDK
    链接:https://pan.baidu.com/s/14CUm62hqorvYKQHR4CXIDQ
    提取码:sjzg


解决问题的思路

  1. 遇到错误不要着急搜索引擎搜索,往往在出错文件的位置,会有一个readme.txt。 会告诉依赖项,以及解决方法。

  2. 遇到tar解压报错,估计你图快,windows下载后,拷贝到ubuntu中,文件会出错,google也救不了,这时候静下心来,wget重新慢慢下载,再编译试试。

  3. 提示系统命令缺失,可直接搜索。


参考文件

1.package\osdrv\readme.cn

1.osdrv 顶层 Makefile 使用说明
本目录下的编译脚本支持 arm-himix200-linux,arm-himix200-linux工具链对应glibc库。具体命令如下(以hi3516dv300举例)
注意:
    由于开源工具整改,部分开源工具不再提供源码包,客户编译OSDRV时需要自行下载:
    a:linux-4.9.37.tar.gz (https://www.kernel.org/pub/)
        将下载的 linux-4.9.37.tar.gz 存放到 osdrv的opensource/kernel目录中

    b:yaffs2utils-0.2.9.tar.gz (https://github.com/dorigom/yaffs2utils/releases)
        将下载的 yaffs2utils-0.2.9.tar.gz 存放到osdrv的tools/pc/mkyaffs2image/目录中

    c:gdb-7.9.1.tar.gz  (http://ftp.gnu.org/gnu/gdb/)
        将下载的 gdb-7.9.1.tar.gz 存放到 osdrv的tools/board/gdb/目录中

    d:ncurses-6.0.tar.gz  ( http://ftp.gnu.org/gnu/ncurses/)
        将下载的 ncurses-6.0.tar.gz 存放到 osdrv的tools/board/gdb/目录中

    e:util-linux-2.31.tar.gz (https://www.kernel.org/pub/linux/utils/util-linux/v2.31)

        将下载的 util-linux-2.31.tar.gz 存放到 osdrv的tools/pc/cramfs_tool/目录中

(1)编译整个osdrv目录:
    注意:默认不发布内核源码包,只发布补丁文件。内核源码包需自行从开源社区上下载。
          从linux开源社区下载v4.9.37版本的内核:
         1)进入网站:www.kernel.org
         2)选择HTTP协议资源的https://www.kernel.org/pub/选项,进入子页面
         3)选择linux/菜单项,进入子页面
         4)选择kernel/菜单项,进入子页面
         5)选择v4.x/菜单项,进入子页面
         6)下载linux-4.9.37.tar.gz (或者linux-4.9.37.tar.xz)到osdrv/opensource/kernel目录下     

    make all

注意:由于Makefile中文件系统编译依赖组件较多,不能保证单独编译的文件系统可用,建议采用make all编译;
        但可单独编译uboot,kernel;

    可以传如下参数:
    a, BOOT_MEDIA:spi(default) or emmc
    b, CHIP:hi3516dv300(default) 、 hi3516av300 or hi3516cv500
    c, 如果客户想要更换可以使用TARGET_XLSM=*.xlsm来指定所需要的u-boot表格文件

(2)清除整个osdrv目录的编译文件:
    make OSDRV_CROSS=arm-himix200-linux clean
(3)彻底清除整个osdrv目录的编译文件,除清除编译文件外,还删除已编译好的镜像:
    make OSDRV_CROSS=arm-himix200-linux distclean

(4)单独编译kernel(以hi3516dv300举例):
    注意:单独编译内核之前请先阅读osdrv/opensource/kernel下的readme_cn.txt说明。

    待进入内核源代码目录后,执行以下操作
    cp arch/arm/configs/hi3516dv300_smp_defconfig  .config
    (emmc启动时执行如下操作:cp arch/arm/configs/hi3516dv300_emmc_smp_defconfig  .config)

    make ARCH=arm CROSS_COMPILE=arm-himix200-linux- menuconfig
    make ARCH=arm CROSS_COMPILE=arm-himix200-linux- uImage

(5)单独编译模块(以hi3516dv300举例):
    待进入内核源代码目录后,执行以下操作
    cp arch/arm/configs/hi3516dv300_smp_defconfig  .config
    (emmc启动时执行如下操作:cp arch/arm/configs/hi3516dv300_emmc_smp_defconfig  .config)
    make ARCH=arm CROSS_COMPILE=arm-himix200-linux- menuconfig
    make ARCH=arm CROSS_COMPILE=arm-himix200-linux- modules

(6)单独编译uboot(以hi3516dv300举例):
   (注意:发布包默认按照DMEB板的配置发布,如果客户单板和DEMB板不一致,需要根据客户自己的单板环境修改uboot表格才能使用,否则可能导致uboot无法启动或者其他问题。)
    待进入boot源代码目录后,执行以下操作
    make ARCH=arm CROSS_COMPILE=arm-himix200-linux- hi3516dv300_defconfig
    (emmc启动时执行如下操作:make ARCH=arm CROSS_COMPILE=arm-himix200-linux- hi3516dv300_emmc_defconfig)

    make ARCH=arm CROSS_COMPILE=arm-himix200-linux- -j 20

    make -C ../../../tools/pc/hi_gzip

    cp ../../../tools/pc/hi_gzip/bin/gzip arch/arm/cpu/armv7/hi3516dv300/hw_compressed/ -rf 

    Windowns下进入到osdrv/tools/pc/uboot_tools/目录下打开对应单板的Excel文件,在main标签中点击"Generate reg bin file"按钮,生成reg_info.bin即为对应平台的表格文件。
    从osdrv/tools/pc/uboot_tools目录拷贝reg_info.bin到boot源代码目录,重命名为.reg
    cp ../../../tools/pc/uboot_tools/reg_info.bin .reg

    make ARCH=arm CROSS_COMPILE=arm-himix200-linux- u-boot-z.bin

    opensource/uboot/u-boot-2016.11下生成的u-boot-hi3516dv300.bin即为可用的u-boot镜像

(7)制作文件系统镜像:
在osdrv/pub/中有已经编译好的文件系统,因此无需再重复编译文件系统,只需要根据单板上flash的规格型号制作文件系统镜像即可。

    SPI NOR Flash使用jffs2格式的镜像,制作jffs2镜像时,需要用到SPI NOR Flash的块大小。这些信息会在uboot启动时
    会打印出来。建议使用时先直接运行mkfs.jffs2工具,根据打印信息填写相关参数。
    下面以块大小为64KB为例:
    osdrv/pub/bin/pc/mkfs.jffs2 -d osdrv/pub/rootfs_uclibc -l -e 0x10000 -o osdrv/pub/rootfs_uclibc_64k.jffs2
    或者
    osdrv/pub/bin/pc/mkfs.jffs2 -d osdrv/pub/rootfs_glibc -l -e 0x10000 -o osdrv/pub/rootfs_glibc_64k.jffs2

        Nand Flash使用yaffs2格式的镜像,制作yaffs2镜像时,需要用到nand flash的pagesize和ecc。这些信息会在uboot启动时会打
    印出来。建议使用时先直接运行mkyaffs2image工具,根据打印信息填写相关参数。
    下面以并口NAND的2KB pagesize、4bit ecc为例:
        osdrv/pub/bin/pc/mkyaffs2image610 osdrv/pub/rootfs_uclibc osdrv/pub/rootfs_uclibc_2k_4bit.yaffs2 1 2
        或者
        osdrv/pub/bin/pc/mkyaffs2image610 osdrv/pub/rootfs_glibc osdrv/pub/rootfs_glibc_2k_4bit.yaffs2 1 2

        Nand Flash使用UBI文件系统,在osdrv/tools/pc/ubi_sh下提供mkubiimg.sh工具用于制作UBI文件系统,需要用到Nand
    Flash的pagesize、blocksize和UBIFS分区的大小。
    以2KB pagesize, 128KB blocksize和UBI文件系统分区大小32MB为例:

    mkubiimg.sh hi3516dv300 2k 128k osdrv/pub/rootfs 32M osdrv/pub/bin/pc

    osdrv/pub/rootfs是根文件系统文件夹目录
    osdrv/pub/bin/pc是制作UBI文件系统镜像的工具目录
        生成的rootfs_hi3516dv300_2k_128k_32M.ubifs,就是最终用于烧写的UBI文件系统镜像。

2. 镜像存放目录说明
编译完的image,rootfs等存放在osdrv/pub目录下
pub
├─ bin
│   ├─ board_glibc -------------------------------------------- himix200编译出的单板用工具
│   │   ├── ethtool
│   │   ├── flashcp
│   │   ├── flash_erase
│   │   ├── flash_otp_dump
│   │   ├── flash_otp_info
│   │   ├── gdb-arm-himix200-linux
│   │   ├── mtd_debug
│   │   ├── mtdinfo
│   │   ├── nanddump
│   │   ├── nandtest
│   │   ├── nandwrite
│   │   ├── sumtool
│   │   ├── ubiattach
│   │   ├── ubicrc32
│   │   ├── ubidetach
│   │   ├── ubiformat
│   │   ├── ubimkvol
│   │   ├── ubinfo
│   │   ├── ubinize
│   │   ├── ubirename
│   │   ├── ubirmvol
│   │   ├── ubirsvol
│   │   └── ubiupdatevol
│   └─ pc
│       ├── lzma
│       ├── mkfs.cramfs
│       ├── mkfs.jffs2
│       ├── mkfs.ubifs
│       ├── mkimage
│       ├── mksquashfs
│       └── ubinize
├─image_glibc ------------------------------------------------- himix200编译出的镜像文件
│   ├── uImage_hi3516dv300 ----------------------------------------- kernel镜像
│   ├── u-boot-hi3516dv300.bin ------------------------------------- u-boot镜像
│   ├── rootfs_hi3516dv300_64k.jffs2 ------------------------------- 64K jffs2 文件系统镜像
│   ├── rootfs_hi3516dv300_128k.jffs2 ------------------------------ 128K jffs2 文件系统镜像
│   ├── rootfs_hi3516dv300_256k.jffs2 ------------------------------ 256K jffs2 文件系统镜像
│   ├── rootfs_hi3516dv300_2k_4bit.yaffs2 -------------------------- yaffs2 文件系统镜像
│   ├── rootfs_hi3516dv300_2k_24bit.yaffs2 ------------------------- yaffs2 文件系统镜像
│   ├── rootfs_hi3516dv300_4k_4bit.yaffs2 -------------------------- yaffs2 文件系统镜像
│   ├── rootfs_hi3516dv300_4k_24bit.yaffs2 ------------------------- yaffs2 文件系统镜像
│   ├── rootfs_hi3516dv300_2k_128k_32M.ubifs------------------------ 2k 128k UBI 文件系统镜像
│   └── rootfs_hi3516dv300_4k_256k_50M.ubifs------------------------ 4k 256k UBI 文件系统镜像
│
├─ rootfs.ubiimg ----------------------------------------------- UBIFS根文件系统
├─ rootfs_glibc.tgz  ------------------------------------------- himix200编译出的rootfs文件系统

3.osdrv目录结构说明:
osdrv
├─Makefile ------------------------------ osdrv目录编译脚本
├─tools --------------------------------- 存放各种工具的目录
│  ├─board ------------------------------ 各种单板上使用工具
│  │  ├─ethtools ----------------------- ethtools工具
│  │  ├─reg-tools-1.0.0 ----------------- 寄存器读写工具
│  │  ├─udev-167 ------------------------ udev工具集
│  │  ├─mtd-utils ----------------------- flash裸读写工具集
│  │  ├─gdb ----------------------------- gdb工具
│  │  └─e2fsprogs ----------------------- mkfs工具集
│  └─pc ---------------------------------- 各种pc上使用工具
│      ├─jffs2_tool----------------------- jffs2文件系统制作工具
│      ├─cramfs_tool --------------------- cramfs文件系统制作工具
│      ├─squashfs4.3 --------------------- squashfs文件系统制作工具
│      ├─nand_production ----------------- nand量产工具
│      ├─lzma_tool ----------------------- lzma压缩工具
│      ├─zlib ---------------------------- zlib工具
│      ├─mkyaffs2image -- ---------------- yaffs2文件系统制作工具
│      └─uboot_tools ----------------------uboot镜像制作工具、xls文件及ddr初始化脚本、reg_info.bin制作工具
├─pub ----------------------------------- 存放各种镜像的目录
│  ├─image_glibc ------------------------ 基于himix200工具链编译,可供FLASH烧写的映像文件,包括uboot、内核、文件系统
│  ├─bin -------------------------------- 各种未放入根文件系统的工具
│  │  ├─pc ------------------------------ 在pc上执行的工具
│  │  ├─board_glibc --------------------- 基于himix200工具链编译,在单板上执行的工具
│  └─rootfs_glibc.tgz ------------------- 基于himix200工具链编译的根文件系统
├─opensource----------------------------- 存放各种开源源码目录
│  ├─busybox ---------------------------- 存放busybox源代码的目录
│  ├─uboot ------------------------------ 存放uboot及安全boot源代码的目录
│  └─kernel ----------------------------- 存放kernel源代码的目录
└─rootfs_scripts ------------------------- 存放根文件系统制作脚本的目录

4.注意事项
(1)在windows下复制源码包时,linux下的可执行文件可能变为非可执行文件,导致无法编译使用;u-boot或内核下编译后,会有很多符号链接文件,在windows下复制这些源码包, 会使源码包变的巨大,因为linux下的符号链接文件变为windows下实实在在的文件,因此源码包膨胀。因此使用时请注意不要在windows下复制源代码包。
(2)使用某一工具链编译后,如果需要更换工具链,请先将原工具链编译文件清除,然后再更换工具链编译。
(3)编译板端软件
    a.此芯片具有浮点运算单元和neon。文件系统中的库是采用兼容软浮点调用接口的硬浮点和neon编译而成,因此请用户注意,所有此芯片板端代码编译时需要在Makefile里面添加选项-mcpu=cortex-a7、-mfloat-abi=softfp和-mfpu=neon-vfpv4。
如:
对于A7:
    CFLAGS += -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -fno-aggressive-loop-optimizations
    CXXFlAGS +=-mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -fno-aggressive-loop-optimizations
其中CXXFlAGS中的XX根据用户Makefile中所使用宏的具体名称来确定,e.g:CPPFLAGS。

kernel 下载

进入 osdrv/opensource/kernel/目下载linuxlinux-4.9.37.tar.gz

cd osdrv/opensource/kernel/
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.9.37.tar.gz

该方法下载很慢,建议迅雷下载,拷贝到osdrv/opensource/kernel/

下载yaffs2utils-0.2.9.tar.gz

cd osdrv/tools/pc/mkyaffs2image/
wget --no-check-certificate https://codeload.github.com/dorigom/yaffs2utils/tar.gz/0.2.9 -O yaffs2utils-0.2.9.tar.gz 

PS: wget指令下载https有些wget版本需要跳过https才能下载成功,使用--no-check-certificate 跳过,默认下载的文件可以使用-O参数修改文件名
执行log:

$ wget https://codeload.github.com/dorigom/yaffs2utils/tar.gz/0.2.9
--2020-06-29 06:23:09--  https://codeload.github.com/dorigom/yaffs2utils/tar.gz/0.2.9
Resolving codeload.github.com (codeload.github.com)... 13.229.189.0
Connecting to codeload.github.com (codeload.github.com)|13.229.189.0|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to:0.2.90.2.9                   [   <=>              ]  38.95K  82.5KB/s    in 0.5s    

2020-06-29 06:23:11 (82.5 KB/s) - ‘0.2.9’ saved [39880]

下载gdb-7.9.1.tar.gz

cd osdrv/tools/board/gdb/
wget http://ftp.gnu.org/gnu/gdb/gdb-7.9.1.tar.gz

下载ncurses-6.0.tar.gz

cd osdrv/tools/board/gdb/
wget http://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz

下载util-linux-2.31.tar.gz

osdrv/tools/pc/cramfs_tool/
wget https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.31/util-linux-2.31.tar.gz

编译:

 cd osdrv/
 make all

编译需要20多分钟,一次性编译通过,无错误。

operation complete,
489 objects in 2716 NAND pages.
/usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv
chmod 644 /usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv/pub/hi3516dv300_spi_smp_image_glibc/rootfs_hi3516dv300_4k_24bit.yaffs2
find /usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv/pub/rootfs_glibc/ -name '*svn' | xargs rm -rf
pushd /usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv/pub/rootfs_glibc; chmod +w usr/bin -R; chmod +w usr/sbin -R; chmod +w sbin -R; popd
/usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv/pub/rootfs_glibc /usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv
/usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv
pushd /usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv/pub;tar czf rootfs_glibc.tgz rootfs_glibc;rm rootfs_glibc -rf;popd
/usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv/pub /usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv
/usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv
---------finish osdrv work
dopi@ubuntu:/usr/dopi/dopi_dv300/Hi3516CV500_SDK_V2.0.2.0/package/osdrv$ 

研读Makefile

##########################################################################################
#    prepare param
##########################################################################################
export OSDRV_DIR=$(shell pwd)
export OSDRV_CROSS=arm-himix200-linux
export CHIP?=hi3516dv300
export ARCH=arm
export CROSS_COMPILE=$(OSDRV_CROSS)-
export OSDRV_CROSS_CFLAGS
MP_TYPE=smp
BOOT_MEDIA?=spi

ifneq ($(BOOT_MEDIA),spi)
ifneq ($(BOOT_MEDIA),emmc)
$(error you must set valid BOOT_MEDIA:spi or emmc!)
endif
endif
ifneq ($(MP_TYPE),smp)
#only support smp 
$(error you must set valid MP_TYPE:smp!)
endif
ifneq ($(CHIP),hi3516cv500)
ifneq ($(CHIP),hi3516dv300)
ifneq ($(CHIP),hi3516av300)
$(error you must set valid CHIP:hi3516dv300 、 hi3516av300 or hi3516cv500!)
endif
endif
endif
ifeq ($(OSDRV_CROSS), )
$(error you must set OSDRV_CROSS first!)
endif
ifeq ($(OSDRV_CROSS),arm-himix100-linux)
LIB_TYPE:=uclibc
BUSYBOX_CFG:=config_v100_a7_softfp_neon
TOOLCHAIN_DIR:=arm-himix100-linux
TOOLCHAINI_VERSION:=
RUNTIME_LIB:=runtime_uclibc
CROSS_SPECIFIED:=y
endif

ifeq ($(OSDRV_CROSS),arm-himix200-linux)
LIB_TYPE:=glibc
BUSYBOX_CFG:=config_v200_a7_softfp_neon
TOOLCHAIN_DIR:=arm-himix200-linux
TOOLCHAINI_VERSION:=
RUNTIME_LIB:=runtime_glibc
CROSS_SPECIFIED:=y
endif

BUSYBOX_VER:=busybox-1.26.2
TOOLCHAIN_RUNTIME_LIB_C:=lib.tgz

TOOLCHAIN_RUNTIME_LIB:=a7_softfp_neon-vfpv4
OSDRV_CROSS_CFLAGS:=-mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -w

UBOOT_VER:=u-boot-2016.11
UBOOT_TAR:=$(UBOOT_VER).tgz
UBOOT:=u-boot-$(CHIP).bin
UBOOT_REG_BIN:=reg_info_$(CHIP).bin
ifeq ($(BOOT_MEDIA),emmc)
export UBOOT_CONFIG:=$(CHIP)_$(BOOT_MEDIA)_config
else
export UBOOT_CONFIG:=$(CHIP)_config
endif

KERNEL_VER:=linux-4.9.y-$(MP_TYPE)
KERNEL_FULL_VER:=linux-4.9.37
KERNEL_TAR:=$(KERNEL_FULL_VER).tar.gz
KERNEL_PATCH:= $(KERNEL_FULL_VER).patch

UIMAGE:=uImage_$(CHIP)_$(MP_TYPE)
ifeq ($(BOOT_MEDIA),emmc)
export KERNEL_CFG:=$(CHIP)_$(BOOT_MEDIA)_$(MP_TYPE)_defconfig
else
export KERNEL_CFG:=$(CHIP)_$(MP_TYPE)_defconfig
endif
export PUB_IMAGE:=$(CHIP)_$(BOOT_MEDIA)_$(MP_TYPE)_image_$(LIB_TYPE)

EXT4_TOOL:=make_ext4fs
EXT4_IMAGE_BIN:=rootfs_$(CHIP)_96M.ext4
export PUB_BOARD:=board_$(LIB_TYPE)
export PUB_ROOTFS:=rootfs_$(LIB_TYPE)

JFFS2_IMAGE_BIN_64K:=rootfs_$(CHIP)_64k.jffs2
JFFS2_IMAGE_BIN_128K:=rootfs_$(CHIP)_128k.jffs2
JFFS2_IMAGE_BIN_256K:=rootfs_$(CHIP)_256k.jffs2

YAFFS2_PATCH:= hi_yaffs2utils.patch
YAFFS2_VER:= yaffs2utils-0.2.9
YAFFS2_TAR:=$(YAFFS2_VER).tar.gz
YAFFS_TOOL:=mkyaffs2image100
YAFFS2_IMAGE_BIN_2K_4BIT:=rootfs_$(CHIP)_2k_4bit.yaffs2
YAFFS2_IMAGE_BIN_2K_24BIT:=rootfs_$(CHIP)_2k_24bit.yaffs2
YAFFS2_IMAGE_BIN_4K_4BIT:=rootfs_$(CHIP)_4k_4bit.yaffs2
YAFFS2_IMAGE_BIN_4K_24BIT:=rootfs_$(CHIP)_4k_24bit.yaffs2

GDB_PATCH:= hi-gdb-7.9.1.patch
GDB_VER:= gdb-7.9.1
GDB_TAR:=$(GDB_VER).tar.gz
NCURSES_VER:= ncurses-6.0
NCURSES_TAR:=$(NCURSES_VER).tar.gz
CRAMFS_VER:= util-linux-2.31
CRAMFS_TAR:=$(CRAMFS_VER).tar.gz

HIREGBING_PACKAGE_VER:=hiregbin-v5.0.1
ifeq ($(TARGET_XLSM),)
ifeq ($(CHIP), hi3516dv300)
TARGET_XLSM:=Hi3516DV300-DMEBLITE_6L_T-DDR4_1800M_1GB_16bitx2-A7_900M-SYSBUS_300M.xlsm
endif
ifeq ($(CHIP), hi3516av300)
TARGET_XLSM:=Hi3516AV300-DMEB_4L_FLYBY-DDR3_2133M_512MB_16bitx2-A7_900M-SYSBUS_300M.xlsm
endif
ifeq ($(CHIP), hi3516cv500)
TARGET_XLSM:=Hi3516CV500-DMEB_4L-DDR3_1800M_256MB_16bit-A7_900M-SYSBUS_300M.xlsm
endif
endif

TOOLCHAIN_FILE:= $(shell which $(OSDRV_CROSS)-gcc )
TOOLCHAIN_DIR:=$(shell dirname $(shell dirname $(TOOLCHAIN_FILE)))
RUNTIMELIB_DIR=$(shell dirname $(TOOLCHAIN_DIR))/$(OSDRV_CROSS)/$(RUNTIME_LIB)
##########################################################################################
#    set task
##########################################################################################
ifeq ($(CROSS_SPECIFIED),y)
ifeq ($(MP_TYPE),amp)
all: prepare hiboot hikernel hiliteos hirootfs_prepare hiliteos_sample hibusybox \
    hipctools hiboardtools hiipcm hirootfs_build
clean: hiboot_clean hikernel_clean \
       hibusybox_clean hipctools_clean hiboardtools_clean hirootfs_clean hiipcm_clean hiliteos_dirclean
else
all: prepare hiboot hikernel hirootfs_prepare hibusybox \
    hipctools hiboardtools hirootfs_build
clean: hiboot_clean hikernel_clean \
       hibusybox_clean hipctools_clean hiboardtools_clean hirootfs_clean
endif
notools: hiboot hikernel hinotools_prepare hirootfs_notools_build
distclean:clean pub_clean
endif

a:=$(shell $(OSDRV_CROSS)-gcc --version)
b:=$(findstring $(TOOLCHAINI_VERSION),$(a))
c:= $(word 2, $(a))
##########################################################################################
#task [0]    prepare
##########################################################################################
prepare:
    mkdir $(OSDRV_DIR)/pub/$(PUB_IMAGE) -p
    mkdir $(OSDRV_DIR)/pub/bin/$(PUB_BOARD) -p
    mkdir $(OSDRV_DIR)/pub/bin/pc -p

##########################################################################################
#    prepare hiregbin tools
##########################################################################################
check_hiregbin:
HIREGBING_PACKAGE = $(shell find $(OSDRV_DIR)/tools/pc/uboot_tools/ \
                    -name "$(HIREGBING_PACKAGE_VER).tgz")
#$(warning $(HIREGBING_PACKAGE))

ifeq ($(HIREGBING_PACKAGE), )
$(warning "---------------------------------------------------------------------")
$(warning "     Cannot found the $(HIREGBING_PACKAGE_VER).tgz package !!                 ")
$(warning "---------------------------------------------------------------------")
$(error )
endif

##########################################################################################
#    hiregbin_prepare
##########################################################################################
hiregbin_prepare:
    @echo "---------task [0]    hiregbin_prepare"
    tar xzf $(HIREGBING_PACKAGE) -C $(OSDRV_DIR)/tools/pc/uboot_tools
    chmod 777 $(OSDRV_DIR)/tools/pc/uboot_tools/$(HIREGBING_PACKAGE_VER)/hiregbin
    cp $(OSDRV_DIR)/tools/pc/uboot_tools/$(TARGET_XLSM) $(OSDRV_DIR)/tools/pc/uboot_tools/$(HIREGBING_PACKAGE_VER)
    pushd $(OSDRV_DIR)/tools/pc/uboot_tools/$(HIREGBING_PACKAGE_VER);./hiregbin $(TARGET_XLSM) $(UBOOT_REG_BIN);popd
    mv $(OSDRV_DIR)/tools/pc/uboot_tools/$(HIREGBING_PACKAGE_VER)/$(UBOOT_REG_BIN) $(OSDRV_DIR)/tools/pc/uboot_tools
    rm $(OSDRV_DIR)/tools/pc/uboot_tools/$(HIREGBING_PACKAGE_VER) -rf

##########################################################################################
hinotools_prepare:
    pushd $(OSDRV_DIR)/pub;tar xzf $(PUB_ROOTFS).tgz;popd
##########################################################################################
#task [1]    build uboot
##########################################################################################
hiboot: prepare hiregbin_prepare
    @echo "---------task [1]    build boot"
    pushd $(OSDRV_DIR)/opensource/uboot;tar xzf secureboot_release.tgz -C .;popd
ifneq ($(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER), $(wildcard $(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER)))
    pushd $(OSDRV_DIR)/opensource/uboot;tar xzf $(UBOOT_TAR) -C .;popd
endif
    find $(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER) | xargs touch
    make -C $(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER) ARCH=arm CROSS_COMPILE=$(OSDRV_CROSS)- $(UBOOT_CONFIG)
    pushd $(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER);make ARCH=arm CROSS_COMPILE=$(OSDRV_CROSS)- -j 5 >/dev/null;popd
    make -C $(OSDRV_DIR)/tools/pc/hi_gzip/
    cp $(OSDRV_DIR)/tools/pc/hi_gzip/bin/gzip $(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER)/arch/arm/cpu/armv7/$(CHIP)/hw_compressed -rf
    chmod +x $(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER)/arch/arm/cpu/armv7/$(CHIP)/hw_compressed/gzip
    cp $(OSDRV_DIR)/tools/pc/uboot_tools/$(UBOOT_REG_BIN) $(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER)/.reg
    pushd $(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER);make ARCH=arm CROSS_COMPILE=$(OSDRV_CROSS)- u-boot-z.bin >/dev/null;popd
    cp $(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER)/u-boot-$(CHIP).bin $(OSDRV_DIR)/pub/$(PUB_IMAGE)
    cp $(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER)/u-boot-$(CHIP).bin  $(OSDRV_DIR)/opensource/uboot/secureboot_release

hiboot_clean:
    rm $(OSDRV_DIR)/opensource/uboot/$(UBOOT_VER) -rf
    rm $(OSDRV_DIR)/opensource/uboot/secureboot_release -rf
    rm $(OSDRV_DIR)/tools/pc/uboot_tools/$(UBOOT_REG_BIN) -rf
    make -C $(OSDRV_DIR)/tools/pc/hi_gzip/ clean
    rm -rf $(OSDRV_DIR)/tools/pc/uboot_tools/*.bin

##########################################################################################
#    check_package :kernel and yaffs2 source file
##########################################################################################
check_kernel:
PACKAGE=$(notdir $(wildcard $(OSDRV_DIR)/opensource/kernel/*.tar.xz))
ifeq ($(PACKAGE), $(KERNEL_TAR))
result=$(shell xz -d $(OSDRV_DIR)/opensource/kernel/$(PACKAGE)\
       && echo "pass" || "fail")
$(warning $(result))
endif
PACKAGE = $(shell find $(OSDRV_DIR)/opensource/kernel/ \
                    -name "$(KERNEL_FULL_VER).tar*")

ifeq ($(PACKAGE_YAFFS2), $(YAFFS2_TAR))
result=$(shell echo "pass" || "fail")
$(warning $(result))
endif
PACKAGE_YAFFS2 = $(shell find $(OSDRV_DIR)/tools/pc/mkyaffs2image/ \
                    -name "$(YAFFS2_TAR)")

ifeq ($(PACKAGE_GDB), $(GDB_TAR))
    result=$(shell echo "pass" || "fail")
    $(warning $(result))
endif

ifeq ($(PACKAGE_NCURSES), $(NCURSES_TAR))
    result=$(shell echo "pass" || "fail")
    $(warning $(result))
endif

ifeq ($(PACKAGE_CRAMFS), $(CRAMFS_TAR))
    result=$(shell echo "pass" || "fail")
    $(warning $(result))
endif

PACKAGE_GDB = $(shell find $(OSDRV_DIR)/tools/board/gdb/ -name "$(GDB_TAR)")
PACKAGE_NCURSES = $(shell find $(OSDRV_DIR)/tools/board/gdb/ -name "$(NCURSES_TAR)")
PACKAGE_CRAMFS = $(shell find $(OSDRV_DIR)/tools/pc/cramfs_tool/ -name "$(CRAMFS_TAR)")
ifeq ($(PACKAGE), )
$(warning "---------------------------------------------------------------------")
$(warning "     Cannot found the $(KERNEL_FULL_VER) kernel source file                ")
$(warning "  Please download the compression package to osdrv/opensource/kernel/")
$(warning "---------------------------------------------------------------------")
$(error )
endif

ifeq ($(PACKAGE_YAFFS2), )
$(warning "---------------------------------------------------------------------")
$(warning "     Cannot found the $(YAFFS2_TAR)  source file                        ")
$(warning "   Please download the compression package to osdrv/tools/pc/mkyaffs2image/")
$(warning "---------------------------------------------------------------------")
$(error )
endif

ifeq ($(PACKAGE_GDB), )
$(warning "---------------------------------------------------------------------")
$(warning "     Cannot found the $(GDB_TAR)  source file                        ")
$(warning "   Please download the compression package to osdrv/tools/board/gdb/ ")
$(warning "---------------------------------------------------------------------")
$(error )
endif

ifeq ($(PACKAGE_NCURSES), )
$(warning "---------------------------------------------------------------------")
$(warning "     Cannot found the $(NCURSES_TAR) source file                        ")
$(warning "   Please download the compression package to osdrv/tools/board/gdb/ ")
$(warning "---------------------------------------------------------------------")
$(error )
endif

ifeq ($(PACKAGE_CRAMFS), )
$(warning "---------------------------------------------------------------------")
$(warning "     Cannot found the $(CRAMFS_TAR) source file                        ")
$(warning "   Please download the compression package to osdrv/tools/pc/cramfs_tool/ ")
$(warning "---------------------------------------------------------------------")
$(error )
endif

##########################################################################################
#task [2]    build kernel
##########################################################################################
hikernel: prepare check_kernel
    @echo "---------task [2] build kernel"
    rm $(OSDRV_DIR)/opensource/kernel/$(KERNEL_VER) -rf
    tar xf $(PACKAGE) -C $(OSDRV_DIR)/opensource/kernel/
    mv $(OSDRV_DIR)/opensource/kernel/$(KERNEL_FULL_VER) $(OSDRV_DIR)/opensource/kernel/$(KERNEL_VER)
    pushd $(OSDRV_DIR)/opensource/kernel/$(KERNEL_VER);patch -p1 < ../$(KERNEL_PATCH);popd
    find $(OSDRV_DIR)/opensource/kernel/$(KERNEL_VER) | xargs touch
    make -C $(OSDRV_DIR)/opensource/kernel/$(KERNEL_VER) ARCH=arm CROSS_COMPILE=$(OSDRV_CROSS)- $(KERNEL_CFG)

    pushd $(OSDRV_DIR)/opensource/kernel/$(KERNEL_VER);\
        make ARCH=arm CROSS_COMPILE=$(OSDRV_CROSS)- uImage -j 2 >/dev/null;popd
    cp $(OSDRV_DIR)/opensource/kernel/$(KERNEL_VER)/arch/arm/boot/uImage $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(UIMAGE)

hikernel_clean:
    rm $(OSDRV_DIR)/opensource/kernel/$(KERNEL_VER) -rf

##########################################################################################
#task [3]    prepare rootfs
##########################################################################################
hirootfs_prepare: prepare
    @echo "---------task [3] prepare rootfs "
    rm $(OSDRV_DIR)/pub/$(PUB_ROOTFS)* -rf
    tar xzf $(OSDRV_DIR)/rootfs_scripts/rootfs.tgz -C $(OSDRV_DIR)/pub
    mv $(OSDRV_DIR)/pub/rootfs $(OSDRV_DIR)/pub/$(PUB_ROOTFS)
    tar xzf $(RUNTIMELIB_DIR)/$(TOOLCHAIN_RUNTIME_LIB)/$(TOOLCHAIN_RUNTIME_LIB_C) -C $(OSDRV_DIR)/pub/$(PUB_ROOTFS)
    pushd $(OSDRV_DIR)/pub/$(PUB_ROOTFS);$(CROSS_COMPILE)strip -d ./lib/*;popd

##########################################################################################
#task [4]    build busybox
##########################################################################################
hibusybox: prepare
    @echo "---------task [4] build busybox "
    rm $(OSDRV_DIR)/opensource/busybox/$(BUSYBOX_VER) -rf
    tar xzf $(OSDRV_DIR)/opensource/busybox/$(BUSYBOX_VER).tgz -C $(OSDRV_DIR)/opensource/busybox
    find $(OSDRV_DIR)/opensource/busybox/$(BUSYBOX_VER) | xargs touch
    cp $(OSDRV_DIR)/opensource/busybox/$(BUSYBOX_VER)/$(BUSYBOX_CFG) \
        $(OSDRV_DIR)/opensource/busybox/$(BUSYBOX_VER)/.config
    pushd $(OSDRV_DIR)/opensource/busybox/$(BUSYBOX_VER)/;make -j 20 >/dev/null;popd
    make -C $(OSDRV_DIR)/opensource/busybox/$(BUSYBOX_VER) install
    cp -af $(OSDRV_DIR)/opensource/busybox/$(BUSYBOX_VER)/_install/* $(OSDRV_DIR)/pub/$(PUB_ROOTFS)

hibusybox_clean:
    rm $(OSDRV_DIR)/opensource/busybox/$(BUSYBOX_VER) -rf

##########################################################################################
#task [5]    build pc tools
##########################################################################################
hipctools: prepare
    @echo "---------task [5] build tools which run on pc"
    tar xf $(PACKAGE_YAFFS2) -C $(OSDRV_DIR)/tools/pc/mkyaffs2image/
    pushd $(OSDRV_DIR)/tools/pc/mkyaffs2image/$(YAFFS2_VER);patch -p1 < ../$(YAFFS2_PATCH);popd
    find $(OSDRV_DIR)/tools/pc/mkyaffs2image/$(YAFFS2_VER) | xargs touch
    make -C $(OSDRV_DIR)/tools/pc/mkyaffs2image/
    cp $(OSDRV_DIR)/tools/pc/mkyaffs2image/bin/$(YAFFS_TOOL) $(OSDRV_DIR)/pub/bin/pc
    make -C $(OSDRV_DIR)/tools/pc/jffs2_tool/
    cp $(OSDRV_DIR)/tools/pc/jffs2_tool/mkfs.jffs2 $(OSDRV_DIR)/pub/bin/pc
    cp $(OSDRV_DIR)/tools/pc/jffs2_tool/mkfs.ubifs $(OSDRV_DIR)/pub/bin/pc
    cp $(OSDRV_DIR)/tools/pc/jffs2_tool/ubinize $(OSDRV_DIR)/pub/bin/pc
    make -C $(OSDRV_DIR)/tools/pc/cramfs_tool/
    cp $(OSDRV_DIR)/tools/pc/cramfs_tool/mkfs.cramfs $(OSDRV_DIR)/pub/bin/pc
    make -C $(OSDRV_DIR)/tools/pc/squashfs4.3/
    cp $(OSDRV_DIR)/tools/pc/squashfs4.3/mksquashfs $(OSDRV_DIR)/pub/bin/pc
    make -C $(OSDRV_DIR)/tools/pc/lzma_tool/
    cp $(OSDRV_DIR)/tools/pc/lzma_tool/lzma $(OSDRV_DIR)/pub/bin/pc
    make -C $(OSDRV_DIR)/tools/pc/ext4_utils/
    cp $(OSDRV_DIR)/tools/pc/ext4_utils/bin/$(EXT4_TOOL) $(OSDRV_DIR)/pub/bin/pc
    make -C $(OSDRV_DIR)/tools/pc/nand_production/fmc_nand_ecc_product_v100
    cp $(OSDRV_DIR)/tools/pc/nand_production/fmc_nand_ecc_product_v100/nand_product $(OSDRV_DIR)/pub/bin/pc

hipctools_clean:
    make -C $(OSDRV_DIR)/tools/pc/mkyaffs2image clean
    make -C $(OSDRV_DIR)/tools/pc/jffs2_tool distclean
    make -C $(OSDRV_DIR)/tools/pc/cramfs_tool distclean
    make -C $(OSDRV_DIR)/tools/pc/squashfs4.3 distclean
    make -C $(OSDRV_DIR)/tools/pc/lzma_tool distclean
    make -C $(OSDRV_DIR)/tools/pc/ext4_utils clean
    rm $(OSDRV_DIR)/tools/pc/uboot_tools/$(HIREGBING_PACKAGE_VER) -rf
    make -C $(OSDRV_DIR)/tools/pc/nand_production/fmc_nand_ecc_product_v100 clean

##########################################################################################
#task [6]    build board tools
##########################################################################################
hiboardtools: hirootfs_prepare hiboardtools_clean
    @echo "---------task [6] build tools which run on board "
    make -C $(OSDRV_DIR)/tools/board/e2fsprogs
    cp -af $(OSDRV_DIR)/tools/board/e2fsprogs/bin/* $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/bin
    make -C $(OSDRV_DIR)/tools/board/reg-tools-1.0.0
    cp -af $(OSDRV_DIR)/tools/board/reg-tools-1.0.0/bin/* $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/bin
    make -C $(OSDRV_DIR)/tools/board/eudev-3.2.7/
    cp -af $(OSDRV_DIR)/tools/board/eudev-3.2.7/rootfs/. $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/
    tar xf $(PACKAGE_GDB) -C $(OSDRV_DIR)/tools/board/gdb/
    pushd $(OSDRV_DIR)/tools/board/gdb/$(GDB_VER);patch -p1 < ../$(GDB_PATCH);popd
    find $(OSDRV_DIR)/tools/board/gdb/$(GDB_VER) | xargs touch
    make -C $(OSDRV_DIR)/tools/board/gdb
    cp $(OSDRV_DIR)/tools/board/gdb/gdb-$(OSDRV_CROSS) $(OSDRV_DIR)/pub/bin/$(PUB_BOARD)
    make -C $(OSDRV_DIR)/tools/board/mtd-utils/
    cp $(OSDRV_DIR)/tools/board/mtd-utils/bin/* $(OSDRV_DIR)/pub/bin/$(PUB_BOARD)
    cp $(OSDRV_DIR)/tools/board/reg-tools-1.0.0/bin/himm $(OSDRV_DIR)/pub/bin/$(PUB_BOARD)
    cp $(OSDRV_DIR)/tools/board/reg-tools-1.0.0/bin/himc $(OSDRV_DIR)/pub/bin/$(PUB_BOARD)
    cp $(OSDRV_DIR)/tools/board/reg-tools-1.0.0/bin/himd $(OSDRV_DIR)/pub/bin/$(PUB_BOARD)
    cp $(OSDRV_DIR)/tools/board/reg-tools-1.0.0/bin/himd.l $(OSDRV_DIR)/pub/bin/$(PUB_BOARD)

hiboardtools_clean:
    make -C $(OSDRV_DIR)/tools/board/e2fsprogs distclean
    make -C $(OSDRV_DIR)/tools/board/reg-tools-1.0.0 clean
    make -C $(OSDRV_DIR)/tools/board/eudev-3.2.7 clean
    make -C $(OSDRV_DIR)/tools/board/gdb distclean
    make -C $(OSDRV_DIR)/tools/board/mtd-utils distclean

##########################################################################################
#task [7]    build rootfs
##########################################################################################
hirootfs_build: hirootfs_prepare hibusybox hiboardtools  hipctools hirootfs_notools_build
hirootfs_notools_build:
    @echo "---------task [7] build rootfs"
    chmod 777 $(OSDRV_DIR)/pub/bin/$(PUB_BOARD)/*
    chmod 777 $(OSDRV_DIR)/pub/bin/pc/*
    rm $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/dev/* -rf
    rm $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/bin/himm -rf
    rm $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/bin/himc -rf
    rm $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/bin/himd -rf
    rm $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/bin/himd.l -rf
    pushd $(OSDRV_DIR)/pub/$(PUB_ROOTFS);ln -s sbin/init init;popd
    pushd $(OSDRV_DIR)/pub/$(PUB_ROOTFS); chmod 750 * -R; chmod 750 usr/* -R; popd
    pushd $(OSDRV_DIR)/pub/$(PUB_ROOTFS); chmod -w usr/bin -R; chmod -w usr/sbin -R; chmod -w sbin -R; popd

ifeq ($(BOOT_MEDIA),spi)
    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

    cp $(OSDRV_DIR)/tools/pc/ubi_sh/mkubiimg.sh $(OSDRV_DIR)/pub/$(PUB_IMAGE)
    chmod +x $(OSDRV_DIR)/pub/$(PUB_IMAGE)/mkubiimg.sh
    # build the pagesize = 2k, blocksize = 128k, part_size = 32M #
    pushd $(OSDRV_DIR)/pub/$(PUB_IMAGE);./mkubiimg.sh $(CHIP) 2k 128k $(OSDRV_DIR)/pub/$(PUB_ROOTFS) 32M $(OSDRV_DIR)/pub/bin/pc;popd
    # build the pagesize = 4k, blocksize = 256k, part_size = 50M #
    pushd $(OSDRV_DIR)/pub/$(PUB_IMAGE);./mkubiimg.sh $(CHIP) 4k 256k $(OSDRV_DIR)/pub/$(PUB_ROOTFS) 50M $(OSDRV_DIR)/pub/bin/pc;popd
    rm $(OSDRV_DIR)/pub/$(PUB_IMAGE)/mkubiimg.sh
endif
ifeq ($(BOOT_MEDIA),emmc)
    pushd $(OSDRV_DIR)/pub/bin/pc;./$(EXT4_TOOL) -l 96M -s $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(EXT4_IMAGE_BIN) $(OSDRV_DIR)/pub/$(PUB_ROOTFS);popd
endif
ifeq ($(BOOT_MEDIA),spi)
    pushd $(OSDRV_DIR)/pub/bin/pc;./$(YAFFS_TOOL) $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/ $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(YAFFS2_IMAGE_BIN_2K_4BIT) 1 2;popd
    chmod 644 $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(YAFFS2_IMAGE_BIN_2K_4BIT)
    pushd $(OSDRV_DIR)/pub/bin/pc;./$(YAFFS_TOOL) $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/ $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(YAFFS2_IMAGE_BIN_2K_24BIT) 1 4;popd
    chmod 644 $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(YAFFS2_IMAGE_BIN_2K_24BIT)
    pushd $(OSDRV_DIR)/pub/bin/pc;./$(YAFFS_TOOL) $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/ $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(YAFFS2_IMAGE_BIN_4K_4BIT) 2 2;popd
    chmod 644 $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(YAFFS2_IMAGE_BIN_4K_4BIT)
    pushd $(OSDRV_DIR)/pub/bin/pc;./$(YAFFS_TOOL) $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/ $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(YAFFS2_IMAGE_BIN_4K_24BIT) 2 4;popd
    chmod 644 $(OSDRV_DIR)/pub/$(PUB_IMAGE)/$(YAFFS2_IMAGE_BIN_4K_24BIT)
endif
    find $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/ -name '*svn' | xargs rm -rf
    pushd $(OSDRV_DIR)/pub/$(PUB_ROOTFS); chmod +w usr/bin -R; chmod +w usr/sbin -R; chmod +w sbin -R; popd
    pushd $(OSDRV_DIR)/pub;tar czf $(PUB_ROOTFS).tgz $(PUB_ROOTFS);rm $(PUB_ROOTFS) -rf;popd
    @echo "---------finish osdrv work"

hirootfs_clean:
ifeq ($(OSDRV_DIR)/pub/$(PUB_ROOTFS), $(wildcard $(OSDRV_DIR)/pub/$(PUB_ROOTFS)))
    pushd $(OSDRV_DIR)/pub/$(PUB_ROOTFS); chmod +w usr/bin -R; chmod +w usr/sbin -R; chmod +w sbin -R; popd
endif
    rm $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/ -rf

##########################################################################################
#task [9] ipcm build
##########################################################################################
# smp not support hiipcm
hiipcm:
    @echo -e $(INFO)"------- task [9] build ipcm"$(DONE)
    rm -rf  $(OSDRV_DIR)/components/ipcm/ipcm
    pushd $(OSDRV_DIR)/components/ipcm;tar xzf ipcm.tgz -C .;popd
    pushd  $(OSDRV_DIR)/components/ipcm/ipcm; make PLATFORM=$(CHIP) CFG=$(CHIP)_a7_liteos_config all; popd
    pushd  $(OSDRV_DIR)/components/ipcm/ipcm; make PLATFORM=$(CHIP) CFG=$(CHIP)_a7_linux_config all; popd
    cp $(OSDRV_DIR)/components/ipcm/ipcm/out/node_1/*.a $(OSDRV_DIR)/platform/liteos/out/$(CHIP)/lib
    cp $(OSDRV_DIR)/components/ipcm/ipcm/out/node_0/sharefs $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/bin
    cp $(OSDRV_DIR)/components/ipcm/ipcm/out/node_0/virt-tty $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/bin
    cp $(OSDRV_DIR)/components/ipcm/ipcm/out/node_0/*.ko $(OSDRV_DIR)/pub/$(PUB_ROOTFS)/komod
hiipcm_clean:
    rm -rf $(OSDRV_DIR)/components/ipcm/ipcm
##########################################################################################
#task [10]    clean pub
##########################################################################################
pub_clean:
    rm $(OSDRV_DIR)/pub/* -rf

##########################################################################################
#task [11]  a7 liteos build
##########################################################################################
# smp not support hiliteos
hiliteos: prepare
ifneq ($(OSDRV_DIR)/platform/liteos, $(wildcard $(OSDRV_DIR)/platform/liteos))
    pushd $(OSDRV_DIR)/platform;tar xzf liteos.tgz;popd
else
    @echo -e $(NOTE)"Attention:"$(DONE)
    @echo -e $(NOTE)"you should compile ipcm for new libs!"$(DONE)
endif
    pushd $(OSDRV_DIR)/platform/liteos;cp ./tools/build/config/$(CHIP)_defconfig .config;make -j 2 >/dev/null;popd

hiliteos_clean:
    make -C $(OSDRV_DIR)/platform/liteos clean
hiliteos_distclean:
    make -C $(OSDRV_DIR)/platform/liteos clean
hiliteos_dirclean:
    rm -rf $(OSDRV_DIR)/platform/liteos

##########################################################################################
#task [12]  a7 liteos sample.bin build
##########################################################################################
# smp not support hiliteos
hiliteos_sample: prepare hiliteos
    pushd $(OSDRV_DIR)/platform/liteos/sample/sample_osdrv; \
    make >/dev/null; \
    cp sample.bin $(OSDRV_DIR)/pub/$(PUB_IMAGE); \
    popd

hiliteos_sample_clean:
    make -C $(OSDRV_DIR)/platform/liteos/sample/sample_osdrv clean

烧录

还是老规矩,编译好的文件在pub文件下,拷贝出boot,uImange,rootfs后,用HiTool烧录。

注意,DV300在win10下无法识别,所以我们这里建议用串口烧录,此过程耗时很长。

烧录后修改uboot的bootargs和bootcmd

setenv  bootargs 'mem=256M console=tty0 console=ttyAMA0,115200 root=/dev/mtdblock2 rootfstype=jffs2 rw mtdparts=hi_sfc:1024K(boot),5120K(kernel),10240K(rootfs)'
setenv bootcmd  'sf probe 0;sf read 0x82000000 0x100000 0x400000;bootm 0x82000000'
saveenv

启动log:见到了久违的 Welcome to HiLinux.

NET: Registered protocol family 17
8021q: 802.1Q VLAN Support v1.8
Key type dns_resolver registered
Registering SWP/SWPB emulation handler
hibvt_rtc 12080000.rtc: setting system clock to 1970-01-01 00:10:42 UTC (642)
VFS: Mounted root (jffs2 filesystem) on device 31:2.
devtmpfs: mounted
Freeing unused kernel memory: 1024K (c0900000 - c0a00000)

            _ _ _ _ _ _ _ _ _ _ _ _
            \  _  _   _  _ _ ___
            / /__/ \ |_/
           / __   /  -  _ ___
          / /  / /  / /
  _ _ _ _/ /  /  \_/  \_ ______
___________\___\__________________

[RCS]: /etc/init.d/S00devs
mknod: /dev/console: File exists
mknod: /dev/ttyAMA0: File exists
mknod: /dev/null: File exists
[RCS]: /etc/init.d/S01udev
random: udevd: uninitialized urandom read (16 bytes read)
udevd[79]: starting eudev-3.2.7
[RCS]: /etc/init.d/S80network
Auto login as root ...
login[95]: root login on 'ttyS000'
Welcome to HiLinux.
None of nfsroot found in cmdline.
文档更新时间: 2020-11-11 15:08   作者:Tony