Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 1 | package fsgen |
| 2 | |
| 3 | import ( |
| 4 | "android/soong/android" |
| 5 | "android/soong/filesystem" |
| 6 | "path/filepath" |
| 7 | |
| 8 | "github.com/google/blueprint/proptools" |
| 9 | ) |
| 10 | |
| 11 | func createBootImage(ctx android.LoadHookContext) bool { |
| 12 | partitionVariables := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
| 13 | |
| 14 | if partitionVariables.TargetKernelPath == "" { |
| 15 | // There are potentially code paths that don't set TARGET_KERNEL_PATH |
| 16 | return false |
| 17 | } |
| 18 | |
| 19 | kernelDir := filepath.Dir(partitionVariables.TargetKernelPath) |
| 20 | kernelBase := filepath.Base(partitionVariables.TargetKernelPath) |
| 21 | kernelFilegroupName := generatedModuleName(ctx.Config(), "kernel") |
| 22 | |
| 23 | ctx.CreateModuleInDirectory( |
| 24 | android.FileGroupFactory, |
| 25 | kernelDir, |
| 26 | &struct { |
| 27 | Name *string |
| 28 | Srcs []string |
| 29 | Visibility []string |
| 30 | }{ |
| 31 | Name: proptools.StringPtr(kernelFilegroupName), |
| 32 | Srcs: []string{kernelBase}, |
| 33 | Visibility: []string{"//visibility:public"}, |
| 34 | }, |
| 35 | ) |
| 36 | |
| 37 | bootImageName := generatedModuleNameForPartition(ctx.Config(), "boot") |
| 38 | |
| 39 | ctx.CreateModule( |
| 40 | filesystem.BootimgFactory, |
| 41 | &filesystem.BootimgProperties{ |
| 42 | Kernel_prebuilt: proptools.StringPtr(":" + kernelFilegroupName), |
| 43 | Ramdisk_module: proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "ramdisk")), |
| 44 | Header_version: proptools.StringPtr(partitionVariables.BoardBootHeaderVersion), |
| 45 | }, |
| 46 | &struct { |
| 47 | Name *string |
| 48 | }{ |
| 49 | Name: proptools.StringPtr(bootImageName), |
| 50 | }, |
| 51 | ) |
| 52 | return true |
| 53 | } |
| 54 | |
| 55 | // Returns the equivalent of the BUILDING_BOOT_IMAGE variable in make. Derived from this logic: |
| 56 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/board_config.mk;l=458;drc=5b55f926830963c02ab1d2d91e46442f04ba3af0 |
| 57 | func buildingBootImage(partitionVars android.PartitionVariables) bool { |
| 58 | if partitionVars.BoardUsesRecoveryAsBoot { |
| 59 | return false |
| 60 | } |
| 61 | |
| 62 | if partitionVars.ProductBuildBootImage { |
| 63 | return true |
| 64 | } |
| 65 | |
| 66 | if len(partitionVars.BoardPrebuiltBootimage) > 0 { |
| 67 | return false |
| 68 | } |
| 69 | |
| 70 | if len(partitionVars.BoardBootimagePartitionSize) > 0 { |
| 71 | return true |
| 72 | } |
| 73 | |
| 74 | // TODO: return true if BOARD_KERNEL_BINARIES is set and has a *_BOOTIMAGE_PARTITION_SIZE |
| 75 | // variable. However, I don't think BOARD_KERNEL_BINARIES is ever set in practice. |
| 76 | |
| 77 | return false |
| 78 | } |