Suren Baghdasaryan | 42fa0e2 | 2017-08-28 14:39:54 -0700 | [diff] [blame] | 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # |
| 3 | # Copyright (C) 2015, ARM Limited and contributors. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # 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, WITHOUT |
| 13 | # 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 | # |
| 17 | |
| 18 | import logging |
| 19 | import os |
| 20 | from collections import namedtuple |
| 21 | |
| 22 | class Build(object): |
| 23 | BuildParams = namedtuple("BuildParams", "arch defconfig cross_compile") |
| 24 | |
| 25 | device_kernel_build_params = { |
| 26 | 'hikey960': BuildParams('arm64', 'hikey960_defconfig', 'aarch64-linux-android-'), |
| 27 | 'hikey': BuildParams('arm64', 'hikey_defconfig', 'aarch64-linux-android-') |
| 28 | } |
| 29 | |
| 30 | """ |
| 31 | Collection of Android related build actions |
| 32 | """ |
| 33 | def __init__(self, te): |
| 34 | if (te.ANDROID_BUILD_TOP and te.TARGET_PRODUCT and te.TARGET_BUILD_VARIANT): |
| 35 | self._te = te |
| 36 | else: |
| 37 | te._log.warning('Build initialization failed: invalid paramterers') |
| 38 | raise |
| 39 | |
| 40 | def build_module(self, module_path): |
| 41 | """ |
| 42 | Build a module and its dependencies. |
| 43 | |
| 44 | :param module_path: module path |
| 45 | :type module_path: str |
| 46 | |
| 47 | """ |
| 48 | self._te._log.info('BUILDING module %s', module_path) |
| 49 | cur_dir = os.getcwd() |
| 50 | os.chdir(self._te.ANDROID_BUILD_TOP) |
| 51 | lunch_target = self._te.TARGET_PRODUCT + '-' + self._te.TARGET_BUILD_VARIANT |
| 52 | os.system('source build/envsetup.sh && lunch ' + |
| 53 | lunch_target + ' && mmma -j16 ' + module_path) |
| 54 | os.chdir(cur_dir) |
| 55 | |
| 56 | |
| 57 | def build_kernel(self, kernel_path, arch, defconfig, cross_compile, clean=False): |
| 58 | """ |
| 59 | Build kernel. |
| 60 | |
| 61 | :param kernel_path: path to kernel sources |
| 62 | :type kernel_path: str |
| 63 | |
| 64 | :param arch: device architecture string used in ARCH command line parameter |
| 65 | :type arch: str |
| 66 | |
| 67 | :param defconfig: defconfig file name |
| 68 | :type defconfig: str |
| 69 | |
| 70 | :param cross_compile: compiler string used in CROSS_COMPILE command line parameter |
| 71 | :type cross_compile: str |
| 72 | |
| 73 | :param clean: flag to clean the previous build |
| 74 | :type clean: boolean |
| 75 | |
| 76 | """ |
| 77 | self._te._log.info('BUILDING kernel @ %s', kernel_path) |
| 78 | cur_dir = os.getcwd() |
| 79 | os.chdir(kernel_path) |
| 80 | os.system('. ./build.config') |
| 81 | if clean: |
| 82 | os.system('make clean') |
| 83 | os.system('make ARCH=' + arch + ' ' + defconfig) |
| 84 | os.system('make -j24 ARCH=' + arch + ' CROSS_COMPILE=' + cross_compile) |
| 85 | os.chdir(cur_dir) |
| 86 | |
| 87 | def build_kernel_for_device(self, kernel_path, device_name, clean): |
| 88 | """ |
| 89 | Build kernel for specified device. |
| 90 | |
| 91 | :param kernel_path: path to kernel sources |
| 92 | :type kernel_path: str |
| 93 | |
| 94 | :param device_name: device name |
| 95 | :type device_name: str |
| 96 | |
| 97 | :param clean: flag to clean the previous build |
| 98 | :type clean: boolean |
| 99 | |
| 100 | """ |
| 101 | if not device_name in self.device_kernel_build_params: |
| 102 | return False |
| 103 | |
| 104 | params = self.device_kernel_build_params[device_name] |
| 105 | self.build_kernel(kernel_path, params.arch, |
| 106 | params.defconfig, params.cross_compile, clean) |
| 107 | return True |
| 108 | |
| 109 | |
| 110 | # vim :set tabstop=4 shiftwidth=4 expandtab |