`
收藏列表
标题 标签 来源
预置第三方应用的一种方式 编译
预置第三方应用的一种方式
1.讲需要预置的应用集成在特定路径下,比如:
vendor\xxx\3rd_apps\preload_3rd
在该目录下创建Android.mk,用于集成应用,分两种情况:
(1)只有APK文件,只需要将apk文件集成在如上的目录下,然后在Android.mk文件中集成即可,比如ALiPay.apk
在Android.mk中如下:
LOCAL_PATH := $(call my-dir)

#######################################################################
include $(CLEAR_VARS)
LOCAL_MODULE        := Paypal
LOCAL_MODULE_TAGS   := optional
LOCAL_MODULE_CLASS  := APPS
LOCAL_CERTIFICATE   := PRESIGNED
LOCAL_MODULE_SUFFIX := .apk
LOCAL_SRC_FILES     := Paypal.apk
LOCAL_MODULE_PATH   := $(PRODUCT_OUT)/system/vendor/operator/app
include $(BUILD_PREBUILT)
(2)对于除了APK还有对应的配置文件的应用,则需要建立对应得文件夹,放置apk文件和配置文件,比如meituan:
在文件夹下放置:aimeituan-kupai8-signed-aligned-051110.apk 和mtconfig.ini
#######################################################
include $(CLEAR_VARS)
LOCAL_MODULE        := meituan
LOCAL_MODULE_TAGS   := optional
LOCAL_MODULE_CLASS  := APPS
LOCAL_CERTIFICATE   := PRESIGNED
LOCAL_MODULE_SUFFIX := .apk
LOCAL_SRC_FILES     := meituan/aimeituan-kupai8-signed-aligned-051110.apk
LOCAL_MODULE_PATH   := $(PRODUCT_OUT)/system/vendor/operator/app
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE        := mtconfig.ini
LOCAL_MODULE_TAGS   := optional
LOCAL_MODULE_CLASS  := ETC
LOCAL_SRC_FILES     := meituan/mtconfig.ini
LOCAL_MODULE_PATH   := $(PRODUCT_OUT)/system/etc
include $(BUILD_PREBUILT)

比如baidusearch
#######################################################################
include $(CLEAR_VARS)
LOCAL_MODULE        := baidusearch
LOCAL_MODULE_TAGS   := optional
LOCAL_MODULE_CLASS  := APPS
LOCAL_CERTIFICATE   := PRESIGNED
LOCAL_MODULE_SUFFIX := .apk
LOCAL_SRC_FILES     := baidusearch/baidusearch_Android_1-0-45-164_1012933z.apk
LOCAL_MODULE_PATH   := $(PRODUCT_OUT)/system/vendor/operator/app
include $(BUILD_PREBUILT)
#注意文件路径不存在会执行失败,但不会报错
#$(shell mkdir -p $(TARGET_OUT)/lib)
#$(shell cp -rf $(LOCAL_PATH)/libBDoeminfo_baidusearch.so $(TARGET_OUT)/lib)
2.另外需要在特定的3rd_apps.mk或者3rd_apps_oversea.mk文件中添加需要集成的apk,否则在编译的时候不会install,
ifneq ($(filter S01, $(CARR_REG)),)
PRODUCT_PACKAGES += \
   Paypal \
   Musicone \
   Mobileofficeplus \
   Myaccount \
   Mytvsuper \
   WiFiConcierge
else
PRODUCT_PACKAGES += \
   Paypal
endif
3.上面提到的mk文件的调用如下的msm8952_region.mk中
ifneq ($(filter C00, $(CARR_REG)),)
$(call inherit-product, vendor/xxx/3rd_apps/3rd_apps.mk)
else
$(call inherit-product, vendor/xxx/3rd_apps/3rd_apps_oversea.mk)
$(call inherit-product-if-exists, vendor/google/products/gms.mk)
endif
$(call inherit-product-if-exists, vendor/xxx/prebuild/ukl_prebuild_module.mk)
4.而上述的msm8952_region.mk的调用如下:
./device/qcom/msm8952_64/msm8952_64.mk:30:$(call inherit-product, vendor/xxx/3rd_apps/msm8952_region.mk)
5.msm8952_64.mk的调用如下
./device/qcom/msm8952_64/AndroidProducts.mk:2:    $(LOCAL_DIR)/msm8952_64.mk
PRODUCT_MAKEFILES := \
    $(LOCAL_DIR)/msm8952_64.mk
Android 7.0 jackserver 编译报错 编译
jackserver编译错误
1、修改~/.jack-settings中的SERVER_PORT_SERVICE跟SERVER_PORT_ADMIN端口号
2、开始编译,编译错误后生成~/.jack-server/config.properties,修改该配置文件中的jack.server.service.port跟jack.server.admin.port,数值与1相同
3、修改prebuilts/sdk/tools/jack-admin,在JACK_SERVER_VM_ARGUMENTS行的最后大括号前添加-Xmx4096M,修改SERVER_PORT_SERVICE跟SERVER_PORT_ADMIN的值,跟1相同
4、编译
MTK平台SimLock功能的recovery模式下实现总结 recovery
MTK平台SimLock功能的recovery模式下实现总结
在介绍SimLock功能的recovery模式实现前,我们先来说明两个问题:第一就是SimLock的功能具体是含义;第二就是系统负责recovery模式下主要实现那些功能。
简单来说,SimLock功能主要是:手机在开机后检测到的sim卡如果是本运营商发放的,那么手机就正常开机使用,如果是非本运营商发放的手机卡,那么开机后将无法正常起网使用,除非经过本运营商授权并提供解锁密码。这样运营商就会提高自己与其他运营商的用户量的竞争。
系统负责的recovery模式的实现的功能主要是:在recovery模式下解析由运营商提供的Config.dat文件。该文件内存储了手机的开机密码且密码与手机的IMEI一一对应,还有运营商的MCCMNC。具体实现就是在当手机进入recovery模式时,我们选择Sim Lock选项,会从外置Sd卡下面读取Config.dat文件,该文件中存储了手机的IMEI号与MCCMNC,然后在从宇龙参数分区内读取本手机的IMEI号,且与Config.dat文件中的IMEI号进行比对,如果两个IMEI号匹配成功,则会生成解锁密码;否则匹配失败,功能停止。如果两个IMEI号匹配成功后,会上生成的密码写入/persist/simlock/unlock中,将MCCMNC写入到/persist/simlock/numerics中,具体如图1所示。
 
图1 Recovery模式下解析秘钥过程
上层会读取这两个文件中的值,完成SimLock的主要逻辑。接下来我们就recovery模式下具体功能,总结实现的具体过程以及遇到问题。
一.	具体功能实现过程
1.	在recovery模式下增加菜单选项
我们首先需要添加操作的入口,即需要在device.cpp与文件device.h文件中完成。
另外SINLock功能只是针对部分欧洲运营商,因此不能所有产品都添加SIMLock功能,所以需要通过在product_feature中增加客制话的属性FEATURE_TCCM_OEM_CUSTOMIZATION来控制,此外还需要添加对应的入口函数,在device.h中声明。

device.cpp:
#include "device.h"
/* yulong begin, add */
/* include yulong feature, yebiqing, 20160317 */
#include <product/YulongFeature.h>
/* yulong end */

static const char* MENU_ITEMS[] = {
   "Reboot system now",
    ………
    /* yulong begin, add */
    /* for write SIM Lock info ,requirement from tccm, liucaifei, 20160704*/
    #if FEATURE_TCCM_OEM_CUSTOMIZATION == 1
    "SIM Lock",
    #endif
/* yulong end */
………
null
};

device.h:
enum BuiltinAction { ……..
         /* yulong begin, add */
         /* for write SIM Lock info ,requirement from tccm, sunliang, 20160317*/
         #if FEATURE_TCCM_OEM_CUSTOMIZATION == 1
           , WRITE_SIMLOCK_INFO
         #endif
         /*yulong end*/
         };

platform_features
# add for simlock by liucaifei
FEATURE_TCCM_OEM_CUSTOMIZATION = false

product_features
# add for simlock by liucaifei
FEATURE_TCCM_OEM_CUSTOMIZATION = ture
2.	Config.dat文件解析及存储
进入static int write_simlock(Device* device)入口函数后,首先查找并加载存储在SdCard上的Config.dat文件,该过程是在lookup_dat_file(const char* path, Device* device)接口内实现,然后会执行static int get_deviceIMEI(char* str_IMEI1,char* str_IMEI2),在该接口函数内完成了获取本设备IMEI1和IMEI2的过程,最后,我们会根据IMEI1进行匹配之前解析的Config.dat文件,将查询到的unlock code存储在/persist/simlock/unlock路径下,此外,会继续解析Configuration Tool中输入的numeric_code(mccmnc),由于可能在Configuration Tool中输入多个mccmnc(针对解决此类一网多号设计),因此需要将解析到的所有mccmnc存储至/persist/simlock/numerics路径下,后续Framework会查询匹配这些参数,下面是详细的解析过程。
recovery.cpp:
while( read(config_dat_fd, buf, CONTENT_OFFSET)){
        if ( buf[0] == 0x17 && buf[1] == 0x00 ){
            ret = read(config_dat_fd, buf, LEN_IMEI);
            buf[ret] = '\0';
            printf("readed IMEI %s \n", buf);
            if (0 == strncmp(str_IMEI1, buf, LEN_IMEI)) {
                matched = 1;
                ui->Print("current IMEI matched.\n");
                ret = read(config_dat_fd, buf, LEN_ACTIVIATION);
                buf[ret] = '\0';
                strncpy(activation_code, buf, ret);
                ui->Print("current activation code is %s \n", activation_code);
            }else{
                ret = read(config_dat_fd, buf, LEN_ACTIVIATION);
                buf[ret] = '\0';
            }
            printf("readed activation code is %s \n", buf);
        }else{
            if(!matched){
                ui->Print("IMEI %s not matched.\n",str_IMEI1);
                ui->Print("Failed to write SIMLOCK information.\n");
                close(config_dat_fd);
                return -1;
            }
            while( ret = read(config_dat_fd, buf, LEN_NUMERIC)){
                strncpy(numeric_code, buf, ret);
                ui->Print("current numeric code is %s \n", numeric_code);
            }
            break;
        }
    }
if(matched){
        ensure_path_mounted(PERSIST_PATH);
        unlock_fd = open(SIMLOCK_UNLOCK_FILE, O_RDWR|O_CREAT, 0644);
        if (unlock_fd < 0) {
            ui->Print("open SIMLOCK_UNLOCK_FILE failed, (%s).\n", strerror(errno));
            return -1;
        }
        ret = write(unlock_fd, activation_code, strlen(activation_code));
        if (ret <= 0) {
            ui->Print("failed to write target activation code.\n");
            close(unlock_fd);
            return -1;
        }else{
            ui->Print("target activation code is %s \n", activation_code);
        }
        close(unlock_fd);
        chmod(SIMLOCK_UNLOCK_FILE, 0644);
        sync();
        numeric_fd = open(SIMLOCK_NUMERIC_FILE, O_RDWR|O_CREAT, 0644);
        if (numeric_fd < 0) {
            ui->Print("open SIMLOCK_NUMERIC_FILE failed.\n");
            return -1;
        }

        ret = write(numeric_fd, numeric_code, strlen(numeric_code));
        if (ret <= 0) {
            ui->Print("failed to write target numeric code.\n");
            close(numeric_fd);
            return -1;
        }else{
            ui->Print("target numeric code is %s\n", numeric_code);
        }
        close(numeric_fd);
        chmod(SIMLOCK_NUMERIC_FILE, 0644);
        sync();
        ensure_path_unmounted(PERSIST_PATH);
    }

    ensure_path_unmounted(SDCARD_ROOT);
ui->Print("Write SIMLOCK information successfully.\n");

具体的修改活动如下:
二.	实现过程中遇到的问题
1.	persist分区的挂载问题
在recovery模式下需要将解析的解锁密码和MCCMNC存储到/persist/simlock/unlock和/persist/simlock/numerics下,并且在正常模式下读取这两个文件的值,供上层应用。因此,系统需要在recovery模式和正常模式都挂载persist分区。
1.1问题的确认
确定底层已经打开persist分区:
root@CPY83_U00:/dev/block/platform/mtk-msdc.0/11230000.msdc0/by-name #ls –l
lrwxrwxrwx root     root    2016-01-01 20:07 persist -> /dev/block/mmcblk0p21
在projectConfig.mk文件中打开persist相关宏:
MTK_PERSIST_PARTITION_SUPPORT = yes
在recovery.fstab中添加recovery模式下的挂载:
  /persist    ext4        /dev/block/mmcblk0p21
利用mount命令显示:未挂载persist分区:
1.2 问题分析
确认修改是否成功:
root@CPY83_U00:/ # cat fstab.mt6735
/dev/block/platform/mtk-msdc.0/11230000.msdc0/by-name/persist /persist ext4 noatime,nosuid,nodev,noauto_da_alloc,commit=1,nodelalloc wait,check,formattable
有挂载信息,证明在projectConfig.mk文件中打开的宏起作用
日志分析:
在recovery模式下的last_log打印出的日志为:
readed activation code is 27018334 
current numeric code is 46000F46002F 
E:failed to mount /persist (Invalid argument)
open SIMLOCK_UNLOCK_FILE failed.
这日志是从\bootable\recovery\root.cpp文件中ensure_path_mounted函数打印出来的:
int ensure_path_mounted(const char* path) {
    ………
		
    } else if (strcmp(v->fs_type, "ext4") == 0 ||
               strcmp(v->fs_type, "squashfs") == 0 ||
               strcmp(v->fs_type, "vfat") == 0) {
				   
        mt_ensure_dev_ready(v->mount_point);
        result = mount(v->blk_device, v->mount_point, v->fs_type,
                       v->flags, v->fs_options);
        if (result == 0) {
            goto mount_done;
        } else {
            result = mt_ensure_path_mounted(v);
            if (result == 0)
                goto mount_done;
        }
        LOGE("failed to mount %s (%s)\n", v->mount_point, strerror(errno));
        return -1;
    }
     ………
  }
进一步分析日志,发现在dumpstate.txt日志中有这样的权限问题:
14>[    6.426141] .(0)[190:init]fs_mgr: __mount(source=/dev/block/platform/mtk-msdc.0/11230000.msdc0/by-name/persist,target=/persist,type=ext4)=-1
<11>[    6.428161] .(0)[190:init]fs_mgr: Failed to mount an un-encryptable or wiped partition on/dev/block/platform/mtk-msdc.0/11230000.msdc0/by-name/persist at /persist options: noauto_da_alloc,commit=1,nodelalloc error: Invalid argument
猜测和权限有关,进一步在该日志中发现:
14>[    6.377590] .(0)[190:init]fs_mgr: check_fs(): mount(/dev/block/platform/mtk-msdc.0/11230000.msdc0/by-name/persist,/persist,ext4)=-1: Invalid argument

<14>[    6.379324] .(0)[190:init]fs_mgr: Running /system/bin/e2fsck on /dev/block/platform/mtk-msdc.0/11230000.msdc0/by-name/persist

<5>[    6.396816] .(0)[230:e2fsck]audit: type=1400 audit(1262447888.830:4): avc:  denied  { open } for  pid=230 comm="e2fsck" path="/dev/block/mmcblk0p21" dev="tmpfs" ino=7137 scontext=u:r:fsck:s0 tcontext=u:object_r:persist_block_device:s0 tclass=blk_file permissive=0
因此,可以确定persist分区挂载后的设备没有open权限。我们在MTK\yulong\device\mediatek\common\sepolicy\fsck.te文件中添加open权限
allow fsck persist_block_device:blk_file { open read write getattr ioctl };
1.3.编译版本,利用mount命令查看persist分区挂载成功
C:\Users\liucaifei>adb shell
…….
/dev/block/platform/mtk-msdc.0/11230000.msdc0/by-name/persist /persist ext4 rw,seclabel,nosuid,nodev,noatime,nodelalloc,noauto_da_alloc,comm
it=1,data=ordered 0 0
2.	persist根目录及其子目录文件无法访问问题
2.1 问题确认
首先确认persist分区已经挂载到/persist节点:
root@CPY83_U00:/ # mount
/dev/block/platform/mtk-msdc.0/11230000.msdc0/by-name/persist /persist ext4 rw,seclabel,nosuid,nodev,noatime,nodelalloc,noauto_da_alloc,commit=1,data=ordered 0 0
在init.mt6735.rc和init.recovery.mt6735.rc中增加创建挂载点下的目录:
#yulong add for simlock requirement of TCCM by liucaifei,20170719
 mkdir /persist/simlock  0760 radio radio
 chmod 0760         /persist/simlock/unlock
 chown radio radio  /persist/simlock/unlock
 chmod 0760         /persist/simlock/numerics
 chown radio radio  /persist/simlock/numerics
 #yulong end
cat查看挂载点下的两个文件可以访问:
root@CPY83_U00:/persist/simlock # ls
numerics
unlock
root@CPY83_U00:/persist/simlock # cat numerics
root@CPY83_U00:/persist/simlock # cat unlock
46665716root@CPY83_U00:/persist/simlock # 
上层访问出现:
01-01 20:06:49.363693  1218  1218 D CPSimLockUtil: getParamFromPath -- /persist/simlock/unlock is not exist, return N/A
01-01 20:06:49.348407  1218  1218 W System.err: java.io.FileNotFoundException: /persist/simlock/unlock: open failed: EACCES (Permission denied)
2.2日志分析:
2.2.1 /persist目录selinux中标签为unlabeled问题
首先从radio.boot日志发现,确实是上层无法访问该挂载路径下文件:
01-01 20:06:49.363693  1218  1218 D CPSimLockUtil: getParamFromPath -- /persist/simlock/unlock is not exist, return N/A
01-01 20:06:49.372214  1218  1218 D CPSimLockUtil: getParamFromPath -- /persist/simlock/numerics is not exist, return N/A
01-01 20:06:49.372282  1218  1218 D CPSimLockUtil: unlockCode = null
01-01 20:06:49.372323  1218  1218 D CPSimLockUtil: mNumericsUnlocked = N/A
进一步从main.boot日志中发现是由于权限问题:上层应用无法访问/persist,而且发现/persist的标签为unlabeled:
01-01 20:06:49.348407  1218  1218 W System.err: java.io.FileNotFoundException: /persist/simlock/unlock: open failed: EACCES (Permission denied)
01-01 20:06:49.340000  1218  1218 W m.android.phone: type=1400 audit(0.0:36): avc: denied { search } for name="/" dev="mmcblk0p21" ino=2 scontext=u:r:radio:s0 tcontext=u:object_r:unlabeled:s0 tclass=dir permissive=0
可以在手机根目录下执行ls –Z,发现确实/persist挂载点的标签为unlabeled:
root@CPY83_U00:/ # ls –Z
drwxrwx--x system   system            u:object_r:unlabeled:s0 persist
因此,需要在init.mt6735.rc文件中创建/persist挂载点时,需要添加如下语句:
    chown system system /persist
    chmod 0771 /persist
    #yulong add for simlock requirement of TCCM by sunliang,20160318
    mkdir /persist/simlock  0760 radio radio
    chmod 0760         /persist/simlock/unlock
    chown radio radio  /persist/simlock/unlock
    chmod 0760         /persist/simlock/numerics
    chown radio radio  /persist/simlock/numerics
    restorecon_recursive /persist
    #yulong end
该语句的含义就是根据file_context内容递归给/persist目录添加标签。添加后编译版本利用ls命令进行验证,结果如下:
root@CPY83_U00:/ # ls –Z
drwxrwx--x system   system            u:object_r:persist_data_file:s0 persist
发现/persist的标签变为persist_data_file,其实这正是/persist子目录文件的标签,这正是restorecon_recursive命令的作用,递归根据子目录给指定的目录添加标签。
root@CPY83_U00:/persist # cd simlock/
root@CPY83_U00:/persist/simlock # ls -Z
-rwxrw---- radio    radio             u:object_r:persist_data_file:s0 numerics
-rwxrw---- radio    radio             u:object_r:persist_data_file:s0 unlock
2.2.2 应用访问子目录文件的权限问题
    当/persist目录有指定标签后,进一步验证发现上层还是无法访问/persist下面的子目录文件,日志如下:
01-01 20:06:49.363693  1218  1218 D CPSimLockUtil: getParamFromPath -- /persist/simlock/unlock is not exist, return N/A
01-01 20:06:49.372214  1218  1218 D CPSimLockUtil: getParamFromPath -- /persist/simlock/numerics is not exist, return N/A
01-01 20:06:49.372282  1218  1218 D CPSimLockUtil: unlockCode = null
01-01 20:06:49.372323  1218  1218 D CPSimLockUtil: mNumericsUnlocked = N/A
   不过此时再来看main.log.boot日志发现,测试报的权限问题是因为无法读取/persist/simlock/numberics,日志如下:
01-01 20:07:22.119138  1211  1211 W System.err: java.io.FileNotFoundException: /persist/simlock/unlock: fstat failed: EACCES (Permission denied)
01-01 20:07:22.110000  1211  1211 W m.android.phone: type=1400 audit(0.0:31): avc: denied { read } for path="/persist/simlock/unlock" dev="mmcblk0p21" ino=13 scontext=u:r:radio:s0 tcontext=u:object_r:persist_data_file:s0 tclass=file permissive=0
因此在radio.te中增加访问该标签的read权限,代码如下:
  allow radio persist_data_file:file  read ;
编译版本后又发现缺少open权限,所以在radio.te文件添加open权限,代码如下:
  allow radio persist_data_file:file { read open };
编译版本后又发现缺少getattr权限,所以在radio.te文件添加getattr权限,代码如下:
  allow radio persist_data_file:file { read open getattr };
编译版本后又发现缺少getattr权限,所以在radio.te文件添加write权限,代码如下:
  allow radio persist_data_file:file { read open getattr write };

附录1:具体修改活动
http://10.3.11.35:8080/#/c/37909/  (recovery模式增加源文件)
http://10.3.11.35:8080/#/c/37921/3 (增加simlock逻辑)
http://10.3.11.35:8080/#/c/37913/  (增加源文件,打开feature控制,打开读取权限)
http://10.3.11.35:8080/#/c/37955/  (打开挂载persist分区宏开关)


ota_info_format.sh ota
#!/bin/bash
touch ota_parameter_tmp.txt
TEXT=`awk '/TEXT/ {print NR}' ota_parameter.txt`
TEXT_BEGIN=`echo $TEXT | awk -F " " '{print $1}'`
TEXT_END=`echo $TEXT | awk -F " " '{print $2}'`
if [ ${TEXT_END} -gt `expr $TEXT_BEGIN + 1` ];then
    awk 'NR=='$TEXT_BEGIN+1',NR=='$TEXT_END-1' {print $1 " " $2}' ota_parameter.txt > ota_parameter_tmp.txt
    while read i
    do	    
	    i=`echo $i | tr -d " "`
	    i=`echo $i | tr -d "\015"`
	    Desc=${Desc}\\\n${i}
    done < ota_parameter_tmp.txt
	Description=`echo ${Desc#*n}`
	Description=`echo $Description | tr -d " "`
	blank=`echo $Description | awk -F " " '{print $2}'`
	if [ "$blank" != "" ];then
	    echo "There are some blanks in description.erro!"
		rm -rf ota_parameter_tmp.txt
		exit 1
	fi
	sed -i '4,$d' ota_parameter.txt
	echo "description=$Description" >> ota_parameter.txt
fi
cat ota_parameter.txt
rm -rf ota_parameter_tmp.txt
exit 0




#获取以*或#开头的所有行
Description=`cat ota_parameter.txt | grep ^[*#]`

#删除每行的回车换行符,并将所有行连成一行
for DES in $Description
do
    DES=`echo $DES | tr -d "\015"`
    Desc=${Desc}${DES}
done
#删除第一个*,将每个*号替换成\n\n,将每个#替换成\n
Description=`echo ${Desc#*\*}`
Description=`echo $Description | sed 's/*/\\\*\\\*/g'`
Description=`echo $Description | sed 's/#/\\\*/g'`
echo $Description
#删除文本中所有以*或#开头的行
sed -i -e '/^[*#]/d' ota_parameter.txt
#完成description内容
sed -i '/\<description\>/c\description='$Description'' ota_parameter.txt
sed -i "s/*/\\\n/g" ota_parameter.txt
cat ota_parameter.txt


Main.sh ota
# /bin/bash

echo 311-320有2行注释,请解除

envsetup_file=envsetup.txt


echo ================================================================================
prj_name=`grep '^prj_name=' $envsetup_file | awk -F = '{print $2}'`
echo 项目名称:$prj_name
prj_mode=`grep '^prj_mode=' $envsetup_file | awk -F = '{print $2}'`
echo 产品型号:$prj_mode

#服务器地址
int_server=`grep '^int_server=' $envsetup_file | awk -F = '{print $2}'`
int_server_name=`grep '^int_server_name=' $envsetup_file | awk -F = '{print $2}'`
int_server_ip=`grep '^int_server_ip=' $envsetup_file | awk -F = '{print $2}'`
int_platform=`grep '^int_platform=' $envsetup_file | awk -F = '{print $2}'`

rel_server=`grep '^rel_server=' $envsetup_file | awk -F = '{print $2}'`
rel_server_name=`grep '^rel_server_name=' $envsetup_file | awk -F = '{print $2}'`
rel_server_ip=`grep '^rel_server_ip=' $envsetup_file | awk -F = '{print $2}'`
rel_platform=`grep '^rel_platform=' $envsetup_file | awk -F = '{print $2}'`

ota_path=`grep '^ota_path=' $envsetup_file | awk -F = '{print $2}'`
echo 编译环境路径:$ota_path

window_out_path=`grep '^window_out_path=' $envsetup_file | awk -F = '{print $2}'`
echo Window的输出地址:$window_out_path

#编译环境路径
old_path=$ota_path/old
new_path=$ota_path/new
#ota_parameter.txt存放处
share_path=$ota_path/share

#upc工具存放处
upc_tool_path=$ota_path/upc_tool

#每制作一个差分包的输出地址
out_path=$ota_path/out

#每制作一个差分包的输出,后将移到该地址
out_upc_path=$ota_path/out_upc

#ota参数文件
ota_parameter_file=ota_parameter.txt
ota_parameter_file_changed=ota_parameter_changed.txt
echo ================================================================================
while  getopts :LC opt
do
   case $opt in
   L) hw_ver=$prj_mode
    ;;
   C) hw_ver=PT$prj_mode
    ;;
   esac
