Created
August 19, 2019 02:25
-
-
Save muttiopenbts/1106bc6dc99c5ecafc3320a2a86d5568 to your computer and use it in GitHub Desktop.
Generate ivt binary for use when running an imx6 SoC in HAB mode. Helper towards signing kernel images.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gen_ivt(loadaddr, image_file): | |
'''Generate imx SoC ivt | |
Args: | |
loadaddr int. Hex representing load address in ram for uboot. | |
Can be obtained from your u-boot.cfg build file. | |
image_file string. filename and path to binary image. If | |
generating ivt for signing kernel image, ensure kernel | |
image file is pre-padded. | |
returns: | |
Generates binary file called ivt.bin which can be appended to kernel. | |
''' | |
import os | |
img_size = os.stat(image_file).st_size | |
output_file = 'ivt.bin' | |
# Shouldn't change. Tag=0xD1, Length=0x0020, Ver=0x41 | |
ivt_header = 0x412000D1 | |
# mem size boundary | |
mem_boundary = 0x1000 # 4096 bytes | |
# Jump Location | |
jump_loc = loadaddr + mem_boundary | |
# ivt size 32 bytes. Fixed. | |
ivt_size = 0x20 | |
# Self pointer | |
self_pointer = loadaddr + img_size | |
# csf pointer | |
csf_pointer = self_pointer + ivt_size | |
print('Creating ivt.\n{} size:{}'.format(image_file,hex(img_size))) | |
with open(output_file,'wb') as ivt_file: | |
ivt_file.write((ivt_header).to_bytes(4,byteorder="little")) | |
ivt_file.write((jump_loc).to_bytes(4,byteorder="little")) | |
ivt_file.write((0x0).to_bytes(4,byteorder="little")) # Reserved | |
ivt_file.write((0x0).to_bytes(4,byteorder="little")) # DCD pointer | |
ivt_file.write((0x0).to_bytes(4,byteorder="little")) # Boot data | |
ivt_file.write((self_pointer).to_bytes(4,byteorder="little")) | |
ivt_file.write((csf_pointer).to_bytes(4,byteorder="little")) | |
ivt_file.write((0x0).to_bytes(4,byteorder="little")) # Reserved | |
print('New {} size is {}'.format(output_file,os.stat(output_file).st_size)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment