#!/usr/bin/env python3 # # Build Actions NVRAM config binary file # # Copyright (c) 2017 Actions Semiconductor Co., Ltd # # SPDX-License-Identifier: Apache-2.0 # import os import sys import struct import array import argparse import zlib import configparser from ctypes import *; BINARY_BLOCK_SIZE_ALIGN = 512 IMAGE_HEAD_SIZE = 512 def boot_padding(filename, align = BINARY_BLOCK_SIZE_ALIGN): fsize = os.path.getsize(filename) if fsize % align: padding_size = align - (fsize % align) print('fsize %d, padding_size %d' %(fsize, padding_size)) with open(filename, 'rb+') as f: f.seek(fsize, 0) buf = (c_byte * padding_size)(); f.write(buf) f.close() def img_header_add(img_bin_f): """ check img header, and add h_img_size """ img_len = os.path.getsize(img_bin_f) print('img origin length %d' %(img_len)) if img_len % 4: boot_padding(img_bin_f, 4) img_len = os.path.getsize(img_bin_f) print('img align 4 length %d' %(img_len)) with open(img_bin_f, 'rb+') as f: f.seek(IMAGE_HEAD_SIZE, 0) data = f.read(8) i_sp,i_run_addr = struct.unpack('II',data) print('i_run_addr 0x%x.' %i_run_addr) f.seek(0, 0) f.write(struct.pack('