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

Commit 96fdba92 authored by Jihoon Kang's avatar Jihoon Kang
Browse files

Introduce boot_image_type property in bootimg module

The property is used to replace vendor_boot and init_boot properties.
It is used to specify the type of the boot image the module is building.

Test: CI
Bug: 377563630
Change-Id: Id648ce6e6ea214c2d840f474d4b8fb9bb7dcc642
parent 95eb1dac
Loading
Loading
Loading
Loading
+54 −23
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ type bootimg struct {

	output     android.Path
	installDir android.InstallPath

	bootImageType bootImageType
}

type BootimgProperties struct {
@@ -56,12 +58,13 @@ type BootimgProperties struct {
	// https://source.android.com/devices/bootloader/boot-image-header
	Header_version *string

	// Determines if this image is for the vendor_boot partition. Default is false. Refer to
	// https://source.android.com/devices/bootloader/partitions/vendor-boot-partitions
	Vendor_boot *bool

	// Determines if this image is for the init_boot partition. Default is false.
	Init_boot *bool
	// Determines the specific type of boot image this module is building. Can be boot,
	// vendor_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
	// init_boot.
	Boot_image_type *string

	// Optional kernel commandline arguments
	Cmdline []string `android:"arch_variant"`
@@ -84,6 +87,41 @@ type BootimgProperties struct {
	Avb_algorithm *string
}

type bootImageType int

const (
	unsupported bootImageType = iota
	boot
	vendorBoot
	initBoot
)

func toBootImageType(ctx android.ModuleContext, bootImageType string) bootImageType {
	switch bootImageType {
	case "boot":
		return boot
	case "vendor_boot":
		return vendorBoot
	case "init_boot":
		return initBoot
	default:
		ctx.ModuleErrorf("Unknown boot_image_type %s. Must be one of \"boot\", \"vendor_boot\", or \"init_boot\"", bootImageType)
	}
	return unsupported
}

func (b bootImageType) isBoot() bool {
	return b == boot
}

func (b bootImageType) isVendorBoot() bool {
	return b == vendorBoot
}

func (b bootImageType) isInitBoot() bool {
	return b == initBoot
}

// bootimg is the image for the boot partition. It consists of header, kernel, ramdisk, and dtb.
func BootimgFactory() android.Module {
	module := &bootimg{}
@@ -115,14 +153,8 @@ func (b *bootimg) partitionName() string {
}

func (b *bootimg) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	vendor := proptools.Bool(b.properties.Vendor_boot)
	init := proptools.Bool(b.properties.Init_boot)

	if vendor && init {
		ctx.ModuleErrorf("vendor_boot and init_boot cannot be both set to true")
	}

	unsignedOutput := b.buildBootImage(ctx, vendor, init)
	b.bootImageType = toBootImageType(ctx, proptools.StringDefault(b.properties.Boot_image_type, "boot"))
	unsignedOutput := b.buildBootImage(ctx)

	output := unsignedOutput
	if proptools.Bool(b.properties.Use_avb) {
@@ -136,20 +168,19 @@ func (b *bootimg) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	b.output = output
}

func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool, init bool) android.Path {
func (b *bootimg) buildBootImage(ctx android.ModuleContext) android.Path {
	output := android.PathForModuleOut(ctx, "unsigned", b.installFileName())

	builder := android.NewRuleBuilder(pctx, ctx)
	cmd := builder.Command().BuiltTool("mkbootimg")

	kernel := proptools.String(b.properties.Kernel_prebuilt)
	if vendor && kernel != "" {
	if b.bootImageType.isVendorBoot() && kernel != "" {
		ctx.PropertyErrorf("kernel_prebuilt", "vendor_boot partition can't have kernel")
		return output
	}

	buildingBoot := !vendor && !init
	if buildingBoot && kernel == "" {
	if b.bootImageType.isBoot() && kernel == "" {
		ctx.PropertyErrorf("kernel_prebuilt", "boot partition must have kernel")
		return output
	}
@@ -158,7 +189,7 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool, init bo
	}

	// These arguments are passed for boot.img and init_boot.img generation
	if !vendor {
	if b.bootImageType.isBoot() || b.bootImageType.isInitBoot() {
		cmd.FlagWithArg("--os_version ", ctx.Config().PlatformVersionLastStable())
		cmd.FlagWithArg("--os_patch_level ", ctx.Config().PlatformSecurityPatch())
	}
@@ -172,7 +203,7 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool, init bo
	cmdline := strings.Join(b.properties.Cmdline, " ")
	if cmdline != "" {
		flag := "--cmdline "
		if vendor {
		if b.bootImageType.isVendorBoot() {
			flag = "--vendor_cmdline "
		}
		cmd.FlagWithArg(flag, proptools.ShellEscapeIncludingSpaces(cmdline))
@@ -199,7 +230,7 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool, init bo
		ramdisk := ctx.GetDirectDepWithTag(ramdiskName, bootimgRamdiskDep)
		if filesystem, ok := ramdisk.(*filesystem); ok {
			flag := "--ramdisk "
			if vendor {
			if b.bootImageType.isVendorBoot() {
				flag = "--vendor_ramdisk "
			}
			cmd.FlagWithInput(flag, filesystem.OutputPath())
@@ -211,7 +242,7 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool, init bo

	bootconfig := proptools.String(b.properties.Bootconfig)
	if bootconfig != "" {
		if !vendor {
		if !b.bootImageType.isVendorBoot() {
			ctx.PropertyErrorf("bootconfig", "requires vendor_boot: true")
			return output
		}
@@ -224,7 +255,7 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool, init bo

	// Output flag for boot.img and init_boot.img
	flag := "--output "
	if vendor {
	if b.bootImageType.isVendorBoot() {
		flag = "--vendor_boot "
	}
	cmd.FlagWithOutput(flag, output)
+6 −6
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ func createVendorBootImage(ctx android.LoadHookContext) bool {
	ctx.CreateModule(
		filesystem.BootimgFactory,
		&filesystem.BootimgProperties{
			Vendor_boot:    proptools.BoolPtr(true),
			Boot_image_type: proptools.StringPtr("vendor_boot"),
			Ramdisk_module:  proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor_ramdisk")),
			Header_version:  proptools.StringPtr(partitionVariables.BoardBootHeaderVersion),
		},
@@ -82,7 +82,7 @@ func createInitBootImage(ctx android.LoadHookContext) bool {
	ctx.CreateModule(
		filesystem.BootimgFactory,
		&filesystem.BootimgProperties{
			Init_boot:      proptools.BoolPtr(true),
			Boot_image_type: proptools.StringPtr("init_boot"),
			Ramdisk_module:  proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "ramdisk")),
			Header_version:  proptools.StringPtr(partitionVariables.BoardBootHeaderVersion),
		},