Skip to content

Instantly share code, notes, and snippets.

@kazikcz
Created Mar 16, 2015
Embed
What would you like to do?
#
# usage: python assemble.py VERSION_STRING DECIMAL_BITMASK_OF_FEATURES FW_BIN_PATH OTP_BIN_PATH WMI_VER > firmware-4.bin
#
import sys
import struct
magic = "QCA-ATH10K\0"
version = sys.argv[1]
features = int(sys.argv[2])
fw_bin = open(sys.argv[3], "r").read()
otp_bin = open(sys.argv[4], "r").read()
wmi_ver = int(sys.argv[5])
def round_up(x):
return str((x+3)/4*4)
# Length-Tag-Value (padded to 4 bytes)
sys.stdout.write(
struct.pack(round_up(len(magic)) + "s", magic)
+ struct.pack("<II" + round_up(len(version)) + "s", 0, len(version), version)
+ struct.pack("<III", 2, 4, features)
+ struct.pack("<III", 5, 4, wmi_ver)
+ struct.pack("<II" + round_up(len(fw_bin)) + "s", 3, len(fw_bin), fw_bin)
+ struct.pack("<II" + round_up(len(otp_bin)) + "s", 4, len(otp_bin), otp_bin)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment