鸣涧 发表于 2022-7-27 16:36:35

Hi3518EV300芯片linux系统配置USB Camera功能

Hi3518EV300芯片linux系统配置USB Camera功能




一,安装好虚拟机VMware® Workstation 15 Pro 和Ubuntu16.04 64位版本;并且安装应用软件,配置好 NFS、 telnetd、 samba、 VIM等等工具;


二,SDK版本Hi3516EV200R001C01SPC012\01.software\board\Hi3516EV200_SDK_V1.0.1.2.tgz该文件就是 Hi3518E V300 的软件开发包,
1, 在 linux 服务器上(或者一台装有 linux 的 PC 上,主流的 linux 发行版本均可以),使用命令:tar -zxf Hi3516EV200_SDK_Vx.x.x.x.tgz,解压缩该文件,可以得到一个Hi3516EV200_SDK_Vx.x.x.x 目录。
2,返回 Hi3516EV200_SDK_Vx.x.x.x 目录,运行./sdk.unpack(请用 root 或 sudo 权限执行)将会展开 SDK 包打包压缩存放的内容,请按照提示完成操作。如果您需要通过 WINDOWS 操作系统中转拷贝 SDK 包,请先运行./sdk.cleanup,收起SDK 包的内容,拷贝到新的目录后再展开。

三,软件包的安装:
详见:“Hi3516EV200╱Hi3516EV300╱HI3518EV300╱Hi3516D V200 U-boot 移植应用开发指南.pdf”1.3.3章节;

四,安装交叉编译工具 arm-himix100-linux.tgz
1,安装 himix100 交叉编译器:
解压 tar –xzf arm-himix100-linux.tgz,运行 chmod +x arm-himix100-linux.install,然后运
行./arm-himix100-linux.install 即可。
2, 执行 source /etc/profile,安装交叉编译器的脚本配置的环境变量就可以生效了,或者请重新登陆也可。
重新生效的时候,颜色变成白色;

3,每个SDK有配套的编译工具链,编译器分uclibc和glibc版本,比如arm-hisiv300-linux为uclibc版本,对应的glibc版本为arm-hisiv400-linux;
4,如果要想看编译器支持哪些特性,可以通过arm-hisixxx-gcc –v 查看对应的GCC版本号,然后在GNU网站查看该版本的GCC支持的特性
arm-himix100-linux-gcc -v

5,如果不同芯片的SDK使用的工具链名称相同,那么该工具链可以通用,编译服务器上只需要安装一个最新版本即可。 比如Hi3536C 和Hi3536D 都使用arm-hisiv500-linux工具链,那么Hi3536C SDK带的hisiv500工具链也适用于Hi3536D;
五,编译OSDRV; 参见 osdrv 目录下 readme;
make OSDRV_CROSS=arm-himix100-linux CHIP=hi3518ev300 all

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

六,串口设置:Hi3518EV300 有个3pin的白色插座,依次是:TxD RXD GND 信号!推荐用 mobaXterm工具,波特率设置:115200;
注意下串口的电平为:LVCMOS3.3V,要用USB转串口的小板子,若是连接PC电脑的串口需要增加MAX232转换芯片才可以;


推荐用: 英国进口FR232RL芯片的串口小板子,一般价格在20元左右,质量很好,避免串口弄坏,损坏到主控Hi3518EV300板子!
七,固件烧录,Hi3518EV300芯片支持USB或者SD卡烧录;
1,介绍使用Hitool工具USB口单板烧录方法
Hitool工具安装:建议使用HiTool-BVT-5.0.60以上版本,详见SDK说明:
HiTool工具平台 使用指南.pdf
HiBurn 工具使用指南.pdf
确保Hitool工具正常运行,
HiMobileCam SDK安装使用说明(Huawei LiteOS).pdf 文章:5.2.1.2 USB 口烧写章节:

2,烧写准备 请下载Windows PC 上安装USB 驱动安装程序zadig.exe,此软件可从http://zadig.akeo.ie上下载。确保单板已连接串口和USB 线(请选用较短且质量好的USB 连接线)。
步骤 1 连接电源,单板上电;
步骤 2 请参照5.2.1.1 烧写并运行u-boot,按键进入uboot命令行;
步骤 3 uboot命令行中使用“usb device”命令,使单板进入usb 驱动待安装状态,见下图:

