blob: 1497d69ed78b1fbd26393088525a2fb71d4cd27b [file] [log] [blame]
Doug Zongkerc9253822014-02-04 12:17:58 -08001#!/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 Bao89fbb0f2017-01-10 10:47:58 -080017from __future__ import print_function
18
Tao Bao32fcdab2018-10-12 10:30:39 -070019import logging
20import os
Doug Zongkerc9253822014-02-04 12:17:58 -080021import sys
22
Tao Bao32fcdab2018-10-12 10:30:39 -070023import common
24
Doug Zongkercf6d5a92014-02-18 10:57:07 -080025if sys.hexversion < 0x02070000:
Tao Bao89fbb0f2017-01-10 10:47:58 -080026 print("Python 2.7 or newer is required.", file=sys.stderr)
Doug Zongkerc9253822014-02-04 12:17:58 -080027 sys.exit(1)
28
Tao Bao32fcdab2018-10-12 10:30:39 -070029logger = logging.getLogger(__name__)
Doug Zongkerc9253822014-02-04 12:17:58 -080030
31OPTIONS = common.OPTIONS
32
Doug Zongkerc9253822014-02-04 12:17:58 -080033
Tao Bao32fcdab2018-10-12 10:30:39 -070034def main(argv):
Doug Zongkerc9253822014-02-04 12:17:58 -080035 args = common.ParseOptions(argv, __doc__)
36 input_dir, output_dir = args
37
Tao Bao32fcdab2018-10-12 10:30:39 -070038 common.InitLogging()
39
Doug Zongkerc9253822014-02-04 12:17:58 -080040 OPTIONS.info_dict = common.LoadInfoDict(input_dir)
41
42 recovery_img = common.GetBootableImage("recovery.img", "recovery.img",
43 input_dir, "RECOVERY")
44 boot_img = common.GetBootableImage("boot.img", "boot.img",
45 input_dir, "BOOT")
46
Ying Wangd89ffa82014-02-05 11:28:51 -080047 if not recovery_img or not boot_img:
48 sys.exit(0)
49
Bill Peckhame868aec2019-09-17 17:06:47 -070050 board_uses_vendorimage = OPTIONS.info_dict.get(
51 "board_uses_vendorimage") == "true"
52
53 if board_uses_vendorimage:
54 target_files_dir = "VENDOR"
55 else:
56 target_files_dir = "SYSTEM"
57
Doug Zongkerc9253822014-02-04 12:17:58 -080058 def output_sink(fn, data):
Bill Peckhame868aec2019-09-17 17:06:47 -070059 with open(os.path.join(output_dir, target_files_dir,
60 *fn.split("/")), "wb") as f:
Doug Zongkerc9253822014-02-04 12:17:58 -080061 f.write(data)
62
63 common.MakeRecoveryPatch(input_dir, output_sink, recovery_img, boot_img)
64
65
66if __name__ == '__main__':
67 main(sys.argv[1:])