summaryrefslogtreecommitdiff
path: root/filesystem/bootimg.go
diff options
context:
space:
mode:
Diffstat (limited to 'filesystem/bootimg.go')
-rw-r--r--filesystem/bootimg.go70
1 files changed, 57 insertions, 13 deletions
diff --git a/filesystem/bootimg.go b/filesystem/bootimg.go
index 5aa60d2ae..22495064d 100644
--- a/filesystem/bootimg.go
+++ b/filesystem/bootimg.go
@@ -36,6 +36,8 @@ type bootimg struct {
output android.Path
installDir android.InstallPath
+
+ bootImageType bootImageType
}
type BootimgProperties struct {
@@ -56,9 +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 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"`
@@ -85,6 +91,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{}
@@ -116,8 +157,8 @@ func (b *bootimg) partitionName() string {
}
func (b *bootimg) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- vendor := proptools.Bool(b.properties.Vendor_boot)
- unsignedOutput := b.buildBootImage(ctx, vendor)
+ 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) {
@@ -131,18 +172,19 @@ func (b *bootimg) GenerateAndroidBuildActions(ctx android.ModuleContext) {
b.output = output
}
-func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor 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
}
- if !vendor && kernel == "" {
+
+ if b.bootImageType.isBoot() && kernel == "" {
ctx.PropertyErrorf("kernel_prebuilt", "boot partition must have kernel")
return output
}
@@ -150,7 +192,8 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool) android
cmd.FlagWithInput("--kernel ", android.PathForModuleSrc(ctx, kernel))
}
- if !vendor {
+ // These arguments are passed for boot.img and init_boot.img generation
+ if b.bootImageType.isBoot() || b.bootImageType.isInitBoot() {
cmd.FlagWithArg("--os_version ", ctx.Config().PlatformVersionLastStable())
cmd.FlagWithArg("--os_patch_level ", ctx.Config().PlatformSecurityPatch())
}
@@ -164,7 +207,7 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool) android
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))
@@ -191,7 +234,7 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool) android
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())
@@ -203,7 +246,7 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool) android
bootconfig := proptools.String(b.properties.Bootconfig)
if bootconfig != "" {
- if !vendor {
+ if !b.bootImageType.isVendorBoot() {
ctx.PropertyErrorf("bootconfig", "requires vendor_boot: true")
return output
}
@@ -214,8 +257,9 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool) android
cmd.FlagWithInput("--vendor_bootconfig ", android.PathForModuleSrc(ctx, bootconfig))
}
+ // Output flag for boot.img and init_boot.img
flag := "--output "
- if vendor {
+ if b.bootImageType.isVendorBoot() {
flag = "--vendor_boot "
}
cmd.FlagWithOutput(flag, output)