| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2016 The CyanogenMod 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 | # |
| 17 | |
| 18 | PRODUCT_COPY_FILES_LIST=() |
| 19 | PRODUCT_COPY_FILES_HASHES=() |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 20 | PRODUCT_COPY_FILES_FIXUP_HASHES=() |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 21 | PRODUCT_PACKAGES_LIST=() |
| 22 | PRODUCT_PACKAGES_HASHES=() |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 23 | PRODUCT_PACKAGES_FIXUP_HASHES=() |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 24 | PRODUCT_SYMLINKS_LIST=() |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 25 | PACKAGE_LIST=() |
| SamarV-121 | 7e6b408 | 2024-02-26 14:39:34 +0530 | [diff] [blame] | 26 | REQUIRED_PACKAGES_LIST= |
| Michael Bestas | f458ca0 | 2023-06-12 14:20:28 +0300 | [diff] [blame] | 27 | EXTRACT_SRC= |
| 28 | EXTRACT_STATE=-1 |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 29 | VENDOR_STATE=-1 |
| 30 | VENDOR_RADIO_STATE=-1 |
| 31 | COMMON=-1 |
| 32 | ARCHES= |
| 33 | FULLY_DEODEXED=-1 |
| 34 | |
| Michael Bestas | fc97f2d | 2023-06-12 13:53:31 +0300 | [diff] [blame] | 35 | KEEP_DUMP=${KEEP_DUMP:-0} |
| Chirayu Desai | 51ddd8d | 2022-05-26 14:50:35 +0530 | [diff] [blame] | 36 | SKIP_CLEANUP=${SKIP_CLEANUP:-0} |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 37 | EXTRACT_TMP_DIR=$(mktemp -d) |
| Volodymyr Zhdanov | e54a159 | 2020-10-22 01:33:24 +0300 | [diff] [blame] | 38 | HOST="$(uname | tr '[:upper:]' '[:lower:]')" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 39 | |
| 40 | # |
| 41 | # cleanup |
| 42 | # |
| 43 | # kill our tmpfiles with fire on exit |
| 44 | # |
| 45 | function cleanup() { |
| Chirayu Desai | 51ddd8d | 2022-05-26 14:50:35 +0530 | [diff] [blame] | 46 | if [ "$SKIP_CLEANUP" == "true" ] || [ "$SKIP_CLEANUP" == "1" ]; then |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 47 | echo "Skipping cleanup of $EXTRACT_TMP_DIR" |
| Chirayu Desai | 51ddd8d | 2022-05-26 14:50:35 +0530 | [diff] [blame] | 48 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 49 | rm -rf "${EXTRACT_TMP_DIR:?}" |
| Chirayu Desai | 51ddd8d | 2022-05-26 14:50:35 +0530 | [diff] [blame] | 50 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| Gabriele M | b8e5457 | 2017-10-11 12:55:51 +0200 | [diff] [blame] | 53 | trap cleanup 0 |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 54 | |
| 55 | # |
| Chirayu Desai | 795ce32 | 2022-04-05 03:32:25 +0530 | [diff] [blame] | 56 | # setup_vendor_deps |
| 57 | # |
| 58 | # $1: Android root directory |
| 59 | # Sets up common dependencies for extraction |
| 60 | # |
| 61 | function setup_vendor_deps() { |
| 62 | export ANDROID_ROOT="$1" |
| 63 | if [ ! -d "$ANDROID_ROOT" ]; then |
| 64 | echo "\$ANDROID_ROOT must be set and valid before including this script!" |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
| 68 | export BINARIES_LOCATION="$ANDROID_ROOT"/vendor/omni/build/tools/${HOST}/bin |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 69 | export CLANG_BINUTILS="$ANDROID_ROOT"/prebuilts/clang/host/${HOST}-x86/llvm-binutils-stable |
| Chirayu Desai | 795ce32 | 2022-04-05 03:32:25 +0530 | [diff] [blame] | 70 | |
| 71 | export SIMG2IMG="$BINARIES_LOCATION"/simg2img |
| 72 | export LPUNPACK="$BINARIES_LOCATION"/lpunpack |
| 73 | export OTA_EXTRACTOR="$BINARIES_LOCATION"/ota_extractor |
| 74 | export SIGSCAN="$BINARIES_LOCATION"/SigScan |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 75 | export OBJDUMP="$CLANG_BINUTILS"/llvm-objdump |
| Chirayu Desai | 795ce32 | 2022-04-05 03:32:25 +0530 | [diff] [blame] | 76 | |
| 77 | for version in 0_8 0_9 0_17_2; do |
| 78 | export PATCHELF_${version}="$BINARIES_LOCATION"/patchelf-"${version}" |
| 79 | done |
| 80 | |
| 81 | if [ -z "$PATCHELF_VERSION" ]; then |
| 82 | export PATCHELF_VERSION=0_9 |
| 83 | fi |
| 84 | |
| 85 | if [ -z "$PATCHELF" ]; then |
| 86 | local patchelf_variable="PATCHELF_${PATCHELF_VERSION}" |
| 87 | export PATCHELF=${!patchelf_variable} |
| 88 | fi |
| 89 | } |
| 90 | |
| 91 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 92 | # setup_vendor |
| 93 | # |
| 94 | # $1: device name |
| 95 | # $2: vendor name |
| Michael Bestas | 6d90893 | 2020-12-19 03:29:25 +0200 | [diff] [blame] | 96 | # $3: Android root directory |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 97 | # $4: is common device - optional, default to false |
| 98 | # $5: cleanup - optional, default to true |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 99 | # $6: custom vendor makefile name - optional, default to false |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 100 | # |
| 101 | # Must be called before any other functions can be used. This |
| 102 | # sets up the internal state for a new vendor configuration. |
| 103 | # |
| 104 | function setup_vendor() { |
| 105 | local DEVICE="$1" |
| 106 | if [ -z "$DEVICE" ]; then |
| 107 | echo "\$DEVICE must be set before including this script!" |
| 108 | exit 1 |
| 109 | fi |
| 110 | |
| 111 | export VENDOR="$2" |
| 112 | if [ -z "$VENDOR" ]; then |
| 113 | echo "\$VENDOR must be set before including this script!" |
| 114 | exit 1 |
| 115 | fi |
| 116 | |
| Michael Bestas | 6d90893 | 2020-12-19 03:29:25 +0200 | [diff] [blame] | 117 | export ANDROID_ROOT="$3" |
| 118 | if [ ! -d "$ANDROID_ROOT" ]; then |
| 119 | echo "\$ANDROID_ROOT must be set and valid before including this script!" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 120 | exit 1 |
| 121 | fi |
| 122 | |
| 123 | export OUTDIR=vendor/"$VENDOR"/"$DEVICE" |
| Michael Bestas | 6d90893 | 2020-12-19 03:29:25 +0200 | [diff] [blame] | 124 | if [ ! -d "$ANDROID_ROOT/$OUTDIR" ]; then |
| 125 | mkdir -p "$ANDROID_ROOT/$OUTDIR" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 126 | fi |
| 127 | |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 128 | VNDNAME="$6" |
| 129 | if [ -z "$VNDNAME" ]; then |
| 130 | VNDNAME="$DEVICE" |
| 131 | fi |
| 132 | |
| Michael Bestas | 6d90893 | 2020-12-19 03:29:25 +0200 | [diff] [blame] | 133 | export PRODUCTMK="$ANDROID_ROOT"/"$OUTDIR"/"$VNDNAME"-vendor.mk |
| 134 | export ANDROIDBP="$ANDROID_ROOT"/"$OUTDIR"/Android.bp |
| 135 | export ANDROIDMK="$ANDROID_ROOT"/"$OUTDIR"/Android.mk |
| Michael Bestas | 6d90893 | 2020-12-19 03:29:25 +0200 | [diff] [blame] | 136 | export BOARDMK="$ANDROID_ROOT"/"$OUTDIR"/BoardConfigVendor.mk |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 137 | |
| 138 | if [ "$4" == "true" ] || [ "$4" == "1" ]; then |
| 139 | COMMON=1 |
| 140 | else |
| 141 | COMMON=0 |
| 142 | fi |
| 143 | |
| Gabriele M | c44696d | 2017-05-01 18:22:04 +0200 | [diff] [blame] | 144 | if [ "$5" == "false" ] || [ "$5" == "0" ]; then |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 145 | VENDOR_STATE=1 |
| 146 | VENDOR_RADIO_STATE=1 |
| 147 | else |
| 148 | VENDOR_STATE=0 |
| 149 | VENDOR_RADIO_STATE=0 |
| 150 | fi |
| Volodymyr Zhdanov | e54a159 | 2020-10-22 01:33:24 +0300 | [diff] [blame] | 151 | |
| Chirayu Desai | 795ce32 | 2022-04-05 03:32:25 +0530 | [diff] [blame] | 152 | setup_vendor_deps "$ANDROID_ROOT" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| Vladimir Oltean | 75d8e05 | 2018-06-24 20:22:41 +0300 | [diff] [blame] | 155 | # Helper functions for parsing a spec. |
| 156 | # notes: an optional "|SHA1" that may appear in the format is stripped |
| 157 | # early from the spec in the parse_file_list function, and |
| 158 | # should not be present inside the input parameter passed |
| 159 | # to these functions. |
| 160 | |
| 161 | # |
| 162 | # input: spec in the form of "src[:dst][;args]" |
| 163 | # output: "src" |
| 164 | # |
| 165 | function src_file() { |
| 166 | local SPEC="$1" |
| 167 | local SPLIT=(${SPEC//:/ }) |
| 168 | local ARGS="$(target_args ${SPEC})" |
| 169 | # Regardless of there being a ":" delimiter or not in the spec, |
| 170 | # the source file is always either the first, or the only entry. |
| 171 | local SRC="${SPLIT[0]}" |
| 172 | # Remove target_args suffix, if present |
| 173 | echo "${SRC%;${ARGS}}" |
| 174 | } |
| 175 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 176 | # |
| Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 177 | # input: spec in the form of "src[:dst][;args]" |
| 178 | # output: "dst" if present, "src" otherwise. |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 179 | # |
| 180 | function target_file() { |
| dianlujitao | 4918b8a | 2020-01-02 15:26:44 +0800 | [diff] [blame] | 181 | local SPEC="${1%%;*}" |
| Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 182 | local SPLIT=(${SPEC//:/ }) |
| 183 | local ARGS="$(target_args ${SPEC})" |
| 184 | local DST= |
| 185 | case ${#SPLIT[@]} in |
| 186 | 1) |
| 187 | # The spec doesn't have a : delimiter |
| 188 | DST="${SPLIT[0]}" |
| 189 | ;; |
| 190 | *) |
| 191 | # The spec actually has a src:dst format |
| 192 | DST="${SPLIT[1]}" |
| 193 | ;; |
| 194 | esac |
| 195 | # Remove target_args suffix, if present |
| 196 | echo "${DST%;${ARGS}}" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | # |
| Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 200 | # input: spec in the form of "src[:dst][;args]" |
| 201 | # output: "args" if present, "" otherwise. |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 202 | # |
| 203 | function target_args() { |
| Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 204 | local SPEC="$1" |
| 205 | local SPLIT=(${SPEC//;/ }) |
| 206 | local ARGS= |
| 207 | case ${#SPLIT[@]} in |
| 208 | 1) |
| 209 | # No ";" delimiter in the spec. |
| 210 | ;; |
| 211 | *) |
| 212 | # The "args" are whatever comes after the ";" character. |
| 213 | # Basically the spec stripped of whatever is to the left of ";". |
| 214 | ARGS="${SPEC#${SPLIT[0]};}" |
| 215 | ;; |
| 216 | esac |
| 217 | echo "${ARGS}" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | # |
| 221 | # prefix_match: |
| 222 | # |
| Vladimir Oltean | 011b6b6 | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 223 | # input: |
| 224 | # - $1: prefix |
| 225 | # - (global variable) PRODUCT_PACKAGES_LIST: array of [src:]dst[;args] specs. |
| 226 | # output: |
| 227 | # - new array consisting of dst[;args] entries where $1 is a prefix of ${dst}. |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 228 | # |
| 229 | function prefix_match() { |
| 230 | local PREFIX="$1" |
| Sebastiano Barezzi | df527c7 | 2022-03-25 16:59:58 +0100 | [diff] [blame] | 231 | local NEW_ARRAY=() |
| Vladimir Oltean | 7220f36 | 2018-04-02 22:37:09 +0300 | [diff] [blame] | 232 | for LINE in "${PRODUCT_PACKAGES_LIST[@]}"; do |
| 233 | local FILE=$(target_file "$LINE") |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 234 | if [[ "$FILE" =~ ^"$PREFIX" ]]; then |
| Vladimir Oltean | 011b6b6 | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 235 | local ARGS=$(target_args "$LINE") |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 236 | if [[ -z "${ARGS}" || "${ARGS}" =~ 'SYMLINK' ]]; then |
| Sebastiano Barezzi | df527c7 | 2022-03-25 16:59:58 +0100 | [diff] [blame] | 237 | NEW_ARRAY+=("${FILE#$PREFIX}") |
| Vladimir Oltean | 011b6b6 | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 238 | else |
| Sebastiano Barezzi | df527c7 | 2022-03-25 16:59:58 +0100 | [diff] [blame] | 239 | NEW_ARRAY+=("${FILE#$PREFIX};${ARGS}") |
| Vladimir Oltean | 011b6b6 | 2018-06-12 01:17:35 +0300 | [diff] [blame] | 240 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 241 | fi |
| 242 | done |
| Sebastiano Barezzi | df527c7 | 2022-03-25 16:59:58 +0100 | [diff] [blame] | 243 | printf '%s\n' "${NEW_ARRAY[@]}" | LC_ALL=C sort |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | # |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 247 | # prefix_match_file: |
| 248 | # |
| 249 | # $1: the prefix to match on |
| 250 | # $2: the file to match the prefix for |
| 251 | # |
| 252 | # Internal function which returns true if a filename contains the |
| 253 | # specified prefix. |
| 254 | # |
| 255 | function prefix_match_file() { |
| 256 | local PREFIX="$1" |
| 257 | local FILE="$2" |
| 258 | if [[ "$FILE" =~ ^"$PREFIX" ]]; then |
| 259 | return 0 |
| 260 | else |
| 261 | return 1 |
| 262 | fi |
| 263 | } |
| 264 | |
| 265 | # |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 266 | # suffix_match_file: |
| 267 | # |
| 268 | # $1: the suffix to match on |
| 269 | # $2: the file to match the suffix for |
| 270 | # |
| 271 | # Internal function which returns true if a filename contains the |
| 272 | # specified suffix. |
| 273 | # |
| 274 | function suffix_match_file() { |
| 275 | local SUFFIX="$1" |
| 276 | local FILE="$2" |
| 277 | if [[ "$FILE" = *"$SUFFIX" ]]; then |
| 278 | return 0 |
| 279 | else |
| 280 | return 1 |
| 281 | fi |
| 282 | } |
| 283 | |
| 284 | # |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 285 | # truncate_file |
| 286 | # |
| 287 | # $1: the filename to truncate |
| 288 | # $2: the argument to output the truncated filename to |
| 289 | # |
| 290 | # Internal function which truncates a filename by removing the first dir |
| 291 | # in the path. ex. vendor/lib/libsdmextension.so -> lib/libsdmextension.so |
| 292 | # |
| 293 | function truncate_file() { |
| 294 | local FILE="$1" |
| 295 | RETURN_FILE="$2" |
| 296 | local FIND="${FILE%%/*}" |
| 297 | local LOCATION="${#FIND}+1" |
| 298 | echo ${FILE:$LOCATION} |
| 299 | } |
| 300 | |
| 301 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 302 | # write_product_copy_files: |
| 303 | # |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 304 | # $1: make treble compatible makefile - optional and deprecated, default to true |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 305 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 306 | # Creates the PRODUCT_COPY_FILES section in the product makefile for all |
| 307 | # items in the list which do not start with a dash (-). |
| 308 | # |
| 309 | function write_product_copy_files() { |
| 310 | local COUNT=${#PRODUCT_COPY_FILES_LIST[@]} |
| 311 | local TARGET= |
| 312 | local FILE= |
| 313 | local LINEEND= |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 314 | local TREBLE_COMPAT=$1 |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 315 | |
| 316 | if [ "$COUNT" -eq "0" ]; then |
| 317 | return 0 |
| 318 | fi |
| 319 | |
| 320 | printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK" |
| 321 | for (( i=1; i<COUNT+1; i++ )); do |
| 322 | FILE="${PRODUCT_COPY_FILES_LIST[$i-1]}" |
| 323 | LINEEND=" \\" |
| 324 | if [ "$i" -eq "$COUNT" ]; then |
| 325 | LINEEND="" |
| 326 | fi |
| 327 | |
| Vladimir Oltean | c70bc12 | 2018-06-24 20:09:55 +0300 | [diff] [blame] | 328 | TARGET=$(target_file "$FILE") |
| Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 329 | if prefix_match_file "product/" $TARGET ; then |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 330 | local OUTTARGET=$(truncate_file $TARGET) |
| Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 331 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \ |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 332 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 333 | elif prefix_match_file "system/product/" $TARGET ; then |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 334 | local OUTTARGET=$(truncate_file $TARGET) |
| 335 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \ |
| 336 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 337 | elif prefix_match_file "system_ext/" $TARGET ; then |
| 338 | local OUTTARGET=$(truncate_file $TARGET) |
| 339 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \ |
| 340 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 341 | elif prefix_match_file "system/system_ext/" $TARGET ; then |
| 342 | local OUTTARGET=$(truncate_file $TARGET) |
| 343 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \ |
| 344 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 345 | elif prefix_match_file "odm/" $TARGET ; then |
| 346 | local OUTTARGET=$(truncate_file $TARGET) |
| 347 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \ |
| 348 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 349 | elif prefix_match_file "vendor/odm/" $TARGET ; then |
| 350 | local OUTTARGET=$(truncate_file $TARGET) |
| 351 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \ |
| 352 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 353 | elif prefix_match_file "system/vendor/odm/" $TARGET ; then |
| 354 | local OUTTARGET=$(truncate_file $TARGET) |
| 355 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \ |
| 356 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 357 | elif prefix_match_file "vendor/" $TARGET ; then |
| 358 | local OUTTARGET=$(truncate_file $TARGET) |
| 359 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \ |
| 360 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Alexander Koskovich | 44c8fac | 2022-01-22 22:27:29 -0700 | [diff] [blame] | 361 | elif prefix_match_file "vendor_dlkm/" $TARGET ; then |
| 362 | local OUTTARGET=$(truncate_file $TARGET) |
| 363 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR_DLKM)/%s%s\n' \ |
| 364 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | 06688fc | 2019-10-05 00:09:41 -0400 | [diff] [blame] | 365 | elif prefix_match_file "system/vendor/" $TARGET ; then |
| 366 | local OUTTARGET=$(truncate_file $TARGET) |
| 367 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \ |
| 368 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 369 | elif prefix_match_file "system/" $TARGET ; then |
| 370 | local OUTTARGET=$(truncate_file $TARGET) |
| 371 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \ |
| 372 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Mohd Faraz | d683fe4 | 2022-07-23 14:33:59 +0200 | [diff] [blame] | 373 | elif prefix_match_file "recovery/" $TARGET ; then |
| 374 | local OUTTARGET=$(truncate_file $TARGET) |
| 375 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_RECOVERY)/%s%s\n' \ |
| 376 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| 377 | elif prefix_match_file "vendor_ramdisk/" $TARGET ; then |
| 378 | local OUTTARGET=$(truncate_file $TARGET) |
| 379 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR_RAMDISK)/%s%s\n' \ |
| 380 | "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK" |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 381 | else |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 382 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \ |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 383 | "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK" |
| 384 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 385 | done |
| 386 | return 0 |
| 387 | } |
| 388 | |
| 389 | # |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 390 | # write_blueprint_packages: |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 391 | # |
| 392 | # $1: The LOCAL_MODULE_CLASS for the given module list |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 393 | # $2: /system, /odm, /product, /system_ext, or /vendor partition |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 394 | # $3: type-specific extra flags |
| 395 | # $4: Name of the array holding the target list |
| 396 | # |
| 397 | # Internal function which writes out the BUILD_PREBUILT stanzas |
| 398 | # for all modules in the list. This is called by write_product_packages |
| 399 | # after the modules are categorized. |
| 400 | # |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 401 | function write_blueprint_packages() { |
| 402 | |
| 403 | local CLASS="$1" |
| 404 | local PARTITION="$2" |
| 405 | local EXTRA="$3" |
| 406 | |
| 407 | # Yes, this is a horrible hack - we create a new array using indirection |
| 408 | local ARR_NAME="$4[@]" |
| 409 | local FILELIST=("${!ARR_NAME}") |
| 410 | |
| 411 | local FILE= |
| 412 | local ARGS= |
| 413 | local BASENAME= |
| 414 | local EXTENSION= |
| 415 | local PKGNAME= |
| 416 | local SRC= |
| Tim Zimmermann | d932076 | 2021-12-23 07:06:17 +0100 | [diff] [blame] | 417 | local STEM= |
| TheStrix | 6e24acc | 2020-04-10 18:20:19 +0530 | [diff] [blame] | 418 | local OVERRIDEPKG= |
| SamarV-121 | 7e6b408 | 2024-02-26 14:39:34 +0530 | [diff] [blame] | 419 | local REQUIREDPKG= |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 420 | local DISABLE_CHECKELF= |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 421 | |
| 422 | for P in "${FILELIST[@]}"; do |
| 423 | FILE=$(target_file "$P") |
| 424 | ARGS=$(target_args "$P") |
| Tim Zimmermann | d932076 | 2021-12-23 07:06:17 +0100 | [diff] [blame] | 425 | ARGS=(${ARGS//;/ }) |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 426 | |
| 427 | BASENAME=$(basename "$FILE") |
| 428 | DIRNAME=$(dirname "$FILE") |
| 429 | EXTENSION=${BASENAME##*.} |
| 430 | PKGNAME=${BASENAME%.*} |
| 431 | |
| Tim Zimmermann | e93bb1b | 2021-12-23 10:15:26 +0100 | [diff] [blame] | 432 | if [ "$CLASS" = "EXECUTABLES" ] && [ "$EXTENSION" != "sh" ]; then |
| 433 | PKGNAME="$BASENAME" |
| 434 | EXTENSION="" |
| 435 | fi |
| 436 | |
| Tim Zimmermann | d932076 | 2021-12-23 07:06:17 +0100 | [diff] [blame] | 437 | # Allow overriding module name |
| 438 | STEM= |
| Aaron Kling | 7f4d181 | 2023-11-02 16:04:22 -0500 | [diff] [blame] | 439 | if [ "$TARGET_ENABLE_CHECKELF" == "true" ]; then |
| 440 | DISABLE_CHECKELF= |
| 441 | else |
| 442 | DISABLE_CHECKELF="true" |
| 443 | fi |
| Tim Zimmermann | d932076 | 2021-12-23 07:06:17 +0100 | [diff] [blame] | 444 | for ARG in "${ARGS[@]}"; do |
| 445 | if [[ "$ARG" =~ "MODULE" ]]; then |
| 446 | STEM="$PKGNAME" |
| 447 | PKGNAME=${ARG#*=} |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 448 | elif [[ "$ARG" == "DISABLE_CHECKELF" ]]; then |
| 449 | DISABLE_CHECKELF="true" |
| Tim Zimmermann | d932076 | 2021-12-23 07:06:17 +0100 | [diff] [blame] | 450 | fi |
| 451 | done |
| 452 | |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 453 | # Add to final package list |
| 454 | PACKAGE_LIST+=("$PKGNAME") |
| 455 | |
| 456 | SRC="proprietary" |
| 457 | if [ "$PARTITION" = "system" ]; then |
| 458 | SRC+="/system" |
| 459 | elif [ "$PARTITION" = "vendor" ]; then |
| 460 | SRC+="/vendor" |
| 461 | elif [ "$PARTITION" = "product" ]; then |
| 462 | SRC+="/product" |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 463 | elif [ "$PARTITION" = "system_ext" ]; then |
| 464 | SRC+="/system_ext" |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 465 | elif [ "$PARTITION" = "odm" ]; then |
| 466 | SRC+="/odm" |
| 467 | fi |
| 468 | |
| 469 | if [ "$CLASS" = "SHARED_LIBRARIES" ]; then |
| 470 | printf 'cc_prebuilt_library_shared {\n' |
| 471 | printf '\tname: "%s",\n' "$PKGNAME" |
| Tim Zimmermann | d932076 | 2021-12-23 07:06:17 +0100 | [diff] [blame] | 472 | if [ ! -z "$STEM" ]; then |
| 473 | printf '\tstem: "%s",\n' "$STEM" |
| 474 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 475 | printf '\towner: "%s",\n' "$VENDOR" |
| 476 | printf '\tstrip: {\n' |
| 477 | printf '\t\tnone: true,\n' |
| 478 | printf '\t},\n' |
| 479 | printf '\ttarget: {\n' |
| 480 | if [ "$EXTRA" = "both" ]; then |
| 481 | printf '\t\tandroid_arm: {\n' |
| 482 | printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE" |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 483 | if [ -z "$DISABLE_CHECKELF" ]; then |
| 484 | printf '\t\t\tshared_libs: [%s],\n' "$(basename -s .so $(${OBJDUMP} -x "$ANDROID_ROOT"/"$OUTDIR"/"$SRC"/lib/"$FILE" 2>/dev/null |grep NEEDED) 2>/dev/null |grep -v ^NEEDED$ |sed 's/-3.9.1//g' |sed 's/\(.*\)/"\1",/g' |tr '\n' ' ')" |
| 485 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 486 | printf '\t\t},\n' |
| 487 | printf '\t\tandroid_arm64: {\n' |
| 488 | printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE" |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 489 | if [ -z "$DISABLE_CHECKELF" ]; then |
| 490 | printf '\t\t\tshared_libs: [%s],\n' "$(basename -s .so $(${OBJDUMP} -x "$ANDROID_ROOT"/"$OUTDIR"/"$SRC"/lib64/"$FILE" 2>/dev/null |grep NEEDED) 2>/dev/null |grep -v ^NEEDED$ |sed 's/-3.9.1//g' |sed 's/\(.*\)/"\1",/g' |tr '\n' ' ')" |
| 491 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 492 | printf '\t\t},\n' |
| 493 | elif [ "$EXTRA" = "64" ]; then |
| 494 | printf '\t\tandroid_arm64: {\n' |
| 495 | printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE" |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 496 | if [ -z "$DISABLE_CHECKELF" ]; then |
| 497 | printf '\t\t\tshared_libs: [%s],\n' "$(basename -s .so $(${OBJDUMP} -x "$ANDROID_ROOT"/"$OUTDIR"/"$SRC"/lib64/"$FILE" 2>/dev/null |grep NEEDED) 2>/dev/null |grep -v ^NEEDED$ |sed 's/-3.9.1//g' |sed 's/\(.*\)/"\1",/g' |tr '\n' ' ')" |
| 498 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 499 | printf '\t\t},\n' |
| 500 | else |
| 501 | printf '\t\tandroid_arm: {\n' |
| 502 | printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE" |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 503 | if [ -z "$DISABLE_CHECKELF" ]; then |
| 504 | printf '\t\t\tshared_libs: [%s],\n' "$(basename -s .so $(${OBJDUMP} -x "$ANDROID_ROOT"/"$OUTDIR"/"$SRC"/lib/"$FILE" 2>/dev/null |grep NEEDED) 2>/dev/null |grep -v ^NEEDED$ |sed 's/-3.9.1//g' |sed 's/\(.*\)/"\1",/g' |tr '\n' ' ')" |
| 505 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 506 | printf '\t\t},\n' |
| 507 | fi |
| 508 | printf '\t},\n' |
| 509 | if [ "$EXTRA" != "none" ]; then |
| 510 | printf '\tcompile_multilib: "%s",\n' "$EXTRA" |
| 511 | fi |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 512 | if [ ! -z "$DISABLE_CHECKELF" ]; then |
| 513 | printf '\tcheck_elf_files: false,\n' |
| 514 | fi |
| Aaron Kling | c46cd09 | 2023-08-29 20:06:47 -0500 | [diff] [blame] | 515 | elif [ "$CLASS" = "RFSA" ]; then |
| 516 | printf 'prebuilt_rfsa {\n' |
| 517 | printf '\tname: "%s",\n' "$PKGNAME" |
| 518 | printf '\tfilename: "%s",\n' "$BASENAME" |
| 519 | printf '\towner: "%s",\n' "$VENDOR" |
| 520 | printf '\tsrc: "%s/lib/rfsa/%s",\n' "$SRC" "$FILE" |
| Chirayu Desai | a774101 | 2021-12-04 07:17:28 +0530 | [diff] [blame] | 521 | elif [ "$CLASS" = "APEX" ]; then |
| 522 | printf 'prebuilt_apex {\n' |
| 523 | printf '\tname: "%s",\n' "$PKGNAME" |
| 524 | printf '\towner: "%s",\n' "$VENDOR" |
| 525 | SRC="$SRC/apex" |
| 526 | printf '\tsrc: "%s/%s",\n' "$SRC" "$FILE" |
| 527 | printf '\tfilename: "%s",\n' "$FILE" |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 528 | elif [ "$CLASS" = "APPS" ]; then |
| 529 | printf 'android_app_import {\n' |
| 530 | printf '\tname: "%s",\n' "$PKGNAME" |
| 531 | printf '\towner: "%s",\n' "$VENDOR" |
| 532 | if [ "$EXTRA" = "priv-app" ]; then |
| 533 | SRC="$SRC/priv-app" |
| 534 | else |
| 535 | SRC="$SRC/app" |
| 536 | fi |
| 537 | printf '\tapk: "%s/%s",\n' "$SRC" "$FILE" |
| LuK1337 | 508e85f | 2021-08-23 18:18:57 +0200 | [diff] [blame] | 538 | USE_PLATFORM_CERTIFICATE="true" |
| 539 | for ARG in "${ARGS[@]}"; do |
| 540 | if [ "$ARG" = "PRESIGNED" ]; then |
| 541 | USE_PLATFORM_CERTIFICATE="false" |
| Michael Bestas | ab47e91 | 2024-03-06 13:32:05 +0200 | [diff] [blame] | 542 | printf '\tpreprocessed: true,\n' |
| LuK1337 | 508e85f | 2021-08-23 18:18:57 +0200 | [diff] [blame] | 543 | printf '\tpresigned: true,\n' |
| 544 | elif [[ "$ARG" =~ "OVERRIDES" ]]; then |
| 545 | OVERRIDEPKG=${ARG#*=} |
| Arian | 72ac836 | 2021-09-27 17:49:19 +0200 | [diff] [blame] | 546 | OVERRIDEPKG=${OVERRIDEPKG//,/\", \"} |
| LuK1337 | 508e85f | 2021-08-23 18:18:57 +0200 | [diff] [blame] | 547 | printf '\toverrides: ["%s"],\n' "$OVERRIDEPKG" |
| SamarV-121 | 7e6b408 | 2024-02-26 14:39:34 +0530 | [diff] [blame] | 548 | elif [[ "$ARG" =~ "REQUIRED" ]]; then |
| 549 | REQUIREDPKG=${ARG#*=} |
| 550 | REQUIRED_PACKAGES_LIST+="$REQUIREDPKG," |
| 551 | printf '\trequired: ["%s"],\n' "${REQUIREDPKG//,/\", \"}" |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 552 | elif [[ "$ARG" =~ "SYMLINK" ]]; then |
| 553 | continue |
| LuK1337 | 508e85f | 2021-08-23 18:18:57 +0200 | [diff] [blame] | 554 | elif [ ! -z "$ARG" ]; then |
| 555 | USE_PLATFORM_CERTIFICATE="false" |
| 556 | printf '\tcertificate: "%s",\n' "$ARG" |
| 557 | fi |
| 558 | done |
| 559 | if [ "$USE_PLATFORM_CERTIFICATE" = "true" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 560 | printf '\tcertificate: "platform",\n' |
| 561 | fi |
| 562 | elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then |
| 563 | printf 'dex_import {\n' |
| 564 | printf '\tname: "%s",\n' "$PKGNAME" |
| 565 | printf '\towner: "%s",\n' "$VENDOR" |
| 566 | printf '\tjars: ["%s/framework/%s"],\n' "$SRC" "$FILE" |
| 567 | elif [ "$CLASS" = "ETC" ]; then |
| 568 | if [ "$EXTENSION" = "xml" ]; then |
| 569 | printf 'prebuilt_etc_xml {\n' |
| 570 | else |
| 571 | printf 'prebuilt_etc {\n' |
| 572 | fi |
| 573 | printf '\tname: "%s",\n' "$PKGNAME" |
| 574 | printf '\towner: "%s",\n' "$VENDOR" |
| 575 | printf '\tsrc: "%s/etc/%s",\n' "$SRC" "$FILE" |
| LuK1337 | f7f1871 | 2020-10-06 19:29:02 +0200 | [diff] [blame] | 576 | printf '\tfilename_from_src: true,\n' |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 577 | elif [ "$CLASS" = "EXECUTABLES" ]; then |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 578 | if ! objdump -a "$ANDROID_ROOT"/"$OUTDIR"/"$SRC"/bin/"$FILE" 2>/dev/null |grep -c 'file format elf' > /dev/null; then |
| 579 | # This is not an elf file, assume it's a shell script that doesn't have an extension |
| 580 | # Setting extension here does not change the target extension, only the module type |
| 581 | EXTENSION="sh" |
| 582 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 583 | if [ "$EXTENSION" = "sh" ]; then |
| 584 | printf 'sh_binary {\n' |
| 585 | else |
| 586 | printf 'cc_prebuilt_binary {\n' |
| 587 | fi |
| 588 | printf '\tname: "%s",\n' "$PKGNAME" |
| 589 | printf '\towner: "%s",\n' "$VENDOR" |
| Sebastiano Barezzi | fd4b2b3 | 2021-07-14 21:33:10 +0200 | [diff] [blame] | 590 | if [ "$EXTENSION" != "sh" ]; then |
| Aaron Kling | 8a23e7b | 2023-09-12 13:02:16 -0500 | [diff] [blame] | 591 | printf '\ttarget: {\n' |
| 592 | if objdump -a "$ANDROID_ROOT"/"$OUTDIR"/"$SRC"/bin/"$FILE" |grep -c 'file format elf64' > /dev/null; then |
| 593 | printf '\t\tandroid_arm64: {\n' |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 594 | else |
| Aaron Kling | 8a23e7b | 2023-09-12 13:02:16 -0500 | [diff] [blame] | 595 | printf '\t\tandroid_arm: {\n' |
| 596 | fi |
| 597 | printf '\t\t\tsrcs: ["%s/bin/%s"],\n' "$SRC" "$FILE" |
| 598 | if [ -z "$DISABLE_CHECKELF" ]; then |
| 599 | printf '\t\t\tshared_libs: [%s],\n' "$(basename -s .so $(${OBJDUMP} -x "$ANDROID_ROOT"/"$OUTDIR"/"$SRC"/bin/"$FILE" 2>/dev/null |grep NEEDED) 2>/dev/null |grep -v ^NEEDED$ |sed 's/-3.9.1//g' |sed 's/\(.*\)/"\1",/g' |tr '\n' ' ')" |
| 600 | fi |
| 601 | printf '\t\t},\n' |
| 602 | printf '\t},\n' |
| 603 | if objdump -a "$ANDROID_ROOT"/"$OUTDIR"/"$SRC"/bin/"$FILE" |grep -c 'file format elf64' > /dev/null; then |
| 604 | printf '\tcompile_multilib: "%s",\n' "64" |
| 605 | else |
| 606 | printf '\tcompile_multilib: "%s",\n' "32" |
| 607 | fi |
| 608 | if [ ! -z "$DISABLE_CHECKELF" ]; then |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 609 | printf '\tcheck_elf_files: false,\n' |
| 610 | fi |
| Tim Zimmermann | 54606d6 | 2021-12-23 09:26:54 +0100 | [diff] [blame] | 611 | printf '\tstrip: {\n' |
| 612 | printf '\t\tnone: true,\n' |
| 613 | printf '\t},\n' |
| Mohd Faraz | 2509b6e | 2022-10-02 09:48:52 +0200 | [diff] [blame] | 614 | printf '\tprefer: true,\n' |
| 615 | else |
| 616 | printf '\tsrc: "%s/bin/%s",\n' "$SRC" "$FILE" |
| Aaron Kling | 74b654d | 2023-08-29 22:36:54 -0500 | [diff] [blame] | 617 | printf '\tfilename: "%s",\n' "$BASENAME" |
| Sebastiano Barezzi | fd4b2b3 | 2021-07-14 21:33:10 +0200 | [diff] [blame] | 618 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 619 | else |
| 620 | printf '\tsrcs: ["%s/%s"],\n' "$SRC" "$FILE" |
| 621 | fi |
| 622 | if [ "$CLASS" = "APPS" ]; then |
| 623 | printf '\tdex_preopt: {\n' |
| 624 | printf '\t\tenabled: false,\n' |
| 625 | printf '\t},\n' |
| Jyotiraditya Panda | 45f50af | 2024-02-19 05:35:33 +0900 | [diff] [blame] | 626 | if [ "$DIRNAME" != "." ] && [[ "$DIRNAME" == */* ]]; then |
| 627 | printf '\trelative_install_path: "%s",\n' "$DIRNAME" |
| 628 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 629 | fi |
| Aaron Kling | c46cd09 | 2023-08-29 20:06:47 -0500 | [diff] [blame] | 630 | if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ] || [ "$CLASS" = "RFSA" ] ; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 631 | if [ "$DIRNAME" != "." ]; then |
| Aaron Kling | 68cc8bb | 2023-10-10 03:52:45 -0500 | [diff] [blame] | 632 | if [ "$EXTENSION" = "sh" ]; then |
| 633 | printf '\tsub_dir: "%s",\n' "$DIRNAME" |
| 634 | else |
| 635 | printf '\trelative_install_path: "%s",\n' "$DIRNAME" |
| 636 | fi |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 637 | fi |
| 638 | fi |
| Andreas Schneider | dbcf9db | 2020-05-25 17:03:17 +0200 | [diff] [blame] | 639 | if [ "$CLASS" = "ETC" ] ; then |
| 640 | if [ "$DIRNAME" != "." ]; then |
| 641 | printf '\tsub_dir: "%s",\n' "$DIRNAME" |
| 642 | fi |
| 643 | fi |
| Mohd Faraz | 2509b6e | 2022-10-02 09:48:52 +0200 | [diff] [blame] | 644 | if [ "$CLASS" = "SHARED_LIBRARIES" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 645 | printf '\tprefer: true,\n' |
| 646 | fi |
| 647 | if [ "$EXTRA" = "priv-app" ]; then |
| 648 | printf '\tprivileged: true,\n' |
| 649 | fi |
| 650 | if [ "$PARTITION" = "vendor" ]; then |
| 651 | printf '\tsoc_specific: true,\n' |
| 652 | elif [ "$PARTITION" = "product" ]; then |
| 653 | printf '\tproduct_specific: true,\n' |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 654 | elif [ "$PARTITION" = "system_ext" ]; then |
| 655 | printf '\tsystem_ext_specific: true,\n' |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 656 | elif [ "$PARTITION" = "odm" ]; then |
| 657 | printf '\tdevice_specific: true,\n' |
| 658 | fi |
| 659 | printf '}\n\n' |
| 660 | done |
| 661 | } |
| 662 | |
| 663 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 664 | # write_product_packages: |
| 665 | # |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 666 | # This function will create prebuilt entries in the |
| 667 | # Android.bp and associated PRODUCT_PACKAGES list in the |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 668 | # product makefile for all files in the blob list which |
| 669 | # start with a single dash (-) character. |
| 670 | # |
| 671 | function write_product_packages() { |
| 672 | PACKAGE_LIST=() |
| 673 | |
| Chenyang Zhong | c487f38 | 2022-02-10 21:40:41 -0500 | [diff] [blame] | 674 | # Sort the package list for comm |
| 675 | PRODUCT_PACKAGES_LIST=($( printf '%s\n' "${PRODUCT_PACKAGES_LIST[@]}" | LC_ALL=C sort)) |
| 676 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 677 | local COUNT=${#PRODUCT_PACKAGES_LIST[@]} |
| 678 | |
| 679 | if [ "$COUNT" = "0" ]; then |
| 680 | return 0 |
| 681 | fi |
| 682 | |
| 683 | # Figure out what's 32-bit, what's 64-bit, and what's multilib |
| 684 | # I really should not be doing this in bash due to shitty array passing :( |
| 685 | local T_LIB32=( $(prefix_match "lib/") ) |
| 686 | local T_LIB64=( $(prefix_match "lib64/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 687 | local MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) ) |
| 688 | local LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) ) |
| 689 | local LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_LIB64[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) ) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 690 | |
| 691 | if [ "${#MULTILIBS[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 692 | write_blueprint_packages "SHARED_LIBRARIES" "" "both" "MULTILIBS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 693 | fi |
| 694 | if [ "${#LIB32[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 695 | write_blueprint_packages "SHARED_LIBRARIES" "" "32" "LIB32" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 696 | fi |
| 697 | if [ "${#LIB64[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 698 | write_blueprint_packages "SHARED_LIBRARIES" "" "64" "LIB64" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 699 | fi |
| 700 | |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 701 | local T_S_LIB32=( $(prefix_match "system/lib/") ) |
| 702 | local T_S_LIB64=( $(prefix_match "system/lib64/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 703 | local S_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${T_S_LIB64[@]}")) ) |
| 704 | local S_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) ) |
| 705 | local S_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_S_LIB64[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) ) |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 706 | |
| 707 | if [ "${#S_MULTILIBS[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 708 | write_blueprint_packages "SHARED_LIBRARIES" "system" "both" "S_MULTILIBS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 709 | fi |
| 710 | if [ "${#S_LIB32[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 711 | write_blueprint_packages "SHARED_LIBRARIES" "system" "32" "S_LIB32" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 712 | fi |
| 713 | if [ "${#S_LIB64[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 714 | write_blueprint_packages "SHARED_LIBRARIES" "system" "64" "S_LIB64" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 715 | fi |
| 716 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 717 | local T_V_LIB32=( $(prefix_match "vendor/lib/") ) |
| 718 | local T_V_LIB64=( $(prefix_match "vendor/lib64/") ) |
| Aaron Kling | c46cd09 | 2023-08-29 20:06:47 -0500 | [diff] [blame] | 719 | local V_RFSA=( $(prefix_match "vendor/lib/rfsa/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 720 | local V_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) ) |
| 721 | local V_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) ) |
| Aaron Kling | c46cd09 | 2023-08-29 20:06:47 -0500 | [diff] [blame] | 722 | local V_LIB32=( $(LC_ALL=C grep -v 'rfsa/' <(printf '%s\n' "${V_LIB32[@]}")) ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 723 | local V_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_V_LIB64[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) ) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 724 | |
| 725 | if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 726 | write_blueprint_packages "SHARED_LIBRARIES" "vendor" "both" "V_MULTILIBS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 727 | fi |
| 728 | if [ "${#V_LIB32[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 729 | write_blueprint_packages "SHARED_LIBRARIES" "vendor" "32" "V_LIB32" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 730 | fi |
| 731 | if [ "${#V_LIB64[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 732 | write_blueprint_packages "SHARED_LIBRARIES" "vendor" "64" "V_LIB64" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 733 | fi |
| Aaron Kling | c46cd09 | 2023-08-29 20:06:47 -0500 | [diff] [blame] | 734 | if [ "${#V_RFSA[@]}" -gt "0" ]; then |
| 735 | write_blueprint_packages "RFSA" "vendor" "" "V_RFSA" >> "$ANDROIDBP" |
| 736 | fi |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 737 | |
| 738 | local T_P_LIB32=( $(prefix_match "product/lib/") ) |
| 739 | local T_P_LIB64=( $(prefix_match "product/lib64/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 740 | local P_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${T_P_LIB64[@]}")) ) |
| 741 | local P_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) ) |
| 742 | local P_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_P_LIB64[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) ) |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 743 | |
| 744 | if [ "${#P_MULTILIBS[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 745 | write_blueprint_packages "SHARED_LIBRARIES" "product" "both" "P_MULTILIBS" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 746 | fi |
| 747 | if [ "${#P_LIB32[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 748 | write_blueprint_packages "SHARED_LIBRARIES" "product" "32" "P_LIB32" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 749 | fi |
| 750 | if [ "${#P_LIB64[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 751 | write_blueprint_packages "SHARED_LIBRARIES" "product" "64" "P_LIB64" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 752 | fi |
| 753 | |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 754 | local T_SE_LIB32=( $(prefix_match "system_ext/lib/") ) |
| 755 | local T_SE_LIB64=( $(prefix_match "system_ext/lib64/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 756 | local SE_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${T_SE_LIB64[@]}")) ) |
| 757 | local SE_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) ) |
| 758 | local SE_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_SE_LIB64[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) ) |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 759 | |
| 760 | if [ "${#SE_MULTILIBS[@]}" -gt "0" ]; then |
| 761 | write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "both" "SE_MULTILIBS" >> "$ANDROIDBP" |
| 762 | fi |
| 763 | if [ "${#SE_LIB32[@]}" -gt "0" ]; then |
| 764 | write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "32" "SE_LIB32" >> "$ANDROIDBP" |
| 765 | fi |
| 766 | if [ "${#SE_LIB64[@]}" -gt "0" ]; then |
| 767 | write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "64" "SE_LIB64" >> "$ANDROIDBP" |
| 768 | fi |
| 769 | |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 770 | local T_O_LIB32=( $(prefix_match "odm/lib/") ) |
| 771 | local T_O_LIB64=( $(prefix_match "odm/lib64/") ) |
| Pablo Cholaky | 32d80cf | 2022-01-16 13:52:07 -0500 | [diff] [blame] | 772 | local O_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${T_O_LIB64[@]}")) ) |
| 773 | local O_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) ) |
| 774 | local O_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_O_LIB64[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) ) |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 775 | |
| 776 | if [ "${#O_MULTILIBS[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 777 | write_blueprint_packages "SHARED_LIBRARIES" "odm" "both" "O_MULTILIBS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 778 | fi |
| 779 | if [ "${#O_LIB32[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 780 | write_blueprint_packages "SHARED_LIBRARIES" "odm" "32" "O_LIB32" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 781 | fi |
| 782 | if [ "${#O_LIB64[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 783 | write_blueprint_packages "SHARED_LIBRARIES" "odm" "64" "O_LIB64" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 784 | fi |
| 785 | |
| Chirayu Desai | a774101 | 2021-12-04 07:17:28 +0530 | [diff] [blame] | 786 | # APEX |
| 787 | local APEX=( $(prefix_match "apex/") ) |
| 788 | if [ "${#APEX[@]}" -gt "0" ]; then |
| 789 | write_blueprint_packages "APEX" "" "" "APEX" >> "$ANDROIDBP" |
| 790 | fi |
| 791 | local S_APEX=( $(prefix_match "system/apex/") ) |
| 792 | if [ "${#S_APEX[@]}" -gt "0" ]; then |
| 793 | write_blueprint_packages "APEX" "system" "" "S_APEX" >> "$ANDROIDBP" |
| 794 | fi |
| 795 | local V_APEX=( $(prefix_match "vendor/apex/") ) |
| 796 | if [ "${#V_APEX[@]}" -gt "0" ]; then |
| 797 | write_blueprint_packages "APEX" "vendor" "" "V_APEX" >> "$ANDROIDBP" |
| 798 | fi |
| 799 | local SE_APEX=( $(prefix_match "system_ext/apex/") ) |
| 800 | if [ "${#SE_APEX[@]}" -gt "0" ]; then |
| 801 | write_blueprint_packages "APEX" "system_ext" "" "SE_APEX" >> "$ANDROIDBP" |
| 802 | fi |
| 803 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 804 | # Apps |
| 805 | local APPS=( $(prefix_match "app/") ) |
| 806 | if [ "${#APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 807 | write_blueprint_packages "APPS" "" "" "APPS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 808 | fi |
| 809 | local PRIV_APPS=( $(prefix_match "priv-app/") ) |
| 810 | if [ "${#PRIV_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 811 | write_blueprint_packages "APPS" "" "priv-app" "PRIV_APPS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 812 | fi |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 813 | local S_APPS=( $(prefix_match "system/app/") ) |
| 814 | if [ "${#S_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 815 | write_blueprint_packages "APPS" "system" "" "S_APPS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 816 | fi |
| 817 | local S_PRIV_APPS=( $(prefix_match "system/priv-app/") ) |
| 818 | if [ "${#S_PRIV_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 819 | write_blueprint_packages "APPS" "system" "priv-app" "S_PRIV_APPS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 820 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 821 | local V_APPS=( $(prefix_match "vendor/app/") ) |
| 822 | if [ "${#V_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 823 | write_blueprint_packages "APPS" "vendor" "" "V_APPS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 824 | fi |
| 825 | local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") ) |
| 826 | if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 827 | write_blueprint_packages "APPS" "vendor" "priv-app" "V_PRIV_APPS" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 828 | fi |
| 829 | local P_APPS=( $(prefix_match "product/app/") ) |
| 830 | if [ "${#P_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 831 | write_blueprint_packages "APPS" "product" "" "P_APPS" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 832 | fi |
| 833 | local P_PRIV_APPS=( $(prefix_match "product/priv-app/") ) |
| 834 | if [ "${#P_PRIV_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 835 | write_blueprint_packages "APPS" "product" "priv-app" "P_PRIV_APPS" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 836 | fi |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 837 | local SE_APPS=( $(prefix_match "system_ext/app/") ) |
| 838 | if [ "${#SE_APPS[@]}" -gt "0" ]; then |
| 839 | write_blueprint_packages "APPS" "system_ext" "" "SE_APPS" >> "$ANDROIDBP" |
| 840 | fi |
| 841 | local SE_PRIV_APPS=( $(prefix_match "system_ext/priv-app/") ) |
| 842 | if [ "${#SE_PRIV_APPS[@]}" -gt "0" ]; then |
| 843 | write_blueprint_packages "APPS" "system_ext" "priv-app" "SE_PRIV_APPS" >> "$ANDROIDBP" |
| 844 | fi |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 845 | local O_APPS=( $(prefix_match "odm/app/") ) |
| 846 | if [ "${#O_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 847 | write_blueprint_packages "APPS" "odm" "" "O_APPS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 848 | fi |
| 849 | local O_PRIV_APPS=( $(prefix_match "odm/priv-app/") ) |
| 850 | if [ "${#O_PRIV_APPS[@]}" -gt "0" ]; then |
| mickael saibi | 64b0b75 | 2019-11-17 18:35:05 +0100 | [diff] [blame] | 851 | write_blueprint_packages "APPS" "odm" "priv-app" "O_PRIV_APPS" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 852 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 853 | |
| 854 | # Framework |
| 855 | local FRAMEWORK=( $(prefix_match "framework/") ) |
| 856 | if [ "${#FRAMEWORK[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 857 | write_blueprint_packages "JAVA_LIBRARIES" "" "" "FRAMEWORK" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 858 | fi |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 859 | local S_FRAMEWORK=( $(prefix_match "system/framework/") ) |
| 860 | if [ "${#S_FRAMEWORK[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 861 | write_blueprint_packages "JAVA_LIBRARIES" "system" "" "S_FRAMEWORK" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 862 | fi |
| Christian Oder | 974b590 | 2017-10-08 23:15:52 +0200 | [diff] [blame] | 863 | local V_FRAMEWORK=( $(prefix_match "vendor/framework/") ) |
| Michael Bestas | 26eb01e | 2018-02-27 22:31:55 +0200 | [diff] [blame] | 864 | if [ "${#V_FRAMEWORK[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 865 | write_blueprint_packages "JAVA_LIBRARIES" "vendor" "" "V_FRAMEWORK" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 866 | fi |
| 867 | local P_FRAMEWORK=( $(prefix_match "product/framework/") ) |
| 868 | if [ "${#P_FRAMEWORK[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 869 | write_blueprint_packages "JAVA_LIBRARIES" "product" "" "P_FRAMEWORK" >> "$ANDROIDBP" |
| Christian Oder | 974b590 | 2017-10-08 23:15:52 +0200 | [diff] [blame] | 870 | fi |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 871 | local SE_FRAMEWORK=( $(prefix_match "system_ext/framework/") ) |
| Alexander Koskovich | 052c77d | 2020-09-16 17:58:53 -0700 | [diff] [blame] | 872 | if [ "${#SE_FRAMEWORK[@]}" -gt "0" ]; then |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 873 | write_blueprint_packages "JAVA_LIBRARIES" "system_ext" "" "SE_FRAMEWORK" >> "$ANDROIDBP" |
| 874 | fi |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 875 | local O_FRAMEWORK=( $(prefix_match "odm/framework/") ) |
| 876 | if [ "${#O_FRAMEWORK[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 877 | write_blueprint_packages "JAVA_LIBRARIES" "odm" "" "O_FRAMEWORK" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 878 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 879 | |
| 880 | # Etc |
| 881 | local ETC=( $(prefix_match "etc/") ) |
| 882 | if [ "${#ETC[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 883 | write_blueprint_packages "ETC" "" "" "ETC" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 884 | fi |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 885 | local S_ETC=( $(prefix_match "system/etc/") ) |
| Luca Weiss | 737940e | 2022-09-27 14:52:41 +0200 | [diff] [blame] | 886 | if [ "${#S_ETC[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 887 | write_blueprint_packages "ETC" "system" "" "S_ETC" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 888 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 889 | local V_ETC=( $(prefix_match "vendor/etc/") ) |
| 890 | if [ "${#V_ETC[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 891 | write_blueprint_packages "ETC" "vendor" "" "V_ETC" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 892 | fi |
| 893 | local P_ETC=( $(prefix_match "product/etc/") ) |
| 894 | if [ "${#P_ETC[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 895 | write_blueprint_packages "ETC" "product" "" "P_ETC" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 896 | fi |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 897 | local SE_ETC=( $(prefix_match "system_ext/etc/") ) |
| 898 | if [ "${#SE_ETC[@]}" -gt "0" ]; then |
| 899 | write_blueprint_packages "ETC" "system_ext" "" "SE_ETC" >> "$ANDROIDBP" |
| 900 | fi |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 901 | local O_ETC=( $(prefix_match "odm/etc/") ) |
| 902 | if [ "${#O_ETC[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 903 | write_blueprint_packages "ETC" "odm" "" "O_ETC" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 904 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 905 | |
| 906 | # Executables |
| 907 | local BIN=( $(prefix_match "bin/") ) |
| 908 | if [ "${#BIN[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 909 | write_blueprint_packages "EXECUTABLES" "" "" "BIN" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 910 | fi |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 911 | local S_BIN=( $(prefix_match "system/bin/") ) |
| Luca Weiss | 737940e | 2022-09-27 14:52:41 +0200 | [diff] [blame] | 912 | if [ "${#S_BIN[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 913 | write_blueprint_packages "EXECUTABLES" "system" "" "S_BIN" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a6373e5 | 2019-09-28 23:37:36 -0400 | [diff] [blame] | 914 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 915 | local V_BIN=( $(prefix_match "vendor/bin/") ) |
| 916 | if [ "${#V_BIN[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 917 | write_blueprint_packages "EXECUTABLES" "vendor" "" "V_BIN" >> "$ANDROIDBP" |
| razorloves | a0d296b | 2019-07-29 02:21:34 -0500 | [diff] [blame] | 918 | fi |
| 919 | local P_BIN=( $(prefix_match "product/bin/") ) |
| 920 | if [ "${#P_BIN[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 921 | write_blueprint_packages "EXECUTABLES" "product" "" "P_BIN" >> "$ANDROIDBP" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 922 | fi |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 923 | local SE_BIN=( $(prefix_match "system_ext/bin/") ) |
| 924 | if [ "${#SE_BIN[@]}" -gt "0" ]; then |
| 925 | write_blueprint_packages "EXECUTABLES" "system_ext" "" "SE_BIN" >> "$ANDROIDBP" |
| 926 | fi |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 927 | local O_BIN=( $(prefix_match "odm/bin/") ) |
| 928 | if [ "${#O_BIN[@]}" -gt "0" ]; then |
| Rashed Abdel-Tawab | b91adc0 | 2019-09-20 10:30:38 -0700 | [diff] [blame] | 929 | write_blueprint_packages "EXECUTABLES" "odm" "" "O_BIN" >> "$ANDROIDBP" |
| Rashed Abdel-Tawab | a94af58 | 2019-09-20 07:32:39 -0700 | [diff] [blame] | 930 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 931 | |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 932 | write_package_definition "${PACKAGE_LIST[@]}" >> "$PRODUCTMK" |
| 933 | } |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 934 | |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 935 | |
| 936 | # |
| 937 | # write_symlink_packages: |
| 938 | # |
| 939 | # Creates symlink entries in the Android.bp and related PRODUCT_PACKAGES |
| 940 | # list in the product makefile for all files in the blob list which has |
| 941 | # SYMLINK argument. |
| 942 | # |
| 943 | function write_symlink_packages() { |
| 944 | local FILE= |
| 945 | local ARGS= |
| 946 | local ARCH= |
| 947 | local BASENAME= |
| 948 | local PKGNAME= |
| 949 | local PREFIX= |
| 950 | local SYMLINK_BASENAME= |
| 951 | local SYMLINK_PACKAGES=() |
| 952 | |
| 953 | # Sort the symlinks list for comm |
| 954 | PRODUCT_SYMLINKS_LIST=($( printf '%s\n' "${PRODUCT_SYMLINKS_LIST[@]}" | LC_ALL=C sort)) |
| 955 | |
| 956 | local COUNT=${#PRODUCT_SYMLINKS_LIST[@]} |
| 957 | |
| 958 | if [ "$COUNT" = "0" ]; then |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 959 | return 0 |
| 960 | fi |
| 961 | |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 962 | for LINE in "${PRODUCT_SYMLINKS_LIST[@]}"; do |
| Bruno Martins | be7f3cb | 2024-06-23 15:54:02 +0100 | [diff] [blame] | 963 | FILE=$(target_file "$LINE") |
| Bruno Martins | f96fd12 | 2024-03-28 14:31:02 +0000 | [diff] [blame] | 964 | if [[ "$LINE" =~ '/lib64/' || "$LINE" =~ '/lib/arm64/' ]]; then |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 965 | ARCH="64" |
| Bruno Martins | f96fd12 | 2024-03-28 14:31:02 +0000 | [diff] [blame] | 966 | elif [[ "$LINE" =~ '/lib/' ]]; then |
| 967 | ARCH="32" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 968 | fi |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 969 | BASENAME=$(basename "$FILE") |
| 970 | ARGS=$(target_args "$LINE") |
| 971 | ARGS=(${ARGS//;/ }) |
| 972 | for ARG in "${ARGS[@]}"; do |
| 973 | if [[ "$ARG" =~ "SYMLINK" ]]; then |
| 974 | SYMLINKS=${ARG#*=} |
| 975 | SYMLINKS=(${SYMLINKS//,/ }) |
| 976 | for SYMLINK in "${SYMLINKS[@]}"; do |
| 977 | SYMLINK_BASENAME=$(basename "$SYMLINK") |
| Bruno Martins | ad05f51 | 2024-06-28 00:34:33 +0100 | [diff] [blame] | 978 | PKGNAME="${BASENAME%.*}_${SYMLINK_BASENAME%.*}_symlink${ARCH}" |
| 979 | if [[ "${SYMLINK_PACKAGES[@]}" =~ "$PKGNAME" ]]; then |
| 980 | PKGNAME+="_$(grep -o "$PKGNAME" <<< ${SYMLINK_PACKAGES[*]} | wc -l)" |
| 981 | fi |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 982 | { |
| 983 | printf 'install_symlink {\n' |
| 984 | printf '\tname: "%s",\n' "$PKGNAME" |
| Mashopy | 06100c9 | 2024-04-23 21:52:04 +0200 | [diff] [blame] | 985 | if prefix_match_file "vendor/" "$SYMLINK"; then |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 986 | PREFIX='vendor/' |
| 987 | printf '\tsoc_specific: true,\n' |
| Mashopy | 06100c9 | 2024-04-23 21:52:04 +0200 | [diff] [blame] | 988 | elif prefix_match_file "product/" "$SYMLINK"; then |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 989 | PREFIX='product/' |
| 990 | printf '\tproduct_specific: true,\n' |
| Mashopy | 06100c9 | 2024-04-23 21:52:04 +0200 | [diff] [blame] | 991 | elif prefix_match_file "system_ext/" "$SYMLINK"; then |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 992 | PREFIX='system_ext/' |
| 993 | printf '\tsystem_ext_specific: true,\n' |
| Mashopy | 06100c9 | 2024-04-23 21:52:04 +0200 | [diff] [blame] | 994 | elif prefix_match_file "odm/" "$SYMLINK"; then |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 995 | PREFIX='odm/' |
| 996 | printf '\tdevice_specific: true,\n' |
| 997 | fi |
| 998 | printf '\tinstalled_location: "%s",\n' "${SYMLINK#"$PREFIX"}" |
| 999 | printf '\tsymlink_target: "/%s",\n' "$FILE" |
| 1000 | printf '}\n\n' |
| 1001 | } >> "$ANDROIDBP" |
| 1002 | SYMLINK_PACKAGES+=("$PKGNAME") |
| 1003 | done |
| 1004 | fi |
| 1005 | done |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1006 | done |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1007 | |
| 1008 | write_package_definition "${SYMLINK_PACKAGES[@]}" >> "$PRODUCTMK" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | # |
| Michael Bestas | fe71eb3 | 2023-06-11 18:59:10 +0300 | [diff] [blame] | 1012 | # write_single_product_copy_files: |
| 1013 | # |
| 1014 | # $1: the file to be copied |
| 1015 | # |
| 1016 | # Creates a PRODUCT_COPY_FILES section in the product makefile for the |
| 1017 | # item provided in $1. |
| 1018 | # |
| 1019 | function write_single_product_copy_files() { |
| 1020 | local FILE="$1" |
| 1021 | if [ -z "$FILE" ]; then |
| 1022 | echo "A file must be provided to write_single_product_copy_files()!" |
| 1023 | exit 1 |
| 1024 | fi |
| 1025 | |
| 1026 | local TARGET=$(target_file "$FILE") |
| 1027 | local OUTTARGET=$(truncate_file $TARGET) |
| 1028 | |
| 1029 | printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK" |
| 1030 | printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s\n' \ |
| 1031 | "$OUTDIR" "$TARGET" "$OUTTARGET" >> "$PRODUCTMK" |
| 1032 | } |
| 1033 | |
| 1034 | # |
| 1035 | # write_single_product_packages: |
| 1036 | # |
| 1037 | # $1: the package to be built |
| 1038 | # |
| 1039 | # Creates a PRODUCT_PACKAGES section in the product makefile for the |
| 1040 | # item provided in $1. |
| 1041 | # |
| 1042 | function write_single_product_packages() { |
| 1043 | local PACKAGE="$1" |
| 1044 | if [ -z "$PACKAGE" ]; then |
| 1045 | echo "A package must be provided to write_single_product_packages()!" |
| 1046 | exit 1 |
| 1047 | fi |
| 1048 | |
| 1049 | printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK" |
| 1050 | printf ' %s%s\n' "$PACKAGE" >> "$PRODUCTMK" |
| 1051 | } |
| 1052 | |
| 1053 | # |
| Michael Bestas | 431a800 | 2023-06-11 20:04:45 +0300 | [diff] [blame] | 1054 | # write_rro_androidmanifest: |
| 1055 | # |
| 1056 | # $2: target package for the RRO overlay |
| 1057 | # |
| 1058 | # Creates an AndroidManifest.xml for an RRO overlay. |
| 1059 | # |
| 1060 | function write_rro_androidmanifest() { |
| 1061 | local TARGET_PACKAGE="$1" |
| 1062 | |
| 1063 | cat << EOF |
| 1064 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 1065 | package="$TARGET_PACKAGE.vendor" |
| 1066 | android:versionCode="1" |
| 1067 | android:versionName="1.0"> |
| 1068 | <application android:hasCode="false" /> |
| 1069 | <overlay |
| 1070 | android:targetPackage="$TARGET_PACKAGE" |
| 1071 | android:isStatic="true" |
| 1072 | android:priority="0"/> |
| 1073 | </manifest> |
| 1074 | EOF |
| 1075 | } |
| 1076 | |
| 1077 | # |
| 1078 | # write_rro_blueprint: |
| 1079 | # |
| 1080 | # $1: package name for the RRO overlay |
| 1081 | # $2: target partition for the RRO overlay |
| 1082 | # |
| 1083 | # Creates an Android.bp for an RRO overlay. |
| 1084 | # |
| 1085 | function write_rro_blueprint() { |
| 1086 | local PKGNAME="$1" |
| 1087 | local PARTITION="$2" |
| 1088 | |
| 1089 | printf 'runtime_resource_overlay {\n' |
| 1090 | printf '\tname: "%s",\n' "$PKGNAME" |
| 1091 | printf '\ttheme: "%s",\n' "$PKGNAME" |
| 1092 | printf '\tsdk_version: "%s",\n' "current" |
| 1093 | printf '\taaptflags: ["%s"],\n' "--keep-raw-values" |
| 1094 | |
| 1095 | if [ "$PARTITION" = "vendor" ]; then |
| 1096 | printf '\tsoc_specific: true,\n' |
| 1097 | elif [ "$PARTITION" = "product" ]; then |
| 1098 | printf '\tproduct_specific: true,\n' |
| 1099 | elif [ "$PARTITION" = "system_ext" ]; then |
| 1100 | printf '\tsystem_ext_specific: true,\n' |
| 1101 | elif [ "$PARTITION" = "odm" ]; then |
| 1102 | printf '\tdevice_specific: true,\n' |
| 1103 | fi |
| 1104 | printf '}\n' |
| 1105 | } |
| 1106 | |
| 1107 | # |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1108 | # write_blueprint_header: |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1109 | # |
| 1110 | # $1: file which will be written to |
| 1111 | # |
| Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 1112 | # writes out the warning message regarding manual file modifications. |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1113 | # note that this is not an append operation, and should |
| 1114 | # be executed first! |
| 1115 | # |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1116 | function write_blueprint_header() { |
| 1117 | if [ -f $1 ]; then |
| 1118 | rm $1 |
| 1119 | fi |
| 1120 | |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1121 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 1122 | |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1123 | cat << EOF >> $1 |
| Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 1124 | // Automatically generated file. DO NOT MODIFY |
| 1125 | // |
| 1126 | // This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1127 | |
| 1128 | EOF |
| 1129 | } |
| 1130 | |
| 1131 | # |
| 1132 | # write_makefile_header: |
| 1133 | # |
| 1134 | # $1: file which will be written to |
| 1135 | # |
| Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 1136 | # writes out the warning message regarding manual file modifications. |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1137 | # note that this is not an append operation, and should |
| 1138 | # be executed first! |
| 1139 | # |
| 1140 | function write_makefile_header() { |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1141 | if [ -f $1 ]; then |
| 1142 | rm $1 |
| 1143 | fi |
| 1144 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1145 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 1146 | |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1147 | cat << EOF >> $1 |
| Michael Bestas | a2934df | 2020-12-19 03:50:32 +0200 | [diff] [blame] | 1148 | # Automatically generated file. DO NOT MODIFY |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1149 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1150 | # This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh |
| 1151 | |
| 1152 | EOF |
| 1153 | } |
| 1154 | |
| 1155 | # |
| Michael Bestas | 431a800 | 2023-06-11 20:04:45 +0300 | [diff] [blame] | 1156 | # write_xml_header: |
| 1157 | # |
| 1158 | # $1: file which will be written to |
| 1159 | # |
| 1160 | # writes out the warning message regarding manual file modifications. |
| 1161 | # note that this is not an append operation, and should |
| 1162 | # be executed first! |
| 1163 | # |
| 1164 | function write_xml_header() { |
| 1165 | if [ -f $1 ]; then |
| 1166 | rm $1 |
| 1167 | fi |
| 1168 | |
| 1169 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 1170 | [ "$COMMON" -eq 1 ] && local VENDOR="${VENDOR_COMMON:-$VENDOR}" |
| 1171 | |
| 1172 | cat << EOF >> $1 |
| 1173 | <?xml version="1.0" encoding="utf-8"?> |
| 1174 | <!-- |
| 1175 | Automatically generated file. DO NOT MODIFY |
| 1176 | |
| 1177 | This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh |
| 1178 | --> |
| 1179 | EOF |
| 1180 | } |
| 1181 | |
| 1182 | # |
| 1183 | # write_rro_package: |
| 1184 | # |
| 1185 | # $1: the RRO package name |
| 1186 | # $2: the RRO target package |
| 1187 | # $3: the partition for the RRO overlay |
| 1188 | # |
| 1189 | # Generates the file structure for an RRO overlay. |
| 1190 | # |
| 1191 | function write_rro_package() { |
| 1192 | local PKGNAME="$1" |
| 1193 | if [ -z "$PKGNAME" ]; then |
| 1194 | echo "A package name must be provided to write_rro_package()!" |
| 1195 | exit 1 |
| 1196 | fi |
| 1197 | |
| 1198 | local TARGET_PACKAGE="$2" |
| 1199 | if [ -z "$TARGET_PACKAGE" ]; then |
| 1200 | echo "A target package must be provided to write_rro_package()!" |
| 1201 | exit 1 |
| 1202 | fi |
| 1203 | |
| 1204 | local PARTITION="$3" |
| 1205 | if [ -z "$PARTITION" ]; then |
| 1206 | PARTITION="vendor" |
| 1207 | fi |
| 1208 | |
| 1209 | local RROBP="$ANDROID_ROOT"/"$OUTDIR"/rro_overlays/"$PKGNAME"/Android.bp |
| 1210 | local RROMANIFEST="$ANDROID_ROOT"/"$OUTDIR"/rro_overlays/"$PKGNAME"/AndroidManifest.xml |
| 1211 | |
| 1212 | write_blueprint_header "$RROBP" |
| 1213 | write_xml_header "$RROMANIFEST" |
| 1214 | |
| 1215 | write_rro_blueprint "$PKGNAME" "$PARTITION" >> "$RROBP" |
| 1216 | write_rro_androidmanifest "$TARGET_PACKAGE" >> "$RROMANIFEST" |
| 1217 | } |
| 1218 | |
| 1219 | # |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1220 | # write_package_definition: |
| 1221 | # |
| 1222 | # $@: list of packages |
| 1223 | # |
| 1224 | # writes out the final PRODUCT_PACKAGES list |
| 1225 | # |
| 1226 | function write_package_definition() { |
| 1227 | local PACKAGE_LIST=("${@}") |
| 1228 | local PACKAGE_COUNT=${#PACKAGE_LIST[@]} |
| 1229 | |
| 1230 | if [ "$PACKAGE_COUNT" -eq "0" ]; then |
| 1231 | return 0 |
| 1232 | fi |
| 1233 | |
| 1234 | printf '\n%s\n' "PRODUCT_PACKAGES += \\" |
| 1235 | for (( i=1; i<PACKAGE_COUNT+1; i++ )); do |
| SamarV-121 | 7e6b408 | 2024-02-26 14:39:34 +0530 | [diff] [blame] | 1236 | local SKIP=false |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1237 | local LINEEND=" \\" |
| 1238 | if [ "$i" -eq "$PACKAGE_COUNT" ]; then |
| 1239 | LINEEND="" |
| 1240 | fi |
| SamarV-121 | 7e6b408 | 2024-02-26 14:39:34 +0530 | [diff] [blame] | 1241 | for PKG in $(tr "," "\n" <<< "$REQUIRED_PACKAGES_LIST"); do |
| 1242 | if [[ $PKG == "${PACKAGE_LIST[$i - 1]}" ]]; then |
| 1243 | SKIP=true |
| 1244 | break |
| 1245 | fi |
| 1246 | done |
| 1247 | # Skip adding of the package to product makefile if it's in the required list |
| 1248 | if [[ $SKIP == false ]]; then |
| 1249 | printf ' %s%s\n' "${PACKAGE_LIST[$i - 1]}" "$LINEEND" >> "$PRODUCTMK" |
| 1250 | fi |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1251 | done |
| 1252 | } |
| 1253 | |
| 1254 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1255 | # write_headers: |
| 1256 | # |
| 1257 | # $1: devices falling under common to be added to guard - optional |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1258 | # $2: custom guard - optional |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1259 | # |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1260 | # Calls write_makefile_header for each of the makefiles and |
| 1261 | # write_blueprint_header for Android.bp and creates the initial |
| 1262 | # path declaration and device guard for the Android.mk |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1263 | # |
| 1264 | function write_headers() { |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1265 | write_makefile_header "$ANDROIDMK" |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1266 | |
| 1267 | GUARD="$2" |
| 1268 | if [ -z "$GUARD" ]; then |
| 1269 | GUARD="TARGET_DEVICE" |
| 1270 | fi |
| 1271 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1272 | cat << EOF >> "$ANDROIDMK" |
| 1273 | LOCAL_PATH := \$(call my-dir) |
| 1274 | |
| 1275 | EOF |
| 1276 | if [ "$COMMON" -ne 1 ]; then |
| 1277 | cat << EOF >> "$ANDROIDMK" |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1278 | ifeq (\$($GUARD),$DEVICE) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1279 | |
| 1280 | EOF |
| 1281 | else |
| 1282 | if [ -z "$1" ]; then |
| 1283 | echo "Argument with devices to be added to guard must be set!" |
| 1284 | exit 1 |
| 1285 | fi |
| 1286 | cat << EOF >> "$ANDROIDMK" |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1287 | ifneq (\$(filter $1,\$($GUARD)),) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1288 | |
| 1289 | EOF |
| 1290 | fi |
| 1291 | |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1292 | write_makefile_header "$BOARDMK" |
| 1293 | write_makefile_header "$PRODUCTMK" |
| 1294 | write_blueprint_header "$ANDROIDBP" |
| 1295 | |
| 1296 | cat << EOF >> "$ANDROIDBP" |
| 1297 | soong_namespace { |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 1298 | imports: [ |
| 1299 | EOF |
| 1300 | |
| 1301 | if [ ! -z "$DEVICE_COMMON" -a "$COMMON" -ne 1 ]; then |
| 1302 | cat << EOF >> "$ANDROIDBP" |
| 1303 | "vendor/${VENDOR_COMMON:-$VENDOR}/$DEVICE_COMMON", |
| 1304 | EOF |
| 1305 | fi |
| 1306 | vendor_imports "$ANDROIDBP" |
| 1307 | |
| 1308 | cat << EOF >> "$ANDROIDBP" |
| 1309 | ], |
| Rashed Abdel-Tawab | e204704 | 2019-09-20 07:06:09 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | EOF |
| 1313 | |
| 1314 | [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON" |
| 1315 | cat << EOF >> "$PRODUCTMK" |
| 1316 | PRODUCT_SOONG_NAMESPACES += \\ |
| 1317 | vendor/$VENDOR/$DEVICE |
| 1318 | |
| 1319 | EOF |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | # |
| 1323 | # write_footers: |
| 1324 | # |
| 1325 | # Closes the inital guard and any other finalization tasks. Must |
| 1326 | # be called as the final step. |
| 1327 | # |
| 1328 | function write_footers() { |
| 1329 | cat << EOF >> "$ANDROIDMK" |
| 1330 | endif |
| 1331 | EOF |
| 1332 | } |
| 1333 | |
| 1334 | # Return success if adb is up and not in recovery |
| 1335 | function _adb_connected { |
| 1336 | { |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1337 | if [[ "$(adb get-state)" == device ]] |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1338 | then |
| 1339 | return 0 |
| 1340 | fi |
| 1341 | } 2>/dev/null |
| 1342 | |
| 1343 | return 1 |
| 1344 | }; |
| 1345 | |
| 1346 | # |
| 1347 | # parse_file_list: |
| 1348 | # |
| 1349 | # $1: input file |
| Rashed Abdel-Tawab | b0d08e8 | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 1350 | # $2: blob section in file - optional |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1351 | # |
| 1352 | # Sets PRODUCT_PACKAGES and PRODUCT_COPY_FILES while parsing the input file |
| 1353 | # |
| 1354 | function parse_file_list() { |
| 1355 | if [ -z "$1" ]; then |
| 1356 | echo "An input file is expected!" |
| 1357 | exit 1 |
| 1358 | elif [ ! -f "$1" ]; then |
| 1359 | echo "Input file "$1" does not exist!" |
| 1360 | exit 1 |
| 1361 | fi |
| 1362 | |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1363 | if [ -n "$2" ]; then |
| 1364 | echo "Using section \"$2\"" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1365 | LIST=$EXTRACT_TMP_DIR/files.txt |
| Vladimir Oltean | fa79f21 | 2019-01-19 00:44:07 +0200 | [diff] [blame] | 1366 | # Match all lines starting with first line found to start* with '#' |
| 1367 | # comment and contain** $2, and ending with first line to be empty*. |
| 1368 | # *whitespaces (tabs, spaces) at the beginning of lines are discarded |
| 1369 | # **the $2 match is case-insensitive |
| 1370 | cat $1 | sed -n '/^[[:space:]]*#.*'"$2"'/I,/^[[:space:]]*$/ p' > $LIST |
| Rashed Abdel-Tawab | b0d08e8 | 2017-04-04 02:48:18 -0400 | [diff] [blame] | 1371 | else |
| 1372 | LIST=$1 |
| 1373 | fi |
| 1374 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1375 | PRODUCT_PACKAGES_LIST=() |
| 1376 | PRODUCT_PACKAGES_HASHES=() |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1377 | PRODUCT_PACKAGES_FIXUP_HASHES=() |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1378 | PRODUCT_SYMLINKS_LIST=() |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1379 | PRODUCT_COPY_FILES_LIST=() |
| 1380 | PRODUCT_COPY_FILES_HASHES=() |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1381 | PRODUCT_COPY_FILES_FIXUP_HASHES=() |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1382 | |
| 1383 | while read -r line; do |
| 1384 | if [ -z "$line" ]; then continue; fi |
| 1385 | |
| 1386 | # If the line has a pipe delimiter, a sha1 hash should follow. |
| 1387 | # This indicates the file should be pinned and not overwritten |
| 1388 | # when extracting files. |
| 1389 | local SPLIT=(${line//\|/ }) |
| 1390 | local COUNT=${#SPLIT[@]} |
| 1391 | local SPEC=${SPLIT[0]} |
| 1392 | local HASH="x" |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1393 | local FIXUP_HASH="x" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1394 | if [ "$COUNT" -gt "1" ]; then |
| 1395 | HASH=${SPLIT[1]} |
| 1396 | fi |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1397 | if [ "$COUNT" -gt "2" ]; then |
| 1398 | FIXUP_HASH=${SPLIT[2]} |
| 1399 | fi |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1400 | if [[ "$SPEC" =~ 'SYMLINK=' ]]; then |
| 1401 | PRODUCT_SYMLINKS_LIST+=("${SPEC#-}") |
| 1402 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1403 | # if line starts with a dash, it needs to be packaged |
| 1404 | if [[ "$SPEC" =~ ^- ]]; then |
| 1405 | PRODUCT_PACKAGES_LIST+=("${SPEC#-}") |
| 1406 | PRODUCT_PACKAGES_HASHES+=("$HASH") |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1407 | PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH") |
| Chirayu Desai | a774101 | 2021-12-04 07:17:28 +0530 | [diff] [blame] | 1408 | # if line contains apex, apk, jar or vintf fragment, it needs to be packaged |
| 1409 | elif suffix_match_file ".apex" "$(src_file "$SPEC")" || \ |
| 1410 | suffix_match_file ".apk" "$(src_file "$SPEC")" || \ |
| Michael Bestas | ea90aef | 2021-11-15 22:18:04 +0200 | [diff] [blame] | 1411 | suffix_match_file ".jar" "$(src_file "$SPEC")" || \ |
| Aaron Kling | 7f4d181 | 2023-11-02 16:04:22 -0500 | [diff] [blame] | 1412 | [[ "$TARGET_ENABLE_CHECKELF" == "true" && \ |
| 1413 | ( "${SPEC%%;*}" == *".so" || \ |
| 1414 | "$SPEC" == *"bin/"* || \ |
| 1415 | "$SPEC" == *"lib/rfsa"* ) ]] || \ |
| Michael Bestas | ea90aef | 2021-11-15 22:18:04 +0200 | [diff] [blame] | 1416 | [[ "$SPEC" == *"etc/vintf/manifest/"* ]]; then |
| 1417 | PRODUCT_PACKAGES_LIST+=("$SPEC") |
| 1418 | PRODUCT_PACKAGES_HASHES+=("$HASH") |
| 1419 | PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH") |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1420 | else |
| 1421 | PRODUCT_COPY_FILES_LIST+=("$SPEC") |
| 1422 | PRODUCT_COPY_FILES_HASHES+=("$HASH") |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1423 | PRODUCT_COPY_FILES_FIXUP_HASHES+=("$FIXUP_HASH") |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1424 | fi |
| 1425 | |
| Chirayu Desai | f1a2130 | 2022-09-13 00:29:33 +0530 | [diff] [blame] | 1426 | done < <(grep -v -E '(^#|^[[:space:]]*$)' "$LIST" | LC_ALL=C sort | uniq) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | # |
| 1430 | # write_makefiles: |
| 1431 | # |
| 1432 | # $1: file containing the list of items to extract |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 1433 | # $2: make treble compatible makefile - optional |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1434 | # |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1435 | # Calls write_product_copy_files, write_product_packages and |
| 1436 | # lastly write_symlink_packages on the given file and appends |
| 1437 | # to the Android.bp as well as the product makefile. |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1438 | # |
| 1439 | function write_makefiles() { |
| 1440 | parse_file_list "$1" |
| Rashed Abdel-Tawab | 7fd3ccb | 2017-10-07 14:18:39 -0400 | [diff] [blame] | 1441 | write_product_copy_files "$2" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1442 | write_product_packages |
| SamarV-121 | 5556e2d | 2024-03-19 08:50:02 +0530 | [diff] [blame] | 1443 | write_symlink_packages |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | # |
| 1447 | # append_firmware_calls_to_makefiles: |
| 1448 | # |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1449 | # $1: file containing the list of items to extract |
| 1450 | # |
| Michael Bestas | c72d0f6 | 2022-04-16 21:06:28 +0300 | [diff] [blame] | 1451 | # Appends the calls to all images present in radio folder to Android.mk |
| 1452 | # and radio AB_OTA_PARTITIONS to BoardConfigVendor.mk |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1453 | # |
| Michael Bestas | c72d0f6 | 2022-04-16 21:06:28 +0300 | [diff] [blame] | 1454 | function append_firmware_calls_to_makefiles() { |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1455 | parse_file_list "$1" |
| 1456 | |
| 1457 | local FILELIST=(${PRODUCT_COPY_FILES_LIST[@]}) |
| 1458 | local COUNT=${#FILELIST[@]} |
| 1459 | |
| SamarV-121 | 7e56a0b | 2024-03-09 12:58:18 +0530 | [diff] [blame] | 1460 | if [[ ${FILELIST[*]} =~ ";AB" ]]; then |
| 1461 | printf '%s\n' "AB_OTA_PARTITIONS += \\" >> "$BOARDMK" |
| 1462 | fi |
| 1463 | |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1464 | for (( i=1; i<COUNT+1; i++ )); do |
| 1465 | local DST_FILE=$(target_file "${FILELIST[$i-1]}") |
| 1466 | local ARGS=$(target_args "${FILELIST[$i-1]}") |
| LuK1337 | 11d8686 | 2023-12-11 01:34:29 +0100 | [diff] [blame] | 1467 | local SHA1=$(get_hash "$ANDROID_ROOT"/"$OUTDIR"/radio/"$DST_FILE") |
| Michael Bestas | c72d0f6 | 2022-04-16 21:06:28 +0300 | [diff] [blame] | 1468 | DST_FILE_NAME=(${DST_FILE//.img/ }) |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1469 | ARGS=(${ARGS//;/ }) |
| 1470 | LINEEND=" \\" |
| 1471 | if [ "$i" -eq "$COUNT" ]; then |
| 1472 | LINEEND="" |
| 1473 | fi |
| 1474 | |
| 1475 | for ARG in "${ARGS[@]}"; do |
| 1476 | if [[ "$ARG" =~ "AB" ]]; then |
| Michael Bestas | c72d0f6 | 2022-04-16 21:06:28 +0300 | [diff] [blame] | 1477 | printf ' %s%s\n' "$DST_FILE_NAME" "$LINEEND" >> "$BOARDMK" |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1478 | fi |
| 1479 | done |
| LuK1337 | 11d8686 | 2023-12-11 01:34:29 +0100 | [diff] [blame] | 1480 | printf '%s\n' "\$(call add-radio-file-sha1-checked,radio/$DST_FILE,$SHA1)" >> "$ANDROIDMK" |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1481 | done |
| Michael Bestas | c72d0f6 | 2022-04-16 21:06:28 +0300 | [diff] [blame] | 1482 | printf '\n' >> "$ANDROIDMK" |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1486 | # get_file: |
| 1487 | # |
| 1488 | # $1: input file |
| 1489 | # $2: target file/folder |
| 1490 | # $3: source of the file (can be "adb" or a local folder) |
| 1491 | # |
| 1492 | # Silently extracts the input file to defined target |
| 1493 | # Returns success if file can be pulled from the device or found locally |
| 1494 | # |
| 1495 | function get_file() { |
| 1496 | local SRC="$3" |
| 1497 | |
| 1498 | if [ "$SRC" = "adb" ]; then |
| 1499 | # try to pull |
| LuK1337 | 0f7f0d1 | 2022-08-19 21:49:56 +0200 | [diff] [blame] | 1500 | adb pull "$1" "$2" >/dev/null 2>&1 && return 0 |
| 1501 | adb pull "${1#/system}" "$2" >/dev/null 2>&1 && return 0 |
| 1502 | adb pull "system/$1" "$2" >/dev/null 2>&1 && return 0 |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1503 | |
| 1504 | return 1 |
| 1505 | else |
| 1506 | # try to copy |
| Vladimir Oltean | fe49eae | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 1507 | cp -r "$SRC/$1" "$2" 2>/dev/null && return 0 |
| 1508 | cp -r "$SRC/${1#/system}" "$2" 2>/dev/null && return 0 |
| Vladimir Oltean | 6780da3 | 2019-01-06 19:38:31 +0200 | [diff] [blame] | 1509 | cp -r "$SRC/system/$1" "$2" 2>/dev/null && return 0 |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1510 | |
| LuK1337 | dbb77cc | 2023-12-04 19:03:10 +0100 | [diff] [blame] | 1511 | # try /vendor/odm for devices without /odm partition |
| 1512 | [[ "$1" == /system/odm/* ]] && cp -r "$SRC/vendor/${1#/system}" "$2" 2>/dev/null && return 0 |
| 1513 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1514 | return 1 |
| 1515 | fi |
| 1516 | }; |
| 1517 | |
| 1518 | # |
| 1519 | # oat2dex: |
| 1520 | # |
| 1521 | # $1: extracted apk|jar (to check if deodex is required) |
| 1522 | # $2: odexed apk|jar to deodex |
| 1523 | # $3: source of the odexed apk|jar |
| 1524 | # |
| 1525 | # Convert apk|jar .odex in the corresposing classes.dex |
| 1526 | # |
| 1527 | function oat2dex() { |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1528 | local OMNI_TARGET="$1" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1529 | local OEM_TARGET="$2" |
| 1530 | local SRC="$3" |
| 1531 | local TARGET= |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1532 | local OAT= |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1533 | |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1534 | if [ -z "$BAKSMALIJAR" ] || [ -z "$SMALIJAR" ]; then |
| Michael Bestas | 6d90893 | 2020-12-19 03:29:25 +0200 | [diff] [blame] | 1535 | export BAKSMALIJAR="$ANDROID_ROOT"/vendor/omni/build/tools/smali/baksmali.jar |
| 1536 | export SMALIJAR="$ANDROID_ROOT"/vendor/omni/build/tools/smali/smali.jar |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1537 | fi |
| 1538 | |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1539 | if [ -z "$VDEXEXTRACTOR" ]; then |
| micky387 | 0cdacd0 | 2024-07-17 21:28:44 -0400 | [diff] [blame] | 1540 | export VDEXEXTRACTOR="$BINARIES_LOCATION"/vdexExtractor |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1541 | fi |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1542 | |
| codeworkx | 85eda75 | 2018-09-23 12:36:57 +0200 | [diff] [blame] | 1543 | if [ -z "$CDEXCONVERTER" ]; then |
| micky387 | 0cdacd0 | 2024-07-17 21:28:44 -0400 | [diff] [blame] | 1544 | export CDEXCONVERTER="$BINARIES_LOCATION"/compact_dex_converter |
| codeworkx | 85eda75 | 2018-09-23 12:36:57 +0200 | [diff] [blame] | 1545 | fi |
| 1546 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1547 | # Extract existing boot.oats to the temp folder |
| 1548 | if [ -z "$ARCHES" ]; then |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1549 | echo "Checking if system is odexed and locating boot.oats..." |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1550 | for ARCH in "arm64" "arm" "x86_64" "x86"; do |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1551 | mkdir -p "$EXTRACT_TMP_DIR/system/framework/$ARCH" |
| 1552 | if get_file "/system/framework/$ARCH" "$EXTRACT_TMP_DIR/system/framework/" "$SRC"; then |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1553 | ARCHES+="$ARCH " |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1554 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1555 | rmdir "$EXTRACT_TMP_DIR/system/framework/$ARCH" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1556 | fi |
| 1557 | done |
| 1558 | fi |
| 1559 | |
| 1560 | if [ -z "$ARCHES" ]; then |
| 1561 | FULLY_DEODEXED=1 && return 0 # system is fully deodexed, return |
| 1562 | fi |
| 1563 | |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1564 | if [ ! -f "$OMNI_TARGET" ]; then |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1565 | return; |
| 1566 | fi |
| 1567 | |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1568 | if grep "classes.dex" "$OMNI_TARGET" >/dev/null; then |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1569 | return 0 # target apk|jar is already odexed, return |
| 1570 | fi |
| 1571 | |
| 1572 | for ARCH in $ARCHES; do |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1573 | BOOTOAT="$EXTRACT_TMP_DIR/system/framework/$ARCH/boot.oat" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1574 | |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1575 | local OAT="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").odex" |
| 1576 | local VDEX="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").vdex" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1577 | |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1578 | if get_file "$OAT" "$EXTRACT_TMP_DIR" "$SRC"; then |
| 1579 | if get_file "$VDEX" "$EXTRACT_TMP_DIR" "$SRC"; then |
| 1580 | "$VDEXEXTRACTOR" -o "$EXTRACT_TMP_DIR/" -i "$EXTRACT_TMP_DIR/$(basename "$VDEX")" > /dev/null |
| 1581 | CLASSES=$(ls "$EXTRACT_TMP_DIR/$(basename "${OEM_TARGET%.*}")_classes"*) |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1582 | for CLASS in $CLASSES; do |
| 1583 | NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/') |
| 1584 | # Check if we have to deal with CompactDex |
| 1585 | if [[ "$CLASS" == *.cdex ]]; then |
| 1586 | "$CDEXCONVERTER" "$CLASS" &>/dev/null |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1587 | mv "$CLASS.new" "$EXTRACT_TMP_DIR/$NEWCLASS" |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1588 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1589 | mv "$CLASS" "$EXTRACT_TMP_DIR/$NEWCLASS" |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1590 | fi |
| 1591 | done |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1592 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1593 | java -jar "$BAKSMALIJAR" deodex -o "$EXTRACT_TMP_DIR/dexout" -b "$BOOTOAT" -d "$EXTRACT_TMP_DIR" "$EXTRACT_TMP_DIR/$(basename "$OAT")" |
| 1594 | java -jar "$SMALIJAR" assemble "$EXTRACT_TMP_DIR/dexout" -o "$EXTRACT_TMP_DIR/classes.dex" |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1595 | fi |
| theimpulson | 9a911af | 2019-08-14 03:25:12 +0000 | [diff] [blame] | 1596 | elif [[ "$OMNI_TARGET" =~ .jar$ ]]; then |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1597 | JAROAT="$EXTRACT_TMP_DIR/system/framework/$ARCH/boot-$(basename ${OEM_TARGET%.*}).oat" |
| Luca Stefani | 082f1e8 | 2018-10-07 12:44:53 +0200 | [diff] [blame] | 1598 | JARVDEX="/system/framework/boot-$(basename ${OEM_TARGET%.*}).vdex" |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1599 | if [ ! -f "$JAROAT" ]; then |
| Luca Stefani | 082f1e8 | 2018-10-07 12:44:53 +0200 | [diff] [blame] | 1600 | JAROAT=$BOOTOAT |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1601 | fi |
| Sebastiano Barezzi | e85075b | 2023-08-10 16:07:13 +0200 | [diff] [blame] | 1602 | if [ ! -f "$JARVDEX" ]; then |
| 1603 | JARVDEX="/system/framework/$ARCH/boot-$(basename ${OEM_TARGET%.*}).vdex" |
| 1604 | fi |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1605 | # try to extract classes.dex from boot.vdex for frameworks jars |
| 1606 | # fallback to boot.oat if vdex is not available |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1607 | if get_file "$JARVDEX" "$EXTRACT_TMP_DIR" "$SRC"; then |
| 1608 | "$VDEXEXTRACTOR" -o "$EXTRACT_TMP_DIR/" -i "$EXTRACT_TMP_DIR/$(basename "$JARVDEX")" > /dev/null |
| Sebastiano Barezzi | e85075b | 2023-08-10 16:07:13 +0200 | [diff] [blame] | 1609 | CLASSES=$(ls "$EXTRACT_TMP_DIR/$(basename "${JARVDEX%.*}")_classes"* 2> /dev/null) |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1610 | for CLASS in $CLASSES; do |
| 1611 | NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/') |
| 1612 | # Check if we have to deal with CompactDex |
| 1613 | if [[ "$CLASS" == *.cdex ]]; then |
| 1614 | "$CDEXCONVERTER" "$CLASS" &>/dev/null |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1615 | mv "$CLASS.new" "$EXTRACT_TMP_DIR/$NEWCLASS" |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1616 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1617 | mv "$CLASS" "$EXTRACT_TMP_DIR/$NEWCLASS" |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1618 | fi |
| 1619 | done |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1620 | else |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1621 | java -jar "$BAKSMALIJAR" deodex -o "$EXTRACT_TMP_DIR/dexout" -b "$BOOTOAT" -d "$EXTRACT_TMP_DIR" "$JAROAT/$OEM_TARGET" |
| 1622 | java -jar "$SMALIJAR" assemble "$EXTRACT_TMP_DIR/dexout" -o "$EXTRACT_TMP_DIR/classes.dex" |
| Joe Maples | fb3941c | 2018-01-05 14:51:33 -0500 | [diff] [blame] | 1623 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1624 | else |
| 1625 | continue |
| 1626 | fi |
| 1627 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1628 | done |
| Rashed Abdel-Tawab | d712497 | 2018-03-15 12:55:22 -0700 | [diff] [blame] | 1629 | |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1630 | rm -rf "$EXTRACT_TMP_DIR/dexout" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | # |
| 1634 | # init_adb_connection: |
| 1635 | # |
| 1636 | # Starts adb server and waits for the device |
| 1637 | # |
| 1638 | function init_adb_connection() { |
| 1639 | adb start-server # Prevent unexpected starting server message from adb get-state in the next line |
| 1640 | if ! _adb_connected; then |
| 1641 | echo "No device is online. Waiting for one..." |
| 1642 | echo "Please connect USB and/or enable USB debugging" |
| 1643 | until _adb_connected; do |
| 1644 | sleep 1 |
| 1645 | done |
| 1646 | echo "Device Found." |
| 1647 | fi |
| 1648 | |
| 1649 | # Retrieve IP and PORT info if we're using a TCP connection |
| Chirayu Desai | f1a2130 | 2022-09-13 00:29:33 +0530 | [diff] [blame] | 1650 | TCPIPPORT=$(adb devices | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \ |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1651 | | head -1 | awk '{print $1}') |
| 1652 | adb root &> /dev/null |
| 1653 | sleep 0.3 |
| 1654 | if [ -n "$TCPIPPORT" ]; then |
| 1655 | # adb root just killed our connection |
| 1656 | # so reconnect... |
| 1657 | adb connect "$TCPIPPORT" |
| 1658 | fi |
| 1659 | adb wait-for-device &> /dev/null |
| 1660 | sleep 0.3 |
| 1661 | } |
| 1662 | |
| 1663 | # |
| 1664 | # fix_xml: |
| 1665 | # |
| 1666 | # $1: xml file to fix |
| 1667 | # |
| 1668 | function fix_xml() { |
| 1669 | local XML="$1" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1670 | local TEMP_XML="$EXTRACT_TMP_DIR/`basename "$XML"`.temp" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1671 | |
| Dobroslaw Kijowski | 3af2a8d | 2017-05-18 12:35:02 +0200 | [diff] [blame] | 1672 | grep -a '^<?xml version' "$XML" > "$TEMP_XML" |
| 1673 | grep -av '^<?xml version' "$XML" >> "$TEMP_XML" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1674 | |
| 1675 | mv "$TEMP_XML" "$XML" |
| 1676 | } |
| 1677 | |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1678 | function get_hash() { |
| 1679 | local FILE="$1" |
| 1680 | |
| 1681 | if [ "$(uname)" == "Darwin" ]; then |
| 1682 | shasum "${FILE}" | awk '{print $1}' |
| 1683 | else |
| 1684 | sha1sum "${FILE}" | awk '{print $1}' |
| 1685 | fi |
| 1686 | } |
| 1687 | |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1688 | function print_spec() { |
| 1689 | local SPEC_PRODUCT_PACKAGE="$1" |
| 1690 | local SPEC_SRC_FILE="$2" |
| 1691 | local SPEC_DST_FILE="$3" |
| 1692 | local SPEC_ARGS="$4" |
| 1693 | local SPEC_HASH="$5" |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1694 | local SPEC_FIXUP_HASH="$6" |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1695 | |
| 1696 | local PRODUCT_PACKAGE="" |
| 1697 | if [ ${SPEC_PRODUCT_PACKAGE} = true ]; then |
| 1698 | PRODUCT_PACKAGE="-" |
| 1699 | fi |
| 1700 | local SRC="" |
| 1701 | if [ ! -z "${SPEC_SRC_FILE}" ] && [ "${SPEC_SRC_FILE}" != "${SPEC_DST_FILE}" ]; then |
| 1702 | SRC="${SPEC_SRC_FILE}:" |
| 1703 | fi |
| 1704 | local DST="" |
| 1705 | if [ ! -z "${SPEC_DST_FILE}" ]; then |
| 1706 | DST="${SPEC_DST_FILE}" |
| 1707 | fi |
| 1708 | local ARGS="" |
| 1709 | if [ ! -z "${SPEC_ARGS}" ]; then |
| 1710 | ARGS=";${SPEC_ARGS}" |
| 1711 | fi |
| 1712 | local HASH="" |
| 1713 | if [ ! -z "${SPEC_HASH}" ] && [ "${SPEC_HASH}" != "x" ]; then |
| 1714 | HASH="|${SPEC_HASH}" |
| 1715 | fi |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1716 | local FIXUP_HASH="" |
| 1717 | if [ ! -z "${SPEC_FIXUP_HASH}" ] && [ "${SPEC_FIXUP_HASH}" != "x" ] && [ "${SPEC_FIXUP_HASH}" != "${SPEC_HASH}" ]; then |
| 1718 | FIXUP_HASH="|${SPEC_FIXUP_HASH}" |
| 1719 | fi |
| 1720 | printf '%s%s%s%s%s%s\n' "${PRODUCT_PACKAGE}" "${SRC}" "${DST}" "${ARGS}" "${HASH}" "${FIXUP_HASH}" |
| 1721 | } |
| 1722 | |
| 1723 | # To be overridden by device-level extract-files.sh |
| 1724 | # Parameters: |
| 1725 | # $1: spec name of a blob. Can be used for filtering. |
| 1726 | # If the spec is "src:dest", then $1 is "dest". |
| 1727 | # If the spec is "src", then $1 is "src". |
| 1728 | # $2: path to blob file. Can be used for fixups. |
| 1729 | # |
| 1730 | function blob_fixup() { |
| 1731 | : |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1732 | } |
| 1733 | |
| Aaron Kling | b264919 | 2023-08-26 15:04:17 -0500 | [diff] [blame] | 1734 | # To be overridden by device-level extract-files.sh |
| 1735 | # Parameters: |
| 1736 | # $1: Path to vendor Android.bp |
| 1737 | # |
| 1738 | function vendor_imports() { |
| 1739 | : |
| 1740 | } |
| 1741 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1742 | # |
| Michael Bestas | f458ca0 | 2023-06-12 14:20:28 +0300 | [diff] [blame] | 1743 | # prepare_images: |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1744 | # |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1745 | # Positional parameters: |
| Michael Bestas | f458ca0 | 2023-06-12 14:20:28 +0300 | [diff] [blame] | 1746 | # $1: path to extracted system folder or an ota zip file |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1747 | # |
| Michael Bestas | f458ca0 | 2023-06-12 14:20:28 +0300 | [diff] [blame] | 1748 | function prepare_images() { |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1749 | # Consume positional parameters |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1750 | local SRC="$1"; shift |
| Michael Bestas | fc97f2d | 2023-06-12 13:53:31 +0300 | [diff] [blame] | 1751 | local KEEP_DUMP_DIR="$SRC" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1752 | |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1753 | if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then |
| Michael Bestas | 5312537 | 2023-12-13 18:06:36 +0200 | [diff] [blame] | 1754 | local BASENAME=$(basename "$SRC") |
| 1755 | local DIRNAME=$(dirname "$SRC") |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1756 | DUMPDIR="$EXTRACT_TMP_DIR"/system_dump |
| Michael Bestas | 5312537 | 2023-12-13 18:06:36 +0200 | [diff] [blame] | 1757 | KEEP_DUMP_DIR="$DIRNAME"/"${BASENAME%.zip}" |
| 1758 | if [ "$KEEP_DUMP" == "true" ] || [ "$KEEP_DUMP" == "1" ]; then |
| 1759 | rm -rf "$KEEP_DUMP_DIR" |
| 1760 | mkdir "$KEEP_DUMP_DIR" |
| 1761 | fi |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1762 | |
| 1763 | # Check if we're working with the same zip that was passed last time. |
| 1764 | # If so, let's just use what's already extracted. |
| 1765 | MD5=`md5sum "$SRC"| awk '{print $1}'` |
| 1766 | OLDMD5=`cat "$DUMPDIR"/zipmd5.txt` |
| 1767 | |
| 1768 | if [ "$MD5" != "$OLDMD5" ]; then |
| 1769 | rm -rf "$DUMPDIR" |
| 1770 | mkdir "$DUMPDIR" |
| 1771 | unzip "$SRC" -d "$DUMPDIR" |
| 1772 | echo "$MD5" > "$DUMPDIR"/zipmd5.txt |
| 1773 | |
| Chirayu Desai | 817dc76 | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1774 | # Extract A/B OTA |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1775 | if [ -a "$DUMPDIR"/payload.bin ]; then |
| Michael Bestas | c0e50db | 2023-12-13 19:43:49 +0200 | [diff] [blame] | 1776 | for PARTITION in "system" "odm" "product" "system_ext" "vendor" |
| 1777 | do |
| 1778 | "$OTA_EXTRACTOR" --payload "$DUMPDIR"/payload.bin --output_dir "$DUMPDIR" --partitions "$PARTITION" &2>&1 |
| 1779 | done |
| 1780 | wait |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1781 | fi |
| dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1782 | |
| Luca Stefani | 776be46 | 2020-09-09 15:53:58 +0200 | [diff] [blame] | 1783 | for PARTITION in "system" "odm" "product" "system_ext" "vendor" |
| dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1784 | do |
| 1785 | # If OTA is block based, extract it. |
| dianlujitao | e2cbe26 | 2020-04-21 23:01:13 +0800 | [diff] [blame] | 1786 | if [ -a "$DUMPDIR"/"$PARTITION".new.dat.br ]; then |
| 1787 | echo "Converting "$PARTITION".new.dat.br to "$PARTITION".new.dat" |
| 1788 | brotli -d "$DUMPDIR"/"$PARTITION".new.dat.br |
| 1789 | rm "$DUMPDIR"/"$PARTITION".new.dat.br |
| 1790 | fi |
| dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1791 | if [ -a "$DUMPDIR"/"$PARTITION".new.dat ]; then |
| 1792 | echo "Converting "$PARTITION".new.dat to "$PARTITION".img" |
| Michael Bestas | 6d90893 | 2020-12-19 03:29:25 +0200 | [diff] [blame] | 1793 | python "$ANDROID_ROOT"/vendor/omni/build/tools/sdat2img.py "$DUMPDIR"/"$PARTITION".transfer.list "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION".img 2>&1 |
| dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1794 | rm -rf "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION" |
| 1795 | mkdir "$DUMPDIR"/"$PARTITION" "$DUMPDIR"/tmp |
| Chirayu Desai | 62ed12a | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1796 | extract_img_data "$DUMPDIR"/"$PARTITION".img "$DUMPDIR"/"$PARTITION"/ |
| 1797 | rm "$DUMPDIR"/"$PARTITION".img |
| dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1798 | fi |
| Chirayu Desai | 817dc76 | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1799 | if [ -a "$DUMPDIR"/"$PARTITION".img ]; then |
| 1800 | extract_img_data "$DUMPDIR"/"$PARTITION".img "$DUMPDIR"/"$PARTITION"/ |
| 1801 | fi |
| dianlujitao | 85ddca6 | 2020-04-21 23:03:20 +0800 | [diff] [blame] | 1802 | done |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1803 | fi |
| 1804 | |
| Michael Bestas | fc97f2d | 2023-06-12 13:53:31 +0300 | [diff] [blame] | 1805 | if [ "$KEEP_DUMP" == "true" ] || [ "$KEEP_DUMP" == "1" ]; then |
| 1806 | rm -rf "$KEEP_DUMP_DIR"/system_dump |
| 1807 | cp -a "$DUMPDIR" "$KEEP_DUMP_DIR"/system_dump |
| 1808 | fi |
| 1809 | |
| Dan Pasanen | 0cc0501 | 2017-03-21 09:06:11 -0500 | [diff] [blame] | 1810 | SRC="$DUMPDIR" |
| 1811 | fi |
| 1812 | |
| Michael Bestas | f2501c3 | 2022-02-18 23:45:09 +0200 | [diff] [blame] | 1813 | if [ -d "$SRC" ] && [ -f "$SRC"/super.img ]; then |
| 1814 | DUMPDIR="$TMPDIR"/super_dump |
| 1815 | mkdir -p "$DUMPDIR" |
| 1816 | |
| 1817 | echo "Unpacking super.img" |
| 1818 | "$SIMG2IMG" "$SRC"/super.img "$DUMPDIR"/super.raw |
| 1819 | |
| 1820 | for PARTITION in "system" "odm" "product" "system_ext" "vendor" |
| 1821 | do |
| 1822 | echo "Preparing "$PARTITION"" |
| 1823 | if "$LPUNPACK" -p "$PARTITION"_a "$DUMPDIR"/super.raw "$DUMPDIR" ; then |
| 1824 | mv "$DUMPDIR"/"$PARTITION"_a.img "$DUMPDIR"/"$PARTITION".img |
| 1825 | else |
| 1826 | "$LPUNPACK" -p "$PARTITION" "$DUMPDIR"/super.raw "$DUMPDIR" |
| 1827 | fi |
| 1828 | done |
| Michael Bestas | 7c01b95 | 2023-06-12 14:21:54 +0300 | [diff] [blame] | 1829 | rm "$DUMPDIR"/super.raw |
| Michael Bestas | f2501c3 | 2022-02-18 23:45:09 +0200 | [diff] [blame] | 1830 | |
| Michael Bestas | fc97f2d | 2023-06-12 13:53:31 +0300 | [diff] [blame] | 1831 | if [ "$KEEP_DUMP" == "true" ] || [ "$KEEP_DUMP" == "1" ]; then |
| 1832 | rm -rf "$KEEP_DUMP_DIR"/super_dump |
| 1833 | cp -a "$DUMPDIR" "$KEEP_DUMP_DIR"/super_dump |
| 1834 | fi |
| 1835 | |
| Michael Bestas | f2501c3 | 2022-02-18 23:45:09 +0200 | [diff] [blame] | 1836 | SRC="$DUMPDIR" |
| 1837 | fi |
| 1838 | |
| Chirayu Desai | a3850bd | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1839 | if [ -d "$SRC" ] && [ -f "$SRC"/system.img ]; then |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 1840 | DUMPDIR="$EXTRACT_TMP_DIR"/system_dump |
| Chirayu Desai | a3850bd | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1841 | mkdir -p "$DUMPDIR" |
| 1842 | |
| 1843 | for PARTITION in "system" "odm" "product" "system_ext" "vendor" |
| 1844 | do |
| 1845 | echo "Extracting "$PARTITION"" |
| 1846 | local IMAGE="$SRC"/"$PARTITION".img |
| 1847 | if [ -f "$IMAGE" ]; then |
| LuK1337 | 07657db | 2023-11-30 18:11:51 +0100 | [diff] [blame] | 1848 | if [[ $(file -b "$IMAGE") == EROFS* ]]; then |
| 1849 | fsck.erofs --extract="$DUMPDIR"/"$PARTITION" "$IMAGE" |
| 1850 | elif [[ $(file -b "$IMAGE") == Linux* ]]; then |
| Chirayu Desai | a3850bd | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1851 | extract_img_data "$IMAGE" "$DUMPDIR"/"$PARTITION" |
| 1852 | elif [[ $(file -b "$IMAGE") == Android* ]]; then |
| Chirayu Desai | 501ffd6 | 2022-03-17 06:27:33 +0530 | [diff] [blame] | 1853 | "$SIMG2IMG" "$IMAGE" "$DUMPDIR"/"$PARTITION".raw |
| Chirayu Desai | a3850bd | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1854 | extract_img_data "$DUMPDIR"/"$PARTITION".raw "$DUMPDIR"/"$PARTITION"/ |
| 1855 | else |
| 1856 | echo "Unsupported "$IMAGE"" |
| 1857 | fi |
| 1858 | fi |
| 1859 | done |
| 1860 | |
| Michael Bestas | fc97f2d | 2023-06-12 13:53:31 +0300 | [diff] [blame] | 1861 | if [ "$KEEP_DUMP" == "true" ] || [ "$KEEP_DUMP" == "1" ]; then |
| 1862 | rm -rf "$KEEP_DUMP_DIR"/output |
| 1863 | cp -a "$DUMPDIR" "$KEEP_DUMP_DIR"/output |
| 1864 | fi |
| 1865 | |
| Chirayu Desai | a3850bd | 2021-11-26 05:47:25 +0530 | [diff] [blame] | 1866 | SRC="$DUMPDIR" |
| 1867 | fi |
| 1868 | |
| Michael Bestas | f458ca0 | 2023-06-12 14:20:28 +0300 | [diff] [blame] | 1869 | EXTRACT_SRC="$SRC" |
| 1870 | EXTRACT_STATE=1 |
| 1871 | } |
| 1872 | |
| 1873 | # |
| 1874 | # extract: |
| 1875 | # |
| 1876 | # Positional parameters: |
| 1877 | # $1: file containing the list of items to extract (aka proprietary-files.txt) |
| 1878 | # $2: path to extracted system folder, an ota zip file, or "adb" to extract from device |
| 1879 | # $3: section in list file to extract - optional. Setting section via $3 is deprecated. |
| 1880 | # |
| 1881 | # Non-positional parameters (coming after $2): |
| 1882 | # --section: preferred way of selecting the portion to parse and extract from |
| 1883 | # proprietary-files.txt |
| 1884 | # --kang: if present, this option will activate the printing of hashes for the |
| 1885 | # extracted blobs. Useful with --section for subsequent pinning of |
| 1886 | # blobs taken from other origins. |
| 1887 | # |
| 1888 | function extract() { |
| 1889 | # Consume positional parameters |
| 1890 | local PROPRIETARY_FILES_TXT="$1"; shift |
| 1891 | local SRC="$1"; shift |
| 1892 | local SECTION="" |
| 1893 | local KANG=false |
| 1894 | |
| 1895 | # Consume optional, non-positional parameters |
| 1896 | while [ "$#" -gt 0 ]; do |
| 1897 | case "$1" in |
| 1898 | -s|--section) |
| 1899 | SECTION="$2"; shift |
| 1900 | ;; |
| 1901 | -k|--kang) |
| 1902 | KANG=true |
| 1903 | DISABLE_PINNING=1 |
| 1904 | ;; |
| 1905 | *) |
| 1906 | # Backwards-compatibility with the old behavior, where $3, if |
| 1907 | # present, denoted an optional positional ${SECTION} argument. |
| 1908 | # Users of ${SECTION} are encouraged to migrate from setting it as |
| 1909 | # positional $3, to non-positional --section ${SECTION}, the |
| 1910 | # reason being that it doesn't scale to have more than 1 optional |
| 1911 | # positional argument. |
| 1912 | SECTION="$1" |
| 1913 | ;; |
| 1914 | esac |
| 1915 | shift |
| 1916 | done |
| 1917 | |
| 1918 | if [ -z "$OUTDIR" ]; then |
| 1919 | echo "Output dir not set!" |
| 1920 | exit 1 |
| 1921 | fi |
| 1922 | |
| 1923 | parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}" |
| 1924 | |
| 1925 | # Allow failing, so we can try $DEST and/or $FILE |
| 1926 | set +e |
| 1927 | |
| 1928 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} ) |
| 1929 | local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} ) |
| 1930 | local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} ) |
| 1931 | local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]} |
| 1932 | local COUNT=${#FILELIST[@]} |
| 1933 | local OUTPUT_ROOT="$ANDROID_ROOT"/"$OUTDIR"/proprietary |
| 1934 | local OUTPUT_TMP="$EXTRACT_TMP_DIR"/"$OUTDIR"/proprietary |
| 1935 | |
| 1936 | if [ "$SRC" = "adb" ]; then |
| 1937 | init_adb_connection |
| 1938 | fi |
| 1939 | |
| 1940 | if [ "$EXTRACT_STATE" -ne "1" ]; then |
| 1941 | prepare_images "$SRC" |
| 1942 | fi |
| 1943 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1944 | if [ "$VENDOR_STATE" -eq "0" ]; then |
| 1945 | echo "Cleaning output directory ($OUTPUT_ROOT).." |
| 1946 | rm -rf "${OUTPUT_TMP:?}" |
| 1947 | mkdir -p "${OUTPUT_TMP:?}" |
| Jake Whatley | 9843b32 | 2017-01-25 21:49:16 -0500 | [diff] [blame] | 1948 | if [ -d "$OUTPUT_ROOT" ]; then |
| 1949 | mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/" |
| 1950 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1951 | VENDOR_STATE=1 |
| 1952 | fi |
| 1953 | |
| Michael Bestas | f458ca0 | 2023-06-12 14:20:28 +0300 | [diff] [blame] | 1954 | echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${EXTRACT_SRC}:" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1955 | |
| 1956 | for (( i=1; i<COUNT+1; i++ )); do |
| 1957 | |
| Vladimir Oltean | 8e2de65 | 2018-06-24 20:41:30 +0300 | [diff] [blame] | 1958 | local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}") |
| Vladimir Oltean | b06f3aa | 2018-06-24 20:38:04 +0300 | [diff] [blame] | 1959 | local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}") |
| Vladimir Oltean | d639133 | 2018-06-24 20:42:01 +0300 | [diff] [blame] | 1960 | local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}") |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1961 | local OUTPUT_DIR= |
| 1962 | local TMP_DIR= |
| 1963 | local SRC_FILE= |
| 1964 | local DST_FILE= |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 1965 | local IS_PRODUCT_PACKAGE=false |
| 1966 | |
| 1967 | # Note: this relies on the fact that the ${FILELIST[@]} array |
| 1968 | # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}. |
| 1969 | if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then |
| 1970 | IS_PRODUCT_PACKAGE=true |
| 1971 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1972 | |
| Michael Bestas | bda3020 | 2020-12-28 04:44:52 +0200 | [diff] [blame] | 1973 | OUTPUT_DIR="${OUTPUT_ROOT}" |
| 1974 | TMP_DIR="${OUTPUT_TMP}" |
| 1975 | SRC_FILE="/system/${SPEC_SRC_FILE}" |
| 1976 | DST_FILE="/system/${SPEC_DST_FILE}" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1977 | |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1978 | # Strip the file path in the vendor repo of "system", if present |
| Vladimir Oltean | 724a7bc | 2019-01-17 03:04:16 +0200 | [diff] [blame] | 1979 | local BLOB_DISPLAY_NAME="${DST_FILE#/system/}" |
| dianlujitao | 4ddcfb7 | 2020-04-06 12:43:16 +0800 | [diff] [blame] | 1980 | local VENDOR_REPO_FILE="$OUTPUT_DIR/${BLOB_DISPLAY_NAME}" |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1981 | mkdir -p $(dirname "${VENDOR_REPO_FILE}") |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 1982 | |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1983 | # Check pinned files |
| Vladimir Oltean | e688cf9 | 2019-01-17 02:47:02 +0200 | [diff] [blame] | 1984 | local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1985 | local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1986 | local KEEP="" |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1987 | if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then |
| Vladimir Oltean | 4daf559 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1988 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 1989 | local PINNED="${VENDOR_REPO_FILE}" |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1990 | else |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 1991 | local PINNED="${TMP_DIR}${DST_FILE#/system}" |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1992 | fi |
| 1993 | if [ -f "$PINNED" ]; then |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 1994 | local TMP_HASH=$(get_hash "${PINNED}") |
| 1995 | if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1996 | KEEP="1" |
| Vladimir Oltean | 4daf559 | 2018-06-24 20:46:42 +0300 | [diff] [blame] | 1997 | if [ ! -f "${VENDOR_REPO_FILE}" ]; then |
| 1998 | cp -p "$PINNED" "${VENDOR_REPO_FILE}" |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 1999 | fi |
| 2000 | fi |
| 2001 | fi |
| 2002 | fi |
| 2003 | |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 2004 | if [ "${KANG}" = false ]; then |
| 2005 | printf ' - %s\n' "${BLOB_DISPLAY_NAME}" |
| 2006 | fi |
| 2007 | |
| Gabriele M | 58270a3 | 2017-11-13 23:15:29 +0100 | [diff] [blame] | 2008 | if [ "$KEEP" = "1" ]; then |
| Arian | 2d80238 | 2021-09-09 15:18:35 +0200 | [diff] [blame] | 2009 | if [ "${FIXUP_HASH}" != "x" ]; then |
| 2010 | printf ' + keeping pinned file with hash %s\n' "${FIXUP_HASH}" |
| 2011 | else |
| 2012 | printf ' + keeping pinned file with hash %s\n' "${HASH}" |
| 2013 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2014 | else |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 2015 | FOUND=false |
| 2016 | # Try Lineage target first. |
| 2017 | # Also try to search for files stripped of |
| 2018 | # the "/system" prefix, if we're actually extracting |
| 2019 | # from a system image. |
| Vladimir Oltean | fe49eae | 2018-06-25 00:05:56 +0300 | [diff] [blame] | 2020 | for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do |
| Michael Bestas | f458ca0 | 2023-06-12 14:20:28 +0300 | [diff] [blame] | 2021 | get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${EXTRACT_SRC} && { |
| Vladimir Oltean | b5500d7 | 2018-06-24 21:06:12 +0300 | [diff] [blame] | 2022 | FOUND=true |
| 2023 | break |
| 2024 | } |
| 2025 | done |
| 2026 | |
| 2027 | if [ "${FOUND}" = false ]; then |
| Bruno Martins | 74e00eb | 2021-04-10 14:36:50 +0100 | [diff] [blame] | 2028 | colored_echo red " !! ${BLOB_DISPLAY_NAME}: file not found in source" |
| Vladimir Oltean | 1132937 | 2018-10-18 00:44:02 +0300 | [diff] [blame] | 2029 | continue |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2030 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2031 | |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 2032 | # Blob fixup pipeline has 2 parts: one that is fixed and |
| 2033 | # one that is user-configurable |
| 2034 | local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
| 2035 | # Deodex apk|jar if that's the case |
| 2036 | if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then |
| Michael Bestas | f458ca0 | 2023-06-12 14:20:28 +0300 | [diff] [blame] | 2037 | oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "$EXTRACT_SRC" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 2038 | if [ -f "$EXTRACT_TMP_DIR/classes.dex" ]; then |
| 2039 | touch -t 200901010000 "$EXTRACT_TMP_DIR/classes"* |
| 2040 | zip -gjq "${VENDOR_REPO_FILE}" "$EXTRACT_TMP_DIR/classes"* |
| 2041 | rm "$EXTRACT_TMP_DIR/classes"* |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 2042 | printf ' (updated %s from odex files)\n' "${SRC_FILE}" |
| 2043 | fi |
| 2044 | elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then |
| 2045 | fix_xml "${VENDOR_REPO_FILE}" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2046 | fi |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 2047 | # Now run user-supplied fixup function |
| 2048 | blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}" |
| 2049 | local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2050 | |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 2051 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 2052 | local DIR=$(dirname "${VENDOR_REPO_FILE}") |
| 2053 | local TYPE="${DIR##*/}" |
| Michael Bestas | bda3020 | 2020-12-28 04:44:52 +0200 | [diff] [blame] | 2054 | if [ "$TYPE" = "bin" ]; then |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 2055 | chmod 755 "${VENDOR_REPO_FILE}" |
| 2056 | else |
| 2057 | chmod 644 "${VENDOR_REPO_FILE}" |
| 2058 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2059 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2060 | |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 2061 | if [ "${KANG}" = true ]; then |
| 2062 | print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}" |
| 2063 | fi |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 2064 | |
| Arian | 5f98d79 | 2021-09-09 15:24:25 +0200 | [diff] [blame] | 2065 | # Check and print whether the fixup pipeline actually did anything. |
| 2066 | # This isn't done right after the fixup pipeline because we want this print |
| 2067 | # to come after print_spec above, when in kang mode. |
| 2068 | if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then |
| 2069 | printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}" |
| 2070 | # Now sanity-check the spec for this blob. |
| 2071 | if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then |
| 2072 | colored_echo yellow "WARNING: The ${BLOB_DISPLAY_NAME} file was fixed up, but it is pinned." |
| 2073 | colored_echo yellow "This is a mistake and you want to either remove the hash completely, or add an extra one." |
| 2074 | fi |
| Vladimir Oltean | de985fe | 2019-01-17 03:07:34 +0200 | [diff] [blame] | 2075 | fi |
| Vladimir Oltean | a7d2049 | 2019-01-17 03:05:52 +0200 | [diff] [blame] | 2076 | fi |
| 2077 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2078 | done |
| 2079 | |
| 2080 | # Don't allow failing |
| 2081 | set -e |
| 2082 | } |
| 2083 | |
| 2084 | # |
| Rashed Abdel-Tawab | 5b97a98 | 2019-09-29 01:19:57 -0400 | [diff] [blame] | 2085 | # extract2: |
| 2086 | # |
| 2087 | # Positional parameters: |
| 2088 | # $1: file containing the list of items to extract (aka proprietary-files.txt) |
| 2089 | # |
| 2090 | # Non-positional parameters (coming after $2): |
| 2091 | # --section: selects the portion to parse and extracts from proprietary-files.txt |
| 2092 | # --kang: if present, this option will activate the printing of hashes for the |
| 2093 | # extracted blobs. Useful with --section for subsequent pinning of |
| 2094 | # blobs taken from other origins. |
| 2095 | # |
| 2096 | function extract2() { |
| 2097 | # Consume positional parameters |
| 2098 | local PROPRIETARY_FILES_TXT="$1"; shift |
| 2099 | local SECTION="" |
| 2100 | local KANG=false |
| 2101 | |
| 2102 | # Consume optional, non-positional parameters |
| 2103 | while [ "$#" -gt 0 ]; do |
| 2104 | case "$1" in |
| 2105 | --adb) |
| 2106 | ADB=true |
| 2107 | ;; |
| 2108 | --system) |
| 2109 | SYSTEM_SRC="$2"; shift |
| 2110 | ;; |
| 2111 | --vendor) |
| 2112 | VENDOR_SRC="$2"; shift |
| 2113 | ;; |
| 2114 | --odm) |
| 2115 | ODM_SRC="$2"; shift |
| 2116 | ;; |
| 2117 | --product) |
| 2118 | PRODUCT_SRC="$2"; shift |
| 2119 | ;; |
| 2120 | -s|--section) |
| 2121 | SECTION="$2"; shift |
| 2122 | ;; |
| 2123 | -k|--kang) |
| 2124 | KANG=true |
| 2125 | DISABLE_PINNING=1 |
| 2126 | ;; |
| 2127 | esac |
| 2128 | shift |
| 2129 | done |
| 2130 | |
| 2131 | if [ -z "$ADB" ] || [ -z "$SYSTEM_SRC" && -z "$VENDOR_SRC" && -z "$ODM_SRC" && -z "$PRODUCT_SRC" ]; then |
| 2132 | echo "No sources set! You must select --adb or pass paths to partition dumps." |
| 2133 | exit 1 |
| 2134 | fi |
| 2135 | |
| 2136 | if [ -z "$OUTDIR" ]; then |
| 2137 | echo "Output dir not set!" |
| 2138 | exit 1 |
| 2139 | fi |
| 2140 | |
| 2141 | parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}" |
| 2142 | |
| 2143 | # Allow failing, so we can try $DEST and/or $FILE |
| 2144 | set +e |
| 2145 | |
| 2146 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} ) |
| 2147 | local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} ) |
| 2148 | local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} ) |
| 2149 | local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]} |
| 2150 | local COUNT=${#FILELIST[@]} |
| Michael Bestas | 6d90893 | 2020-12-19 03:29:25 +0200 | [diff] [blame] | 2151 | local OUTPUT_ROOT="$ANDROID_ROOT"/"$OUTDIR"/proprietary |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 2152 | local OUTPUT_TMP="$EXTRACT_TMP_DIR"/"$OUTDIR"/proprietary |
| Rashed Abdel-Tawab | 5b97a98 | 2019-09-29 01:19:57 -0400 | [diff] [blame] | 2153 | |
| 2154 | if [ "$ADB" = true ]; then |
| 2155 | init_adb_connection |
| 2156 | fi |
| 2157 | |
| 2158 | if [ "$VENDOR_STATE" -eq "0" ]; then |
| 2159 | echo "Cleaning output directory ($OUTPUT_ROOT).." |
| 2160 | rm -rf "${OUTPUT_TMP:?}" |
| 2161 | mkdir -p "${OUTPUT_TMP:?}" |
| 2162 | if [ -d "$OUTPUT_ROOT" ]; then |
| 2163 | mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/" |
| 2164 | fi |
| 2165 | VENDOR_STATE=1 |
| 2166 | fi |
| 2167 | |
| 2168 | echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:" |
| 2169 | |
| 2170 | for (( i=1; i<COUNT+1; i++ )); do |
| 2171 | |
| 2172 | local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}") |
| 2173 | local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}") |
| 2174 | local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}") |
| 2175 | local OUTPUT_DIR= |
| 2176 | local TMP_DIR= |
| 2177 | local SRC_FILE= |
| 2178 | local DST_FILE= |
| 2179 | local IS_PRODUCT_PACKAGE=false |
| 2180 | |
| 2181 | # Note: this relies on the fact that the ${FILELIST[@]} array |
| 2182 | # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}. |
| 2183 | if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then |
| 2184 | IS_PRODUCT_PACKAGE=true |
| 2185 | fi |
| 2186 | |
| 2187 | if [ "${SPEC_ARGS}" = "rootfs" ]; then |
| 2188 | OUTPUT_DIR="${OUTPUT_ROOT}/rootfs" |
| 2189 | TMP_DIR="${OUTPUT_TMP}/rootfs" |
| 2190 | else |
| 2191 | OUTPUT_DIR="${OUTPUT_ROOT}" |
| 2192 | TMP_DIR="${OUTPUT_TMP}" |
| 2193 | fi |
| 2194 | SRC_FILE="${SPEC_SRC_FILE}" |
| 2195 | DST_FILE="${SPEC_DST_FILE}" |
| 2196 | |
| 2197 | local VENDOR_REPO_FILE="$OUTPUT_DIR/${DST_FILE}" |
| 2198 | local BLOB_DISPLAY_NAME="${DST_FILE}" |
| 2199 | mkdir -p $(dirname "${VENDOR_REPO_FILE}") |
| 2200 | |
| 2201 | # Check pinned files |
| 2202 | local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
| 2203 | local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')" |
| 2204 | local KEEP="" |
| 2205 | if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then |
| 2206 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 2207 | local PINNED="${VENDOR_REPO_FILE}" |
| 2208 | else |
| 2209 | local PINNED="${TMP_DIR}${DST_FILE}" |
| 2210 | fi |
| 2211 | if [ -f "$PINNED" ]; then |
| 2212 | local TMP_HASH=$(get_hash "${PINNED}") |
| 2213 | if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then |
| 2214 | KEEP="1" |
| 2215 | if [ ! -f "${VENDOR_REPO_FILE}" ]; then |
| 2216 | cp -p "$PINNED" "${VENDOR_REPO_FILE}" |
| 2217 | fi |
| 2218 | fi |
| 2219 | fi |
| 2220 | fi |
| 2221 | |
| 2222 | if [ "${KANG}" = false ]; then |
| 2223 | printf ' - %s\n' "${BLOB_DISPLAY_NAME}" |
| 2224 | fi |
| 2225 | |
| 2226 | if [ "$KEEP" = "1" ]; then |
| 2227 | printf ' + keeping pinned file with hash %s\n' "${HASH}" |
| 2228 | else |
| 2229 | FOUND=false |
| 2230 | PARTITION_SOURCE_DIR= |
| 2231 | # Try Lineage target first. |
| 2232 | for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do |
| 2233 | PARTITION=$(echo "$CANDIDATE" | cut -d/ -f1) |
| 2234 | if [ "$PARTITION" = "system" ]; then |
| 2235 | PARTITION_SOURCE_DIR="$SYSTEM_SRC" |
| 2236 | elif [ "$PARTITION" = "vendor" ]; then |
| 2237 | PARTITION_SOURCE_DIR="$VENDOR_SRC" |
| 2238 | elif [ "$PARTITION" = "product" ]; then |
| 2239 | PARTITION_SOURCE_DIR="$PRODUCT_SRC" |
| 2240 | elif [ "$PARTITION" = "odm" ]; then |
| 2241 | PARTITION_SOURCE_DIR="$ODM_SRC" |
| 2242 | fi |
| 2243 | CANDIDATE_RELATIVE_NAME=$(echo "$CANDIDATE" | cut -d/ -f2-) |
| 2244 | get_file ${CANDIDATE_RELATIVE_NAME} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && { |
| 2245 | FOUND=true |
| 2246 | break |
| 2247 | } |
| 2248 | # Search with the full system/ prefix if the file was not found on the system partition |
| 2249 | # because we may be searching in a mounted system-as-root system.img |
| 2250 | if [[ "${FOUND}" = false && "$PARTITION" = "system" ]]; then |
| 2251 | get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && { |
| 2252 | FOUND=true |
| 2253 | break |
| 2254 | } |
| 2255 | fi |
| 2256 | done |
| 2257 | |
| 2258 | if [ -z "${PARTITION_SOURCE_DIR}" ]; then |
| 2259 | echo "$CANDIDATE has no preceeding partition path. Prepend system/, vendor/, product/, or odm/ to this entry." |
| 2260 | fi |
| 2261 | |
| 2262 | if [ "${FOUND}" = false ]; then |
| 2263 | printf ' !! %s: file not found in source\n' "${BLOB_DISPLAY_NAME}" |
| 2264 | continue |
| 2265 | fi |
| 2266 | fi |
| 2267 | |
| 2268 | # Blob fixup pipeline has 2 parts: one that is fixed and |
| 2269 | # one that is user-configurable |
| 2270 | local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
| 2271 | # Deodex apk|jar if that's the case |
| 2272 | if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then |
| 2273 | oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "${SYSTEM_SRC}" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 2274 | if [ -f "$EXTRACT_TMP_DIR/classes.dex" ]; then |
| 2275 | zip -gjq "${VENDOR_REPO_FILE}" "$EXTRACT_TMP_DIR/classes"* |
| 2276 | rm "$EXTRACT_TMP_DIR/classes"* |
| Rashed Abdel-Tawab | 5b97a98 | 2019-09-29 01:19:57 -0400 | [diff] [blame] | 2277 | printf ' (updated %s from odex files)\n' "${SRC_FILE}" |
| 2278 | fi |
| 2279 | elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then |
| 2280 | fix_xml "${VENDOR_REPO_FILE}" |
| 2281 | fi |
| 2282 | # Now run user-supplied fixup function |
| 2283 | blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}" |
| 2284 | local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE}) |
| 2285 | |
| 2286 | if [ -f "${VENDOR_REPO_FILE}" ]; then |
| 2287 | local DIR=$(dirname "${VENDOR_REPO_FILE}") |
| 2288 | local TYPE="${DIR##*/}" |
| 2289 | if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then |
| 2290 | chmod 755 "${VENDOR_REPO_FILE}" |
| 2291 | else |
| 2292 | chmod 644 "${VENDOR_REPO_FILE}" |
| 2293 | fi |
| 2294 | fi |
| 2295 | |
| 2296 | if [ "${KANG}" = true ]; then |
| 2297 | print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}" |
| 2298 | fi |
| 2299 | |
| 2300 | # Check and print whether the fixup pipeline actually did anything. |
| 2301 | # This isn't done right after the fixup pipeline because we want this print |
| 2302 | # to come after print_spec above, when in kang mode. |
| 2303 | if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then |
| 2304 | printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}" |
| 2305 | # Now sanity-check the spec for this blob. |
| 2306 | if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then |
| 2307 | printf "WARNING: The %s file was fixed up, but it is pinned.\n" ${BLOB_DISPLAY_NAME} |
| 2308 | printf "This is a mistake and you want to either remove the hash completely, or add an extra one.\n" |
| 2309 | fi |
| 2310 | fi |
| 2311 | |
| 2312 | done |
| 2313 | |
| 2314 | # Don't allow failing |
| 2315 | set -e |
| 2316 | } |
| 2317 | |
| 2318 | # |
| Michael Bestas | f3c5908 | 2023-11-30 20:26:02 +0200 | [diff] [blame] | 2319 | # To be overridden by device-level extract-files.sh |
| 2320 | # |
| 2321 | function prepare_firmware() { |
| 2322 | : |
| 2323 | } |
| 2324 | |
| 2325 | # |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2326 | # extract_firmware: |
| 2327 | # |
| 2328 | # $1: file containing the list of items to extract |
| 2329 | # $2: path to extracted radio folder |
| 2330 | # |
| 2331 | function extract_firmware() { |
| 2332 | if [ -z "$OUTDIR" ]; then |
| 2333 | echo "Output dir not set!" |
| 2334 | exit 1 |
| 2335 | fi |
| 2336 | |
| 2337 | parse_file_list "$1" |
| 2338 | |
| 2339 | # Don't allow failing |
| 2340 | set -e |
| 2341 | |
| 2342 | local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ) |
| 2343 | local COUNT=${#FILELIST[@]} |
| 2344 | local SRC="$2" |
| Michael Bestas | 6d90893 | 2020-12-19 03:29:25 +0200 | [diff] [blame] | 2345 | local OUTPUT_DIR="$ANDROID_ROOT"/"$OUTDIR"/radio |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2346 | |
| 2347 | if [ "$VENDOR_RADIO_STATE" -eq "0" ]; then |
| 2348 | echo "Cleaning firmware output directory ($OUTPUT_DIR).." |
| 2349 | rm -rf "${OUTPUT_DIR:?}/"* |
| 2350 | VENDOR_RADIO_STATE=1 |
| 2351 | fi |
| 2352 | |
| 2353 | echo "Extracting $COUNT files in $1 from $SRC:" |
| 2354 | |
| Michael Bestas | f3c5908 | 2023-11-30 20:26:02 +0200 | [diff] [blame] | 2355 | prepare_firmware |
| 2356 | |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2357 | for (( i=1; i<COUNT+1; i++ )); do |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 2358 | local SRC_FILE=$(src_file "${FILELIST[$i-1]}") |
| 2359 | local DST_FILE=$(target_file "${FILELIST[$i-1]}") |
| Michael Bestas | 6975c64 | 2023-07-18 15:55:55 +0300 | [diff] [blame] | 2360 | local COPY_FILE= |
| Michael Bestas | f62d403 | 2022-02-22 19:06:41 +0200 | [diff] [blame] | 2361 | |
| 2362 | printf ' - %s \n' "radio/$DST_FILE" |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2363 | |
| 2364 | if [ ! -d "$OUTPUT_DIR" ]; then |
| 2365 | mkdir -p "$OUTPUT_DIR" |
| 2366 | fi |
| Chirayu Desai | 1041868 | 2022-05-25 23:37:27 +0530 | [diff] [blame] | 2367 | if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then |
| 2368 | # Extract A/B OTA |
| 2369 | if [ -a "$DUMPDIR"/payload.bin ]; then |
| Michael Bestas | d898eea | 2023-12-13 18:00:41 +0200 | [diff] [blame] | 2370 | "$OTA_EXTRACTOR" --payload "$DUMPDIR"/payload.bin --output_dir "$DUMPDIR" --partitions $(basename "${DST_FILE%.*}") 2>&1 |
| Michael Bestas | 6975c64 | 2023-07-18 15:55:55 +0300 | [diff] [blame] | 2371 | if [ -f "$DUMPDIR/$(basename $DST_FILE)" ]; then |
| 2372 | COPY_FILE="$DUMPDIR/$(basename $DST_FILE)" |
| 2373 | fi |
| Chirayu Desai | 1041868 | 2022-05-25 23:37:27 +0530 | [diff] [blame] | 2374 | fi |
| Michael Bestas | ed3cae9 | 2023-04-13 16:38:34 +0300 | [diff] [blame] | 2375 | else |
| Chirayu Desai | 1041868 | 2022-05-25 23:37:27 +0530 | [diff] [blame] | 2376 | if [ -f "$SRC/$SRC_FILE" ]; then |
| Michael Bestas | 6975c64 | 2023-07-18 15:55:55 +0300 | [diff] [blame] | 2377 | COPY_FILE="$SRC/$SRC_FILE" |
| 2378 | elif [ -f "$SRC/$DST_FILE" ]; then |
| 2379 | COPY_FILE="$SRC/$DST_FILE" |
| Chirayu Desai | 1041868 | 2022-05-25 23:37:27 +0530 | [diff] [blame] | 2380 | fi |
| Michael Bestas | 2664f08 | 2024-01-02 23:08:02 +0200 | [diff] [blame] | 2381 | if [[ $(file -b "$COPY_FILE") == Android* ]]; then |
| 2382 | "$SIMG2IMG" "$COPY_FILE" "$SRC"/"$(basename "$COPY_FILE").raw" |
| 2383 | COPY_FILE="$SRC"/"$(basename "$COPY_FILE").raw" |
| 2384 | fi |
| Michael Bestas | ed3cae9 | 2023-04-13 16:38:34 +0300 | [diff] [blame] | 2385 | fi |
| Michael Bestas | 6975c64 | 2023-07-18 15:55:55 +0300 | [diff] [blame] | 2386 | |
| 2387 | if [ -f "$COPY_FILE" ]; then |
| 2388 | cp "$COPY_FILE" "$OUTPUT_DIR/$DST_FILE" |
| 2389 | chmod 644 "$OUTPUT_DIR/$DST_FILE" |
| 2390 | else |
| 2391 | colored_echo yellow "${DST_FILE} not found, skipping copy" |
| 2392 | fi |
| Steve Kondik | 5bd6660 | 2016-07-15 10:39:58 -0700 | [diff] [blame] | 2393 | done |
| 2394 | } |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2395 | |
| 2396 | function extract_img_data() { |
| 2397 | local image_file="$1" |
| 2398 | local out_dir="$2" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 2399 | local logFile="$EXTRACT_TMP_DIR/debugfs.log" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2400 | |
| 2401 | if [ ! -d "$out_dir" ]; then |
| 2402 | mkdir -p "$out_dir" |
| 2403 | fi |
| 2404 | |
| 2405 | if [[ "$HOST_OS" == "Darwin" ]]; then |
| 2406 | debugfs -R "rdump / \"$out_dir\"" "$image_file" &> "$logFile" || { |
| 2407 | echo "[-] Failed to extract data from '$image_file'" |
| 2408 | abort 1 |
| 2409 | } |
| 2410 | else |
| 2411 | debugfs -R 'ls -p' "$image_file" 2>/dev/null | cut -d '/' -f6 | while read -r entry |
| 2412 | do |
| 2413 | debugfs -R "rdump \"$entry\" \"$out_dir\"" "$image_file" >> "$logFile" 2>&1 || { |
| 2414 | echo "[-] Failed to extract data from '$image_file'" |
| 2415 | abort 1 |
| 2416 | } |
| 2417 | done |
| 2418 | fi |
| 2419 | |
| 2420 | local symlink_err="rdump: Attempt to read block from filesystem resulted in short read while reading symlink" |
| 2421 | if grep -Fq "$symlink_err" "$logFile"; then |
| 2422 | echo "[-] Symlinks have not been properly processed from $image_file" |
| Michael Bestas | 1b57025 | 2021-12-02 21:05:36 +0200 | [diff] [blame] | 2423 | echo "[!] You might not have a compatible debugfs version" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2424 | abort 1 |
| 2425 | fi |
| 2426 | } |
| 2427 | |
| 2428 | declare -ra VENDOR_SKIP_FILES=( |
| 2429 | "bin/toybox_vendor" |
| 2430 | "bin/toolbox" |
| 2431 | "bin/grep" |
| 2432 | "build.prop" |
| 2433 | "compatibility_matrix.xml" |
| 2434 | "default.prop" |
| 2435 | "etc/NOTICE.xml.gz" |
| 2436 | "etc/vintf/compatibility_matrix.xml" |
| 2437 | "etc/vintf/manifest.xml" |
| 2438 | "etc/wifi/wpa_supplicant.conf" |
| 2439 | "manifest.xml" |
| 2440 | "overlay/DisplayCutoutEmulationCorner/DisplayCutoutEmulationCornerOverlay.apk" |
| 2441 | "overlay/DisplayCutoutEmulationDouble/DisplayCutoutEmulationDoubleOverlay.apk" |
| 2442 | "overlay/DisplayCutoutEmulationTall/DisplayCutoutEmulationTallOverlay.apk" |
| 2443 | "overlay/DisplayCutoutNoCutout/NoCutoutOverlay.apk" |
| 2444 | "overlay/framework-res__auto_generated_rro.apk" |
| 2445 | "overlay/SysuiDarkTheme/SysuiDarkThemeOverlay.apk" |
| 2446 | ) |
| 2447 | |
| 2448 | function array_contains() { |
| 2449 | local element |
| 2450 | for element in "${@:2}"; do [[ "$element" == "$1" ]] && return 0; done |
| 2451 | return 1 |
| 2452 | } |
| 2453 | |
| 2454 | function generate_prop_list_from_image() { |
| 2455 | local image_file="$1" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 2456 | local image_dir="$EXTRACT_TMP_DIR/image-temp" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2457 | local output_list="$2" |
| Chirayu Desai | 5da0bf8 | 2022-10-19 02:58:42 +0530 | [diff] [blame] | 2458 | local output_list_tmp="$EXTRACT_TMP_DIR/_proprietary-blobs.txt" |
| Michael Bestas | ca5d78a | 2021-12-02 20:58:40 +0200 | [diff] [blame] | 2459 | local -n skipped_files="$3" |
| Michael Bestas | fc1a22e | 2023-06-11 17:45:46 +0300 | [diff] [blame] | 2460 | local component="$4" |
| 2461 | local partition="$component" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2462 | |
| Chirayu Desai | 203cc52 | 2021-12-04 01:18:45 +0530 | [diff] [blame] | 2463 | mkdir -p "$image_dir" |
| 2464 | |
| LuK1337 | 07657db | 2023-11-30 18:11:51 +0100 | [diff] [blame] | 2465 | if [[ $(file -b "$image_file") == EROFS* ]]; then |
| 2466 | fsck.erofs --extract="$image_dir" "$image_file" |
| 2467 | elif [[ $(file -b "$image_file") == Linux* ]]; then |
| Chirayu Desai | 203cc52 | 2021-12-04 01:18:45 +0530 | [diff] [blame] | 2468 | extract_img_data "$image_file" "$image_dir" |
| 2469 | elif [[ $(file -b "$image_file") == Android* ]]; then |
| Chirayu Desai | 501ffd6 | 2022-03-17 06:27:33 +0530 | [diff] [blame] | 2470 | "$SIMG2IMG" "$image_file" "$image_dir"/"$(basename "$image_file").raw" |
| Chirayu Desai | 203cc52 | 2021-12-04 01:18:45 +0530 | [diff] [blame] | 2471 | extract_img_data "$image_dir"/"$(basename "$image_file").raw" "$image_dir" |
| 2472 | rm "$image_dir"/"$(basename "$image_file").raw" |
| 2473 | else |
| 2474 | echo "Unsupported "$image_file"" |
| 2475 | fi |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2476 | |
| Michael Bestas | fc1a22e | 2023-06-11 17:45:46 +0300 | [diff] [blame] | 2477 | if [ -z "$component" ]; then |
| 2478 | partition="vendor" |
| 2479 | elif [[ "$component" == "carriersettings" ]]; then |
| 2480 | partition="product" |
| 2481 | fi |
| 2482 | |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2483 | find "$image_dir" -not -type d | sed "s#^$image_dir/##" | while read -r FILE |
| 2484 | do |
| Michael Bestas | fc1a22e | 2023-06-11 17:45:46 +0300 | [diff] [blame] | 2485 | if [[ "$component" == "carriersettings" ]] && ! prefix_match_file "etc/CarrierSettings" "$FILE" ; then |
| 2486 | continue |
| 2487 | fi |
| Alessandro Astone | 60697c4 | 2020-12-04 01:04:01 +0100 | [diff] [blame] | 2488 | if suffix_match_file ".odex" "$FILE" || suffix_match_file ".vdex" "$FILE" ; then |
| 2489 | continue |
| 2490 | fi |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2491 | # Skip VENDOR_SKIP_FILES since it will be re-generated at build time |
| 2492 | if array_contains "$FILE" "${VENDOR_SKIP_FILES[@]}"; then |
| 2493 | continue |
| 2494 | fi |
| 2495 | # Skip device defined skipped files since they will be re-generated at build time |
| Michael Bestas | ca5d78a | 2021-12-02 20:58:40 +0200 | [diff] [blame] | 2496 | if array_contains "$FILE" "${skipped_files[@]}"; then |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2497 | continue |
| 2498 | fi |
| Michael Bestas | fc1a22e | 2023-06-11 17:45:46 +0300 | [diff] [blame] | 2499 | echo "$partition/$FILE" >> "$output_list_tmp" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2500 | done |
| 2501 | |
| 2502 | # Sort merged file with all lists |
| Michael Bestas | 1e6efb3 | 2021-11-15 19:28:56 +0200 | [diff] [blame] | 2503 | LC_ALL=C sort -u "$output_list_tmp" > "$output_list" |
| Rashed Abdel-Tawab | 841c6e8 | 2019-03-29 20:07:25 -0700 | [diff] [blame] | 2504 | |
| 2505 | # Clean-up |
| 2506 | rm -f "$output_list_tmp" |
| 2507 | } |
| Bruno Martins | 0f425f1 | 2021-04-10 14:57:32 +0100 | [diff] [blame] | 2508 | |
| 2509 | function colored_echo() { |
| 2510 | IFS=" " |
| 2511 | local color=$1; |
| 2512 | shift |
| 2513 | if ! [[ $color =~ '^[0-9]$' ]] ; then |
| 2514 | case $(echo $color | tr '[:upper:]' '[:lower:]') in |
| 2515 | black) color=0 ;; |
| 2516 | red) color=1 ;; |
| 2517 | green) color=2 ;; |
| 2518 | yellow) color=3 ;; |
| 2519 | blue) color=4 ;; |
| 2520 | magenta) color=5 ;; |
| 2521 | cyan) color=6 ;; |
| 2522 | white|*) color=7 ;; # white or invalid color |
| 2523 | esac |
| 2524 | fi |
| Bruno Martins | 5064db2 | 2021-06-21 14:47:40 +0100 | [diff] [blame] | 2525 | if [ -t 1 ] ; then tput setaf $color; fi |
| Bruno Martins | 0f425f1 | 2021-04-10 14:57:32 +0100 | [diff] [blame] | 2526 | printf '%s\n' "$*" |
| Bruno Martins | 5064db2 | 2021-06-21 14:47:40 +0100 | [diff] [blame] | 2527 | if [ -t 1 ] ; then tput sgr0; fi |
| Bruno Martins | 0f425f1 | 2021-04-10 14:57:32 +0100 | [diff] [blame] | 2528 | } |