Home | History | Annotate | Download | only in common
      1 # Copyright (C) 2009 The Android Open Source Project
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #      http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 
     15 """Emit commands needed for Motorola devices during OTA installation
     16 (installing the MBM, CDT, LBL and BP images)."""
     17 
     18 import common
     19 
     20 def FullOTA_InstallEnd(info):
     21   try:
     22     WriteBPUpdate(info,info.input_zip.read("RADIO/rdl.bin"),
     23                 info.input_zip.read("RADIO/bp.img"))
     24   except KeyError:
     25     print ("warning: rdl.bin and/or bp.img not in input target_files; "
     26            "skipping BP update")
     27   if info.extras.get("mbm", None) == "consumer":
     28     try:
     29       info.input_zip.getinfo("RADIO/mbm_consumer.bin")
     30       Write2FullOTAPackage(info, "mbm", "mbm_consumer.bin")
     31     except KeyError, e:
     32       print ("warning: mbm_consumer.bin not in input target_files; "
     33              "skipping MBM update")
     34   else:
     35     Write2FullOTAPackage(info, "mbm", "mbm.bin")
     36   Write2FullOTAPackage(info, "lbl", "lbl")
     37   Write2FullOTAPackage(info, "cdt", "cdt.bin")
     38 
     39 def IncrementalOTA_InstallEnd(info):
     40   WriteBP2IncrementalPackage(info)
     41   if info.extras.get("mbm", None) == "consumer":
     42     try:
     43       info.target_zip.getinfo("RADIO/mbm_consumer.bin")
     44       Write2IncrementalPackage(info, "mbm", "mbm_consumer.bin")
     45     except KeyError, e:
     46       print ("warning: mbm_consumer.bin not in input target_files; "
     47              "skipping MBM update")
     48   else:
     49     Write2IncrementalPackage(info, "mbm", "mbm.bin")
     50   Write2IncrementalPackage(info, "lbl", "lbl")
     51   Write2IncrementalPackage(info, "cdt", "cdt.bin")
     52 
     53 #Append BP image and BP update agent(RDL, run in BP side) to package
     54 def WriteBPUpdate(info, rdl_bin, bp_bin):
     55   common.ZipWriteStr(info.output_zip, "rdl.bin",
     56                      rdl_bin)
     57   common.ZipWriteStr(info.output_zip, "bp.img",
     58                      bp_bin)
     59   # this only works with edify; motorola devices never use amend.
     60   info.script.AppendExtra('''assert(package_extract_file("bp.img", "/tmp/bp.img"),
     61        package_extract_file("rdl.bin", "/tmp/rdl.bin"),
     62        moto.update_cdma_bp("/tmp/rdl.bin", "/tmp/bp.img"),
     63        delete("/tmp/bp.img", "/tmp/rdl.bin"));''')
     64 
     65 #Append BP image and RDL to incremental package
     66 def WriteBP2IncrementalPackage(info):
     67   try:
     68     target_rdl = info.target_zip.read("RADIO/rdl.bin")
     69     target_bp = info.target_zip.read("RADIO/bp.img")
     70     try:
     71       source_bp = info.source_zip.read("RADIO/bp.img")
     72       if source_bp == target_bp:
     73         print("BP images unchanged; skipping")
     74       else:
     75         print("BP image changed; including")
     76         info.script.Print("Writing RDL/BP image...")
     77         WriteBPUpdate(info,target_rdl,target_bp)
     78     except KeyError:
     79       print("warning: no rdl.bin and/or bp.img in source_files; just use target")
     80       info.script.Print("Writing RDL/BP image...")
     81       WriteBPUpdate(info,target_rdl,target_bp)
     82   except KeyError:
     83     print("warning: no rdl.bin and/or bp.img in target_files; not flashing")
     84 
     85 #Append raw image update to package
     86 def Write2FullOTAPackage(info, dev_name, bin_name):
     87   try:
     88     common.ZipWriteStr(info.output_zip, bin_name,
     89                        info.input_zip.read("RADIO/"+bin_name))
     90     info.script.WriteRawImage(dev_name, bin_name)
     91   except KeyError:
     92     print ("warning: no "+ bin_name +" in input target_files; not flashing")
     93 
     94 #Append raw image update to incremental package
     95 def Write2IncrementalPackage(info, dev_name, bin_name):
     96   try:
     97     file_name = "RADIO/" + bin_name;
     98     target = info.target_zip.read(file_name);
     99     try:
    100       source = info.source_zip.read(file_name);
    101       if source == target:
    102         print(dev_name + " image unchanged; skipping")
    103       else:
    104         print(dev_name + " image changed; including")
    105         common.ZipWriteStr(info.output_zip, bin_name, target)
    106         info.script.WriteRawImage(dev_name, bin_name)
    107     except KeyError:
    108       print("warning: no "+ bin_name +" in source_files; just use target")
    109       common.ZipWriteStr(info.output_zip, bin_name, target)
    110       info.script.WriteRawImage(dev_name, bin_name)
    111   except KeyError:
    112     print("warning: no "+ bin_name +" in target_files; not flashing")
    113