blob: 5003a2a9560b1babdcdea939b4685462004fef89 [file] [log] [blame]
Steve Kondik5bd66602016-07-15 10:39:58 -07001#!/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
18PRODUCT_COPY_FILES_LIST=()
19PRODUCT_COPY_FILES_HASHES=()
Vladimir Olteande985fe2019-01-17 03:07:34 +020020PRODUCT_COPY_FILES_FIXUP_HASHES=()
Steve Kondik5bd66602016-07-15 10:39:58 -070021PRODUCT_PACKAGES_LIST=()
22PRODUCT_PACKAGES_HASHES=()
Vladimir Olteande985fe2019-01-17 03:07:34 +020023PRODUCT_PACKAGES_FIXUP_HASHES=()
SamarV-1215556e2d2024-03-19 08:50:02 +053024PRODUCT_SYMLINKS_LIST=()
Steve Kondik5bd66602016-07-15 10:39:58 -070025PACKAGE_LIST=()
SamarV-1217e6b4082024-02-26 14:39:34 +053026REQUIRED_PACKAGES_LIST=
Steve Kondik5bd66602016-07-15 10:39:58 -070027VENDOR_STATE=-1
28VENDOR_RADIO_STATE=-1
29COMMON=-1
30ARCHES=
31FULLY_DEODEXED=-1
32
Chirayu Desai51ddd8d2022-05-26 14:50:35 +053033SKIP_CLEANUP=${SKIP_CLEANUP:-0}
Chirayu Desai5da0bf82022-10-19 02:58:42 +053034EXTRACT_TMP_DIR=$(mktemp -d)
Volodymyr Zhdanove54a1592020-10-22 01:33:24 +030035HOST="$(uname | tr '[:upper:]' '[:lower:]')"
Steve Kondik5bd66602016-07-15 10:39:58 -070036
37#
38# cleanup
39#
40# kill our tmpfiles with fire on exit
41#
42function cleanup() {
Chirayu Desai51ddd8d2022-05-26 14:50:35 +053043 if [ "$SKIP_CLEANUP" == "true" ] || [ "$SKIP_CLEANUP" == "1" ]; then
Chirayu Desai5da0bf82022-10-19 02:58:42 +053044 echo "Skipping cleanup of $EXTRACT_TMP_DIR"
Chirayu Desai51ddd8d2022-05-26 14:50:35 +053045 else
Chirayu Desai5da0bf82022-10-19 02:58:42 +053046 rm -rf "${EXTRACT_TMP_DIR:?}"
Chirayu Desai51ddd8d2022-05-26 14:50:35 +053047 fi
Steve Kondik5bd66602016-07-15 10:39:58 -070048}
49
Gabriele Mb8e54572017-10-11 12:55:51 +020050trap cleanup 0
Steve Kondik5bd66602016-07-15 10:39:58 -070051
52#
53# setup_vendor
54#
55# $1: device name
56# $2: vendor name
theimpulson9a911af2019-08-14 03:25:12 +000057# $3: OMNI root directory
Steve Kondik5bd66602016-07-15 10:39:58 -070058# $4: is common device - optional, default to false
59# $5: cleanup - optional, default to true
Jake Whatley9843b322017-01-25 21:49:16 -050060# $6: custom vendor makefile name - optional, default to false
Steve Kondik5bd66602016-07-15 10:39:58 -070061#
62# Must be called before any other functions can be used. This
63# sets up the internal state for a new vendor configuration.
64#
65function setup_vendor() {
66 local DEVICE="$1"
67 if [ -z "$DEVICE" ]; then
68 echo "\$DEVICE must be set before including this script!"
69 exit 1
70 fi
71
72 export VENDOR="$2"
73 if [ -z "$VENDOR" ]; then
74 echo "\$VENDOR must be set before including this script!"
75 exit 1
76 fi
77
theimpulson9a911af2019-08-14 03:25:12 +000078 export OMNI_ROOT="$3"
79 if [ ! -d "$OMNI_ROOT" ]; then
80 echo "\$OMNI_ROOT must be set and valid before including this script!"
Steve Kondik5bd66602016-07-15 10:39:58 -070081 exit 1
82 fi
83
84 export OUTDIR=vendor/"$VENDOR"/"$DEVICE"
theimpulson9a911af2019-08-14 03:25:12 +000085 if [ ! -d "$OMNI_ROOT/$OUTDIR" ]; then
86 mkdir -p "$OMNI_ROOT/$OUTDIR"
Steve Kondik5bd66602016-07-15 10:39:58 -070087 fi
88
Jake Whatley9843b322017-01-25 21:49:16 -050089 VNDNAME="$6"
90 if [ -z "$VNDNAME" ]; then
91 VNDNAME="$DEVICE"
92 fi
93
theimpulsonbb72ab82019-08-14 06:03:32 +000094 export PRODUCTMK="$OMNI_ROOT"/"$OUTDIR"/"$VNDNAME"-vendor.mk
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -070095 export ANDROIDBP="$OMNI_ROOT"/"$OUTDIR"/Android.bp
theimpulson9a911af2019-08-14 03:25:12 +000096 export ANDROIDMK="$OMNI_ROOT"/"$OUTDIR"/Android.mk
97 export BOARDMK="$OMNI_ROOT"/"$OUTDIR"/BoardConfigVendor.mk
Steve Kondik5bd66602016-07-15 10:39:58 -070098
99 if [ "$4" == "true" ] || [ "$4" == "1" ]; then
100 COMMON=1
101 else
102 COMMON=0
103 fi
104
Gabriele Mc44696d2017-05-01 18:22:04 +0200105 if [ "$5" == "false" ] || [ "$5" == "0" ]; then
Steve Kondik5bd66602016-07-15 10:39:58 -0700106 VENDOR_STATE=1
107 VENDOR_RADIO_STATE=1
108 else
109 VENDOR_STATE=0
110 VENDOR_RADIO_STATE=0
111 fi
Volodymyr Zhdanove54a1592020-10-22 01:33:24 +0300112
Chirayu Desai501ffd62022-03-17 06:27:33 +0530113 export BINARIES_LOCATION="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/bin
114
115 export SIMG2IMG="$BINARIES_LOCATION"/simg2img
Michael Bestasf2501c32022-02-18 23:45:09 +0200116 export LPUNPACK="$BINARIES_LOCATION"/lpunpack
Michael Bestase04d4be2022-03-23 23:15:23 +0200117 export SIGSCAN="$BINARIES_LOCATION"/SigScan
Chirayu Desai501ffd62022-03-17 06:27:33 +0530118
Woomymyfad4e792023-02-26 16:47:57 +0100119 for version in 0_8 0_9 0_17_2; do
Sebastiano Barezzicaed7592021-01-17 02:26:08 +0100120 export PATCHELF_${version}="$BINARIES_LOCATION"/patchelf-"${version}"
121 done
122
123 if [ -z "$PATCHELF_VERSION" ]; then
124 export PATCHELF_VERSION=0_9
125 fi
126
Volodymyr Zhdanove54a1592020-10-22 01:33:24 +0300127 if [ -z "$PATCHELF" ]; then
Sebastiano Barezzicaed7592021-01-17 02:26:08 +0100128 local patchelf_variable="PATCHELF_${PATCHELF_VERSION}"
129 export PATCHELF=${!patchelf_variable}
Volodymyr Zhdanove54a1592020-10-22 01:33:24 +0300130 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700131}
132
Vladimir Oltean75d8e052018-06-24 20:22:41 +0300133# Helper functions for parsing a spec.
134# notes: an optional "|SHA1" that may appear in the format is stripped
135# early from the spec in the parse_file_list function, and
136# should not be present inside the input parameter passed
137# to these functions.
138
139#
140# input: spec in the form of "src[:dst][;args]"
141# output: "src"
142#
143function src_file() {
144 local SPEC="$1"
145 local SPLIT=(${SPEC//:/ })
146 local ARGS="$(target_args ${SPEC})"
147 # Regardless of there being a ":" delimiter or not in the spec,
148 # the source file is always either the first, or the only entry.
149 local SRC="${SPLIT[0]}"
150 # Remove target_args suffix, if present
151 echo "${SRC%;${ARGS}}"
152}
153
Steve Kondik5bd66602016-07-15 10:39:58 -0700154#
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300155# input: spec in the form of "src[:dst][;args]"
156# output: "dst" if present, "src" otherwise.
Steve Kondik5bd66602016-07-15 10:39:58 -0700157#
158function target_file() {
dianlujitao4918b8a2020-01-02 15:26:44 +0800159 local SPEC="${1%%;*}"
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300160 local SPLIT=(${SPEC//:/ })
161 local ARGS="$(target_args ${SPEC})"
162 local DST=
163 case ${#SPLIT[@]} in
164 1)
165 # The spec doesn't have a : delimiter
166 DST="${SPLIT[0]}"
167 ;;
168 *)
169 # The spec actually has a src:dst format
170 DST="${SPLIT[1]}"
171 ;;
172 esac
173 # Remove target_args suffix, if present
174 echo "${DST%;${ARGS}}"
Steve Kondik5bd66602016-07-15 10:39:58 -0700175}
176
177#
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300178# input: spec in the form of "src[:dst][;args]"
179# output: "args" if present, "" otherwise.
Steve Kondik5bd66602016-07-15 10:39:58 -0700180#
181function target_args() {
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300182 local SPEC="$1"
183 local SPLIT=(${SPEC//;/ })
184 local ARGS=
185 case ${#SPLIT[@]} in
186 1)
187 # No ";" delimiter in the spec.
188 ;;
189 *)
190 # The "args" are whatever comes after the ";" character.
191 # Basically the spec stripped of whatever is to the left of ";".
192 ARGS="${SPEC#${SPLIT[0]};}"
193 ;;
194 esac
195 echo "${ARGS}"
Steve Kondik5bd66602016-07-15 10:39:58 -0700196}
197
198#
199# prefix_match:
200#
Vladimir Oltean011b6b62018-06-12 01:17:35 +0300201# input:
202# - $1: prefix
203# - (global variable) PRODUCT_PACKAGES_LIST: array of [src:]dst[;args] specs.
204# output:
205# - new array consisting of dst[;args] entries where $1 is a prefix of ${dst}.
Steve Kondik5bd66602016-07-15 10:39:58 -0700206#
207function prefix_match() {
208 local PREFIX="$1"
Sebastiano Barezzidf527c72022-03-25 16:59:58 +0100209 local NEW_ARRAY=()
Vladimir Oltean7220f362018-04-02 22:37:09 +0300210 for LINE in "${PRODUCT_PACKAGES_LIST[@]}"; do
211 local FILE=$(target_file "$LINE")
Steve Kondik5bd66602016-07-15 10:39:58 -0700212 if [[ "$FILE" =~ ^"$PREFIX" ]]; then
Vladimir Oltean011b6b62018-06-12 01:17:35 +0300213 local ARGS=$(target_args "$LINE")
SamarV-1215556e2d2024-03-19 08:50:02 +0530214 if [[ -z "${ARGS}" || "${ARGS}" =~ 'SYMLINK' ]]; then
Sebastiano Barezzidf527c72022-03-25 16:59:58 +0100215 NEW_ARRAY+=("${FILE#$PREFIX}")
Vladimir Oltean011b6b62018-06-12 01:17:35 +0300216 else
Sebastiano Barezzidf527c72022-03-25 16:59:58 +0100217 NEW_ARRAY+=("${FILE#$PREFIX};${ARGS}")
Vladimir Oltean011b6b62018-06-12 01:17:35 +0300218 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700219 fi
220 done
Sebastiano Barezzidf527c72022-03-25 16:59:58 +0100221 printf '%s\n' "${NEW_ARRAY[@]}" | LC_ALL=C sort
Steve Kondik5bd66602016-07-15 10:39:58 -0700222}
223
224#
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400225# prefix_match_file:
226#
227# $1: the prefix to match on
228# $2: the file to match the prefix for
229#
230# Internal function which returns true if a filename contains the
231# specified prefix.
232#
233function prefix_match_file() {
234 local PREFIX="$1"
235 local FILE="$2"
236 if [[ "$FILE" =~ ^"$PREFIX" ]]; then
237 return 0
238 else
239 return 1
240 fi
241}
242
243#
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -0700244# suffix_match_file:
245#
246# $1: the suffix to match on
247# $2: the file to match the suffix for
248#
249# Internal function which returns true if a filename contains the
250# specified suffix.
251#
252function suffix_match_file() {
253 local SUFFIX="$1"
254 local FILE="$2"
255 if [[ "$FILE" = *"$SUFFIX" ]]; then
256 return 0
257 else
258 return 1
259 fi
260}
261
262#
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400263# truncate_file
264#
265# $1: the filename to truncate
266# $2: the argument to output the truncated filename to
267#
268# Internal function which truncates a filename by removing the first dir
269# in the path. ex. vendor/lib/libsdmextension.so -> lib/libsdmextension.so
270#
271function truncate_file() {
272 local FILE="$1"
273 RETURN_FILE="$2"
274 local FIND="${FILE%%/*}"
275 local LOCATION="${#FIND}+1"
276 echo ${FILE:$LOCATION}
277}
278
279#
Steve Kondik5bd66602016-07-15 10:39:58 -0700280# write_product_copy_files:
281#
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400282# $1: make treble compatible makefile - optional and deprecated, default to true
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400283#
Steve Kondik5bd66602016-07-15 10:39:58 -0700284# Creates the PRODUCT_COPY_FILES section in the product makefile for all
285# items in the list which do not start with a dash (-).
286#
287function write_product_copy_files() {
288 local COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
289 local TARGET=
290 local FILE=
291 local LINEEND=
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400292 local TREBLE_COMPAT=$1
Steve Kondik5bd66602016-07-15 10:39:58 -0700293
294 if [ "$COUNT" -eq "0" ]; then
295 return 0
296 fi
297
298 printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK"
299 for (( i=1; i<COUNT+1; i++ )); do
300 FILE="${PRODUCT_COPY_FILES_LIST[$i-1]}"
301 LINEEND=" \\"
302 if [ "$i" -eq "$COUNT" ]; then
303 LINEEND=""
304 fi
305
Vladimir Olteanc70bc122018-06-24 20:09:55 +0300306 TARGET=$(target_file "$FILE")
Rashed Abdel-Tawab06688fc2019-10-05 00:09:41 -0400307 if prefix_match_file "product/" $TARGET ; then
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400308 local OUTTARGET=$(truncate_file $TARGET)
Rashed Abdel-Tawab06688fc2019-10-05 00:09:41 -0400309 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400310 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab06688fc2019-10-05 00:09:41 -0400311 elif prefix_match_file "system/product/" $TARGET ; then
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400312 local OUTTARGET=$(truncate_file $TARGET)
313 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s%s\n' \
314 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Luca Stefani776be462020-09-09 15:53:58 +0200315 elif prefix_match_file "system_ext/" $TARGET ; then
316 local OUTTARGET=$(truncate_file $TARGET)
317 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \
318 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
319 elif prefix_match_file "system/system_ext/" $TARGET ; then
320 local OUTTARGET=$(truncate_file $TARGET)
321 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM_EXT)/%s%s\n' \
322 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400323 elif prefix_match_file "odm/" $TARGET ; then
324 local OUTTARGET=$(truncate_file $TARGET)
325 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
326 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab06688fc2019-10-05 00:09:41 -0400327 elif prefix_match_file "vendor/odm/" $TARGET ; then
328 local OUTTARGET=$(truncate_file $TARGET)
329 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
330 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
331 elif prefix_match_file "system/vendor/odm/" $TARGET ; then
332 local OUTTARGET=$(truncate_file $TARGET)
333 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_ODM)/%s%s\n' \
334 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
335 elif prefix_match_file "vendor/" $TARGET ; then
336 local OUTTARGET=$(truncate_file $TARGET)
337 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \
338 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Alexander Koskovich44c8fac2022-01-22 22:27:29 -0700339 elif prefix_match_file "vendor_dlkm/" $TARGET ; then
340 local OUTTARGET=$(truncate_file $TARGET)
341 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR_DLKM)/%s%s\n' \
342 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab06688fc2019-10-05 00:09:41 -0400343 elif prefix_match_file "system/vendor/" $TARGET ; then
344 local OUTTARGET=$(truncate_file $TARGET)
345 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR)/%s%s\n' \
346 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400347 elif prefix_match_file "system/" $TARGET ; then
348 local OUTTARGET=$(truncate_file $TARGET)
349 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \
350 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Mohd Farazd683fe42022-07-23 14:33:59 +0200351 elif prefix_match_file "recovery/" $TARGET ; then
352 local OUTTARGET=$(truncate_file $TARGET)
353 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_RECOVERY)/%s%s\n' \
354 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
355 elif prefix_match_file "vendor_ramdisk/" $TARGET ; then
356 local OUTTARGET=$(truncate_file $TARGET)
357 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_VENDOR_RAMDISK)/%s%s\n' \
358 "$OUTDIR" "$TARGET" "$OUTTARGET" "$LINEEND" >> "$PRODUCTMK"
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400359 else
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400360 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_SYSTEM)/%s%s\n' \
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -0400361 "$OUTDIR" "$TARGET" "$TARGET" "$LINEEND" >> "$PRODUCTMK"
362 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700363 done
364 return 0
365}
366
367#
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700368# write_blueprint_packages:
Steve Kondik5bd66602016-07-15 10:39:58 -0700369#
370# $1: The LOCAL_MODULE_CLASS for the given module list
Luca Stefani776be462020-09-09 15:53:58 +0200371# $2: /system, /odm, /product, /system_ext, or /vendor partition
Steve Kondik5bd66602016-07-15 10:39:58 -0700372# $3: type-specific extra flags
373# $4: Name of the array holding the target list
374#
375# Internal function which writes out the BUILD_PREBUILT stanzas
376# for all modules in the list. This is called by write_product_packages
377# after the modules are categorized.
378#
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700379function write_blueprint_packages() {
380
381 local CLASS="$1"
382 local PARTITION="$2"
383 local EXTRA="$3"
384
385 # Yes, this is a horrible hack - we create a new array using indirection
386 local ARR_NAME="$4[@]"
387 local FILELIST=("${!ARR_NAME}")
388
389 local FILE=
390 local ARGS=
391 local BASENAME=
392 local EXTENSION=
393 local PKGNAME=
394 local SRC=
Tim Zimmermannd9320762021-12-23 07:06:17 +0100395 local STEM=
TheStrix6e24acc2020-04-10 18:20:19 +0530396 local OVERRIDEPKG=
SamarV-1217e6b4082024-02-26 14:39:34 +0530397 local REQUIREDPKG=
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700398
399 for P in "${FILELIST[@]}"; do
400 FILE=$(target_file "$P")
401 ARGS=$(target_args "$P")
Tim Zimmermannd9320762021-12-23 07:06:17 +0100402 ARGS=(${ARGS//;/ })
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700403
404 BASENAME=$(basename "$FILE")
405 DIRNAME=$(dirname "$FILE")
406 EXTENSION=${BASENAME##*.}
407 PKGNAME=${BASENAME%.*}
408
Tim Zimmermanne93bb1b2021-12-23 10:15:26 +0100409 if [ "$CLASS" = "EXECUTABLES" ] && [ "$EXTENSION" != "sh" ]; then
410 PKGNAME="$BASENAME"
411 EXTENSION=""
412 fi
413
Tim Zimmermannd9320762021-12-23 07:06:17 +0100414 # Allow overriding module name
415 STEM=
416 for ARG in "${ARGS[@]}"; do
417 if [[ "$ARG" =~ "MODULE" ]]; then
418 STEM="$PKGNAME"
419 PKGNAME=${ARG#*=}
420 fi
421 done
422
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700423 # Add to final package list
424 PACKAGE_LIST+=("$PKGNAME")
425
426 SRC="proprietary"
427 if [ "$PARTITION" = "system" ]; then
428 SRC+="/system"
429 elif [ "$PARTITION" = "vendor" ]; then
430 SRC+="/vendor"
431 elif [ "$PARTITION" = "product" ]; then
432 SRC+="/product"
Luca Stefani776be462020-09-09 15:53:58 +0200433 elif [ "$PARTITION" = "system_ext" ]; then
434 SRC+="/system_ext"
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700435 elif [ "$PARTITION" = "odm" ]; then
436 SRC+="/odm"
437 fi
438
439 if [ "$CLASS" = "SHARED_LIBRARIES" ]; then
440 printf 'cc_prebuilt_library_shared {\n'
441 printf '\tname: "%s",\n' "$PKGNAME"
Tim Zimmermannd9320762021-12-23 07:06:17 +0100442 if [ ! -z "$STEM" ]; then
443 printf '\tstem: "%s",\n' "$STEM"
444 fi
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700445 printf '\towner: "%s",\n' "$VENDOR"
446 printf '\tstrip: {\n'
447 printf '\t\tnone: true,\n'
448 printf '\t},\n'
449 printf '\ttarget: {\n'
450 if [ "$EXTRA" = "both" ]; then
451 printf '\t\tandroid_arm: {\n'
452 printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE"
453 printf '\t\t},\n'
454 printf '\t\tandroid_arm64: {\n'
455 printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE"
456 printf '\t\t},\n'
457 elif [ "$EXTRA" = "64" ]; then
458 printf '\t\tandroid_arm64: {\n'
459 printf '\t\t\tsrcs: ["%s/lib64/%s"],\n' "$SRC" "$FILE"
460 printf '\t\t},\n'
461 else
462 printf '\t\tandroid_arm: {\n'
463 printf '\t\t\tsrcs: ["%s/lib/%s"],\n' "$SRC" "$FILE"
464 printf '\t\t},\n'
465 fi
466 printf '\t},\n'
467 if [ "$EXTRA" != "none" ]; then
468 printf '\tcompile_multilib: "%s",\n' "$EXTRA"
469 fi
dianlujitao848101c2020-09-12 00:15:13 +0800470 printf '\tcheck_elf_files: false,\n'
Chirayu Desaia7741012021-12-04 07:17:28 +0530471 elif [ "$CLASS" = "APEX" ]; then
472 printf 'prebuilt_apex {\n'
473 printf '\tname: "%s",\n' "$PKGNAME"
474 printf '\towner: "%s",\n' "$VENDOR"
475 SRC="$SRC/apex"
476 printf '\tsrc: "%s/%s",\n' "$SRC" "$FILE"
477 printf '\tfilename: "%s",\n' "$FILE"
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700478 elif [ "$CLASS" = "APPS" ]; then
479 printf 'android_app_import {\n'
480 printf '\tname: "%s",\n' "$PKGNAME"
481 printf '\towner: "%s",\n' "$VENDOR"
482 if [ "$EXTRA" = "priv-app" ]; then
483 SRC="$SRC/priv-app"
484 else
485 SRC="$SRC/app"
486 fi
487 printf '\tapk: "%s/%s",\n' "$SRC" "$FILE"
LuK1337508e85f2021-08-23 18:18:57 +0200488 USE_PLATFORM_CERTIFICATE="true"
489 for ARG in "${ARGS[@]}"; do
490 if [ "$ARG" = "PRESIGNED" ]; then
491 USE_PLATFORM_CERTIFICATE="false"
Michael Bestasab47e912024-03-06 13:32:05 +0200492 printf '\tpreprocessed: true,\n'
LuK1337508e85f2021-08-23 18:18:57 +0200493 printf '\tpresigned: true,\n'
494 elif [[ "$ARG" =~ "OVERRIDES" ]]; then
495 OVERRIDEPKG=${ARG#*=}
Arian72ac8362021-09-27 17:49:19 +0200496 OVERRIDEPKG=${OVERRIDEPKG//,/\", \"}
LuK1337508e85f2021-08-23 18:18:57 +0200497 printf '\toverrides: ["%s"],\n' "$OVERRIDEPKG"
SamarV-1217e6b4082024-02-26 14:39:34 +0530498 elif [[ "$ARG" =~ "REQUIRED" ]]; then
499 REQUIREDPKG=${ARG#*=}
500 REQUIRED_PACKAGES_LIST+="$REQUIREDPKG,"
501 printf '\trequired: ["%s"],\n' "${REQUIREDPKG//,/\", \"}"
SamarV-1215556e2d2024-03-19 08:50:02 +0530502 elif [[ "$ARG" =~ "SYMLINK" ]]; then
503 continue
LuK1337508e85f2021-08-23 18:18:57 +0200504 elif [ ! -z "$ARG" ]; then
505 USE_PLATFORM_CERTIFICATE="false"
506 printf '\tcertificate: "%s",\n' "$ARG"
507 fi
508 done
509 if [ "$USE_PLATFORM_CERTIFICATE" = "true" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700510 printf '\tcertificate: "platform",\n'
511 fi
512 elif [ "$CLASS" = "JAVA_LIBRARIES" ]; then
513 printf 'dex_import {\n'
514 printf '\tname: "%s",\n' "$PKGNAME"
515 printf '\towner: "%s",\n' "$VENDOR"
516 printf '\tjars: ["%s/framework/%s"],\n' "$SRC" "$FILE"
517 elif [ "$CLASS" = "ETC" ]; then
518 if [ "$EXTENSION" = "xml" ]; then
519 printf 'prebuilt_etc_xml {\n'
520 else
521 printf 'prebuilt_etc {\n'
522 fi
523 printf '\tname: "%s",\n' "$PKGNAME"
524 printf '\towner: "%s",\n' "$VENDOR"
525 printf '\tsrc: "%s/etc/%s",\n' "$SRC" "$FILE"
LuK1337f7f18712020-10-06 19:29:02 +0200526 printf '\tfilename_from_src: true,\n'
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700527 elif [ "$CLASS" = "EXECUTABLES" ]; then
528 if [ "$EXTENSION" = "sh" ]; then
529 printf 'sh_binary {\n'
530 else
531 printf 'cc_prebuilt_binary {\n'
532 fi
533 printf '\tname: "%s",\n' "$PKGNAME"
534 printf '\towner: "%s",\n' "$VENDOR"
Sebastiano Barezzifd4b2b32021-07-14 21:33:10 +0200535 if [ "$EXTENSION" != "sh" ]; then
Mohd Faraz2509b6e2022-10-02 09:48:52 +0200536 printf '\tsrcs: ["%s/bin/%s"],\n' "$SRC" "$FILE"
Sebastiano Barezzifd4b2b32021-07-14 21:33:10 +0200537 printf '\tcheck_elf_files: false,\n'
Tim Zimmermann54606d62021-12-23 09:26:54 +0100538 printf '\tstrip: {\n'
539 printf '\t\tnone: true,\n'
540 printf '\t},\n'
Mohd Faraz2509b6e2022-10-02 09:48:52 +0200541 printf '\tprefer: true,\n'
542 else
543 printf '\tsrc: "%s/bin/%s",\n' "$SRC" "$FILE"
Sebastiano Barezzifd4b2b32021-07-14 21:33:10 +0200544 fi
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700545 unset EXTENSION
546 else
547 printf '\tsrcs: ["%s/%s"],\n' "$SRC" "$FILE"
548 fi
549 if [ "$CLASS" = "APPS" ]; then
550 printf '\tdex_preopt: {\n'
551 printf '\t\tenabled: false,\n'
552 printf '\t},\n'
Jyotiraditya Panda45f50af2024-02-19 05:35:33 +0900553 if [ "$DIRNAME" != "." ] && [[ "$DIRNAME" == */* ]]; then
554 printf '\trelative_install_path: "%s",\n' "$DIRNAME"
555 fi
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700556 fi
Andreas Schneiderdbcf9db2020-05-25 17:03:17 +0200557 if [ "$CLASS" = "SHARED_LIBRARIES" ] || [ "$CLASS" = "EXECUTABLES" ] ; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700558 if [ "$DIRNAME" != "." ]; then
Andreas Schneider408526a2020-05-23 15:58:43 +0200559 printf '\trelative_install_path: "%s",\n' "$DIRNAME"
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700560 fi
561 fi
Andreas Schneiderdbcf9db2020-05-25 17:03:17 +0200562 if [ "$CLASS" = "ETC" ] ; then
563 if [ "$DIRNAME" != "." ]; then
564 printf '\tsub_dir: "%s",\n' "$DIRNAME"
565 fi
566 fi
Mohd Faraz2509b6e2022-10-02 09:48:52 +0200567 if [ "$CLASS" = "SHARED_LIBRARIES" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700568 printf '\tprefer: true,\n'
569 fi
570 if [ "$EXTRA" = "priv-app" ]; then
571 printf '\tprivileged: true,\n'
572 fi
573 if [ "$PARTITION" = "vendor" ]; then
574 printf '\tsoc_specific: true,\n'
575 elif [ "$PARTITION" = "product" ]; then
576 printf '\tproduct_specific: true,\n'
Luca Stefani776be462020-09-09 15:53:58 +0200577 elif [ "$PARTITION" = "system_ext" ]; then
578 printf '\tsystem_ext_specific: true,\n'
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700579 elif [ "$PARTITION" = "odm" ]; then
580 printf '\tdevice_specific: true,\n'
581 fi
582 printf '}\n\n'
583 done
584}
585
586#
Steve Kondik5bd66602016-07-15 10:39:58 -0700587# write_product_packages:
588#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -0700589# This function will create prebuilt entries in the
590# Android.bp and associated PRODUCT_PACKAGES list in the
Steve Kondik5bd66602016-07-15 10:39:58 -0700591# product makefile for all files in the blob list which
592# start with a single dash (-) character.
593#
594function write_product_packages() {
595 PACKAGE_LIST=()
596
Chenyang Zhongc487f382022-02-10 21:40:41 -0500597 # Sort the package list for comm
598 PRODUCT_PACKAGES_LIST=($( printf '%s\n' "${PRODUCT_PACKAGES_LIST[@]}" | LC_ALL=C sort))
599
Steve Kondik5bd66602016-07-15 10:39:58 -0700600 local COUNT=${#PRODUCT_PACKAGES_LIST[@]}
601
602 if [ "$COUNT" = "0" ]; then
603 return 0
604 fi
605
606 # Figure out what's 32-bit, what's 64-bit, and what's multilib
607 # I really should not be doing this in bash due to shitty array passing :(
608 local T_LIB32=( $(prefix_match "lib/") )
609 local T_LIB64=( $(prefix_match "lib64/") )
Pablo Cholaky32d80cf2022-01-16 13:52:07 -0500610 local MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${T_LIB64[@]}")) )
611 local LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_LIB32[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
612 local LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_LIB64[@]}") <(printf '%s\n' "${MULTILIBS[@]}")) )
Steve Kondik5bd66602016-07-15 10:39:58 -0700613
614 if [ "${#MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700615 write_blueprint_packages "SHARED_LIBRARIES" "" "both" "MULTILIBS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700616 fi
617 if [ "${#LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700618 write_blueprint_packages "SHARED_LIBRARIES" "" "32" "LIB32" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700619 fi
620 if [ "${#LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700621 write_blueprint_packages "SHARED_LIBRARIES" "" "64" "LIB64" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700622 fi
623
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400624 local T_S_LIB32=( $(prefix_match "system/lib/") )
625 local T_S_LIB64=( $(prefix_match "system/lib64/") )
Pablo Cholaky32d80cf2022-01-16 13:52:07 -0500626 local S_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${T_S_LIB64[@]}")) )
627 local S_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_S_LIB32[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
628 local S_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_S_LIB64[@]}") <(printf '%s\n' "${S_MULTILIBS[@]}")) )
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400629
630 if [ "${#S_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700631 write_blueprint_packages "SHARED_LIBRARIES" "system" "both" "S_MULTILIBS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400632 fi
633 if [ "${#S_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700634 write_blueprint_packages "SHARED_LIBRARIES" "system" "32" "S_LIB32" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400635 fi
636 if [ "${#S_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700637 write_blueprint_packages "SHARED_LIBRARIES" "system" "64" "S_LIB64" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400638 fi
639
Steve Kondik5bd66602016-07-15 10:39:58 -0700640 local T_V_LIB32=( $(prefix_match "vendor/lib/") )
641 local T_V_LIB64=( $(prefix_match "vendor/lib64/") )
Pablo Cholaky32d80cf2022-01-16 13:52:07 -0500642 local V_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${T_V_LIB64[@]}")) )
643 local V_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_V_LIB32[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
644 local V_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_V_LIB64[@]}") <(printf '%s\n' "${V_MULTILIBS[@]}")) )
Steve Kondik5bd66602016-07-15 10:39:58 -0700645
646 if [ "${#V_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700647 write_blueprint_packages "SHARED_LIBRARIES" "vendor" "both" "V_MULTILIBS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700648 fi
649 if [ "${#V_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700650 write_blueprint_packages "SHARED_LIBRARIES" "vendor" "32" "V_LIB32" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700651 fi
652 if [ "${#V_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700653 write_blueprint_packages "SHARED_LIBRARIES" "vendor" "64" "V_LIB64" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500654 fi
655
656 local T_P_LIB32=( $(prefix_match "product/lib/") )
657 local T_P_LIB64=( $(prefix_match "product/lib64/") )
Pablo Cholaky32d80cf2022-01-16 13:52:07 -0500658 local P_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${T_P_LIB64[@]}")) )
659 local P_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_P_LIB32[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
660 local P_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_P_LIB64[@]}") <(printf '%s\n' "${P_MULTILIBS[@]}")) )
razorlovesa0d296b2019-07-29 02:21:34 -0500661
662 if [ "${#P_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700663 write_blueprint_packages "SHARED_LIBRARIES" "product" "both" "P_MULTILIBS" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500664 fi
665 if [ "${#P_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700666 write_blueprint_packages "SHARED_LIBRARIES" "product" "32" "P_LIB32" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500667 fi
668 if [ "${#P_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700669 write_blueprint_packages "SHARED_LIBRARIES" "product" "64" "P_LIB64" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700670 fi
671
Luca Stefani776be462020-09-09 15:53:58 +0200672 local T_SE_LIB32=( $(prefix_match "system_ext/lib/") )
673 local T_SE_LIB64=( $(prefix_match "system_ext/lib64/") )
Pablo Cholaky32d80cf2022-01-16 13:52:07 -0500674 local SE_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${T_SE_LIB64[@]}")) )
675 local SE_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_SE_LIB32[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) )
676 local SE_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_SE_LIB64[@]}") <(printf '%s\n' "${SE_MULTILIBS[@]}")) )
Luca Stefani776be462020-09-09 15:53:58 +0200677
678 if [ "${#SE_MULTILIBS[@]}" -gt "0" ]; then
679 write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "both" "SE_MULTILIBS" >> "$ANDROIDBP"
680 fi
681 if [ "${#SE_LIB32[@]}" -gt "0" ]; then
682 write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "32" "SE_LIB32" >> "$ANDROIDBP"
683 fi
684 if [ "${#SE_LIB64[@]}" -gt "0" ]; then
685 write_blueprint_packages "SHARED_LIBRARIES" "system_ext" "64" "SE_LIB64" >> "$ANDROIDBP"
686 fi
687
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700688 local T_O_LIB32=( $(prefix_match "odm/lib/") )
689 local T_O_LIB64=( $(prefix_match "odm/lib64/") )
Pablo Cholaky32d80cf2022-01-16 13:52:07 -0500690 local O_MULTILIBS=( $(LC_ALL=C comm -12 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${T_O_LIB64[@]}")) )
691 local O_LIB32=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_O_LIB32[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
692 local O_LIB64=( $(LC_ALL=C comm -23 <(printf '%s\n' "${T_O_LIB64[@]}") <(printf '%s\n' "${O_MULTILIBS[@]}")) )
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700693
694 if [ "${#O_MULTILIBS[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700695 write_blueprint_packages "SHARED_LIBRARIES" "odm" "both" "O_MULTILIBS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700696 fi
697 if [ "${#O_LIB32[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700698 write_blueprint_packages "SHARED_LIBRARIES" "odm" "32" "O_LIB32" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700699 fi
700 if [ "${#O_LIB64[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700701 write_blueprint_packages "SHARED_LIBRARIES" "odm" "64" "O_LIB64" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700702 fi
703
Chirayu Desaia7741012021-12-04 07:17:28 +0530704 # APEX
705 local APEX=( $(prefix_match "apex/") )
706 if [ "${#APEX[@]}" -gt "0" ]; then
707 write_blueprint_packages "APEX" "" "" "APEX" >> "$ANDROIDBP"
708 fi
709 local S_APEX=( $(prefix_match "system/apex/") )
710 if [ "${#S_APEX[@]}" -gt "0" ]; then
711 write_blueprint_packages "APEX" "system" "" "S_APEX" >> "$ANDROIDBP"
712 fi
713 local V_APEX=( $(prefix_match "vendor/apex/") )
714 if [ "${#V_APEX[@]}" -gt "0" ]; then
715 write_blueprint_packages "APEX" "vendor" "" "V_APEX" >> "$ANDROIDBP"
716 fi
717 local SE_APEX=( $(prefix_match "system_ext/apex/") )
718 if [ "${#SE_APEX[@]}" -gt "0" ]; then
719 write_blueprint_packages "APEX" "system_ext" "" "SE_APEX" >> "$ANDROIDBP"
720 fi
721
Steve Kondik5bd66602016-07-15 10:39:58 -0700722 # Apps
723 local APPS=( $(prefix_match "app/") )
724 if [ "${#APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100725 write_blueprint_packages "APPS" "" "" "APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700726 fi
727 local PRIV_APPS=( $(prefix_match "priv-app/") )
728 if [ "${#PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100729 write_blueprint_packages "APPS" "" "priv-app" "PRIV_APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700730 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400731 local S_APPS=( $(prefix_match "system/app/") )
732 if [ "${#S_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100733 write_blueprint_packages "APPS" "system" "" "S_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400734 fi
735 local S_PRIV_APPS=( $(prefix_match "system/priv-app/") )
736 if [ "${#S_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100737 write_blueprint_packages "APPS" "system" "priv-app" "S_PRIV_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400738 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700739 local V_APPS=( $(prefix_match "vendor/app/") )
740 if [ "${#V_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100741 write_blueprint_packages "APPS" "vendor" "" "V_APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700742 fi
743 local V_PRIV_APPS=( $(prefix_match "vendor/priv-app/") )
744 if [ "${#V_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100745 write_blueprint_packages "APPS" "vendor" "priv-app" "V_PRIV_APPS" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500746 fi
747 local P_APPS=( $(prefix_match "product/app/") )
748 if [ "${#P_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100749 write_blueprint_packages "APPS" "product" "" "P_APPS" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500750 fi
751 local P_PRIV_APPS=( $(prefix_match "product/priv-app/") )
752 if [ "${#P_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100753 write_blueprint_packages "APPS" "product" "priv-app" "P_PRIV_APPS" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700754 fi
Luca Stefani776be462020-09-09 15:53:58 +0200755 local SE_APPS=( $(prefix_match "system_ext/app/") )
756 if [ "${#SE_APPS[@]}" -gt "0" ]; then
757 write_blueprint_packages "APPS" "system_ext" "" "SE_APPS" >> "$ANDROIDBP"
758 fi
759 local SE_PRIV_APPS=( $(prefix_match "system_ext/priv-app/") )
760 if [ "${#SE_PRIV_APPS[@]}" -gt "0" ]; then
761 write_blueprint_packages "APPS" "system_ext" "priv-app" "SE_PRIV_APPS" >> "$ANDROIDBP"
762 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700763 local O_APPS=( $(prefix_match "odm/app/") )
764 if [ "${#O_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100765 write_blueprint_packages "APPS" "odm" "" "O_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700766 fi
767 local O_PRIV_APPS=( $(prefix_match "odm/priv-app/") )
768 if [ "${#O_PRIV_APPS[@]}" -gt "0" ]; then
mickael saibi64b0b752019-11-17 18:35:05 +0100769 write_blueprint_packages "APPS" "odm" "priv-app" "O_PRIV_APPS" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700770 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700771
772 # Framework
773 local FRAMEWORK=( $(prefix_match "framework/") )
774 if [ "${#FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700775 write_blueprint_packages "JAVA_LIBRARIES" "" "" "FRAMEWORK" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700776 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400777 local S_FRAMEWORK=( $(prefix_match "system/framework/") )
778 if [ "${#S_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700779 write_blueprint_packages "JAVA_LIBRARIES" "system" "" "S_FRAMEWORK" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400780 fi
Christian Oder974b5902017-10-08 23:15:52 +0200781 local V_FRAMEWORK=( $(prefix_match "vendor/framework/") )
Michael Bestas26eb01e2018-02-27 22:31:55 +0200782 if [ "${#V_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700783 write_blueprint_packages "JAVA_LIBRARIES" "vendor" "" "V_FRAMEWORK" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500784 fi
785 local P_FRAMEWORK=( $(prefix_match "product/framework/") )
786 if [ "${#P_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700787 write_blueprint_packages "JAVA_LIBRARIES" "product" "" "P_FRAMEWORK" >> "$ANDROIDBP"
Christian Oder974b5902017-10-08 23:15:52 +0200788 fi
Luca Stefani776be462020-09-09 15:53:58 +0200789 local SE_FRAMEWORK=( $(prefix_match "system_ext/framework/") )
Alexander Koskovich052c77d2020-09-16 17:58:53 -0700790 if [ "${#SE_FRAMEWORK[@]}" -gt "0" ]; then
Luca Stefani776be462020-09-09 15:53:58 +0200791 write_blueprint_packages "JAVA_LIBRARIES" "system_ext" "" "SE_FRAMEWORK" >> "$ANDROIDBP"
792 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700793 local O_FRAMEWORK=( $(prefix_match "odm/framework/") )
794 if [ "${#O_FRAMEWORK[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700795 write_blueprint_packages "JAVA_LIBRARIES" "odm" "" "O_FRAMEWORK" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700796 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700797
798 # Etc
799 local ETC=( $(prefix_match "etc/") )
800 if [ "${#ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700801 write_blueprint_packages "ETC" "" "" "ETC" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700802 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400803 local S_ETC=( $(prefix_match "system/etc/") )
Luca Weiss737940e2022-09-27 14:52:41 +0200804 if [ "${#S_ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700805 write_blueprint_packages "ETC" "system" "" "S_ETC" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400806 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700807 local V_ETC=( $(prefix_match "vendor/etc/") )
808 if [ "${#V_ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700809 write_blueprint_packages "ETC" "vendor" "" "V_ETC" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500810 fi
811 local P_ETC=( $(prefix_match "product/etc/") )
812 if [ "${#P_ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700813 write_blueprint_packages "ETC" "product" "" "P_ETC" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700814 fi
Luca Stefani776be462020-09-09 15:53:58 +0200815 local SE_ETC=( $(prefix_match "system_ext/etc/") )
816 if [ "${#SE_ETC[@]}" -gt "0" ]; then
817 write_blueprint_packages "ETC" "system_ext" "" "SE_ETC" >> "$ANDROIDBP"
818 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700819 local O_ETC=( $(prefix_match "odm/etc/") )
820 if [ "${#O_ETC[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700821 write_blueprint_packages "ETC" "odm" "" "O_ETC" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700822 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700823
824 # Executables
825 local BIN=( $(prefix_match "bin/") )
826 if [ "${#BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700827 write_blueprint_packages "EXECUTABLES" "" "" "BIN" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700828 fi
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400829 local S_BIN=( $(prefix_match "system/bin/") )
Luca Weiss737940e2022-09-27 14:52:41 +0200830 if [ "${#S_BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700831 write_blueprint_packages "EXECUTABLES" "system" "" "S_BIN" >> "$ANDROIDBP"
Rashed Abdel-Tawaba6373e52019-09-28 23:37:36 -0400832 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700833 local V_BIN=( $(prefix_match "vendor/bin/") )
834 if [ "${#V_BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700835 write_blueprint_packages "EXECUTABLES" "vendor" "" "V_BIN" >> "$ANDROIDBP"
razorlovesa0d296b2019-07-29 02:21:34 -0500836 fi
837 local P_BIN=( $(prefix_match "product/bin/") )
838 if [ "${#P_BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700839 write_blueprint_packages "EXECUTABLES" "product" "" "P_BIN" >> "$ANDROIDBP"
Steve Kondik5bd66602016-07-15 10:39:58 -0700840 fi
Luca Stefani776be462020-09-09 15:53:58 +0200841 local SE_BIN=( $(prefix_match "system_ext/bin/") )
842 if [ "${#SE_BIN[@]}" -gt "0" ]; then
843 write_blueprint_packages "EXECUTABLES" "system_ext" "" "SE_BIN" >> "$ANDROIDBP"
844 fi
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700845 local O_BIN=( $(prefix_match "odm/bin/") )
846 if [ "${#O_BIN[@]}" -gt "0" ]; then
Rashed Abdel-Tawabb91adc02019-09-20 10:30:38 -0700847 write_blueprint_packages "EXECUTABLES" "odm" "" "O_BIN" >> "$ANDROIDBP"
Rashed Abdel-Tawaba94af582019-09-20 07:32:39 -0700848 fi
Steve Kondik5bd66602016-07-15 10:39:58 -0700849
SamarV-1215556e2d2024-03-19 08:50:02 +0530850 write_package_definition "${PACKAGE_LIST[@]}" >> "$PRODUCTMK"
851}
Steve Kondik5bd66602016-07-15 10:39:58 -0700852
SamarV-1215556e2d2024-03-19 08:50:02 +0530853
854#
855# write_symlink_packages:
856#
857# Creates symlink entries in the Android.bp and related PRODUCT_PACKAGES
858# list in the product makefile for all files in the blob list which has
859# SYMLINK argument.
860#
861function write_symlink_packages() {
862 local FILE=
863 local ARGS=
864 local ARCH=
865 local BASENAME=
866 local PKGNAME=
867 local PREFIX=
868 local SYMLINK_BASENAME=
869 local SYMLINK_PACKAGES=()
870
871 # Sort the symlinks list for comm
872 PRODUCT_SYMLINKS_LIST=($( printf '%s\n' "${PRODUCT_SYMLINKS_LIST[@]}" | LC_ALL=C sort))
873
874 local COUNT=${#PRODUCT_SYMLINKS_LIST[@]}
875
876 if [ "$COUNT" = "0" ]; then
Steve Kondik5bd66602016-07-15 10:39:58 -0700877 return 0
878 fi
879
SamarV-1215556e2d2024-03-19 08:50:02 +0530880 for LINE in "${PRODUCT_SYMLINKS_LIST[@]}"; do
Bruno Martinsbe7f3cb2024-06-23 15:54:02 +0100881 FILE=$(target_file "$LINE")
Bruno Martinsf96fd122024-03-28 14:31:02 +0000882 if [[ "$LINE" =~ '/lib64/' || "$LINE" =~ '/lib/arm64/' ]]; then
SamarV-1215556e2d2024-03-19 08:50:02 +0530883 ARCH="64"
Bruno Martinsf96fd122024-03-28 14:31:02 +0000884 elif [[ "$LINE" =~ '/lib/' ]]; then
885 ARCH="32"
Steve Kondik5bd66602016-07-15 10:39:58 -0700886 fi
SamarV-1215556e2d2024-03-19 08:50:02 +0530887 BASENAME=$(basename "$FILE")
888 ARGS=$(target_args "$LINE")
889 ARGS=(${ARGS//;/ })
890 for ARG in "${ARGS[@]}"; do
891 if [[ "$ARG" =~ "SYMLINK" ]]; then
892 SYMLINKS=${ARG#*=}
893 SYMLINKS=(${SYMLINKS//,/ })
894 for SYMLINK in "${SYMLINKS[@]}"; do
895 SYMLINK_BASENAME=$(basename "$SYMLINK")
Bruno Martinsad05f512024-06-28 00:34:33 +0100896 PKGNAME="${BASENAME%.*}_${SYMLINK_BASENAME%.*}_symlink${ARCH}"
897 if [[ "${SYMLINK_PACKAGES[@]}" =~ "$PKGNAME" ]]; then
898 PKGNAME+="_$(grep -o "$PKGNAME" <<< ${SYMLINK_PACKAGES[*]} | wc -l)"
899 fi
SamarV-1215556e2d2024-03-19 08:50:02 +0530900 {
901 printf 'install_symlink {\n'
902 printf '\tname: "%s",\n' "$PKGNAME"
Mashopy06100c92024-04-23 21:52:04 +0200903 if prefix_match_file "vendor/" "$SYMLINK"; then
SamarV-1215556e2d2024-03-19 08:50:02 +0530904 PREFIX='vendor/'
905 printf '\tsoc_specific: true,\n'
Mashopy06100c92024-04-23 21:52:04 +0200906 elif prefix_match_file "product/" "$SYMLINK"; then
SamarV-1215556e2d2024-03-19 08:50:02 +0530907 PREFIX='product/'
908 printf '\tproduct_specific: true,\n'
Mashopy06100c92024-04-23 21:52:04 +0200909 elif prefix_match_file "system_ext/" "$SYMLINK"; then
SamarV-1215556e2d2024-03-19 08:50:02 +0530910 PREFIX='system_ext/'
911 printf '\tsystem_ext_specific: true,\n'
Mashopy06100c92024-04-23 21:52:04 +0200912 elif prefix_match_file "odm/" "$SYMLINK"; then
SamarV-1215556e2d2024-03-19 08:50:02 +0530913 PREFIX='odm/'
914 printf '\tdevice_specific: true,\n'
915 fi
916 printf '\tinstalled_location: "%s",\n' "${SYMLINK#"$PREFIX"}"
917 printf '\tsymlink_target: "/%s",\n' "$FILE"
918 printf '}\n\n'
919 } >> "$ANDROIDBP"
920 SYMLINK_PACKAGES+=("$PKGNAME")
921 done
922 fi
923 done
Steve Kondik5bd66602016-07-15 10:39:58 -0700924 done
SamarV-1215556e2d2024-03-19 08:50:02 +0530925
926 write_package_definition "${SYMLINK_PACKAGES[@]}" >> "$PRODUCTMK"
Steve Kondik5bd66602016-07-15 10:39:58 -0700927}
928
929#
Michael Bestasfe71eb32023-06-11 18:59:10 +0300930# write_single_product_copy_files:
931#
932# $1: the file to be copied
933#
934# Creates a PRODUCT_COPY_FILES section in the product makefile for the
935# item provided in $1.
936#
937function write_single_product_copy_files() {
938 local FILE="$1"
939 if [ -z "$FILE" ]; then
940 echo "A file must be provided to write_single_product_copy_files()!"
941 exit 1
942 fi
943
944 local TARGET=$(target_file "$FILE")
945 local OUTTARGET=$(truncate_file $TARGET)
946
947 printf '%s\n' "PRODUCT_COPY_FILES += \\" >> "$PRODUCTMK"
948 printf ' %s/proprietary/%s:$(TARGET_COPY_OUT_PRODUCT)/%s\n' \
949 "$OUTDIR" "$TARGET" "$OUTTARGET" >> "$PRODUCTMK"
950}
951
952#
953# write_single_product_packages:
954#
955# $1: the package to be built
956#
957# Creates a PRODUCT_PACKAGES section in the product makefile for the
958# item provided in $1.
959#
960function write_single_product_packages() {
961 local PACKAGE="$1"
962 if [ -z "$PACKAGE" ]; then
963 echo "A package must be provided to write_single_product_packages()!"
964 exit 1
965 fi
966
967 printf '\n%s\n' "PRODUCT_PACKAGES += \\" >> "$PRODUCTMK"
968 printf ' %s%s\n' "$PACKAGE" >> "$PRODUCTMK"
969}
970
971#
Michael Bestas431a8002023-06-11 20:04:45 +0300972# write_rro_androidmanifest:
973#
974# $2: target package for the RRO overlay
975#
976# Creates an AndroidManifest.xml for an RRO overlay.
977#
978function write_rro_androidmanifest() {
979 local TARGET_PACKAGE="$1"
980
981 cat << EOF
982<manifest xmlns:android="http://schemas.android.com/apk/res/android"
983 package="$TARGET_PACKAGE.vendor"
984 android:versionCode="1"
985 android:versionName="1.0">
986 <application android:hasCode="false" />
987 <overlay
988 android:targetPackage="$TARGET_PACKAGE"
989 android:isStatic="true"
990 android:priority="0"/>
991</manifest>
992EOF
993}
994
995#
996# write_rro_blueprint:
997#
998# $1: package name for the RRO overlay
999# $2: target partition for the RRO overlay
1000#
1001# Creates an Android.bp for an RRO overlay.
1002#
1003function write_rro_blueprint() {
1004 local PKGNAME="$1"
1005 local PARTITION="$2"
1006
1007 printf 'runtime_resource_overlay {\n'
1008 printf '\tname: "%s",\n' "$PKGNAME"
1009 printf '\ttheme: "%s",\n' "$PKGNAME"
1010 printf '\tsdk_version: "%s",\n' "current"
1011 printf '\taaptflags: ["%s"],\n' "--keep-raw-values"
1012
1013 if [ "$PARTITION" = "vendor" ]; then
1014 printf '\tsoc_specific: true,\n'
1015 elif [ "$PARTITION" = "product" ]; then
1016 printf '\tproduct_specific: true,\n'
1017 elif [ "$PARTITION" = "system_ext" ]; then
1018 printf '\tsystem_ext_specific: true,\n'
1019 elif [ "$PARTITION" = "odm" ]; then
1020 printf '\tdevice_specific: true,\n'
1021 fi
1022 printf '}\n'
1023}
1024
1025#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001026# write_blueprint_header:
Steve Kondik5bd66602016-07-15 10:39:58 -07001027#
1028# $1: file which will be written to
1029#
Michael Bestasa2934df2020-12-19 03:50:32 +02001030# writes out the warning message regarding manual file modifications.
Steve Kondik5bd66602016-07-15 10:39:58 -07001031# note that this is not an append operation, and should
1032# be executed first!
1033#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001034function write_blueprint_header() {
1035 if [ -f $1 ]; then
1036 rm $1
1037 fi
1038
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001039 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
1040
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001041 cat << EOF >> $1
Michael Bestasa2934df2020-12-19 03:50:32 +02001042// Automatically generated file. DO NOT MODIFY
1043//
1044// This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001045
1046EOF
1047}
1048
1049#
1050# write_makefile_header:
1051#
1052# $1: file which will be written to
1053#
Michael Bestasa2934df2020-12-19 03:50:32 +02001054# writes out the warning message regarding manual file modifications.
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001055# note that this is not an append operation, and should
1056# be executed first!
1057#
1058function write_makefile_header() {
Jake Whatley9843b322017-01-25 21:49:16 -05001059 if [ -f $1 ]; then
1060 rm $1
1061 fi
1062
Steve Kondik5bd66602016-07-15 10:39:58 -07001063 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
1064
Jake Whatley9843b322017-01-25 21:49:16 -05001065 cat << EOF >> $1
Michael Bestasa2934df2020-12-19 03:50:32 +02001066# Automatically generated file. DO NOT MODIFY
Steve Kondik5bd66602016-07-15 10:39:58 -07001067#
Steve Kondik5bd66602016-07-15 10:39:58 -07001068# This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
1069
1070EOF
1071}
1072
1073#
Michael Bestas431a8002023-06-11 20:04:45 +03001074# write_xml_header:
1075#
1076# $1: file which will be written to
1077#
1078# writes out the warning message regarding manual file modifications.
1079# note that this is not an append operation, and should
1080# be executed first!
1081#
1082function write_xml_header() {
1083 if [ -f $1 ]; then
1084 rm $1
1085 fi
1086
1087 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
1088 [ "$COMMON" -eq 1 ] && local VENDOR="${VENDOR_COMMON:-$VENDOR}"
1089
1090 cat << EOF >> $1
1091<?xml version="1.0" encoding="utf-8"?>
1092<!--
1093 Automatically generated file. DO NOT MODIFY
1094
1095 This file is generated by device/$VENDOR/$DEVICE/setup-makefiles.sh
1096-->
1097EOF
1098}
1099
1100#
1101# write_rro_package:
1102#
1103# $1: the RRO package name
1104# $2: the RRO target package
1105# $3: the partition for the RRO overlay
1106#
1107# Generates the file structure for an RRO overlay.
1108#
1109function write_rro_package() {
1110 local PKGNAME="$1"
1111 if [ -z "$PKGNAME" ]; then
1112 echo "A package name must be provided to write_rro_package()!"
1113 exit 1
1114 fi
1115
1116 local TARGET_PACKAGE="$2"
1117 if [ -z "$TARGET_PACKAGE" ]; then
1118 echo "A target package must be provided to write_rro_package()!"
1119 exit 1
1120 fi
1121
1122 local PARTITION="$3"
1123 if [ -z "$PARTITION" ]; then
1124 PARTITION="vendor"
1125 fi
1126
1127 local RROBP="$ANDROID_ROOT"/"$OUTDIR"/rro_overlays/"$PKGNAME"/Android.bp
1128 local RROMANIFEST="$ANDROID_ROOT"/"$OUTDIR"/rro_overlays/"$PKGNAME"/AndroidManifest.xml
1129
1130 write_blueprint_header "$RROBP"
1131 write_xml_header "$RROMANIFEST"
1132
1133 write_rro_blueprint "$PKGNAME" "$PARTITION" >> "$RROBP"
1134 write_rro_androidmanifest "$TARGET_PACKAGE" >> "$RROMANIFEST"
1135}
1136
1137#
SamarV-1215556e2d2024-03-19 08:50:02 +05301138# write_package_definition:
1139#
1140# $@: list of packages
1141#
1142# writes out the final PRODUCT_PACKAGES list
1143#
1144function write_package_definition() {
1145 local PACKAGE_LIST=("${@}")
1146 local PACKAGE_COUNT=${#PACKAGE_LIST[@]}
1147
1148 if [ "$PACKAGE_COUNT" -eq "0" ]; then
1149 return 0
1150 fi
1151
1152 printf '\n%s\n' "PRODUCT_PACKAGES += \\"
1153 for (( i=1; i<PACKAGE_COUNT+1; i++ )); do
SamarV-1217e6b4082024-02-26 14:39:34 +05301154 local SKIP=false
SamarV-1215556e2d2024-03-19 08:50:02 +05301155 local LINEEND=" \\"
1156 if [ "$i" -eq "$PACKAGE_COUNT" ]; then
1157 LINEEND=""
1158 fi
SamarV-1217e6b4082024-02-26 14:39:34 +05301159 for PKG in $(tr "," "\n" <<< "$REQUIRED_PACKAGES_LIST"); do
1160 if [[ $PKG == "${PACKAGE_LIST[$i - 1]}" ]]; then
1161 SKIP=true
1162 break
1163 fi
1164 done
1165 # Skip adding of the package to product makefile if it's in the required list
1166 if [[ $SKIP == false ]]; then
1167 printf ' %s%s\n' "${PACKAGE_LIST[$i - 1]}" "$LINEEND" >> "$PRODUCTMK"
1168 fi
SamarV-1215556e2d2024-03-19 08:50:02 +05301169 done
1170}
1171
1172#
Steve Kondik5bd66602016-07-15 10:39:58 -07001173# write_headers:
1174#
1175# $1: devices falling under common to be added to guard - optional
Jake Whatley9843b322017-01-25 21:49:16 -05001176# $2: custom guard - optional
Steve Kondik5bd66602016-07-15 10:39:58 -07001177#
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001178# Calls write_makefile_header for each of the makefiles and
1179# write_blueprint_header for Android.bp and creates the initial
1180# path declaration and device guard for the Android.mk
Steve Kondik5bd66602016-07-15 10:39:58 -07001181#
1182function write_headers() {
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001183 write_makefile_header "$ANDROIDMK"
Jake Whatley9843b322017-01-25 21:49:16 -05001184
1185 GUARD="$2"
1186 if [ -z "$GUARD" ]; then
1187 GUARD="TARGET_DEVICE"
1188 fi
1189
Steve Kondik5bd66602016-07-15 10:39:58 -07001190 cat << EOF >> "$ANDROIDMK"
1191LOCAL_PATH := \$(call my-dir)
1192
1193EOF
1194 if [ "$COMMON" -ne 1 ]; then
1195 cat << EOF >> "$ANDROIDMK"
Jake Whatley9843b322017-01-25 21:49:16 -05001196ifeq (\$($GUARD),$DEVICE)
Steve Kondik5bd66602016-07-15 10:39:58 -07001197
1198EOF
1199 else
1200 if [ -z "$1" ]; then
1201 echo "Argument with devices to be added to guard must be set!"
1202 exit 1
1203 fi
1204 cat << EOF >> "$ANDROIDMK"
Jake Whatley9843b322017-01-25 21:49:16 -05001205ifneq (\$(filter $1,\$($GUARD)),)
Steve Kondik5bd66602016-07-15 10:39:58 -07001206
1207EOF
1208 fi
1209
Rashed Abdel-Tawabe2047042019-09-20 07:06:09 -07001210 write_makefile_header "$BOARDMK"
1211 write_makefile_header "$PRODUCTMK"
1212 write_blueprint_header "$ANDROIDBP"
1213
1214 cat << EOF >> "$ANDROIDBP"
1215soong_namespace {
1216}
1217
1218EOF
1219
1220 [ "$COMMON" -eq 1 ] && local DEVICE="$DEVICE_COMMON"
1221 cat << EOF >> "$PRODUCTMK"
1222PRODUCT_SOONG_NAMESPACES += \\
1223 vendor/$VENDOR/$DEVICE
1224
1225EOF
Steve Kondik5bd66602016-07-15 10:39:58 -07001226}
1227
1228#
1229# write_footers:
1230#
1231# Closes the inital guard and any other finalization tasks. Must
1232# be called as the final step.
1233#
1234function write_footers() {
1235 cat << EOF >> "$ANDROIDMK"
1236endif
1237EOF
1238}
1239
1240# Return success if adb is up and not in recovery
1241function _adb_connected {
1242 {
Jake Whatley9843b322017-01-25 21:49:16 -05001243 if [[ "$(adb get-state)" == device ]]
Steve Kondik5bd66602016-07-15 10:39:58 -07001244 then
1245 return 0
1246 fi
1247 } 2>/dev/null
1248
1249 return 1
1250};
1251
1252#
1253# parse_file_list:
1254#
1255# $1: input file
Rashed Abdel-Tawabb0d08e82017-04-04 02:48:18 -04001256# $2: blob section in file - optional
Steve Kondik5bd66602016-07-15 10:39:58 -07001257#
1258# Sets PRODUCT_PACKAGES and PRODUCT_COPY_FILES while parsing the input file
1259#
1260function parse_file_list() {
1261 if [ -z "$1" ]; then
1262 echo "An input file is expected!"
1263 exit 1
1264 elif [ ! -f "$1" ]; then
1265 echo "Input file "$1" does not exist!"
1266 exit 1
1267 fi
1268
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001269 if [ -n "$2" ]; then
1270 echo "Using section \"$2\""
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301271 LIST=$EXTRACT_TMP_DIR/files.txt
Vladimir Olteanfa79f212019-01-19 00:44:07 +02001272 # Match all lines starting with first line found to start* with '#'
1273 # comment and contain** $2, and ending with first line to be empty*.
1274 # *whitespaces (tabs, spaces) at the beginning of lines are discarded
1275 # **the $2 match is case-insensitive
1276 cat $1 | sed -n '/^[[:space:]]*#.*'"$2"'/I,/^[[:space:]]*$/ p' > $LIST
Rashed Abdel-Tawabb0d08e82017-04-04 02:48:18 -04001277 else
1278 LIST=$1
1279 fi
1280
Steve Kondik5bd66602016-07-15 10:39:58 -07001281 PRODUCT_PACKAGES_LIST=()
1282 PRODUCT_PACKAGES_HASHES=()
Vladimir Olteande985fe2019-01-17 03:07:34 +02001283 PRODUCT_PACKAGES_FIXUP_HASHES=()
SamarV-1215556e2d2024-03-19 08:50:02 +05301284 PRODUCT_SYMLINKS_LIST=()
Steve Kondik5bd66602016-07-15 10:39:58 -07001285 PRODUCT_COPY_FILES_LIST=()
1286 PRODUCT_COPY_FILES_HASHES=()
Vladimir Olteande985fe2019-01-17 03:07:34 +02001287 PRODUCT_COPY_FILES_FIXUP_HASHES=()
Steve Kondik5bd66602016-07-15 10:39:58 -07001288
1289 while read -r line; do
1290 if [ -z "$line" ]; then continue; fi
1291
1292 # If the line has a pipe delimiter, a sha1 hash should follow.
1293 # This indicates the file should be pinned and not overwritten
1294 # when extracting files.
1295 local SPLIT=(${line//\|/ })
1296 local COUNT=${#SPLIT[@]}
1297 local SPEC=${SPLIT[0]}
1298 local HASH="x"
Vladimir Olteande985fe2019-01-17 03:07:34 +02001299 local FIXUP_HASH="x"
Steve Kondik5bd66602016-07-15 10:39:58 -07001300 if [ "$COUNT" -gt "1" ]; then
1301 HASH=${SPLIT[1]}
1302 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001303 if [ "$COUNT" -gt "2" ]; then
1304 FIXUP_HASH=${SPLIT[2]}
1305 fi
SamarV-1215556e2d2024-03-19 08:50:02 +05301306 if [[ "$SPEC" =~ 'SYMLINK=' ]]; then
1307 PRODUCT_SYMLINKS_LIST+=("${SPEC#-}")
1308 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001309 # if line starts with a dash, it needs to be packaged
1310 if [[ "$SPEC" =~ ^- ]]; then
1311 PRODUCT_PACKAGES_LIST+=("${SPEC#-}")
1312 PRODUCT_PACKAGES_HASHES+=("$HASH")
Vladimir Olteande985fe2019-01-17 03:07:34 +02001313 PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH")
Chirayu Desaia7741012021-12-04 07:17:28 +05301314 # if line contains apex, apk, jar or vintf fragment, it needs to be packaged
1315 elif suffix_match_file ".apex" "$(src_file "$SPEC")" || \
1316 suffix_match_file ".apk" "$(src_file "$SPEC")" || \
Michael Bestasea90aef2021-11-15 22:18:04 +02001317 suffix_match_file ".jar" "$(src_file "$SPEC")" || \
1318 [[ "$SPEC" == *"etc/vintf/manifest/"* ]]; then
1319 PRODUCT_PACKAGES_LIST+=("$SPEC")
1320 PRODUCT_PACKAGES_HASHES+=("$HASH")
1321 PRODUCT_PACKAGES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik5bd66602016-07-15 10:39:58 -07001322 else
1323 PRODUCT_COPY_FILES_LIST+=("$SPEC")
1324 PRODUCT_COPY_FILES_HASHES+=("$HASH")
Vladimir Olteande985fe2019-01-17 03:07:34 +02001325 PRODUCT_COPY_FILES_FIXUP_HASHES+=("$FIXUP_HASH")
Steve Kondik5bd66602016-07-15 10:39:58 -07001326 fi
1327
Chirayu Desaif1a21302022-09-13 00:29:33 +05301328 done < <(grep -v -E '(^#|^[[:space:]]*$)' "$LIST" | LC_ALL=C sort | uniq)
Steve Kondik5bd66602016-07-15 10:39:58 -07001329}
1330
1331#
1332# write_makefiles:
1333#
1334# $1: file containing the list of items to extract
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -04001335# $2: make treble compatible makefile - optional
Steve Kondik5bd66602016-07-15 10:39:58 -07001336#
SamarV-1215556e2d2024-03-19 08:50:02 +05301337# Calls write_product_copy_files, write_product_packages and
1338# lastly write_symlink_packages on the given file and appends
1339# to the Android.bp as well as the product makefile.
Steve Kondik5bd66602016-07-15 10:39:58 -07001340#
1341function write_makefiles() {
1342 parse_file_list "$1"
Rashed Abdel-Tawab7fd3ccb2017-10-07 14:18:39 -04001343 write_product_copy_files "$2"
Steve Kondik5bd66602016-07-15 10:39:58 -07001344 write_product_packages
SamarV-1215556e2d2024-03-19 08:50:02 +05301345 write_symlink_packages
Steve Kondik5bd66602016-07-15 10:39:58 -07001346}
1347
1348#
1349# append_firmware_calls_to_makefiles:
1350#
Michael Bestasf62d4032022-02-22 19:06:41 +02001351# $1: file containing the list of items to extract
1352#
Michael Bestasc72d0f62022-04-16 21:06:28 +03001353# Appends the calls to all images present in radio folder to Android.mk
1354# and radio AB_OTA_PARTITIONS to BoardConfigVendor.mk
Michael Bestasf62d4032022-02-22 19:06:41 +02001355#
Michael Bestasc72d0f62022-04-16 21:06:28 +03001356function append_firmware_calls_to_makefiles() {
Michael Bestasf62d4032022-02-22 19:06:41 +02001357 parse_file_list "$1"
1358
1359 local FILELIST=(${PRODUCT_COPY_FILES_LIST[@]})
1360 local COUNT=${#FILELIST[@]}
1361
SamarV-1217e56a0b2024-03-09 12:58:18 +05301362 if [[ ${FILELIST[*]} =~ ";AB" ]]; then
1363 printf '%s\n' "AB_OTA_PARTITIONS += \\" >> "$BOARDMK"
1364 fi
1365
Michael Bestasf62d4032022-02-22 19:06:41 +02001366 for (( i=1; i<COUNT+1; i++ )); do
1367 local DST_FILE=$(target_file "${FILELIST[$i-1]}")
1368 local ARGS=$(target_args "${FILELIST[$i-1]}")
LuK133711d86862023-12-11 01:34:29 +01001369 local SHA1=$(get_hash "$ANDROID_ROOT"/"$OUTDIR"/radio/"$DST_FILE")
Michael Bestasc72d0f62022-04-16 21:06:28 +03001370 DST_FILE_NAME=(${DST_FILE//.img/ })
Michael Bestasf62d4032022-02-22 19:06:41 +02001371 ARGS=(${ARGS//;/ })
1372 LINEEND=" \\"
1373 if [ "$i" -eq "$COUNT" ]; then
1374 LINEEND=""
1375 fi
1376
1377 for ARG in "${ARGS[@]}"; do
1378 if [[ "$ARG" =~ "AB" ]]; then
Michael Bestasc72d0f62022-04-16 21:06:28 +03001379 printf ' %s%s\n' "$DST_FILE_NAME" "$LINEEND" >> "$BOARDMK"
Michael Bestasf62d4032022-02-22 19:06:41 +02001380 fi
1381 done
LuK133711d86862023-12-11 01:34:29 +01001382 printf '%s\n' "\$(call add-radio-file-sha1-checked,radio/$DST_FILE,$SHA1)" >> "$ANDROIDMK"
Michael Bestasf62d4032022-02-22 19:06:41 +02001383 done
Michael Bestasc72d0f62022-04-16 21:06:28 +03001384 printf '\n' >> "$ANDROIDMK"
Michael Bestasf62d4032022-02-22 19:06:41 +02001385}
1386
1387#
Steve Kondik5bd66602016-07-15 10:39:58 -07001388# get_file:
1389#
1390# $1: input file
1391# $2: target file/folder
1392# $3: source of the file (can be "adb" or a local folder)
1393#
1394# Silently extracts the input file to defined target
1395# Returns success if file can be pulled from the device or found locally
1396#
1397function get_file() {
1398 local SRC="$3"
1399
1400 if [ "$SRC" = "adb" ]; then
1401 # try to pull
LuK13370f7f0d12022-08-19 21:49:56 +02001402 adb pull "$1" "$2" >/dev/null 2>&1 && return 0
1403 adb pull "${1#/system}" "$2" >/dev/null 2>&1 && return 0
1404 adb pull "system/$1" "$2" >/dev/null 2>&1 && return 0
Steve Kondik5bd66602016-07-15 10:39:58 -07001405
1406 return 1
1407 else
1408 # try to copy
Vladimir Olteanfe49eae2018-06-25 00:05:56 +03001409 cp -r "$SRC/$1" "$2" 2>/dev/null && return 0
1410 cp -r "$SRC/${1#/system}" "$2" 2>/dev/null && return 0
Vladimir Oltean6780da32019-01-06 19:38:31 +02001411 cp -r "$SRC/system/$1" "$2" 2>/dev/null && return 0
Steve Kondik5bd66602016-07-15 10:39:58 -07001412
LuK1337dbb77cc2023-12-04 19:03:10 +01001413 # try /vendor/odm for devices without /odm partition
1414 [[ "$1" == /system/odm/* ]] && cp -r "$SRC/vendor/${1#/system}" "$2" 2>/dev/null && return 0
1415
Steve Kondik5bd66602016-07-15 10:39:58 -07001416 return 1
1417 fi
1418};
1419
1420#
1421# oat2dex:
1422#
1423# $1: extracted apk|jar (to check if deodex is required)
1424# $2: odexed apk|jar to deodex
1425# $3: source of the odexed apk|jar
1426#
1427# Convert apk|jar .odex in the corresposing classes.dex
1428#
1429function oat2dex() {
theimpulson9a911af2019-08-14 03:25:12 +00001430 local OMNI_TARGET="$1"
Steve Kondik5bd66602016-07-15 10:39:58 -07001431 local OEM_TARGET="$2"
1432 local SRC="$3"
1433 local TARGET=
Joe Maplesfb3941c2018-01-05 14:51:33 -05001434 local OAT=
Steve Kondik5bd66602016-07-15 10:39:58 -07001435
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001436 if [ -z "$BAKSMALIJAR" ] || [ -z "$SMALIJAR" ]; then
1437 export BAKSMALIJAR="$OMNI_ROOT"/vendor/omni/build/tools/smali/baksmali.jar
1438 export SMALIJAR="$OMNI_ROOT"/vendor/omni/build/tools/smali/smali.jar
Steve Kondik5bd66602016-07-15 10:39:58 -07001439 fi
1440
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001441 if [ -z "$VDEXEXTRACTOR" ]; then
Han Wang7a0b0bd2020-03-10 09:40:47 +02001442 export VDEXEXTRACTOR="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/vdexExtractor
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001443 fi
Joe Maplesfb3941c2018-01-05 14:51:33 -05001444
codeworkx85eda752018-09-23 12:36:57 +02001445 if [ -z "$CDEXCONVERTER" ]; then
Han Wang7a0b0bd2020-03-10 09:40:47 +02001446 export CDEXCONVERTER="$OMNI_ROOT"/vendor/omni/build/tools/${HOST}/compact_dex_converter
codeworkx85eda752018-09-23 12:36:57 +02001447 fi
1448
Steve Kondik5bd66602016-07-15 10:39:58 -07001449 # Extract existing boot.oats to the temp folder
1450 if [ -z "$ARCHES" ]; then
Jake Whatley9843b322017-01-25 21:49:16 -05001451 echo "Checking if system is odexed and locating boot.oats..."
Steve Kondik5bd66602016-07-15 10:39:58 -07001452 for ARCH in "arm64" "arm" "x86_64" "x86"; do
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301453 mkdir -p "$EXTRACT_TMP_DIR/system/framework/$ARCH"
1454 if get_file "/system/framework/$ARCH" "$EXTRACT_TMP_DIR/system/framework/" "$SRC"; then
Steve Kondik5bd66602016-07-15 10:39:58 -07001455 ARCHES+="$ARCH "
Jake Whatley9843b322017-01-25 21:49:16 -05001456 else
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301457 rmdir "$EXTRACT_TMP_DIR/system/framework/$ARCH"
Steve Kondik5bd66602016-07-15 10:39:58 -07001458 fi
1459 done
1460 fi
1461
1462 if [ -z "$ARCHES" ]; then
1463 FULLY_DEODEXED=1 && return 0 # system is fully deodexed, return
1464 fi
1465
theimpulson9a911af2019-08-14 03:25:12 +00001466 if [ ! -f "$OMNI_TARGET" ]; then
Steve Kondik5bd66602016-07-15 10:39:58 -07001467 return;
1468 fi
1469
theimpulson9a911af2019-08-14 03:25:12 +00001470 if grep "classes.dex" "$OMNI_TARGET" >/dev/null; then
Steve Kondik5bd66602016-07-15 10:39:58 -07001471 return 0 # target apk|jar is already odexed, return
1472 fi
1473
1474 for ARCH in $ARCHES; do
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301475 BOOTOAT="$EXTRACT_TMP_DIR/system/framework/$ARCH/boot.oat"
Steve Kondik5bd66602016-07-15 10:39:58 -07001476
Joe Maplesfb3941c2018-01-05 14:51:33 -05001477 local OAT="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").odex"
1478 local VDEX="$(dirname "$OEM_TARGET")/oat/$ARCH/$(basename "$OEM_TARGET" ."${OEM_TARGET##*.}").vdex"
Steve Kondik5bd66602016-07-15 10:39:58 -07001479
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301480 if get_file "$OAT" "$EXTRACT_TMP_DIR" "$SRC"; then
1481 if get_file "$VDEX" "$EXTRACT_TMP_DIR" "$SRC"; then
1482 "$VDEXEXTRACTOR" -o "$EXTRACT_TMP_DIR/" -i "$EXTRACT_TMP_DIR/$(basename "$VDEX")" > /dev/null
1483 CLASSES=$(ls "$EXTRACT_TMP_DIR/$(basename "${OEM_TARGET%.*}")_classes"*)
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001484 for CLASS in $CLASSES; do
1485 NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/')
1486 # Check if we have to deal with CompactDex
1487 if [[ "$CLASS" == *.cdex ]]; then
1488 "$CDEXCONVERTER" "$CLASS" &>/dev/null
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301489 mv "$CLASS.new" "$EXTRACT_TMP_DIR/$NEWCLASS"
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001490 else
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301491 mv "$CLASS" "$EXTRACT_TMP_DIR/$NEWCLASS"
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001492 fi
1493 done
Joe Maplesfb3941c2018-01-05 14:51:33 -05001494 else
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301495 java -jar "$BAKSMALIJAR" deodex -o "$EXTRACT_TMP_DIR/dexout" -b "$BOOTOAT" -d "$EXTRACT_TMP_DIR" "$EXTRACT_TMP_DIR/$(basename "$OAT")"
1496 java -jar "$SMALIJAR" assemble "$EXTRACT_TMP_DIR/dexout" -o "$EXTRACT_TMP_DIR/classes.dex"
Joe Maplesfb3941c2018-01-05 14:51:33 -05001497 fi
theimpulson9a911af2019-08-14 03:25:12 +00001498 elif [[ "$OMNI_TARGET" =~ .jar$ ]]; then
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301499 JAROAT="$EXTRACT_TMP_DIR/system/framework/$ARCH/boot-$(basename ${OEM_TARGET%.*}).oat"
Luca Stefani082f1e82018-10-07 12:44:53 +02001500 JARVDEX="/system/framework/boot-$(basename ${OEM_TARGET%.*}).vdex"
Jake Whatley9843b322017-01-25 21:49:16 -05001501 if [ ! -f "$JAROAT" ]; then
Luca Stefani082f1e82018-10-07 12:44:53 +02001502 JAROAT=$BOOTOAT
Jake Whatley9843b322017-01-25 21:49:16 -05001503 fi
Joe Maplesfb3941c2018-01-05 14:51:33 -05001504 # try to extract classes.dex from boot.vdex for frameworks jars
1505 # fallback to boot.oat if vdex is not available
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301506 if get_file "$JARVDEX" "$EXTRACT_TMP_DIR" "$SRC"; then
1507 "$VDEXEXTRACTOR" -o "$EXTRACT_TMP_DIR/" -i "$EXTRACT_TMP_DIR/$(basename "$JARVDEX")" > /dev/null
1508 CLASSES=$(ls "$EXTRACT_TMP_DIR/$(basename "${JARVDEX%.*}")_classes"*)
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001509 for CLASS in $CLASSES; do
1510 NEWCLASS=$(echo "$CLASS" | sed 's/.*_//;s/cdex/dex/')
1511 # Check if we have to deal with CompactDex
1512 if [[ "$CLASS" == *.cdex ]]; then
1513 "$CDEXCONVERTER" "$CLASS" &>/dev/null
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301514 mv "$CLASS.new" "$EXTRACT_TMP_DIR/$NEWCLASS"
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001515 else
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301516 mv "$CLASS" "$EXTRACT_TMP_DIR/$NEWCLASS"
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001517 fi
1518 done
Joe Maplesfb3941c2018-01-05 14:51:33 -05001519 else
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301520 java -jar "$BAKSMALIJAR" deodex -o "$EXTRACT_TMP_DIR/dexout" -b "$BOOTOAT" -d "$EXTRACT_TMP_DIR" "$JAROAT/$OEM_TARGET"
1521 java -jar "$SMALIJAR" assemble "$EXTRACT_TMP_DIR/dexout" -o "$EXTRACT_TMP_DIR/classes.dex"
Joe Maplesfb3941c2018-01-05 14:51:33 -05001522 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001523 else
1524 continue
1525 fi
1526
Steve Kondik5bd66602016-07-15 10:39:58 -07001527 done
Rashed Abdel-Tawabd7124972018-03-15 12:55:22 -07001528
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301529 rm -rf "$EXTRACT_TMP_DIR/dexout"
Steve Kondik5bd66602016-07-15 10:39:58 -07001530}
1531
1532#
1533# init_adb_connection:
1534#
1535# Starts adb server and waits for the device
1536#
1537function init_adb_connection() {
1538 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
1539 if ! _adb_connected; then
1540 echo "No device is online. Waiting for one..."
1541 echo "Please connect USB and/or enable USB debugging"
1542 until _adb_connected; do
1543 sleep 1
1544 done
1545 echo "Device Found."
1546 fi
1547
1548 # Retrieve IP and PORT info if we're using a TCP connection
Chirayu Desaif1a21302022-09-13 00:29:33 +05301549 TCPIPPORT=$(adb devices | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
Steve Kondik5bd66602016-07-15 10:39:58 -07001550 | head -1 | awk '{print $1}')
1551 adb root &> /dev/null
1552 sleep 0.3
1553 if [ -n "$TCPIPPORT" ]; then
1554 # adb root just killed our connection
1555 # so reconnect...
1556 adb connect "$TCPIPPORT"
1557 fi
1558 adb wait-for-device &> /dev/null
1559 sleep 0.3
1560}
1561
1562#
1563# fix_xml:
1564#
1565# $1: xml file to fix
1566#
1567function fix_xml() {
1568 local XML="$1"
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301569 local TEMP_XML="$EXTRACT_TMP_DIR/`basename "$XML"`.temp"
Steve Kondik5bd66602016-07-15 10:39:58 -07001570
Dobroslaw Kijowski3af2a8d2017-05-18 12:35:02 +02001571 grep -a '^<?xml version' "$XML" > "$TEMP_XML"
1572 grep -av '^<?xml version' "$XML" >> "$TEMP_XML"
Steve Kondik5bd66602016-07-15 10:39:58 -07001573
1574 mv "$TEMP_XML" "$XML"
1575}
1576
Vladimir Olteande985fe2019-01-17 03:07:34 +02001577function get_hash() {
1578 local FILE="$1"
1579
1580 if [ "$(uname)" == "Darwin" ]; then
1581 shasum "${FILE}" | awk '{print $1}'
1582 else
1583 sha1sum "${FILE}" | awk '{print $1}'
1584 fi
1585}
1586
Vladimir Olteana7d20492019-01-17 03:05:52 +02001587function print_spec() {
1588 local SPEC_PRODUCT_PACKAGE="$1"
1589 local SPEC_SRC_FILE="$2"
1590 local SPEC_DST_FILE="$3"
1591 local SPEC_ARGS="$4"
1592 local SPEC_HASH="$5"
Vladimir Olteande985fe2019-01-17 03:07:34 +02001593 local SPEC_FIXUP_HASH="$6"
Vladimir Olteana7d20492019-01-17 03:05:52 +02001594
1595 local PRODUCT_PACKAGE=""
1596 if [ ${SPEC_PRODUCT_PACKAGE} = true ]; then
1597 PRODUCT_PACKAGE="-"
1598 fi
1599 local SRC=""
1600 if [ ! -z "${SPEC_SRC_FILE}" ] && [ "${SPEC_SRC_FILE}" != "${SPEC_DST_FILE}" ]; then
1601 SRC="${SPEC_SRC_FILE}:"
1602 fi
1603 local DST=""
1604 if [ ! -z "${SPEC_DST_FILE}" ]; then
1605 DST="${SPEC_DST_FILE}"
1606 fi
1607 local ARGS=""
1608 if [ ! -z "${SPEC_ARGS}" ]; then
1609 ARGS=";${SPEC_ARGS}"
1610 fi
1611 local HASH=""
1612 if [ ! -z "${SPEC_HASH}" ] && [ "${SPEC_HASH}" != "x" ]; then
1613 HASH="|${SPEC_HASH}"
1614 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001615 local FIXUP_HASH=""
1616 if [ ! -z "${SPEC_FIXUP_HASH}" ] && [ "${SPEC_FIXUP_HASH}" != "x" ] && [ "${SPEC_FIXUP_HASH}" != "${SPEC_HASH}" ]; then
1617 FIXUP_HASH="|${SPEC_FIXUP_HASH}"
1618 fi
1619 printf '%s%s%s%s%s%s\n' "${PRODUCT_PACKAGE}" "${SRC}" "${DST}" "${ARGS}" "${HASH}" "${FIXUP_HASH}"
1620}
1621
1622# To be overridden by device-level extract-files.sh
1623# Parameters:
1624# $1: spec name of a blob. Can be used for filtering.
1625# If the spec is "src:dest", then $1 is "dest".
1626# If the spec is "src", then $1 is "src".
1627# $2: path to blob file. Can be used for fixups.
1628#
1629function blob_fixup() {
1630 :
Vladimir Olteana7d20492019-01-17 03:05:52 +02001631}
1632
Steve Kondik5bd66602016-07-15 10:39:58 -07001633#
1634# extract:
1635#
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001636# Positional parameters:
1637# $1: file containing the list of items to extract (aka proprietary-files.txt)
Dan Pasanen0cc05012017-03-21 09:06:11 -05001638# $2: path to extracted system folder, an ota zip file, or "adb" to extract from device
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001639# $3: section in list file to extract - optional. Setting section via $3 is deprecated.
1640#
1641# Non-positional parameters (coming after $2):
1642# --section: preferred way of selecting the portion to parse and extract from
1643# proprietary-files.txt
Vladimir Olteana7d20492019-01-17 03:05:52 +02001644# --kang: if present, this option will activate the printing of hashes for the
1645# extracted blobs. Useful with --section for subsequent pinning of
1646# blobs taken from other origins.
Steve Kondik5bd66602016-07-15 10:39:58 -07001647#
1648function extract() {
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001649 # Consume positional parameters
1650 local PROPRIETARY_FILES_TXT="$1"; shift
1651 local SRC="$1"; shift
1652 local SECTION=""
Vladimir Olteana7d20492019-01-17 03:05:52 +02001653 local KANG=false
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001654
1655 # Consume optional, non-positional parameters
1656 while [ "$#" -gt 0 ]; do
1657 case "$1" in
1658 -s|--section)
1659 SECTION="$2"; shift
1660 ;;
Vladimir Olteana7d20492019-01-17 03:05:52 +02001661 -k|--kang)
1662 KANG=true
1663 DISABLE_PINNING=1
1664 ;;
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001665 *)
1666 # Backwards-compatibility with the old behavior, where $3, if
1667 # present, denoted an optional positional ${SECTION} argument.
1668 # Users of ${SECTION} are encouraged to migrate from setting it as
1669 # positional $3, to non-positional --section ${SECTION}, the
1670 # reason being that it doesn't scale to have more than 1 optional
1671 # positional argument.
1672 SECTION="$1"
1673 ;;
1674 esac
1675 shift
1676 done
1677
Steve Kondik5bd66602016-07-15 10:39:58 -07001678 if [ -z "$OUTDIR" ]; then
1679 echo "Output dir not set!"
1680 exit 1
1681 fi
1682
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001683 parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001684
1685 # Allow failing, so we can try $DEST and/or $FILE
1686 set +e
1687
1688 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} )
1689 local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} )
Vladimir Olteande985fe2019-01-17 03:07:34 +02001690 local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} )
Vladimir Olteana7d20492019-01-17 03:05:52 +02001691 local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
Steve Kondik5bd66602016-07-15 10:39:58 -07001692 local COUNT=${#FILELIST[@]}
theimpulson9a911af2019-08-14 03:25:12 +00001693 local OUTPUT_ROOT="$OMNI_ROOT"/"$OUTDIR"/proprietary
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301694 local OUTPUT_TMP="$EXTRACT_TMP_DIR"/"$OUTDIR"/proprietary
Steve Kondik5bd66602016-07-15 10:39:58 -07001695
1696 if [ "$SRC" = "adb" ]; then
1697 init_adb_connection
1698 fi
1699
Dan Pasanen0cc05012017-03-21 09:06:11 -05001700 if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301701 DUMPDIR="$EXTRACT_TMP_DIR"/system_dump
Dan Pasanen0cc05012017-03-21 09:06:11 -05001702
1703 # Check if we're working with the same zip that was passed last time.
1704 # If so, let's just use what's already extracted.
1705 MD5=`md5sum "$SRC"| awk '{print $1}'`
1706 OLDMD5=`cat "$DUMPDIR"/zipmd5.txt`
1707
1708 if [ "$MD5" != "$OLDMD5" ]; then
1709 rm -rf "$DUMPDIR"
1710 mkdir "$DUMPDIR"
1711 unzip "$SRC" -d "$DUMPDIR"
1712 echo "$MD5" > "$DUMPDIR"/zipmd5.txt
1713
Chirayu Desai817dc762021-11-26 05:47:25 +05301714 # Extract A/B OTA
Dan Pasanen0cc05012017-03-21 09:06:11 -05001715 if [ -a "$DUMPDIR"/payload.bin ]; then
Chirayu Desai817dc762021-11-26 05:47:25 +05301716 python3 "$ANDROID_ROOT"/tools/extract-utils/extract_ota.py "$DUMPDIR"/payload.bin -o "$DUMPDIR" -p "system" "odm" "product" "system_ext" "vendor" 2>&1
Dan Pasanen0cc05012017-03-21 09:06:11 -05001717 fi
dianlujitao85ddca62020-04-21 23:03:20 +08001718
Luca Stefani776be462020-09-09 15:53:58 +02001719 for PARTITION in "system" "odm" "product" "system_ext" "vendor"
dianlujitao85ddca62020-04-21 23:03:20 +08001720 do
1721 # If OTA is block based, extract it.
dianlujitaoe2cbe262020-04-21 23:01:13 +08001722 if [ -a "$DUMPDIR"/"$PARTITION".new.dat.br ]; then
1723 echo "Converting "$PARTITION".new.dat.br to "$PARTITION".new.dat"
1724 brotli -d "$DUMPDIR"/"$PARTITION".new.dat.br
1725 rm "$DUMPDIR"/"$PARTITION".new.dat.br
1726 fi
dianlujitao85ddca62020-04-21 23:03:20 +08001727 if [ -a "$DUMPDIR"/"$PARTITION".new.dat ]; then
1728 echo "Converting "$PARTITION".new.dat to "$PARTITION".img"
1729 python "$OMNI_ROOT"/vendor/omni/build/tools/sdat2img.py "$DUMPDIR"/"$PARTITION".transfer.list "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION".img 2>&1
1730 rm -rf "$DUMPDIR"/"$PARTITION".new.dat "$DUMPDIR"/"$PARTITION"
1731 mkdir "$DUMPDIR"/"$PARTITION" "$DUMPDIR"/tmp
Chirayu Desai62ed12a2021-11-26 05:47:25 +05301732 extract_img_data "$DUMPDIR"/"$PARTITION".img "$DUMPDIR"/"$PARTITION"/
1733 rm "$DUMPDIR"/"$PARTITION".img
dianlujitao85ddca62020-04-21 23:03:20 +08001734 fi
Chirayu Desai817dc762021-11-26 05:47:25 +05301735 if [ -a "$DUMPDIR"/"$PARTITION".img ]; then
1736 extract_img_data "$DUMPDIR"/"$PARTITION".img "$DUMPDIR"/"$PARTITION"/
1737 fi
dianlujitao85ddca62020-04-21 23:03:20 +08001738 done
Dan Pasanen0cc05012017-03-21 09:06:11 -05001739 fi
1740
1741 SRC="$DUMPDIR"
1742 fi
1743
Michael Bestasf2501c32022-02-18 23:45:09 +02001744 if [ -d "$SRC" ] && [ -f "$SRC"/super.img ]; then
1745 DUMPDIR="$TMPDIR"/super_dump
1746 mkdir -p "$DUMPDIR"
1747
1748 echo "Unpacking super.img"
1749 "$SIMG2IMG" "$SRC"/super.img "$DUMPDIR"/super.raw
1750
1751 for PARTITION in "system" "odm" "product" "system_ext" "vendor"
1752 do
1753 echo "Preparing "$PARTITION""
1754 if "$LPUNPACK" -p "$PARTITION"_a "$DUMPDIR"/super.raw "$DUMPDIR" ; then
1755 mv "$DUMPDIR"/"$PARTITION"_a.img "$DUMPDIR"/"$PARTITION".img
1756 else
1757 "$LPUNPACK" -p "$PARTITION" "$DUMPDIR"/super.raw "$DUMPDIR"
1758 fi
1759 done
1760
1761 SRC="$DUMPDIR"
1762 fi
1763
Chirayu Desaia3850bd2021-11-26 05:47:25 +05301764 if [ -d "$SRC" ] && [ -f "$SRC"/system.img ]; then
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301765 DUMPDIR="$EXTRACT_TMP_DIR"/system_dump
Chirayu Desaia3850bd2021-11-26 05:47:25 +05301766 mkdir -p "$DUMPDIR"
1767
1768 for PARTITION in "system" "odm" "product" "system_ext" "vendor"
1769 do
1770 echo "Extracting "$PARTITION""
1771 local IMAGE="$SRC"/"$PARTITION".img
1772 if [ -f "$IMAGE" ]; then
LuK133707657db2023-11-30 18:11:51 +01001773 if [[ $(file -b "$IMAGE") == EROFS* ]]; then
1774 fsck.erofs --extract="$DUMPDIR"/"$PARTITION" "$IMAGE"
1775 elif [[ $(file -b "$IMAGE") == Linux* ]]; then
Chirayu Desaia3850bd2021-11-26 05:47:25 +05301776 extract_img_data "$IMAGE" "$DUMPDIR"/"$PARTITION"
1777 elif [[ $(file -b "$IMAGE") == Android* ]]; then
Chirayu Desai501ffd62022-03-17 06:27:33 +05301778 "$SIMG2IMG" "$IMAGE" "$DUMPDIR"/"$PARTITION".raw
Chirayu Desaia3850bd2021-11-26 05:47:25 +05301779 extract_img_data "$DUMPDIR"/"$PARTITION".raw "$DUMPDIR"/"$PARTITION"/
1780 else
1781 echo "Unsupported "$IMAGE""
1782 fi
1783 fi
1784 done
1785
1786 SRC="$DUMPDIR"
1787 fi
1788
Steve Kondik5bd66602016-07-15 10:39:58 -07001789 if [ "$VENDOR_STATE" -eq "0" ]; then
1790 echo "Cleaning output directory ($OUTPUT_ROOT).."
1791 rm -rf "${OUTPUT_TMP:?}"
1792 mkdir -p "${OUTPUT_TMP:?}"
Jake Whatley9843b322017-01-25 21:49:16 -05001793 if [ -d "$OUTPUT_ROOT" ]; then
1794 mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/"
1795 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001796 VENDOR_STATE=1
1797 fi
1798
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001799 echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:"
Steve Kondik5bd66602016-07-15 10:39:58 -07001800
1801 for (( i=1; i<COUNT+1; i++ )); do
1802
Vladimir Oltean8e2de652018-06-24 20:41:30 +03001803 local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}")
Vladimir Olteanb06f3aa2018-06-24 20:38:04 +03001804 local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}")
Vladimir Olteand6391332018-06-24 20:42:01 +03001805 local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}")
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001806 local OUTPUT_DIR=
1807 local TMP_DIR=
1808 local SRC_FILE=
1809 local DST_FILE=
Vladimir Olteana7d20492019-01-17 03:05:52 +02001810 local IS_PRODUCT_PACKAGE=false
1811
1812 # Note: this relies on the fact that the ${FILELIST[@]} array
1813 # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}.
1814 if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then
1815 IS_PRODUCT_PACKAGE=true
1816 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001817
Michael Bestasbda30202020-12-28 04:44:52 +02001818 OUTPUT_DIR="${OUTPUT_ROOT}"
1819 TMP_DIR="${OUTPUT_TMP}"
1820 SRC_FILE="/system/${SPEC_SRC_FILE}"
1821 DST_FILE="/system/${SPEC_DST_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001822
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001823 # Strip the file path in the vendor repo of "system", if present
Vladimir Oltean724a7bc2019-01-17 03:04:16 +02001824 local BLOB_DISPLAY_NAME="${DST_FILE#/system/}"
dianlujitao4ddcfb72020-04-06 12:43:16 +08001825 local VENDOR_REPO_FILE="$OUTPUT_DIR/${BLOB_DISPLAY_NAME}"
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001826 mkdir -p $(dirname "${VENDOR_REPO_FILE}")
Steve Kondik5bd66602016-07-15 10:39:58 -07001827
Gabriele M58270a32017-11-13 23:15:29 +01001828 # Check pinned files
Vladimir Olteane688cf92019-01-17 02:47:02 +02001829 local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Vladimir Olteande985fe2019-01-17 03:07:34 +02001830 local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
Gabriele M58270a32017-11-13 23:15:29 +01001831 local KEEP=""
Vladimir Olteande985fe2019-01-17 03:07:34 +02001832 if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001833 if [ -f "${VENDOR_REPO_FILE}" ]; then
1834 local PINNED="${VENDOR_REPO_FILE}"
Gabriele M58270a32017-11-13 23:15:29 +01001835 else
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001836 local PINNED="${TMP_DIR}${DST_FILE#/system}"
Gabriele M58270a32017-11-13 23:15:29 +01001837 fi
1838 if [ -f "$PINNED" ]; then
Vladimir Olteande985fe2019-01-17 03:07:34 +02001839 local TMP_HASH=$(get_hash "${PINNED}")
1840 if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then
Gabriele M58270a32017-11-13 23:15:29 +01001841 KEEP="1"
Vladimir Oltean4daf5592018-06-24 20:46:42 +03001842 if [ ! -f "${VENDOR_REPO_FILE}" ]; then
1843 cp -p "$PINNED" "${VENDOR_REPO_FILE}"
Gabriele M58270a32017-11-13 23:15:29 +01001844 fi
1845 fi
1846 fi
1847 fi
1848
Vladimir Olteana7d20492019-01-17 03:05:52 +02001849 if [ "${KANG}" = false ]; then
1850 printf ' - %s\n' "${BLOB_DISPLAY_NAME}"
1851 fi
1852
Gabriele M58270a32017-11-13 23:15:29 +01001853 if [ "$KEEP" = "1" ]; then
Arian2d802382021-09-09 15:18:35 +02001854 if [ "${FIXUP_HASH}" != "x" ]; then
1855 printf ' + keeping pinned file with hash %s\n' "${FIXUP_HASH}"
1856 else
1857 printf ' + keeping pinned file with hash %s\n' "${HASH}"
1858 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001859 else
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001860 FOUND=false
1861 # Try Lineage target first.
1862 # Also try to search for files stripped of
1863 # the "/system" prefix, if we're actually extracting
1864 # from a system image.
Vladimir Olteanfe49eae2018-06-25 00:05:56 +03001865 for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do
Vladimir Olteanb5500d72018-06-24 21:06:12 +03001866 get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${SRC} && {
1867 FOUND=true
1868 break
1869 }
1870 done
1871
1872 if [ "${FOUND}" = false ]; then
Bruno Martins74e00eb2021-04-10 14:36:50 +01001873 colored_echo red " !! ${BLOB_DISPLAY_NAME}: file not found in source"
Vladimir Oltean11329372018-10-18 00:44:02 +03001874 continue
Steve Kondik5bd66602016-07-15 10:39:58 -07001875 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001876
Arian5f98d792021-09-09 15:24:25 +02001877 # Blob fixup pipeline has 2 parts: one that is fixed and
1878 # one that is user-configurable
1879 local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
1880 # Deodex apk|jar if that's the case
1881 if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then
1882 oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "$SRC"
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301883 if [ -f "$EXTRACT_TMP_DIR/classes.dex" ]; then
1884 touch -t 200901010000 "$EXTRACT_TMP_DIR/classes"*
1885 zip -gjq "${VENDOR_REPO_FILE}" "$EXTRACT_TMP_DIR/classes"*
1886 rm "$EXTRACT_TMP_DIR/classes"*
Arian5f98d792021-09-09 15:24:25 +02001887 printf ' (updated %s from odex files)\n' "${SRC_FILE}"
1888 fi
1889 elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then
1890 fix_xml "${VENDOR_REPO_FILE}"
Steve Kondik5bd66602016-07-15 10:39:58 -07001891 fi
Arian5f98d792021-09-09 15:24:25 +02001892 # Now run user-supplied fixup function
1893 blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}"
1894 local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
Steve Kondik5bd66602016-07-15 10:39:58 -07001895
Arian5f98d792021-09-09 15:24:25 +02001896 if [ -f "${VENDOR_REPO_FILE}" ]; then
1897 local DIR=$(dirname "${VENDOR_REPO_FILE}")
1898 local TYPE="${DIR##*/}"
Michael Bestasbda30202020-12-28 04:44:52 +02001899 if [ "$TYPE" = "bin" ]; then
Arian5f98d792021-09-09 15:24:25 +02001900 chmod 755 "${VENDOR_REPO_FILE}"
1901 else
1902 chmod 644 "${VENDOR_REPO_FILE}"
1903 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001904 fi
Steve Kondik5bd66602016-07-15 10:39:58 -07001905
Arian5f98d792021-09-09 15:24:25 +02001906 if [ "${KANG}" = true ]; then
1907 print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}"
1908 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001909
Arian5f98d792021-09-09 15:24:25 +02001910 # Check and print whether the fixup pipeline actually did anything.
1911 # This isn't done right after the fixup pipeline because we want this print
1912 # to come after print_spec above, when in kang mode.
1913 if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then
1914 printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}"
1915 # Now sanity-check the spec for this blob.
1916 if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then
1917 colored_echo yellow "WARNING: The ${BLOB_DISPLAY_NAME} file was fixed up, but it is pinned."
1918 colored_echo yellow "This is a mistake and you want to either remove the hash completely, or add an extra one."
1919 fi
Vladimir Olteande985fe2019-01-17 03:07:34 +02001920 fi
Vladimir Olteana7d20492019-01-17 03:05:52 +02001921 fi
1922
Steve Kondik5bd66602016-07-15 10:39:58 -07001923 done
1924
1925 # Don't allow failing
1926 set -e
1927}
1928
1929#
Rashed Abdel-Tawab5b97a982019-09-29 01:19:57 -04001930# extract2:
1931#
1932# Positional parameters:
1933# $1: file containing the list of items to extract (aka proprietary-files.txt)
1934#
1935# Non-positional parameters (coming after $2):
1936# --section: selects the portion to parse and extracts from proprietary-files.txt
1937# --kang: if present, this option will activate the printing of hashes for the
1938# extracted blobs. Useful with --section for subsequent pinning of
1939# blobs taken from other origins.
1940#
1941function extract2() {
1942 # Consume positional parameters
1943 local PROPRIETARY_FILES_TXT="$1"; shift
1944 local SECTION=""
1945 local KANG=false
1946
1947 # Consume optional, non-positional parameters
1948 while [ "$#" -gt 0 ]; do
1949 case "$1" in
1950 --adb)
1951 ADB=true
1952 ;;
1953 --system)
1954 SYSTEM_SRC="$2"; shift
1955 ;;
1956 --vendor)
1957 VENDOR_SRC="$2"; shift
1958 ;;
1959 --odm)
1960 ODM_SRC="$2"; shift
1961 ;;
1962 --product)
1963 PRODUCT_SRC="$2"; shift
1964 ;;
1965 -s|--section)
1966 SECTION="$2"; shift
1967 ;;
1968 -k|--kang)
1969 KANG=true
1970 DISABLE_PINNING=1
1971 ;;
1972 esac
1973 shift
1974 done
1975
1976 if [ -z "$ADB" ] || [ -z "$SYSTEM_SRC" && -z "$VENDOR_SRC" && -z "$ODM_SRC" && -z "$PRODUCT_SRC" ]; then
1977 echo "No sources set! You must select --adb or pass paths to partition dumps."
1978 exit 1
1979 fi
1980
1981 if [ -z "$OUTDIR" ]; then
1982 echo "Output dir not set!"
1983 exit 1
1984 fi
1985
1986 parse_file_list "${PROPRIETARY_FILES_TXT}" "${SECTION}"
1987
1988 # Allow failing, so we can try $DEST and/or $FILE
1989 set +e
1990
1991 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} ${PRODUCT_PACKAGES_LIST[@]} )
1992 local HASHLIST=( ${PRODUCT_COPY_FILES_HASHES[@]} ${PRODUCT_PACKAGES_HASHES[@]} )
1993 local FIXUP_HASHLIST=( ${PRODUCT_COPY_FILES_FIXUP_HASHES[@]} ${PRODUCT_PACKAGES_FIXUP_HASHES[@]} )
1994 local PRODUCT_COPY_FILES_COUNT=${#PRODUCT_COPY_FILES_LIST[@]}
1995 local COUNT=${#FILELIST[@]}
1996 local OUTPUT_ROOT="$OMNI_ROOT"/"$OUTDIR"/proprietary
Chirayu Desai5da0bf82022-10-19 02:58:42 +05301997 local OUTPUT_TMP="$EXTRACT_TMP_DIR"/"$OUTDIR"/proprietary
Rashed Abdel-Tawab5b97a982019-09-29 01:19:57 -04001998
1999 if [ "$ADB" = true ]; then
2000 init_adb_connection
2001 fi
2002
2003 if [ "$VENDOR_STATE" -eq "0" ]; then
2004 echo "Cleaning output directory ($OUTPUT_ROOT).."
2005 rm -rf "${OUTPUT_TMP:?}"
2006 mkdir -p "${OUTPUT_TMP:?}"
2007 if [ -d "$OUTPUT_ROOT" ]; then
2008 mv "${OUTPUT_ROOT:?}/"* "${OUTPUT_TMP:?}/"
2009 fi
2010 VENDOR_STATE=1
2011 fi
2012
2013 echo "Extracting ${COUNT} files in ${PROPRIETARY_FILES_TXT} from ${SRC}:"
2014
2015 for (( i=1; i<COUNT+1; i++ )); do
2016
2017 local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}")
2018 local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}")
2019 local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}")
2020 local OUTPUT_DIR=
2021 local TMP_DIR=
2022 local SRC_FILE=
2023 local DST_FILE=
2024 local IS_PRODUCT_PACKAGE=false
2025
2026 # Note: this relies on the fact that the ${FILELIST[@]} array
2027 # contains first ${PRODUCT_COPY_FILES_LIST[@]}, then ${PRODUCT_PACKAGES_LIST[@]}.
2028 if [ "${i}" -gt "${PRODUCT_COPY_FILES_COUNT}" ]; then
2029 IS_PRODUCT_PACKAGE=true
2030 fi
2031
2032 if [ "${SPEC_ARGS}" = "rootfs" ]; then
2033 OUTPUT_DIR="${OUTPUT_ROOT}/rootfs"
2034 TMP_DIR="${OUTPUT_TMP}/rootfs"
2035 else
2036 OUTPUT_DIR="${OUTPUT_ROOT}"
2037 TMP_DIR="${OUTPUT_TMP}"
2038 fi
2039 SRC_FILE="${SPEC_SRC_FILE}"
2040 DST_FILE="${SPEC_DST_FILE}"
2041
2042 local VENDOR_REPO_FILE="$OUTPUT_DIR/${DST_FILE}"
2043 local BLOB_DISPLAY_NAME="${DST_FILE}"
2044 mkdir -p $(dirname "${VENDOR_REPO_FILE}")
2045
2046 # Check pinned files
2047 local HASH="$(echo ${HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
2048 local FIXUP_HASH="$(echo ${FIXUP_HASHLIST[$i-1]} | awk '{ print tolower($0); }')"
2049 local KEEP=""
2050 if [ "$DISABLE_PINNING" != "1" ] && [ "$HASH" != "x" ]; then
2051 if [ -f "${VENDOR_REPO_FILE}" ]; then
2052 local PINNED="${VENDOR_REPO_FILE}"
2053 else
2054 local PINNED="${TMP_DIR}${DST_FILE}"
2055 fi
2056 if [ -f "$PINNED" ]; then
2057 local TMP_HASH=$(get_hash "${PINNED}")
2058 if [ "${TMP_HASH}" = "${HASH}" ] || [ "${TMP_HASH}" = "${FIXUP_HASH}" ]; then
2059 KEEP="1"
2060 if [ ! -f "${VENDOR_REPO_FILE}" ]; then
2061 cp -p "$PINNED" "${VENDOR_REPO_FILE}"
2062 fi
2063 fi
2064 fi
2065 fi
2066
2067 if [ "${KANG}" = false ]; then
2068 printf ' - %s\n' "${BLOB_DISPLAY_NAME}"
2069 fi
2070
2071 if [ "$KEEP" = "1" ]; then
2072 printf ' + keeping pinned file with hash %s\n' "${HASH}"
2073 else
2074 FOUND=false
2075 PARTITION_SOURCE_DIR=
2076 # Try Lineage target first.
2077 for CANDIDATE in "${DST_FILE}" "${SRC_FILE}"; do
2078 PARTITION=$(echo "$CANDIDATE" | cut -d/ -f1)
2079 if [ "$PARTITION" = "system" ]; then
2080 PARTITION_SOURCE_DIR="$SYSTEM_SRC"
2081 elif [ "$PARTITION" = "vendor" ]; then
2082 PARTITION_SOURCE_DIR="$VENDOR_SRC"
2083 elif [ "$PARTITION" = "product" ]; then
2084 PARTITION_SOURCE_DIR="$PRODUCT_SRC"
2085 elif [ "$PARTITION" = "odm" ]; then
2086 PARTITION_SOURCE_DIR="$ODM_SRC"
2087 fi
2088 CANDIDATE_RELATIVE_NAME=$(echo "$CANDIDATE" | cut -d/ -f2-)
2089 get_file ${CANDIDATE_RELATIVE_NAME} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && {
2090 FOUND=true
2091 break
2092 }
2093 # Search with the full system/ prefix if the file was not found on the system partition
2094 # because we may be searching in a mounted system-as-root system.img
2095 if [[ "${FOUND}" = false && "$PARTITION" = "system" ]]; then
2096 get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${PARTITION_SOURCE_DIR} && {
2097 FOUND=true
2098 break
2099 }
2100 fi
2101 done
2102
2103 if [ -z "${PARTITION_SOURCE_DIR}" ]; then
2104 echo "$CANDIDATE has no preceeding partition path. Prepend system/, vendor/, product/, or odm/ to this entry."
2105 fi
2106
2107 if [ "${FOUND}" = false ]; then
2108 printf ' !! %s: file not found in source\n' "${BLOB_DISPLAY_NAME}"
2109 continue
2110 fi
2111 fi
2112
2113 # Blob fixup pipeline has 2 parts: one that is fixed and
2114 # one that is user-configurable
2115 local PRE_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
2116 # Deodex apk|jar if that's the case
2117 if [[ "$FULLY_DEODEXED" -ne "1" && "${VENDOR_REPO_FILE}" =~ .(apk|jar)$ ]]; then
2118 oat2dex "${VENDOR_REPO_FILE}" "${SRC_FILE}" "${SYSTEM_SRC}"
Chirayu Desai5da0bf82022-10-19 02:58:42 +05302119 if [ -f "$EXTRACT_TMP_DIR/classes.dex" ]; then
2120 zip -gjq "${VENDOR_REPO_FILE}" "$EXTRACT_TMP_DIR/classes"*
2121 rm "$EXTRACT_TMP_DIR/classes"*
Rashed Abdel-Tawab5b97a982019-09-29 01:19:57 -04002122 printf ' (updated %s from odex files)\n' "${SRC_FILE}"
2123 fi
2124 elif [[ "${VENDOR_REPO_FILE}" =~ .xml$ ]]; then
2125 fix_xml "${VENDOR_REPO_FILE}"
2126 fi
2127 # Now run user-supplied fixup function
2128 blob_fixup "${BLOB_DISPLAY_NAME}" "${VENDOR_REPO_FILE}"
2129 local POST_FIXUP_HASH=$(get_hash ${VENDOR_REPO_FILE})
2130
2131 if [ -f "${VENDOR_REPO_FILE}" ]; then
2132 local DIR=$(dirname "${VENDOR_REPO_FILE}")
2133 local TYPE="${DIR##*/}"
2134 if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then
2135 chmod 755 "${VENDOR_REPO_FILE}"
2136 else
2137 chmod 644 "${VENDOR_REPO_FILE}"
2138 fi
2139 fi
2140
2141 if [ "${KANG}" = true ]; then
2142 print_spec "${IS_PRODUCT_PACKAGE}" "${SPEC_SRC_FILE}" "${SPEC_DST_FILE}" "${SPEC_ARGS}" "${PRE_FIXUP_HASH}" "${POST_FIXUP_HASH}"
2143 fi
2144
2145 # Check and print whether the fixup pipeline actually did anything.
2146 # This isn't done right after the fixup pipeline because we want this print
2147 # to come after print_spec above, when in kang mode.
2148 if [ "${PRE_FIXUP_HASH}" != "${POST_FIXUP_HASH}" ]; then
2149 printf " + Fixed up %s\n" "${BLOB_DISPLAY_NAME}"
2150 # Now sanity-check the spec for this blob.
2151 if [ "${KANG}" = false ] && [ "${FIXUP_HASH}" = "x" ] && [ "${HASH}" != "x" ]; then
2152 printf "WARNING: The %s file was fixed up, but it is pinned.\n" ${BLOB_DISPLAY_NAME}
2153 printf "This is a mistake and you want to either remove the hash completely, or add an extra one.\n"
2154 fi
2155 fi
2156
2157 done
2158
2159 # Don't allow failing
2160 set -e
2161}
2162
2163#
Michael Bestasf3c59082023-11-30 20:26:02 +02002164# To be overridden by device-level extract-files.sh
2165#
2166function prepare_firmware() {
2167 :
2168}
2169
2170#
Steve Kondik5bd66602016-07-15 10:39:58 -07002171# extract_firmware:
2172#
2173# $1: file containing the list of items to extract
2174# $2: path to extracted radio folder
2175#
2176function extract_firmware() {
2177 if [ -z "$OUTDIR" ]; then
2178 echo "Output dir not set!"
2179 exit 1
2180 fi
2181
2182 parse_file_list "$1"
2183
2184 # Don't allow failing
2185 set -e
2186
2187 local FILELIST=( ${PRODUCT_COPY_FILES_LIST[@]} )
2188 local COUNT=${#FILELIST[@]}
2189 local SRC="$2"
theimpulson9a911af2019-08-14 03:25:12 +00002190 local OUTPUT_DIR="$OMNI_ROOT"/"$OUTDIR"/radio
Steve Kondik5bd66602016-07-15 10:39:58 -07002191
2192 if [ "$VENDOR_RADIO_STATE" -eq "0" ]; then
2193 echo "Cleaning firmware output directory ($OUTPUT_DIR).."
2194 rm -rf "${OUTPUT_DIR:?}/"*
2195 VENDOR_RADIO_STATE=1
2196 fi
2197
2198 echo "Extracting $COUNT files in $1 from $SRC:"
2199
Michael Bestasf3c59082023-11-30 20:26:02 +02002200 prepare_firmware
2201
Steve Kondik5bd66602016-07-15 10:39:58 -07002202 for (( i=1; i<COUNT+1; i++ )); do
Michael Bestasf62d4032022-02-22 19:06:41 +02002203 local SRC_FILE=$(src_file "${FILELIST[$i-1]}")
2204 local DST_FILE=$(target_file "${FILELIST[$i-1]}")
2205
2206 printf ' - %s \n' "radio/$DST_FILE"
Steve Kondik5bd66602016-07-15 10:39:58 -07002207
2208 if [ ! -d "$OUTPUT_DIR" ]; then
2209 mkdir -p "$OUTPUT_DIR"
2210 fi
Chirayu Desai10418682022-05-25 23:37:27 +05302211 if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then
2212 # Extract A/B OTA
2213 if [ -a "$DUMPDIR"/payload.bin ]; then
2214 python3 "$ANDROID_ROOT"/tools/extract-utils/extract_ota.py "$DUMPDIR"/payload.bin -o "$DUMPDIR" -p $(basename "${DST_FILE%.*}") 2>&1
2215 cp "$DUMPDIR/$(basename $DST_FILE)" "$OUTPUT_DIR/$DST_FILE"
2216 fi
Michael Bestased3cae92023-04-13 16:38:34 +03002217 else
Chirayu Desai10418682022-05-25 23:37:27 +05302218 if [ -f "$SRC/$SRC_FILE" ]; then
2219 cp "$SRC/$SRC_FILE" "$OUTPUT_DIR/$DST_FILE"
2220 else
2221 cp "$SRC/$DST_FILE" "$OUTPUT_DIR/$DST_FILE"
2222 fi
Michael Bestased3cae92023-04-13 16:38:34 +03002223 fi
Michael Bestasf62d4032022-02-22 19:06:41 +02002224 chmod 644 "$OUTPUT_DIR/$DST_FILE"
Steve Kondik5bd66602016-07-15 10:39:58 -07002225 done
2226}
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07002227
2228function extract_img_data() {
2229 local image_file="$1"
2230 local out_dir="$2"
Chirayu Desai5da0bf82022-10-19 02:58:42 +05302231 local logFile="$EXTRACT_TMP_DIR/debugfs.log"
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07002232
2233 if [ ! -d "$out_dir" ]; then
2234 mkdir -p "$out_dir"
2235 fi
2236
2237 if [[ "$HOST_OS" == "Darwin" ]]; then
2238 debugfs -R "rdump / \"$out_dir\"" "$image_file" &> "$logFile" || {
2239 echo "[-] Failed to extract data from '$image_file'"
2240 abort 1
2241 }
2242 else
2243 debugfs -R 'ls -p' "$image_file" 2>/dev/null | cut -d '/' -f6 | while read -r entry
2244 do
2245 debugfs -R "rdump \"$entry\" \"$out_dir\"" "$image_file" >> "$logFile" 2>&1 || {
2246 echo "[-] Failed to extract data from '$image_file'"
2247 abort 1
2248 }
2249 done
2250 fi
2251
2252 local symlink_err="rdump: Attempt to read block from filesystem resulted in short read while reading symlink"
2253 if grep -Fq "$symlink_err" "$logFile"; then
2254 echo "[-] Symlinks have not been properly processed from $image_file"
Michael Bestas1b570252021-12-02 21:05:36 +02002255 echo "[!] You might not have a compatible debugfs version"
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07002256 abort 1
2257 fi
2258}
2259
2260declare -ra VENDOR_SKIP_FILES=(
2261 "bin/toybox_vendor"
2262 "bin/toolbox"
2263 "bin/grep"
2264 "build.prop"
2265 "compatibility_matrix.xml"
2266 "default.prop"
2267 "etc/NOTICE.xml.gz"
2268 "etc/vintf/compatibility_matrix.xml"
2269 "etc/vintf/manifest.xml"
2270 "etc/wifi/wpa_supplicant.conf"
2271 "manifest.xml"
2272 "overlay/DisplayCutoutEmulationCorner/DisplayCutoutEmulationCornerOverlay.apk"
2273 "overlay/DisplayCutoutEmulationDouble/DisplayCutoutEmulationDoubleOverlay.apk"
2274 "overlay/DisplayCutoutEmulationTall/DisplayCutoutEmulationTallOverlay.apk"
2275 "overlay/DisplayCutoutNoCutout/NoCutoutOverlay.apk"
2276 "overlay/framework-res__auto_generated_rro.apk"
2277 "overlay/SysuiDarkTheme/SysuiDarkThemeOverlay.apk"
2278)
2279
2280function array_contains() {
2281 local element
2282 for element in "${@:2}"; do [[ "$element" == "$1" ]] && return 0; done
2283 return 1
2284}
2285
2286function generate_prop_list_from_image() {
2287 local image_file="$1"
Chirayu Desai5da0bf82022-10-19 02:58:42 +05302288 local image_dir="$EXTRACT_TMP_DIR/image-temp"
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07002289 local output_list="$2"
Chirayu Desai5da0bf82022-10-19 02:58:42 +05302290 local output_list_tmp="$EXTRACT_TMP_DIR/_proprietary-blobs.txt"
Michael Bestasca5d78a2021-12-02 20:58:40 +02002291 local -n skipped_files="$3"
Michael Bestasfc1a22e2023-06-11 17:45:46 +03002292 local component="$4"
2293 local partition="$component"
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07002294
Chirayu Desai203cc522021-12-04 01:18:45 +05302295 mkdir -p "$image_dir"
2296
LuK133707657db2023-11-30 18:11:51 +01002297 if [[ $(file -b "$image_file") == EROFS* ]]; then
2298 fsck.erofs --extract="$image_dir" "$image_file"
2299 elif [[ $(file -b "$image_file") == Linux* ]]; then
Chirayu Desai203cc522021-12-04 01:18:45 +05302300 extract_img_data "$image_file" "$image_dir"
2301 elif [[ $(file -b "$image_file") == Android* ]]; then
Chirayu Desai501ffd62022-03-17 06:27:33 +05302302 "$SIMG2IMG" "$image_file" "$image_dir"/"$(basename "$image_file").raw"
Chirayu Desai203cc522021-12-04 01:18:45 +05302303 extract_img_data "$image_dir"/"$(basename "$image_file").raw" "$image_dir"
2304 rm "$image_dir"/"$(basename "$image_file").raw"
2305 else
2306 echo "Unsupported "$image_file""
2307 fi
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07002308
Michael Bestasfc1a22e2023-06-11 17:45:46 +03002309 if [ -z "$component" ]; then
2310 partition="vendor"
2311 elif [[ "$component" == "carriersettings" ]]; then
2312 partition="product"
2313 fi
2314
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07002315 find "$image_dir" -not -type d | sed "s#^$image_dir/##" | while read -r FILE
2316 do
Michael Bestasfc1a22e2023-06-11 17:45:46 +03002317 if [[ "$component" == "carriersettings" ]] && ! prefix_match_file "etc/CarrierSettings" "$FILE" ; then
2318 continue
2319 fi
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07002320 # Skip VENDOR_SKIP_FILES since it will be re-generated at build time
2321 if array_contains "$FILE" "${VENDOR_SKIP_FILES[@]}"; then
2322 continue
2323 fi
2324 # Skip device defined skipped files since they will be re-generated at build time
Michael Bestasca5d78a2021-12-02 20:58:40 +02002325 if array_contains "$FILE" "${skipped_files[@]}"; then
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07002326 continue
2327 fi
Michael Bestasfc1a22e2023-06-11 17:45:46 +03002328 echo "$partition/$FILE" >> "$output_list_tmp"
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07002329 done
2330
2331 # Sort merged file with all lists
Michael Bestas1e6efb32021-11-15 19:28:56 +02002332 LC_ALL=C sort -u "$output_list_tmp" > "$output_list"
Rashed Abdel-Tawab841c6e82019-03-29 20:07:25 -07002333
2334 # Clean-up
2335 rm -f "$output_list_tmp"
2336}
Bruno Martins0f425f12021-04-10 14:57:32 +01002337
2338function colored_echo() {
2339 IFS=" "
2340 local color=$1;
2341 shift
2342 if ! [[ $color =~ '^[0-9]$' ]] ; then
2343 case $(echo $color | tr '[:upper:]' '[:lower:]') in
2344 black) color=0 ;;
2345 red) color=1 ;;
2346 green) color=2 ;;
2347 yellow) color=3 ;;
2348 blue) color=4 ;;
2349 magenta) color=5 ;;
2350 cyan) color=6 ;;
2351 white|*) color=7 ;; # white or invalid color
2352 esac
2353 fi
Bruno Martins5064db22021-06-21 14:47:40 +01002354 if [ -t 1 ] ; then tput setaf $color; fi
Bruno Martins0f425f12021-04-10 14:57:32 +01002355 printf '%s\n' "$*"
Bruno Martins5064db22021-06-21 14:47:40 +01002356 if [ -t 1 ] ; then tput sgr0; fi
Bruno Martins0f425f12021-04-10 14:57:32 +01002357}