[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
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?
(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.Am getting this error on termux. Also the same in windows. Help
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
- Right-click in the folder where all your files are (avbtool, key and images) and click Open in Terminal
- Run this command
Code:python avbtool info_image --image recovery_stock.img
- 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
- 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
- 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
(03-02-2023, 12:43 AM)CarlosCMD Am getting this error on termux. Also the same in windows. Help
(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
- Right-click in the folder where all your files are (avbtool, key and images) and click Open in Terminal
- Run this command
Code:python avbtool info_image --image recovery_stock.img
- 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
- 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
- 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
(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.
(05-08-2023, 09:23 PM)Benja254the system partition does not need to be signed(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
(13-03-2020, 05:32 PM)hovatek ..
(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