blob: 9a0f4504d8948097a0e5bf04236125a99161563c [file] [log] [blame]
Norman James372b9662015-10-06 07:47:55 -05001#!/usr/bin/env python
2
3import sys
4import gobject
5import dbus
6import dbus.service
7import dbus.mainloop.glib
8import tftpy
9
10
11
12DBUS_NAME = 'org.openbmc.managers.Flash'
13OBJ_NAME = '/org/openbmc/managers/'+sys.argv[1]
14TFTP_PORT = 69
15DOWNLOAD_DIR = '/tmp'
16
17class FlashManagerObject(dbus.service.Object):
18 def __init__(self,bus,name):
19 self.dbus_objects = { }
20
21 dbus.service.Object.__init__(self,bus,name)
22 ## load utilized objects
23 self.dbus_objects = {
24 'bios' : {
25 'bus_name' : 'org.openbmc.flash.Bios',
26 'object_name' : '/org/openbmc/flash/Bios_0',
27 'interface_name' : 'org.openbmc.Flash'
28 },
29 'bmc' : {
30 'bus_name' : 'org.openbmc.flash.Bmc',
31 'object_name' : '/org/openbmc/flash/Bmc_0',
32 'interface_name' : 'org.openbmc.Flash'
33 }
34 }
35 bus = dbus.SessionBus()
36
37 def getInterface(self,name):
38 o = self.dbus_objects[name]
39 obj = bus.get_object(o['bus_name'],o['object_name'])
40 return dbus.Interface(obj,o['interface_name'])
41
42 @dbus.service.method(DBUS_NAME,
43 in_signature='sss', out_signature='')
44 def updateFromTftp(self,flash,url,filename):
45 if (self.dbus_objects.has_key(flash) == False):
46 print "Error: Not a valid flash device: "+flash
47 return
48 try:
49 client = tftpy.TftpClient(url, TFTP_PORT)
50 outfile = DOWNLOAD_DIR+"/"+filename
51 client.download(filename,outfile)
52 intf = self.getInterface(flash)
53 intf.update(outfile)
54
55 except Exception as e:
56 print "ERROR: "+str(e)
57
58
59
60if __name__ == '__main__':
61 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
62
63 bus = dbus.SessionBus()
64 name = dbus.service.BusName(DBUS_NAME, bus)
65 obj = FlashManagerObject(bus, OBJ_NAME)
66 mainloop = gobject.MainLoop()
67
68 print "Running Flash Manager"
69 mainloop.run()
70