Hovatek Forum DEVELOPMENT Android [Tutorial] How to use AVBtool and a private key to sign a Unisoc (SPD) image
Try our Online TWRP Builder..its free!
Can't login? Please, reset your password.


[Tutorial] How to use AVBtool and a private key to sign a Unisoc (SPD) image

[Tutorial] How to use AVBtool and a private key to sign a Unisoc (SPD) image

Pages (5): Previous 1 2 3 4 5 Next
Gargoyle
Gargoyle
Gargoyle
Contributor
479
22-05-2022, 08:39 PM
#31



Ahmed Jubayer Do i everytime need to flash a custom signed vbmeta before flashing a custom signed image?

or it's an one time process, Once I flashed the custom signed vbmeta from then I can just flash a image directly after signing that image... right?

If you do not change the keys you use to sign the .img, you do not have to flash the signed vbmeta again.
This post was last modified: 22-05-2022, 08:41 PM by Gargoyle.
CarlosCMD
CarlosCMD
CarlosCMD
Junior Member
26
03-02-2023, 12:43 AM
#32
(13-03-2020, 05:32 PM)hovatek This guide will explain how to sign Unisoc / Spreadtrum (SPD) images (e.g boot, recovery, system etc) using a private key and AVBtool. This guide is ideal for those with vbmeta-sign.img in their firmware as such device's will only accept images signed with keys that match what's contained in the device's vbmeta partition.

Requirements

  • An Unlocked Bootloader
  • A custom signed vbmeta image which has already been flashed to the device
  • If you'd replaced the stock public keys for any partition while creating your custom signed vbmeta then you'll need the private key (used to generate your custom public key) for signing any image you intend to flash to that partition. I'd used hovatek.pem
  • A Linux based PC. Windows users can use Vmware or Linux Live USB. I'm using Ubuntu via Live USB on my Windows PC for this guide
  • Download zipped AVBtool python script (unzip after downloading) @ https://mega.nz/#!s7JEGCbA!9H2KJkppDGYbU...w7yLOHL9KA
  • The image you intend to flash and its stock version (e.g twrp image and stock recovery image). This guide will be using recovery_stock.img (stock) and recovery_magisk.img (magisk patched recovery).

Steps to use AVBtool and a private key to sign a Unisoc (SPD) image


Follow the steps below to sign boot.img, recovery.img etc images using avbtool


See the video below or @ https://youtu.be/ggUcN4xcLkI


  1. Right-click in the folder where all your files are (avbtool, key and images) and click Open in Terminal

  2. Run this command

    Code:

    python avbtool info_image --image recovery_stock.img

  3. You should get an output like:

    Code:

    Footer version:           1.0
    Image size:               41943040 bytes
    Original image size:      23742464 bytes
    VBMeta offset:            23744512
    VBMeta size:              2112 bytes
    --
    Minimum libavb version:   1.0
    Header Block:             256 bytes
    Authentication Block:     576 bytes
    Auxiliary Block:          1280 bytes
    Algorithm:                SHA256_RSA4096
    Rollback Index:           0
    Flags:                    0
    Release String:           'avbtool 1.1.0'
    Descriptors:
        Hash descriptor:
          Image Size:            23742464 bytes
          Hash Algorithm:        sha256
          Partition Name:        recovery
          Salt:                  6d13e635e505f337460c4e0f9d22be4a96518ceee422511cca6c6113cd96fa25
          Digest:                75ab9441053eb877eb2c95f1dd3474beeead5437a9a16c3d09efe931c4d16693
          Flags:                 0

  4. From the output, take note of the Image size, Algorithm and Partition Name  . You'll need them in the next command. Next, run:

    Code:

    python avbtool add_hash_footer --image recovery_magisk.img --partition_name recovery --partition_size 41943040 --key hovatek.pem --algorithm SHA256_RSA4096

  5. Now, you'll have a magisk patched recovery image which is identical in size to stock and has been signed with your private key.

