Doug Zongker | c925382 | 2014-02-04 12:17:58 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (C) 2014 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Tao Bao | 89fbb0f | 2017-01-10 10:47:58 -0800 | [diff] [blame] | 17 | from __future__ import print_function |
| 18 | |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 19 | import logging |
| 20 | import os |
Doug Zongker | c925382 | 2014-02-04 12:17:58 -0800 | [diff] [blame] | 21 | import sys |
| 22 | |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 23 | import common |
Kelvin Zhang | 513b86e | 2023-10-27 13:27:07 -0700 | [diff] [blame] | 24 | from non_ab_ota import MakeRecoveryPatch |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 25 | |
Doug Zongker | cf6d5a9 | 2014-02-18 10:57:07 -0800 | [diff] [blame] | 26 | if sys.hexversion < 0x02070000: |
Tao Bao | 89fbb0f | 2017-01-10 10:47:58 -0800 | [diff] [blame] | 27 | print("Python 2.7 or newer is required.", file=sys.stderr) |
Doug Zongker | c925382 | 2014-02-04 12:17:58 -0800 | [diff] [blame] | 28 | sys.exit(1) |
| 29 | |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 30 | logger = logging.getLogger(__name__) |
Doug Zongker | c925382 | 2014-02-04 12:17:58 -0800 | [diff] [blame] | 31 | |
| 32 | OPTIONS = common.OPTIONS |
| 33 | |
Doug Zongker | c925382 | 2014-02-04 12:17:58 -0800 | [diff] [blame] | 34 | |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 35 | def main(argv): |
Doug Zongker | c925382 | 2014-02-04 12:17:58 -0800 | [diff] [blame] | 36 | args = common.ParseOptions(argv, __doc__) |
| 37 | input_dir, output_dir = args |
| 38 | |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 39 | common.InitLogging() |
| 40 | |
Doug Zongker | c925382 | 2014-02-04 12:17:58 -0800 | [diff] [blame] | 41 | OPTIONS.info_dict = common.LoadInfoDict(input_dir) |
| 42 | |
| 43 | recovery_img = common.GetBootableImage("recovery.img", "recovery.img", |
| 44 | input_dir, "RECOVERY") |
| 45 | boot_img = common.GetBootableImage("boot.img", "boot.img", |
| 46 | input_dir, "BOOT") |
| 47 | |
Ying Wang | d89ffa8 | 2014-02-05 11:28:51 -0800 | [diff] [blame] | 48 | if not recovery_img or not boot_img: |
| 49 | sys.exit(0) |
| 50 | |
Bill Peckham | e868aec | 2019-09-17 17:06:47 -0700 | [diff] [blame] | 51 | board_uses_vendorimage = OPTIONS.info_dict.get( |
| 52 | "board_uses_vendorimage") == "true" |
| 53 | |
| 54 | if board_uses_vendorimage: |
| 55 | target_files_dir = "VENDOR" |
| 56 | else: |
| 57 | target_files_dir = "SYSTEM" |
| 58 | |
Doug Zongker | c925382 | 2014-02-04 12:17:58 -0800 | [diff] [blame] | 59 | def output_sink(fn, data): |
Bill Peckham | e868aec | 2019-09-17 17:06:47 -0700 | [diff] [blame] | 60 | with open(os.path.join(output_dir, target_files_dir, |
| 61 | *fn.split("/")), "wb") as f: |
Doug Zongker | c925382 | 2014-02-04 12:17:58 -0800 | [diff] [blame] | 62 | f.write(data) |
| 63 | |
Kelvin Zhang | 513b86e | 2023-10-27 13:27:07 -0700 | [diff] [blame] | 64 | MakeRecoveryPatch(input_dir, output_sink, recovery_img, boot_img) |
Doug Zongker | c925382 | 2014-02-04 12:17:58 -0800 | [diff] [blame] | 65 | |
| 66 | |
| 67 | if __name__ == '__main__': |
| 68 | main(sys.argv[1:]) |