summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-05-16 02:32:20 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-05-16 02:32:20 +0000
commitc7739e71fc82caaf3550c8615830a51fbdca6f78 (patch)
tree56b32f51ce1eedf483a30b22a65d8f20430eca34
parent30f2b81b4b14323e26ee49c357668e22d8a41ed6 (diff)
parentb9ba4b67e90b85d01eb2f9cebf62830a73574cd9 (diff)
downloadbuild-android-gs-pantah-5.10-u-beta3.tar.gz
Snap for 10088735 from b9ba4b67e90b85d01eb2f9cebf62830a73574cd9 to android13-gs-pixel-5.10-releaseandroid-u-beta-3_r0.5android-u-beta-3_r0.4android-13.0.0_r0.94android-gs-pantah-5.10-u-beta3android-gs-lynx-5.10-u-beta3
Change-Id: I3ed327905962447fdafebe797d4b5597eeffc603
-rwxr-xr-xbuild.sh23
-rw-r--r--build_utils.sh98
-rw-r--r--kleaf/impl/image/image_utils.bzl25
-rw-r--r--kleaf/impl/image/initramfs.bzl18
-rw-r--r--kleaf/impl/image/kernel_images.bzl3
5 files changed, 141 insertions, 26 deletions
diff --git a/build.sh b/build.sh
index 5b7b2e4..f67cbc8 100755
--- a/build.sh
+++ b/build.sh
@@ -230,6 +230,14 @@
# - MODULES_LIST=<file to list of modules> list of modules to use for
# vendor_boot.modules.load. If this property is not set, then the default
# modules.load is used.
+# - MODULES_RECOVERY_LIST=<file to list of modules> list of modules to load
+# in addition to the modules defined in MODULES_LIST during first stage
+# init when booting into recovery. If MODULES_LIST is not specified, this
+# variable is ignored. Defining this variable is optional.
+# - MODULES_CHARGER_LIST=<file to list of modules> list of modules to load
+# in addition to the modules defined in MODULES_LIST during first stage
+# init when booting into charger mode. If MODULES_LIST is not specified, this
+# variable is ignored. Defining this variable is optional.
# - TRIM_UNUSED_MODULES. If set, then modules not mentioned in
# modules.load are removed from initramfs. If MODULES_LIST is unset, then
# having this variable set effectively becomes a no-op.
@@ -1013,15 +1021,20 @@ if [ -n "${MODULES}" ]; then
echo " Creating initramfs"
rm -rf ${INITRAMFS_STAGING_DIR}
create_modules_staging "${MODULES_LIST}" ${MODULES_STAGING_DIR} \
- ${INITRAMFS_STAGING_DIR} "${MODULES_BLOCKLIST}" "-e"
-
+ ${INITRAMFS_STAGING_DIR} "${MODULES_BLOCKLIST}" "${MODULES_RECOVERY_LIST:-""}" \
+ "${MODULES_CHARGER_LIST:-""}" "-e"
MODULES_ROOT_DIR=$(echo ${INITRAMFS_STAGING_DIR}/lib/modules/*)
- cp ${MODULES_ROOT_DIR}/modules.load ${DIST_DIR}/modules.load
if [ -n "${BUILD_VENDOR_BOOT_IMG}" ]; then
- cp ${MODULES_ROOT_DIR}/modules.load ${DIST_DIR}/vendor_boot.modules.load
+ VENDOR_BOOT_NAME="vendor_boot"
elif [ -n "${BUILD_VENDOR_KERNEL_BOOT}" ]; then
- cp ${MODULES_ROOT_DIR}/modules.load ${DIST_DIR}/vendor_kernel_boot.modules.load
+ VENDOR_BOOT_NAME="vendor_kernel_boot"
fi
+ MODULES_LOAD_FILES=( "modules.load" "modules.load.recovery" "modules.load.charger" )
+ for file in "${MODULES_LOAD_FILES[@]}"; do
+ [ -f ${MODULES_ROOT_DIR}/${file} ] && cp ${MODULES_ROOT_DIR}/${file} ${DIST_DIR}/${file}
+ [ -f ${MODULES_ROOT_DIR}/${file} -a -n "${VENDOR_BOOT_NAME}" ] && \
+ cp ${MODULES_ROOT_DIR}/${file} ${DIST_DIR}/${VENDOR_BOOT_NAME}.${file}
+ done
echo "${MODULES_OPTIONS}" > ${MODULES_ROOT_DIR}/modules.options
mkbootfs "${INITRAMFS_STAGING_DIR}" >"${MODULES_STAGING_DIR}/initramfs.cpio"
diff --git a/build_utils.sh b/build_utils.sh
index aac2cb7..f8d2aa0 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
diff --git a/kleaf/impl/image/image_utils.bzl b/kleaf/impl/image/image_utils.bzl
index 967c424..331163b 100644
--- a/kleaf/impl/image/image_utils.bzl
+++ b/kleaf/impl/image/image_utils.bzl
@@ -11,6 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+"""
+Common utilities for working with kernel images.
+"""
load("//build/kernel/kleaf:directory_with_structure.bzl", dws = "directory_with_structure")
load(
@@ -35,14 +38,17 @@ def _build_modules_image_impl_common(
"""Command implementation for building images that directly contain modules.
Args:
- ctx: ctx
- what: what is being built, for logging
+ ctx: ctx.
+ what: what is being built, for logging.
outputs: list of `ctx.actions.declare_file`
- build_command: the command to build `outputs` and `implicit_outputs`
- modules_staging_dir: a staging directory for module installation
- implicit_outputs: like `outputs`, but not installed to `DIST_DIR` (not returned in
- `DefaultInfo`)
- restore_modules_install: If `True`, restore `ctx.attr.kernel_modules_install`. Default is `True`.
+ build_command: the command to build `outputs` and `implicit_outputs`.
+ modules_staging_dir: a staging directory for module installation.
+ restore_modules_install: If `True`, restore `ctx.attr.kernel_modules_install`.
+ Default is `True`.
+ implicit_outputs: like `outputs`, but not installed to `DIST_DIR` (not
+ returned in `DefaultInfo`).
+ additional_inputs: Additional files to be included.
+ mnemonic: string to reference the build operation.
"""
if restore_modules_install == None:
@@ -57,15 +63,14 @@ def _build_modules_image_impl_common(
what = "{}: outs of dependent kernel_build {}".format(ctx.label, kernel_build),
)
+ modules_install_staging_dws = None
if restore_modules_install:
modules_install_staging_dws = ctx.attr.kernel_modules_install[KernelModuleInfo].modules_staging_dws
inputs = []
if additional_inputs != None:
inputs += additional_inputs
- inputs += [
- system_map,
- ]
+ inputs.append(system_map)
if restore_modules_install:
inputs += dws.files(modules_install_staging_dws)
inputs += ctx.files.deps
diff --git a/kleaf/impl/image/initramfs.bzl b/kleaf/impl/image/initramfs.bzl
index 40c78a2..a63759c 100644
--- a/kleaf/impl/image/initramfs.bzl
+++ b/kleaf/impl/image/initramfs.bzl
@@ -11,14 +11,19 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+"""
+Build initramfs.
+"""
-load(":debug.bzl", "debug")
load(":image/image_utils.bzl", "image_utils")
-InitramfsInfo = provider(fields = {
- "initramfs_img": "Output image",
- "initramfs_staging_archive": "Archive of initramfs staging directory",
-})
+InitramfsInfo = provider(
+ doc = "Provides information about initramfs outputs.",
+ fields = {
+ "initramfs_img": "Output image",
+ "initramfs_staging_archive": "Archive of initramfs staging directory",
+ },
+)
def _initramfs_impl(ctx):
initramfs_img = ctx.actions.declare_file("{}/initramfs.img".format(ctx.label.name))
@@ -61,7 +66,8 @@ def _initramfs_impl(ctx):
mkdir -p {initramfs_staging_dir}
# Build initramfs
create_modules_staging "${{MODULES_LIST}}" {modules_staging_dir} \
- {initramfs_staging_dir} "${{MODULES_BLOCKLIST}}" "-e"
+ {initramfs_staging_dir} "${{MODULES_BLOCKLIST}}" \
+ "${{MODULES_RECOVERY_LIST:-""}}" "${{MODULES_CHARGER_LIST:-""}}" "-e"
modules_root_dir=$(readlink -e {initramfs_staging_dir}/lib/modules/*) || exit 1
cp ${{modules_root_dir}}/modules.load {modules_load}
{cp_vendor_boot_modules_load_cmd}
diff --git a/kleaf/impl/image/kernel_images.bzl b/kleaf/impl/image/kernel_images.bzl
index 6e305b2..5010be6 100644
--- a/kleaf/impl/image/kernel_images.bzl
+++ b/kleaf/impl/image/kernel_images.bzl
@@ -11,6 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+"""
+Build multiple kernel images.
+"""
load(":image/boot_images.bzl", "boot_images")
load(":image/dtbo.bzl", "dtbo")