done

export OTA_RELEASE_TYPE=NORMAL

if [ -f $ota_path/ota_building.txt ]; then
	echo =========================================
	echo OTA正在制作中,请等待此次制作完!
	echo =========================================
	exit 1
else
	echo "OTA正在制作中,请等待此次制作完!">$ota_path/ota_building.txt
fi

function fail_exit() {
	reason=$1
	echo =========================================
	echo $reason,退出!
	echo =========================================
	if [ -f $share_path/ota_parameter.txt ]; then
		rm -rv $share_path/ota_parameter.txt 
	fi
	rm -rf $ota_path/ota_building.txt
	exit 1
}

if [ ! "$make_ota" = "true" ]; then
	if [ ! -f $ota_path/$ota_parameter_file ]; then
		fail_exit "这是量产方式的OTA制作,必须上传$ota_parameter_file!"
	fi
fi

echo ===============================================================================================
echo 是否随版本制作的OTA:$make_ota (true将自动从服务器下载最新版本,否则将从txt读路径再下载最新版本)
echo ===============================================================================================

#清除share,out,out_upc目录,只清除一次,制作多个包需要。
clean_flag=0

#清除文件,创建环境。
function build_env() {
	if [ ! -d $new_path ]; then echo not exist $new_path & mkdir $new_path ;	fi
	if [ ! -d $old_path ]; then echo not exist $old_path & mkdir $old_path ; fi
	if [ ! -d $share_path ]; then echo not exist $share_path & mkdir $share_path ; fi
	if [ ! -d $out_path ]; then echo not exist $out_path & mkdir $out_path ; fi
	if [ ! -d $out_upc_path ]; then echo not exist $out_path & mkdir $out_upc_path ; fi
#	if [ ! -d $window_out_path ]; then fail_exit "$window_out_path不存在,请创建,并且检查输出脚本是否存在" ; fi
	if [ ! -f $upc_tool_path/ota_pack.out ]; then fail_exit "upc制作工具不存在" ; fi
	
#加上一层判断,防止空值,把整个系统给删除掉
	if [ -d $new_path ]; then rm -rf $new_path/* ; fi
	if [ -d $old_path ]; then rm -rf $old_path/* ; fi	
	rm -rf $ota_path/diff
	rm -rf $ota_path/*.zip

#只清除一次
	if [ "$clean_flag" = "0" ]; then
		if [ -d $share_path ]; then rm -rf $share_path/* ; fi
		if [ -d $out_path ]; then rm -rf $out_path/* ; fi		
		if [ -d $out_upc_path ]; then rm -rf $out_upc_path/* ; fi
		if [ -d $window_out_path ]; then rm -rf $window_out_path/* ; fi
		clean_flag=1
	fi
}
function changed_parameter_txt() {
	if [ ! -d $share_path ]; then echo not exist $share_path & mkdir $share_path ; fi
	iconv -f gb2312 -t utf-8 $ota_path/$ota_parameter_file>$share_path/$ota_parameter_file_changed
	#避免make_ota=true进来时,无法判断该文件是不是上次制作遗留的。
	echo ==========================================================================
	echo ota_parameter.txt文件内容如下:
	cat $share_path/$ota_parameter_file_changed
	echo 	
	echo ==========================================================================
	rm -rf $ota_path/$ota_parameter_file
}

#检查版本是否带有"fail",""XW,"RW"标识,若有将退出。
function check_version_flag() {
	version_all=$1
	version_flag=$(echo $version_all | grep -i "fail")
	if [ ! "$version_flag" = "" ]; then
		fail_exit "服务器版本$version_all带有fail标识"
	fi
	version_flag=$(echo $version_all | grep -i "XW")
	if [ ! "$version_flag" = "" ]; then
		fail_exit "服务器版本$version_all带有XW标识"
	fi
	version_flag=$(echo $version_all | grep -i "RW")
	if [ ! "$version_flag" = "" ]; then
		fail_exit "服务器版本$version_all带有RW标识"
	fi
}

#将要制作的OTA参数从.txt全部获取出来
function get_parameter_txt() {
	changed_parameter_txt
	source_version_all=$(grep source_version $share_path/$ota_parameter_file_changed | tr -s "[\r]" "[\n]" | awk -F \= '{print $2}' | sed 's/\\/\//g')
	server_type=`echo $source_version_all | awk -F / '{print $3}'`
	if [ "$server_type" = "10.1.11.53" ];then
	   source_version_all=`echo ${source_version_all##*CP}`
           source_version_all=`echo ${source_version_all#*/}`
           source_version_all=$rel_server/$source_version_all
	fi
	if [ "$server_type" = "10.1.11.58" ];then
	   source_version_all=`echo ${source_version_all##*Rel_Version}`
           source_version_all=`echo ${source_version_all#*/}`
           source_version_all=$int_server/$source_version_all
	fi
	check_version_flag "$source_version_all"
        dest_version_all=$(grep dest_version $share_path/$ota_parameter_file_changed | tr -s "[\r]" "[\n]" | awk -F \= '{print $2}' | sed 's/\\/\//g')
	server_type=`echo $dest_version_all | awk -F / '{print $3}'`
	if [ "$server_type" = "10.1.11.53" ];then
	   dest_version_all=`echo ${dest_version_all##*CP}`
           dest_version_all=`echo ${dest_version_all#*/}`
           dest_version_all=$rel_server/$dest_version_all
	fi
	if [ "$server_type" = "10.1.11.58" ];then
	   dest_version_all=`echo ${dest_version_all##*Rel_Version}`
           dest_version_all=`echo ${dest_version_all#*/}`
           dest_version_all=$int_server/$dest_version_all
	fi
	check_version_flag "$dest_version_all"
}

