Skip to content
Snippets Groups Projects
Commit b0fedfdc authored by Ramji Jiyani's avatar Ramji Jiyani Committed by Treehugger Robot
Browse files

kleaf: system_dlkm build images for list of fs


Introduces system_dlkm_fs_types list attribute for the
kernel_images rule to build the system_dlkm partition
images for all filesystem provided in the list.

Deprecates the system_dlkm_fs_type but gives it priority
for backward compitability resons.

Behavior based on values of system_dlkm_fs_type &
system_dlkm_fs_types:

    Both specified: Fail with deprecation message
    Both not specified: system_dlkm.img with ext4
	This is same as current default behavior when
	system_dlkm_fs_type is not specified.
    system_dlkm_fs_type="fs": system_dlkm.img with given fs
	This is same as current behavior.
    system_dlkm_fs_types=[list_of_filesystems]: system_dlkm.fs.img
	for each file system type in list_of_filesystems

Bug: 297407875
Test: TH, Manual with all permutations & combinations
Change-Id: Ie8ee880dbbc41576603a1ab1b56f0307a6ab2e90
Signed-off-by: default avatarRamji Jiyani <ramjiyani@google.com>
parent ba855a1d
No related branches found
No related tags found
No related merge requests found
......@@ -248,8 +248,12 @@ function build_system_dlkm() {
done
fi
if [ -z "${SYSTEM_DLKM_IMAGE_NAME}" ]; then
SYSTEM_DLKM_IMAGE_NAME="system_dlkm.img"
fi
build_image "${SYSTEM_DLKM_STAGING_DIR}" "${system_dlkm_props_file}" \
"${DIST_DIR}/system_dlkm.img" /dev/null
"${DIST_DIR}/${SYSTEM_DLKM_IMAGE_NAME}" /dev/null
if [ -z "${SYSTEM_DLKM_PROPS}" ]; then
rm ${system_dlkm_props_file}
......@@ -260,7 +264,7 @@ function build_system_dlkm() {
avbtool add_hashtree_footer \
--partition_name system_dlkm \
--hash_algorithm sha256 \
--image "${DIST_DIR}/system_dlkm.img"
--image "${DIST_DIR}/${SYSTEM_DLKM_IMAGE_NAME}"
# Archive system_dlkm_staging_dir
tar -czf "${DIST_DIR}/system_dlkm_staging_archive.tar.gz" -C "${SYSTEM_DLKM_STAGING_DIR}" .
......
......@@ -22,7 +22,7 @@ load(
"GKI_ARTIFACTS_AARCH64_OUTS",
"MODULES_STAGING_ARCHIVE",
"MODULE_OUTS_FILE_SUFFIX",
"SYSTEM_DLKM_OUTS",
"SYSTEM_DLKM_COMMON_OUTS",
"TOOLCHAIN_VERSION_FILENAME",
)
......@@ -70,7 +70,8 @@ GKI_DOWNLOAD_CONFIGS = [
},
{
"target_suffix": "images",
"outs": SYSTEM_DLKM_OUTS,
# TODO(b/297934577): Update GKI prebuilts to download system_dlkm.<fs>.img
"outs": SYSTEM_DLKM_COMMON_OUTS,
},
{
"target_suffix": "toolchain_version",
......
......@@ -588,7 +588,7 @@ See [documentation for all rules].
## SYSTEM\_DLKM\_FS\_TYPE
```python
kernel_images(system_dlkm_fs_type=[ext4, erofs])
kernel_images(system_dlkm_fs_types=["ext4", "erofs"])
```
See [documentation for all rules].
......
......@@ -42,8 +42,7 @@ GKI_ARTIFACTS_AARCH64_OUTS = [
for e in DEFAULT_IMAGES
]
SYSTEM_DLKM_OUTS = [
"system_dlkm.img",
SYSTEM_DLKM_COMMON_OUTS = [
"system_dlkm_staging_archive.tar.gz",
"system_dlkm.modules.load",
"system_dlkm.modules.blocklist",
......
......@@ -122,6 +122,7 @@ def _build_modules_image_impl_common(
"vendor_dlkm_modules_blocklist",
"vendor_dlkm_props",
"system_dlkm_fs_type",
"system_dlkm_fs_types",
"system_dlkm_modules_list",
"system_dlkm_modules_blocklist",
"system_dlkm_props",
......
......@@ -45,6 +45,7 @@ def kernel_images(
modules_options = None,
vendor_ramdisk_binaries = None,
system_dlkm_fs_type = None,
system_dlkm_fs_types = None,
system_dlkm_modules_list = None,
system_dlkm_modules_blocklist = None,
system_dlkm_props = None,
......@@ -193,7 +194,15 @@ def kernel_images(
```
This corresponds to `MODULES_OPTIONS` in `build.config` for `build.sh`.
system_dlkm_fs_type: Supported filesystems for `system_dlkm.img` are `ext4` and `erofs`. Defaults to `ext4` if not specified.
system_dlkm_fs_type: Deprecated. Use `system_dlkm_fs_types` instead.
Supported filesystems for `system_dlkm` image are `ext4` and `erofs`.
Defaults to `ext4` if not specified.
system_dlkm_fs_types: List of file systems type for `system_dlkm` images.
Supported filesystems for `system_dlkm` image are `ext4` and `erofs`.
If not specified, builds `system_dlkm.img` with ext4 else builds
`system_dlkm.<fs>.img` for each file system type in the list.
system_dlkm_modules_list: location of an optional file
containing the list of kernel modules which shall be copied into a
system_dlkm partition image.
......@@ -356,9 +365,6 @@ def kernel_images(
all_rules.append(":{}_initramfs".format(name))
if build_system_dlkm:
if system_dlkm_fs_type == None:
system_dlkm_fs_type = "ext4"
system_dlkm_image(
name = "{}_system_dlkm_image".format(name),
# For GKI system_dlkm
......@@ -369,6 +375,7 @@ def kernel_images(
modules_list = modules_list,
modules_blocklist = modules_blocklist,
system_dlkm_fs_type = system_dlkm_fs_type,
system_dlkm_fs_types = system_dlkm_fs_types,
system_dlkm_modules_list = system_dlkm_modules_list,
system_dlkm_modules_blocklist = system_dlkm_modules_blocklist,
system_dlkm_props = system_dlkm_props,
......
......@@ -15,7 +15,7 @@
Build system_dlkm image for GKI modules.
"""
load("//build/kernel/kleaf/impl:constants.bzl", "SYSTEM_DLKM_OUTS")
load("//build/kernel/kleaf/impl:constants.bzl", "SYSTEM_DLKM_COMMON_OUTS")
load("//build/kernel/kleaf/impl:utils.bzl", "utils")
load(
":common_providers.bzl",
......@@ -31,14 +31,26 @@ load(
visibility("//build/kernel/kleaf/...")
def _system_dlkm_image_impl(ctx):
system_dlkm_img = ctx.actions.declare_file("{}/system_dlkm.img".format(ctx.label.name))
system_dlkm_modules_load = ctx.actions.declare_file("{}/{}".format(ctx.label.name, _MODULES_LOAD_NAME))
system_dlkm_staging_archive = ctx.actions.declare_file("{}/{}".format(ctx.label.name, _STAGING_ARCHIVE_NAME))
system_dlkm_modules_blocklist = ctx.actions.declare_file("{}/system_dlkm.modules.blocklist".format(ctx.label.name))
modules_staging_dir = system_dlkm_img.dirname + "/staging"
modules_staging_dir = system_dlkm_staging_archive.dirname + "/staging"
system_dlkm_staging_dir = modules_staging_dir + "/system_dlkm_staging"
system_dlkm_fs_type = ctx.attr.system_dlkm_fs_type
system_dlkm_fs_type = ctx.attr.system_dlkm_fs_type # str | None
system_dlkm_fs_types = ctx.attr.system_dlkm_fs_types # list[str]
if system_dlkm_fs_type and system_dlkm_fs_types:
fail("""{}: Both system_dlkm_fs_type="{}" and system_dlkm_fs_types={} are specified. system_dlkm_fs_type is deprecated, use system_dlkm_fs_types instead.""".format(ctx.label, system_dlkm_fs_type, system_dlkm_fs_types))
# Build system_dlkm.img with ext4 fs as default
if not system_dlkm_fs_type and not system_dlkm_fs_types:
system_dlkm_fs_type = "ext4"
# if system_dlkm_fs_type: Build system_dlkm.img with given fs type
if system_dlkm_fs_type:
system_dlkm_fs_types = [system_dlkm_fs_type]
additional_inputs = []
restore_modules_install = True
......@@ -88,46 +100,61 @@ def _system_dlkm_image_impl(ctx):
SYSTEM_DLKM_RE_SIGN=0
"""
command = """
{extract_staging_archive_cmd}
# Build system_dlkm.img
mkdir -p {system_dlkm_staging_dir}
(
MODULES_STAGING_DIR={modules_staging_dir}
SYSTEM_DLKM_FS_TYPE={system_dlkm_fs_type}
SYSTEM_DLKM_STAGING_DIR={system_dlkm_staging_dir}
{extra_flags_cmd}
build_system_dlkm
)
# Move output files into place
mv "${{DIST_DIR}}/system_dlkm.img" {system_dlkm_img}
mv "${{DIST_DIR}}/system_dlkm.modules.load" {system_dlkm_modules_load}
mv "${{DIST_DIR}}/system_dlkm_staging_archive.tar.gz" {system_dlkm_staging_archive}
if [ -f "${{DIST_DIR}}/system_dlkm.modules.blocklist" ]; then
mv "${{DIST_DIR}}/system_dlkm.modules.blocklist" {system_dlkm_modules_blocklist}
else
: > {system_dlkm_modules_blocklist}
fi
# Remove staging directories
rm -rf {system_dlkm_staging_dir}
""".format(
extract_staging_archive_cmd = extract_staging_archive_cmd,
extra_flags_cmd = extra_flags_cmd,
modules_staging_dir = modules_staging_dir,
system_dlkm_fs_type = system_dlkm_fs_type,
system_dlkm_staging_dir = system_dlkm_staging_dir,
system_dlkm_img = system_dlkm_img.path,
system_dlkm_modules_load = system_dlkm_modules_load.path,
system_dlkm_staging_archive = system_dlkm_staging_archive.path,
system_dlkm_modules_blocklist = system_dlkm_modules_blocklist.path,
)
command = ""
outputs = []
outputs_to_compare = []
for fs_type in system_dlkm_fs_types:
if system_dlkm_fs_type:
system_dlkm_img = ctx.actions.declare_file("{}/system_dlkm.img".format(ctx.label.name))
system_dlkm_img_name = "system_dlkm.img"
else:
system_dlkm_img = ctx.actions.declare_file("{}/system_dlkm.{}.img".format(ctx.label.name, fs_type))
system_dlkm_img_name = "system_dlkm.{}.img".format(fs_type)
outputs.append(system_dlkm_img)
outputs_to_compare.append(system_dlkm_img_name)
command += """
{extract_staging_archive_cmd}
# Build {system_dlkm_img_name}
mkdir -p {system_dlkm_staging_dir}
(
MODULES_STAGING_DIR={modules_staging_dir}
SYSTEM_DLKM_FS_TYPE={system_dlkm_fs_type}
SYSTEM_DLKM_STAGING_DIR={system_dlkm_staging_dir}
SYSTEM_DLKM_IMAGE_NAME={system_dlkm_img_name}
{extra_flags_cmd}
build_system_dlkm
)
# Move output files into place
mv "${{DIST_DIR}}/{system_dlkm_img_name}" {system_dlkm_img}
mv "${{DIST_DIR}}/system_dlkm.modules.load" {system_dlkm_modules_load}
mv "${{DIST_DIR}}/system_dlkm_staging_archive.tar.gz" {system_dlkm_staging_archive}
if [ -f "${{DIST_DIR}}/system_dlkm.modules.blocklist" ]; then
mv "${{DIST_DIR}}/system_dlkm.modules.blocklist" {system_dlkm_modules_blocklist}
else
: > {system_dlkm_modules_blocklist}
fi
# Remove staging directories
rm -rf {system_dlkm_staging_dir}
""".format(
extract_staging_archive_cmd = extract_staging_archive_cmd,
extra_flags_cmd = extra_flags_cmd,
modules_staging_dir = modules_staging_dir,
system_dlkm_fs_type = fs_type,
system_dlkm_staging_dir = system_dlkm_staging_dir,
system_dlkm_img = system_dlkm_img.path,
system_dlkm_img_name = system_dlkm_img_name,
system_dlkm_modules_load = system_dlkm_modules_load.path,
system_dlkm_staging_archive = system_dlkm_staging_archive.path,
system_dlkm_modules_blocklist = system_dlkm_modules_blocklist.path,
)
default_info = image_utils.build_modules_image_impl_common(
ctx = ctx,
what = "system_dlkm",
outputs = [
system_dlkm_img,
outputs = outputs + [
system_dlkm_modules_load,
system_dlkm_staging_archive,
system_dlkm_modules_blocklist,
......@@ -141,7 +168,7 @@ def _system_dlkm_image_impl(ctx):
utils.compare_file_names(
default_info.files.to_list(),
SYSTEM_DLKM_OUTS,
SYSTEM_DLKM_COMMON_OUTS + outputs_to_compare,
what = "{}: Internal error: not producing the expected list of outputs".format(ctx.label),
)
......@@ -149,10 +176,11 @@ def _system_dlkm_image_impl(ctx):
system_dlkm_image = rule(
implementation = _system_dlkm_image_impl,
doc = """Build system_dlkm.img an erofs image with GKI modules.
doc = """Build system_dlkm partition image with signed GKI modules.
When included in a `copy_to_dist_dir` rule, this rule copies the following to `DIST_DIR`:
- `system_dlkm.img`
- `system_dlkm.img` if system_dlkm_fs_type is specified
- `system_dlkm.[erfos|ext4].img` if system_dlkm_fs_types is specified
- `system_dlkm.modules.load`
""",
......@@ -160,7 +188,8 @@ When included in a `copy_to_dist_dir` rule, this rule copies the following to `D
"base_kernel_images": attr.label(allow_files = True),
"modules_list": attr.label(allow_single_file = True),
"modules_blocklist": attr.label(allow_single_file = True),
"system_dlkm_fs_type": attr.string(doc = """system_dlkm.img fs type""", values = ["ext4", "erofs"]),
"system_dlkm_fs_type": attr.string(doc = """Deprecated. system_dlkm image fs type""", values = ["ext4", "erofs"]),
"system_dlkm_fs_types": attr.string_list(doc = """system_dlkm image fs types""", allow_empty = True),
"system_dlkm_modules_list": attr.label(allow_single_file = True),
"system_dlkm_modules_blocklist": attr.label(allow_single_file = True),
"system_dlkm_props": attr.label(allow_single_file = True),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment