Add vendor_kernel_boot to android_device This is the soong implementation of vendor_kernel_boot, which was introduced to make packaging in https://r.android.com/2018599 Bug: 420672950 Test: built the autogenerated soong vendor_kernel_boot.img locally Test: It is not bit-identical with make's vendor_kernel_boot.img (diffs arise from their respective ramdisk partitions). I will debug this in followup work Change-Id: Ibbb1f5b02952df61f76a903329b4f1fb03474613
diff --git a/android/module.go b/android/module.go index bdaff79..bcfb974 100644 --- a/android/module.go +++ b/android/module.go
@@ -86,6 +86,7 @@ InstallInSanitizerDir() bool InstallInRamdisk() bool InstallInVendorRamdisk() bool + InstallInVendorKernelRamdisk() bool InstallInDebugRamdisk() bool InstallInRecovery() bool InstallInRoot() bool @@ -411,6 +412,9 @@ // Whether this module is installed to vendor ramdisk Vendor_ramdisk *bool + // Whether this module is installed to vendor kernel ramdisk + Vendor_kernel_ramdisk *bool + // Whether this module is installed to debug ramdisk Debug_ramdisk *bool @@ -1567,6 +1571,10 @@ return Bool(m.commonProperties.Vendor_ramdisk) } +func (m *ModuleBase) InstallInVendorKernelRamdisk() bool { + return Bool(m.commonProperties.Vendor_kernel_ramdisk) +} + func (m *ModuleBase) InstallInDebugRamdisk() bool { return Bool(m.commonProperties.Debug_ramdisk) }
diff --git a/android/module_context.go b/android/module_context.go index 986ecf4..e8c6729 100644 --- a/android/module_context.go +++ b/android/module_context.go
@@ -181,6 +181,7 @@ InstallInSanitizerDir() bool InstallInRamdisk() bool InstallInVendorRamdisk() bool + InstallInVendorKernelRamdisk() bool InstallInDebugRamdisk() bool InstallInRecovery() bool InstallInRoot() bool @@ -524,6 +525,10 @@ return m.module.InstallInVendorRamdisk() } +func (m *moduleContext) InstallInVendorKernelRamdisk() bool { + return m.module.InstallInVendorKernelRamdisk() +} + func (m *moduleContext) InstallInDebugRamdisk() bool { return m.module.InstallInDebugRamdisk() }
diff --git a/android/paths.go b/android/paths.go index f70f7cf..b81720e 100644 --- a/android/paths.go +++ b/android/paths.go
@@ -114,6 +114,7 @@ InstallInSanitizerDir() bool InstallInRamdisk() bool InstallInVendorRamdisk() bool + InstallInVendorKernelRamdisk() bool InstallInDebugRamdisk() bool InstallInRecovery() bool InstallInRoot() bool @@ -152,6 +153,10 @@ return ctx.Module().InstallInVendorRamdisk() } +func (ctx *baseModuleContextToModuleInstallPathContext) InstallInVendorKernelRamdisk() bool { + return ctx.Module().InstallInVendorKernelRamdisk() +} + func (ctx *baseModuleContextToModuleInstallPathContext) InstallInDebugRamdisk() bool { return ctx.Module().InstallInDebugRamdisk() } @@ -2071,6 +2076,8 @@ partition = ctx.DeviceConfig().VendorDlkmPath() } else if ctx.InstallInOdmDlkm() { partition = ctx.DeviceConfig().OdmDlkmPath() + } else if ctx.InstallInVendorKernelRamdisk() { + partition = "vendor_kernel_ramdisk" } else { partition = "system" } @@ -2309,6 +2316,10 @@ return m.inVendorRamdisk } +func (m testModuleInstallPathContext) InstallInVendorKernelRamdisk() bool { + return false +} + func (m testModuleInstallPathContext) InstallInDebugRamdisk() bool { return m.inDebugRamdisk }
diff --git a/android/variable.go b/android/variable.go index 9b4e3e4..10acc4f 100644 --- a/android/variable.go +++ b/android/variable.go
@@ -745,6 +745,9 @@ DoNotStripVendorRamdiskModules bool `json:",omitempty"` DoNotStripVendorModules bool `json:",omitempty"` + VendorKernelRamdiskKernelModules []string `json:",omitempty"` + VendorKernelRamdiskKernelModulesBlocklistFile string `json:",omitempty"` + ProductFsverityGenerateMetadata bool `json:",omitempty"` TargetScreenDensity string `json:",omitempty"`
diff --git a/filesystem/android_device.go b/filesystem/android_device.go index 082740d..9bdc748 100644 --- a/filesystem/android_device.go +++ b/filesystem/android_device.go
@@ -41,6 +41,8 @@ Boot_16k_partition_name *string // Name of the vendor boot partition filesystem module Vendor_boot_partition_name *string + // Name of the vendor kernel boot partition filesystem module + Vendor_kernel_boot_partition_name *string // Name of the init boot partition filesystem module Init_boot_partition_name *string // Name of the system partition filesystem module @@ -195,6 +197,7 @@ addDependencyIfDefined(a.partitionProps.Boot_16k_partition_name) addDependencyIfDefined(a.partitionProps.Init_boot_partition_name) addDependencyIfDefined(a.partitionProps.Vendor_boot_partition_name) + addDependencyIfDefined(a.partitionProps.Vendor_kernel_boot_partition_name) addDependencyIfDefined(a.partitionProps.System_partition_name) addDependencyIfDefined(a.partitionProps.System_ext_partition_name) addDependencyIfDefined(a.partitionProps.Product_partition_name) @@ -572,6 +575,7 @@ targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "BOOT/RAMDISK"}, targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "INIT_BOOT/RAMDISK"}, targetFilesZipCopy{a.partitionProps.Vendor_boot_partition_name, "VENDOR_BOOT/RAMDISK"}, + targetFilesZipCopy{a.partitionProps.Vendor_kernel_boot_partition_name, "VENDOR_KERNEL_BOOT/RAMDISK"}, } filesystemsToCopy := []targetFilesystemZipCopy{} @@ -645,6 +649,19 @@ builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/VENDOR_BOOT/vendor_bootconfig", targetFilesDir) } } + if a.partitionProps.Vendor_kernel_boot_partition_name != nil { + bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Vendor_kernel_boot_partition_name), filesystemDepTag) + bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider) + if bootImgInfo.Dtb != nil { + builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/VENDOR_KERNEL_BOOT/dtb", targetFilesDir) + // Make packaging copies dtb to recovery subdir. + // https://source.corp.google.com/h/googleplex-android/platform/build/+/06d7d8ca0c4fd1e90c7b0aa64c4107ce3f3b1126:core/Makefile;l=6663-6665;bpv=1;bpt=0;drc=9d8019e0c19db397f4ce03ba5abdb9df614adc7d + if ctx.DeviceConfig().BoardMoveRecoveryResourcesToVendorBoot() { + builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/VENDOR_BOOT/dtb", targetFilesDir) + } + } + } + if a.partitionProps.Boot_partition_name != nil { bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Boot_partition_name), filesystemDepTag) bootImgInfo, ok := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider) @@ -1068,6 +1085,7 @@ a.partitionProps.Boot_partition_name, a.partitionProps.Init_boot_partition_name, a.partitionProps.Vendor_boot_partition_name, + a.partitionProps.Vendor_kernel_boot_partition_name, } for _, bootImgName := range bootImgNames { if bootImgName == nil {
diff --git a/filesystem/bootimg.go b/filesystem/bootimg.go index 80f2099..1f1b2bc 100644 --- a/filesystem/bootimg.go +++ b/filesystem/bootimg.go
@@ -70,7 +70,7 @@ Header_version *string // Determines the specific type of boot image this module is building. Can be boot, - // vendor_boot or init_boot. Defaults to boot. + // vendor_boot, vendor_kernel_boot or init_boot. Defaults to boot. // Refer to https://source.android.com/devices/bootloader/partitions/vendor-boot-partitions // for vendor_boot. // Refer to https://source.android.com/docs/core/architecture/partitions/generic-boot for @@ -118,6 +118,7 @@ boot vendorBoot initBoot + vendorKernelBoot ) func toBootImageType(ctx android.ModuleContext, bootImageType string) bootImageType { @@ -128,8 +129,10 @@ return vendorBoot case "init_boot": return initBoot + case "vendor_kernel_boot": + return vendorKernelBoot default: - ctx.ModuleErrorf("Unknown boot_image_type %s. Must be one of \"boot\", \"vendor_boot\", or \"init_boot\"", bootImageType) + ctx.ModuleErrorf("Unknown boot_image_type %s. Must be one of \"boot\", \"vendor_boot\", \"vendor_kernel_boot\", or \"init_boot\"", bootImageType) } return unsupported } @@ -142,6 +145,8 @@ return "vendor_boot" case initBoot: return "init_boot" + case vendorKernelBoot: + return "vendor_kernel_boot" default: panic("unknown boot image type") } @@ -155,6 +160,10 @@ return b == vendorBoot } +func (b bootImageType) isVendorKernelBoot() bool { + return b == vendorKernelBoot +} + func (b bootImageType) isInitBoot() bool { return b == initBoot } @@ -384,7 +393,7 @@ ramdisk := ctx.GetDirectDepWithTag(ramdiskName, bootimgRamdiskDep) if fsInfo, ok := android.OtherModuleProvider(ctx, ramdisk, FilesystemProvider); ok { flag := "--ramdisk " - if b.bootImageType.isVendorBoot() { + if b.bootImageType.isVendorBoot() || b.bootImageType.isVendorKernelBoot() { flag = "--vendor_ramdisk " } cmd.FlagWithInput(flag, fsInfo.Output) @@ -409,7 +418,7 @@ // Output flag for boot.img and init_boot.img flag := "--output " - if b.bootImageType.isVendorBoot() { + if b.bootImageType.isVendorBoot() || b.bootImageType.isVendorKernelBoot() { flag = "--vendor_boot " } cmd.FlagWithOutput(flag, output) @@ -460,7 +469,7 @@ cmd.FlagWithInput("--key ", key) } - if !b.bootImageType.isVendorBoot() { + if !b.bootImageType.isVendorBoot() && !b.bootImageType.isVendorKernelBoot() { cmd.FlagWithArg("--prop ", proptools.NinjaAndShellEscape(fmt.Sprintf( "com.android.build.%s.os_version:%s", b.bootImageType.String(), ctx.Config().PlatformVersionLastStable()))) } @@ -525,7 +534,7 @@ func (b *bootimg) getAvbHashFooterArgs(ctx android.ModuleContext) string { ret := "" - if !b.bootImageType.isVendorBoot() { + if !b.bootImageType.isVendorBoot() && !b.bootImageType.isVendorKernelBoot() { ret += "--prop " + fmt.Sprintf("com.android.build.%s.os_version:%s", b.bootImageType.String(), ctx.Config().PlatformVersionLastStable()) } @@ -733,7 +742,7 @@ cmd.FlagWithInput("--key ", key) } - if !b.bootImageType.isVendorBoot() { + if !b.bootImageType.isVendorBoot() && !b.bootImageType.isVendorKernelBoot() { cmd.FlagWithArg("--prop ", proptools.NinjaAndShellEscape(fmt.Sprintf( "com.android.build.%s.os_version:%s", b.bootImageType.String(), ctx.Config().PlatformVersionLastStable()))) }
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index 70b72a3..5825957 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go
@@ -716,6 +716,8 @@ partitionNameForInstalledFiles = "" case "vendor_ramdisk": partitionNameForInstalledFiles = "vendor-ramdisk" + case "vendor_kernel_ramdisk": + partitionNameForInstalledFiles = "vendor-kernel-ramdisk" default: partitionNameForInstalledFiles = f.partitionName() } @@ -1541,6 +1543,7 @@ "ramdisk", "vendor_ramdisk", "recovery", + "vendor_kernel_ramdisk", } func (f *filesystem) buildEventLogtagsFile(
diff --git a/fsgen/boot_imgs.go b/fsgen/boot_imgs.go index 945bdeb..02d37f3 100644 --- a/fsgen/boot_imgs.go +++ b/fsgen/boot_imgs.go
@@ -198,6 +198,60 @@ return true } +func createVendorKernelBootImage(ctx android.LoadHookContext, dtbImg dtbImg) bool { + vendorKernelBootVariables, exists := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.PartitionQualifiedVariables["vendor_kernel_boot"] + if !exists { + return false + } + + bootImageName := generatedModuleNameForPartition(ctx.Config(), "vendor_kernel_boot") + + avbInfo := getAvbInfo(ctx.Config(), "vendor_kernel_boot") + + var dtbPrebuilt *string + if dtbImg.include && dtbImg.imgType == "boot" { + dtbPrebuilt = proptools.StringPtr(":" + dtbImg.name) + } + + var partitionSize *int64 + if vendorKernelBootVariables.BoardPartitionSize != "" { + // Base of zero will allow base 10 or base 16 if starting with 0x + parsed, err := strconv.ParseInt(vendorKernelBootVariables.BoardPartitionSize, 0, 64) + if err != nil { + ctx.ModuleErrorf("BOARD_VENDOR_KERNEL_BOOTIMAGE_PARTITION_SIZE must be an int, got %s", vendorKernelBootVariables.BoardPartitionSize) + } + partitionSize = &parsed + } + + ctx.CreateModule( + filesystem.BootimgFactory, + &filesystem.BootimgProperties{ + Ramdisk_module: proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor_kernel_ramdisk")), + Dtb_prebuilt: dtbPrebuilt, + Stem: proptools.StringPtr("vendor_kernel_boot.img"), + }, + &filesystem.CommonBootimgProperties{ + Boot_image_type: proptools.StringPtr("vendor_kernel_boot"), + Header_version: proptools.StringPtr("4"), + Partition_size: partitionSize, + Use_avb: avbInfo.avbEnable, + Avb_mode: avbInfo.avbMode, + Avb_private_key: avbInfo.avbkeyFilegroup, + Avb_rollback_index: avbInfo.avbRollbackIndex, + Avb_rollback_index_location: avbInfo.avbRollbackIndexLocation, + }, + + &struct { + Name *string + Visibility []string + }{ + Name: proptools.StringPtr(bootImageName), + Visibility: []string{"//visibility:public"}, + }, + ) + return true +} + func createInitBootImage(ctx android.LoadHookContext) bool { partitionVariables := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse @@ -289,6 +343,11 @@ return false } +func buildingVendorKernelBootImage(partitionVars android.PartitionVariables) bool { + vendorKernelBootVariables, exists := partitionVars.PartitionQualifiedVariables["vendor_kernel_boot"] + return exists && vendorKernelBootVariables.BuildingImage +} + // Derived from: https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/board_config.mk;l=480;drc=5b55f926830963c02ab1d2d91e46442f04ba3af0 func buildingInitBootImage(partitionVars android.PartitionVariables) bool { if !partitionVars.ProductBuildInitBootImage { @@ -338,6 +397,12 @@ if !buildingVendorBootImage(partitionVars) { imgType = "boot" } + if buildingVendorKernelBootImage(partitionVars) { + // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=1655-1658?q=INTERNAL_VENDOR_BOOTIMAGE_ARGS&ss=android%2Fplatform%2Fsuperproject%2Fmain + // If we have vendor_kernel_boot partition, we migrate dtb image to that image + // and allow dtb in vendor_boot to be empty. + imgType = "boot" + } if partitionVars.BoardPrebuiltDtbDir != "" { // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=1019-1022?q=BOARD_PREBUILT_DTBIMAGE_DIR&ss=android%2Fplatform%2Fsuperproject%2Fmaini ctx.CreateModuleInDirectory(
diff --git a/fsgen/filesystem_creator.go b/fsgen/filesystem_creator.go index ee509e9..88f0b96 100644 --- a/fsgen/filesystem_creator.go +++ b/fsgen/filesystem_creator.go
@@ -126,11 +126,12 @@ Vbmeta_module_names []string `blueprint:"mutated"` Vbmeta_partition_names []string `blueprint:"mutated"` - Boot_image string `blueprint:"mutated" android:"path_device_first"` - Boot_16k_image string `blueprint:"mutated" android:"path_device_first"` - Vendor_boot_image string `blueprint:"mutated" android:"path_device_first"` - Init_boot_image string `blueprint:"mutated" android:"path_device_first"` - Super_image string `blueprint:"mutated" android:"path_device_first"` + Boot_image string `blueprint:"mutated" android:"path_device_first"` + Boot_16k_image string `blueprint:"mutated" android:"path_device_first"` + Vendor_boot_image string `blueprint:"mutated" android:"path_device_first"` + Vendor_kernel_boot_image string `blueprint:"mutated" android:"path_device_first"` + Init_boot_image string `blueprint:"mutated" android:"path_device_first"` + Super_image string `blueprint:"mutated" android:"path_device_first"` } type filesystemCreator struct { @@ -231,6 +232,10 @@ if buildingVendorBootImage(partitionVars) { addGenerated("vendor_ramdisk") } + if buildingVendorKernelBootImage(partitionVars) { + addGenerated("vendor_kernel_ramdisk") + } + if ctx.DeviceConfig().BuildingRecoveryImage() && ctx.DeviceConfig().RecoveryPath() == "recovery" { addGenerated("recovery") } @@ -262,6 +267,14 @@ f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "vendor_boot") } } + + if buildingVendorKernelBootImage(partitionVars) { + createVendorKernelBootImage(ctx, dtbImg) + f.properties.Vendor_kernel_boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "vendor_kernel_boot") + } else { + f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "vendor_kernel_boot") + } + if buildingInitBootImage(partitionVars) { if createInitBootImage(ctx) { f.properties.Init_boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "init_boot") @@ -447,6 +460,10 @@ if f.properties.Init_boot_image != "" { partitionProps.Init_boot_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "init_boot")) } + if f.properties.Vendor_kernel_boot_image != "" { + partitionProps.Vendor_kernel_boot_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor_kernel_boot")) + } + partitionProps.Vbmeta_partitions = vbmetaPartitions deviceProps := &filesystem.DeviceProperties{ @@ -750,6 +767,8 @@ fsProps.Include_files_of = []string{recoveryName} } fsProps.Stem = proptools.StringPtr("vendor_ramdisk.img") + case "vendor_kernel_ramdisk": + fsProps.Stem = proptools.StringPtr("vendor_kernel_ramdisk.img") } } @@ -784,7 +803,7 @@ } } - if android.InList(partitionType, append(dlkmPartitions, "vendor_ramdisk")) { + if android.InList(partitionType, append(dlkmPartitions, "vendor_ramdisk", "vendor_kernel_ramdisk")) { f.createPrebuiltKernelModules(ctx, partitionType) } @@ -902,18 +921,19 @@ name := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-kernel-modules", partitionType)) partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse props := &struct { - Name *string - Srcs []string - Srcs_16k []string - System_deps []string - System_dlkm_specific *bool - Vendor_dlkm_specific *bool - Odm_dlkm_specific *bool - Vendor_ramdisk *bool - Load_by_default *bool - Blocklist_file *string - Options_file *string - Strip_debug_symbols *bool + Name *string + Srcs []string + Srcs_16k []string + System_deps []string + System_dlkm_specific *bool + Vendor_dlkm_specific *bool + Odm_dlkm_specific *bool + Vendor_ramdisk *bool + Vendor_kernel_ramdisk *bool + Load_by_default *bool + Blocklist_file *string + Options_file *string + Strip_debug_symbols *bool }{ Name: proptools.StringPtr(name), } @@ -962,7 +982,9 @@ if partitionVars.DoNotStripVendorRamdiskModules { props.Strip_debug_symbols = proptools.BoolPtr(false) } - + case "vendor_kernel_ramdisk": + props.Srcs = android.ExistentPathsForSources(ctx, partitionVars.VendorKernelRamdiskKernelModules).Strings() + props.Vendor_kernel_ramdisk = proptools.BoolPtr(true) default: ctx.ModuleErrorf("DLKM is not supported for %s\n", partitionType) } @@ -1389,6 +1411,9 @@ } var diffTestFiles []android.Path for _, partitionType := range partitions.types() { + if partitionType == "vendor_kernel_ramdisk" { + continue // Make packaging does not create a filter file for this partition. + } diffTestFile := f.createFileListDiffTest(ctx, partitionType, partitions.nameForType(partitionType)) diffTestFiles = append(diffTestFiles, diffTestFile) ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
diff --git a/fsgen/fsgen_mutators.go b/fsgen/fsgen_mutators.go index 8ead4ff..50d8576 100644 --- a/fsgen/fsgen_mutators.go +++ b/fsgen/fsgen_mutators.go
@@ -227,8 +227,9 @@ "fs_config_files_odm_dlkm": defaultDepCandidateProps(ctx.Config()), "notice_xml_odm_dlkm": defaultDepCandidateProps(ctx.Config()), }, - "ramdisk": {}, - "vendor_ramdisk": {}, + "ramdisk": {}, + "vendor_ramdisk": {}, + "vendor_kernel_ramdisk": {}, "recovery": { "sepolicy.recovery": defaultDepCandidateProps(ctx.Config()), "plat_file_contexts.recovery": defaultDepCandidateProps(ctx.Config()),