步骤 4 PC上打开zadig工具,勾选Options->List All Devices;

步骤 5 在下拉列表中选择新识别的usb设备“HiUSBBurn”;
步骤 6 请参考《HiBurn 工具使用指南》1.5节环境准备步骤7,依次安装好驱动LibusbK和
libusb-win32;

步骤 7 右键点击PC“计算机”,依次点击“管理”,“设备管理器”,观察设备驱动
libusbK USB Device –>HiUSBBurn是否安装成功;安装成功后如图5-3 所示。

3,镜像烧写:


八,设置环境参数
setenv bootargs ‘mem=32M console=ttyAMA0,115200 root=/dev/mtdblock2 rootfstype=jffs2 rw mtdparts=hi_sfc:1M(boot),4M(kernel),11M(rootfs)’
setenv bootcmd ‘sf probe 0;sf read 0x42000000 0x100000 0x400000;bootm 0x42000000’
sa

九,运行UVC业务,支持linux版本的;
1, 修改\Hi3516EV200_SDK_V1.0.1.2\mpp\sample\Makefile.param
海思SDK交付默认是imx307,但是单板sensor是sc2231,需要修改为:SENSOR0_TYPE ?= SMART_SC2231_MIPI_2M_30FPS_10BIT

2, 进入Hi3516EV200_SDK_V1.0.1.2\mpp\sample\uvc_app\Makefile.linux.param
修改为:UAC_COMPILE := y
详见该目录下readme.txt
最后,编译得到“uvc_app” “uvc_app.conf”
3, alsa安装和编译,详见alsa_readme.txt
最终将Ubuntu16.04 路径下/home/install/alsa-lib-1.1.7/lib/libasound.so.2 拷贝到Hi3518EV300单板/lib/
/home/audio/alsa/ 拷贝到Hi3518EV300单板/home/audio/alsa/
4, 内核下USB Device操作过程,修改内核kernel,生成uImage和USB摄像头相关的XXXX.Ko文件;
进入:Hi3516EV200_SDK_V1.0.1.2\osdrv\opensource\kernel\linux-4.9.y目录下,详见“外围设备驱动 操作指南.doc”文档;
A,输入:cp arch/arm/configs/hi3518ev300_full_defconfig .config #选择Hi3518EV300芯片配置;
B,然后:make ARCH=arm CROSS_COMPILE=arm-himix100-linux- menuconfig 进入menuconfig的如下路径,USB2.0 device 作为网口、串口、u盘、摄像头的配置如下


PHY选项

音频驱动配置选项

<> Sound card support —>
<> Advanced Linux Sound Architecture —>
[] USB sound devices (NEW) —>
<> USB Audio/MIDI driver

USB Gadget 功能选项

内核模块主要选项图

C,配置好,退出,记得保存;


D,输入:make ARCH=arm CROSS_COMPILE=arm-himix100-linux- uImage 在目录下arch/arm/boot/uImage生成kernel镜像 uImage;

E,输入:make ARCH=arm CROSS_COMPILE=arm-himix100-linux- modules 生成摄像头相关的驱动;
在目录linux-4.9.y\drivers\usb\gadget和 linux-4.9.y\drivers\usb\gadget\function 找到如下5个KO文件;
libcomposite.ko
usb_f_uvc.ko
u_audio.ko
usb_f_uac1.ko
usb_f_uac2.ko
5, 制作rootfs_uclibc_64k.jffs2烧录镜像;
A,回到第五步骤,编译OSDRV目录后,在\Hi3516EV200_SDK_V1.0.1.2\osdrv\pub目录下生成rootfs_uclibc.tgz压缩包,然后解压;

B,详见文档“外围设备驱动 操作指南.doc”2.3.8.2章节:进入rootfs_uclibc目录,创建root文件夹,拷贝USB2.0 device摄像头要的UVC_app、Ko、lib、脚本等,
mkdir root
chmod –R 777 root

C,修改KO目录下loadhi3518ev300脚本“SNS_TYPE0=sc2231;”

