Merge pull request #30 from adamliyi/powercap3

skeleton: Rewrite setValue() method for Dbus object /org/openbmc/sens…
diff --git a/Makefile b/Makefile
index ea2dde2..65787ff 100755
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@
 %.o: objects/pflash/libflash/%.c
 	$(CC) -c -o obj/$@ $< $(CFLAGS) $(INCLUDES)
 
-all: setup libopenbmc_intf power_control led_controller button_power button_reset control_host host_watchdog control_bmc board_vpd pcie_slot_present flash_bios flasher control_bmc_barreleye pflash hwmons_barreleye
+all: setup libopenbmc_intf power_control led_controller button_power button_reset control_host host_watchdog board_vpd pcie_slot_present flash_bios flasher pflash hwmons_barreleye control_bmc
 
 setup: 
 	mkdir -p obj lib
@@ -39,6 +39,9 @@
 led_controller: led_controller.o gpio.o object_mapper.o libopenbmc_intf
 	$(CC) -o bin/$@.exe obj/gpio.o obj/led_controller.o obj/object_mapper.o $(LDFLAGS) $(LIBS)
 
+led_controller_new: led_controller_new.o
+	$(CC) -o bin/$@.exe obj/led_controller_new.o $(LDFLAGS) $(LIBS) -lsystemd
+
 button_power: button_power_obj.o gpio.o object_mapper.o libopenbmc_intf
 	$(CC) -o bin/$@.exe obj/button_power_obj.o obj/gpio.o obj/object_mapper.o $(LDFLAGS) $(LIBS)
 
@@ -55,12 +58,6 @@
 host_watchdog: host_watchdog_obj.o object_mapper.o libopenbmc_intf
 	$(CC) -o bin/$@.exe obj/host_watchdog_obj.o obj/object_mapper.o  $(LDFLAGS) $(LIBS)
 
-control_bmc: control_bmc_obj.o libopenbmc_intf
-	$(CC) -o bin/$@.exe obj/control_bmc_obj.o $(LDFLAGS) $(LIBS)
-
-control_bmc_barreleye: control_bmc_barreleye.o libopenbmc_intf
-	$(CC) -o bin/$@.exe obj/control_bmc_barreleye.o $(LDFLAGS) $(LIBS)
-
 board_vpd: board_vpd_obj.o libopenbmc_intf
 	$(CC) -o bin/$@.exe obj/board_vpd_obj.o $(LDFLAGS) $(LIBS)
 
@@ -76,3 +73,6 @@
 hwmons_barreleye: hwmons_barreleye.o object_mapper.o libopenbmc_intf
 	$(CC) -o bin/$@.exe obj/hwmons_barreleye.o obj/object_mapper.o  $(LDFLAGS) $(LIBS)
 
+control_bmc: control_bmc_obj.o libopenbmc_intf
+	$(CC) -o bin/$@.exe obj/control_bmc_obj.o $(LDFLAGS) $(LIBS)
+
diff --git a/bin/Barreleye.py b/bin/Barreleye.py
index e9b188b..386a2d6 100755
--- a/bin/Barreleye.py
+++ b/bin/Barreleye.py
@@ -141,15 +141,12 @@
 		'monitor_process' : True,
 		'process_name'    : 'button_power.exe',
 	},
-
         'reset_button' : {
                 'system_state'    : 'BMC_STARTING',
                 'start_process'   : True,
                 'monitor_process' : True,
                 'process_name'    : 'button_reset.exe',
         },
-
-
 	'led_control' : {
 		'system_state'    : 'BMC_STARTING',
 		'start_process'   : True,
@@ -162,6 +159,12 @@
 		'monitor_process' : True,
 		'process_name'    : 'flash_bios.exe',
 	},
+	'bmc_flash_control' : {
+		'system_state'    : 'BMC_STARTING',
+		'start_process'   : True,
+		'monitor_process' : True,
+		'process_name'    : 'bmc_update.py',
+	},
 	'download_manager' : {
 		'system_state'    : 'BMC_STARTING',
 		'start_process'   : True,
@@ -186,7 +189,21 @@
 		'start_process'   : True,
 		'monitor_process' : False,
 		'process_name'    : 'phosphor-read-eeprom',
-		'args'            : ['--eeprom','/sys/devices/platform/ahb/ahb:apb/1e78a000.i2c/1e78a040.i2c-bus/i2c-0/0-0050/eeprom','--fruid','64'],
+		'args'            : ['--eeprom','/sys/bus/i2c/devices/0-0050/eeprom','--fruid','64'],
+	},
+	'exp_vpd' : {
+		'system_state'    : 'BMC_STARTING2',
+		'start_process'   : True,
+		'monitor_process' : False,
+		'process_name'    : 'phosphor-read-eeprom',
+		'args'            : ['--eeprom','/sys/bus/i2c/devices/6-0051/eeprom','--fruid','65'],
+	},
+	'hdd_vpd' : {
+		'system_state'    : 'BMC_STARTING2',
+		'start_process'   : True,
+		'monitor_process' : False,
+		'process_name'    : 'phosphor-read-eeprom',
+		'args'            : ['--eeprom','/sys/bus/i2c/devices/6-0055/eeprom','--fruid','66'],
 	},
 	'restore' : {
 		'system_state'    : 'BMC_READY',
@@ -194,6 +211,12 @@
 		'monitor_process' : False,
 		'process_name'    : 'discover_system_state.py',
 	},
+	'bmc_control' : {
+		'system_state'    : 'BMC_STARTING',
+		'start_process'   : True,
+		'monitor_process' : True,
+		'process_name'    : 'control_bmc.exe',
+	},
 }
 
 CACHED_INTERFACES = {
@@ -211,6 +234,8 @@
 
 	'<inventory_root>/system/chassis/motherboard' : { 'fru_type' : 'MAIN_PLANAR','is_fru' : True, },
 	'<inventory_root>/system/chassis/io_board' : { 'fru_type' : 'DAUGHTER_CARD','is_fru' : True, },
+	'<inventory_root>/system/chassis/sas_expander' : { 'fru_type' : 'DAUGHTER_CARD','is_fru' : True, },
+	'<inventory_root>/system/chassis/hdd_backplane' : { 'fru_type' : 'DAUGHTER_CARD','is_fru' : True, },
 
 	'<inventory_root>/system/systemevent'                  : { 'fru_type' : 'SYSTEM_EVENT', 'is_fru' : False, },
 	'<inventory_root>/system/chassis/motherboard/refclock' : { 'fru_type' : 'MAIN_PLANAR', 'is_fru' : False, },
@@ -223,6 +248,7 @@
 	'<inventory_root>/system/chassis/fan2' : { 'fru_type' : 'FAN','is_fru' : True, },
 	'<inventory_root>/system/chassis/fan3' : { 'fru_type' : 'FAN','is_fru' : True, },
 	'<inventory_root>/system/chassis/fan4' : { 'fru_type' : 'FAN','is_fru' : True, },
+	'<inventory_root>/system/chassis/fan5' : { 'fru_type' : 'FAN','is_fru' : True, },
 
 	'<inventory_root>/system/chassis/motherboard/bmc' : { 'fru_type' : 'BMC','is_fru' : False, 'manufacturer' : 'ASPEED' },
 
@@ -363,6 +389,8 @@
 		'CHASSIS_2'  : '<inventory_root>/system/chassis',
 		'CHASSIS_100': '<inventory_root>/system/chassis',
 		'BOARD_100'  : '<inventory_root>/system/chassis/io_board',
+		'BOARD_101'  : '<inventory_root>/system/chassis/sas_expander',
+		'BOARD_102'  : '<inventory_root>/system/chassis/hdd_backplane',
 		'CHASSIS_3'  : '<inventory_root>/system/chassis/motherboard',
 		'BOARD_1'    : '<inventory_root>/system/chassis/motherboard/cpu0',
 		'BOARD_2'    : '<inventory_root>/system/chassis/motherboard/cpu1',
@@ -485,8 +513,8 @@
 		0x09 : '/org/openbmc/sensors/host/BootCount',
 		0x05 : '/org/openbmc/sensors/host/BootProgress',
 		0x04 : '/org/openbmc/sensors/host/HostStatus',
-		0x08 : '/org/openbmc/sensors/host/OccStatus',
-		0x0A : '/org/openbmc/sensors/host/OccStatus1',
+		0x08 : '/org/openbmc/sensors/host/cpu0/OccStatus',
+		0x0A : '/org/openbmc/sensors/host/cpu1/OccStatus',
 		0x32 : '/org/openbmc/sensors/host/OperatingSystemStatus',
 		0x33 : '/org/openbmc/sensors/host/powercap',
 	},
