diff options
author | 2024-11-15 00:15:03 +0000 | |
---|---|---|
committer | 2024-11-15 00:15:03 +0000 | |
commit | 3d817e8c014beae37407a7adaae2c2c625dd74fd (patch) | |
tree | 0f37c0c5d8276e5c5830981ff44d21b201b06bdb /fsgen/filesystem_creator.go | |
parent | 79a70ac66e8d23052579eaeb6fdfc2db9a3ef1d8 (diff) | |
parent | 953476f26e0cf21af707c8c1a3d4b31841110b79 (diff) |
Merge "Fix missing avb keys" into main
Diffstat (limited to 'fsgen/filesystem_creator.go')
-rw-r--r-- | fsgen/filesystem_creator.go | 82 |
1 files changed, 74 insertions, 8 deletions
diff --git a/fsgen/filesystem_creator.go b/fsgen/filesystem_creator.go index d46f67904..c74579aba 100644 --- a/fsgen/filesystem_creator.go +++ b/fsgen/filesystem_creator.go @@ -64,6 +64,7 @@ func filesystemCreatorFactory() android.Module { generatedPrebuiltEtcModuleNames := createPrebuiltEtcModules(ctx) avbpubkeyGenerated := createAvbpubkeyModule(ctx) createFsGenState(ctx, generatedPrebuiltEtcModuleNames, avbpubkeyGenerated) + module.createAvbKeyFilegroups(ctx) module.createInternalModules(ctx) }) @@ -254,6 +255,51 @@ func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partiti return true } +// Creates filegroups for the files specified in BOARD_(partition_)AVB_KEY_PATH +func (f *filesystemCreator) createAvbKeyFilegroups(ctx android.LoadHookContext) { + partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse + var files []string + + if len(partitionVars.BoardAvbKeyPath) > 0 { + files = append(files, partitionVars.BoardAvbKeyPath) + } + for _, partition := range android.SortedKeys(partitionVars.PartitionQualifiedVariables) { + specificPartitionVars := partitionVars.PartitionQualifiedVariables[partition] + if len(specificPartitionVars.BoardAvbKeyPath) > 0 { + files = append(files, specificPartitionVars.BoardAvbKeyPath) + } + } + + fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState) + for _, file := range files { + if _, ok := fsGenState.avbKeyFilegroups[file]; ok { + continue + } + if file == "external/avb/test/data/testkey_rsa4096.pem" { + // There already exists a checked-in filegroup for this commonly-used key, just use that + fsGenState.avbKeyFilegroups[file] = "avb_testkey_rsa4096" + continue + } + dir := filepath.Dir(file) + base := filepath.Base(file) + name := fmt.Sprintf("avb_key_%x", strings.ReplaceAll(file, "/", "_")) + ctx.CreateModuleInDirectory( + android.FileGroupFactory, + dir, + &struct { + Name *string + Srcs []string + Visibility []string + }{ + Name: proptools.StringPtr(name), + Srcs: []string{base}, + Visibility: []string{"//visibility:public"}, + }, + ) + fsGenState.avbKeyFilegroups[file] = name + } +} + // createPrebuiltKernelModules creates `prebuilt_kernel_modules`. These modules will be added to deps of the // autogenerated *_dlkm filsystem modules. Each _dlkm partition should have a single prebuilt_kernel_modules dependency. // This ensures that the depmod artifacts (modules.* installed in /lib/modules/) are generated with a complete view. @@ -419,21 +465,41 @@ func generateBaseProps(namePtr *string) *filesystemBaseProperty { } func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*filesystem.FilesystemProperties, bool) { + fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState) fsProps := &filesystem.FilesystemProperties{} partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse - var specificPartitionVars android.PartitionQualifiedVariablesType var boardAvbEnable bool + var boardAvbKeyPath string + var boardAvbAlgorithm string + var boardAvbRollbackIndex string var fsType string if strings.Contains(partitionType, "ramdisk") { fsType = "compressed_cpio" } else { - specificPartitionVars = partitionVars.PartitionQualifiedVariables[partitionType] - boardAvbEnable = partitionVars.BoardAvbEnable + specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType] fsType = specificPartitionVars.BoardFileSystemType + boardAvbEnable = partitionVars.BoardAvbEnable + boardAvbKeyPath = specificPartitionVars.BoardAvbKeyPath + boardAvbAlgorithm = specificPartitionVars.BoardAvbAlgorithm + boardAvbRollbackIndex = specificPartitionVars.BoardAvbRollbackIndex + if boardAvbEnable { + if boardAvbKeyPath == "" { + boardAvbKeyPath = partitionVars.BoardAvbKeyPath + } + if boardAvbAlgorithm == "" { + boardAvbAlgorithm = partitionVars.BoardAvbAlgorithm + } + if boardAvbRollbackIndex == "" { + boardAvbRollbackIndex = partitionVars.BoardAvbRollbackIndex + } + } + if fsType == "" { + fsType = "ext4" //default + } } - if fsType == "" { - fsType = "ext4" //default + if boardAvbKeyPath != "" { + boardAvbKeyPath = ":" + fsGenState.avbKeyFilegroups[boardAvbKeyPath] } fsProps.Type = proptools.StringPtr(fsType) @@ -449,11 +515,11 @@ func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*fil // BOARD_AVB_ENABLE fsProps.Use_avb = proptools.BoolPtr(boardAvbEnable) // BOARD_AVB_KEY_PATH - fsProps.Avb_private_key = proptools.StringPtr(specificPartitionVars.BoardAvbKeyPath) + fsProps.Avb_private_key = proptools.StringPtr(boardAvbKeyPath) // BOARD_AVB_ALGORITHM - fsProps.Avb_algorithm = proptools.StringPtr(specificPartitionVars.BoardAvbAlgorithm) + fsProps.Avb_algorithm = proptools.StringPtr(boardAvbAlgorithm) // BOARD_AVB_SYSTEM_ROLLBACK_INDEX - if rollbackIndex, err := strconv.ParseInt(specificPartitionVars.BoardAvbRollbackIndex, 10, 64); err == nil { + if rollbackIndex, err := strconv.ParseInt(boardAvbRollbackIndex, 10, 64); err == nil { fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex) } |