[Tutorial] How to create a custom signed vbmeta.img for Unisoc using AVBtool
[Tutorial] How to create a custom signed vbmeta.img for Unisoc using AVBtool
(30-05-2020, 10:12 PM)X3non(30-05-2020, 10:55 AM)mainframe Thanks for a great indepth guide. I was wondering how can i determine the padding used the stock image? The guide uses a 16k padding because the stock has that aswel, but can i check/verify the padding?
Thanks.
open the original vbmeta using hxd
search for text-string : DHTB
after the DHTB section you'll find a string similar to the ss below
convert that to little endian using the link @ https://www.scadacore.com/tools/programm...converter/
PS. if you have
00 50 00 00 then padding size = 20480
00 40 00 00 then padding size = 16384
00 30 00 00 then padding size = 12288
Minimum libavb version: 1.0
Header Block: 256 bytes
Authentication Block: 320 bytes
Auxiliary Block: 1664 bytes
Public key (sha1): fa41159a5d696abdef93176a07d0b0d001263f01
Algorithm: SHA256_RSA2048
Rollback Index: 0
Flags: 0
Rollback Index Location: 0
Release String: 'avbtool 1.2.0'
Descriptors:
Prop: com.android.build.product.fingerprint -> 'Blackview/Tab_13/Tab_13:12/SP1A.210812.016/1660223750:user/release-keys'
Prop: com.android.build.product.os_version -> '12'
Prop: com.android.build.product.security_patch -> '2022-06-05'
Prop: com.android.build.system.fingerprint -> 'Blackview/Tab_13/Tab_13:12/SP1A.210812.016/1660223750:user/release-keys'
Prop: com.android.build.system.os_version -> '12'
Prop: com.android.build.system.security_patch -> '2022-06-05'
Hashtree descriptor:
Version of dm-verity: 1
Image Size: 2136846336 bytes
Tree Offset: 2136846336
Tree Size: 16830464 bytes
Data Block Size: 4096 bytes
Hash Block Size: 4096 bytes
FEC num roots: 2
FEC offset: 2153676800
FEC size: 17031168 bytes
Hash Algorithm: sha256
Partition Name: product
Salt: c81f7f13c44dc09fc9edb2a1273ece94d560ed3de5b12c65339811e9679856fc
Root Digest: 66cb79ffd367137a19b95658ae5dcccecf6eb8a9a8749d11062a17a3741a5b81
Flags: 0
Hashtree descriptor:
Version of dm-verity: 1
Image Size: 3216822272 bytes
Tree Offset: 3216822272
Tree Size: 25333760 bytes
Data Block Size: 4096 bytes
Hash Block Size: 4096 bytes
FEC num roots: 2
FEC offset: 3242156032
FEC size: 25632768 bytes
Hash Algorithm: sha256
Partition Name: system
Salt: c81f7f13c44dc09fc9edb2a1273ece94d560ed3de5b12c65339811e9679856fc
Root Digest: b00e12e18a89d955d0422476af774c30cb3b360fd62ef5b18f53f398fe0fc1e2
Flags: 0(16-06-2023, 12:17 PM)itapi Hey.
Thank you very much for that awesome informed guide.
I've used it several times on few devices,works as charm!
I've trying now to use it on vbmeta_system ,it's structure looks a bit different,with hash trees,for example:
I guess it would be a bit different work with the partition signing etc...?right?Code:Minimum libavb version: 1.0 Header Block: 256 bytes Authentication Block: 320 bytes Auxiliary Block: 1664 bytes Public key (sha1): fa41159a5d696abdef93176a07d0b0d001263f01 Algorithm: SHA256_RSA2048 Rollback Index: 0 Flags: 0 Rollback Index Location: 0 Release String: 'avbtool 1.2.0' Descriptors: Prop: com.android.build.product.fingerprint -> 'Blackview/Tab_13/Tab_13:12/SP1A.210812.016/1660223750:user/release-keys' Prop: com.android.build.product.os_version -> '12' Prop: com.android.build.product.security_patch -> '2022-06-05' Prop: com.android.build.system.fingerprint -> 'Blackview/Tab_13/Tab_13:12/SP1A.210812.016/1660223750:user/release-keys' Prop: com.android.build.system.os_version -> '12' Prop: com.android.build.system.security_patch -> '2022-06-05' Hashtree descriptor: Version of dm-verity: 1 Image Size: 2136846336 bytes Tree Offset: 2136846336 Tree Size: 16830464 bytes Data Block Size: 4096 bytes Hash Block Size: 4096 bytes FEC num roots: 2 FEC offset: 2153676800 FEC size: 17031168 bytes Hash Algorithm: sha256 Partition Name: product Salt: c81f7f13c44dc09fc9edb2a1273ece94d560ed3de5b12c65339811e9679856fc Root Digest: 66cb79ffd367137a19b95658ae5dcccecf6eb8a9a8749d11062a17a3741a5b81 Flags: 0 Hashtree descriptor: Version of dm-verity: 1 Image Size: 3216822272 bytes Tree Offset: 3216822272 Tree Size: 25333760 bytes Data Block Size: 4096 bytes Hash Block Size: 4096 bytes FEC num roots: 2 FEC offset: 3242156032 FEC size: 25632768 bytes Hash Algorithm: sha256 Partition Name: system Salt: c81f7f13c44dc09fc9edb2a1273ece94d560ed3de5b12c65339811e9679856fc Root Digest: b00e12e18a89d955d0422476af774c30cb3b360fd62ef5b18f53f398fe0fc1e2 Flags: 0
can you just write a few words about the stages I need to do in order to do that?
Thank you so so much!
(23-06-2023, 04:52 AM)safin252(16-06-2023, 12:17 PM)itapi Hey.
Thank you very much for that awesome informed guide.
I've used it several times on few devices,works as charm!
I've trying now to use it on vbmeta_system ,it's structure looks a bit different,with hash trees,for example:
I guess it would be a bit different work with the partition signing etc...?right?Code:Minimum libavb version: 1.0 Header Block: 256 bytes Authentication Block: 320 bytes Auxiliary Block: 1664 bytes Public key (sha1): fa41159a5d696abdef93176a07d0b0d001263f01 Algorithm: SHA256_RSA2048 Rollback Index: 0 Flags: 0 Rollback Index Location: 0 Release String: 'avbtool 1.2.0' Descriptors: Prop: com.android.build.product.fingerprint -> 'Blackview/Tab_13/Tab_13:12/SP1A.210812.016/1660223750:user/release-keys' Prop: com.android.build.product.os_version -> '12' Prop: com.android.build.product.security_patch -> '2022-06-05' Prop: com.android.build.system.fingerprint -> 'Blackview/Tab_13/Tab_13:12/SP1A.210812.016/1660223750:user/release-keys' Prop: com.android.build.system.os_version -> '12' Prop: com.android.build.system.security_patch -> '2022-06-05' Hashtree descriptor: Version of dm-verity: 1 Image Size: 2136846336 bytes Tree Offset: 2136846336 Tree Size: 16830464 bytes Data Block Size: 4096 bytes Hash Block Size: 4096 bytes FEC num roots: 2 FEC offset: 2153676800 FEC size: 17031168 bytes Hash Algorithm: sha256 Partition Name: product Salt: c81f7f13c44dc09fc9edb2a1273ece94d560ed3de5b12c65339811e9679856fc Root Digest: 66cb79ffd367137a19b95658ae5dcccecf6eb8a9a8749d11062a17a3741a5b81 Flags: 0 Hashtree descriptor: Version of dm-verity: 1 Image Size: 3216822272 bytes Tree Offset: 3216822272 Tree Size: 25333760 bytes Data Block Size: 4096 bytes Hash Block Size: 4096 bytes FEC num roots: 2 FEC offset: 3242156032 FEC size: 25632768 bytes Hash Algorithm: sha256 Partition Name: system Salt: c81f7f13c44dc09fc9edb2a1273ece94d560ed3de5b12c65339811e9679856fc Root Digest: b00e12e18a89d955d0422476af774c30cb3b360fd62ef5b18f53f398fe0fc1e2 Flags: 0
can you just write a few words about the stages I need to do in order to do that?
Thank you so so much!
No need to sign system.img in unisoc devices...just open platform tools folder use cmd from there and then u can flash any system img via fastboot mode.... I'm currently experiencing bunch of gsi-s ...At first I thought it requires sign but no...Btw what are you gonna do by signing system.img?