Important Notice
  • If you encounter an error such as avbtool: Image size of 36700160 exceeds maximum image size of 36630528 in order to fit in a partition size of 36700160 , simply unpack and repack your magisk patched boot image using Android Image Kitchen. This will reduce the size.
  • Recall I'd used hovatek.pem private key to create hovatek.bin public key which I'd then used to sign recovery partition when creating my custom signed vbmeta. The custom signed vbmeta first needs to have been flashed to the device else it won't accept this newly signed recovery image
  • You can repeat the same procedure for other partitions. Just replace recovery in the command with the partition name e.g system. You also need to have signed that partition using your custom public key back when creating your custom signed vbmeta
  • Credits goes to Petercxy
Am getting this error on termux. Also the same in windows. Help
Attached Files
.png
Screenshot_20230203-023949.png
Size: 458.72 KB / Downloads: 7
hovatek
hovatek
hovatek
Administrator
49,585
09-02-2023, 11:15 AM
#33
(03-02-2023, 12:43 AM)CarlosCMD Am getting this error on termux. Also the same in windows. Help

Create a thread by clicking Ask Question at the top

Note!
We have a reply schedule for Free Support. Please upgrade to Private Support if you can't wait.
Benja254
Benja254
Benja254
Junior Member
20
04-08-2023, 12:23 PM
#34
(13-03-2020, 05:32 PM)hovatek This guide will explain how to sign Unisoc / Spreadtrum (SPD) images (e.g boot, recovery, system etc) using a private key and AVBtool. This guide is ideal for those with vbmeta-sign.img in their firmware as such device's will only accept images signed with keys that match what's contained in the device's vbmeta partition.

