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

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

Merge "Add partition size check to boot partitions" into main

parents 517c6f81 26bdac55
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -73,6 +73,10 @@ type BootimgProperties struct {
	// and `header_version` is greater than or equal to 4.
	Bootconfig *string `android:"arch_variant,path"`

	// The size of the partition on the device. It will be a build error if this built partition
	// image exceeds this size.
	Partition_size *int64

	// When set to true, sign the image with avbtool. Default is false.
	Use_avb *bool

@@ -260,6 +264,10 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext) android.Path {
	}
	cmd.FlagWithOutput(flag, output)

	if b.properties.Partition_size != nil {
		assertMaxImageSize(builder, output, *b.properties.Partition_size, proptools.Bool(b.properties.Use_avb))
	}

	builder.Build("build_bootimg", fmt.Sprintf("Creating %s", b.BaseModuleName()))
	return output
}
+23 −0
Original line number Diff line number Diff line
@@ -926,3 +926,26 @@ func (f *filesystem) getLibsForLinkerConfig(ctx android.ModuleContext) ([]androi

	return provideModules, requireModules
}

// Checks that the given file doesn't exceed the given size, and will also print a warning
// if it's nearing the maximum size. Equivalent to assert-max-image-size in make:
// https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/definitions.mk;l=3455;drc=993c4de29a02a6accd60ceaaee153307e1a18d10
func assertMaxImageSize(builder *android.RuleBuilder, image android.Path, maxSize int64, addAvbLater bool) {
	if addAvbLater {
		// The value 69632 is derived from MAX_VBMETA_SIZE + MAX_FOOTER_SIZE in avbtool.
		// Logic copied from make:
		// https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=228;drc=a6a0007ef24e16c0b79f439beac4a118416717e6
		maxSize -= 69632
	}
	cmd := builder.Command()
	cmd.Textf(`file="%s"; maxsize="%d";`+
		`total=$(stat -c "%%s" "$file" | tr -d '\n');`+
		`if [ "$total" -gt "$maxsize" ]; then `+
		`  echo "error: $file too large ($total > $maxsize)";`+
		`  false;`+
		`elif [ "$total" -gt $((maxsize - 32768)) ]; then `+
		`  echo "WARNING: $file approaching size limit ($total now; limit $maxsize)";`+
		`fi`,
		image, maxSize)
	cmd.Implicit(image)
}
+10 −0
Original line number Diff line number Diff line
@@ -36,6 +36,15 @@ func createBootImage(ctx android.LoadHookContext) bool {
		},
	)

	var partitionSize *int64
	if partitionVariables.BoardBootimagePartitionSize != "" {
		parsed, err := strconv.ParseInt(partitionVariables.BoardBootimagePartitionSize, 10, 64)
		if err != nil {
			panic(fmt.Sprintf("BOARD_BOOTIMAGE_PARTITION_SIZE must be an int, got %s", partitionVariables.BoardBootimagePartitionSize))
		}
		partitionSize = &parsed
	}

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

	ctx.CreateModule(
@@ -43,6 +52,7 @@ func createBootImage(ctx android.LoadHookContext) bool {
		&filesystem.BootimgProperties{
			Kernel_prebuilt: proptools.StringPtr(":" + kernelFilegroupName),
			Header_version:  proptools.StringPtr(partitionVariables.BoardBootHeaderVersion),
			Partition_size:  partitionSize,
		},
		&struct {
			Name *string