summaryrefslogtreecommitdiffstats
path: root/releasetools/aries_ota_from_target_files
blob: 283548caf1b9b10f0237e3872ed0cc627e9c01fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python
#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import os
import aries_common as common

LOCAL_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
RELEASETOOLS_DIR = os.path.abspath(os.path.join(LOCAL_DIR, '../../../build/tools/releasetools'))
TARGET_DIR = os.getenv('OUT')
UTILITIES_DIR = os.path.join(TARGET_DIR, 'utilities')

# Add releasetools directory to python path
sys.path.append(RELEASETOOLS_DIR)

# Import the existing file so we just have to rewrite the modules we need.
# This is a nasty hack as the filename doesn't end in .py, but it works
filename = os.path.join(RELEASETOOLS_DIR, "ota_from_target_files")
ota_from_target_files = common.load_module_from_file('ota_from_target_files', filename)

from ota_from_target_files import *
import aries_edify_generator as edify_generator

__doc__ = ota_from_target_files.__doc__

def CopyBootFiles(input_zip, output_zip):
    output_zip.write(os.path.join(TARGET_DIR, "boot.img"),"boot.img")

def CopyBMLoverMTD(output_zip):
  """Copy the bml_over_mtd utility and script to the output."""
  output_zip.write(os.path.join(TARGET_DIR, "modem.bin"),"modem.bin")
  output_zip.write(os.path.join(UTILITIES_DIR, "make_ext4fs"),"make_ext4fs")
  output_zip.write(os.path.join(UTILITIES_DIR, "busybox"),"busybox")
  output_zip.write(os.path.join(UTILITIES_DIR, "flash_image"),"flash_image")
  output_zip.write(os.path.join(UTILITIES_DIR, "erase_image"),"erase_image")
  output_zip.write(os.path.join(UTILITIES_DIR, "bml_over_mtd"),"bml_over_mtd")
  output_zip.write(os.path.join(LOCAL_DIR, "bml_over_mtd.sh"),"bml_over_mtd.sh")
  output_zip.write(os.path.join(TARGET_DIR, "updater.sh"),"updater.sh")

def WriteFullOTAPackage(input_zip, output_zip):
  # TODO: how to determine this?  We don't know what version it will
  # be installed on top of.  For now, we expect the API just won't
  # change very often.
  script = edify_generator.EdifyGenerator(3, OPTIONS.info_dict)

  metadata = {"post-build": GetBuildProp("ro.build.fingerprint", input_zip),
              "pre-device": GetBuildProp("ro.product.device", input_zip),
              "post-timestamp": GetBuildProp("ro.build.date.utc", input_zip),
              }

  device_specific = common.DeviceSpecificParams(
      input_zip=input_zip,
      input_version=OPTIONS.info_dict["recovery_api_version"],
      output_zip=output_zip,
      script=script,
      input_tmp=OPTIONS.input_tmp,
      metadata=metadata,
      info_dict=OPTIONS.info_dict)

#  if not OPTIONS.omit_prereq:
#    ts = GetBuildProp("ro.build.date.utc", input_zip)
#    script.AssertOlderBuild(ts)

  # script.ShowProgress(0.15, 5) in device-specific assert as I could not get it to show up before it in here

  AppendAssertions(script, input_zip)
  device_specific.FullOTA_Assertions()

  if OPTIONS.backuptool:
    script.Mount("/system")
    script.RunBackup("backup")
    script.Unmount("/system")

  if OPTIONS.wipe_user_data:
    script.FormatPartition("/data")

  script.FormatPartition("/system")
  script.Mount("/system")
  script.ShowProgress(0.7, 30);
  script.UnpackPackageDir("recovery", "/system")
  script.UnpackPackageDir("system", "/system")

  (symlinks, retouch_files) = CopySystemFiles(input_zip, output_zip)
  script.MakeSymlinks(symlinks)

  if OPTIONS.aslr_mode:
    script.RetouchBinaries(retouch_files)
  else:
    script.UndoRetouchBinaries(retouch_files)

  Item.GetMetadata(input_zip)
  script.ShowProgress(0.15, 5)
  Item.Get("system").SetPermissions(script)

  if OPTIONS.backuptool:
    script.ShowProgress(0.2, 10)
    script.RunBackup("restore")

  if OPTIONS.modelidcfg:
    script.RunConfig("")

  CopyBootFiles(input_zip, output_zip)
  CopyBMLoverMTD(output_zip)

  device_specific.FullOTA_InstallEnd()

  if OPTIONS.extra_script is not None:
    script.AppendExtra(OPTIONS.extra_script)

  script.UnmountAll()
  script.AddToZip(input_zip, output_zip)
  WriteMetadata(metadata, output_zip)
ota_from_target_files.WriteFullOTAPackage = WriteFullOTAPackage


def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):
    print "Incremental OTA Packages are not support on the Samsung Galaxy S at this time"
    sys.exit(1)
ota_from_target_files.WriteIncrementalOTAPackage = WriteIncrementalOTAPackage


if __name__ == '__main__':
  try:
    main(sys.argv[1:])
  except common.ExternalError, e:
    print
    print "   ERROR: %s" % (e,)
    print
    sys.exit(1)