Home Forum Blog Private Support Courses
Our courses are now on YouTube! Start Watching
Hovatek Forum OPERATING SYSTEMS Android [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

[Tutorial] How to create a custom signed vbmeta.img for Unisoc using AVBtool

Pages (18): Previous 1 11 12 13 14 15 18 Next
ardv
ardv
ardv
Enthusiastic Member
5
28-02-2023, 06:52 AM



(27-02-2023, 02:10 AM)Kelexine Yeah, as far as the firmwares contains -sign.img or -sign.bin

that two firmwares i found doesnt have sign.img not sign.bin
safin252
safin252
safin252
Senior Member
192
24-04-2023, 04:23 AM
(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

[Image: attachment.php?aid=7851]

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

mine is 16384 ....how can i convert hex string as you said can you tell me in details?
itapi
itapi
itapi
Enthusiastic Member
6
16-06-2023, 12:17 PM
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:
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
I guess it would be a bit different work with the partition signing etc...?right?
can you just write a few words about the stages I need to do in order to do that?
Thank you so so much!
Rana583
Rana583
Rana583
Newbie
3
22-06-2023, 03:23 PM
I am getting Errors at creating customsignedvbmeta.img. Can someone help
safin252
safin252
safin252
Senior Member
192
23-06-2023, 04:52 AM

Mediatek Course Mediatek Course


(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:
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
I guess it would be a bit different work with the partition signing etc...?right?
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?
itapi
itapi
itapi
Enthusiastic Member
6
03-07-2023, 05:18 PM
(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:
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
I guess it would be a bit different work with the partition signing etc...?right?
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...Smile
And what about mtk/qualcomm devices?

Thanks in advance ,me
safin252
safin252
safin252
Senior Member
192
03-07-2023, 05:29 PM
(03-07-2023, 05:18 PM)itapi
(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:
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
I guess it would be a bit different work with the partition signing etc...?right?
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...Smile
And what about mtk/qualcomm devices?

Thanks in advance ,me
nope..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
safin252
safin252
safin252
Senior Member
192
03-07-2023, 05:34 PM
(22-06-2023, 03:23 PM)Rana583 I am getting Errors at creating customsignedvbmeta.img. Can someone help

which error send ss
itapi
itapi
itapi
Enthusiastic Member
6
06-07-2023, 03:27 PM
(03-07-2023, 05:29 PM)safin252
(03-07-2023, 05:18 PM)itapi
(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:
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
I guess it would be a bit different work with the partition signing etc...?right?
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...Smile
And what about mtk/qualcomm devices?

Thanks in advance ,me
nope..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

no sir,if you sign both vbmeta and boot(for example) in the same key,you don't need to unlock the bootloader in order to flash them!
and the devices works like charm! no bootloop problems...

try it yourself!
Benja254
Benja254
Benja254
Junior Member
20
01-08-2023, 05:23 PM
(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


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

  1. The files and folders you have should look something like this:

    [Image: custom-signed-vbmeta-requirements.png]

  2. With all the required files in the same folder, launch Terminal by right-clicking in the folder and clicking Open Terminal

  3. 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.

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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.         
Pages (18): Previous 1 11 12 13 14 15 18 Next
Users browsing this thread:
 2 Guest(s)
Users browsing this thread:
 2 Guest(s)
WhTlYt