function get_parameter_server() {

#获取3.37最新版本--源版本
	cd $rel_server
	num=1
	version_flag=XW
	while [ "$version_flag" != "" ]
	do
		source_version_all=$(ls -tr | grep $prj_name | tail -n $num | head -n 1 )
		version_flag=$(echo $source_version_all | grep -i "XW")
                if [ ! "$version_flag" = "" ]; then
         		echo "发布服务器版本$source_version_all带有-XW标识"
                fi

		if [ "$version_flag" = "" ]; then
			version_flag=$(echo $source_version_all | grep -i "RW")
			if [ ! "$version_flag" = "" ]; then
                        	echo "发布服务器版本$source_version_all带有-RW标识"
			fi 
		fi

		declare -i num=$num+1
	done
	echo 发布服务器取用的版本:$source_version_all
	if [ -d $rel_server/$source_version_all/配置文件包 ]; then
		source_version_all=$rel_server\/$source_version_all\/配置文件包
	else
		source_version_all=$rel_server\/$source_version_all\/Configurations
	fi

#获取最新集成出来的rel版本--目标版本
	cd $int_server
	num=1
	version_flag=XW
	while [ "$version_flag" != "" ]
	do
		dest_version_all=$(ls -tr | grep $prj_name | tail -n $num | head -n 1 )	
		version_flag=$(echo $dest_version_all | grep -i "fail")
		if [ ! "$version_flag" = "" ]; then
			fail_exit "集成服务器版本$dest_version_all带有-fail标识"
		fi
		version_flag=$(echo $dest_version_all | grep -i "XW")
                if [ ! "$version_flag" = "" ]; then
                        fail_exit "集成服务器版本$dest_version_all带有-XW标识"
                fi
                version_flag=$(echo $dest_version_all | grep -i "RW")
                if [ ! "$version_flag" = "" ]; then
                        fail_exit "集成服务器版本$dest_version_all带有-RW标识"
                fi
		declare -i num=$num+1
	done
	#检测该版本是否制作过OTA--检查是否存在OTA文件夹
        version_folder=$int_server\/$dest_version_all
        cd $version_folder
        soft_folder=$(ls |grep 软件包*)
        if [ "$soft_folder" = "" ]; then
        	soft_folder=$(ls | grep -i "Install*")
        fi
        soft_folder_path=$version_folder\/$soft_folder
        cd $soft_folder_path
        ota_folder_flag=$(ls | grep OTA)
        if [ ! "$ota_folder_flag" = "" ]; then
                fail_exit "集成服务器版本$dest_version_all该版本已制作OTA,存在OTA目录!"
        fi
	echo 编译服务器取用的版本:$dest_version_all
	if [ -d $int_server\/$dest_version_all\/配置文件包 ]; then
		dest_version_all=$int_server\/$dest_version_all\/配置文件包
	else
		dest_version_all=$int_server\/$dest_version_all\/Configurations
	fi
}

