13-03-2020, 05:32 PM
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
Note!
We have a reply schedule for Free Support. Please upgrade to Private Support if you can't wait.