Home | History | Annotate | Download | only in crespo4g
      1 # Copyright (C) 2010 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 import re
     16 
     17 import common
     18 
     19 def WriteRadio(info, radio_file):
     20   radio_file.AddToZip(info.output_zip)
     21   info.script.Print("Writing radio...")
     22   info.script.AppendExtra(
     23       'assert(samsung.update_modem(package_extract_file("%s")));\n' %
     24       (radio_file.name,))
     25 
     26 def WriteBootloader(info, bootloader_file):
     27   bootloader_file.AddToZip(info.output_zip)
     28   info.script.Print("Writing bootloader...")
     29   info.script.WriteRawImage("/bootloader", bootloader_file.name)
     30 
     31 def FindImage(zipfile, basename):
     32   matches = []
     33   for name in zipfile.namelist():
     34     m = re.match(r"^RADIO/(" + basename + "[.](.+[.])?img)$", name)
     35     if m:
     36       matches.append((name, m.group(1)))
     37   if len(matches) > 1:
     38     raise ValueError("multiple radio images in target-files zip!")
     39   if matches:
     40     matches = matches[0]
     41     print "using %s as %s" % matches
     42     return common.File(matches[1], zipfile.read(matches[0]))
     43   else:
     44     return None
     45 
     46 def FullOTA_InstallEnd(info):
     47   bootloader_img = FindImage(info.input_zip, "bootloader")
     48   if bootloader_img:
     49     WriteBootloader(info, bootloader_img)
     50   else:
     51     print "no bootloader in target_files; skipping install"
     52 
     53   radio_img = FindImage(info.input_zip, "radio")
     54   if radio_img:
     55     WriteRadio(info, radio_img)
     56   else:
     57     print "no radio in target_files; skipping install"
     58 
     59 def IncrementalOTA_InstallEnd(info):
     60   tf = FindImage(info.target_zip, "bootloader")
     61   sf = FindImage(info.source_zip, "bootloader")
     62 
     63   if not tf:
     64     print "no bootloader image in target target_files; skipping"
     65   elif sf and tf.sha1 == sf.sha1:
     66     print "bootloader image unchanged; skipping"
     67   else:
     68     WriteBootloader(info, sf)
     69 
     70   tf = FindImage(info.target_zip, "radio")
     71   sf = FindImage(info.source_zip, "radio")
     72 
     73   if not tf:
     74     print "no radio image in target target_files; skipping"
     75   elif sf and tf.sha1 == sf.sha1:
     76     print "radio image unchanged; skipping"
     77   else:
     78     WriteRadio(info, tf)
     79