#获取升级类型,描述说明等
function get_parameter_other() {
#这个判断时给make=true使用的
	if [ -f $ota_path/$ota_parameter_file ]; then
		changed_parameter_txt
	fi
	if [ -f $share_path/$ota_parameter_file_changed ]; then
		priority_all=$(grep priority $share_path/$ota_parameter_file_changed | tr -s "[\r]" "[\n]" | awk -F \= '{print $2}')	
		description_all=$(grep description $share_path/$ota_parameter_file_changed | tr -s "[\r]" "[\n]" | awk -F \= '{print $2}')
		ota_style_all=$(grep ota_style $share_path/$ota_parameter_file_changed | tr -s "[\r]" "[\n]" | awk -F \= '{print $2}')
	else
		echo $ota_parameter_file_changed文件不存在,upc参数将取用默认值。
	fi
}

#此函数获取到的参数才真正需要用到的,之前是将参数列数组。
function get_parameter_final() {
	num=$1
	if [ -z $num ]; then
		echo num没有传递参数
	fi
	source_version=$(echo $source_version_all | awk '{print $'$num'}')

	cd $source_version
	source_file_path=$source_version/$(ls | grep *ota*.zip)
	echo source_file_path:$source_file_path
	if [ ! -f $source_file_path ]; then	
		fail_exit "源OTA包不存在"
	fi
	
    echo YLH:source_version=$source_version
    cd $source_version/../
    echo pwd=$(pwd)

    source_lk_file_path=$(ls Inst*/image_verified | grep lk-verified.bin)
    echo YLH:source_lk_file_path=$source_lk_file_path
    if [ -z $source_lk_file_path ]; then
        fail_exit "源lk不存在"
    fi
	dest_version=$(echo $dest_version_all | awk '{print $'$num'}')

	cd $dest_version
	dest_file_path=$dest_version/$(ls | grep *ota*.zip)
	echo dest_file_path:$dest_file_path
	if [ ! -f $dest_file_path ]; then	
		fail_exit "目标OTA包不存在"
	fi
	
    cd $source_version/../
    dest_lk_file_path=$(ls Inst*/image_verified | grep lk-verified.bin)
    if [ -z $dest_lk_file_path ]; then
        fail_exit "目标lk不存在"
    fi
	priority=$(echo $priority_all | awk '{print $'$num'}')
	echo priority:$priority

	description=$(echo $description_all | awk '{print $'$num'}')
	echo description:$description
	
	ota_style=$(echo $ota_style_all | awk '{print $'$num'}')
#强制自动读取版本时,前向后向都需制作,避免在传了txt文件,制作类型是full或diff类型。
	if [ "$make_ota" = "true" ]; then
		ota_style=all
	fi
	echo ota_style:$ota_style
		
	zip_hw_version=$(echo $source_file_path | awk -F \/ '{print $6}' | awk -F \. '{print $2}')
#        echo 硬件版本号写死为:P0
#        zip_hw_version=P0
#	下面是避免填入的版本是取自集成服务器的
	if [ "$zip_hw_version" = "" ]; then
		zip_hw_version=$(echo $source_file_path | awk -F \/ '{print $7}' | awk -F \. '{print $2}')
	fi
	echo zip_hw_version:$zip_hw_version--源版本目录名的硬件版本号,供差分包.zip命名
}

