예제 #1
0
    def setUp(self):
        self.dbg = False
        self.vbs = False
        if "S1_VERBOSE" in os.environ:
            if (os.environ["S1_VERBOSE"] == "True"):
                self.vbs = True

        if "S1_DEBUG" in os.environ:
            if (os.environ["S1_DEBUG"] == "True"):
                self.dbg = True

        os.environ["S1_BASE"] = sys.path[0] + "/s1-pycontrol"

        self.manager = SerialFlashManager(0x0403, 0x8530, 2)
        self.flash = self.manager.get_flash_device()
        return
예제 #2
0
	def setUp(self):
		self.dbg = False;
		self.vbs = False;
		if "S1_VERBOSE" in os.environ:
			if (os.environ["S1_VERBOSE"] == "True"):
				self.vbs = True

		if "S1_DEBUG" in os.environ:
			if (os.environ["S1_DEBUG"] == "True"):
				self.dbg = True

		os.environ["S1_BASE"] = sys.path[0] + "/s1-pycontrol"


		self.manager = SerialFlashManager(0x0403, 0x8530, 2)
		self.flash = self.manager.get_flash_device()
		return
예제 #3
0
class Test (unittest.TestCase):
	"""Unit test for Numonyx SPI Flash"""

	def setUp(self):
		self.dbg = False;
		self.vbs = False;
		if "S1_VERBOSE" in os.environ:
			if (os.environ["S1_VERBOSE"] == "True"):
				self.vbs = True

		if "S1_DEBUG" in os.environ:
			if (os.environ["S1_DEBUG"] == "True"):
				self.dbg = True

		os.environ["S1_BASE"] = sys.path[0] + "/s1-pycontrol"


		self.manager = SerialFlashManager(0x0403, 0x8530, 2)
		self.flash = self.manager.get_flash_device()
		return

	def tearDown(self):
		del self.flash
		del self.manager


	def test_read_jedec_id(self):
		"""reads the JEDEC identification number"""
		print "reading JEDEC ID number"
		self.assertEqual(1, 1)

	def test_read_size_and_string(self):
		"""read the JEDEC size and string"""
		print "String: "
		print str(self.flash)

	def test_read_status(self):
		"""read the status byte"""
		status = self.flash._read_status()
		print "Status: " + str(status)

#	def test_read_small_data(self):
#		"""read 32 bytes"""
#		data = self.flash.read(0x00, 32)
#		print "Data: " + str(data)

#	def test_erase_sector(self):
#		"""erase sector"""
#		#self.flash.bulk_erase()
#		self.flash.erase(0x00, 0x010000)
#		data = self.flash.read(0x00, 32)
#		print "Data: " + str(data)

#	def test_small_write(self):
#		self.flash.write(0x040000, [0x01, 0x02, 0x03, 0x05])
#		data = self.flash.read(0x040000, 4)
#		print "Data: " + str(data)

#	def test_wake(self):
#		self.flash.wake()

#	def test_flashdevice_read_bandwidth(self):
#		print "Start reading the whole device..."
#		delta = time.time()
#		data = self.flash.read(0, len(self.flash))
#		delta = time.time()-delta
#		length = len(data)
#		print "%d bytes in %d seconds @ %.1f KB/s" % \
#			(length, delta, length/(1024.0*delta))



	def test_flashdevice_small_rw(self):
		self.flash.erase(0x00000, 0x010000)
		data = self.flash.read(0x00, 128)
		ref = Array('B', [0xff] * 128)
		self.assertEqual(data, ref)
		string = 'This is a serial SPI flash test'
		ref2 = Array('B', string)
		self.flash.write(0x0020, string)
		data = self.flash.read(0x0020, 128)
		ref2.extend(ref)
		ref2 = ref2[:128]
		self.assertEqual(data, ref2)


#
#	def test_unlock(self):
#		"""test the chip's capability to unlock"""
#		self.flash.unlock()

	def test_rw_sector_1(self):
		from hashlib import sha1
		buf = Array('I')
#		length = 65536
		length = len(self.flash)
		print "length: " + str(length)
		print "Build Sequence"
		for address in range (0, length):
			buf.append(address)
		print "Swap sequence"
		buf = buf.byteswap()
		#print "Erase flash from %08X to %08X" % (0, length)
		print "Erase all of the flash"
		self.flash.erase(0, len(self.flash))
		bufstr = buf.tostring()
		dout = Array('B')
		dout.fromstring(bufstr)
		self.flash.write(0, bufstr)
		print "Verify Flash"
		wmd = sha1()
		wmd.update(buf.tostring())
		refdigest = wmd.hexdigest()
		print "Read Flash"
		din = self.flash.read(0, length)
		print "Dump Flash"
		print hexdump(din.tostring())
		print "Verify Flash"
		rmd = sha1()
		rmd.update(din.tostring())
		newdigest = rmd.hexdigest()
		print "Reference: ", refdigest
		print "Retrieved: ", newdigest

		try:
			f = open("din.hex", "w")
			din.tofile(f)
			f.close()
		except IOError, err:
			print "Error writing to din file"

		try:
			f = open("dout.hex", "w")
			dout.tofile(f)
			f.close()
		except IOError, err:
			print "Error writing to dout file"
