[Feature]add MT2731_MP2_MR2_SVN388 baseline version

Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/bach/build.bach/tools/project/fo_example.txt b/src/bach/build.bach/tools/project/fo_example.txt
new file mode 100644
index 0000000..fbde0e4
--- /dev/null
+++ b/src/bach/build.bach/tools/project/fo_example.txt
@@ -0,0 +1,13 @@
+
+# ----------------------------------------------------------------------------
+# # [NEW_FEATURE_NAME]                                   {#l1_new_feature_option}
+# ## description
+# > [NEW_FEATURE_NAME] is used to [FILL_IN_THE_FUNCTION].   \n
+#
+# value     | definition
+# :-------- | :--------------
+# VAL1      | DEF1
+# VAL2      | DEF2
+#
+# ## present value
+[NEW_FEATURE_NAME] = VAL1
diff --git a/src/bach/build.bach/tools/project/insert_paras.sh b/src/bach/build.bach/tools/project/insert_paras.sh
new file mode 100755
index 0000000..6201dbb
--- /dev/null
+++ b/src/bach/build.bach/tools/project/insert_paras.sh
@@ -0,0 +1,28 @@
+#/bin/bash
+
+insert_place=$1
+feature_info=$2
+
+function usage {
+	printf "./insert_paras.sh [INSERT_PLACE] [TXT_FILE_TO_INSERT] \n"
+	printf "[INSERT_PLACE]: The feature option that you want to insert after. \n"
+	printf "[TXT_FILE_TO_INSERT]: The paragraph that you want to insert for\
+	the new feature option.\n"
+}
+
+echo "Insert place: $1"
+echo "Inserted file: $2"
+
+if [ $# -ne 2 ]; then
+	echo "Wrong usage, it should be:"
+	usage
+	exit 1
+fi
+
+for entry in config/*
+do
+echo "Folder: $entry"
+sed -i "/$insert_place =/r $2" $entry/internal_feature_option
+done
+
+
diff --git a/src/bach/build.bach/tools/project/prj_crt.sh b/src/bach/build.bach/tools/project/prj_crt.sh
new file mode 100755
index 0000000..7588227
--- /dev/null
+++ b/src/bach/build.bach/tools/project/prj_crt.sh
@@ -0,0 +1,96 @@
+#!/bin/bash
+
+# usage: ./tools/backtrace/prj_crt.sh clone_prj new_prj"
+CLONE_PRJ=$1
+NEW_PRJ=$2
+# $3 is address list
+
+if [ "$#" -lt "2" ]; then
+    echo "Usage: $0 <clone project> <new project>"
+    exit
+fi
+
+RED_PAT="\033[37;41m"
+BLUE_PAT="\033[37;44m"
+YELLOW_PAT="\033[30;43m"
+RESET_PAT="\033[0m"
+
+# check firstly
+if [ ! -f "make/projects/${CLONE_PRJ}.prj" ] || [ ! -d "work/custom/${CLONE_PRJ}" ]; then
+    echo -e "${RED_PAT} Cannot find ${CLONE_PRJ} in project list!${RESET_PAT}"
+    exit
+fi
+
+# start to create project ...
+echo ""
+echo -e "Start to clone ${CLONE_PRJ} to ${NEW_PRJ}..."
+echo -e "Copy *.prj ..."
+rm -f make/projects/${NEW_PRJ}.prj
+cp -f make/projects/${CLONE_PRJ}.prj make/projects/${NEW_PRJ}.prj
+
+echo -e "Check rel mapping ..."
+relmap=`cat rel/mapping/prj_map | grep "${NEW_PRJ};"`
+if [ "$relmap" != "" ]; then
+    echo -e " ${BLUE_PAT}> Find in project mapping, no need to add new ... $result${RESET_PAT}"
+else
+    echo -e " ${RED_PAT}> Cannot find ${NEW_PRJ} in project mapping!${RESET_PAT}"
+    result=`cat rel/mapping/prj_map | grep "${CLONE_PRJ};"`
+    if [ "$result" != "" ]; then
+        echo -e " > try to clone one from ${CLONE_PRJ}"
+        relmap=`echo $result | sed "s/${CLONE_PRJ};/${NEW_PRJ};/g"`
+        echo -e " ${BLUE_PAT}> $relmap${RESET_PAT}"
+        echo $relmap >> rel/mapping/prj_map
+    else
+        echo -e " ${RED_PAT}> Still cannot find similar setting, please add manaually!${RESET_PAT}"
+        exit
+    fi
+fi
+
+echo -e "Clone rel folders ..."
+rm -fr rel/filter/${NEW_PRJ}
+cp -fr rel/filter/${CLONE_PRJ} rel/filter/${NEW_PRJ} 
+
+echo -e "Check internal feature option ..."
+BUILD_FDR=`cat work/custom/${CLONE_PRJ}/build/customer_feature_option | grep "INTERNAL_FEATURE_OPTION.*=" | grep "INTERNAL_FEATURE_OPTION.*=" | sed 's/.*\/\(build\..*\)\/config.*/\1/'`
+if [ "$BUILD_FDR" != "" ]; then
+    echo -e " ${BLUE_PAT}> Find $BUILD_FDR in cloned project ${CLOSE_PRJ}${RESET_PAT}"
+else
+    echo -e " ${RED_PAT}> Cannot find build.xxxx in cloned project!${RESET_PAT}"
+    exit
+fi
+
+echo -e "Clone internal feature option ..."
+rm -fr work/${BUILD_FDR}/config/${NEW_PRJ}
+cp -fr work/${BUILD_FDR}/config/${CLONE_PRJ} work/${BUILD_FDR}/config/${NEW_PRJ}
+
+echo -e "Clone custom folder ..."
+rm -fr work/custom/${NEW_PRJ}
+cp -fr work/custom/${CLONE_PRJ} work/custom/${NEW_PRJ}
+# replace the INTERNAL_FEATURE_OPTION
+sed -i "s/\/${CLONE_PRJ}\//\/${NEW_PRJ}\//g" work/custom/${NEW_PRJ}/build/customer_feature_option
+# check GPIO
+GPIO_FDR=work/custom/${NEW_PRJ}/gpio
+if [ -f "${GPIO_FDR}/${CLONE_PRJ}.csv" ]; then
+    # find GPIO file
+    echo -e " ${BLUE_PAT}> rename ${GPIO_FDR}/${CLONE_PRJ}.csv to ${GPIO_FDR}/${NEW_PRJ}.csv${RESET_PAT}"
+    mv ${GPIO_FDR}/${CLONE_PRJ}.csv ${GPIO_FDR}/${NEW_PRJ}.csv
+fi
+
+CFG=`echo $relmap | awk -F ';' '{print $2}'`
+SDK=`echo $relmap | awk -F ';' '{print $3}'`
+echo ""
+echo "----------------------------------------------------------"
+echo -e "${BLUE_PAT}${NEW_PRJ}${RESET_PAT} is cloned from ${CLONE_PRJ} done!"
+echo "Please check/modify and upload following files/folders/configurations ..."
+echo -e " ${YELLOW_PAT}> Config: ${CFG}"
+echo -e " ${YELLOW_PAT}> SDK: ${SDK}"
+echo -e " ${YELLOW_PAT}> make/${RESET_PAT}"
+mtk_repo status make
+echo -e " ${YELLOW_PAT}> rel/${RESET_PAT}"
+mtk_repo status rel
+echo -e " ${YELLOW_PAT}> work/${BUILD_FDR}/${RESET_PAT}"
+mtk_repo status work/${BUILD_FDR}
+echo -e " ${YELLOW_PAT}> work/custom/${RESET_PAT}"
+mtk_repo status work/custom
+echo "----------------------------------------------------------"
+echo ""
diff --git a/src/bach/build.bach/tools/project/replace_keyword.sh b/src/bach/build.bach/tools/project/replace_keyword.sh
new file mode 100644
index 0000000..68f8f99
--- /dev/null
+++ b/src/bach/build.bach/tools/project/replace_keyword.sh
@@ -0,0 +1,74 @@
+#usage: bash replace_keyword.sh [PROJECTS...], postfix 'prj' not needed
+#example: bash replace_keyword.sh MERCURY_FPGA_HOSTED
+cd ../../
+cp tools/project/replace_keyword.sh .
+
+declare -A rename_list replace_list 
+#module_list=(config make/projects tools build)
+#module_list=(work/slk work/lk work/linux-4.4 config work/base-files make/projects work/custom tools build work/bootloader_lte)
+#rename_list=([mercury]=mt6298 [MERCURY]=MT6298)
+#replace_list=([mercury]=mt6298 [MERCURY]=MT6298)
+#module_list+=(work/slk work/lk work/linux-4.4 config work/base-files make/projects work/custom tools build work/bootloader_lte work/busybox work/slk)
+module_list=(make work/mloader)
+rename_list=([mercury]=mt6298 [MERCURY]=MT6298)
+replace_list=([mercury]=mt6298 [MERCURY]=MT6298 [gen97p]=gen98 [GEN97P]=GEN98)
+
+# rename folders under $1 with naming $2 to $3
+function rename_folder {
+    retry=0
+    ret=0
+    echo -e "\033[0;32m"rename folders under $1 from $2 to $3 "\033[0m"
+    #retry for multiple matches, e.g., AAA/mercury/BBB/mercury/
+    while [ "$retry" != "5" ]; do 
+        find $1 -execdir rename "s/$2/$3/" '{}' \+
+        ret=$?
+        if [ "$ret" == "0" ]; then
+            break
+        fi
+        retry=$((retry + 1))
+        echo ret=$ret, retry=$retry
+    done
+}
+
+# replace all content under folder $1 from $2 to $3
+function replace_keyword {
+    echo -e "\033[0;32m"replace keyword $2 to $3 under folder $1"\033[0m"
+    grep -rl --exclude-dir=".git" $2 $1 | xargs sed -i "s/$2/$3/g"
+}
+
+function parse_module {
+    echo parse make/projects/$1.prj
+    module_list+=(`grep "p4:" make/projects/$1.prj | awk '{print "work/"$1}'`)
+}
+
+for proj in $@ ; do
+    parse_module "${proj}"
+done
+
+echo remove duplicate elements...
+sorted_module_list=($(echo "${module_list[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
+for module in "${!sorted_module_list[@]}"; do
+    for key in "${!rename_list[@]}"; do
+        rename_folder ${sorted_module_list[$module]} $key ${rename_list[$key]}
+    done
+    for key in "${!replace_list[@]}"; do
+        replace_keyword ${sorted_module_list[$module]} $key ${replace_list[$key]}
+    done
+done
+
+#uncomment to rollback
+: '
+for module in "${!sorted_module_list[@]}"; do
+    for key in "${!rename_list[@]}"; do
+        rename_folder ${sorted_module_list[$module]} ${rename_list[$key]} $key 
+    done
+    for key in "${!replace_list[@]}"; do
+        replace_keyword ${sorted_module_list[$module]} ${replace_list[$key]} $key 
+    done
+done
+'
+
+#replace old build script with modified ones
+cp build/* .
+#restore this script since it may also be modified
+mv replace_keyword.sh tools/project/.