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

Commit c9854201 authored by Spandan Das's avatar Spandan Das Committed by Gerrit Code Review
Browse files

Merge "Create super_empty.img using Soong" into main

parents 84ec3e01 d73441e4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -656,6 +656,7 @@ type PartitionVariables struct {
	ProductUseDynamicPartitions       bool                                     `json:",omitempty"`
	ProductRetrofitDynamicPartitions  bool                                     `json:",omitempty"`
	ProductBuildSuperPartition        bool                                     `json:",omitempty"`
	BuildingSuperEmptyImage           bool                                     `json:",omitempty"`
	BoardSuperPartitionSize           string                                   `json:",omitempty"`
	BoardSuperPartitionMetadataDevice string                                   `json:",omitempty"`
	BoardSuperPartitionBlockDevices   []string                                 `json:",omitempty"`
+4 −0
Original line number Diff line number Diff line
@@ -623,6 +623,10 @@ func (a *androidDevice) copyImagesToTargetZip(ctx android.ModuleContext, builder
					builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].MapFile).Textf(" %s/IMAGES/", targetFilesDir.String())
				}
			}
			// super_empty.img
			if info.SuperEmptyImage != nil {
				builder.Command().Textf("cp ").Input(info.SuperEmptyImage).Textf(" %s/IMAGES/", targetFilesDir.String())
			}
		} else {
			ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name())
		}
+31 −2
Original line number Diff line number Diff line
@@ -80,6 +80,8 @@ type SuperImageProperties struct {
	}
	// Whether the super image will be disted in the update package
	Super_image_in_update_package *bool
	// Whether a super_empty.img should be created
	Create_super_empty *bool
}

type PartitionGroupsInfo struct {
@@ -118,6 +120,8 @@ type SuperImageInfo struct {
	SubImageInfo map[string]FilesystemInfo

	DynamicPartitionsInfo android.Path

	SuperEmptyImage android.Path
}

var SuperImageProvider = blueprint.NewProvider[SuperImageInfo]()
@@ -163,7 +167,7 @@ func (s *superImage) DepsMutator(ctx android.BottomUpMutatorContext) {
}

func (s *superImage) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	miscInfo, deps, subImageInfos := s.buildMiscInfo(ctx)
	miscInfo, deps, subImageInfos := s.buildMiscInfo(ctx, false)
	builder := android.NewRuleBuilder(pctx, ctx)
	output := android.PathForModuleOut(ctx, s.installFileName())
	lpMake := ctx.Config().HostToolPath(ctx, "lpmake")
@@ -176,10 +180,27 @@ func (s *superImage) GenerateAndroidBuildActions(ctx android.ModuleContext) {
		Implicits(deps).
		Output(output)
	builder.Build("build_super_image", fmt.Sprintf("Creating super image %s", s.BaseModuleName()))
	var superEmptyImage android.WritablePath
	if proptools.Bool(s.properties.Create_super_empty) {
		superEmptyImageBuilder := android.NewRuleBuilder(pctx, ctx)
		superEmptyImage = android.PathForModuleOut(ctx, "super_empty.img")
		superEmptyMiscInfo, superEmptyDeps, _ := s.buildMiscInfo(ctx, true)
		if superEmptyDeps != nil {
			ctx.ModuleErrorf("TODO: Handle additional deps when building super_empty.img")
		}
		superEmptyImageBuilder.Command().Textf("PATH=%s:\\$PATH", lpMakeDir).
			BuiltTool("build_super_image").
			Text("-v").
			Input(superEmptyMiscInfo).
			Implicit(lpMake).
			Output(superEmptyImage)
		superEmptyImageBuilder.Build("build_super_empty_image", fmt.Sprintf("Creating super empty image %s", s.BaseModuleName()))
	}
	android.SetProvider(ctx, SuperImageProvider, SuperImageInfo{
		SuperImage:            output,
		SubImageInfo:          subImageInfos,
		DynamicPartitionsInfo: s.generateDynamicPartitionsInfo(ctx),
		SuperEmptyImage:       superEmptyImage,
	})
	ctx.SetOutputFiles([]android.Path{output}, "")
	ctx.CheckbuildFile(output)
@@ -191,7 +212,7 @@ func (s *superImage) installFileName() string {
	return "super.img"
}

func (s *superImage) buildMiscInfo(ctx android.ModuleContext) (android.Path, android.Paths, map[string]FilesystemInfo) {
func (s *superImage) buildMiscInfo(ctx android.ModuleContext, superEmpty bool) (android.Path, android.Paths, map[string]FilesystemInfo) {
	var miscInfoString strings.Builder
	partitionList := s.dumpDynamicPartitionInfo(ctx, &miscInfoString)
	addStr := func(name string, value string) {
@@ -201,6 +222,11 @@ func (s *superImage) buildMiscInfo(ctx android.ModuleContext) (android.Path, and
		miscInfoString.WriteRune('\n')
	}
	addStr("ab_update", strconv.FormatBool(proptools.Bool(s.properties.Ab_update)))
	if superEmpty {
		miscInfo := android.PathForModuleOut(ctx, "misc_info_super_empty.txt")
		android.WriteFileRule(ctx, miscInfo, miscInfoString.String())
		return miscInfo, nil, nil
	}

	subImageInfo := make(map[string]FilesystemInfo)
	var deps android.Paths
@@ -300,6 +326,9 @@ func (s *superImage) dumpDynamicPartitionInfo(ctx android.ModuleContext, sb *str
	}

	addStr("build_super_partition", "true")
	if proptools.Bool(s.properties.Create_super_empty) {
		addStr("build_super_empty_partition", "true")
	}
	addStr("use_dynamic_partitions", strconv.FormatBool(proptools.Bool(s.properties.Use_dynamic_partitions)))
	if proptools.Bool(s.properties.Retrofit) {
		addStr("dynamic_partition_retrofit", "true")
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ func createSuperImage(
		Retrofit:                      proptools.BoolPtr(partitionVars.ProductRetrofitDynamicPartitions),
		Use_dynamic_partitions:        proptools.BoolPtr(partitionVars.ProductUseDynamicPartitions),
		Super_image_in_update_package: proptools.BoolPtr(partitionVars.BoardSuperImageInUpdatePackage),
		Create_super_empty:            proptools.BoolPtr(partitionVars.BuildingSuperEmptyImage),
	}
	if partitionVars.ProductVirtualAbOta {
		superImageProps.Virtual_ab.Enable = proptools.BoolPtr(true)