@@ -591,6 +619,14 @@
 		}
          },
 	'3-0050' : {
+		'names' : {
+			'caps_curr_powercap' : { 'object_path' : 'powercap/curr_cap','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+			'caps_curr_powerreading' : { 'object_path' : 'powercap/system_power','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+			'caps_max_powercap' : { 'object_path' : 'powercap/max_cap','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+			'caps_min_powercap' : { 'object_path' : 'powercap/min_cap','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+			'caps_norm_powercap' : { 'object_path' : 'powercap/n_cap','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+			'caps_user_powerlimit' : { 'object_path' : 'powercap/user_cap','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+		},
 		'labels' : {
 		'176' :  { 'object_path' : 'temperature/cpu0/core0','poll_interval' : 5000,'scale' : 1000,'units' : 'C',
 			'critical_upper' : 100, 'critical_lower' : -100, 'warning_upper' : 90, 'warning_lower' : -99, 'emergency_enabled' : True },
diff --git a/bin/Palmetto.py b/bin/Palmetto.py
index 5d53e41..9f89e3f 100755
--- a/bin/Palmetto.py
+++ b/bin/Palmetto.py
@@ -149,6 +149,11 @@
 		'process_name'    : 'fan.exe',
 		'args'            : [ 'fan0','fan1','fan2','fan3','fan4' ]
 	}
+	'bmc_control' : {
+		'system_state'    : 'BMC_STARTING',
+		'start_process'   : True,
+		'monitor_process' : True,
+		'process_name'    : 'control_bmc.exe',
 }
 
 CACHED_INTERFACES = {
@@ -252,7 +257,7 @@
 		0x21 : '<inventory_root>/system/chassis/motherboard/dimm3',
 		0x09 : '/org/openbmc/sensors/host/BootCount',
 		0x05 : '/org/openbmc/sensors/host/BootProgress',
-		0x08 : '/org/openbmc/sensors/host/OccStatus',
+		0x08 : '/org/openbmc/sensors/host/cpu0/OccStatus',
 		0x32 : '/org/openbmc/sensors/host/OperatingSystemStatus',
 		0x33 : '/org/openbmc/sensors/host/PowerCap',
 	},
@@ -297,5 +302,15 @@
 		'names' : {
 			'temp1_input' : { 'object_path' : 'temperature/ambient','poll_interval' : 5000,'scale' : 1000,'units' : 'C' },
 		}
+	},
+	'3-0050' : {
+		'names' : {
+			'caps_curr_powercap' : { 'object_path' : 'powercap/curr_cap','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+			'caps_curr_powerreading' : { 'object_path' : 'powercap/system_power','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+			'caps_max_powercap' : { 'object_path' : 'powercap/max_cap','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+			'caps_min_powercap' : { 'object_path' : 'powercap/min_cap','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+			'caps_norm_powercap' : { 'object_path' : 'powercap/n_cap','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+			'caps_user_powerlimit' : { 'object_path' : 'powercap/user_cap','poll_interval' : 10000,'scale' : 1,'units' : 'W' },
+		}
 	}
 }
diff --git a/bin/Sensors.py b/bin/Sensors.py
index d31f513..f951eeb 100755
--- a/bin/Sensors.py
+++ b/bin/Sensors.py
@@ -177,6 +177,8 @@
 		
 class OccStatusSensor(VirtualSensor):
 	def __init__(self,bus,name):
+		## default path. can be override
+		self.sysfs_attr = "/sys/class/i2c-adapter/i2c-3/3-0050/online"
 		VirtualSensor.__init__(self,bus,name)
 		self.setValue("Disabled")
 		bus.add_signal_receiver(self.SystemStateHandler,signal_name = "GotoSystemState")
@@ -184,7 +186,6 @@
 	def SystemStateHandler(self,state):
 		if (state == "HOST_POWERED_OFF"):
 			self.setValue("Disabled")
-			
 
 	##override setValue method
 	@dbus.service.method(SensorValue.IFACE_NAME,
@@ -192,14 +193,10 @@
 	def setValue(self,value):
 		if (value == "Enabled"):
 			print "Installing OCC device"
-			os.system("echo occ-i2c 0x50 >  /sys/bus/i2c/devices/i2c-3/new_device")
-			os.system("echo occ-i2c 0x51 >  /sys/bus/i2c/devices/i2c-3/new_device")
+			os.system("echo 1 > " +  self.sysfs_attr)
 		else:
 			print "Deleting OCC device"
-			os.system("echo 0x50 >  /sys/bus/i2c/devices/i2c-3/delete_device")
-			os.system("echo 0x51 >  /sys/bus/i2c/devices/i2c-3/delete_device")
-
-
+			os.system("echo 0 > " +  self.sysfs_attr)
 		SensorValue.setValue(self,value)
 			
 	@dbus.service.signal(CONTROL_IFACE,signature='s')
diff --git a/bin/bmc_update.py b/bin/bmc_update.py
new file mode 100755
index 0000000..e68dcf7
--- /dev/null
+++ b/bin/bmc_update.py
@@ -0,0 +1,126 @@
+#!/usr/bin/python -u
+
+import gobject
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+import Openbmc
+import shutil
+import tarfile
+
+DBUS_NAME = 'org.openbmc.control.BmcFlash'
+OBJ_NAME = '/org/openbmc/control/flash/bmc'
+FLASH_INTF = 'org.openbmc.Flash'
+DOWNLOAD_INTF = 'org.openbmc.managers.Download'
+
+UPDATE_PATH = '/run/initramfs'
+
+
+def doExtract(members,files):
+    for tarinfo in members:
+        if files.has_key(tarinfo.name) == True:
+            yield tarinfo
+
+
+class BmcFlashControl(Openbmc.DbusProperties,Openbmc.DbusObjectManager):
+	def __init__(self,bus,name):
+		self.dbus_objects = { }
+		Openbmc.DbusProperties.__init__(self)
+		Openbmc.DbusObjectManager.__init__(self)
+		dbus.service.Object.__init__(self,bus,name)
+		
+		self.Set(DBUS_NAME,"status","Idle")
+		self.Set(DBUS_NAME,"filename","")
+		self.Set(DBUS_NAME,"preserve_network_settings",False)
+		self.Set(DBUS_NAME,"restore_application_defaults",False)
+		self.Set(DBUS_NAME,"update_kernel_and_apps_only",False)
+	
+		bus.add_signal_receiver(self.download_error_handler,signal_name = "DownloadError")
+		bus.add_signal_receiver(self.download_complete_handler,signal_name = "DownloadComplete")
+
+		self.InterfacesAdded(name,self.properties)
+
+
+	@dbus.service.method(DBUS_NAME,
+		in_signature='ss', out_signature='')
+	def updateViaTftp(self,ip,filename):
+		self.TftpDownload(ip,filename)
+		self.Set(DBUS_NAME,"status","Downloading")
+		
+	@dbus.service.signal(DOWNLOAD_INTF,signature='ss')
+	def TftpDownload(self,ip,filename):
+		self.Set(DBUS_NAME,"filename",filename)
+		pass		
+
+
+	## Signal handler
+	def download_error_handler(self,filename):
+		if (filename == self.Get(DBUS_NAME,"filename")):
+			self.Set(DBUS_NAME,"status","Download Error")
+
+	def download_complete_handler(self,outfile,filename):
+		## do update
+		if (filename != self.Get(DBUS_NAME,"filename")):
+			return
+	
+		print "Download complete. Updating..."
+	
+		self.Set(DBUS_NAME,"status","Download Complete")
+		copy_files = {}
+		
+		## determine needed files
+		if (self.Get(DBUS_NAME,"update_kernel_and_apps_only") == False):
+			copy_files["image-bmc"] = True
+		else:
+			copy_files["image-kernel"] = True
+			copy_files["image-initramfs"] = True
+			copy_files["image-rofs"] = True
+
+		if (self.Get(DBUS_NAME,"restore_application_defaults") == True):
+			copy_files["image-rofs"] = True
+			
+		
+		## make sure files exist in archive
+		try:
+			tar = tarfile.open(outfile,"r")
+			files = {}
+			for f in tar.getnames():
+				files[f] = True
+			tar.close()
+			for f in copy_files.keys():
+				if (files.has_key(f) == False):
+					raise Exception("ERROR: File not found in update archive: "+f)							
+
+		except Exception as e:
+			print e
+			self.Set(DBUS_NAME,"status","Update Error")
+			return
+
+		try:
+			tar = tarfile.open(outfile,"r")
+			tar.extractall(UPDATE_PATH,members=doExtract(tar,copy_files))
+			tar.close()
+	
+			if (self.Get(DBUS_NAME,"preserve_network_settings") == True):
+				shutil.copy2("/dev/mtd2",UPDATE_PATH+"image-u-boot-env")
+				
+		except Exception as e:
+			print e
+			self.Set(DBUS_NAME,"status","Update Error")
+				
+		
+
+		self.Set(DBUS_NAME,"status","Update Success.  Please reboot.")
+		
+
+if __name__ == '__main__':
+    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+    bus = Openbmc.getDBus()
+    name = dbus.service.BusName(DBUS_NAME, bus)
+    obj = BmcFlashControl(bus, OBJ_NAME)
+    mainloop = gobject.MainLoop()
+    
+    print "Running Bmc Flash Control"
+    mainloop.run()
+
diff --git a/bin/chassis_control.py b/bin/chassis_control.py
index fa3b9b6..2ed954e 100755
--- a/bin/chassis_control.py
+++ b/bin/chassis_control.py
@@ -46,13 +46,16 @@
 				'object_name' : '/org/openbmc/HostServices',
 				'interface_name' : 'org.openbmc.HostServices'
 			},
+			'settings' : {
+				'bus_name' : 'org.openbmc.settings.Host',
+				'object_name' : '/org/openbmc/settings/host0',
+				'interface_name' : 'org.freedesktop.DBus.Properties'
+			},
 		}
 
 		#uuid
 		self.Set(DBUS_NAME,"uuid",str(uuid.uuid1()))
 		self.Set(DBUS_NAME,"reboot",0)
-		self.Set(DBUS_NAME,"power_policy",0)	
-		self.Set(DBUS_NAME,"last_system_state","")
 
 		bus.add_signal_receiver(self.power_button_signal_handler, 
 					dbus_interface = "org.openbmc.Button", signal_name = "Released", 
@@ -156,25 +159,15 @@
 		intf = self.getInterface('power_control')
 		return intf.getPowerState()
 
-	@dbus.service.method(DBUS_NAME,
-		in_signature='', out_signature='')
-	def setDebugMode(self):
-		return None
-
-	@dbus.service.method(DBUS_NAME,
-		in_signature='i', out_signature='')
-	def setPowerPolicy(self,policy):
-		self.Set(DBUS_NAME,"power_policy",policy)	
-		return None
-
-
 	## Signal handler
 
 	def SystemStateHandler(self,state_name):
-		self.Set(DBUS_NAME,"last_system_state",state_name)	
+		if (state_name == "HOST_POWERED_OFF" or state_name == "HOST_POWERED_ON"):
+			intf = self.getInterface('settings')
+			intf.Set("org.openbmc.settings.Host","system_state",state_name)
+
 		if (state_name == "HOST_POWERED_OFF" and self.Get(DBUS_NAME,"reboot")==1):
 			self.powerOn()
-				
 
 	def power_button_signal_handler(self):
 		# toggle power
diff --git a/bin/discover_system_state.py b/bin/discover_system_state.py
index 236bd01..5bd8fdc 100755
--- a/bin/discover_system_state.py
+++ b/bin/discover_system_state.py
@@ -13,9 +13,14 @@
 		'object_name' : '/org/openbmc/control/power0',
 		'interface_name' : 'org.openbmc.control.Power'
 	},
-	'occstatus' : { 
+	'occstatus0' : { 
 		'bus_name' : 'org.openbmc.Sensors',
-		'object_name' : '/org/openbmc/sensors/host/OccStatus',
+		'object_name' : '/org/openbmc/sensors/host/cpu0/OccStatus',
+		'interface_name' : 'org.openbmc.SensorValue'
+	},
+	'occstatus1' : { 
+		'bus_name' : 'org.openbmc.Sensors',
+		'object_name' : '/org/openbmc/sensors/host/cpu1/OccStatus',
 		'interface_name' : 'org.openbmc.SensorValue'
 	},
 	'bootprogress' : { 
@@ -23,6 +28,16 @@
 		'object_name' : '/org/openbmc/sensors/host/BootProgress',
 		'interface_name' : 'org.openbmc.SensorValue'
 	},
+	'chassis' : { 
+		'bus_name' : 'org.openbmc.control.Chassis',
+		'object_name' : '/org/openbmc/control/chassis0',
+		'interface_name' : 'org.openbmc.control.Chassis'
+	},
+	'settings' : {
+		'bus_name' : 'org.openbmc.settings.Host',
+		'object_name' : '/org/openbmc/settings/host0',
+		'interface_name' : 'org.freedesktop.DBus.Properties'
+	},
 }
 
 def getInterface(bus,objs,key):
@@ -41,9 +56,21 @@
 if (pgood == 1):
 	intf = getInterface(bus,dbus_objects,'bootprogress')
 	intf.setValue("FW Progress, Starting OS")
-	intf = getInterface(bus,dbus_objects,'occstatus')
+	intf = getInterface(bus,dbus_objects,'occstatus0')
 	intf.setValue("Enabled")
-	
+	intf = getInterface(bus,dbus_objects,'occstatus1')
+	intf.setValue("Enabled")
+else:
+	## Power is off, so check power policy
+	settings_intf = getInterface(bus,dbus_objects,'settings')
+	system_state = settings_intf.Get("org.openbmc.settings.Host","system_state")
+	power_policy = settings_intf.Get("org.openbmc.settings.Host","power_policy")
 
-		
+	print "Last System State: "+system_state+";  Power Policy: "+power_policy
+	chassis_intf = getInterface(bus,dbus_objects,'chassis')
+	if (power_policy == "ALWAYS_POWER_ON" or
+	   (power_policy == "RESTORE_LAST_STATE" and 
+	    system_state =="HOST_POWERED_ON")):
+		chassis_intf.powerOn()
+
 
diff --git a/bin/download_manager.py b/bin/download_manager.py
index 2a4cab9..36005d5 100755
--- a/bin/download_manager.py
+++ b/bin/download_manager.py
@@ -5,6 +5,7 @@
 import dbus
 import dbus.service
 import dbus.mainloop.glib
+import subprocess
 import Openbmc
 if (len(sys.argv) < 2):
 	print "Usage:  download_manager.py [system name]"
@@ -20,7 +21,11 @@
 	def __init__(self,bus,name):
 		dbus.service.Object.__init__(self,bus,name)
 		bus.add_signal_receiver(self.DownloadHandler, 
-			dbus_interface = "org.openbmc.Flash", signal_name = "Download", path_keyword = "path")
+			dbus_interface = "org.openbmc.Flash",
+			signal_name = "Download", path_keyword = "path")
+		bus.add_signal_receiver(self.TftpDownloadHandler,
+			signal_name = "TftpDownload", path_keyword = "path")
+
 
 	@dbus.service.signal(DBUS_NAME,signature='ss')
 	def DownloadComplete(self,outfile,filename):
@@ -31,6 +36,24 @@
 	def DownloadError(self,filename):
 		pass
 
+	def TftpDownloadHandler(self,ip,filename,path = None):
+		try:
+			filename = str(filename)
+			print "Downloading: "+filename+" from "+ip
+			outfile = System.FLASH_DOWNLOAD_PATH+"/"+filename
+			rc = subprocess.call(["tftp", "-l",outfile,"-r",filename,"-g",ip])
+			if (rc == 0):
+				self.DownloadComplete(outfile,filename)
+			else:
+				self.DownloadError(filename)
+
+
+		except Exception as e:
+			print "ERROR DownloadManager: "+str(e)
+			self.DownloadError(filename)
+
+
+	## TODO: this needs to be deprecated.  Shouldn't call flash interface from here
 	def DownloadHandler(self,url,filename,path = None):
 		try:
 			filename = str(filename)
diff --git a/bin/hconsole b/bin/hconsole
index 43e2832..426056b 100755
--- a/bin/hconsole
+++ b/bin/hconsole
@@ -5,5 +5,5 @@
 echo "[Enter] to continue"
 read a
 devmem 0x1e78909c 32 0x08060000
-screen -U -L /dev/ttyS3 115200
+screen -U /dev/ttyS3 115200
 devmem 0x1e78909c 32 0x00000000
diff --git a/bin/ipmid.py b/bin/ipmid.py
deleted file mode 100755
index 35bd7e9..0000000
--- a/bin/ipmid.py
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import subprocess
-import dbus
-import string
-import os
-import fcntl
-import glib
-import gobject
-import dbus.service
-import dbus.mainloop.glib
-
-DBUS_NAME = 'org.openbmc.HostIpmi'
-OBJ_NAME = '/org/openbmc/HostIpmi/1'
-
-def print_packet(seq, netfn, cmd, data):
-#    print 'seq:   0x%02x\nnetfn: 0x%02x\ncmd:   0x%02x\ndata:  [%s]' % (
-#            seq, netfn, cmd,
-#            ", ".join(['0x%02x' % x for x in data]))
-        new_str = ""
-        for x in data:
-                new_str += "0x%s " % (x.encode('hex'))
-        print new_str
-
-
-class Ipmid(dbus.service.Object):
-    def __init__(self, bus, name):
-        dbus.service.Object.__init__(self,bus,name)
-
-    def setReader(self, reader):
-        self.reader = reader
-
-    @dbus.service.signal(DBUS_NAME, "yyyay")
-    def ReceivedMessage(self, seq, netfn, cmd, data):
-        #print("IPMI packet from host. Seq = 0x%x Netfn = 0x%x Cmd = 0x%x" %
-        #      (ord(seq), ord(netfn), ord(cmd)))
-        print_packet(seq, netfn, cmd, data)
-
-    @dbus.service.method(DBUS_NAME, "", "")
-    def test(self):
-        print("TEST")
-
-    @dbus.service.method(DBUS_NAME, "yyyay", "x")
-    def sendMessage(self, seq, netfn, cmd, data):
-        #print("IPMI packet sent to host. Seq = 0x%x Netfn = 0x%x Cmd = 0x%x" %
-        #      (int(seq), int(netfn), int(cmd)))
-        #print_packet(seq, netfn, cmd, data)
-
-        self.reader.write(seq, netfn, cmd, data)
-
-        return 0
-
-class BtReader(object):
-    def __init__(self, ipmi_obj):
-        self.ipmi_obj = ipmi_obj
-        flags = os.O_NONBLOCK | os.O_RDWR
-        self.bt = os.open("/dev/bt-host", flags)
-        glib.io_add_watch(self.bt, glib.IO_IN, self.io_callback)
-        ipmi_obj.setReader(self)
-
-    def write(self, seq, netfn, cmd, data):
-        # Untested
-        val = chr(netfn) + chr(seq) + chr(cmd)
-        val += reduce(lambda a, b: a + chr(b), data, "")
-        val = chr(len(val)) + val
-        os.write(self.bt, val)
-
-    def io_callback(self, fd, condition):
-        data = os.read(self.bt, 128)
-        if (len(data) > 2):
-            self.ipmi_obj.ReceivedMessage(data[2], data[1], data[3], data[4:])
-        return True
-
-def main():
-    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-    bus = dbus.SystemBus()
-    name = dbus.service.BusName(DBUS_NAME, bus)
-    obj = Ipmid(bus, OBJ_NAME)
-    r = BtReader(obj)
-    mainloop = gobject.MainLoop()
-    print("Started")
-    mainloop.run()
-
-if __name__ == '__main__':
-    sys.exit(main())
diff --git a/bin/obmcutil b/bin/obmcutil
index 55b5e2d..e63fa27 100755
--- a/bin/obmcutil
+++ b/bin/obmcutil
@@ -175,7 +175,7 @@
 bus_name = objinfo['bus_name']
 obj_path = objinfo['object_name']
 intf_name = objinfo['interface_name']
-obj = bus.get_object(bus_name,obj_path,introspect=False)
+obj = bus.get_object(bus_name,obj_path)
 
 if (method_name != ""):
 	methd = obj.get_dbus_method(method_name,intf_name)
diff --git a/bin/sensor_manager2.py b/bin/sensor_manager2.py
index c924a75..b5aac53 100755
--- a/bin/sensor_manager2.py
+++ b/bin/sensor_manager2.py
@@ -61,8 +61,17 @@
 
 	obj_path = OBJ_PATH+"/host/BootProgress"
 	root_sensor.add(obj_path,Sensors.BootProgressSensor(bus,obj_path))
-	obj_path = OBJ_PATH+"/host/OccStatus"
-	root_sensor.add(obj_path,Sensors.OccStatusSensor(bus,obj_path))
+
+	obj_path = OBJ_PATH+"/host/cpu0/OccStatus"
+	sensor_obj = Sensors.OccStatusSensor(bus,obj_path)
+	sensor_obj.sysfs_attr = "/sys/class/i2c-adapter/i2c-3/3-0050/online"
+	root_sensor.add(obj_path,sensor_obj)
+
+	obj_path = OBJ_PATH+"/host/cpu1/OccStatus"
+	sensor_obj = Sensors.OccStatusSensor(bus,obj_path)
+	sensor_obj.sysfs_attr = "/sys/class/i2c-adapter/i2c-3/3-0051/online"
+	root_sensor.add(obj_path,sensor_obj)
+
 	obj_path = OBJ_PATH+"/host/BootCount"
 	root_sensor.add(obj_path,Sensors.BootCountSensor(bus,obj_path))
 	obj_path = OBJ_PATH+"/host/OperatingSystemStatus"
diff --git a/interfaces/openbmc_intf.c b/interfaces/openbmc_intf.c
index 1619115..62b6016 100644
--- a/interfaces/openbmc_intf.c
+++ b/interfaces/openbmc_intf.c
@@ -14419,22 +14419,22 @@
 
 /* ---- Introspection data for org.openbmc.control.Bmc ---- */
 
-static const _ExtendedGDBusMethodInfo _control_bmc_method_info_place_holder =
+static const _ExtendedGDBusMethodInfo _control_bmc_method_info_warm_reset =
 {
   {
     -1,
-    (gchar *) "place_holder",
+    (gchar *) "warmReset",
     NULL,
     NULL,
     NULL
   },
-  "handle-place-holder",
+  "handle-warm-reset",
   FALSE
 };
 
 static const _ExtendedGDBusMethodInfo * const _control_bmc_method_info_pointers[] =
 {
-  &_control_bmc_method_info_place_holder,
+  &_control_bmc_method_info_warm_reset,
   NULL
 };
 
@@ -14492,7 +14492,7 @@
 /**
  * ControlBmcIface:
  * @parent_iface: The parent interface.
- * @handle_place_holder: Handler for the #ControlBmc::handle-place-holder signal.
+ * @handle_warm_reset: Handler for the #ControlBmc::handle-warm-reset signal.
  *
  * Virtual table for the D-Bus interface <link linkend="gdbus-interface-org-openbmc-control-Bmc.top_of_page">org.openbmc.control.Bmc</link>.
  */
@@ -14505,20 +14505,20 @@
 {
   /* GObject signals for incoming D-Bus method calls: */
   /**
-   * ControlBmc::handle-place-holder:
+   * ControlBmc::handle-warm-reset:
    * @object: A #ControlBmc.
    * @invocation: A #GDBusMethodInvocation.
    *
-   * Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-openbmc-control-Bmc.place_holder">place_holder()</link> D-Bus method.
+   * Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-openbmc-control-Bmc.warmReset">warmReset()</link> D-Bus method.
    *
-   * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call control_bmc_complete_place_holder() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned.
+   * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call control_bmc_complete_warm_reset() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned.
    *
    * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run.
    */
-  g_signal_new ("handle-place-holder",
+  g_signal_new ("handle-warm-reset",
     G_TYPE_FROM_INTERFACE (iface),
     G_SIGNAL_RUN_LAST,
-    G_STRUCT_OFFSET (ControlBmcIface, handle_place_holder),
+    G_STRUCT_OFFSET (ControlBmcIface, handle_warm_reset),
     g_signal_accumulator_true_handled,
     NULL,
     g_cclosure_marshal_generic,
@@ -14529,27 +14529,27 @@
 }
 
 /**
- * control_bmc_call_place_holder:
+ * control_bmc_call_warm_reset:
  * @proxy: A #ControlBmcProxy.
  * @cancellable: (allow-none): A #GCancellable or %NULL.
  * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
  * @user_data: User data to pass to @callback.
  *
- * Asynchronously invokes the <link linkend="gdbus-method-org-openbmc-control-Bmc.place_holder">place_holder()</link> D-Bus method on @proxy.
+ * Asynchronously invokes the <link linkend="gdbus-method-org-openbmc-control-Bmc.warmReset">warmReset()</link> D-Bus method on @proxy.
  * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
- * You can then call control_bmc_call_place_holder_finish() to get the result of the operation.
+ * You can then call control_bmc_call_warm_reset_finish() to get the result of the operation.
  *
- * See control_bmc_call_place_holder_sync() for the synchronous, blocking version of this method.
+ * See control_bmc_call_warm_reset_sync() for the synchronous, blocking version of this method.
  */
 void
-control_bmc_call_place_holder (
+control_bmc_call_warm_reset (
     ControlBmc *proxy,
     GCancellable *cancellable,
     GAsyncReadyCallback callback,
     gpointer user_data)
 {
   g_dbus_proxy_call (G_DBUS_PROXY (proxy),
-    "place_holder",
+    "warmReset",
     g_variant_new ("()"),
     G_DBUS_CALL_FLAGS_NONE,
     -1,
@@ -14559,17 +14559,17 @@
 }
 
 /**
- * control_bmc_call_place_holder_finish:
+ * control_bmc_call_warm_reset_finish:
  * @proxy: A #ControlBmcProxy.
- * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to control_bmc_call_place_holder().
+ * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to control_bmc_call_warm_reset().
  * @error: Return location for error or %NULL.
  *
- * Finishes an operation started with control_bmc_call_place_holder().
+ * Finishes an operation started with control_bmc_call_warm_reset().
  *
  * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set.
  */
 gboolean
-control_bmc_call_place_holder_finish (
+control_bmc_call_warm_reset_finish (
     ControlBmc *proxy,
     GAsyncResult *res,
     GError **error)
@@ -14586,26 +14586,26 @@
 }
 
 /**
- * control_bmc_call_place_holder_sync:
+ * control_bmc_call_warm_reset_sync:
  * @proxy: A #ControlBmcProxy.
  * @cancellable: (allow-none): A #GCancellable or %NULL.
  * @error: Return location for error or %NULL.
  *
- * Synchronously invokes the <link linkend="gdbus-method-org-openbmc-control-Bmc.place_holder">place_holder()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received.
+ * Synchronously invokes the <link linkend="gdbus-method-org-openbmc-control-Bmc.warmReset">warmReset()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received.
  *
- * See control_bmc_call_place_holder() for the asynchronous version of this method.
+ * See control_bmc_call_warm_reset() for the asynchronous version of this method.
  *
  * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set.
  */
 gboolean
-control_bmc_call_place_holder_sync (
+control_bmc_call_warm_reset_sync (
     ControlBmc *proxy,
     GCancellable *cancellable,
     GError **error)
 {
   GVariant *_ret;
   _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),
-    "place_holder",
+    "warmReset",
     g_variant_new ("()"),
     G_DBUS_CALL_FLAGS_NONE,
     -1,
@@ -14621,16 +14621,16 @@
 }
 
 /**
- * control_bmc_complete_place_holder:
+ * control_bmc_complete_warm_reset:
  * @object: A #ControlBmc.
  * @invocation: (transfer full): A #GDBusMethodInvocation.
  *
- * Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-openbmc-control-Bmc.place_holder">place_holder()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar.
+ * Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-openbmc-control-Bmc.warmReset">warmReset()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar.
  *
  * This method will free @invocation, you cannot use it afterwards.
  */
 void
-control_bmc_complete_place_holder (
+control_bmc_complete_warm_reset (
     ControlBmc *object,
     GDBusMethodInvocation *invocation)
 {
diff --git a/interfaces/openbmc_intf.h b/interfaces/openbmc_intf.h
index bb71e45..ac7603e 100644
--- a/interfaces/openbmc_intf.h
+++ b/interfaces/openbmc_intf.h
@@ -1850,7 +1850,7 @@
 {
   GTypeInterface parent_iface;
 
-  gboolean (*handle_place_holder) (
+  gboolean (*handle_warm_reset) (
     ControlBmc *object,
     GDBusMethodInvocation *invocation);
 
@@ -1863,25 +1863,25 @@
 
 
 /* D-Bus method call completion functions: */
-void control_bmc_complete_place_holder (
+void control_bmc_complete_warm_reset (
     ControlBmc *object,
     GDBusMethodInvocation *invocation);
 
 
 
 /* D-Bus method calls: */
-void control_bmc_call_place_holder (
+void control_bmc_call_warm_reset (
     ControlBmc *proxy,
     GCancellable *cancellable,
     GAsyncReadyCallback callback,
     gpointer user_data);
 
-gboolean control_bmc_call_place_holder_finish (
+gboolean control_bmc_call_warm_reset_finish (
     ControlBmc *proxy,
     GAsyncResult *res,
     GError **error);
 
-gboolean control_bmc_call_place_holder_sync (
+gboolean control_bmc_call_warm_reset_sync (
     ControlBmc *proxy,
     GCancellable *cancellable,
     GError **error);
diff --git a/objects/control_bmc_obj.c b/objects/control_bmc_obj.c
index 6b92235..f1a47c7 100644
--- a/objects/control_bmc_obj.c
+++ b/objects/control_bmc_obj.c
@@ -67,7 +67,6 @@
 

 	//UART

 

-	

 	bmcreg = memmap(mem_fd,UART_BASE);

 	devmem(bmcreg+0x00,0x00000000);  //Set Baud rate divisor -> 13 (Baud 115200)

 	devmem(bmcreg+0x04,0x00000000);  //Set Baud rate divisor -> 13 (Baud 115200)

@@ -109,9 +108,31 @@
 	//#endif

 	control_complete_init(control,invocation);

 	//control_emit_goto_system_state(control,"BMC_STARTING");

-	

 	return TRUE;

 }

+
+static gboolean
+on_warm_reset (ControlBmc            	*bmc,
+               GDBusMethodInvocation	*invocation,
+               gpointer		            user_data)
+{
+	GError *err = NULL;
+	/* Wait a while before reboot, so the caller can be responded.
+	 * Note that g_spawn_command_line_async() cannot parse ';' as
+	 * a command separator. Need to use 'sh -c' to let shell parse it.
+	 */
+	gchar *reboot_command = "/bin/sh -c 'sleep 3;reboot'";
+
+	g_spawn_command_line_async(reboot_command, &err);
+	if (err != NULL) {
+		fprintf(stderr, "warmReset() error: %s\n", err->message);
+		g_error_free(err);
+	}
+
+	control_bmc_complete_warm_reset(bmc, invocation);
+	return TRUE;
+}
+
 gboolean go(gpointer user_data)

 {

  	cmdline *cmd = user_data;

@@ -124,8 +145,8 @@
 	//g_main_loop_quit(cmd->loop);

 	return FALSE;

 }

-

-static void 

+
+static void
 on_bus_acquired (GDBusConnection *connection,

                  const gchar     *name,

                  gpointer         user_data)

@@ -153,6 +174,12 @@
                	    G_CALLBACK (on_init),

                	    NULL); /* user_data */

 

+
+	g_signal_connect (control_bmc,
+		"handle-warm-reset",
+		G_CALLBACK (on_warm_reset),
+		NULL); /* user_data */
+
 	/* Export the object (@manager takes its own reference to @object) */

 	g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));

 	g_object_unref (object);

@@ -163,7 +190,7 @@
 	//TODO:  This is a bad hack to wait for object to be on bus

 	//sleep(1);

 	cmd->user_data = object;

-	g_idle_add(go,cmd);

+	//g_idle_add(go,cmd);

 }

 

 

@@ -210,7 +237,7 @@
                        NULL);

 

   g_main_loop_run (loop);

-  

+
   g_bus_unown_name (id);

   g_main_loop_unref (loop);

   return 0;

diff --git a/objects/flash_bios_obj.c b/objects/flash_bios_obj.c
index bbd1c55..89ddc4e 100644
--- a/objects/flash_bios_obj.c
+++ b/objects/flash_bios_obj.c
@@ -308,8 +308,8 @@
 		c--;

 	}

 

-	const char* inst[] = {"bios","bmc","bmc_ramdisk","bmc_kernel"};

-  	for (i=0;i<4;i++)

+	const char* inst[] = {"bios"};

+  	for (i=0;i<1;i++)

   	{

 		gchar* s;

 		s = g_strdup_printf ("%s/%s",dbus_object_path,inst[i]);

diff --git a/objects/led_controller_new.c b/objects/led_controller_new.c
new file mode 100755
index 0000000..c8b3f92
--- /dev/null
+++ b/objects/led_controller_new.c
@@ -0,0 +1,488 @@
+#include <stdio.h>

+#include <stdlib.h>

+#include <errno.h>

+#include <string.h>

+#include <dirent.h>

+#include <systemd/sd-bus.h>

+

+/*

+ * These are control files that are present for each led under

+ *'/sys/class/leds/<led_name>/' which are used to trigger action

+ * on the respective leds by writing predefined data.

+ */

+const char *power_ctrl = "brightness";

+const char *blink_ctrl = "trigger";

+const char *duty_on    = "delay_on";

+const char *duty_off   = "delay_off";

+

+/*

+ * --------------------------------------------------

+ * Given the dbus path, returns the name of the LED

+ * --------------------------------------------------

+ */

+char *get_led_name(const char *dbus_path)

+{

+    char *led_name = NULL;

+

+    /* Get the led name from /org/openbmc/control/led/<name> */

+    led_name = strrchr(dbus_path, '/');

+    if(led_name)

+    {

+        led_name++;

+    }

+

+    return led_name;

+}

+

+/*

+ * -------------------------------------------------------------------------

+ * Writes the 'on / off / blink' trigger to leds.

+ * -------------------------------------------------------------------------

+ */

+int write_to_led(const char *name, const char *ctrl_file, const char *value)

+{

+    /* Generic error reporter. */

+    int rc = -1;

+

+    /* To get /sys/class/leds/<name>/<control file> */

+    char led_path[128] = {0};

+

+    int len = 0;

+    len = snprintf(led_path, sizeof(led_path), 

+                   "/sys/class/leds/%s/%s",name, ctrl_file);

+    if(len >= sizeof(led_path))

+    {

+        fprintf(stderr, "Error. LED path is too long. :[%d]\n",len);

+        return rc;

+    }

+

+    FILE *fp = fopen(led_path,"w");

+    if(fp == NULL)

+    {

+        perror("Error:");

+        fprintf(stderr,"Error opening:[%s]\n",led_path);

+        return rc;

+    }

+

+    rc = fwrite(value, strlen(value), 1, fp);

+    if(rc != 1)

+    {

+        perror("Error:");

+        fprintf(stderr, "Error writing to :[%s]\n",led_path);

+    }

+

+    fclose(fp);

+

+    /* When we get here, rc would be what it was from writing to the file */

+    return (rc == 1) ? 0 : -1;

+}

+

+/*

+ * ----------------------------------------------------------------

+ * Router function for any LED operations that come via dbus

+ *----------------------------------------------------------------

+ */

+static int led_function_router(sd_bus_message *msg, void *user_data,

+                               sd_bus_error *ret_error)

+{

+    /* Generic error reporter. */

+    int rc = -1;

+

+    /* Extract the led name from the full dbus path */

+    const char *led_path = sd_bus_message_get_path(msg);

+    if(led_path == NULL)

+    {

+        fprintf(stderr, "Error. LED path is empty");

+        return sd_bus_reply_method_return(msg, "i", rc);

+    }

+

+    char *led_name = get_led_name(led_path);

+    if(led_name == NULL)

+    {

+        fprintf(stderr, "Invalid LED name for path :[%s]\n",led_path);

+        return sd_bus_reply_method_return(msg, "i", rc);

+    }

+

+    /* Now that we have the LED name, get the Operation. */

+    const char *led_function = sd_bus_message_get_member(msg);

+    if(led_function == NULL)

+    {

+        fprintf(stderr, "Null LED function specificed for : [%s]\n",led_name);

+        return sd_bus_reply_method_return(msg, "i", rc);

+    }

+

+    /* Route the user action to appropriate handlers. */

+    if( (strcmp(led_function, "setOn") == 0) ||

+        (strcmp(led_function, "setOff") == 0))

+    {

+        rc = led_stable_state_function(led_name, led_function);

+        return sd_bus_reply_method_return(msg, "i", rc);

+    }

+    else if( (strcmp(led_function, "setBlinkFast") == 0) ||

+             (strcmp(led_function, "setBlinkSlow") == 0))

+    {

+        rc = led_default_blink(led_name, led_function);

+        return sd_bus_reply_method_return(msg, "i", rc);

+    }

+    else if(strcmp(led_function, "GetLedState") == 0)

+    {

+        char value_str[10] = {0};

+        const char *led_state = NULL;

+

+        rc = read_led(led_name, power_ctrl, value_str, sizeof(value_str));

+        if(rc >= 0)

+        {

+            /* LED is active low */

+            led_state = strtoul(value_str, NULL, 0) ? "Off" : "On";

+        }

+        return sd_bus_reply_method_return(msg, "is", rc, led_state);

+    }

+    else

+    {

+        fprintf(stderr,"Invalid LED function:[%s]\n",led_function);

+    }

+

+    return sd_bus_reply_method_return(msg, "i", rc);

+}

+

+/*

+ * --------------------------------------------------------------

+ * Turn On or Turn Off the LED

+ * --------------------------------------------------------------

+ */

+int led_stable_state_function(char *led_name, char *led_function)

+{

+    /* Generic error reporter. */

+    int rc = -1;

+

+    const char *value = NULL;

+    if(strcmp(led_function, "setOn") == 0)

+    {

+        /* LED active low */

+        value = "0";

+    }

+    else if(strcmp(led_function, "setOff") == 0)

+    {

+        value  = "255";

+    }

+    else

+    {

+        fprintf(stderr,"Invalid LED stable state operation:[%s] \n",led_function);

+        return rc;

+    }

+

+    /*

+     * Before doing anything, need to turn off the blinking

+     * if there is one in progress by writing 'none' to trigger

+     */

+    rc = write_to_led(led_name, blink_ctrl, "none");

+    if(rc < 0)

+    {

+        fprintf(stderr,"Error disabling blink. Function:[%s]\n", led_function);

+        return rc;

+    }

+

+    /*

+     * Open the brightness file and write corresponding values.

+     */

+    rc = write_to_led(led_name, power_ctrl, value);

+    if(rc < 0)

+    {

+        fprintf(stderr,"Error driving LED. Function:[%s]\n", led_function);

+    }

+

+    return rc;

+}

+

+//-----------------------------------------------------------------------------------

+// Given the on and off duration, applies the action on the specified LED.

+//-----------------------------------------------------------------------------------

+int blink_led(const char *led_name, const char *on_duration, const char *off_duration)

+{

+    /* Generic error reporter */

+    int rc = -1;

+

+    /* Protocol demands that 'timer' be echoed to 'trigger' */

+    rc = write_to_led(led_name, blink_ctrl, "timer");

+    if(rc < 0)

+    {

+        fprintf(stderr,"Error writing timer to Led:[%s]\n", led_name);

+        return rc;

+    }

+

+    /*

+     * After writing 'timer to 'trigger', 2 new files get generated namely

+     *'delay_on' and 'delay_off' which are telling the time duration for a

+     * particular LED on and off.

+     */

+    rc = write_to_led(led_name, duty_on, on_duration);

+    if(rc < 0)

+    {

+        fprintf(stderr,"Error writing [%s] to delay_on:[%s]\n",on_duration,led_name);

+        return rc;

+    }

+

+    rc = write_to_led(led_name, duty_off, off_duration);

+    if(rc < 0)

+    {

+        fprintf(stderr,"Error writing [%s] to delay_off:[%s]\n",off_duration,led_name);

+    }

+

+    return rc;

+}

+

+/*

+ * ----------------------------------------------------

+ * Default blink action on the LED.

+ * ----------------------------------------------------

+ */

+int led_default_blink(char *led_name, char *blink_type)

+{

+    /* Generic error reporter */

+    int rc = -1;

+

+    /* How long the LED needs to be in on and off state while blinking */

+    const char *on_duration = NULL;

+    const char *off_duration = NULL;

+    if(strcmp(blink_type, "setBlinkSlow") == 0)

+    {

+        //*Delay 900 millisec before 'on' and delay 900 millisec before off */

+        on_duration = "900";

+        off_duration = "900";

+    }

+    else if(strcmp(blink_type, "setBlinkFast") == 0)

+    {

+        /* Delay 200 millisec before 'on' and delay 200 millisec before off */

+        on_duration = "200";

+        off_duration = "200";

+    }

+    else

+    {

+        fprintf(stderr,"Invalid blink operation:[%s]\n",blink_type);

+        return rc;

+    }

+

+    rc = blink_led(led_name, on_duration, off_duration);

+

+    return rc;

+}

+

+/*

+ * ---------------------------------------------------------------

+ * Gets the current value of passed in LED file

+ * Mainly used for reading 'brightness'

+ * NOTE : It is the responsibility of the caller to allocate

+ * sufficient space for buffer. This will read upto user supplied 

+ * size -or- entire contents of file whichever is smaller

+ * ----------------------------------------------------------------

+ */

+int read_led(const char *name, const char *ctrl_file, 

+             void *value, const size_t len)

+{

+    /* Generic error reporter. */

+    int rc = -1;

+    int count = 0;

+

+    if(value == NULL || len <= 0)

+    {

+        fprintf(stderr, "Invalid buffer passed to LED read\n");

+        return rc;

+    }

+

+    /* To get /sys/class/leds/<name>/<control file> */

+    char led_path[128] = {0};

+

+    int led_len = 0;

+    led_len = snprintf(led_path, sizeof(led_path), 

+                   "/sys/class/leds/%s/%s",name, ctrl_file);

+    if(led_len >= sizeof(led_path))

+    {

+        fprintf(stderr, "Error. LED path is too long. :[%d]\n",led_len);

+        return rc;

+    }

+

+    FILE *fp = fopen(led_path,"rb");

+    if(fp == NULL)

+    {

+        perror("Error:");

+        fprintf(stderr,"Error opening:[%s]\n",led_path);

+        return rc;

+    }

+

+    char *sysfs_value = (char *)value;

+    while(!feof(fp) && (count < len))

+    {

+        sysfs_value[count++] = fgetc(fp);

+    }

+    sysfs_value[count]='\0';

+

+    fclose(fp);

+    return 0;

+}

+

+/*

+ * -----------------------------------------------

+ * Dbus Services offered by this LED controller

+ * -----------------------------------------------

+ */

+static const sd_bus_vtable led_control_vtable[] =

+{

+    SD_BUS_VTABLE_START(0),

+    SD_BUS_METHOD("setOn", "", "i", &led_function_router, SD_BUS_VTABLE_UNPRIVILEGED),

+    SD_BUS_METHOD("setOff", "", "i", &led_function_router, SD_BUS_VTABLE_UNPRIVILEGED),

+    SD_BUS_METHOD("setBlinkFast", "", "i", &led_function_router, SD_BUS_VTABLE_UNPRIVILEGED),

+    SD_BUS_METHOD("setBlinkSlow", "", "i", &led_function_router, SD_BUS_VTABLE_UNPRIVILEGED),

+    SD_BUS_METHOD("GetLedState", "", "is", &led_function_router, SD_BUS_VTABLE_UNPRIVILEGED),

+    SD_BUS_VTABLE_END,

+};

+

+/*

+ * ---------------------------------------------

+ * Interested in all files except standard ones

+ * ---------------------------------------------

+ */

+int led_select(const struct dirent *entry)

+{

+    if( (strcmp(entry->d_name, ".") == 0) ||

+        (strcmp(entry->d_name, "..") == 0))

+    {

+        return 0;

+    }

+    return 1;

+}

+

+/*

+ * ------------------------------------------------

+ * Called as part of setting up skeleton services.

+ * -----------------------------------------------

+ */

+int start_led_services()

+{

+    /* Generic error reporter. */

+    int rc = -1;

+    int num_leds = 0;

+    int count_leds = 0;

+

+    /* Bus and slot where we are offering the LED dbus service. */

+    sd_bus *bus_type = NULL;

+    sd_bus_slot *led_slot = NULL;

+

+    /* For walking '/sys/class/leds/' looking for names of LED.*/

+    struct dirent **led_list;

+

+    /* Get a hook onto system bus. */

+    rc = sd_bus_open_system(&bus_type);

+    if(rc < 0)

+    {

+        fprintf(stderr,"Error opening system bus.\n");

+        return rc;

+    }

+

+    count_leds = num_leds = scandir("/sys/class/leds/", 

+                                    &led_list, led_select, alphasort);

+    if(num_leds <= 0)

+    {

+        fprintf(stderr,"No LEDs present in the system\n");

+

+        sd_bus_slot_unref(led_slot);

+        sd_bus_unref(bus_type);

+        return rc;

+    }

+

+    /* Fully qualified Dbus object for a particular LED */

+    char led_object[128] = {0};

+    int len = 0;

+

+    /* For each led present, announce the service on dbus. */

+    while(num_leds--)

+    {

+        memset(led_object, 0x0, sizeof(led_object));

+

+        len = snprintf(led_object, sizeof(led_object), "%s%s",

+                "/org/openbmc/controller/led/", led_list[num_leds]->d_name);

+

+        if(len >= sizeof(led_object))

+        {

+            fprintf(stderr, "Error. LED object is too long:[%d]\n",len);

+            rc = -1;

+            break;

+        }

+

+        /* Install the object */

+        rc = sd_bus_add_object_vtable(bus_type,

+                                      &led_slot,

+                                      led_object,                     /* object path */

+                                      "org.openbmc.controller.led",   /* interface name */

+                                      led_control_vtable,

+                                      NULL);

+

+        if (rc < 0)

+        {

+            fprintf(stderr, "Failed to add object to dbus: %s\n", strerror(-rc));

+            break;

+        }

+    }

+

+    /* Done with all registration. */

+    while (count_leds > 0)

+    {

+        free(led_list[--count_leds]);

+        if(count_leds == 0)

+        {

+            free(led_list);

+        }

+    }

+

+    /* If we had success in adding the providers, request for a bus name. */

+    if(rc == 0)

+    {

+        /* Take one in OpenBmc */

+        rc = sd_bus_request_name(bus_type, "org.openbmc.controller.led", 0);

+        if (rc < 0)

+        {

+            fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-rc));

+        }

+        else

+        {

+            for (;;)

+            {

+                /* Process requests */

+                rc = sd_bus_process(bus_type, NULL);

+                if (rc < 0)

+                {

+                    fprintf(stderr, "Failed to process bus: %s\n", strerror(-rc));

+                    break;

+                }

+                if (rc > 0)

+                {

+                    continue;

+                }

+

+                rc = sd_bus_wait(bus_type, (uint64_t) - 1);

+                if (rc < 0)

+                {

+                    fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-rc));

+                    break;

+                }

+            }

+        }

+    }

+    sd_bus_slot_unref(led_slot);

+    sd_bus_unref(bus_type);

+

+    return rc;

+}

+

+int main(void)

+{

+    int rc = 0;

+

+    /* This call is not supposed to return. If it does, then an error */

+    rc = start_led_services();

+    if(rc < 0)

+    {

+        fprintf(stderr, "Error starting LED Services. Exiting");

+    }

+

+    return rc;

+}

diff --git a/xml/openbmc_intf.xml b/xml/openbmc_intf.xml
index 791fc48..ead899c 100644
--- a/xml/openbmc_intf.xml
+++ b/xml/openbmc_intf.xml
@@ -107,7 +107,7 @@
 		<signal name="Started"/>
 	</interface>
 	<interface name="org.openbmc.control.Bmc">
-		<method name="place_holder"/>
+		<method name="warmReset"/>
 	</interface>
 	<interface name="org.openbmc.control.Host">
 		<method name="boot"/>