X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=blobdiff_plain;f=lib%2Fpython%2FPlugins%2FSystemPlugins%2FFPGAUpgrade%2Fplugin.py;h=87ecedf13e36dd8444e7b3f459bfe591078ff1c2;hp=a5b76b0cd52f95b5a7ab9803a68833259192624d;hb=630294d38cb3cab784ecc1102804394974b162b0;hpb=792c4625d009c6b542756ba39a555be2264cd3a8 diff --git a/lib/python/Plugins/SystemPlugins/FPGAUpgrade/plugin.py b/lib/python/Plugins/SystemPlugins/FPGAUpgrade/plugin.py index a5b76b0..87ecedf 100644 --- a/lib/python/Plugins/SystemPlugins/FPGAUpgrade/plugin.py +++ b/lib/python/Plugins/SystemPlugins/FPGAUpgrade/plugin.py @@ -1,7 +1,6 @@ -import os +import os, fcntl, thread -import fpga -from enigma import eTimer +from enigma import eTimer, getDesktop from urllib import urlretrieve import urllib @@ -21,27 +20,131 @@ from Components.ActionMap import ActionMap from Components.PluginComponent import plugins from Components.Sources.StaticText import StaticText +STATUS_READY = 0 +STATUS_DONE = 1 +STATUS_ERROR = 2 +STATUS_PREPARED = 3 +STATUS_PROGRAMMING = 4 + +class FPGAUpgradeCore() : + status = STATUS_READY + errmsg = '' + callcount = 0 + MAX_CALL_COUNT = 1500 + def __init__(self, firmwarefile, devicefile): + print '[FPGAUpgrade]' + self.devicefile = devicefile + self.firmwarefile = firmwarefile + + def doUpgrade(self): + firmware,device = None,None + def closefpga(fp, fd): + if fd is not None: os.close(fd) + if fp is not None: fp.close() + try: + size = os.path.getsize(self.firmwarefile) + if size == 0: raise Exception, 'data_size is zero' + #print '[FPGAUpgradeCore] data_size :',size + + firmware = open(self.firmwarefile, 'rb') + device = os.open(self.devicefile, os.O_RDWR) + #print '[FPGAUpgradeCore] open >> [ok]' + + rc = fcntl.ioctl(device, 0, size) + if rc < 0: raise Exception, 'fail to set size : %d'%(rc) + #print '[FPGAUpgradeCore] set size >> [ok]' + + rc = fcntl.ioctl(device, 2, 5) + if rc < 0: raise Exception, 'fail to set programming mode : %d'%(rc) + #print '[FPGAUpgradeCore] programming mode >> [ok]' + self.status = STATUS_PREPARED + + while True: + data = firmware.read(1024) + if data == '': break + os.write(device, data) + #print '[FPGAUpgradeCore] write data >> [ok]' + + self.status = STATUS_PROGRAMMING + rc = fcntl.ioctl(device, 1, 0) + if rc < 0: raise Exception, 'fail to programming : %d'%(rc) + #print '[FPGAUpgradeCore] upgrade done.' + if self.callcount < 100: raise Exception, 'wrong fpga file.' + except Exception, msg: + self.errmsg = msg + print '[FPGAUpgradeCore] ERROR >>',msg + closefpga(firmware, device) + return STATUS_ERROR + closefpga(firmware, device) + return STATUS_DONE + + def upgradeMain(self): + self.status = STATUS_READY + self.status = self.doUpgrade() + if self.status == STATUS_DONE: + print '[FPGAUpgrade] upgrade done.' + elif self.status == STATUS_ERROR: + print '[FPGAUpgrade] occur error.' + else: print '[FPGAUpgrade] occur unknown error.' + +class FPGAUpgradeManager: + fu = None + def get_interval(self): + return 200 + + def fpga_upgrade(self, datafile, device): + self.fu = FPGAUpgradeCore(firmwarefile=datafile, devicefile=device) + thread.start_new_thread(self.fu.upgradeMain, ()) + + def checkError(self): + if self.fu.status == STATUS_ERROR: + self.fu.callcount = 0 + return True + return False + + def get_status(self): + if self.fu.status == STATUS_READY: + return 0 + elif self.fu.status == STATUS_ERROR: + return -1 + elif self.fu.status == STATUS_PREPARED: + return 2 + elif self.fu.status == STATUS_PROGRAMMING: + self.fu.callcount += 1 + ret = (self.fu.callcount * 100) / self.fu.MAX_CALL_COUNT + 2 + if ret >= 100: ret = 99 + #print "callcount : [%d]"%(self.fu.callcount); + return ret + elif self.fu.status == STATUS_DONE: + return 100 + + def get_error_msg(self, errno, errmsg): + return str(self.fu.errmsg) + class UpgradeStatus(Screen): + size = getDesktop(0).size() + position_params = size.width() > 750 and (' ') or ('backgroundColor=\"blue\"') skin = """ - + - - - + + + - """ - def __init__(self, session, parent, timeout = 10): + """ % position_params + + def __init__(self, session, parent, timeout = 20): Screen.__init__(self,session) self.session = session self["actions"] = ActionMap(["OkCancelActions"], { "ok": self.keyExit, - }, -1) + }, -2) self.is_done = 0 self.exit_count = 0 - self.timeout = timeout + self.timeout = 20 self.title_str = "FPGA Upgrade" #self["name"] = Label(_("Upgrade status")) @@ -59,6 +162,7 @@ class UpgradeStatus(Screen): self.timer_check_progress.callback.append(self.callbackDoCheckProgress) interval = self.parent.FPGA.get_interval() self.timer_check_progress.start(interval) + self.need_restart = False def callbackDoCheckProgress(self): self.status = self.parent.FPGA.get_status() @@ -68,61 +172,70 @@ class UpgradeStatus(Screen): if self.status == 100: #print "fpga-upgrade done!!" - self.status_bar.setText(_("Success. Press OK to exit.")) + self.status_bar.setText(_("Succeed")) #self.status_bar.setText(_("%d / 100" % (self.status))) self.timer_check_progress.stop() self.is_done = 1 - self.timer_exit = eTimer() self.timer_exit.callback.append(self.callbackExit) self.timer_exit.start(1000) - elif self.status == -1 or self.status == -2: + + elif self.status < 0:#elif self.status == -1 or self.status == -2: #print "fpga-upgrade error >> errno : [%d]" % (self.status) - self.status_bar.setText(_("Error[%d]. Press Cancel to exit." % (self.status))) + ERROR_MSG = '' + ERROR_CODE = int(self.status) * -1 + ERROR_MSG = self.parent.FPGA.get_error_msg(ERROR_CODE, ERROR_MSG) + self.status_bar.setText("Fail to update!!") + self["info"].setText(_("Error[%d] : %s.\nPress OK to exit." % (self.status, ERROR_MSG))) self.timer_check_progress.stop() self.is_done = 1 + else: #print "fpga-upgrade status : %d" % self.status self.status_bar.setText(_("%d / 100" % (self.status))) def callbackExit(self): + self.need_restart = True if self.exit_count == self.timeout: self.timer_exit.stop() self.keyExit() self.exit_count = self.exit_count + 1 - self.instance.setTitle("%s (%d)" % (self.title_str, (self.timeout-self.exit_count))) + #self.instance.setTitle("%s (%d)" % (self.title_str, (self.timeout-self.exit_count))) + self["info"].setText("Reboot after %d seconds.\nPress the OK to reboot now." %(self.timeout-self.exit_count)) def keyExit(self): + if self.need_restart: + from Screens.Standby import TryQuitMainloop + self.session.open(TryQuitMainloop, 2) if self.is_done : self.close() class FPGAUpgrade(Screen): + size = getDesktop(0).size() + position_params = size.width() > 750 and ('center', 440) or ('120', 420) skin = """ - - - - - + + + + - - - - + + + - """ + """ % position_params def __init__(self, session): Screen.__init__(self, session) self.session = session self["key_red"] = StaticText(_("Close")) - self["key_green"] = StaticText(_("Ugrade")) - self["key_yellow"] = StaticText(_(" ")) + self["key_green"] = StaticText(_("Upgrade")) self["key_blue"] = StaticText(_("Download")) - #self["key_blue"] = StaticText(_(" ")) + self["status"] = StaticText(_(" ")) self["file_list"] = FileList("/", matchingPattern = "^.*") @@ -146,13 +259,13 @@ class FPGAUpgrade(Screen): self.STATUS_BAR = self["status"] self.STATUS_BAR.setText(_(self.SOURCELIST.getCurrentDirectory())) - self.DEVICE_PATH = '/dev/misc/dp' + self.DEVICE_LIST = '/dev/fpga_dp;/dev/misc/dp;' self.DOWNLOAD_TAR_PATH = '/tmp/' self.DOWNLOAD_FILE_NAME = 'TS_PRO.dat' self.DOWNLOAD_URL = '' self.doLoadConf() - self.FPGA = fpga.Fpga() - print self.DEVICE_PATH + self.FPGA = FPGAUpgradeManager() + print self.DEVICE_LIST print self.DOWNLOAD_TAR_PATH print self.DOWNLOAD_FILE_NAME print self.DOWNLOAD_URL @@ -181,8 +294,6 @@ class FPGAUpgrade(Screen): if confirmed: self.doExit() - - def doUpgradeHandler(self, confirmed): if confirmed == False: return @@ -194,17 +305,30 @@ class FPGAUpgrade(Screen): #self.session.open(MessageBox, _("Can't select directory."), MessageBox.TYPE_INFO, timeout = 5) return - self.ERROR_CODE = self.FPGA.fpga_upgrade(path, self.DEVICE_PATH) + device = "" + device_list = self.DEVICE_LIST.split(";") + + for d in device_list: + if os.path.exists(d): + device = d + break + + if device == None or len(device) == 0: + message = "Fail to upgrade.\nCause : Can't found device.\nDo you want to exit?" + self.session.openWithCallback(self.onCallbackHandler, MessageBox, _(message), MessageBox.TYPE_YESNO, timeout = 10, default = True) + print "DEVICE_LIST : ", device_list + + print "DEVICE : ", device + self.ERROR_CODE = self.FPGA.fpga_upgrade(path, device) if self.ERROR_CODE > 0: self.ERROR_MSG = self.FPGA.get_error_msg(self.ERROR_CODE, self.ERROR_MSG) message = "Fail to upgrade.\nCause : " + self.ERROR_MSG + "\nDo you want to exit?" self.session.openWithCallback(self.onCallbackHandler, MessageBox, _(message), MessageBox.TYPE_YESNO, timeout = 10, default = True) - - print "DEVICE_PATH : ", self.DEVICE_PATH - print "FILE_PATH : ", path + print "DEVICE : ", device + print "FILE : ", path else: #self.session.open(MessageBox, _("Success!!"), MessageBox.TYPE_INFO, timeout = 5) - self.session.open(UpgradeStatus, self, timeout = 10) + self.session.open(UpgradeStatus, self, timeout = 20) def onClickRed(self): self.doExit()