在hi3516a内核启动后的rcS文件中有一句调用:
./load3516a -i -sensor bt1120 -osmem 128 -offline
本文将对load3516a进行解析。
无私分享,从我做起!如有错误,还请指出!
Media Memory Zone
在解析load3516a前,需要了解一下mmz的知识,后面会有分配MMZ大小的参数。
如图所示,在海思平台上将内存分为两个部分:os内存和mmz内存。os内存指:由linux操作系统管理的内存;mmz内存:由mmz驱动模块进行管理供媒体业务单独使用的内存,在驱动加载时可以指定该模块管理内存的大小:
insmod mmz.ko mmz=anonymous,0,0x4fa00000,6Manony=1 || report_error
该驱动主要由两个文件组成:media-mem.c和mmz-userdev.c,加载驱动后相应的设备文件:/dev/mmz_userdev,应用层通过打开该设备文件进行ioctl(申请mmz内存、释放mmz内存、重映射mmz内存到内核等)和直接mmap操作,而媒体底层驱动模块则直接调用mmz驱动的导出接口进行相应操作。
#!/bin/sh
# Useage: ./load3516a [ -r|-i|-a ] [ sensor ]
# -r : rmmod all modules
# -i : insmod all modules
# default : rmmod all moules and then insmod them
#
# imx178 mn34220 imx185 ar0330 ov4689 ov5658 ar0230 imx117 ar0237
####################Variables Definition##########################
SNS_TYPE=mn34220 # sensor type
mem_total=512; # 512M, total mem
mem_start=0x80000000; # phy mem start
os_mem_size=64; # 64M, os mem
mmz_start=0x84000000; # mmz start addr
mmz_size=128M; # 128M, mmz size
//0x84000000-0x80000000=0x04000000,即64M;
//实际调用传入的参数是-osmem 128,故最终mmz_start=0x88000000
##################################################################
report_error()
{
echo "******* Error: There's something wrong, please check! *****"
exit 1
}
//加载音频所需的模块
insert_audio()
{
insmod acodec.ko
#insmod hidmac.ko
insmod hi3516a_aio.ko
insmod hi3516a_ai.ko
insmod hi3516a_ao.ko
insmod hi3516a_aenc.ko
insmod hi3516a_adec.ko
#insmod extdrv/tlv_320aic31.ko
#insmod extdrv/ak7756.ko
echo "insert audio"
}
// 卸载音频部分的模块
remove_audio()
{
#rmmod tlv_320aic31.ko
#rmmod ak7756.ko
rmmod hi3516a_adec
rmmod hi3516a_aenc
rmmod hi3516a_ao
rmmod hi3516a_ai
rmmod hi3516a_aio
rmmod acodec
echo "remove audio"
}
//加载传感器类型对应的模块,根据传感器类型来配置传感器对接的管脚
insert_sns()
{
case $SNS_TYPE in
ar0130|9m034)
himm 0x200f0050 0x2; # i2c0_scl
himm 0x200f0054 0x2; # i2c0_sda
;;
mt9p006)
himm 0x200f0050 0x2; # i2c0_scl
himm 0x200f0054 0x2; # i2c0_sda
himm 0x2003002c 0xE0007 # sensor unreset, clk 24MHz, VI 250MHz
;;
imx136)
himm 0x200f0050 0x1; # spi0_sclk
himm 0x200f0054 0x1; # spi0_sdo
himm 0x200f0058 0x1; # spi0_sdi
himm 0x200f005c 0x1; # spi0_csn
;;
imx123)
himm 0x200f0050 0x1; # spi0_sclk
himm 0x200f0054 0x1; # spi0_sdo
himm 0x200f0058 0x1; # spi0_sdi
himm 0x200f005c 0x1; # spi0_csn
#himm 0x2003002c 0xb0007 # sensor unreset, clk 27MHz, VI 250MHz
himm 0x2003002c 0x90007 # sensor unreset, clk 37.125MHz, VI 250MHz
himm 0x20030104 0x0; # VI 250MHz
insmod extdrv/sensor_spi.ko
;;
imx178)
himm 0x200f0050 0x2; # i2c0_scl
himm 0x200f0054 0x2; # i2c0_sda
himm 0x2003002c 0xF0007 # sensor unreset, clk 25MHz, VI 250MHz
#himm 0x2003002c 0x90007 # sensor unreset, clk 37.125MHz, VI 250MHz
;;
imx185)
himm 0x200f0050 0x1; # spi0_sclk
himm 0x200f0054 0x1; # spi0_sdo
himm 0x200f0058 0x1; # spi0_sdi
himm 0x200f005c 0x1; # spi0_csn
himm 0x2003002c 0x90007 # sensor unreset, clk 37.125MHz, VI 250MHz
insmod extdrv/sensor_spi.ko
;;
imx117)
himm 0x200f0050 0x1; # spi0_sclk
himm 0x200f0054 0x1; # spi0_sdo
himm 0x200f0058 0x1; # spi0_sdi
himm 0x200f005c 0x1; # spi0_csn
himm 0x200f00dc 0x1;
himm 0x200f00e0 0x1;
himm 0x20030038 0x6;
himm 0x20131020 0x30de8;
himm 0x20131024 0x30de5;
himm 0x2013102c 0x5;
himm 0x20131060 0xbf;
himm 0x20131064 0xbc;
himm 0x2013106c 0x5;
himm 0x2003002c 0x90007 # sensor unreset, clk 37.125MHz, VI 250MHz
insmod extdrv/sensor_spi.ko sensor=imx117
;;
mn34220)
himm 0x200f0050 0x2; # i2c0_scl
himm 0x200f0054 0x2; # i2c0_sda
himm 0x2003002c 0x90007 # sensor unreset, clk 37.125MHz, VI 250MHz
;;
ar0330)
himm 0x200f0050 0x2; # i2c0_scl
himm 0x200f0054 0x2; # i2c0_sda
himm 0x2003002c 0xE0007 # sensor unreset, clk 24MHz, VI 250MHz
;;
ov5658)
himm 0x200f0050 0x2; # i2c0_scl
himm 0x200f0054 0x2; # i2c0_sda
himm 0x2003002c 0xE0007 # sensor unreset, clk 24MHz, VI 250MHz
himm 0x20030104 0x0; # VI 250MHz
;;
ov4689)
himm 0x200f0050 0x2; # i2c0_scl
himm 0x200f0054 0x2; # i2c0_sda
himm 0x2003002c 0xE0007 # sensor unreset, clk 24MHz, VI 250MHz
himm 0x20030104 0x0;
;;
ar0230|ar0237)
himm 0x200f0050 0x2; # i2c0_scl
himm 0x200f0054 0x2; # i2c0_sda
himm 0x2003002c 0xB0007 # sensor unreset, clk 27MHz, VI 250MHz
;;
bt1120)
;;
*)
echo "xxxx Invalid sensor type $SNS_TYPE xxxx"
report_error
;;
esac
}
//卸载传感器对应的模块
remove_sns()
{
rmmod ssp &> /dev/null
rmmod sensor_spi &> /dev/null
rmmod ssp_pana &> /dev/null
}
//系统配置,包括管脚、时钟和系统配置三个脚本.sh文件
sys_config()
{
# pinmux configuration
sh pinmux_hi3516a.sh > /dev/null
# clock configuration
sh clkcfg_hi3516a.sh > /dev/null
# system configuration
sh sysctl_hi3516a.sh $b_arg_online > /dev/null
}
//加载所有的模块
insert_ko()
{
# sys config
sys_config;
# driver load
insmod mmz.ko mmz=anonymous,0,$mmz_start,$mmz_size anony=1 || report_error
insmod hi_media.ko
insmod hi3516a_base.ko
insmod hi3516a_sys.ko vi_vpss_online=$b_arg_online sensor=$SNS_TYPE
insmod hi3516a_tde.ko
insmod hi3516a_region.ko
insmod hi3516a_vgs.ko
insmod hi3516a_isp.ko
insmod hi3516a_viu.ko detect_err_frame=10;
insmod hi3516a_vpss.ko
insmod hi3516a_vou.ko lowPowerMode=0
#insmod hi3516a_vou.ko detectCycle=0 #close dac detect
insmod hifb.ko video="hifb:vram0_size:1620" # default pal
insmod hi3516a_rc.ko
insmod hi3516a_venc.ko
insmod hi3516a_chnl.ko
insmod hi3516a_h264e.ko
insmod hi3516a_h265e.ko
insmod hi3516a_jpege.ko
insmod hi3516a_vda.ko
insmod hi3516a_ive.ko
insmod extdrv/sensor_i2c.ko
insmod extdrv/pwm.ko
insmod extdrv/piris.ko
#insmod extdrv/adv_7441.ko
insmod extdrv/sil9024.ko norm=12 #1080P@30fps
echo "==== Your input Sensor type is $SNS_TYPE ===="
#insert_sns > /dev/null
insert_sns
insert_audio
echo "==== Your input Sensor type is $SNS_TYPE ===="
insmod hi_mipi.ko
#insmod hi3516a_pm.ko
}
//移除所有的模块
remove_ko()
{
#rmmod hi3516a_pm
remove_audio
remove_sns
rmmod sil9024 &> /dev/null
rmmod pwm
rmmod hi3516a_ive
rmmod hi3516a_vda
rmmod hi3516a_rc
rmmod hi3516a_jpege
rmmod hi3516a_h264e
rmmod hi3516a_h265e
rmmod hi3516a_chnl
rmmod hi3516a_venc
rmmod hifb
rmmod hi3516a_vou
rmmod hi3516a_vpss
rmmod hi3516a_viu
rmmod hi_mipi
rmmod ssp_ad9020
rmmod hi3516a_vgs
rmmod hi3516a_region
rmmod hi3516a_tde
rmmod sensor_i2c
rmmod piris
rmmod hi3516a_isp
rmmod hi3516a_sys
rmmod hi3516a_base
rmmod hi_media
rmmod mmz
}
//系统恢复
sys_restore()
{
####################################################
pinmux_hi3516a.sh > /dev/null
clkcfg_hi3516a.sh > /dev/null
# system configuration
sysctl_hi3516a.sh $b_arg_online > /dev/null
insert_sns;
}
load_usage()
{
echo "Usage: ./load3516a [-option] [sensor_name]"
echo "options:"
echo " -i insert modules"
echo " -r remove modules"
echo " -a remove modules first, then insert modules"
echo " -sensor sensor_name config sensor type [default: ar0130]"
echo " -osmem os_mem_size config os mem size [unit: M, default: 64]"
echo " -offline vi/vpss offline"
echo " -h help information"
echo -e "Available sensors: imx178, imx185, mn34220, etc"
echo -e "notes: osmem option can't be used when mmz zone partition is enable\n\n"
echo -e "for example online: ./load3516a -a -sensor imx178 -osmem 64\n"
echo -e " offline: ./load3516a -a -sensor imx178 -osmem 64 -offline\n"
}
//mmz内存大小计算
calc_mmz_info()
{
mmz_start=`echo "$mem_start $os_mem_size" |
awk 'BEGIN { temp = 0; }
{
temp = $1/1024/1024 + $2;
}
END { printf("0x%x00000\n", temp); }'`
mmz_size=`echo "$mem_total $os_mem_size" |
awk 'BEGIN { temp = 0; }
{
temp = $1 - $2;
}
END { printf("%dM\n", temp); }'`
echo "mmz_start: $mmz_start, mmz_size: $mmz_size"
}
//分析输入的参数,设置对应的变量
######################parse arg###################################
b_arg_os_mem=0
b_arg_sensor=0
b_arg_insmod=0
b_arg_remove=0
b_arg_online=1
b_arg_restore=0
for arg in $@
do
if [ $b_arg_os_mem -eq 1 ] ; then
b_arg_os_mem=0;
os_mem_size=$arg;
if [ -z $os_mem_size ]; then
echo "[error] os_mem_size is null"
exit;
fi
if [ $os_mem_size -ge $mem_total ] ; then
echo "[err] os_mem[$os_mem_size], over total_mem[$mem_total]"
exit;
fi
calc_mmz_info;
fi
if [ $b_arg_sensor -eq 1 ] ; then
b_arg_sensor=0
SNS_TYPE=$arg;
fi
case $arg in
"-i")
b_arg_insmod=1;
;;
"-r")
b_arg_remove=1;
;;
"-a")
b_arg_insmod=1;
b_arg_remove=1;
;;
"-h")
load_usage;
;;
"-sensor")
b_arg_sensor=1;
;;
"-osmem")
b_arg_os_mem=1;
;;
"-restore")
b_arg_restore=1;
;;
"-offline")
b_arg_online=0;
;;
esac
done
#######################parse arg end########################
//根据参数来执行最终的操作
#######################Action###############################
if [ $# -lt 1 ]; then
load_usage; //打印使用方法
exit 0;
fi
if [ $b_arg_remove -eq 1 ]; then
remove_ko; //移除所有模块
fi
if [ $b_arg_insmod -eq 1 ]; then // b_arg_insmod变量为1的话,执行加载所有模块的操作,其他的变量执行对应的操作
insert_ko;
fi
if [ $b_arg_restore -eq 1 ]; then
sys_restore; //系统恢复
fi
#!/bin/sh
# This is a sample, you should rewrite it according to your chip #
# You can configure your pinmux for the application here!
#VICAP default setting is VIU
vicap_pin_mux()
{
himm 0x200f0000 0x1 # 0: GPIO0_5, 1: SENSOR_CLK
himm 0x200f0004 0x1 # 1:FLASH_TRIG, 0: GPIO0_6, 2:SPI1_CSN1
himm 0x200f0008 0x1 # 1:SHUTTER_TRIG, 0:GPIO0_7, 2:SPI1_CSN2
}
i2c_pin_mux()
{
himm 0x200f0070 0x1; # i2c2_sda
himm 0x200f0074 0x1; # i2c2_scl
}
#BT1120
vo_bt1120_mode()
{
himm 0x200f000c 0x1; # vo clk
himm 0x200f0010 0x1; # vo DAT
himm 0x200f0014 0x1; # vo DAT
himm 0x200f0018 0x1; # vo DAT
himm 0x200f001c 0x1; # vo DAT
himm 0x200f0020 0x1; # vo DAT
himm 0x200f0024 0x1; # vo DAT
himm 0x200f0028 0x1; # vo DAT
himm 0x200f002c 0x1; # vo DAT
himm 0x200f0030 0x1; # vo DAT
himm 0x200f0034 0x1; # vo DAT
himm 0x200f0038 0x1; # vo DAT
himm 0x200f003c 0x1; # vo DAT
himm 0x200f0040 0x1; # vo DAT
himm 0x200f0044 0x1; # vo DAT
himm 0x200f0048 0x1; # vo DAT
himm 0x200f004c 0x1; # vo DAT
}
# just for test
jtag_pin_mux()
{
himm 0x200f0090 0x1; # JTAG_TRSTN
himm 0x200f0094 0x1; # JTAG_TCK
himm 0x200f0098 0x1; # JTAG_TMS
himm 0x200f009c 0x1; # JTAG_TDO
himm 0x200f00a0 0x1; # JTAG_TDI
}
# TEMPER_DQ
temper_pin_mux()
{
himm 0x200f00d8 0x0; # 2:TEMPER_DQ
himm 0x200f00dc 0x0; # 2:TEMPER_DQ
himm 0x200f00e0 0x0; # 2:TEMPER_DQ
himm 0x200f00e4 0x0; # 2:TEMPER_DQ
}
i2s_pin_mux()
{
himm 0x200f0088 0x2; # i2s0_bclk_rx
himm 0x200f008c 0x2; # i2s0_ws_rx
himm 0x200f0090 0x2; # i2s0_mclk
himm 0x200f0094 0x2; # i2s0_bclk_tx
himm 0x200f0098 0x2; # i2s0_ws_tx
himm 0x200f009c 0x2; # i2s0_sd_rx
himm 0x200f00a0 0x2; # i2s0_sd_tx
himm 0x200f00b0 0x2; # i2s1_mclk
himm 0x200f00b4 0x2; # i2s1_bclk_tx
himm 0x200f00b8 0x2; # i2s1_ws_tx
himm 0x200f00bc 0x2; # i2s1_sd_tx
himm 0x200f00c0 0x2; # i2s1_bclk_rx
himm 0x200f00c4 0x2; # i2s1_ws_rx
himm 0x200f00c8 0x2; # i2s1_sd_rx
himm 0x200f01ac 0x2; # i2s2_mclk
himm 0x200f01b0 0x2; # i2s2_bclk_tx
himm 0x200f01b4 0x2; # i2s2_ws_tx
himm 0x200f01b8 0x2; # i2s2_sd_tx
himm 0x200f01bc 0x2; # i2s2_bclk_rx
himm 0x200f01c0 0x2; # i2s2_ws_rx
himm 0x200f01c4 0x2; # i2s2_sd_rx
}
i2c_pin_mux;
vicap_pin_mux;
#i2s_pin_mux;
vo_bt1120_mode;
#!/bin/sh
# This is a sample, you should rewrite it according to your chip #
# You can configure your pinmux for the application here!
#VICAP default setting is VIU
vicap_pin_mux()
{
himm 0x200f0000 0x1 # 0: GPIO0_5, 1: SENSOR_CLK
himm 0x200f0004 0x1 # 1:FLASH_TRIG, 0: GPIO0_6, 2:SPI1_CSN1
himm 0x200f0008 0x1 # 1:SHUTTER_TRIG, 0:GPIO0_7, 2:SPI1_CSN2
}
i2c_pin_mux()
{
himm 0x200f0070 0x1; # i2c2_sda
himm 0x200f0074 0x1; # i2c2_scl
}
#BT1120
vo_bt1120_mode()
{
himm 0x200f000c 0x1; # vo clk
himm 0x200f0010 0x1; # vo DAT
himm 0x200f0014 0x1; # vo DAT
himm 0x200f0018 0x1; # vo DAT
himm 0x200f001c 0x1; # vo DAT
himm 0x200f0020 0x1; # vo DAT
himm 0x200f0024 0x1; # vo DAT
himm 0x200f0028 0x1; # vo DAT
himm 0x200f002c 0x1; # vo DAT
himm 0x200f0030 0x1; # vo DAT
himm 0x200f0034 0x1; # vo DAT
himm 0x200f0038 0x1; # vo DAT
himm 0x200f003c 0x1; # vo DAT
himm 0x200f0040 0x1; # vo DAT
himm 0x200f0044 0x1; # vo DAT
himm 0x200f0048 0x1; # vo DAT
himm 0x200f004c 0x1; # vo DAT
}
# just for test
jtag_pin_mux()
{
himm 0x200f0090 0x1; # JTAG_TRSTN
himm 0x200f0094 0x1; # JTAG_TCK
himm 0x200f0098 0x1; # JTAG_TMS
himm 0x200f009c 0x1; # JTAG_TDO
himm 0x200f00a0 0x1; # JTAG_TDI
}
# TEMPER_DQ
temper_pin_mux()
{
himm 0x200f00d8 0x0; # 2:TEMPER_DQ
himm 0x200f00dc 0x0; # 2:TEMPER_DQ
himm 0x200f00e0 0x0; # 2:TEMPER_DQ
himm 0x200f00e4 0x0; # 2:TEMPER_DQ
}
i2s_pin_mux()
{
himm 0x200f0088 0x2; # i2s0_bclk_rx
himm 0x200f008c 0x2; # i2s0_ws_rx
himm 0x200f0090 0x2; # i2s0_mclk
himm 0x200f0094 0x2; # i2s0_bclk_tx
himm 0x200f0098 0x2; # i2s0_ws_tx
himm 0x200f009c 0x2; # i2s0_sd_rx
himm 0x200f00a0 0x2; # i2s0_sd_tx
himm 0x200f00b0 0x2; # i2s1_mclk
himm 0x200f00b4 0x2; # i2s1_bclk_tx
himm 0x200f00b8 0x2; # i2s1_ws_tx
himm 0x200f00bc 0x2; # i2s1_sd_tx
himm 0x200f00c0 0x2; # i2s1_bclk_rx
himm 0x200f00c4 0x2; # i2s1_ws_rx
himm 0x200f00c8 0x2; # i2s1_sd_rx
himm 0x200f01ac 0x2; # i2s2_mclk
himm 0x200f01b0 0x2; # i2s2_bclk_tx
himm 0x200f01b4 0x2; # i2s2_ws_tx
himm 0x200f01b8 0x2; # i2s2_sd_tx
himm 0x200f01bc 0x2; # i2s2_bclk_rx
himm 0x200f01c0 0x2; # i2s2_ws_rx
himm 0x200f01c4 0x2; # i2s2_sd_rx
}
i2c_pin_mux;
vicap_pin_mux;
#i2s_pin_mux;
vo_bt1120_mode;
#!/bin/sh
# This is a sample, you should rewrite it according to your chip #
# mddrc pri&timeout setting
#########################################################################################
# param $1=1 --- online
# param $1=0 --- offline
vi_vpss_online_config()
{
# -------------vi vpss online open
if [ $b_vpss_online -eq 1 ]; then
echo "==============vi_vpss_online==============";
himm 0x20120004 0x40000000; # online, SPI1 CS0
#pri config
himm 0x20120058 0x26666400 # each module 4bit:vedu ddrt_md ive aio jpge tde vicap vdp
himm 0x2012005c 0x66666103 # each module 4bit:sfc_nand sfc_nor nfc sdio1 sdio0 a7 vpss vgs
himm 0x20120060 0x66266666 # each module 4bit:reserve reserve avc usb cipher dma2 dma1 gsf
#timeout config
himm 0x20120064 0x00000011 # each module 4bit:vedu ddrt_md ive aio jpge tde vicap vdp
himm 0x20120068 0x00000020 # each module 4bit:sfc_nand sfc_nor nfc sdio1 sdio0 a7 vpss vgs
himm 0x2012006c 0x00000000 # each module 4bit:reserve reserve avc usb cipher dma2 dma1 gsf
else
echo "==============vi_vpss_offline==============";
himm 0x20120004 0x0; # offline, mipi SPI1 CS0;
# pri config
himm 0x20120058 0x26666400 # each module 4bit:vedu ddrt_md ive aio jpge tde vicap vdp
himm 0x2012005c 0x66666112 # each module 4bit:sfc_nand sfc_nor nfc sdio1 sdio0 a7 vpss vgs
himm 0x20120060 0x66266666 # each module 4bit:reserve reserve avc usb cipher dma2 dma1 gsf
# timeout config
himm 0x20120064 0x00000011 # each module 4bit:vedu ddrt_md ive aio jpge tde vicap vdp
himm 0x20120068 0x00000000 # each module 4bit:sfc_nand sfc_nor nfc sdio1 sdio0 a7 vpss vgs
himm 0x2012006c 0x00000000 # each module 4bit:reserve reserve avc usb cipher dma2 dma1 gsf
fi
}
#########################################################################################
# msic config
himm 0x201200E0 0xd # internal codec,AIO MCLK out, CODEC AIO TX MCLK
#himm 0x201200E0 0xe # external codec: AIC31/AK7756,AIO MCLK out, CODEC AIO TX MCLK
echo "++++++++++++++++++++++++++++++++++++++++++++++"
b_vpss_online=1
if [ $# -ge 1 ]; then
b_vpss_online=$1
fi
vi_vpss_online_config;
#outstanding
cfg_outstanding()
{
himm 0x20580010 0x00003030 # VICAP outstanding r/w 3, rw
himm 0x205c0034 0x00000003 # VDP outstanding 3
himm 0x20600314 0x00000033 # VPSS outstanding[r0:3, w4:7]
#himm 0x2061002c 0x00444010 # TDE w:[24:21];r:[20:17];r[16:13]
himm 0x20620040 0x3 # AVC
himm 0x20640040 0x00000055 # VEDU
himm 0x206600A4 0x3 # JPEG
}