Requirements

  • An Unlocked Bootloader
  • A custom signed vbmeta image which has already been flashed to the device
  • If you'd replaced the stock public keys for any partition while creating your custom signed vbmeta then you'll need the private key (used to generate your custom public key) for signing any image you intend to flash to that partition. I'd used hovatek.pem
  • A Linux based PC. Windows users can use Vmware or Linux Live USB. I'm using Ubuntu via Live USB on my Windows PC for this guide
  • Download zipped AVBtool python script (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
  • The image you intend to flash and its stock version (e.g twrp image and stock recovery image). This guide will be using recovery_stock.img (stock) and recovery_magisk.img (magisk patched recovery).

Steps to use AVBtool and a private key to sign a Unisoc (SPD) image


Follow the steps below to sign boot.img, recovery.img etc images using avbtool


See the video below or @ https://youtu.be/ggUcN4xcLkI


  1. Right-click in the folder where all your files are (avbtool, key and images) and click Open in Terminal

  2. Run this command

    Code:

    python avbtool info_image --image recovery_stock.img

  3. You should get an output like:

    Code:

    Footer version:           1.0
    Image size:               41943040 bytes
    Original image size:      23742464 bytes
    VBMeta offset:            23744512
    VBMeta size:              2112 bytes
    --
    Minimum libavb version:   1.0
    Header Block:             256 bytes
    Authentication Block:     576 bytes
    Auxiliary Block:          1280 bytes
    Algorithm:                SHA256_RSA4096
    Rollback Index:           0
    Flags:                    0
    Release String:           'avbtool 1.1.0'
    Descriptors:
        Hash descriptor:
          Image Size:            23742464 bytes
          Hash Algorithm:        sha256
          Partition Name:        recovery
          Salt:                  6d13e635e505f337460c4e0f9d22be4a96518ceee422511cca6c6113cd96fa25
          Digest:                75ab9441053eb877eb2c95f1dd3474beeead5437a9a16c3d09efe931c4d16693
          Flags:                 0

  4. From the output, take note of the Image size, Algorithm and Partition Name  . You'll need them in the next command. Next, run:

    Code:

    python avbtool add_hash_footer --image recovery_magisk.img --partition_name recovery --partition_size 41943040 --key hovatek.pem --algorithm SHA256_RSA4096

  5. Now, you'll have a magisk patched recovery image which is identical in size to stock and has been signed with your private key.

Important Notice
  • If you encounter an error such as avbtool: Image size of 36700160 exceeds maximum image size of 36630528 in order to fit in a partition size of 36700160 , simply unpack and repack your magisk patched boot image using Android Image Kitchen. This will reduce the size.
  • Recall I'd used hovatek.pem private key to create hovatek.bin public key which I'd then used to sign recovery partition when creating my custom signed vbmeta. The custom signed vbmeta first needs to have been flashed to the device else it won't accept this newly signed recovery image
  • You can repeat the same procedure for other partitions. Just replace recovery in the command with the partition name e.g system. You also need to have signed that partition using your custom public key back when creating your custom signed vbmeta
  • Credits goes to Petercxy

What if the signed custom recovery ain't working and i want to revert back to stock recovery do i need to sign it too since am using a custom signed vbmeta?
Gargoyle
Gargoyle
Gargoyle
Contributor
479
04-08-2023, 02:20 PM
#35



The easiest will be to sign the stock recovery with the same key that is in the custom vbmeta.
Benja254
Benja254
Benja254
Junior Member
20
05-08-2023, 09:23 PM
#36
(04-08-2023, 02:20 PM)Gargoyle The easiest will be to sign the stock recovery with the same key that is in the custom vbmeta.

Ok ...now what about gsi do i need to sign the system partition too with custom key whether flashing with twrp or fastboot 
And is my command correct signing two partitions at the same time 

avbtool make_vbmeta_image --key rsa4096_vbmeta.pem --algorithm SHA256_RSA4096 --flag 2 --chain_partition boot:1:keys/hovatek.bin --chain_partition vbmeta_system:3:keys/key_vbmeta_system.bin --chain_partition vbmeta_vendor:4:keys/key_vbmeta_vendor.bin --chain_partition socko:10:keys/key_socko.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 odmko:11:keys/key_odmko.bin --padding_size 16384 --output vbmeta-sign-custom.img
Gargoyle
Gargoyle
Gargoyle
Contributor
479
05-08-2023, 09:44 PM
#37
(05-08-2023, 09:23 PM)Benja254
(04-08-2023, 02:20 PM)Gargoyle The easiest will be to sign the stock recovery with the same key that is in the custom vbmeta.

Ok ...now what about gsi do i need to sign the system partition too with custom key whether flashing with twrp or fastboot 
And is my command correct signing two partitions at the same time 
the system partition does not need to be signed
Benja254
Benja254
Benja254
Junior Member
20
22-11-2023, 01:50 PM
#38
(13-03-2020, 05:32 PM)hovatek ..

Custom vbmeta made successfully using this guide also patched boot by magisk roots the phone......noe thr issue lies on the recovery part ..... I signed twrp using the same key but it never booted i signed the stock Recovery it refuses to boot to it too stays on the flag lock is unlock but the phone boots normally i can i get the Recovery to boot....it fails to flash in fastboot and fastbootd is now gone
This post was last modified: 23-11-2023, 11:49 AM by hovatek.
hovatek
hovatek
hovatek
Administrator
49,585
23-11-2023, 11:51 AM
#39
(22-11-2023, 01:50 PM)Benja254 Custom vbmeta made successfully using this guide also patched boot by magisk roots the phone......noe thr issue lies on the recovery part ..... I signed twrp using the same key but it never booted i signed the stock Recovery it refuses to boot to it too stays on the flag lock is unlock but the phone boots normally i can i get the Recovery to boot....it fails to flash in fastboot and fastbootd is now gone

Create a thread for this by clicking Ask Question at the top

Note!
We have a reply schedule for Free Support. Please upgrade to Private Support if you can't wait.
4goTTen21
4goTTen21
4goTTen21
Newbie
4
15-03-2024, 08:12 PM
#40



2 questions:
1- How I make sure to disable user encryption ?
2- If I'm going to flash a GSI, should I sign the .imgs using the device stock vbmeta or should I use the GSI vbmeta ?
Pages (5): Previous 1 2 3 4 5 Next
Users browsing this thread:
 1 Guest(s)
Users browsing this thread:
 1 Guest(s)
YtWhTl
live chat
whatsapp telegram instagram