1310d8641SShawn McCarney# phosphor-regulators Configuration File 2310d8641SShawn McCarney 3860d51afSShawn McCarney## Table of Contents 4860d51afSShawn McCarney 50dbce568SPatrick Williams- [Overview](#overview) 60dbce568SPatrick Williams- [Data Format](#data-format) 70dbce568SPatrick Williams- [Example](#example) 80dbce568SPatrick Williams- [Name](#name) 90dbce568SPatrick Williams- [Contents](#contents) 100dbce568SPatrick Williams- [Validation](#validation) 110dbce568SPatrick Williams- [Installation](#installation) 120dbce568SPatrick Williams- [Loading and Reloading](#loading-and-reloading) 130dbce568SPatrick Williams- [Testing](#testing) 14860d51afSShawn McCarney 15310d8641SShawn McCarney## Overview 16310d8641SShawn McCarney 17310d8641SShawn McCarneyThe `phosphor-regulators` application is controlled by a configuration file 18310d8641SShawn McCarney(config file). The config file defines how to perform the following operations 19310d8641SShawn McCarneyon voltage regulators in the system: 200dbce568SPatrick Williams 210dbce568SPatrick Williams- Modify regulator configuration, such as output voltage or overcurrent settings 220dbce568SPatrick Williams- Read sensor values 230dbce568SPatrick Williams- Detect redundant phase faults (if necessary) 24310d8641SShawn McCarney 25310d8641SShawn McCarneyThe config file does not control how voltage regulators are enabled or how to 26310d8641SShawn McCarneymonitor their Power Good (pgood) status. Those operations are typically 27310d8641SShawn McCarneyperformed by power sequencer hardware and related firmware. 28310d8641SShawn McCarney 29310d8641SShawn McCarney## Data Format 30310d8641SShawn McCarney 310dbce568SPatrick WilliamsThe config file is written using the 320dbce568SPatrick Williams[JSON (JavaScript Object Notation)](https://www.json.org/) data format. 33310d8641SShawn McCarney 344afafc8aSShawn McCarneyThe config file can be created using any text editor, such as Visual Studio 354afafc8aSShawn McCarneyCode, Atom, Notepad++, Vim, or Emacs. 36310d8641SShawn McCarney 37310d8641SShawn McCarney## Example 38310d8641SShawn McCarney 39860d51afSShawn McCarneySee [config.json](../../examples/config.json). 40860d51afSShawn McCarney 41860d51afSShawn McCarney## Name 42860d51afSShawn McCarney 43860d51afSShawn McCarneyThere are two options for naming the config file: 440dbce568SPatrick Williams 450dbce568SPatrick Williams- [Default Name](#default-name) 460dbce568SPatrick Williams- [Name Based on System Type](#name-based-on-system-type) 47860d51afSShawn McCarney 48860d51afSShawn McCarney### Default Name 49860d51afSShawn McCarney 50860d51afSShawn McCarneyThe default config file name is `config.json`. The default name can be used if 510dbce568SPatrick Williamsthe BMC firmware image only supports one system type. It can also be used if the 520dbce568SPatrick Williamsfirmware image supports multiple system types that share a common config file. 53860d51afSShawn McCarney 54860d51afSShawn McCarney### Name Based on System Type 55860d51afSShawn McCarney 564afafc8aSShawn McCarneyThe config file name can be based on the system type that it supports. This is 574afafc8aSShawn McCarneyrequired if the BMC firmware image supports multiple system types, and those 584afafc8aSShawn McCarneysystem types do not share a common config file. 59860d51afSShawn McCarney 604afafc8aSShawn McCarneyA config file is normally system-specific. Each system type usually has a 614afafc8aSShawn McCarneydifferent set of voltage regulators and rails. 624afafc8aSShawn McCarney 634afafc8aSShawn McCarneyThe system type is obtained from a D-Bus Chassis object created by the 644afafc8aSShawn McCarney[Entity Manager](https://github.com/openbmc/entity-manager) application. The 654afafc8aSShawn McCarneyobject must implement the `xyz.openbmc_project.Inventory.Decorator.Compatible` 664afafc8aSShawn McCarneyinterface. 674afafc8aSShawn McCarney 684afafc8aSShawn McCarneyThe `Names` property of this interface contains a list of one or more compatible 694afafc8aSShawn McCarneysystem types. The types are ordered from most specific to least specific. 70860d51afSShawn McCarney 71860d51afSShawn McCarneyExample: 720dbce568SPatrick Williams 734afafc8aSShawn McCarney- `com.acme.Hardware.Chassis.Model.MegaServer4CPU` 744afafc8aSShawn McCarney- `com.acme.Hardware.Chassis.Model.MegaServer` 754afafc8aSShawn McCarney- `com.acme.Hardware.Chassis.Model.Server` 76860d51afSShawn McCarney 774afafc8aSShawn McCarneyThe `phosphor-regulators` application searches for a config file name that 784afafc8aSShawn McCarneymatches one of these compatible system types. It searches from most specific to 794afafc8aSShawn McCarneyleast specific. The first config file found, if any, will be used. 800dbce568SPatrick Williams 814afafc8aSShawn McCarneyFor each compatible system type, the application will look for two config file 824afafc8aSShawn McCarneynames: 834afafc8aSShawn McCarney 844afafc8aSShawn McCarney- The complete compatible system type plus a '.json' suffix 854afafc8aSShawn McCarney- The last node of the compatible system type plus a '.json' suffix 86860d51afSShawn McCarney 87860d51afSShawn McCarneyExample: 880dbce568SPatrick Williams 894afafc8aSShawn McCarney- `com.acme.Hardware.Chassis.Model.MegaServer4CPU.json` 904afafc8aSShawn McCarney- `MegaServer4CPU.json` 91860d51afSShawn McCarney 924afafc8aSShawn McCarneyIf a config file is not found based on system type, `phosphor-regulators` 934afafc8aSShawn McCarneysearches for a file with the [default name](#default-name). 94310d8641SShawn McCarney 95310d8641SShawn McCarney## Contents 96310d8641SShawn McCarney 97310d8641SShawn McCarney### Structure 98310d8641SShawn McCarney 99310d8641SShawn McCarneyThe config file typically contains the following structure: 100310d8641SShawn McCarney 1010dbce568SPatrick Williams- Array of [rules](rule.md) 1020dbce568SPatrick Williams - Rules defining how to modify configuration of regulators 1030dbce568SPatrick Williams - Rules defining how to read sensors 1040dbce568SPatrick Williams - Rules defining how to detect redundant phase faults (if necessary) 1050dbce568SPatrick Williams- Array of [chassis](chassis.md) in the system 1060dbce568SPatrick Williams - Array of regulator [devices](device.md) in the chassis 1070dbce568SPatrick Williams - Array of voltage [rails](rail.md) produced by the regulator 1080dbce568SPatrick Williams 1090dbce568SPatrick WilliamsRules provide common, reusable sequences of actions that can be shared by one or 1100dbce568SPatrick Williamsmore regulators. They are optional and can be omitted if each regulator requires 1110dbce568SPatrick Williamsa unique sequence of actions. 112310d8641SShawn McCarney 113310d8641SShawn McCarney### Syntax 114310d8641SShawn McCarney 115310d8641SShawn McCarneyThe config file contains a single JSON [config_file](config_file.md) object at 116310d8641SShawn McCarneythe root level. That object contains arrays of other JSON objects. 117310d8641SShawn McCarney 118310d8641SShawn McCarneyThe following JSON object types are supported: 1190dbce568SPatrick Williams 1200dbce568SPatrick Williams- [action](action.md) 1210dbce568SPatrick Williams- [and](and.md) 1220dbce568SPatrick Williams- [chassis](chassis.md) 1230dbce568SPatrick Williams- [compare_presence](compare_presence.md) 1240dbce568SPatrick Williams- [compare_vpd](compare_vpd.md) 1250dbce568SPatrick Williams- [config_file](config_file.md) 1260dbce568SPatrick Williams- [configuration](configuration.md) 1270dbce568SPatrick Williams- [device](device.md) 1280dbce568SPatrick Williams- [i2c_capture_bytes](i2c_capture_bytes.md) 1290dbce568SPatrick Williams- [i2c_compare_bit](i2c_compare_bit.md) 1300dbce568SPatrick Williams- [i2c_compare_byte](i2c_compare_byte.md) 1310dbce568SPatrick Williams- [i2c_compare_bytes](i2c_compare_bytes.md) 1320dbce568SPatrick Williams- [i2c_interface](i2c_interface.md) 1330dbce568SPatrick Williams- [i2c_write_bit](i2c_write_bit.md) 1340dbce568SPatrick Williams- [i2c_write_byte](i2c_write_byte.md) 1350dbce568SPatrick Williams- [i2c_write_bytes](i2c_write_bytes.md) 1360dbce568SPatrick Williams- [if](if.md) 1370dbce568SPatrick Williams- [log_phase_fault](log_phase_fault.md) 1380dbce568SPatrick Williams- [not](not.md) 1390dbce568SPatrick Williams- [or](or.md) 1400dbce568SPatrick Williams- [phase_fault_detection](phase_fault_detection.md) 1410dbce568SPatrick Williams- [pmbus_read_sensor](pmbus_read_sensor.md) 1420dbce568SPatrick Williams- [pmbus_write_vout_command](pmbus_write_vout_command.md) 1430dbce568SPatrick Williams- [presence_detection](presence_detection.md) 1440dbce568SPatrick Williams- [rail](rail.md) 1450dbce568SPatrick Williams- [rule](rule.md) 1460dbce568SPatrick Williams- [run_rule](run_rule.md) 1470dbce568SPatrick Williams- [sensor_monitoring](sensor_monitoring.md) 1480dbce568SPatrick Williams- [set_device](set_device.md) 149310d8641SShawn McCarney 150310d8641SShawn McCarney### Comments 151310d8641SShawn McCarney 152310d8641SShawn McCarneyThe JSON data format does not support comments. However, many of the JSON 1530dbce568SPatrick Williamsobjects in the config file provide an optional "comments" property. The value of 1540dbce568SPatrick Williamsthis property is an array of strings. Use this property to annotate the config 1550dbce568SPatrick Williamsfile. The "comments" properties are ignored when the config file is read by the 1560dbce568SPatrick Williams`phosphor-regulators` application. 157310d8641SShawn McCarney 158310d8641SShawn McCarneyExamples: 159310d8641SShawn McCarney 160*6151c286SGeorge Liu```json 161310d8641SShawn McCarney"comments": [ "IR35221 regulator producing the Vdd rail" ] 162*6151c286SGeorge Liu``` 163310d8641SShawn McCarney 164*6151c286SGeorge Liu```json 165310d8641SShawn McCarney"comments": [ "Check if register 0x82 contains 0x7302", 166310d8641SShawn McCarney "Device returns bytes in little-endian order", 167310d8641SShawn McCarney "Ignore most significant bit in each byte" ] 168310d8641SShawn McCarney``` 169310d8641SShawn McCarney 170310d8641SShawn McCarney### Hexadecimal Values 171310d8641SShawn McCarney 172310d8641SShawn McCarneyThe JSON number data type does not support the hexadecimal format. For this 173310d8641SShawn McCarneyreason, properties with hexadecimal values use the string data type. 174310d8641SShawn McCarney 175310d8641SShawn McCarneyExample: 1760dbce568SPatrick Williams 177*6151c286SGeorge Liu```json 178310d8641SShawn McCarney"address": "0x70" 179310d8641SShawn McCarney``` 180310d8641SShawn McCarney 181310d8641SShawn McCarney## Validation 182310d8641SShawn McCarney 183310d8641SShawn McCarneyAfter creating or modifying a config file, you need to validate it using the 184994a873cSBob Kingtool [validate-regulators-config.py](../../tools/validate-regulators-config.py). 185310d8641SShawn McCarney 186310d8641SShawn McCarneyThe validation tool checks the config file for errors, such as: 1870dbce568SPatrick Williams 1880dbce568SPatrick Williams- Invalid JSON syntax (like a missing brace) 1890dbce568SPatrick Williams- Unrecognized JSON object or property 1900dbce568SPatrick Williams- Duplicate rule or device ID 1910dbce568SPatrick Williams- Reference to a rule or device ID that does not exist 1920dbce568SPatrick Williams- Infinite loop, such as rule A runs rule B which runs rule A 193310d8641SShawn McCarney 194310d8641SShawn McCarneyThe tool requires two input files: 1950dbce568SPatrick Williams 1960dbce568SPatrick Williams- config file to validate 1970dbce568SPatrick Williams- [config_schema.json](../../schema/config_schema.json) 198310d8641SShawn McCarney 199310d8641SShawn McCarneyThe tool has the following command line syntax: 2000dbce568SPatrick Williams 201*6151c286SGeorge Liu```sh 202994a873cSBob Kingvalidate-regulators-config.py -c <config file> -s config_schema.json 203310d8641SShawn McCarney``` 204310d8641SShawn McCarney 2050dbce568SPatrick Williamswhere `<config file>` is the name of the config file to validate. 206310d8641SShawn McCarney 207310d8641SShawn McCarney## Installation 208310d8641SShawn McCarney 209310d8641SShawn McCarney### Standard Directory 210310d8641SShawn McCarney 211310d8641SShawn McCarney`/usr/share/phosphor-regulators` 212310d8641SShawn McCarney 2130dbce568SPatrick WilliamsThe standard version of the config file is installed in this read-only directory 2140dbce568SPatrick Williamsas part of the firmware image install. This is the config file that will 2150dbce568SPatrick Williamsnormally be used. 216310d8641SShawn McCarney 217310d8641SShawn McCarney### Test Directory 218310d8641SShawn McCarney 219310d8641SShawn McCarney`/etc/phosphor-regulators` 220310d8641SShawn McCarney 221310d8641SShawn McCarneyA new version of the config file can be tested by copying it into this writable 2220dbce568SPatrick Williamsdirectory. This avoids the need to build and install a new firmware image on the 2230dbce568SPatrick WilliamsBMC. 224310d8641SShawn McCarney 2250dbce568SPatrick WilliamsThe test directory might not exist on the BMC. If it is missing, create it using 2260dbce568SPatrick Williamsthe following command: 2273c68286bSShawn McCarney 2283c68286bSShawn McCarney`mkdir /etc/phosphor-regulators` 2293c68286bSShawn McCarney 230310d8641SShawn McCarney### Search Order 231310d8641SShawn McCarney 23291090e41SShawn McCarneyThe `phosphor-regulators` application will search the installation directories 23391090e41SShawn McCarneyin the following order to find a config file: 2340dbce568SPatrick Williams 23591090e41SShawn McCarney1. test directory 23691090e41SShawn McCarney2. standard directory 237310d8641SShawn McCarney 2383c68286bSShawn McCarney### Firmware Updates 2393c68286bSShawn McCarney 2403c68286bSShawn McCarneyWhen a new firmware image is installed on the BMC, it will update the config 2413c68286bSShawn McCarneyfile in the standard directory. 2423c68286bSShawn McCarney 2433c68286bSShawn McCarneyThe test directory will **not** be modified by a firmware update. If a config 2443c68286bSShawn McCarneyfile exists in the test directory, it will continue to override the config file 2453c68286bSShawn McCarneyin the standard directory. 2463c68286bSShawn McCarney 247310d8641SShawn McCarney## Loading and Reloading 248310d8641SShawn McCarney 249310d8641SShawn McCarneyThe config file is loaded when the `phosphor-regulators` application starts. 250310d8641SShawn McCarney 2510dbce568SPatrick WilliamsTo force the application to reload the config file, use the following command on 2520dbce568SPatrick Williamsthe BMC: 253310d8641SShawn McCarney 2543c68286bSShawn McCarney`systemctl kill -s HUP phosphor-regulators.service` 25591090e41SShawn McCarney 25691090e41SShawn McCarneyTo confirm which config file was loaded, use the following command on the BMC: 25791090e41SShawn McCarney 2583c68286bSShawn McCarney`journalctl -u phosphor-regulators.service | grep Loading` 259310d8641SShawn McCarney 260310d8641SShawn McCarney## Testing 261310d8641SShawn McCarney 262310d8641SShawn McCarneyAfter creating or modifying a config file, you should test it to ensure it 263310d8641SShawn McCarneyprovides the desired behavior. 264310d8641SShawn McCarney 265310d8641SShawn McCarneyPerform the following steps to test the config file: 2660dbce568SPatrick Williams 2670dbce568SPatrick Williams- Run the [validation tool](#validation) to ensure the config file contains no 268310d8641SShawn McCarney errors. 2690dbce568SPatrick Williams- Copy the config file into the [test directory](#test-directory) on the BMC. 2700dbce568SPatrick Williams- Force the `phosphor-regulators` application to 271310d8641SShawn McCarney [reload](#loading-and-reloading) its config file, causing it to find and load 272310d8641SShawn McCarney the file in the test directory. 2730dbce568SPatrick Williams- Boot the system. Regulator configuration changes (such as voltage settings) 274310d8641SShawn McCarney are only applied during the boot. 2750dbce568SPatrick Williams- View output from the `phosphor-regulators` application to make sure no errors 2763c68286bSShawn McCarney occurred. Use the command `journalctl -u phosphor-regulators.service`. 277310d8641SShawn McCarney 278310d8641SShawn McCarneyWhen finished testing, perform the following steps to revert to the standard 279310d8641SShawn McCarneyconfig file: 2800dbce568SPatrick Williams 2810dbce568SPatrick Williams- Remove the config file from the test directory. If this is not done, the test 2820dbce568SPatrick Williams config file will continue to override the standard config file even after a 2830dbce568SPatrick Williams firmware update. 2840dbce568SPatrick Williams- Force the `phosphor-regulators` application to reload its config file, causing 2850dbce568SPatrick Williams it to find and load the file in the standard directory. 2860dbce568SPatrick Williams- Boot the system, if necessary, to apply the regulator configuration changes in 2870dbce568SPatrick Williams the standard config file. 288