X-Git-Url: http://code.vuplus.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpython%2FPlugins%2FSystemPlugins%2FFPGAUpgrade%2Fplugin.py;h=5fd7a7e5ed59c4987af84968ca92dd99de5e9bd5;hb=ea2f1192f5595f67aa225f90767a3037b2c119b1;hp=9951891dec552b954c2710bcf43fff6e766ea89d;hpb=0b587cf9fca3725b24fab81f4f0caa68a8b55afb;p=vuplus_dvbapp
diff --git a/lib/python/Plugins/SystemPlugins/FPGAUpgrade/plugin.py b/lib/python/Plugins/SystemPlugins/FPGAUpgrade/plugin.py
index 9951891..5fd7a7e 100644
--- a/lib/python/Plugins/SystemPlugins/FPGAUpgrade/plugin.py
+++ b/lib/python/Plugins/SystemPlugins/FPGAUpgrade/plugin.py
@@ -1,3 +1,7 @@
+import os, fcntl, thread
+
+from enigma import eTimer, getDesktop
+
from urllib import urlretrieve
import urllib
@@ -6,38 +10,230 @@ from Screens.MessageBox import MessageBox
from Plugins.Plugin import PluginDescriptor
-from Components.PluginComponent import plugins
+from Tools.Directories import fileExists
+
+from Components.Label import Label
+from Components.Slider import Slider
from Components.Pixmap import Pixmap
+from Components.FileList import FileList
from Components.ActionMap import ActionMap
+from Components.PluginComponent import plugins
from Components.Sources.StaticText import StaticText
-from Components.FileList import FileList
+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):
+ skin = """
+
+
+
+
+
+
+ """
+
+ def __init__(self, session, parent, timeout = 20):
+ Screen.__init__(self,session)
+ self.session = session
+
+ self["actions"] = ActionMap(["OkCancelActions"],
+ {
+ "ok": self.keyExit,
+ }, -2)
+
+ self.is_done = 0
+ self.exit_count = 0
+ self.timeout = 20
+ self.title_str = "FPGA Upgrade"
+
+ #self["name"] = Label(_("Upgrade status"))
+ self["name"] = Label(_(" "))
+ self["info"] = StaticText(_("Can't cancel during upgrade!!"))
+
+ self["status"] = Label(_("Status : 0%"))
+ self.status_bar = self["status"]
+
+ self.slider = Slider(0, 100)
+ self["slider"] = self.slider
+
+ self.setTitle("FPGA Upgrade Status")
+
+ self.parent = parent
+ self.timer_check_progress = eTimer()
+ 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()
+
+ if self.status > 0:
+ self.slider.setValue(self.status)
+
+ if self.status == 100:
+ #print "fpga-upgrade done!!"
+ 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 < 0:#elif self.status == -1 or self.status == -2:
+ #print "fpga-upgrade error >> errno : [%d]" % (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["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):
- skin = """
-
-
-
-
-
-
-
-
-
-
-
-
-
- """
+ skin = """
+
+
+
+
+
+
+
+
+
+
+
+
+ """
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 = "^.*")
@@ -61,13 +257,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 = 'fpga.vuplus'
+ self.DOWNLOAD_FILE_NAME = 'TS_PRO.dat'
self.DOWNLOAD_URL = ''
self.doLoadConf()
-
- 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
@@ -76,12 +272,15 @@ class FPGAUpgrade(Screen):
return
def doExit(self):
+ if fileExists(self.DOWNLOAD_TAR_PATH + self.DOWNLOAD_FILE_NAME):
+ os.remove(self.DOWNLOAD_TAR_PATH + self.DOWNLOAD_FILE_NAME)
self.close()
def doLoadConf(self):
- import os
- f = open('/usr/lib/enigma2/python/Plugins/SystemPlugins/FPGAUpgrade/fpga.conf')
- self.DOWNLOAD_URL = str(f.readline())
+ if fileExists("/proc/stb/info/vumodel"):
+ model = open("/proc/stb/info/vumodel").read().strip()
+ download_uri_header = open('/usr/lib/enigma2/python/Plugins/SystemPlugins/FPGAUpgrade/fpga.conf').readline().strip()
+ self.DOWNLOAD_URL = str(download_uri_header) + "vu" + str(model) + "/" + self.DOWNLOAD_FILE_NAME
def doHook(self, blockNumber, blockSize, totalSize) :
if blockNumber*blockSize > totalSize :
@@ -93,14 +292,9 @@ class FPGAUpgrade(Screen):
if confirmed:
self.doExit()
- def onClickRed(self):
- self.doExit()
-
- # run upgrade!!
- def onClickGreen(self):
- import fpga
-
- FPGA = fpga.Fpga()
+ def doUpgradeHandler(self, confirmed):
+ if confirmed == False:
+ return
path = ''
try:
@@ -109,15 +303,39 @@ class FPGAUpgrade(Screen):
#self.session.open(MessageBox, _("Can't select directory."), MessageBox.TYPE_INFO, timeout = 5)
return
- self.ERROR_CODE = FPGA.fpga_upgrade(path, self.DEVICE_PATH)
- if self.ERROR_CODE > 0:
- self.ERROR_MSG = FPGA.get_error_msg(self.ERROR_CODE, self.ERROR_MSG)
- self.session.openWithCallback(self.onCallbackHandler, MessageBox, _("Fail to upgrade.\nCause : " + self.ERROR_MSG + "\nDo you want to exit?"), MessageBox.TYPE_YESNO, timeout = 10, default = True)
+ 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_PATH : ", self.DEVICE_PATH
- print "FILE_PATH : ", path
+ 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 : ", device
+ print "FILE : ", path
else:
- self.session.open(MessageBox, _("Success!!"), MessageBox.TYPE_INFO, timeout = 5)
+ #self.session.open(MessageBox, _("Success!!"), MessageBox.TYPE_INFO, timeout = 5)
+ self.session.open(UpgradeStatus, self, timeout = 20)
+
+ def onClickRed(self):
+ self.doExit()
+
+ # run upgrade!!
+ def onClickGreen(self):
+ #self.session.open(MessageBox, _("Upgrade will take about 5 minutes to finish."), MessageBox.TYPE_INFO, timeout = 10)
+ message = "Upgrade will take about 5 minutes to finish.\nDo you want to upgrade?"
+ self.session.openWithCallback(self.doUpgradeHandler, MessageBox, _(message), MessageBox.TYPE_YESNO, timeout = 10, default = True)
def onClickBlue(self):
fname = ''