Exemplo n.º 1
0
 def __init__(self,device,name="dpflib_c"):
     self._device=None
     self.name = name
     self._height = 0
     self._width = 0
     try:
         self._device=dpf.open(device)
     except SystemError as e:
         print e 
         return
     self._width,self._height=self._device.getRes()
     self.setBacklight(3)
Exemplo n.º 2
0
			print "Module/driver version:", hex(v[2])
			print "Identified module:", g_lcdctrl[v[3]]
		except KeyError:
			print "Unknown module id", hex(v[1]), hex(v[2]), hex(v[3])
	else:
		print "Does not support RDID"

def detect_flash(d):
	manu, dev0, dev1 = d.probeFlash()
	try:
		print "Manufacturer: %s" % g_vendors[manu][0]
		f = g_vendors[manu][1][dev1]
	except KeyError:
		print "Unknown Manufacturer"
		print "Got id[3]: %x, %x, %x" % (manu, dev0, dev1)
		try:
			f = g_stm_types[1][dev1]
			print "Compatible  : %s" % f[0]
		except KeyError:
			print "Unable to detect flash, just assuming 2MB size"
			f = ("m25p16", 32, 0x10000)
	bytes = f[1] * f[2]
	print "Size        : %d MB" % (bytes / (1024 * 1024))
	return bytes

if __name__ == "__main__":
	d = dpf.open(sys.argv[1])
	detect_flash(d)
	detect_lcd(d)
	d.close()
Exemplo n.º 3
0
        sys.exit(-1)

    # Make dir for writing temp code
    if not os.path.exists("lcd.tmp"):
        os.makedirs("lcd.tmp")
    else:
        os.system("rm -f lcd.tmp/*")

    dumpfile = arg

    if arg.startswith("/dev/"):
        #
        # copy of fulldump.py
        #
        print("Detecting & reading dpf flash...")
        d = dpf.open(arg)
        size = detect.detect_flash(d)
        # Offset, size
        print("Reading %x bytes from flash..." % size)
        buf = d.readFlash(0x00, size)
        dump_filename = "fulldump_" + datetime.datetime.now().strftime(
            "%Y%m%d-%H%M%S") + ".bin"
        f = open(dump_filename, "wb")
        f.write(buf)
        f.close()
        d.close()
        print("Flash written to file '%s'." % dump_filename)
        print()
        dumpfile = dump_filename
else:
    ################ WINDOWS ################
Exemplo n.º 4
0
        sys.exit(-1)

    # Make dir for writing temp code
    if not os.path.exists("lcd.tmp"):
        os.makedirs("lcd.tmp")
    else:
        os.system("rm -f lcd.tmp/*")

    dumpfile = arg

    if arg.startswith("/dev/"):
    #
    # copy of fulldump.py
    #
        print("Detecting & reading dpf flash...")
        d = dpf.open(arg)
        size = detect.detect_flash(d)
        # Offset, size
        print("Reading %x bytes from flash..." % size)
        buf = d.readFlash(0x00, size)
        dump_filename="fulldump_" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + ".bin"        
        f = open(dump_filename, "wb")
        f.write(buf)
        f.close()
        d.close()
        print("Flash written to file '%s'." % dump_filename)
        print()
        dumpfile = dump_filename
else:
################ WINDOWS ################    
    if len(sys.argv) != 2:
Exemplo n.º 5
0
splashbin.close()

resx = int(sys.argv[2])
resy = int(sys.argv[3])
if resx > 511 or resx & 0x01:
    print("Image width must be < 512 and even!")
    sys.exit(1)
if resy > 511 or resy & 0x01:
    print("Image height must be < 512 and even!")
    sys.exit(1)
if len(splash) != (resx * resy * 2):
    print("Length of imagefile does not match given image with/height!")
    sys.exit(1)

print("Sending splashfile %s to flash..." % sys.argv[1])
d = dpf.open(sys.argv[4])
data = d.readFlash(0x00, 0x80)
if data[0x50:0x58] != "20120101" or int(
        data[0x73:0x75]) < 0x03 or data[0x77] != "1":
    print("Wrong firmware!")
    d.close()
    sys.exit(1)