#下载OTA文件
function download_ota_file() {
    echo YLH:old_path=$old_path
    echo YLH:new_path=$new_path
	echo =================下载OTA材料文件======================
	cp -rvf $source_file_path $old_path/
	cp -rvf $dest_file_path $new_path/
    echo =================下载lk升级文件=======================
    lk_src=$source_version/../*Insta*/image_verified/lk-verified.bin
    lk_dst=$dest_version/../*Insta*/image_verified/lk-verified.bin
    lk_src_cmp=$source_version/../*Insta*/image/lk.bin
    lk_dst_cmp=$dest_version/../*Insta*/image/lk.bin
    if [ -e $lk_src_cmp -a -e $lk_dst_cmp ]; then
        cmp_ret=$(cmp $lk_src_cmp $lk_dst_cmp)
        echo YLH:cmp_ret=$cmp_ret
    fi
    if [ -n "$cmp_ret" ]; then
        cp -rvf $lk_src $old_path/lk.bin
        cp -rvf $lk_dst $new_path/lk.bin
    fi
	
    echo =================下载logo升级文件=======================
    logo_src=$source_version/../*Insta*/image_verified/logo-verified.bin
    logo_dst=$dest_version/../*Insta*/image_verified/logo-verified.bin
    logo_src_cmp=$source_version/../*Insta*/image/logo.bin
    logo_dst_cmp=$dest_version/../*Insta*/image/logo.bin
    if [ -e $logo_src_cmp -a -e $logo_dst_cmp ]; then
        cmp_ret=$(cmp $logo_src_cmp $logo_dst_cmp)
        echo LJ:cmp_ret=$cmp_ret
    fi
    if [ -n "$cmp_ret" ]; then
        cp -rvf $logo_src $old_path/logo.bin
        cp -rvf $logo_dst $new_path/logo.bin
    fi
    echo =================下载preloader升级文件=======================
    preloader_src=$source_version/../*Insta*/image_verified/preloader.bin
    preloader_dst=$dest_version/../*Insta*/image_verified/preloader.bin
    preloader_src_cmp=$source_version/../*Insta*/image/preloader.bin
    preloader_dst_cmp=$dest_version/../*Insta*/image/preloader.bin
    if [ -e $preloader_src_cmp -a -e $preloader_dst_cmp ]; then
        cmp_ret=$(cmp $preloader_src_cmp $preloader_dst_cmp)
        echo LJ:cmp_ret=$cmp_ret
    fi
    if [ -n "$cmp_ret" ]; then
        cp -rvf $preloader_src $old_path/preloader.bin
        cp -rvf $preloader_dst $new_path/preloader.bin
    fi
    echo =================创建IMAGES目录=======================
    rm -rvf $old_path/IMAGES
    rm -rvf $new_path/IMAGES
    mkdir -v $old_path/IMAGES
    mkdir -v $new_path/IMAGES

    echo =================下载boot.img文件=======================
    cp -rvf $source_version/../*Insta*/image_verified/boot-verified.img $old_path/IMAGES/boot.img
    cp -rvf $dest_version/../*Insta*/image_verified/boot-verified.img $new_path/IMAGES/boot.img

    echo =================下载recovery.img文件=======================
    cp -rvf $source_version/../*Insta*/image_verified/recovery-verified.img $old_path/IMAGES/recovery.img
    cp -rvf $dest_version/../*Insta*/image_verified/recovery-verified.img $new_path/IMAGES/recovery.img

    #=======================================================================================#
    cd $old_path
    echo YLH:pwd=$(pwd)
    target_file=$(ls |grep "target_files")
    echo =================替换boot.img和recovery.img In $old_path/$target_file =======================
    zip -f $target_file IMAGES/boot.img
    zip -f $target_file IMAGES/recovery.img 

    cd $new_path
    echo YLH:pwd=$(pwd)
    target_file=$(ls |grep "target_files")
    echo =================替换boot.img和recovery.img In $new_path/$target_file =======================
    zip -f $target_file IMAGES/boot.img
    zip -f $target_file IMAGES/recovery.img
    #=======================================================================================#
}