D,增加/etc/init.d/rcS
cd /root/
insmod libcomposite.ko
insmod usb_f_uvc.ko
insmod u_audio.ko
insmod usb_f_uac1.ko
insmod usb_f_uac2.ko
export VID=“0x12d1”
export PID=“0x4321”
export MANUFACTURER=“Huawei”
export PRODUCT=“HiCamera”
export SERIALNUMBER=“12345678”
export YUV=“360p”
export MJPEG=“360p 720p 1080p”
export H264=“360p 720p 1080p”
./ConfigUVC.sh
cd /root/ko
./load3518ev300 -a -sensor sc2231 -osmem 32M
cd /root/
./ uvc_app &

E, 拷贝01.software/pc/usb_tools/ConfigUVC.sh 文件;
F,现在需要把这个 Hi3516EV200_SDK_V1.0.1.2\osdrv\pub\rootfs_uclibc 目录下文件,做成rootfs_hi3518ev300_64k.jffs2 这个怎么弄? 才好烧录到Hi3518EV300的板子上;
进入Hi3516EV200_SDK_V1.0.1.2\osdrv\pub\bin\pc目录下,运行mkfs.jffs2工具,制作jffs2镜像,
./mkfs.jffs2 -d /home/samba/Hi3516EV200_SDK_V1.0.1.2/osdrv/pub/rootfs_uclibc -l -e 0x10000 –o
/home/samba/Hi3516EV200_SDK_V1.0.1.2/osdrv/pub/rootfs_uclibc_64k.jffs2 #这个2行是连在一起,注意中间空格#


十,烧录编译和制作好的 kernel和rootfs;

烧录完成后,设置启动参数;使用PotPlayer软件进行音视频捕获







附录一: 单板启动uart0启动消息;
System startup

Uncompress Ok!

U-Boot 2016.11 (May 07 2020 - 15:52:42 +0800)hi3518ev300

Relocation Offset is: 03735000
Relocating to 43f35000, new gd at 43e94ef0, sp at 43e94ed0
SPI Nor: hifmc_ip_ver_check(44): Check Flash Memory Controller v100 …hifmc_ip_ver_check(50): Found
hifmc_spi_nor_probe(1664): SPI Nor ID Table Version 1.0
hifmc_spi_nor_probe(1689): SPI Nor(cs 0) ID: 0xc2 0x20 0x19
hifmc_spi_nor_probe(1754): Block:64KB hifmc_spi_nor_probe(1755): Chip:32MB hifmc_spi_nor_probe(1756): Name:“MX25L(256/257)XX”
hifmc100_spi_nor_probe(147): SPI Nor total size: 32MB
NAND: 0 MiB
MMC:
In: serial
Out: serial
Err: serial
Net: No ethernet found.
Hit any key to stop autoboot: 0
device 0 offset 0x100000, size 0x400000

SF: 4194304 bytes @ 0x100000 Read: OK

Booting kernel from Legacy Image at 42000000 …
Image Name: Linux-4.9.37
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 3492936 Bytes = 3.3 MiB
Load Address: 40008000
Entry Point: 40008000
Loading Kernel Image … OK

Starting kernel …

