cfig / Android_boot_image_editor

Parsing and re-packing Android boot.img/vbmeta.img/payload.bin, supporting Android 15
Apache License 2.0
1.06k stars 234 forks source link

Failed when original image doesn't have AVB footer #137

Closed hamjin closed 10 months ago

hamjin commented 10 months ago

Failed when original image doesn't have AVB footer

11:48:40.320 [main] WARN  cfig.packable.PackableLauncher - [boot.img] will be handled by [BootImgParser]
11:48:40.386 [main] WARN  cfig.packable.PackableLauncher - 'pack' sequence initialized
11:48:40.387 [main] INFO  cfig.packable.BootImgParser - Loading config from build/unzip_boot/boot.json
11:48:40.506 [main] INFO  cfig.bootimg.v3.BootV3 - Writing data ...
11:48:40.703 [main] INFO  cfig.bootimg.v3.BootV3 - [python, aosp/system/tools/mkbootimg/mkbootimg.py, --header_version, 4, --kernel, build/unzip_boot/kernel, --id, --output, boot.img.google]
11:48:40.915 [main] INFO  Helper - boot.img.clear hash e74c0e74dac2a5e37afab660174fa42653af94ff, boot.img.google hash e74c0e74dac2a5e37afab660174fa42653af94ff
11:48:40.915 [main] INFO  Helper - Hash verification passed: e74c0e74dac2a5e37afab660174fa42653af94ff
11:48:40.918 [main] INFO  cfig.bootimg.Signer - Adding hash_footer with verified-boot 2.0 style
11:48:40.995 [main] INFO  cfig.Avb - addHashFooter(boot.img.signed) ...
11:48:40.998 [main] INFO  cfig.Avb - max_image_size: 67039232
11:48:41.000 [main] INFO  cfig.Avb - original image boot.img.signed doesn't have AVB footer
11:48:41.003 [main] INFO  avb.desc.HashDescriptor - preset salt[32] is valid: fee26850765b9f55f73e2848f5253596918e1cc23012ee0cf22d635c76fe5709
11:48:41.003 [main] INFO  avb.desc.HashDescriptor - flag: use_ab = 1
11:48:41.035 [main] INFO  avb.desc.HashDescriptor - Digest(salt + file): d0bda0347c2f41476ffa1398b821331166c9c6e5c7d2d487a4841a31d8b5963d
11:48:41.036 [main] INFO  cfig.Avb - updated hash descriptor:000000000000000200000000000000b800000000011eb000736861323536000000000000000000000000000000000000000000000000000000000004000000200000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000626f6f74fee26850765b9f55f73e2848f5253596918e1cc23012ee0cf22d635c76fe5709d0bda0347c2f41476ffa1398b821331166c9c6e5c7d2d487a4841a31d8b5963d
11:48:41.053 [main] WARN  avb.blob.AuxBlob - Using different key from original vbmeta
11:48:41.053 [main] INFO  avb.blob.AuxBlob - no pubkey metadata in auxBlob
11:48:41.114 [main] WARN avb.blob.AuxBlob - Using different key from original vbmeta
11:48:41.114 [main] INFO  avb.blob.AuxBlob - no pubkey metadata in auxBlob
11:48:41.127 [main] INFO  cfig.Avb - Footer(versionMajor=1, versionMinor=0, originalImageSize=18788352, vbMetaOffset=18788352, vbMetaSize=1664)
11:48:41.128 [main] INFO  cfig.Avb - 1/4 Padding image with 0 bytes ...
11:48:41.130 [main] INFO  cfig.Avb - 2/4 Appending vbmeta (4096 bytes)...
11:48:41.130 [main] INFO  cfig.Avb - 3/4 Appending DONT CARE CHUNK (48312320 bytes) ...
11:48:41.210 [main] INFO  cfig.Avb - 4/4 Appending AVB footer (4096 bytes)...
11:48:41.211 [main] INFO  cfig.Avb - addHashFooter(boot.img.signed) done.
11:48:41.212 [main] INFO  cfig.bootimg.Signer - [python, aosp/avb/avbtool.v1.2.py, add_hash_footer, --image, boot.img.signed2, --flags, 0, --partition_size, 67108864, --salt, fee26850765b9f55f73e2848f5253596918e1cc23012ee0cf22d635c76fe5709, --partition_name, boot, --hash_algorithm, sha256, --algorithm, SHA256_RSA2048, --rollback_index, 0, --key, aosp/avb/data/testkey_rsa2048.pem, --prop, com.android.build.boot.os_version:13, --prop, com.android.build.boot.fingerprint:Xiaomi/hal_mgvi_64_armv82_mt6985_cn/mgvi_64_armv82:13/TP1A.220624.014/V816.0.9.0.UMLCNXM:user/release-keys, --prop, com.android.build.boot.security_patch:2024-01-01, --internal_release_string, avbtool 1.2.0]
aosp/avb/avbtool.v1.2.py: Adding hash_footer failed: [WinError 2] 系统找不到指定的文件。.
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97)
        at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Instance.call(CallerImpl.kt:113)
        at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:108)
        at cfig.packable.PackableLauncherKt.main(PackableLauncher.kt:120)
Caused by: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
        at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
        at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
        at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:153)
        at cfig.bootimg.Signer$Companion.signAVB(Signer.kt:70)
        at cfig.bootimg.v3.BootV3.sign(BootV3.kt:207)
        at cfig.packable.BootImgParser.pack(BootImgParser.kt:95)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        ... 5 more

image Original boot is extracted from Redmi K60 Ultra Xiaomi HyperOS OS1.0.9.0.UMLCNXM boot.img.gz

cfig commented 10 months ago

I tried the boot.img under Windows with PowerShell, "pack" works fine. Can you manually try the command below?

cp boot.img.clear boot.img.signed2
python aosp/avb/avbtool.v1.2.py add_hash_footer --image boot.img.signed2 --flags 0 --partition_size 67108864 --salt fee26850765b9f55f73e2848f5253596918e1cc23012ee0cf22d635c76fe5709 --partition_name boot --hash_algorithm sha256 --algorithm SHA256_RSA2048 --rollback_index 0 --key aosp/avb/data/testkey_rsa2048.pem --prop com.android.build.boot.os_version:13 --prop com.android.build.boot.fingerprint:Xiaomi/hal_mgvi_64_armv82_mt6985_cn/mgvi_64_armv82:13/TP1A.220624.014/V816.0.9.0.UMLCNXM:user/release-keys --prop com.android.build.boot.security_patch:2024-01-01 --internal_release_string "avbtool 1.2.0"
starbucks2010 commented 10 months ago

hi,

I'm getting the same error when trying to work on a samsung vendor_boot. Even trying the 2 commands from above (adapted to my details). I tried both, wincmd and powershell.

thanks

hamjin commented 10 months ago

cp boot.img.clear boot.img.signed2 python aosp/avb/avbtool.v1.2.py add_hash_footer --image boot.img.signed2 --flags 0 --partition_size 67108864 --salt fee26850765b9f55f73e2848f5253596918e1cc23012ee0cf22d635c76fe5709 --partition_name boot --hash_algorithm sha256 --algorithm SHA256_RSA2048 --rollback_index 0 --key aosp/avb/data/testkey_rsa2048.pem --prop com.android.build.boot.os_version:13 --prop com.android.build.boot.fingerprint:Xiaomi/hal_mgvi_64_armv82_mt6985_cn/mgvi_64_armv82:13/TP1A.220624.014/V816.0.9.0.UMLCNXM:user/release-keys --prop com.android.build.boot.security_patch:2024-01-01 --internal_release_string "avbtool 1.2.0"

Tried and found that openssl is still missing after choco install openssl. After choco install openssl --force the problem is solved