#获取UPC文件参数
function get_upcinfo() {
	cd $out_path
	outname=$( ls | grep "OTA" ) 
	echo outname:$outname
	cd $outname
	echo ===================获取版本号============================
	diff_name=$( ls | grep "diff" )
	full_name=$( ls | grep "full" )
	echo diff_name:$diff_name
	if [ ! "$full_name" = "" ]; then
		echo full_name:$full_name
	fi

	if [ ! -d $ota_path/diff ]; then
		cd $ota_path
		unzip $out_path/$outname/$diff_name -d$ota_path/diff
		cd $ota_path/diff/META-INF/com/google/android/
        old_version=$(grep $prj_name updater-script | sed -n '2p' | awk -F \/ '{print $5}' | sed 's/:use.*//g')
        new_version=$(grep $prj_name updater-script | sed -n '3p' | awk -F \/ '{print $5}' | sed 's/:use.*//g')
		echo 旧版本:$old_version
		echo 新版本:$new_version
		ota_oldversion=$(echo $old_version | awk -F \. '{print $3}' )
		ota_newversion=$(echo $new_version | awk -F \. '{print $3}' )
		echo 旧版本号:$ota_oldversion
		echo 新版本号:$ota_newversion

		if [ "$ota_oldversion" == "" ]; then
			echo zhushi旧版本号获取不到
			fail_exit "旧版本号获取不到"
		fi
		if [ "$ota_newversion" == "" ]; then
			echo zhushi新版本号获取不到
			fail_exit "新版本号获取不到"
		fi
		
		echo 获取OTA发布模式
		ota_release_mode=
		if [ "$ota_release_mode" == "dfd" ]; then
		
			echo 编译公测版本
	        else
	                echo 正式版本
			
		fi
	else
		fail_exit "已存在$ota_path/diff,参数将获取错误"
	fi
	
	hw_version=$(echo $old_version | awk -F \. '{print $4}' )
	echo hw_version:$hw_version--源版本号中的硬件版本号,供UPC文件使用
}

