Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 984de3e4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Build boot.img with soong" into main

parents 84dc3244 f2a6e8bc
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -610,6 +610,7 @@ type PartitionVariables struct {
	CopyImagesForTargetFilesZip    bool   `json:",omitempty"`

	// Boot image stuff
	BuildingRamdiskImage            bool   `json:",omitempty"`
	ProductBuildBootImage           bool   `json:",omitempty"`
	ProductBuildInitBootImage       bool   `json:",omitempty"`
	BoardUsesRecoveryAsBoot         bool   `json:",omitempty"`
@@ -618,6 +619,7 @@ type PartitionVariables struct {
	BoardBootimagePartitionSize     string `json:",omitempty"`
	BoardInitBootimagePartitionSize string `json:",omitempty"`
	BoardBootHeaderVersion          string `json:",omitempty"`
	TargetKernelPath                string `json:",omitempty"`

	// Avb (android verified boot) stuff
	BoardAvbEnable          bool                                `json:",omitempty"`
+4 −4
Original line number Diff line number Diff line
@@ -26,19 +26,19 @@ import (
)

func init() {
	android.RegisterModuleType("bootimg", bootimgFactory)
	android.RegisterModuleType("bootimg", BootimgFactory)
}

type bootimg struct {
	android.ModuleBase

	properties bootimgProperties
	properties BootimgProperties

	output     android.Path
	installDir android.InstallPath
}

type bootimgProperties struct {
type BootimgProperties struct {
	// Set the name of the output. Defaults to <module_name>.img.
	Stem *string

@@ -82,7 +82,7 @@ type bootimgProperties struct {
}

// bootimg is the image for the boot partition. It consists of header, kernel, ramdisk, and dtb.
func bootimgFactory() android.Module {
func BootimgFactory() android.Module {
	module := &bootimg{}
	module.AddProperties(&module.properties)
	android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ bootstrap_go_package {
        "soong-kernel",
    ],
    srcs: [
        "boot_imgs.go",
        "filesystem_creator.go",
        "fsgen_mutators.go",
        "prebuilt_etc_modules_gen.go",

fsgen/boot_imgs.go

0 → 100644
+78 −0
Original line number Diff line number Diff line
package fsgen

import (
	"android/soong/android"
	"android/soong/filesystem"
	"path/filepath"

	"github.com/google/blueprint/proptools"
)

func createBootImage(ctx android.LoadHookContext) bool {
	partitionVariables := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse

	if partitionVariables.TargetKernelPath == "" {
		// There are potentially code paths that don't set TARGET_KERNEL_PATH
		return false
	}

	kernelDir := filepath.Dir(partitionVariables.TargetKernelPath)
	kernelBase := filepath.Base(partitionVariables.TargetKernelPath)
	kernelFilegroupName := generatedModuleName(ctx.Config(), "kernel")

	ctx.CreateModuleInDirectory(
		android.FileGroupFactory,
		kernelDir,
		&struct {
			Name       *string
			Srcs       []string
			Visibility []string
		}{
			Name:       proptools.StringPtr(kernelFilegroupName),
			Srcs:       []string{kernelBase},
			Visibility: []string{"//visibility:public"},
		},
	)

	bootImageName := generatedModuleNameForPartition(ctx.Config(), "boot")

	ctx.CreateModule(
		filesystem.BootimgFactory,
		&filesystem.BootimgProperties{
			Kernel_prebuilt: proptools.StringPtr(":" + kernelFilegroupName),
			Ramdisk_module:  proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "ramdisk")),
			Header_version:  proptools.StringPtr(partitionVariables.BoardBootHeaderVersion),
		},
		&struct {
			Name *string
		}{
			Name: proptools.StringPtr(bootImageName),
		},
	)
	return true
}

// Returns the equivalent of the BUILDING_BOOT_IMAGE variable in make. Derived from this logic:
// https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/board_config.mk;l=458;drc=5b55f926830963c02ab1d2d91e46442f04ba3af0
func buildingBootImage(partitionVars android.PartitionVariables) bool {
	if partitionVars.BoardUsesRecoveryAsBoot {
		return false
	}

	if partitionVars.ProductBuildBootImage {
		return true
	}

	if len(partitionVars.BoardPrebuiltBootimage) > 0 {
		return false
	}

	if len(partitionVars.BoardBootimagePartitionSize) > 0 {
		return true
	}

	// TODO: return true if BOARD_KERNEL_BINARIES is set and has a *_BOOTIMAGE_PARTITION_SIZE
	// variable. However, I don't think BOARD_KERNEL_BINARIES is ever set in practice.

	return false
}
+60 −6
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ type filesystemCreatorProps struct {

	Vbmeta_module_names    []string `blueprint:"mutated"`
	Vbmeta_partition_names []string `blueprint:"mutated"`

	Boot_image string `blueprint:"mutated" android:"path_device_first"`
}

type filesystemCreator struct {
@@ -71,6 +73,38 @@ func filesystemCreatorFactory() android.Module {
	return module
}

func generatedPartitions(ctx android.LoadHookContext) []string {
	generatedPartitions := []string{"system"}
	if ctx.DeviceConfig().SystemExtPath() == "system_ext" {
		generatedPartitions = append(generatedPartitions, "system_ext")
	}
	if ctx.DeviceConfig().BuildingVendorImage() && ctx.DeviceConfig().VendorPath() == "vendor" {
		generatedPartitions = append(generatedPartitions, "vendor")
	}
	if ctx.DeviceConfig().BuildingProductImage() && ctx.DeviceConfig().ProductPath() == "product" {
		generatedPartitions = append(generatedPartitions, "product")
	}
	if ctx.DeviceConfig().BuildingOdmImage() && ctx.DeviceConfig().OdmPath() == "odm" {
		generatedPartitions = append(generatedPartitions, "odm")
	}
	if ctx.DeviceConfig().BuildingUserdataImage() && ctx.DeviceConfig().UserdataPath() == "data" {
		generatedPartitions = append(generatedPartitions, "userdata")
	}
	if ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.BuildingSystemDlkmImage {
		generatedPartitions = append(generatedPartitions, "system_dlkm")
	}
	if ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.BuildingVendorDlkmImage {
		generatedPartitions = append(generatedPartitions, "vendor_dlkm")
	}
	if ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.BuildingOdmDlkmImage {
		generatedPartitions = append(generatedPartitions, "odm_dlkm")
	}
	if ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.BuildingRamdiskImage {
		generatedPartitions = append(generatedPartitions, "ramdisk")
	}
	return generatedPartitions
}

func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) {
	soongGeneratedPartitions := generatedPartitions(ctx)
	finalSoongGeneratedPartitions := make([]string, 0, len(soongGeneratedPartitions))
@@ -83,6 +117,14 @@ func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) {
		}
	}

	if buildingBootImage(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse) {
		if createBootImage(ctx) {
			f.properties.Boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "boot")
		} else {
			f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "boot")
		}
	}

	for _, x := range createVbmetaPartitions(ctx, finalSoongGeneratedPartitions) {
		f.properties.Vbmeta_module_names = append(f.properties.Vbmeta_module_names, x.moduleName)
		f.properties.Vbmeta_partition_names = append(f.properties.Vbmeta_partition_names, x.partitionName)
@@ -546,7 +588,7 @@ func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*fil
	return fsProps, true
}

func (f *filesystemCreator) createDiffTest(ctx android.ModuleContext, partitionType string) android.Path {
func (f *filesystemCreator) createFileListDiffTest(ctx android.ModuleContext, partitionType string) android.Path {
	partitionModuleName := generatedModuleNameForPartition(ctx.Config(), partitionType)
	systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag)
	filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider)
@@ -591,13 +633,17 @@ func createVbmetaDiff(ctx android.ModuleContext, vbmetaModuleName string, vbmeta
	makeVbmetaFile := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/%s.img", ctx.Config().DeviceName(), vbmetaPartitionName))

	diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", vbmetaModuleName))
	createDiffTest(ctx, diffTestResultFile, soongVbMetaFile, makeVbmetaFile)
	return diffTestResultFile
}

func createDiffTest(ctx android.ModuleContext, diffTestResultFile android.WritablePath, file1 android.Path, file2 android.Path) {
	builder := android.NewRuleBuilder(pctx, ctx)
	builder.Command().Text("diff").
		Input(soongVbMetaFile).
		Input(makeVbmetaFile)
		Input(file1).
		Input(file2)
	builder.Command().Text("touch").Output(diffTestResultFile)
	builder.Build(vbmetaModuleName+" diff test", vbmetaModuleName+" diff test")
	return diffTestResultFile
	builder.Build("diff test "+diffTestResultFile.String(), "diff test")
}

type systemImageDepTagType struct {
@@ -634,7 +680,7 @@ func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContex

	var diffTestFiles []android.Path
	for _, partitionType := range f.properties.Generated_partition_types {
		diffTestFile := f.createDiffTest(ctx, partitionType)
		diffTestFile := f.createFileListDiffTest(ctx, partitionType)
		diffTestFiles = append(diffTestFiles, diffTestFile)
		ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
	}
@@ -648,6 +694,14 @@ func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContex
		diffTestFiles = append(diffTestFiles, diffTestFile)
		ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", f.properties.Vbmeta_partition_names[i]), diffTestFile)
	}
	if f.properties.Boot_image != "" {
		diffTestFile := android.PathForModuleOut(ctx, "boot_diff_test.txt")
		soongBootImg := android.PathForModuleSrc(ctx, f.properties.Boot_image)
		makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/boot.img", ctx.Config().DeviceName()))
		createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage)
		diffTestFiles = append(diffTestFiles, diffTestFile)
		ctx.Phony("soong_generated_boot_filesystem_test", diffTestFile)
	}
	ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...)
}

Loading