b = struct.unpack("BBB", data[0x20:0x23])
offset = b[0] + (b[1] << 8) + (b[2] << 16)

l = struct.pack("BBBB", resx & 0xff, (resx >> 8) & 0xff, resy & 0xff,
                (resy >> 8) & 0xff)
data = l + splash

print("offset: 0x%x" % offset)
Exemplo n.º 6
0
        except KeyError:
            print("Unknown module id", hex(v[1]), hex(v[2]), hex(v[3]))
    else:
        print("Does not support RDID")


def detect_flash(d):
    manu, dev0, dev1 = d.probeFlash()
    try:
        print("Manufacturer: %s" % g_vendors[manu][0])
        f = g_vendors[manu][1][dev1]
    except KeyError:
        print("Unknown Manufacturer")
        print("Got id[3]: %x, %x, %x" % (manu, dev0, dev1))
        try:
            f = g_stm_types[1][dev1]
            print("Compatible  : %s" % f[0])
        except KeyError:
            print("Unable to detect flash, just assuming 2MB size")
            f = ("m25p16", 32, 0x10000)
    bytes = f[1] * f[2]
    print("Size        : %d MB" % (bytes / (1024 * 1024)))
    return bytes


if __name__ == "__main__":
    d = dpf.open(sys.argv[1])
    detect_flash(d)
    # detect_lcd(d)
    d.close()
Exemplo n.º 7
0
SECTOR_SIZE = 0x10000

def flash_restore(d, data):
        sectors = (len(data) + SECTOR_SIZE - 1) / SECTOR_SIZE
        d.eraseFlash() # erase full flash
        # for i in range(sectors):
                # print "Erasing sector %d..." % i
                # d.eraseFlash(i * SECTOR_SIZE)

        for i in range(sectors):
                offset = i * SECTOR_SIZE
                print("Flashing sector %d..." % i)
                d.writeFlash(offset, data[offset:offset + SECTOR_SIZE])
        

d = dpf.open("usb0")

try:
        file = sys.argv[1]
except:
        file = "../reverse/silver2/full_image.bin"

f = open(file, "r")
data = f.read()

size = detect.detect_flash(d)
n = len(data)
if (n == size) or sys.argv[-1] == "-f":
        flash_restore(d, data)
        d.run(0x136b) # Call reset
else:
Exemplo n.º 8
0
import struct
import sys
sys.path.append("./Debug")
import dpf
import time

d = dpf.open("usb0")

offset = 0x380000

print "Writing firmware..."
d.patchSector(0x0, offset, sys.argv[1])

d.close()

Exemplo n.º 9
0
splashbin.close()

resx = int(sys.argv[2])
resy = int(sys.argv[3])
if resx > 511 or resx & 0x01:
        print("Image width must be < 512 and even!")
        sys.exit(1)
if resy > 511 or resy & 0x01:
        print("Image height must be < 512 and even!")
        sys.exit(1)
if len(splash) != (resx * resy * 2):
        print("Length of imagefile does not match given image with/height!")
        sys.exit(1)
        
print("Sending splashfile %s to flash..." % sys.argv[1])
d = dpf.open(sys.argv[4])
data = d.readFlash(0x00, 0x80)
if data[0x50:0x58] != "20120101" or int(data[0x73:0x75]) < 0x03 or data[0x77] != "1":
        print("Wrong firmware!")
        d.close()
        sys.exit(1)

b = struct.unpack("BBB", data[0x20:0x23])
offset = b[0] + (b[1] << 8) + (b[2] << 16)

l = struct.pack("BBBB", resx & 0xff, (resx >> 8) & 0xff, resy & 0xff, (resy >> 8) & 0xff)
data = l + splash

print("offset: 0x%x" % offset)

sectors = (len(data) + SECTOR_SIZE - 1) / SECTOR_SIZE