(03-07-2023, 05:18 PM)itapinope..bootloader must be unlocked first otherwise your phone will not allow you to flash anything other than stock stuffs....same goes for mtk/qualcomm devices but unlocking process may be different(23-06-2023, 04:52 AM)safin252(16-06-2023, 12:17 PM)itapi Hey.
Thank you very much for that awesome informed guide.
I've used it several times on few devices,works as charm!
I've trying now to use it on vbmeta_system ,it's structure looks a bit different,with hash trees,for example:
I guess it would be a bit different work with the partition signing etc...?right?Code:Minimum libavb version: 1.0 Header Block: 256 bytes Authentication Block: 320 bytes Auxiliary Block: 1664 bytes Public key (sha1): fa41159a5d696abdef93176a07d0b0d001263f01 Algorithm: SHA256_RSA2048 Rollback Index: 0 Flags: 0 Rollback Index Location: 0 Release String: 'avbtool 1.2.0' Descriptors: Prop: com.android.build.product.fingerprint -> 'Blackview/Tab_13/Tab_13:12/SP1A.210812.016/1660223750:user/release-keys' Prop: com.android.build.product.os_version -> '12' Prop: com.android.build.product.security_patch -> '2022-06-05' Prop: com.android.build.system.fingerprint -> 'Blackview/Tab_13/Tab_13:12/SP1A.210812.016/1660223750:user/release-keys' Prop: com.android.build.system.os_version -> '12' Prop: com.android.build.system.security_patch -> '2022-06-05' Hashtree descriptor: Version of dm-verity: 1 Image Size: 2136846336 bytes Tree Offset: 2136846336 Tree Size: 16830464 bytes Data Block Size: 4096 bytes Hash Block Size: 4096 bytes FEC num roots: 2 FEC offset: 2153676800 FEC size: 17031168 bytes Hash Algorithm: sha256 Partition Name: product Salt: c81f7f13c44dc09fc9edb2a1273ece94d560ed3de5b12c65339811e9679856fc Root Digest: 66cb79ffd367137a19b95658ae5dcccecf6eb8a9a8749d11062a17a3741a5b81 Flags: 0 Hashtree descriptor: Version of dm-verity: 1 Image Size: 3216822272 bytes Tree Offset: 3216822272 Tree Size: 25333760 bytes Data Block Size: 4096 bytes Hash Block Size: 4096 bytes FEC num roots: 2 FEC offset: 3242156032 FEC size: 25632768 bytes Hash Algorithm: sha256 Partition Name: system Salt: c81f7f13c44dc09fc9edb2a1273ece94d560ed3de5b12c65339811e9679856fc Root Digest: b00e12e18a89d955d0422476af774c30cb3b360fd62ef5b18f53f398fe0fc1e2 Flags: 0
can you just write a few words about the stages I need to do in order to do that?
Thank you so so much!
No need to sign system.img in unisoc devices...just open platform tools folder use cmd from there and then u can flash any system img via fastboot mode.... I'm currently experiencing bunch of gsi-s ...At first I thought it requires sign but no...Btw what are you gonna do by signing system.img?
Thanks for your response sir!
Do you achieve to flash custom system img without unlocking the bootloader first?
awesome...
In fact t,his is what I wanted to achieve ...to skip that bootloader unlocking stage...
And what about mtk/qualcomm devices?
Thanks in advance ,me
(03-07-2023, 05:29 PM)safin252(03-07-2023, 05:18 PM)itapinope..bootloader must be unlocked first otherwise your phone will not allow you to flash anything other than stock stuffs....same goes for mtk/qualcomm devices but unlocking process may be different(23-06-2023, 04:52 AM)safin252(16-06-2023, 12:17 PM)itapi Hey.
Thank you very much for that awesome informed guide.
I've used it several times on few devices,works as charm!
I've trying now to use it on vbmeta_system ,it's structure looks a bit different,with hash trees,for example:
I guess it would be a bit different work with the partition signing etc...?right?Code:Minimum libavb version: 1.0 Header Block: 256 bytes Authentication Block: 320 bytes Auxiliary Block: 1664 bytes Public key (sha1): fa41159a5d696abdef93176a07d0b0d001263f01 Algorithm: SHA256_RSA2048 Rollback Index: 0 Flags: 0 Rollback Index Location: 0 Release String: 'avbtool 1.2.0' Descriptors: Prop: com.android.build.product.fingerprint -> 'Blackview/Tab_13/Tab_13:12/SP1A.210812.016/1660223750:user/release-keys' Prop: com.android.build.product.os_version -> '12' Prop: com.android.build.product.security_patch -> '2022-06-05' Prop: com.android.build.system.fingerprint -> 'Blackview/Tab_13/Tab_13:12/SP1A.210812.016/1660223750:user/release-keys' Prop: com.android.build.system.os_version -> '12' Prop: com.android.build.system.security_patch -> '2022-06-05' Hashtree descriptor: Version of dm-verity: 1 Image Size: 2136846336 bytes Tree Offset: 2136846336 Tree Size: 16830464 bytes Data Block Size: 4096 bytes Hash Block Size: 4096 bytes FEC num roots: 2 FEC offset: 2153676800 FEC size: 17031168 bytes Hash Algorithm: sha256 Partition Name: product Salt: c81f7f13c44dc09fc9edb2a1273ece94d560ed3de5b12c65339811e9679856fc Root Digest: 66cb79ffd367137a19b95658ae5dcccecf6eb8a9a8749d11062a17a3741a5b81 Flags: 0 Hashtree descriptor: Version of dm-verity: 1 Image Size: 3216822272 bytes Tree Offset: 3216822272 Tree Size: 25333760 bytes Data Block Size: 4096 bytes Hash Block Size: 4096 bytes FEC num roots: 2 FEC offset: 3242156032 FEC size: 25632768 bytes Hash Algorithm: sha256 Partition Name: system Salt: c81f7f13c44dc09fc9edb2a1273ece94d560ed3de5b12c65339811e9679856fc Root Digest: b00e12e18a89d955d0422476af774c30cb3b360fd62ef5b18f53f398fe0fc1e2 Flags: 0
can you just write a few words about the stages I need to do in order to do that?
Thank you so so much!
No need to sign system.img in unisoc devices...just open platform tools folder use cmd from there and then u can flash any system img via fastboot mode.... I'm currently experiencing bunch of gsi-s ...At first I thought it requires sign but no...Btw what are you gonna do by signing system.img?
Thanks for your response sir!
Do you achieve to flash custom system img without unlocking the bootloader first?
awesome...
In fact t,his is what I wanted to achieve ...to skip that bootloader unlocking stage...
And what about mtk/qualcomm devices?
Thanks in advance ,me
(12-03-2020, 11:51 PM)hovatek can you sign for me ? I have the stock vbmeta-sign.img with me allready If you're into rooting and flashing custom recoveries then Android Verified Boot (AVB) or dmverity is something you should be aware of. We'd dropped a blog post on why dmverity could be causing your phone to get bricked when you try root or flash a custom recovery
A little history
Long ago, one-click root apks were a thing. Not anymore...at least till MTKsu brought back something similar to a few 64 bit Mediatek chipsets. Rooting later moved to flashing a custom recovery and SuperSU.zip...then Magisk came along.
We'd dropped a guide on how to root Android using Magisk Manager and stock boot.img and our Mediatek , Unisoc (Spreadtrum) and Qualcomm auto TWRP porters can give you a working TWRP in seconds.
All this was pretty straightforward till dmverity came along. In the first version, you needed to patch the boot.img. Magisk already does that so no worries there. Android 9 came along with AVB in the vbmeta partition...and things became a little more interesting.
Flashing a blank vbmeta before flashing a magisk patched boot or TWRP custom recovery was the way around...till signed vbmeta came along. What this now means for device's with vbmeta-sign is that you must flash a customised but signed vbmeta before you can tamper with checked partitions.
This guide is going to show you how to do that on Unisoc / Spreadtrum (SPD)
Back to present day...
Luckily, many Unisoc OEMs were lazy enough to use the same key to sign vbmeta, this guide capitalizes on that. I used Ubuntu for this guide because AVBtool kept giving errors. I'll update the guide if a fix for Windows is found.
Requirements
- Before proceeding with the guide below, ensure that you've been able to successfully unlock the bootloader of your device using this guide. If you were unable unlock the bootloader of your device then it's likely the OEM of your device used a custom private key (.pem) and the guide on this thread will NOT work for your device unless you've somehow manage to get the key your OEM used to sign vbmeta. If you have you OEM's key then replace "rsa4096_vbmeta.pem" in the list of requirements with your OEM's key
- vbmeta-sign.img extracted from a pac file for your model
- A Linux based PC. Windows PC users should install python and openssl and ensure to add both to PATH or use Linux Live USB (LiLi) or use VMware or VirtualBox
- Once booted to the Linux OS, ensure to check if python is installed and if it's not then install python
- Download zipped AVBtool (unzip after downloading) @ https://mega.nz/#!s7JEGCbA!9H2KJkppDGYbU...w7yLOHL9KA . Python v3 users can use this avbtool.py @ https://mega.nz/file/VtQlgTBS#Ftvh_waarw...KoiH95VSAo
- Depending on your device, download zipped (unzip after downloading) rsa4096_vbmeta.pem @ https://mega.nz/#!tjAg0K4R!sN-XJJe0ca5Ka...SlDNm59q10 or rsa2048_vbmeta.pem @ https://mega.nz/file/RmwTCIoa#UABBUOsERY...thIu9jtc0g
- Download vbmeta_pad.py based on your phone's stock vbmeta's content from the links below (unzip after downloading)
- For Android 8.x (usually with but not limited to 00 30 00 00 padding), download this zipped vbmeta_pad.py @ https://mega.nz/file/FLY0Eb4Q#zP0YHJPtbH...prKuqBJdR8 or vbmeta_pad.py
- For Android 9 (usually with but not limited to 00 40 00 00 padding) devices, download zipped vbmeta_pad.py @ https://mega.nz/#!5vJGyAib!Q-j402gC_lAO1...zO5MgB6ivg
- For Android 10 (usually with but not limited to 00 50 00 00 padding), download zipped vbmeta_pad.py @ https://mega.nz/file/NWQkTBYJ#Hu28sW9lMh...tsCWg7gNuk
- Extract the public keys from your vbmeta-sign.img as explained @ https://www.hovatek.com/forum/thread-32667.html and copy them into a folder named keys. We provided our vbmeta-sign.img and extracted public keys at the guide. Only use ours if your vbmeta-sign matches ours.
- The modified file you intend to flash to the device (e.g boot.img, recovery.img etc). You only need this to extract certain info
- Know how to check file info using AVBtool (avbtool info_image) as explained @ https://www.hovatek.com/forum/thread-32666.html
- Generate a custom signing .pem key using OpenSSL or you could stick with using rsa4096_vbmeta.pem used to sign vbmeta.
- Check and take note of the padding size of your original vbmeta image using this guide
Steps to create a custom signed vbmeta.img for Unisoc using AVBtool
Follow the steps below to use AVBtool to create a custom signed vbmeta image for Unisoc / Spreadtrum (SPD)
See the video below or @ https://youtu.be/hcUv9EsR4kY
- The files and folders you have should look something like this:
- With all the required files in the same folder, launch Terminal by right-clicking in the folder and clicking Open Terminal
- Run the avbtool info_image command against vbmeta-sign.img, copy out the output and save in a notepad. The vbmeta-sign in our example has a padded size of 16384 and DHTB checksum which needs to be added to the custom vbmeta image later on.
- Generate a public key from the (custom) private key you've decided to use to sign your images going forward. I'll be using an OpenSSL generated key (hovatek.pem) as my custom private key for this guide. Feel free to use rsa4096_vbmeta.pem if you like.
Code:python avbtool extract_public_key --key hovatek.pem --output keys/hovatek.bin
- This command will generate a file named hovatek.bin to the keys folder which will be my public key for signing any partition I wish to flash to
- Generate a vbmeta-sign-custom.img file by running the command below. Note that I intend to flash a custom file to recovery partition so instead of using recovery's public key extracted from vbmeta-sign.img, I'll use my newly generated public key for recovery. Feel free to do same for other partitions you intend to flash to
Code:python avbtool make_vbmeta_image --key rsa4096_vbmeta.pem --algorithm SHA256_RSA4096 --flag 2 --chain_partition boot:1:keys/key_boot.bin --chain_partition system:3:keys/key_system.bin --chain_partition vendor:4:keys/key_vendor.bin --chain_partition product:10:keys/key_product.bin --chain_partition dtbo:9:keys/key_dtbo.bin --chain_partition recovery:2:keys/hovatek.bin --chain_partition l_modem:5:keys/key_l_modem.bin --chain_partition l_ldsp:6:keys/key_l_ldsp.bin --chain_partition l_gdsp:7:keys/key_l_gdsp.bin --chain_partition pm_sys:8:keys/key_pm_sys.bin --chain_partition dtb:11:keys/key_dtb.bin --padding_size 16384 --output vbmeta-sign-custom.img
Note: the value for --algorithm was obtained from reading the vbmeta-sign
- Now I have a 16kb vbmeta-sign-custom.img file. I now need to add DHTB back to the same position as in vbmeta-sign.img . vbmeta_pad.py is the script for that. Run the code below:
Code:python vbmeta_pad.py
- vbmeta-sign-custom.img should now become a 1MB file like vbmeta-sign.img . Now, you can flash vbmeta-sign-custom.img via fastboot
Important Notice
- For models with fastbootd support, you might need to flash vbmeta in fastbootd if flashing in fastboot freezes or gives errors.
- Your boottloader will only accept images signed with the key from which you generated your custom public key
- If you must flash back your stock rom, ensure to flash back your stock vbmeta-sign.img first
- Avoid trying to flash images which haven't been signed with the keys your bootloader is expecting to avoid an endless wait in Research Download tool or stuck at writing in fastboot
- Credits goes to Petercxy
Video Transcript
Quote:In this video tutorial, I'll be explaining how to create a custom signed vmbeta image. These are the files you're going to need: the public keys, you can extract these ones from the stock vbmeta, I'll link to a guide on how to do that. I also have my AVBtool. I have my hovatek.pem. Its a private key which I created with OpenSSL, I'll link to that also. I have my rsa.pem which is my key used to sign my vbmeta image. Once you launch terminal as I did while talking, you run this command. this command is to run a check on the stock vbmeta image so I can get the information I need for future commands like the algorithm used and hashes.
Next, I'm going to create a public key using my private key. I'm using hovatek.pem. You can decide to use the rsa.pem as your private key also even though you're using it to sign vbmeta image. When I run this command, its going to create a file named hovatek.bin in the keys folder. This public key is going to be used to sign any partition I intend to flash a custom image to in the future. I'm going to be signing.. I'm going to be flashing to only recovery so I'm going to be signing only the recovery partition using this public key OK? Now, I'm going to run this command. This command is going to create my custom signed vbmeta image.
Now, I'm using the default public keys (extracted) from my stock vbmeta but for recovery, I'm going to replace the public key with my hovatek.bin public key. That means if I want to flash a recovery image to the recovery partition, I'll need to sign that recovery image using the hovatek.pem . I'll link to a guide on how to do that. Now, this command is going to create a vbmeta image which is 16kb. That's because the stock also has a padded size of 16kb but the overall size of stock is 1MB. That's because there's some Checksum that needs to be applied to a certain position. That's what this script is for, vbmeta_pad.py.
So you run this command also and this is going to generate a 1MB file. This is very identical to the stock. I'm going to run a command to see the information about or of this custom vbmeta image. When you compare it to the stock, you're going to see that its very identical; maybe the flag will just be different, which is 2 to disable verity checks and the hash for recovery partition is going to be different. Every other thing is going to be identical to what I have in stock and they're both the same signature.
You're going to need the keys your OEM used to sign your stock vbmeta if not this guide is not going to work. Unisoc uses the same key across, at least so far uses the same key across their models so I have my vbmeta. You can now flash it using fastboot.