#!/usr/bin/env python # # baytrail_sst_firmware_parse.py - parse an SST firmware file # # Copyright (C) 2015 Antonio Ospite # # This program is free software. It comes without any warranty, to # the extent permitted by applicable law. You can redistribute it # and/or modify it under the terms of the Do What The Fuck You Want # To Public License, Version 2, as published by Sam Hocevar. See # http://sam.zoy.org/wtfpl/COPYING for more details. import os import sys import struct FIRMWARE_HEADER_SIZE = 32 MODULE_HEADER_SIZE = 20 def get(f, fmt, offset=None): if offset: f.seek(offset) length = struct.calcsize(fmt) data = f.read(length) value = struct.unpack_from(fmt, data) return value[0] def sst_firmware_parse(firmware_file_name): f = open(firmware_file_name, "rb") filesize = os.path.getsize(firmware_file_name) signature = get(f, "4s") if signature != "$SST": print "Invalid file" return False payload_size = get(f, '