#制作UPC前的参数检查
function check_upcinfo() {
	echo ----------------制作UPC前的参数检查---------------------
	if [ ! "$priority" = "Optional" ] && [ ! "$priority" = "Super" ]; then
		if [ "$make_ota" = "true" ]; then
			echo make_ota="true",priority=Optional
			priority=Optional
		else
#避免第二次制作时,为空值导致失败。
			if [ "$priority" = "" ]; then
				echo priority="",priority=Optional
				priority=Optional
#非Optional,非Super,非空。
			else
				fail_exit "priority=$priority,必须为Optional,Super"
			fi
		fi
	fi
	echo priority:$priority
	
	if [ "$description" = "" ]; then
		description=OTA_$ota_oldversion\_$ota_newversion
	fi
	echo description:$description

	check_old_version=$(echo $old_version | awk -F \. '{print $6}')
	check_new_version=$(echo $new_version | awk -F \. '{print $6}')
	if [ ! "$check_old_version" = "$check_new_version" ]; then
		echo check_old_version:$check_old_version
		echo check_new_version:$check_new_version
		echo "源版本和目标版本中的项目名不一致",注释,不退出。
		#fail_exit "源版本和目标版本中的项目名不一致" 
	fi 

	ckeck_XW_old_version=$(echo $old_version | grep -i XW)
	if [ ! "$ckeck_XW_old_version" = "" ]; then
		echo ckeck_XW_old_version:$ckeck_XW_old_version
 		fail_exit "源版本中的项目名存在“XW”标识"
	fi 

	ckeck_RW_old_version=$(echo $old_version | grep -i RW)
	if [ ! "$ckeck_RW_old_version" = "" ]; then
		echo ckeck_RW_old_version:$ckeck_RW_old_version
		fail_exit "源版本中的项目名存在“RW”标识"
	fi 

	ckeck_XW_new_version=$(echo $new_version | grep -i XW)
	if [ ! "$ckeck_XW_new_version" = "" ]; then
		echo ckeck_XW_new_version:$ckeck_XW_new_version
		fail_exit "目标版本中的项目名存在“XW”标识"
	fi 

	ckeck_RW_new_version=$(echo $new_version | grep -i RW)
	if [ ! "$ckeck_RW_new_version" = "" ]; then
		echo ckeck_RW_new_version:$ckeck_RW_new_version
		fail_exit "目标版本中的项目名存在“RW”标识"
	fi
}

