summaryrefslogtreecommitdiff
path: root/filesystem/filesystem.go
diff options
context:
space:
mode:
author Cole Faust <colefaust@google.com> 2024-11-19 13:37:53 -0800
committer Cole Faust <colefaust@google.com> 2024-11-19 14:49:57 -0800
commit26bdac55ebda7e358c915aeb0711280066de2c7c (patch)
treecc5c47c2099d8ef96d1e0d3c1ee21709bb0b5a4c /filesystem/filesystem.go
parent1c9c335a03a264876e533be9e4ea9d663030b10b (diff)
Add partition size check to boot partitions
Since android devices are partitioned at the factory and the partitions can't be resized aftwards, make allows you to specify that partition size and asserts that the contents don't exceed it. Soong also needed this check. Bug: 377562951 Test: Manually modified BOARD_BOOTIMAGE_PARTITION_SIZE to test the warning and error Change-Id: I2368b350fb99c4055b14baa84b4964012f4934ef
Diffstat (limited to 'filesystem/filesystem.go')
-rw-r--r--filesystem/filesystem.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index 28cec2715..dadacae3d 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -926,3 +926,26 @@ func (f *filesystem) getLibsForLinkerConfig(ctx android.ModuleContext) ([]androi
return provideModules, requireModules
}
+
+// Checks that the given file doesn't exceed the given size, and will also print a warning
+// if it's nearing the maximum size. Equivalent to assert-max-image-size in make:
+// https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/definitions.mk;l=3455;drc=993c4de29a02a6accd60ceaaee153307e1a18d10
+func assertMaxImageSize(builder *android.RuleBuilder, image android.Path, maxSize int64, addAvbLater bool) {
+ if addAvbLater {
+ // The value 69632 is derived from MAX_VBMETA_SIZE + MAX_FOOTER_SIZE in avbtool.
+ // Logic copied from make:
+ // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=228;drc=a6a0007ef24e16c0b79f439beac4a118416717e6
+ maxSize -= 69632
+ }
+ cmd := builder.Command()
+ cmd.Textf(`file="%s"; maxsize="%d";`+
+ `total=$(stat -c "%%s" "$file" | tr -d '\n');`+
+ `if [ "$total" -gt "$maxsize" ]; then `+
+ ` echo "error: $file too large ($total > $maxsize)";`+
+ ` false;`+
+ `elif [ "$total" -gt $((maxsize - 32768)) ]; then `+
+ ` echo "WARNING: $file approaching size limit ($total now; limit $maxsize)";`+
+ `fi`,
+ image, maxSize)
+ cmd.Implicit(image)
+}