Booting Linux on physical CPU 0x0
Linux version 4.9.37 (root@best) (gcc version 6.3.0 (HC&C V1R3C00SPC200B005_20190606) ) #5 Mon May 11 15:54:02 CST 2020
CPU: ARMv7 Processor revision 5 (ARMv7), cr=10c53c7d
CPU: div instructions available: patching division code
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
OF: fdt:Machine model: Hisilicon HI3518EV300 DEMO Board
Memory policy: Data cache writeback
CPU: All CPU(s) started in SVC mode.
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 8128
Kernel command line: mem=32M console=ttyAMA0,115200 root=/dev/mtdblock2 rootfstype=jffs2 rw mtdparts=hi_sfc:1M(boot),4M(kernel),11M(rootfs)
PID hash table entries: 128 (order: -3, 512 bytes)
Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
Memory: 25236K/32768K available (5188K kernel code, 195K rwdata, 1292K rodata, 180K init, 250K bss, 7532K reserved, 0K cma-reserved)
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
vmalloc : 0xc2800000 - 0xff800000 ( 976 MB)
lowmem : 0xc0000000 - 0xc2000000 ( 32 MB)
modules : 0xbf000000 - 0xc0000000 ( 16 MB)
.text : 0xc0008000 - 0xc0519368 (5189 kB)
.init : 0xc065f000 - 0xc068c000 ( 180 kB)
.data : 0xc068c000 - 0xc06bce20 ( 196 kB)
.bss : 0xc06be000 - 0xc06fca48 ( 251 kB)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:16 nr_irqs:16 16
Gic dist init…
arm_arch_timer: Architected cp15 timer(s) running at 50.00MHz (phys).
clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0xb8812736b, max_idle_ns: 440795202655 ns
sched_clock: 56 bits at 50MHz, resolution 20ns, wraps every 4398046511100ns
Switching to timer-based delay loop, resolution 20ns
clocksource: arm,sp804: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 637086815595 ns
Console: colour dummy device 80x30
Calibrating delay loop (skipped), value calculated using timer frequency… 100.00 BogoMIPS (lpj=500000)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
Setting up static identity map for 0x40008200 - 0x40008258
devtmpfs: initialized
VFP support v0.3: implementor 41 architecture 2 part 30 variant 7 rev 5
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 256 (order: -1, 3072 bytes)
pinctrl core: initialized pinctrl subsystem
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
Serial: AMBA PL011 UART driver
12040000.uart: ttyAMA0 at MMIO 0x12040000 (irq = 20, base_baud = 0) is a PL011 rev2
console enabled
SCSI subsystem initialized
ssp-pl022 12070000.spi: ARM PL022 driver, device ID: 0x00800022
ssp-pl022 12070000.spi: mapped registers from 0x12070000 to c2867000
ssp-pl022 12071000.spi: ARM PL022 driver, device ID: 0x00800022
ssp-pl022 12071000.spi: mapped registers from 0x12071000 to c286b000
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
Linux video capture interface: v2.00
Advanced Linux Sound Architecture Driver Initialized.
clocksource: Switched to clocksource arch_sys_counter
NET: Registered protocol family 2
TCP established hash table entries: 1024 (order: 0, 4096 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
workingset: timestamp_bits=30 max_order=13 bucket_order=0
NFS: Registering the id_resolver key type
Key type id_resolver registered
Key type id_legacy registered
jffs2: version 2.2 (NAND) (ZLIB) (RTIME) © 2001-2006 Red Hat, Inc.
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 252)
io scheduler noop registered
io scheduler deadline registered (default)
io scheduler cfq registered
pl061_gpio 120b0000.gpio_chip: PL061 GPIO chip @0x120b0000 registered
pl061_gpio 120b1000.gpio_chip: PL061 GPIO chip @0x120b1000 registered
pl061_gpio 120b2000.gpio_chip: PL061 GPIO chip @0x120b2000 registered
pl061_gpio 120b4000.gpio_chip: PL061 GPIO chip @0x120b4000 registered
pl061_gpio 120b5000.gpio_chip: PL061 GPIO chip @0x120b5000 registered
pl061_gpio 120b6000.gpio_chip: PL061 GPIO chip @0x120b6000 registered
pl061_gpio 120b7000.gpio_chip: PL061 GPIO chip @0x120b7000 registered
pl061_gpio 120b8000.gpio_chip: PL061 GPIO chip @0x120b8000 registered
brd: module loaded
hisi-sfc hisi_spi_nor.0: SPI Nor ID Table Version 1.2
hisi-sfc hisi_spi_nor.0: all blocks is unlocked.
hisi-sfc hisi_spi_nor.0: mx25l25635f (Chipsize 32 Mbytes, Blocksize 64KiB)
3 cmdlinepart partitions found on MTD device hi_sfc
3 cmdlinepart partitions found on MTD device hi_sfc
Creating 3 MTD partitions on “hi_sfc”:
0x000000000000-0x000000100000 : “boot”
0x000000100000-0x000000500000 : “kernel”
0x000000500000-0x000001000000 : “rootfs”
SPI Nand ID Table Version 2.7
Cannot found a valid SPI Nand Device
hisi_spi_nand_probe(175): Error: driver probe, result: -19
usbcore: registered new interface driver usb-storage
mousedev: PS/2 mouse device common for all mice
hibvt_rtc 120e0000.rtc: rtc core: registered 120e0000.rtc as rtc0
hibvt_rtc 120e0000.rtc: RTC driver for hibvt enabled
i2c /dev entries driver
hibvt-i2c 12060000.i2c: hibvt-i2c0@100000hz registered
hibvt-i2c 12061000.i2c: hibvt-i2c1@100000hz registered
hibvt-i2c 12062000.i2c: hibvt-i2c2@100000hz registered
uvcvideo: Unable to create debugfs directory
usbcore: registered new interface driver uvcvideo
USB Video Class driver (1.1.1)
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright© Pierre Ossman
sdhci-pltfm: SDHCI platform and OF driver helper
mmc0: SDHCI controller on 10010000.sdhci using ADMA in legacy mode
mmc1: SDHCI controller on 10020000.sdhci using ADMA in legacy mode
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
usbcore: registered new interface driver snd-usb-audio
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
Key type dns_resolver registered
hibvt_rtc 120e0000.rtc: setting system clock to 1970-01-01 04:12:32 UTC (15152)
ALSA device list:
No soundcards found.
VFS: Mounted root (jffs2 filesystem) on device 31:2.
devtmpfs: mounted
Freeing unused kernel memory: 180K (c065f000 - c068c000)
This architecture does not have kernel memory protection.
random: init: uninitialized urandom read (4 bytes read)

      _ _ _ _ _ _ _ _ _ _ _ _
      \__   __ _ ___
      / /__/ \ |_/
       / __   /-_ ___
      / // // /