예제 #4
0
class Test(unittest.TestCase):
    """Unit test for Numonyx SPI Flash"""
    def setUp(self):
        self.dbg = False
        self.vbs = False
        if "S1_VERBOSE" in os.environ:
            if (os.environ["S1_VERBOSE"] == "True"):
                self.vbs = True

        if "S1_DEBUG" in os.environ:
            if (os.environ["S1_DEBUG"] == "True"):
                self.dbg = True

        os.environ["S1_BASE"] = sys.path[0] + "/s1-pycontrol"

        self.manager = SerialFlashManager(0x0403, 0x8530, 2)
        self.flash = self.manager.get_flash_device()
        return

    def tearDown(self):
        del self.flash
        del self.manager

    def test_read_jedec_id(self):
        """reads the JEDEC identification number"""
        print "reading JEDEC ID number"
        self.assertEqual(1, 1)

    def test_read_size_and_string(self):
        """read the JEDEC size and string"""
        print "String: "
        print str(self.flash)

    def test_read_status(self):
        """read the status byte"""
        status = self.flash._read_status()
        print "Status: " + str(status)

#	def test_read_small_data(self):
#		"""read 32 bytes"""
#		data = self.flash.read(0x00, 32)
#		print "Data: " + str(data)

#	def test_erase_sector(self):
#		"""erase sector"""
#		#self.flash.bulk_erase()
#		self.flash.erase(0x00, 0x010000)
#		data = self.flash.read(0x00, 32)
#		print "Data: " + str(data)

#	def test_small_write(self):
#		self.flash.write(0x040000, [0x01, 0x02, 0x03, 0x05])
#		data = self.flash.read(0x040000, 4)
#		print "Data: " + str(data)

#	def test_wake(self):
#		self.flash.wake()

#	def test_flashdevice_read_bandwidth(self):
#		print "Start reading the whole device..."
#		delta = time.time()
#		data = self.flash.read(0, len(self.flash))
#		delta = time.time()-delta
#		length = len(data)
#		print "%d bytes in %d seconds @ %.1f KB/s" % \
#			(length, delta, length/(1024.0*delta))

    def test_flashdevice_small_rw(self):
        self.flash.erase(0x00000, 0x010000)
        data = self.flash.read(0x00, 128)
        ref = Array('B', [0xff] * 128)
        self.assertEqual(data, ref)
        string = 'This is a serial SPI flash test'
        ref2 = Array('B', string)
        self.flash.write(0x0020, string)
        data = self.flash.read(0x0020, 128)
        ref2.extend(ref)
        ref2 = ref2[:128]
        self.assertEqual(data, ref2)


#
#	def test_unlock(self):
#		"""test the chip's capability to unlock"""
#		self.flash.unlock()

    def test_rw_sector_1(self):
        from hashlib import sha1
        buf = Array('I')
        #		length = 65536
        length = len(self.flash)
        print "length: " + str(length)
        print "Build Sequence"
        for address in range(0, length):
            buf.append(address)
        print "Swap sequence"
        buf = buf.byteswap()
        #print "Erase flash from %08X to %08X" % (0, length)
        print "Erase all of the flash"
        self.flash.erase(0, len(self.flash))
        bufstr = buf.tostring()
        dout = Array('B')
        dout.fromstring(bufstr)
        self.flash.write(0, bufstr)
        print "Verify Flash"
        wmd = sha1()
        wmd.update(buf.tostring())
        refdigest = wmd.hexdigest()
        print "Read Flash"
        din = self.flash.read(0, length)
        print "Dump Flash"
        print hexdump(din.tostring())
        print "Verify Flash"
        rmd = sha1()
        rmd.update(din.tostring())
        newdigest = rmd.hexdigest()
        print "Reference: ", refdigest
        print "Retrieved: ", newdigest

        try:
            f = open("din.hex", "w")
            din.tofile(f)
            f.close()
        except IOError, err:
            print "Error writing to din file"

        try:
            f = open("dout.hex", "w")
            dout.tofile(f)
            f.close()
        except IOError, err:
            print "Error writing to dout file"