[Armadeus-commitlog] SF.net SVN: armadeus: [801] branches/apf2/software/uboot_recover
Brought to you by:
sszy
|
From: <jo...@us...> - 2008-05-01 20:01:12
|
Revision: 801
http://armadeus.svn.sourceforge.net/armadeus/?rev=801&view=rev
Author: jorasse
Date: 2008-05-01 13:01:15 -0700 (Thu, 01 May 2008)
Log Message:
-----------
[TOOLS/APF2] Added preliminary uboot_recover2 (Alpha dev)
Added Paths:
-----------
branches/apf2/software/uboot_recover/u-boot2.bin
branches/apf2/software/uboot_recover/uboot_recover2.py
Added: branches/apf2/software/uboot_recover/u-boot2.bin
===================================================================
(Binary files differ)
Property changes on: branches/apf2/software/uboot_recover/u-boot2.bin
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/apf2/software/uboot_recover/uboot_recover2.py
===================================================================
--- branches/apf2/software/uboot_recover/uboot_recover2.py (rev 0)
+++ branches/apf2/software/uboot_recover/uboot_recover2.py 2008-05-01 20:01:15 UTC (rev 801)
@@ -0,0 +1,298 @@
+#
+# APF27 bootloader
+#
+# Copyright (2008) ARMADEUS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# author: nic...@ar...
+#
+# Change History:
+# - (Jorasse) Added support for PCM038: init DDR RAM and u-boot upload
+#
+
+import sys
+import time
+from struct import *
+import os
+import serial
+
+
+
+class imxlBootloader:
+
+ statuscode = { 0x8D: 'data specified is out of bounds',
+ 0x55: 'error during assert verification',
+ 0x36: 'hash verification failed',
+ 0x33: 'certificate parsing failed or the certificate contained an unsupported key',
+ 0x35: 'signature verification failed',
+ 0x4B: 'CSF command sequence contains unsupported command identifier',
+ 0x4E: 'absence of expected CSF header',
+ 0x4D: 'CSF length is unsupported',
+ 0x2E: 'CSF TYPE does not match processor TYPE',
+ 0x2D: 'CSF UID does not match either processor UID or generic UID',
+ 0x3A: 'CSF customer/product code does not match processor customer/product code',
+ 0x87: 'key indexis either unsupported, or an attempt is made to overwrite the SRK from a CSF command',
+ 0xF0: 'successful operation completion',
+ 0x17: 'SCC unexpectedly not in secure state',
+ 0x1E: 'secureRAM secret key invalid',
+ 0x1D: 'secureRAM initialization failure',
+ 0x1B: 'secureRAM self test failure',
+ 0x2B: 'secureRAM internal failure',
+ 0x27: 'secureRAM secrect key unexpectedly in use',
+ 0x8B: 'an attempt is made to read a key from the list of subordinate public keys at a location where no key is installed',
+ 0x8E: 'algorithm type is either invalid or ortherwise unsupported',
+ 0x66: 'write operation to register failed',
+ 0x63: 'DCD invalid',
+ 0x6F: 'RAM application pointer is NULL or ERASED_FLASH',
+ 0x69: 'CSF missing when HAB TYPE is not HAB-disabled',
+ 0x6A: 'NANDFC boot buffer load failed',
+ 0x6C: 'Exception has occured',
+ 0x67: 'INT_BOOT fuse is blown but BOOT pins are set for external boot',
+ 0x88: 'Successful download completion' }
+
+
+
+ def __init__(self, serialport ):
+
+ self.port = serialport
+
+
+
+ def getstatus(self):
+ self.port.flushInput()
+
+ self.port.write( self.buildcmd("0505" ,"00000000","b","00000000","00","0" ))
+ result = self.port.read(4)
+ if len(result) > 0:
+ print self.statuscode[ord(result[0])]
+ for i in range(len(result)):
+ print '%02x' % ord(result[i]),
+ print '\n'
+ else:
+ print '\nread timeout'
+
+
+
+ def __displayProgress( self, text ):
+
+ sys.stdout.write(chr(13))
+
+ print text,
+
+
+
+
+
+# addr: address to read
+# count: number of bytes to read
+# mode: b, w, l for byte, word, long
+
+ def get( self, addr, count, mode ):
+
+ assert len(addr) <= 8, 'address too long'
+
+ assert int(count,16) > 0, 'zero length get'
+
+ assert int(count,16) < 0xffffffff, 'Too long get, should be < 31 bytes'
+
+
+ self.port.write( self.buildcmd("0101" ,addr,mode,count.zfill(9-len(count)),"00000000","0" ) )
+
+ nbbyte = 1
+ if mode == 'w':
+ nbbyte = 2
+ if mode == 'l':
+ nbbyte = 4
+
+ nbbyte = nbbyte * int(count)
+ result = self.port.read(nbbyte+4) # read n+4 char
+ if len(result) == 0:
+ print '\nread timeout'
+ return
+ print '\nread ACK:',
+ for i in range (4):
+ print '%02x' % ord(result[i]),
+
+ print '\nread data:',
+ for i in range (4,len(result)):
+ print '%02x' % ord(result[i]),
+ print '\n'
+ return result[4:]
+
+
+# addr: address where the data have to be written
+# data: data to write. must match the given mode
+
+# mode: b, w, l for byte, word, long
+
+ def put( self, addr, data, mode ):
+
+ assert len(data) > 0, 'zero length put'
+
+ assert len(addr) == 8, 'address too long'
+
+
+
+ self.port.write( self.buildcmd("0202" ,addr,mode,"00000000",data,"0" ))
+ result = self.port.read(4) #ack
+ if len(result) == 0:
+ print '\nread timeout'
+ return
+ print ' \nwrite ACK:',
+ for i in range (len(result)):
+ print '%02x' % ord(result[i]),
+
+ result = self.port.read(4)
+ if len(result) == 0:
+ print 'read timeout'
+ return
+
+ print '\nwrite success:',
+ for i in range (len(result)):
+ print '%02x' % ord(result[i]),
+ print
+
+ def download( self, addr, data, size, mode ):
+
+ assert size > 0, 'file empty'
+
+
+ f=open(data, 'rb')
+
+
+ self.port.write( self.buildcmd("0404" ,addr,mode, size, "00000000","AA" ))
+ result = self.port.read(4) #ack
+ if len(result) == 0:
+ print '\nread timeout'
+ return
+ print ' \nwrite ACK:',
+ for i in range (len(result)):
+ print '%02x' % ord(result[i]),
+
+ data = f.read(16)
+ count = 16
+ b = 0
+ while len(data):
+ n = len(data)
+ b = 16-n # ensure always 4 bytes
+ #tr = unpack('B'*n,data)
+ self.port.write(data)
+
+ count = count + 16
+ if (count % 1024) == 0:
+ self.__displayProgress( "%d octets" % count )
+ data = f.read(16)
+ self.__displayProgress( "%d octets" % count )
+
+ print ""
+
+ f.close()
+
+ self.getstatus()
+ print
+ return
+
+
+ def buildcmd( self, cmd, addr, ds, cnt, data, ft ):
+ if ds == 'b':
+
+ datatmp = ('%c' % int('00',16)) + ('%c' % int('00',16)) + ('%c' % int('00',16)) + ('%c' % int(data[0:2],16))
+ datasize = "08"
+ if ds == 'w':
+
+ datasize = "10"
+ datatmp = ('%c' % int('00',16)) + ('%c' % int('00',16)) + ('%c' % int(data[0:2],16)) + ('%c' % int(data[2:4],16))
+ if ds == 'l':
+ datasize = "20"
+ datatmp = ('%c' % int(data[0:2],16)) + ('%c' % int(data[2:4],16)) + ('%c' % int(data[4:6],16)) + ('%c' % int(data[6:8],16))
+ if ds == ' ':
+ datasize = "00"
+ datatmp = ('%c' % int(data[0:2],16)) + ('%c' % int(data[2:4],16)) + ('%c' % int(data[4:6],16)) + ('%c' % int(data[6:8],16))
+
+ result = ('%c' % int(cmd[0:2],16)) + ('%c' % int(cmd[2:4],16)) + \
+ ('%c' % int(addr[0:2],16)) + ('%c' % int(addr[2:4],16)) + ('%c' % int(addr[4:6],16)) + ('%c' % int(addr[6:8],16)) + \
+ ('%c' % int(datasize,16)) + \
+ ('%c' % int(cnt[0:2],16)) + ('%c' % int(cnt[2:4],16)) + ('%c' % int(cnt[4:6],16)) + ('%c' % int(cnt[6:8],16)) + \
+ datatmp + ('%c' % int(ft,16))
+
+ for i in range(len(result)):
+ print '%02x' % ord(result[i]),
+ print cnt
+ return result
+
+if __name__ == "__main__":
+
+ SPEED = 115200
+
+ ramSize = 16
+ port = "/dev/ttyS0"
+
+ print "APF2 Bootstrap Tool"
+
+ try:
+
+ ser = serial.Serial(port, SPEED, timeout=1)
+
+ except Exception, msg:
+
+ print "unable to open serial port %s" % port
+
+ print msg
+
+ sys.exit()
+
+ ser.flush()
+
+ apfBootloader = imxlBootloader(ser)
+
+ apfBootloader.getstatus()
+
+ apfBootloader.put("D8001010","00000008","l")
+ apfBootloader.put("10027828","55555555","l")
+ apfBootloader.put("10027830","55555555","l")
+ apfBootloader.put("10027834","55555555","l")
+ apfBootloader.put("10027838","00005005","l")
+ apfBootloader.put("1002783C","15555555","l")
+ apfBootloader.put("D8001010","00000004","l")
+ apfBootloader.put("D8001004","006ac73a","l")
+ apfBootloader.put("D8001000","92100000","l")
+ apfBootloader.put("A0000F00","00000000","l")
+ apfBootloader.put("D8001000","A2100000","l")
+ apfBootloader.put("A0000F00","00000000","l")
+ apfBootloader.put("A0000F00","00000000","l")
+ apfBootloader.put("A0000F00","00000000","l")
+ apfBootloader.put("A0000F00","00000000","l")
+ apfBootloader.put("D8001000","A2200000","l")
+ apfBootloader.put("A0000F00","00000000","l")
+ apfBootloader.put("A0000F00","00000000","l")
+ apfBootloader.put("A0000F00","00000000","l")
+ apfBootloader.put("A0000F00","00000000","l")
+ apfBootloader.put("D8001000","b2100000","l")
+ apfBootloader.put("A0000033","DA0000DA","b")
+ apfBootloader.put("A1000000","FF0000FF","b")
+ apfBootloader.put("D8001000","82226080","l")
+
+
+ result = apfBootloader.get("A0000000","8","b")
+ result = apfBootloader.get("C0000000","8","b")
+
+ fileName = 'u-boot2.bin'
+ fsize = "%08x" % os.path.getsize(fileName) #os.stat(filesize)[6]
+ print "starting download %s bytes" % fsize
+
+ apfBootloader.download("A0000000",fileName, fsize," ")
+
+ del ser
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|