_ _ _ / / / _/ _ ______
_________

mknod: /dev/console: File exists
mknod: /dev/ttyAMA0: File exists
mknod: /dev/null: File exists
RCS: /etc/init.d/S01udev
udevd: starting eudev-3.2.7
RCS: /etc/init.d/S80network
configfs-gadget gadget: uvc_function_bind
sh: 32M: bad number
mmz_start: 0x42000000, mmz_size: 32M
sys_config: loading out-of-tree module taints kernel.
==== online_flag=0, cmos_yuv_flag=0, sensor=sc2231, chip=hi3518ev300, board=demo====
==== g_quick_start_flag=0 ====
sysconfig init success!
Module himedia: init ok
Hisilicon Media Memory Zone Manager
hi_osal 1.0 init success!
hi3516ev200_base: module license ‘Proprietary’ taints kernel.
Disabling lock debugging due to kernel taint
load sys.ko for Hi3516EV200…OK!
load tde.ko for HI3516EV200…OK!
load region.ko for Hi3516EV200…OK!
load vgs.ko for Hi3516EV200…OK!
load vi.ko for Hi3516EV200…OK !
ISP Mod init!
load vpss.ko for Hi3516EV200…OK!
load vo.ko for Hi3516EV200…OK!
load hifb.ko OK!
load chnl.ko for Hi3516EV200…OK!
load vedu.ko for Hi3516EV200…OK!
load rc.ko for Hi3516EV200…OK!
load venc.ko for Hi3516EV200…OK!
load h264e.ko for Hi3516EV200…OK!
load h265e.ko for Hi3516EV200…OK!
load jpege.ko for Hi3516EV200…OK!
load ive.ko for Hi3516EV200…OK!
Load sensor_spi.ko for Hi3516EV200…OK !
insert audio
load mipi_rx driver successful!
pm init ok!
Auto login as root …
Jan 1 04:12:35 login: root login on ‘ttyS000’
Welcome to HiLinux.
None of nfsroot found in cmdline.
~ #
@@@@@ HiUVC App Sample @@@@@

configfs-gadget gadget: high-speed config #1: c
configfs-gadget gadget: uvc_function_set_alt(0, 0)
configfs-gadget gadget: reset UVC Control
configfs-gadget gadget: uvc_function_set_alt(1, 0)
configfs-gadget gadget: uvc_function_set_alt(1, 0)
configfs-gadget gadget: uvc_function_set_alt(1, 0)
random: fast init done
INFO:(uvc_events_process_data:1289):
set device format=MJPEG widconfigfs-gadget gadget: uvc_function_set_alt(1, 1)
configfs-gadget gadget: reset UVC
th=1920 height=1080
INFO:(uvc_events_process:1351): UVC_EVENT_STREAMON
-1854: support this chip 3518e300
-1854: support this chip 3518e300
-2098: ============= MipiDev 0, SetMipiAttr enWDRMode: 0
linear mode
=Smart Sc2231 27MInput 2lane 371.25Mbps 1080P30fps(MIPI) init success!===
-376: ISP Dev 0 running !
random: crng init done

页: [1]
查看完整版本: Hi3518EV300芯片linux系统配置USB Camera功能