Add ramdisk image.
It is similar to recovery image.
Test: m nothing -j
Change-Id: I11389777c6bfb0c0d73bbb4c70091c1e70f44077
diff --git a/android/arch.go b/android/arch.go
index b5b8a8f..6be5993 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -838,8 +838,8 @@
osTargets = targets
}
- // only the primary arch in the recovery partition
- if os == Android && module.InstallInRecovery() {
+ // only the primary arch in the ramdisk / recovery partition
+ if os == Android && (module.InstallInRecovery() || module.InstallInRamdisk()) {
osTargets = []Target{osTargets[0]}
}
diff --git a/android/image.go b/android/image.go
index 5291ce3..061bfa5 100644
--- a/android/image.go
+++ b/android/image.go
@@ -22,6 +22,10 @@
// CoreVariantNeeded should return true if the module needs a core variant (installed on the system image).
CoreVariantNeeded(ctx BaseModuleContext) bool
+ // RamdiskVariantNeeded should return true if the module needs a ramdisk variant (installed on the
+ // ramdisk partition).
+ RamdiskVariantNeeded(ctx BaseModuleContext) bool
+
// RecoveryVariantNeeded should return true if the module needs a recovery variant (installed on the
// recovery partition).
RecoveryVariantNeeded(ctx BaseModuleContext) bool
@@ -46,6 +50,9 @@
// RecoveryVariation means a module to be installed to recovery image.
RecoveryVariation string = "recovery"
+
+ // RamdiskVariation means a module to be installed to ramdisk image.
+ RamdiskVariation string = "ramdisk"
)
// imageMutator creates variants for modules that implement the ImageInterface that
@@ -63,6 +70,9 @@
if m.CoreVariantNeeded(ctx) {
variations = append(variations, CoreVariation)
}
+ if m.RamdiskVariantNeeded(ctx) {
+ variations = append(variations, RamdiskVariation)
+ }
if m.RecoveryVariantNeeded(ctx) {
variations = append(variations, RecoveryVariation)
}
diff --git a/android/module.go b/android/module.go
index 05115d6..2662e2a 100644
--- a/android/module.go
+++ b/android/module.go
@@ -167,6 +167,7 @@
InstallInData() bool
InstallInTestcases() bool
InstallInSanitizerDir() bool
+ InstallInRamdisk() bool
InstallInRecovery() bool
InstallInRoot() bool
InstallBypassMake() bool
@@ -207,6 +208,7 @@
InstallInData() bool
InstallInTestcases() bool
InstallInSanitizerDir() bool
+ InstallInRamdisk() bool
InstallInRecovery() bool
InstallInRoot() bool
InstallBypassMake() bool
@@ -384,6 +386,9 @@
// Whether this module is installed to recovery partition
Recovery *bool
+ // Whether this module is installed to ramdisk
+ Ramdisk *bool
+
// Whether this module is built for non-native architecures (also known as native bridge binary)
Native_bridge_supported *bool `android:"arch_variant"`
@@ -867,6 +872,10 @@
return false
}
+func (m *ModuleBase) InstallInRamdisk() bool {
+ return Bool(m.commonProperties.Ramdisk)
+}
+
func (m *ModuleBase) InstallInRecovery() bool {
return Bool(m.commonProperties.Recovery)
}
@@ -898,6 +907,10 @@
}
}
+func (m *ModuleBase) InRamdisk() bool {
+ return m.base().commonProperties.ImageVariation == RamdiskVariation
+}
+
func (m *ModuleBase) InRecovery() bool {
return m.base().commonProperties.ImageVariation == RecoveryVariation
}
@@ -1649,6 +1662,10 @@
return m.module.InstallInSanitizerDir()
}
+func (m *moduleContext) InstallInRamdisk() bool {
+ return m.module.InstallInRamdisk()
+}
+
func (m *moduleContext) InstallInRecovery() bool {
return m.module.InstallInRecovery()
}
diff --git a/android/paths.go b/android/paths.go
index 02f56d0..7bfd8e1 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -49,6 +49,7 @@
InstallInData() bool
InstallInTestcases() bool
InstallInSanitizerDir() bool
+ InstallInRamdisk() bool
InstallInRecovery() bool
InstallInRoot() bool
InstallBypassMake() bool
@@ -1254,6 +1255,9 @@
partition = "data"
} else if ctx.InstallInTestcases() {
partition = "testcases"
+ } else if ctx.InstallInRamdisk() {
+ // TODO(elsk): should be conditional on RECOVERY_AS_BOOT
+ partition = "ramdisk"
} else if ctx.InstallInRecovery() {
if ctx.InstallInRoot() {
partition = "recovery/root"
diff --git a/android/paths_test.go b/android/paths_test.go
index 46e3e1f..7a32026 100644
--- a/android/paths_test.go
+++ b/android/paths_test.go
@@ -202,6 +202,7 @@
inData bool
inTestcases bool
inSanitizerDir bool
+ inRamdisk bool
inRecovery bool
inRoot bool
}
@@ -224,6 +225,10 @@
return m.inSanitizerDir
}
+func (m moduleInstallPathContextImpl) InstallInRamdisk() bool {
+ return m.inRamdisk
+}
+
func (m moduleInstallPathContextImpl) InstallInRecovery() bool {
return m.inRecovery
}
diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go
index 388d17f..3dea6d8 100644
--- a/android/prebuilt_etc.go
+++ b/android/prebuilt_etc.go
@@ -41,6 +41,9 @@
// is the same as the file name of the source file.
Filename_from_src *bool `android:"arch_variant"`
+ // Make this module available when building for ramdisk.
+ Ramdisk_available *bool
+
// Make this module available when building for recovery.
Recovery_available *bool
@@ -69,6 +72,18 @@
additionalDependencies *Paths
}
+func (p *PrebuiltEtc) inRamdisk() bool {
+ return p.ModuleBase.InRamdisk() || p.ModuleBase.InstallInRamdisk()
+}
+
+func (p *PrebuiltEtc) onlyInRamdisk() bool {
+ return p.ModuleBase.InstallInRamdisk()
+}
+
+func (p *PrebuiltEtc) InstallInRamdisk() bool {
+ return p.inRamdisk()
+}
+
func (p *PrebuiltEtc) inRecovery() bool {
return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery()
}
@@ -86,7 +101,11 @@
func (p *PrebuiltEtc) ImageMutatorBegin(ctx BaseModuleContext) {}
func (p *PrebuiltEtc) CoreVariantNeeded(ctx BaseModuleContext) bool {
- return !p.ModuleBase.InstallInRecovery()
+ return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk()
+}
+
+func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx BaseModuleContext) bool {
+ return Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk()
}
func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx BaseModuleContext) bool {
@@ -167,6 +186,9 @@
func (p *PrebuiltEtc) AndroidMkEntries() []AndroidMkEntries {
nameSuffix := ""
+ if p.inRamdisk() && !p.onlyInRamdisk() {
+ nameSuffix = ".ramdisk"
+ }
if p.inRecovery() && !p.onlyInRecovery() {
nameSuffix = ".recovery"
}
diff --git a/cc/androidmk.go b/cc/androidmk.go
index c9cd01c..137cb63 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -27,6 +27,7 @@
nativeBridgeSuffix = ".native_bridge"
productSuffix = ".product"
vendorSuffix = ".vendor"
+ ramdiskSuffix = ".ramdisk"
recoverySuffix = ".recovery"
)
@@ -40,6 +41,7 @@
UseVndk() bool
VndkVersion() string
static() bool
+ InRamdisk() bool
InRecovery() bool
}
@@ -233,7 +235,7 @@
})
}
if len(library.Properties.Stubs.Versions) > 0 &&
- android.DirectlyInAnyApex(ctx, ctx.Name()) && !ctx.InRecovery() && !ctx.UseVndk() &&
+ android.DirectlyInAnyApex(ctx, ctx.Name()) && !ctx.InRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() &&
!ctx.static() {
if !library.buildStubs() {
ret.SubName = ".bootstrap"
diff --git a/cc/binary.go b/cc/binary.go
index ba6ed5f..280d17b 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -264,7 +264,7 @@
} else {
switch ctx.Os() {
case android.Android:
- if ctx.bootstrap() && !ctx.inRecovery() {
+ if ctx.bootstrap() && !ctx.inRecovery() && !ctx.inRamdisk() {
flags.DynamicLinker = "/system/bin/bootstrap/linker"
} else {
flags.DynamicLinker = "/system/bin/linker"
@@ -458,7 +458,7 @@
// The original path becomes a symlink to the corresponding file in the
// runtime APEX.
translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled
- if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !translatedArch && ctx.apexName() == "" && !ctx.inRecovery() {
+ if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !translatedArch && ctx.apexName() == "" && !ctx.inRamdisk() && !ctx.inRecovery() {
if ctx.Device() && isBionic(ctx.baseModuleName()) {
binary.installSymlinkToRuntimeApex(ctx, file)
}
diff --git a/cc/cc.go b/cc/cc.go
index 022e350..ce3a2ed 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -223,11 +223,15 @@
// file
Logtags []string
+ // Make this module available when building for ramdisk
+ Ramdisk_available *bool
+
// Make this module available when building for recovery
Recovery_available *bool
// Set by imageMutator
CoreVariantNeeded bool `blueprint:"mutated"`
+ RamdiskVariantNeeded bool `blueprint:"mutated"`
RecoveryVariantNeeded bool `blueprint:"mutated"`
ExtraVariants []string `blueprint:"mutated"`
@@ -290,6 +294,7 @@
isVndkExt() bool
inProduct() bool
inVendor() bool
+ inRamdisk() bool
inRecovery() bool
shouldCreateSourceAbiDump() bool
selectedStl() string
@@ -878,10 +883,18 @@
return c.Properties.ImageVariationPrefix == VendorVariationPrefix
}
+func (c *Module) InRamdisk() bool {
+ return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
+}
+
func (c *Module) InRecovery() bool {
return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
}
+func (c *Module) OnlyInRamdisk() bool {
+ return c.ModuleBase.InstallInRamdisk()
+}
+
func (c *Module) OnlyInRecovery() bool {
return c.ModuleBase.InstallInRecovery()
}
@@ -1018,7 +1031,7 @@
}
func (ctx *moduleContextImpl) useSdk() bool {
- if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
+ if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
return String(ctx.mod.Properties.Sdk_version) != ""
}
return false
@@ -1090,6 +1103,10 @@
return ctx.mod.inVendor()
}
+func (ctx *moduleContextImpl) inRamdisk() bool {
+ return ctx.mod.InRamdisk()
+}
+
func (ctx *moduleContextImpl) inRecovery() bool {
return ctx.mod.InRecovery()
}
@@ -1335,6 +1352,8 @@
// .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
// such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
c.Properties.SubName += vendorSuffix
+ } else if c.InRamdisk() && !c.OnlyInRamdisk() {
+ c.Properties.SubName += ramdiskSuffix
} else if c.InRecovery() && !c.OnlyInRecovery() {
c.Properties.SubName += recoverySuffix
}
@@ -1444,7 +1463,7 @@
// (unless it is explicitly referenced via .bootstrap suffix or the
// module is marked with 'bootstrap: true').
if c.HasStubsVariants() &&
- android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
+ android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
!c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
c.IsStubs() {
c.Properties.HideFromMake = false // unhide
@@ -1732,7 +1751,7 @@
addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
var variations []blueprint.Variation
variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
- versionVariantAvail := !ctx.useVndk() && !c.InRecovery()
+ versionVariantAvail := !ctx.useVndk() && !c.InRecovery() && !c.InRamdisk()
if version != "" && versionVariantAvail {
// Version is explicitly specified. i.e. libFoo#30
variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
@@ -1863,6 +1882,10 @@
// Platform code can link to anything
return
}
+ if from.InRamdisk() {
+ // Ramdisk code is not NDK
+ return
+ }
if from.InRecovery() {
// Recovery code is not NDK
return
@@ -2123,8 +2146,8 @@
// If not building for APEX, use stubs only when it is from
// an APEX (and not from platform)
useThisDep = (depInPlatform != depIsStubs)
- if c.InRecovery() || c.bootstrap() {
- // However, for recovery or bootstrap modules,
+ if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
+ // However, for ramdisk, recovery or bootstrap modules,
// always link to non-stub variant
useThisDep = !depIsStubs
}
@@ -2275,7 +2298,7 @@
isVendorPublicLib := inList(libName, *vendorPublicLibraries)
bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
- if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRecovery() {
+ if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
// The vendor module is a no-vendor-variant VNDK library. Depend on the
// core module instead.
return libName
@@ -2285,6 +2308,8 @@
return libName + c.getNameSuffixWithVndkVersion(ctx)
} else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
return libName + vendorPublicLibrarySuffix
+ } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
+ return libName + ramdiskSuffix
} else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
return libName + recoverySuffix
} else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
@@ -2369,6 +2394,10 @@
return c.installer.inSanitizerDir()
}
+func (c *Module) InstallInRamdisk() bool {
+ return c.InRamdisk()
+}
+
func (c *Module) InstallInRecovery() bool {
return c.InRecovery()
}
@@ -2441,6 +2470,8 @@
return "native:product"
}
return "native:vendor"
+ } else if c.InRamdisk() {
+ return "native:ramdisk"
} else if c.InRecovery() {
return "native:recovery"
} else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
@@ -2647,6 +2678,7 @@
}
var coreVariantNeeded bool = false
+ var ramdiskVariantNeeded bool = false
var recoveryVariantNeeded bool = false
var vendorVariants []string
@@ -2729,6 +2761,15 @@
productVariants = []string{}
}
+ if Bool(m.Properties.Ramdisk_available) {
+ ramdiskVariantNeeded = true
+ }
+
+ if m.ModuleBase.InstallInRamdisk() {
+ ramdiskVariantNeeded = true
+ coreVariantNeeded = false
+ }
+
if Bool(m.Properties.Recovery_available) {
recoveryVariantNeeded = true
}
@@ -2746,6 +2787,7 @@
m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
}
+ m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
m.Properties.CoreVariantNeeded = coreVariantNeeded
}
@@ -2754,6 +2796,10 @@
return c.Properties.CoreVariantNeeded
}
+func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
+ return c.Properties.RamdiskVariantNeeded
+}
+
func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
return c.Properties.RecoveryVariantNeeded
}
@@ -2764,7 +2810,9 @@
func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
m := module.(*Module)
- if variant == android.RecoveryVariation {
+ if variant == android.RamdiskVariation {
+ m.MakeAsPlatform()
+ } else if variant == android.RecoveryVariation {
m.MakeAsPlatform()
squashRecoverySrcs(m)
} else if strings.HasPrefix(variant, VendorVariationPrefix) {
diff --git a/cc/fuzz.go b/cc/fuzz.go
index 8b84be8..ee24300 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -355,10 +355,10 @@
return
}
- // Discard vendor-NDK-linked + recovery modules, they're duplicates of
+ // Discard vendor-NDK-linked + ramdisk + recovery modules, they're duplicates of
// fuzz targets we're going to package anyway.
if !ccModule.Enabled() || ccModule.Properties.PreventInstall ||
- ccModule.UseVndk() || ccModule.InRecovery() {
+ ccModule.UseVndk() || ccModule.InRamdisk() || ccModule.InRecovery() {
return
}
diff --git a/cc/genrule.go b/cc/genrule.go
index 548d5f2..155e410 100644
--- a/cc/genrule.go
+++ b/cc/genrule.go
@@ -25,6 +25,7 @@
type GenruleExtraProperties struct {
Vendor_available *bool
+ Ramdisk_available *bool
Recovery_available *bool
}
@@ -62,6 +63,10 @@
return Bool(g.Vendor_available) || !(ctx.SocSpecific() || ctx.DeviceSpecific())
}
+func (g *GenruleExtraProperties) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
+ return Bool(g.Ramdisk_available)
+}
+
func (g *GenruleExtraProperties) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
return Bool(g.Recovery_available)
}
diff --git a/cc/library.go b/cc/library.go
index f29c4d0..14a7536 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1040,7 +1040,7 @@
isVendor := ctx.useVndk()
isOwnerPlatform := Bool(library.Properties.Sysprop.Platform)
- if !ctx.inRecovery() && (isProduct || (isOwnerPlatform == isVendor)) {
+ if !ctx.inRamdisk() && !ctx.inRecovery() && (isProduct || (isOwnerPlatform == isVendor)) {
dir = android.PathForModuleGen(ctx, "sysprop/public", "include")
}
}
@@ -1118,7 +1118,7 @@
// The original path becomes a symlink to the corresponding file in the
// runtime APEX.
translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled
- if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !library.buildStubs() && !translatedArch && !ctx.inRecovery() {
+ if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !library.buildStubs() && !translatedArch && !ctx.inRamdisk() && !ctx.inRecovery() {
if ctx.Device() {
library.installSymlinkToRuntimeApex(ctx, file)
}
@@ -1133,7 +1133,7 @@
}
if Bool(library.Properties.Static_ndk_lib) && library.static() &&
- !ctx.useVndk() && !ctx.inRecovery() && ctx.Device() &&
+ !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && ctx.Device() &&
library.baseLinker.sanitize.isUnsanitizedVariant() &&
!library.buildStubs() {
installPath := getNdkSysrootBase(ctx).Join(
diff --git a/cc/linkable.go b/cc/linkable.go
index 106092b..3c46d9d 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -38,6 +38,9 @@
Shared() bool
Toc() android.OptionalPath
+ InRamdisk() bool
+ OnlyInRamdisk() bool
+
InRecovery() bool
OnlyInRecovery() bool
diff --git a/cc/sanitize.go b/cc/sanitize.go
index c4aeb96..93c4b41 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -351,8 +351,8 @@
}
// HWASan ramdisk (which is built from recovery) goes over some bootloader limit.
- // Keep libc instrumented so that recovery can run hwasan-instrumented code if necessary.
- if ctx.inRecovery() && !strings.HasPrefix(ctx.ModuleDir(), "bionic/libc") {
+ // Keep libc instrumented so that ramdisk / recovery can run hwasan-instrumented code if necessary.
+ if (ctx.inRamdisk() || ctx.inRecovery()) && !strings.HasPrefix(ctx.ModuleDir(), "bionic/libc") {
s.Hwaddress = nil
}
diff --git a/genrule/genrule.go b/genrule/genrule.go
index c5aaed2..a0008d3 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -550,6 +550,7 @@
func (x noopImageInterface) ImageMutatorBegin(android.BaseModuleContext) {}
func (x noopImageInterface) CoreVariantNeeded(android.BaseModuleContext) bool { return false }
+func (x noopImageInterface) RamdiskVariantNeeded(android.BaseModuleContext) bool { return false }
func (x noopImageInterface) RecoveryVariantNeeded(android.BaseModuleContext) bool { return false }
func (x noopImageInterface) ExtraImageVariations(ctx android.BaseModuleContext) []string { return nil }
func (x noopImageInterface) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
diff --git a/rust/rust.go b/rust/rust.go
index 14513fb..e2af6f0 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -85,6 +85,10 @@
return true
}
+func (mod *Module) RamdiskVariantNeeded(android.BaseModuleContext) bool {
+ return mod.InRamdisk()
+}
+
func (mod *Module) RecoveryVariantNeeded(android.BaseModuleContext) bool {
return mod.InRecovery()
}
@@ -152,6 +156,10 @@
panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
}
+func (mod *Module) OnlyInRamdisk() bool {
+ return false
+}
+
func (mod *Module) OnlyInRecovery() bool {
return false
}