1#!/usr/bin/env python3
2
3HOME_PATH = "./"
4CACHE_PATH = "/var/cache/obmc/"
5FLASH_DOWNLOAD_PATH = "/tmp"
6GPIO_BASE = 320
7SYSTEM_NAME = "Palmetto"
8
9
10# System states
11# state can change to next state in 2 ways:
12# - a process emits a GotoSystemState signal with state name to goto
13# - objects specified in EXIT_STATE_DEPEND have started
14SYSTEM_STATES = [
15    "BASE_APPS",
16    "BMC_STARTING",
17    "BMC_READY",
18    "HOST_POWERING_ON",
19    "HOST_POWERED_ON",
20    "HOST_BOOTING",
21    "HOST_BOOTED",
22    "HOST_POWERED_OFF",
23]
24
25EXIT_STATE_DEPEND = {
26    "BASE_APPS": {
27        "/org/openbmc/sensors": 0,
28    },
29    "BMC_STARTING": {
30        "/org/openbmc/control/chassis0": 0,
31        "/org/openbmc/control/power0": 0,
32        "/org/openbmc/control/led/identify": 0,
33        "/org/openbmc/control/host0": 0,
34        "/org/openbmc/control/flash/bios": 0,
35    },
36}
37
38# method will be called when state is entered
39ENTER_STATE_CALLBACK = {
40    "HOST_POWERED_ON": {
41        "boot": {
42            "bus_name": "org.openbmc.control.Host",
43            "obj_name": "/org/openbmc/control/host0",
44            "interface_name": "org.openbmc.control.Host",
45        }
46    },
47    "BMC_READY": {
48        "setOn": {
49            "bus_name": "org.openbmc.control.led",
50            "obj_name": "/org/openbmc/control/led/identify",
51            "interface_name": "org.openbmc.Led",
52        },
53        "init": {
54            "bus_name": "org.openbmc.control.Flash",
55            "obj_name": "/org/openbmc/control/flash/bios",
56            "interface_name": "org.openbmc.Flash",
57        },
58    },
59}
60
61APPS = {
62    "startup_hacks": {
63        "system_state": "BASE_APPS",
64        "start_process": True,
65        "monitor_process": False,
66        "process_name": "startup_hacks.sh",
67    },
68    "inventory": {
69        "system_state": "BMC_STARTING",
70        "start_process": True,
71        "monitor_process": True,
72        "process_name": "inventory_items.py",
73        "args": [SYSTEM_NAME],
74    },
75    "pcie_present": {
76        "system_state": "HOST_POWERED_ON",
77        "start_process": False,
78        "monitor_process": False,
79        "process_name": "pcie_slot_present.exe",
80    },
81    "virtual_sensors": {
82        "system_state": "BMC_STARTING",
83        "start_process": True,
84        "monitor_process": True,
85        "process_name": "hwmon.py",
86        "args": [SYSTEM_NAME],
87    },
88    "sensor_manager": {
89        "system_state": "BASE_APPS",
90        "start_process": True,
91        "monitor_process": True,
92        "process_name": "sensor_manager2.py",
93        "args": [SYSTEM_NAME],
94    },
95    "host_watchdog": {
96        "system_state": "BMC_STARTING",
97        "start_process": True,
98        "monitor_process": True,
99        "process_name": "host_watchdog.exe",
100    },
101    "power_control": {
102        "system_state": "BMC_STARTING",
103        "start_process": True,
104        "monitor_process": True,
105        "process_name": "power_control.exe",
106        "args": ["3000", "10"],
107    },
108    "power_button": {
109        "system_state": "BMC_STARTING",
110        "start_process": False,
111        "monitor_process": False,
112        "process_name": "button_power.exe",
113    },
114    "led_control": {
115        "system_state": "BMC_STARTING",
116        "start_process": True,
117        "monitor_process": True,
118        "process_name": "led_controller.exe",
119    },
120    "flash_control": {
121        "system_state": "BMC_STARTING",
122        "start_process": True,
123        "monitor_process": True,
124        "process_name": "flash_bios.exe",
125    },
126    "bmc_flash_control": {
127        "system_state": "BMC_STARTING",
128        "start_process": True,
129        "monitor_process": True,
130        "process_name": "bmc_update.py",
131    },
132    "download_manager": {
133        "system_state": "BMC_STARTING",
134        "start_process": True,
135        "monitor_process": True,
136        "process_name": "download_manager.py",
137        "args": [SYSTEM_NAME],
138    },
139    "host_control": {
140        "system_state": "BMC_STARTING",
141        "start_process": True,
142        "monitor_process": True,
143        "process_name": "control_host.exe",
144    },
145    "chassis_control": {
146        "system_state": "BMC_STARTING",
147        "start_process": True,
148        "monitor_process": True,
149        "process_name": "chassis_control.py",
150    },
151    "bmc_control": {
152        "system_state": "BMC_STARTING",
153        "start_process": True,
154        "monitor_process": True,
155        "process_name": "control_bmc.exe",
156    },
157}
158
159CACHED_INTERFACES = {
160    "org.openbmc.InventoryItem": True,
161    "org.openbmc.control.Chassis": True,
162}
163INVENTORY_ROOT = "/org/openbmc/inventory"
164
165FRU_INSTANCES = {
166    "<inventory_root>/system": {
167        "fru_type": "SYSTEM",
168        "is_fru": True,
169    },
170    "<inventory_root>/system/chassis": {
171        "fru_type": "SYSTEM",
172        "is_fru": True,
173    },
174    "<inventory_root>/system/chassis/motherboard": {
175        "fru_type": "MAIN_PLANAR",
176        "is_fru": True,
177    },
178    "<inventory_root>/system/chassis/fan0": {
179        "fru_type": "FAN",
180        "is_fru": True,
181    },
182    "<inventory_root>/system/chassis/fan1": {
183        "fru_type": "FAN",
184        "is_fru": True,
185    },
186    "<inventory_root>/system/chassis/fan2": {
187        "fru_type": "FAN",
188        "is_fru": True,
189    },
190    "<inventory_root>/system/chassis/fan3": {
191        "fru_type": "FAN",
192        "is_fru": True,
193    },
194    "<inventory_root>/system/chassis/fan4": {
195        "fru_type": "FAN",
196        "is_fru": True,
197    },
198    "<inventory_root>/system/chassis/motherboard/bmc": {
199        "fru_type": "BMC",
200        "is_fru": False,
201        "manufacturer": "ASPEED",
202    },
203    "<inventory_root>/system/chassis/motherboard/cpu": {
204        "fru_type": "CPU",
205        "is_fru": True,
206    },
207    "<inventory_root>/system/chassis/motherboard/cpu/core0": {
208        "fru_type": "CORE",
209        "is_fru": False,
210    },
211    "<inventory_root>/system/chassis/motherboard/cpu/core1": {
212        "fru_type": "CORE",
213        "is_fru": False,
214    },
215    "<inventory_root>/system/chassis/motherboard/cpu/core2": {
216        "fru_type": "CORE",
217        "is_fru": False,
218    },
219    "<inventory_root>/system/chassis/motherboard/cpu/core3": {
220        "fru_type": "CORE",
221        "is_fru": False,
222    },
223    "<inventory_root>/system/chassis/motherboard/cpu/core4": {
224        "fru_type": "CORE",
225        "is_fru": False,
226    },
227    "<inventory_root>/system/chassis/motherboard/cpu/core5": {
228        "fru_type": "CORE",
229        "is_fru": False,
230    },
231    "<inventory_root>/system/chassis/motherboard/cpu/core6": {
232        "fru_type": "CORE",
233        "is_fru": False,
234    },
235    "<inventory_root>/system/chassis/motherboard/cpu/core7": {
236        "fru_type": "CORE",
237        "is_fru": False,
238    },
239    "<inventory_root>/system/chassis/motherboard/cpu/core8": {
240        "fru_type": "CORE",
241        "is_fru": False,
242    },
243    "<inventory_root>/system/chassis/motherboard/cpu/core9": {
244        "fru_type": "CORE",
245        "is_fru": False,
246    },
247    "<inventory_root>/system/chassis/motherboard/cpu/core10": {
248        "fru_type": "CORE",
249        "is_fru": False,
250    },
251    "<inventory_root>/system/chassis/motherboard/cpu/core11": {
252        "fru_type": "CORE",
253        "is_fru": False,
254    },
255    "<inventory_root>/system/chassis/motherboard/membuf": {
256        "fru_type": "MEMORY_BUFFER",
257        "is_fru": False,
258    },
259    "<inventory_root>/system/chassis/motherboard/dimm0": {
260        "fru_type": "DIMM",
261        "is_fru": True,
262    },
263    "<inventory_root>/system/chassis/motherboard/dimm1": {
264        "fru_type": "DIMM",
265        "is_fru": True,
266    },
267    "<inventory_root>/system/chassis/motherboard/dimm2": {
268        "fru_type": "DIMM",
269        "is_fru": True,
270    },
271    "<inventory_root>/system/chassis/motherboard/dimm3": {
272        "fru_type": "DIMM",
273        "is_fru": True,
274    },
275    "<inventory_root>/system/chassis/io_board/pcie_slot0": {
276        "fru_type": "PCIE_CARD",
277        "is_fru": True,
278    },
279    "<inventory_root>/system/chassis/io_board/pcie_slot1": {
280        "fru_type": "PCIE_CARD",
281        "is_fru": True,
282    },
283    "<inventory_root>/system/systemevent": {
284        "fru_type": "SYSTEM_EVENT",
285        "is_fru": False,
286    },
287    "<inventory_root>/system/chassis/motherboard/refclock": {
288        "fru_type": "MAIN_PLANAR",
289        "is_fru": False,
290    },
291    "<inventory_root>/system/chassis/motherboard/pcieclock": {
292        "fru_type": "MAIN_PLANAR",
293        "is_fru": False,
294    },
295    "<inventory_root>/system/chassis/motherboard/todclock": {
296        "fru_type": "MAIN_PLANAR",
297        "is_fru": False,
298    },
299    "<inventory_root>/system/chassis/motherboard/apss": {
300        "fru_type": "MAIN_PLANAR",
301        "is_fru": False,
302    },
303}
304
305ID_LOOKUP = {
306    "FRU": {
307        0x0D: "<inventory_root>/system/chassis",
308        0x34: "<inventory_root>/system/chassis/motherboard",
309        0x01: "<inventory_root>/system/chassis/motherboard/cpu",
310        0x02: "<inventory_root>/system/chassis/motherboard/membuf",
311        0x03: "<inventory_root>/system/chassis/motherboard/dimm0",
312        0x04: "<inventory_root>/system/chassis/motherboard/dimm1",
313        0x05: "<inventory_root>/system/chassis/motherboard/dimm2",
314        0x06: "<inventory_root>/system/chassis/motherboard/dimm3",
315        0x35: "<inventory_root>/system",
316    },
317    "FRU_STR": {
318        "PRODUCT_15": "<inventory_root>/system",
319        "CHASSIS_2": "<inventory_root>/system/chassis",
320        "BOARD_1": "<inventory_root>/system/chassis/motherboard/cpu",
321        "BOARD_2": "<inventory_root>/system/chassis/motherboard/membuf",
322        "BOARD_14": "<inventory_root>/system/chassis/motherboard",
323        "PRODUCT_3": "<inventory_root>/system/chassis/motherboard/dimm0",
324        "PRODUCT_4": "<inventory_root>/system/chassis/motherboard/dimm1",
325        "PRODUCT_5": "<inventory_root>/system/chassis/motherboard/dimm2",
326        "PRODUCT_6": "<inventory_root>/system/chassis/motherboard/dimm3",
327    },
328    "SENSOR": {
329        0x34: "<inventory_root>/system/chassis/motherboard",
330        0x37: "<inventory_root>/system/chassis/motherboard/refclock",
331        0x38: "<inventory_root>/system/chassis/motherboard/pcieclock",
332        0x39: "<inventory_root>/system/chassis/motherboard/todclock",
333        0x3A: "<inventory_root>/system/chassis/apss",
334        0x2F: "<inventory_root>/system/chassis/motherboard/cpu",
335        0x22: "<inventory_root>/system/chassis/motherboard/cpu/core1",
336        0x23: "<inventory_root>/system/chassis/motherboard/cpu/core2",
337        0x24: "<inventory_root>/system/chassis/motherboard/cpu/core3",
338        0x25: "<inventory_root>/system/chassis/motherboard/cpu/core4",
339        0x26: "<inventory_root>/system/chassis/motherboard/cpu/core5",
340        0x27: "<inventory_root>/system/chassis/motherboard/cpu/core6",
341        0x28: "<inventory_root>/system/chassis/motherboard/cpu/core9",
342        0x29: "<inventory_root>/system/chassis/motherboard/cpu/core10",
343        0x2A: "<inventory_root>/system/chassis/motherboard/cpu/core11",
344        0x2B: "<inventory_root>/system/chassis/motherboard/cpu/core12",
345        0x2C: "<inventory_root>/system/chassis/motherboard/cpu/core13",
346        0x2D: "<inventory_root>/system/chassis/motherboard/cpu/core14",
347        0x2E: "<inventory_root>/system/chassis/motherboard/membuf",
348        0x1E: "<inventory_root>/system/chassis/motherboard/dimm0",
349        0x1F: "<inventory_root>/system/chassis/motherboard/dimm1",
350        0x20: "<inventory_root>/system/chassis/motherboard/dimm2",
351        0x21: "<inventory_root>/system/chassis/motherboard/dimm3",
352        0x09: "/org/openbmc/sensors/host/BootCount",
353        0x05: "/org/openbmc/sensors/host/BootProgress",
354        0x08: "/org/openbmc/sensors/host/cpu0/OccStatus",
355        0x32: "/org/openbmc/sensors/host/OperatingSystemStatus",
356        0x33: "/org/openbmc/sensors/host/PowerCap",
357    },
358    "GPIO_PRESENT": {
359        "SLOT0_PRESENT": "<inventory_root>/system/chassis/io_board/pcie_slot0",
360        "SLOT1_PRESENT": "<inventory_root>/system/chassis/io_board/pcie_slot1",
361    },
362}
363
364GPIO_CONFIG = {}
365GPIO_CONFIG["FSI_CLK"] = {"gpio_pin": "A4", "direction": "out"}
366GPIO_CONFIG["FSI_DATA"] = {"gpio_pin": "A5", "direction": "out"}
367GPIO_CONFIG["FSI_ENABLE"] = {"gpio_pin": "D0", "direction": "out"}
368GPIO_CONFIG["POWER_PIN"] = {"gpio_pin": "E1", "direction": "out"}
369GPIO_CONFIG["CRONUS_SEL"] = {"gpio_pin": "A6", "direction": "out"}
370GPIO_CONFIG["PGOOD"] = {"gpio_pin": "C7", "direction": "in"}
371GPIO_CONFIG["BMC_THROTTLE"] = {"gpio_pin": "J3", "direction": "out"}
372GPIO_CONFIG["IDBTN"] = {"gpio_pin": "Q7", "direction": "out"}
373GPIO_CONFIG["POWER_BUTTON"] = {"gpio_pin": "E0", "direction": "both"}
374GPIO_CONFIG["PCIE_RESET"] = {"gpio_pin": "B5", "direction": "out"}
375GPIO_CONFIG["USB_RESET"] = {"gpio_pin": "B6", "direction": "out"}
376GPIO_CONFIG["SLOT0_RISER_PRESENT"] = {"gpio_pin": "N0", "direction": "in"}
377GPIO_CONFIG["SLOT1_RISER_PRESENT"] = {"gpio_pin": "N1", "direction": "in"}
378GPIO_CONFIG["SLOT2_RISER_PRESENT"] = {"gpio_pin": "N2", "direction": "in"}
379GPIO_CONFIG["SLOT0_PRESENT"] = {"gpio_pin": "N3", "direction": "in"}
380GPIO_CONFIG["SLOT1_PRESENT"] = {"gpio_pin": "N4", "direction": "in"}
381GPIO_CONFIG["SLOT2_PRESENT"] = {"gpio_pin": "N5", "direction": "in"}
382GPIO_CONFIG["MEZZ0_PRESENT"] = {"gpio_pin": "O0", "direction": "in"}
383GPIO_CONFIG["MEZZ1_PRESENT"] = {"gpio_pin": "O1", "direction": "in"}
384
385
386def convertGpio(name):
387    name = name.upper()
388    c = name[0:1]
389    offset = int(name[1:])
390    a = ord(c) - 65
391    base = a * 8 + GPIO_BASE
392    return base + offset
393
394
395HWMON_CONFIG = {
396    "2-004c": {
397        "names": {
398            "temp1_input": {
399                "object_path": "temperature/ambient",
400                "poll_interval": 5000,
401                "scale": 1000,
402                "units": "C",
403            },
404        }
405    },
406    "3-0050": {
407        "names": {
408            "caps_curr_powercap": {
409                "object_path": "powercap/curr_cap",
410                "poll_interval": 10000,
411                "scale": 1,
412                "units": "W",
413            },
414            "caps_curr_powerreading": {
415                "object_path": "powercap/system_power",
416                "poll_interval": 10000,
417                "scale": 1,
418                "units": "W",
419            },
420            "caps_max_powercap": {
421                "object_path": "powercap/max_cap",
422                "poll_interval": 10000,
423                "scale": 1,
424                "units": "W",
425            },
426            "caps_min_powercap": {
427                "object_path": "powercap/min_cap",
428                "poll_interval": 10000,
429                "scale": 1,
430                "units": "W",
431            },
432            "caps_norm_powercap": {
433                "object_path": "powercap/n_cap",
434                "poll_interval": 10000,
435                "scale": 1,
436                "units": "W",
437            },
438            "caps_user_powerlimit": {
439                "object_path": "powercap/user_cap",
440                "poll_interval": 10000,
441                "scale": 1,
442                "units": "W",
443            },
444        }
445    },
446}
447
448# Miscellaneous non-poll sensor with system specific properties.
449# The sensor id is the same as those defined in ID_LOOKUP['SENSOR'].
450MISC_SENSORS = {
451    0x09: {"class": "BootCountSensor"},
452    0x05: {"class": "BootProgressSensor"},
453    0x08: {
454        "class": "OccStatusSensor",
455        "os_path": "/sys/class/i2c-adapter/i2c-3/3-0050/online",
456    },
457    0x32: {"class": "OperatingSystemStatusSensor"},
458    0x33: {
459        "class": "PowerCap",
460        "os_path": "/sys/class/hwmon/hwmon1/user_powercap",
461    },
462}
463