dm368 ipnc3.0环境搭建脚本
前言
为了方便其他人搭建dm368 ipnc3.0环境,我写了个脚本,执行脚本就可以自动搭建好环境了,绝对的傻瓜操作了,不过有一个地方让我很郁闷,那就是在用sed替换掉某段内容的时候(143行--156行),替换的文本有很多行且里面某些行必须要tab开头(makefile要求,这里看不出,上传的问题),在我写的时候发现我必须把替换的内容靠在最左边,如果我想放到右边写,替换后内容就会包含左边的那些空格。放在最左边导致一点也不美观了,谁有更好的方法可以告诉我哈,先谢谢了! (注意:我的代码其实是有对齐的,放上来就全部都靠左了,看不出我上面说的sed的问题了,实际情况如下图:sed替换的内容放到了最左边, 但我想要把sed替换的内容的每行靠右些,与上面的对齐,不知道我描述清楚了没,呵呵。 还有,如果有人想用这个脚本的话,请自己再测试下,因为我怕上传导致某些tab啊空格啊变了,我不怎么写脚本,所以有些地方可能有更好的方法实现,希望大家提出来,一起学习下,谢谢!)
注: 内部有一些对特定文件的处理,主要是因为我的环境是fedora14,make的版本较高和我认为ipnc3.0原始文件里面有个别文件有些小bug及针对于我们自己的设备的一些小的修改。
#!/bin/sh
#this script is used for configuration of the dm368 3.0 ipnc environment ----rongp
#date: 2012/3/24
PID=$$
BashId=`pidof bash`
DEFAULT_INSTALL_PATH=/home/kez/dm368_3.0_ipnc
INSTALL_PATH=$DEFAULT_INSTALL_PATH
DEFAULT_MV_DIR=/opt/mv_pro_5.0
MV_DIR=$DEFAULT_MV_DIR
MVTOOL_DIR=$MV_DIR/montavista/pro/devkit/arm/v5t_le
function help() {
clear
echo -e "\
\n\n\nI'm assume that : \n\
\tThe default installation path is \"$DEFAULT_INSTALL_PATH\" \n\
and mvtool path is \"$MV_DIR\". if not, please input 'n' or \n\
'N' to exit and use -i option with installation Path or -m option \n\
with Mvtool path to try again! the partion of installtion path should \n\
have 2G can use and the partion of mvtool path should 2G can use.\n"
read -p "continue ?(Y[y]/N[n]): " Yn #-t 3
if [ "$Yn" == "Y" ] || [ "$Yn" == "y" ]; then
return 0
else
return 254
fi
}
function handler_input() {
unset OPTIND
local name=
local ret=0
while getopts "i:m:" name; do
case $name in
i)
INSTALL_PATH=$OPTARG
# echo "get option $INSTALL_PATH"
ret=$(($ret+1))
;;
m)
MV_DIR=$OPTARG
# echo "get option $MVTOOL_DIR"
ret=$(($ret+1))
;;
?)
echo "Input Error!!! Argument invalid!!!"
return 255 #means error occured
;;
esac
done
return $ret
}
function clean_package() {
find "$INSTALL_PATH" -name *.tar.gz | xargs -i rm -rf {} >/dev/null 2>&1
find "$INSTALL_PATH" -name *.bin | xargs -i rm -rf {} >/dev/null 2>&1
echo -e "clean *tar.gz ok, you can remove IPNC_RDK_DM36x_Release_3.0.0 \nfrom shared zone to other disk or partion to reduce virtual disk size"
}
function check_exec_method() {
for i in $BashId
do
if [ "$PID" == "$i" ]; then
PID=""
break;
fi
done
if [ "$PID" != "" ]; then
echo "Error!!! Usage: use source to excute the script, Don't use sh srcipt or ./srcipt!!!eg: source init.sh"
exit 1
fi
}
check_exec_method
handler_input $@
ret=$?
if [ "$ret" != "255" ]; then
help
ret=$?
fi
if [ $((ret)) -lt 250 ]; then
if [ "$INSTALL_PATH" == "$DEFAULT_INSTALL_PATH" ]; then
mkdir -p "$INSTALL_PATH" >/dev/null 2>&1
fi
if [ "$MV_DIR" == "$DEFAULT_MV_DIR" ]; then
mkdir -p "$MV_DIR" >/dev/null 2>&1
fi
[ ! -d "$INSTALL_PATH" ] || [ ! -d "$MV_DIR" ] && { ret=253; echo "Input Error!!! $INSTALL_PATH or $MVTOOL_DIR is not a Dir!!!"; }
fi
if [ $((ret)) -lt 250 ]; then
clear
echo "===================================================="
echo "Please wait, it will spend about 3-6 minutes!"
echo "Starting Decompress...Please wait!"
if [ ! -e "$MVTOOL_DIR" ];then
tar -zkxf Mvtool/mvltools5_0_0801921_update.tar.gz -C $MV_DIR
[ $? ] && echo "Decompress mvltools5_0_0801921_update.tar.gz Ok..."
tar -zkxf Mvtool/DaVinciLSP_02_10_00_14.tar.gz -C $MV_DIR
[ $? ] && echo "Decompress DaVinciLSP_02_10_00_14.tar.gz Ok..."
else
echo -e "echo $MVTOOL_DIR already exists, skip decompress Mvtool"
fi
tar -zkxf Private/PrivateTI_IPNC_DM36x_3.0.0.tar.gz -C $INSTALL_PATH
[ $? ] && echo "Decompress PrivateTI_IPNC_DM36x_3.0.0.tar.gz Ok..."
tar -zkxf Open/OpenSrc_IPNC_DM36x_3.0.0.tar.gz -C $INSTALL_PATH
[ $? ] && echo "Decompress OpenSrc_IPNC_DM36x_3.0.0.tar.gz Ok..."
tar -zkxf Appro/Appro_IPNC_DM36x_3.0.0.tar.gz -C $INSTALL_PATH
[ $? ] && echo "Decompress Appro_IPNC_DM36x_3.0.0.tar.gz Ok..."
cd $INSTALL_PATH >/dev/null
mkdir ipnc_psp
mkdir -p ipnc_rdk/tftp
mkdir -p ipnc_rdk/target
tar -zkxf $INSTALL_PATH/Application/src/dvsdk_ipnctools_dm36x_3.0.0.tar.gz -C $INSTALL_PATH
[ $? ] && echo "Decompress dvsdk_ipnctools_dm36x_3.0.0.tar.gz Ok..."
tar -zkxf $INSTALL_PATH/Application/src/lsp_ipnc_dm36x_3.0.0.tar.gz -C $INSTALL_PATH/ipnc_psp
[ $? ] && echo "Decompress lsp_ipnc_dm36x_3.0.0.tar.gz Ok..."
tar -zkxf $INSTALL_PATH/Utils/src/u-boot-1.3.4_ipnc_dm36x_2.0.0.tar.gz -C $INSTALL_PATH/ipnc_psp
[ $? ] && echo "Decompress u-boot-1.3.4_ipnc_dm36x_2.0.0.tar.gz Ok..."
ls $INSTALL_PATH/Application/src/ipnc_app_dm36x_* | xargs -i tar -zkxf {} -C $INSTALL_PATH/ipnc_rdk
[ $? ] && echo "Decompress ipnc_app_dm36x_* Ok..."
ls $INSTALL_PATH/Utils/filesys/* | xargs -i tar -zkxf {} -C $INSTALL_PATH/ipnc_rdk/target
[ $? ] && echo "Decompress filesys_ipnc_dm36x.tar.gz squashfs.tar.gz Ok..."
echo "Decompress Successed..."
cd - >/dev/null
chmod 777 -R $INSTALL_PATH/ipnc_rdk
cd $INSTALL_PATH/ipnc_rdk >/dev/null
sed -i 's/^id:5/id:3/g' target/filesys/etc/inittab
sed -i 's/\(cpu_mips [<=>]\{1,2\} \)150/\1145/g' ipnc_app/sys_server/src/checkPlatform.c
sed -in -e '/config %config:/,+2c\ \
config: scripts_basic outputmakefile FORCE \
$(Q)mkdir -p include/linux include/config \
$(Q)$(MAKE) $(build)=scripts/kconfig $@ \
%config: scripts_basic outputmakefile FORCE \
$(Q)mkdir -p include/linux include/config \
$(Q)$(MAKE) $(build)=scripts/kconfig $@' \
-e '/\/ %\/: prepare scripts FORCE/,+2c\ \
/: prepare scripts FORCE \
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \\\
$(build)=$(build-dir) \
%/: prepare scripts FORCE \
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \\\
$(build)=$(build-dir)' ../ipnc_psp/ti-davinci/Makefile
sed -i -e "s#\(MVTOOL_DIR.*:= \).*#\1$MVTOOL_DIR#" -e "s#\(IPNC_INSTALL_DIR.*:= \).*#\1$INSTALL_PATH#" Rules.make
sed -i '/^squashfs/{n;/.*/d;};' Makefile
read -p "If you want to clean some *tar.gz which are no need any more? (Y[y]/N[n]): " Yn
if [ "$Yn" == "Y" ] || [ "$Yn" == "y" ]; then
clean_package
fi
echo "export PATH=/opt/mv_pro_5.0/montavista/pro/devkit/arm/v5t_le/bin:/opt/mv_pro_5.0/montavista/pro/bin:/opt/mv_pro_5.0/montavista/common/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
echo -e "Enter $INSTALL_PATH/ipnc_rdk successed.\nyou can use \"make sysall\" to rebuild entire System."\
"\nand use \"make squashfs\" to copy File system to tftp folder."\
"\nother options you can refer to Users_Guide_IPNC_DM36x.pdf"
echo "======================================================"
fi
完!
2012年5月
毕业那两年在做嵌入式应用开发,主要是单片机和arm linux上的应用开发,后来又做了两年arm linux驱动开发,15年到现在在做pc端及嵌入式端开发,包括服务器系统裁剪、底层框架实现、硬件加速等。喜欢技术分享、交流!联系方式: 907882971@qq.com、rongpmcu@gmail.com