summaryrefslogtreecommitdiff
path: root/build_utils.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build_utils.sh')
-rw-r--r--build_utils.sh98
1 files changed, 93 insertions, 5 deletions
diff --git a/build_utils.sh b/build_utils.sh
index aac2cb7d..f8d2aa03 100644
--- a/build_utils.sh
+++ b/build_utils.sh
@@ -53,14 +53,27 @@ function rel_path2() {
# $1 directory of kernel modules ($1/lib/modules/x.y)
# $2 flags to pass to depmod
# $3 kernel version
+# $4 Optional: File with list of modules to run depmod on.
+# If left empty, depmod will run on all modules
+# under $1/lib/modules/x.y
function run_depmod() {
(
local ramdisk_dir=$1
local depmod_stdout
local depmod_stderr=$(mktemp)
+ local version=$3
+ local modules_list_file=$4
+ local modules_list=""
+
+ if [[ -n "${modules_list_file}" ]]; then
+ while read -r line; do
+ # depmod expects absolute paths for module files
+ modules_list+="${ramdisk_dir}/lib/modules/${version}/${line} "
+ done <${modules_list_file}
+ fi
cd ${ramdisk_dir}
- if ! depmod_stdout="$(depmod $2 -F ${DIST_DIR}/System.map -b . $3 \
+ if ! depmod_stdout="$(depmod $2 -F ${DIST_DIR}/System.map -b . ${version} ${modules_list} \
2>${depmod_stderr})"; then
echo "$depmod_stdout"
cat ${depmod_stderr} >&2
@@ -78,12 +91,60 @@ function run_depmod() {
)
}
+# $1 MODULES_LIST <File that contains the list of modules that need to be
+# loaded during first-stage init.>
+# $2 ADDITIONAL_MODULES_LIST <File that contains the list of additional modules
+# that need to be loaded from the initramfs.>
+# $3 MODULES_ORDER <File that contains the list of all modules in the order in which
+# they appear in Makefiles.>
+# $4 MODULES_OUTPUT_FILENAME <The name of the output modules.order file>
+function create_additional_modules_order() {
+ local modules_list_file=$1
+ local additional_modules_file=$2
+ local modules_order_file=$3
+ local modules_out_filename=$4
+ local tmp_all_modules_list_file
+
+ if [[ -f "${ROOT_DIR}/${additional_modules_file}" ]]; then
+ additional_modules_file="${ROOT_DIR}/${additional_modules_file}"
+ elif [[ "${additional_modules_file}" != /* ]]; then
+ echo "modules recovery list must be an absolute path or relative to ${ROOT_DIR}: ${additional_modules_file}" >&2
+ exit 1
+ elif [[ ! -f "${additional_modules_file}" ]]; then
+ echo "Failed to find modules list: ${additional_modules_file}" >&2
+ exit 1
+ fi
+
+ tmp_all_modules_list_file=$(mktemp)
+
+ cp ${modules_list_file} ${tmp_all_modules_list_file}
+ # Append to the first stage init modules
+ grep -v "^\#" ${additional_modules_file} >> ${tmp_all_modules_list_file}
+ grep -w -f ${tmp_all_modules_list_file} ${modules_order_file} > ${modules_out_filename}
+
+ rm ${tmp_all_modules_list_file}
+}
+
# $1 MODULES_LIST, <File contains the list of modules that should go in the ramdisk>
# $2 MODULES_STAGING_DIR <The directory to look for all the compiled modules>
# $3 IMAGE_STAGING_DIR <The destination directory in which MODULES_LIST is
# expected, and it's corresponding modules.* files>
# $4 MODULES_BLOCKLIST, <File contains the list of modules to prevent from loading>
-# $5 flags to pass to depmod
+# $5 MODULES_RECOVERY_LIST <File contains the list of modules that should go in
+# the ramdisk but should only be loaded when booting
+# into recovery.
+#
+# This parameter is optional, and if not used, should
+# be passed as an empty string to ensure that the depmod
+# flags are assigned correctly.>
+# $6 MODULES_CHARGER_LIST <File contains the list of modules that should go in
+# the ramdisk but should only be loaded when booting
+# into charger mode.
+#
+# This parameter is optional, and if not used, should
+# be passed as an empty string to ensure that the
+# depmod flags are assigned correctly.>
+# $7 flags to pass to depmod
function create_modules_staging() {
local modules_list_file=$1
local src_dir=$(echo $2/lib/modules/*)
@@ -91,7 +152,9 @@ function create_modules_staging() {
local dest_dir=$3/lib/modules/${version}
local dest_stage=$3
local modules_blocklist_file=$4
- local depmod_flags=$5
+ local modules_recoverylist_file=$5
+ local modules_chargerlist_file=$6
+ local depmod_flags=$7
rm -rf ${dest_dir}
mkdir -p ${dest_dir}/kernel
@@ -166,6 +229,14 @@ function create_modules_staging() {
# grep the modules.order for any KOs in the modules list
cp ${dest_dir}/modules.order ${old_modules_list}
! grep -w -f ${modules_list_filter} ${old_modules_list} > ${dest_dir}/modules.order
+ if [[ -n "${modules_recoverylist_file}" ]]; then
+ create_additional_modules_order "${modules_list_filter}" "${modules_recoverylist_file}" \
+ "${old_modules_list}" "${dest_dir}/modules.order.recovery"
+ fi
+ if [[ -n "${modules_chargerlist_file}" ]]; then
+ create_additional_modules_order "${modules_list_filter}" "${modules_chargerlist_file}" \
+ "${old_modules_list}" "${dest_dir}/modules.order.charger"
+ fi
rm -f ${modules_list_filter} ${old_modules_list}
fi
@@ -196,11 +267,27 @@ function create_modules_staging() {
# Trim modules from tree that aren't mentioned in modules.order
(
cd ${dest_dir}
- find * -type f -name "*.ko" | (grep -v -w -f modules.order -f $used_blocklist_modules - || true) | xargs -r rm
+ local grep_flags="-v -w -f modules.order -f ${used_blocklist_modules} "
+ [[ -f modules.order.recovery ]] && grep_flags+="-f modules.order.recovery "
+ [[ -f modules.order.charger ]] && grep_flags+="-f modules.order.charger "
+ find * -type f -name "*.ko" | (grep ${grep_flags} - || true) | xargs -r rm
)
rm $used_blocklist_modules
fi
+ # Run depmod to ensure that dependencies between all modules loaded during
+ # first stage init when booting into any other mode besides normal boot can be
+ # satisfied.
+ if [[ -f ${dest_dir}/modules.order.recovery ]]; then
+ run_depmod ${dest_stage} "${depmod_flags}" "${version}" "${dest_dir}/modules.order.recovery"
+ cp ${dest_dir}/modules.order.recovery ${dest_dir}/modules.load.recovery
+ fi
+
+ if [[ -f ${dest_dir}/modules.order.charger ]]; then
+ run_depmod ${dest_stage} "${depmod_flags}" "${version}" "${dest_dir}/modules.order.charger"
+ cp ${dest_dir}/modules.order.charger ${dest_dir}/modules.load.charger
+ fi
+
# Re-run depmod to detect any dependencies between in-kernel and external
# modules. Then, create modules.order based on all the modules compiled.
run_depmod ${dest_stage} "${depmod_flags}" "${version}"
@@ -213,7 +300,8 @@ function build_system_dlkm() {
rm -rf ${SYSTEM_DLKM_STAGING_DIR}
create_modules_staging "${SYSTEM_DLKM_MODULES_LIST:-${MODULES_LIST}}" "${MODULES_STAGING_DIR}" \
- ${SYSTEM_DLKM_STAGING_DIR} "${SYSTEM_DLKM_MODULES_BLOCKLIST:-${MODULES_BLOCKLIST}}" "-e"
+ ${SYSTEM_DLKM_STAGING_DIR} "${SYSTEM_DLKM_MODULES_BLOCKLIST:-${MODULES_BLOCKLIST}}" \
+ "${MODULES_RECOVERY_LIST:-""}" "${MODULES_CHARGER_LIST:-""}" "-e"
local system_dlkm_root_dir=$(echo ${SYSTEM_DLKM_STAGING_DIR}/lib/modules/*)
cp ${system_dlkm_root_dir}/modules.load ${DIST_DIR}/system_dlkm.modules.load