@@ -0,0 +1,1543 @@
+#!/usr/bin/env python%0A%0Aimport sys%0Aimport os%0Aimport shutil%0Aimport hashlib%0Aimport binascii%0Aimport ecdsa%0Afrom ecdsa.curves import SECP256k1%0A%0Abinfile = sys.argv%5B1%5D%0Asignedbinfile = sys.argv%5B2%5D%0Aprivatekey = sys.argv%5B3%5D%0Aprivatekey = ecdsa.SigningKey.from_secret_exponent(int(privatekey, 16), curve = SECP256k1)%0A%0Aapplen = 229376 # flash size minus bootloader length%0Achunksize = 8*512%0A%0A%0Adef sha256(x):%0A    return hashlib.sha256(x).digest()%0A%0A%0Adef Hash(x):%0A    if type(x) is unicode: x=x.encode('utf-8')%0A    return sha256(sha256(x))%0A%0A%0Adef signBin(filename):    %0A    with open(filename, %22rb%22) as f:%0A        data = %22%22%0A        while True:     %0A            d = f.read(chunksize)%0A            if d == %22%22:%0A                break%0A            data = data + d%0A    data = data + '%5CxFF' * (applen - len(data)) %0A    return privatekey.sign_digest_deterministic(Hash(data), hashfunc=hashlib.sha256, sigencode = ecdsa.util.sigencode_string)%0A%0A%0Adef readSig(filename):    %0A    with open(filename, %22rb%22) as f:%0A        f.seek(os.stat(filename).st_size - 64)    %0A        return f.read(64)%0A         %0A%0Aif os.stat(binfile).st_size %3E applen:%0A    print '%5CnERROR: Firmware must be less than %7B%7D bytes.%5Cn'.format(applen)%0Aelse:%0A    sig = signBin(binfile)%0A    shutil.copyfile(binfile, signedbinfile)%0A    with open(signedbinfile, 'ab') as f:%0A        f.write(sig)%0A        f.close()%0A%0A    if readSig(signedbinfile) != sig:%0A        os.remove(signedbinfile)%0A        print '%5CnERROR: Could not sign firmware.%5Cn'%0A    else:%0A        print '%5CnFirmware signature: %7B%7D%5Cn'.format(binascii.hexlify(sig))%0A

add python script to sign firmware