1# Copyright (C) 2012 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 extra commands needed for Group during OTA installation
16(installing the bootloader)."""
17
18import common
19
20def FullOTA_InstallEnd(info):
21  try:
22    bootloader_bin = info.input_zip.read("RADIO/bootloader.raw")
23  except KeyError:
24    print "no bootloader.raw in target_files; skipping install"
25  else:
26    WriteBootloader(info, bootloader_bin)
27
28def IncrementalOTA_InstallBegin(info):
29  info.script.Unmount("/system")
30  info.script.TunePartition("/system", "-O", "^has_journal")
31  info.script.Mount("/system")
32
33def IncrementalOTA_InstallEnd(info):
34  try:
35    target_bootloader_bin = info.target_zip.read("RADIO/bootloader.raw")
36    try:
37      source_bootloader_bin = info.source_zip.read("RADIO/bootloader.raw")
38    except KeyError:
39      source_bootloader_bin = None
40
41    if source_bootloader_bin == target_bootloader_bin:
42      print "bootloader unchanged; skipping"
43    else:
44      WriteBootloader(info, target_bootloader_bin)
45  except KeyError:
46    print "no bootloader.raw in target target_files; skipping install"
47
48
49def WriteBootloader(info, bootloader_bin):
50  common.ZipWriteStr(info.output_zip, "bootloader.raw", bootloader_bin)
51  fstab = info.info_dict["fstab"]
52
53  info.script.Print("Writing bootloader...")
54
55  info.script.AppendExtra('''package_extract_file("bootloader.raw", "%s");''' %
56                          (fstab["/staging"].device,))
57