#制作UPC文件
function makeupc() {
	get_upcinfo
	

	check_upcinfo
	
	echo full_package=false > $upc_tool_path/ota.conf
	#echo hardware=$prj_name >> $upc_tool_path/ota.conf
#echo UPC文件项目名写死:Coolpad7730_4.2
	echo hardware=$hw_ver >> $upc_tool_path/ota.conf
	echo hwversion=$hw_version >> $upc_tool_path/ota.conf
	echo source_swv1=$old_version >> $upc_tool_path/ota.conf
	echo dest_swv=$new_version >> $upc_tool_path/ota.conf
	echo priority=$priority >> $upc_tool_path/ota.conf
	echo diff_file1=$out_path/$outname/$diff_name >> $upc_tool_path/ota.conf
	echo description=$description_all >> $upc_tool_path/ota.conf

	echo ============upc文件参数============
	cat $upc_tool_path/ota.conf
	echo ==================================
	cd  $upc_tool_path
	./ota_pack.out 1

#将upc文件改名并且移到OTA文件夹中
	mv $upc_tool_path/*UPC*.xml $upc_tool_path/UPC\_$prj_name\_$hw_version\_$ota_oldversion\-$ota_newversion.xml
	mv $upc_tool_path/UPC*.xml $out_path/$outname/
	mv $out_path/$outname $out_upc_path
}

#===============================函数组合===========================
#获取服务器上的版本信息,和其它upc文件信息
function get_parameter_server_all() {
	get_parameter_server
	get_parameter_other
}
#获取txt文件的版本信息,和其它upc文件信息
function get_parameter_txt_all() {
	get_parameter_txt
	get_parameter_other
}
#只制作前向升级包
function makeota_full() {
	cd $ota_path/
	./MakeOTA.sh -H$zip_hw_version
	makeupc
}
#只制作后向升级包
function makeota_diff() {
	cd $ota_path/
	./MakeOTA.sh -H$zip_hw_version -d
	makeupc
}
#同时制作前向升级包和后向升级包
function makeota_all() {
	cd $ota_path/	
	echo =====================开始制作前向升级包=======================
	./MakeOTA.sh -H$zip_hw_version
	makeupc

	cd $ota_path/
	mv new new1
	mv old new
	mv new1 old

#置空之后会刷新信息,重新自动调用OTA_0XX_0XX,不然这个的描述会用正向升级包的描述
       diff_descritpion=$(echo $description | grep -i "OTA_*" )
       if [ ! "$diff_descritpion" = "" ]; then
                description=
       fi
	
	echo ======================开始制作后向升级包=======================
	rm -r  $ota_path/diff
	./MakeOTA.sh -H$zip_hw_version -d
	makeupc
}

#==============================组合函数完===========================

#主要逻辑控制函数
function makeota() {
#代表在制作第几次OTA包
	count=1
	for i in $dest_version_all
  	do
		build_env
  		echo =====================================================	
		echo               开始第$count次制作OTA包
		echo =====================================================
		#刷新OTA和upc参数
		get_parameter_final $count
		#下载OTA材料文件
		download_ota_file
		cd $ota_path
		
		if [ "$ota_style" = "all" ] || [ "$ota_style" = "" ] || [ "$makeota" = "true" ]; then
			echo ============同时制作顺向升级包和后向升级包===============
			makeota_all
		elif [ "$ota_style" = "diff" ]; then
			echo ==================只制作后向升级包====================
			makeota_diff
		else
			echo ==================只制作前向升级包====================
			echo ota_style:$ota_style
			makeota_full
		fi
			
		echo ======================================================
		echo                 第$count次OTA包制作完成
		echo ======================================================
		declare -i count=$count+1
	done
}

#以上是函数定义,以下是函数运用。
#获取制作OTA包的信息
if [ "$make_ota" = "true" ] ; then 
	get_parameter_server_all
else
  	get_parameter_txt_all
fi

#开始制作OTA包
makeota

#move ota files to mtk int server
mv $out_upc_path/* $int_server/../OTA

echo 返回值:$?
if [ -f  $ota_path/ota_building.txt ];then
    rm -rf $ota_path/ota_building.txt
fi

exit
envsetup.txt ota
#==========================================================
#  main.sh 变量设置区
#==========================================================
#项目名
prj_name=3505I
#产品型号
prj_mode=Coolpad 3505I
#输出目录
prj_out=cp3505I


#发布服务器和集成服务器地址
int_server=/mnt/hgfs/mtk_server/CP3505I/Rel_Version
int_server_name=mtk_server
int_server_ip=10.1.11.58
int_platform=MTK_Test_Version

rel_server=/mnt/hgfs/mtk_rel_server/CP3505I
rel_server_name=mtk_rel_server

rel_server_ip='10.1.11.53\/CP_Release_Version'
rel_platform=MT6737_Release_Version

#编译环境路径
ota_path=/home/system18/CP3505I_INT/OTA

#Window的输出地址
window_out_path=/mnt/hgfs/CP3505I/CP3505I_Ota/out

#==========================================================
#  makeota.sh 变量设置区
#==========================================================
#项目路径
prj_dir=/home/system18/CP3505I_INT
#签名文件
key=/home/system18/CP3505I_INT/security/security_yulong/testkey
#签名工具
signapk=/home/system18/CP3505I_INT/mydroid/out/host/linux-x86/framework/signapk.jar




#==========================================================
#  ota_todest.bat 变量设置区
#==========================================================
#源目录
src_dir=F:\CPY83_I00\CP3505I_Ota\out
#半自动化量产方式输出地址
target_path=\\10.1.11.58\MTK_Test_Version\CP3505I\OTA
#全自动OTA-E化取用地址
int_server_path=\\10.1.11.58\MTK_Test_Version\CP3505I\Rel_Version

Make_OTA.sh ota
#! /bin/bash
#makeota.sh,制作差分包并签名

envsetup_file=envsetup.txt

prj_dir=`grep '^prj_dir=' $envsetup_file | awk -F = '{print $2}'`
echo 项目路径:$prj_dir
prj_out=`grep '^prj_out=' $envsetup_file | awk -F = '{print $2}'`
echo 输出目录:$prj_out

key=`grep '^key=' $envsetup_file | awk -F = '{print $2}'`
echo 项目路径:$key

signapk=`grep '^signapk=' $envsetup_file | awk -F = '{print $2}'`
echo 签名工具:$signapk

#编译根目录
top_name=$prj_dir/mydroid

#OTA制作路径
make_ota_dir=$prj_dir/OTA

#新包路径
target_new_dir=$make_ota_dir/new

#旧包路径
target_old_dir=$make_ota_dir/old

#输出路径
target_out_dir=$make_ota_dir/out

#新target包
newtarget=`ls -1 $target_new_dir/*-target_files-*.zip`

new_ver=`echo "$newtarget" | awk -F \- '{print $4}' | awk -F \. '{print $1}'`

#旧target包
old_target_files=`ls -1 $target_old_dir/*-target_files-*.zip`

function help() {
cat <<EOF
usage $0  [-o|m|g|h|] [-H <硬件版本号>]
  -o : 制作OTA.
  -H : 硬件版本号.
  -m : 添加modem.
  -g : 制作gms.
  -h : 帮助.
EOF
exit 0
}


while getopts :H:hd opt
do
    case $opt in
    H) hardware_id=$OPTARG
      ;;
    d) ota_style=diff
    	;;
    h) help
      ;;
    esac
done

echo  硬件版本号:$hardware_id

echo "---检查基础环境---"
check_value=

if [ "$#" -lt "1"  ] ; then echo "参数不能为空." & exit 1 ;fi

if [ -z $hardware_id ] ; then echo "请加上\"-h 硬件版本号\"" & check_value=error ;fi
if [ -z $ota_style ] ; then echo "需要制作整包和差分包" ;fi
if [ ! -d $target_new_dir ] ; then mkdir -p $target_new_dir ;fi
if [ ! -d $target_old_dir ] ; then mkdir -p $target_old_dir ;fi
if [ ! -d $target_out_dir ] ; then mkdir -p $target_out_dir ;fi
if [ -z $newtarget ] ; then echo "不存在newtarget文件." & check_value=error ;fi
if [ -z "$old_target_files" ] ; then echo "不存在oldtarget文件." & check_value=error ;fi

if [ ! -f $signapk ] ; then echo "不存在\"$signapk\"文件." & check_value=error ;fi
if [ ! -f $key.pk8 ] ; then echo "不存在\"$key.pk8\"文件." & check_value=error ;fi
if [ ! -f $key.x509.pem ] ; then echo "不存在\"$key.x509.pem\"文件." & check_value=error ;fi

if [ "$check_value" = "error" ] ; then exit 1 ;fi

echo "---删除临时文件---"
if [ "$target_out_dir" = "" ] ; then
	echo OTA包输出变量无设置,请设置,退出!
	exit 1
else
	rm -rf $target_out_dir
	mkdir -p $target_out_dir
fi

function makeOTA() {
    local curtime=$(date +%y%m%d_%H%M)
    if [ "$ota_style" = "diff" ] ; then
    	local output_name=OTA_V"$2"_V"$new_ver"\_$curtime\_F
    else
	local output_name=OTA_V"$2"_V"$new_ver"\_$curtime
    fi
    local diff_package_name=ota_diff_"$2"_"$new_ver"_"$hardware_id"_signed.zip
    local full_package_name=ota_full_"$new_ver"_"$hardware_id"_signed.zip
    local oldtarget=$1
    
    mkdir -p $target_out_dir/$output_name

    echo "---制作差分包($output_name)---"
#    cd $top_name/build/tools/releasetools
#    ./ota_from_target_files -x pagesize=2048 -k $top_name/build/target/product/security/testkey -p $top_name/out/host/linux-x86  -i $oldtarget $newtarget $target_out_dir/$output_name/diff.zip
     cd $top_name 
if [ $OTA_RELEASE_TYPE = "KSB" ];then
     echo "---制作差分卡刷包---"
    ./build/tools/releasetools/ota_from_target_files --block -x pagesize=2048 -k $top_name/build/target/product/security/testkey -p $top_name/out/host/linux-x86 -u out/target/product/$prj_out/lk.bin  -l  out/target/product/$prj_out/logo.bin -i $oldtarget $newtarget $target_out_dir/$output_name/diff.zip
else

    ./build/tools/releasetools/ota_from_target_files --block -x pagesize=2048 -k $top_name/build/target/product/security/testkey -p $top_name/out/host/linux-x86  -r out/target/product/$prj_out/preloader.bin -u out/target/product/$prj_out/lk.bin  -l  out/target/product/$prj_out/logo.bin -i $oldtarget $newtarget $target_out_dir/$output_name/diff.zip
fi    
    echo "---签名差分包($output_name)---"
    echo key:$key
    java -Xmx1024m -jar $signapk -w $key.x509.pem $key.pk8 $target_out_dir/$output_name/diff.zip $target_out_dir/$output_name/$diff_package_name
   
    rm -rf $target_out_dir/$output_name/diff.zip

    if [ ! "$ota_style" = "diff" ] ; then
    	 echo "---制作整包($output_name)---"
#    	./ota_from_target_files -x pagesize=2048 -k $top_name/build/target/product/security/testkey -p $top_name/out/host/linux-x86  $newtarget $target_out_dir/$output_name/total.zip
if [ $OTA_RELEASE_TYPE = "KSB" ];then
     echo "---制作整包卡刷包---"
     ./build/tools/releasetools/ota_from_target_files --block -x pagesize=2048 -k $top_name/build/target/product/security/testkey -p $top_name/out/host/linux-x86 -u out/target/product/$prj_out/lk.bin -l  out/target/product/$prj_out/logo.bin $newtarget $target_out_dir/$output_name/total.zip
else
     ./build/tools/releasetools/ota_from_target_files --block -x pagesize=2048 -k $top_name/build/target/product/security/testkey -p $top_name/out/host/linux-x86  $newtarget $target_out_dir/$output_name/total.zip
fi
   	 echo "---签名整包($output_name)---"
    	 java -Xmx2048m -jar $signapk -w $key.x509.pem $key.pk8 $target_out_dir/$output_name/total.zip $target_out_dir/$output_name/$full_package_name
	 rm -rf $target_out_dir/$output_name/total.zip
     fi
}

for target in $old_target_files
do
	old_ver=`echo "$target" | awk -F \- '{print $4}' | awk -F \. '{print $1}'`
	makeOTA $target $old_ver
done



属性文件的使用 java
/**
 * 
 */
package com.xupt.upload;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.ContextLoader;


/**   
 *  
 * Simple to Introduction  
 * @ProjectName:  [徐州联通基站项目-移动网工程] 
 * @Package:      [com.xupt.upload.UploadInfo.java]  
 * @ClassName:    [UploadInfo]   
 * @Description:  [在文件上传中指定路径,方便移植,将属性值放到属性文件中]   
 * @Author:       [xxx]   
 * @CreateDate:   [2014年2月16日 下午4:37:04]   
 * @UpdateUser:   [lenovo]   
 * @UpdateDate:   [2014年2月16日 下午4:37:04]   
 * @UpdateRemark: [说明本次修改内容]  
 * @Version:      [v1.0] 
 *    
 */
public class UploadInfo {
	/**
	 * 设置路径
	 */
	public UploadInfo(){
		Properties p=new Properties();
		
		String filePath=this.getClass().getResource("/").getPath().toString();
		filePath=filePath+"upload.properties";
	
		try {
			FileReader fr=new FileReader(filePath);
			p.load(fr);
			path=p.getProperty("path");
		
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//p.load(reader);
	}
	private String path="";
//	private String path=ContextLoader.getCurrentWebApplicationContext().getServletContext().getRealPath("/");

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	public static void main(String[] args) {
		UploadInfo info=new UploadInfo();
	}

}
在属性文件upload.properties中的内容
path=d:\\uploadfile\\
Global site tag (gtag.js) - Google Analytics