xref: /openbmc/entity-manager/CONFIG_FORMAT.md (revision edc4634763d9898b82150188e076ea45da5f780e)
121608383SEd Tanous# Config Files
2dfa14b5fSEd Tanous
321608383SEd Tanous## Intent
421608383SEd Tanous
521608383SEd TanousConfiguration files are intended to represent the minimum amount of
621608383SEd Tanousconfiguration required to describe a given piece of hardware. As such, they are
721608383SEd Tanousintended to be simple, and are guided by the following principles.
821608383SEd Tanous
921608383SEd Tanous1. Configuration files should be easy to write. If a tradeoff is to be made
1021608383SEd Tanous   between a config file being complex to write, and a reactor being complex to
1121608383SEd Tanous   write, the reactor will be the one to hold the complexity. Why?
12fa8ee87eSPatrick Williams
1321608383SEd Tanous   - Configuration files will get replicated and built to support hundreds of
1421608383SEd Tanous     systems over time, and scale linearly with the number of systems. In
1521608383SEd Tanous     contrast, reactors tend to scale as a logarithm of system count, with each
16fa8ee87eSPatrick Williams     new system supported adding fewer and fewer reactors. As such, pushing the
17fa8ee87eSPatrick Williams     complexity to the reactors leads to fewer lines of code overall, even if
18fa8ee87eSPatrick Williams     the reactor itself contains more complex actions.
1921608383SEd Tanous   - Reactor writers tend to be domain experts on their subsystem, and
2021608383SEd Tanous     intimately understand the constraints that are emplaced on that subsystem.
2121608383SEd Tanous     Config file writers are generally building support for a wide range of
2221608383SEd Tanous     reactors on a single piece of hardware, and will generally have less
2321608383SEd Tanous     knowledge of each individual reactors constraints.
2421608383SEd Tanous
25fa8ee87eSPatrick Williams2. Configuration files should trend toward one config file per physical piece of
26fa8ee87eSPatrick Williams   hardware, and should avoid attempting to support multiple variations of a
2721608383SEd Tanous   given piece of hardware in a single file, even at the risk of duplicating
2821608383SEd Tanous   information. Why?
29fa8ee87eSPatrick Williams
30fa8ee87eSPatrick Williams   - Hardware constraints, bugs, and oddities are generally found over time. The
31fa8ee87eSPatrick Williams     initial commit of a configuration file is far from the final time that
32fa8ee87eSPatrick Williams     changes will be submitted. Having each individual piece of hardware in its
33fa8ee87eSPatrick Williams     own file minimizes the change needed between different components when bugs
34fa8ee87eSPatrick Williams     are found, or features are added.
3521608383SEd Tanous   - Having separate config files reduces the number of platforms that need to
3621608383SEd Tanous     be tested for any given config file change, thus limiting the "blast
3721608383SEd Tanous     radius" of particular kinds of changes, as well as making an explicit log
3821608383SEd Tanous     of what changed for a specific platform.
39fa8ee87eSPatrick Williams   - Having one config file per piece of hardware makes it much easier and clear
40fa8ee87eSPatrick Williams     for a user to determine if a piece of hardware is supported.
41fa8ee87eSPatrick Williams   - Note: This is a "guideline" not a "rule". There are many cases of hardware
42fa8ee87eSPatrick Williams     that despite having different part numbers, are actually physically
43fa8ee87eSPatrick Williams     identical, and as such, the config files will never differ.
4421608383SEd Tanous     - Example: SAS modules and cards made by the same company, on the same
4521608383SEd Tanous       process, and branded with different manufacturers and part numbers.
4621608383SEd Tanous     - Non-Example: Power supplies. While all pmbus power supplies appear
47fa8ee87eSPatrick Williams       similar, there tend to be significant differences in featuresets, bugs,
48fa8ee87eSPatrick Williams       and OEM supported firmware features. As such, they require separate
49fa8ee87eSPatrick Williams       config files.
5021608383SEd Tanous
5121608383SEd Tanous3. Configuration files are not a long-term stable ABI. Why?
52fa8ee87eSPatrick Williams
5321608383SEd Tanous   - Configuration files occasionally need to modify their schema in pursuit of
5421608383SEd Tanous     simplicity, or based on a greater understanding of the system level
5521608383SEd Tanous     constraints.
5621608383SEd Tanous   - The repo will ensure that all schema changes are enacted such that the
5721608383SEd Tanous     files in the repo will not be broken as a result of the schema change, and
58fa8ee87eSPatrick Williams     will be carried forward. The recommended way to avoid merge problems is to
59fa8ee87eSPatrick Williams     upstream your configurations.
6021608383SEd Tanous   - Note: This drives the requirement that config files shall not be checked
6121608383SEd Tanous     into OpenBMC meta layers.
6221608383SEd Tanous
6321608383SEd Tanous4. Configurations should represent only the things that are _different_ and
6421608383SEd Tanous   undetectable between platforms. Why?
65fa8ee87eSPatrick Williams   - There are many behaviors that the BMC has that are very easily detected at
66fa8ee87eSPatrick Williams     runtime, or where the behavior can be identical between different
6721608383SEd Tanous     platforms. Things like timeouts, protocol versions, and communcation
6821608383SEd Tanous     channels can generally be represented with a default that works for all
6921608383SEd Tanous     platforms, and doesn't need to be an entity-configurable parameter. In
7021608383SEd Tanous     general, reducing the config files to _only_ the differences reduces
7121608383SEd Tanous     complexity, and explicitly bounds where dicsussion is needed for platform
7221608383SEd Tanous     differences, and where a difference is "supported" and "reasonable" to
7321608383SEd Tanous     maintain in the long run.
74dfa14b5fSEd Tanous
75dfa14b5fSEd Tanous## Configuration Syntax
76dfa14b5fSEd Tanous
77dfa14b5fSEd TanousIn most cases a server system is built with multiple hardware modules (circuit
78dfa14b5fSEd Tanousboards) such as baseboard, risers, and hot-swap backplanes. While it is
79dfa14b5fSEd Tanousperfectly legal to combine the JSON configuration information for all the
8021608383SEd Tanoushardware modules into a single file if desired, it is recommended to divide them
8121608383SEd Tanousinto multiple configuration files. For example, there may be a baseboard JSON
8221608383SEd Tanousfile (describes all devices on the baseboard) and a chassis JSON file (describes
83fa8ee87eSPatrick Williamsdevices attached to the chassis). Other examples of entities might be removable
84fa8ee87eSPatrick Williamspower supplies, fans, and PCIe add in cards.
85dfa14b5fSEd Tanous
86dfa14b5fSEd TanousWithin a configuration file, there is a JSON object which consists of multiple
87dfa14b5fSEd Tanous"string : value" pairs. This Entity Manager defines the following strings.
88dfa14b5fSEd Tanous
89dfa14b5fSEd Tanous| String        | Example Value                                                       | Description                                                                                                                                                                                                                                                                                                   |
90ec1137d5SPatrick Williams| :------------ | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
91ec1137d5SPatrick Williams| "Name"        | `"X1000 1U Chassis"`                                                | Human readable name used for identification and sorting.                                                                                                                                                                                                                                                      |
92ec1137d5SPatrick Williams| "Probe"       | `"xyz.openbmc_project.FruDevice({'BOARD_PRODUCT_NAME':'FFPANEL'})"` | Statement which attempts to read from d-bus. The result determines if a configuration record should be applied. The value for probe can be set to “TRUE” in the case the record should always be applied, or set to more complex lookups, for instance a field in a FRU file that is exposed by the frudevice |
93ec1137d5SPatrick Williams| "Exposes"     | `[{"Name" : "CPU fan"}, ...]`                                       | An array of JSON objects which are valid if the probe result is successful. These objects describe the devices BMC can interact.                                                                                                                                                                              |
94ec1137d5SPatrick Williams| "Status"      | `"disabled"`                                                        | An indicator that allows for some records to be disabled by default.                                                                                                                                                                                                                                          |
95ec1137d5SPatrick Williams| "Bind\*"      | `"2U System Fan connector 1"`                                       | The record isn't complete and needs to be combined with another to be functional. The value is a unique reference to a record elsewhere.                                                                                                                                                                      |
96ec1137d5SPatrick Williams| "DisableNode" | `"Fan 1"`                                                           | Sets the status of another Entity to disabled.                                                                                                                                                                                                                                                                |
97dfa14b5fSEd Tanous
98dfa14b5fSEd TanousTemplate strings in the form of "$identifier" may be used in configuration
99dfa14b5fSEd Tanousfiles. The following table describes the template strings currently defined.
100dfa14b5fSEd Tanous
101dfa14b5fSEd Tanous| Template String | Description                                                                                                                                                                                                                         |
102fa8ee87eSPatrick Williams| :-------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
103dfa14b5fSEd Tanous| "$bus"          | During a I2C bus scan and when the "probe" command is successful, this template string is substituted with the bus number to which the device is connected.                                                                         |
104dfa14b5fSEd Tanous| "$address"      | When the "probe" is successful, this template string is substituted with the (7-bit) I2C address of the FRU device.                                                                                                                 |
105dfa14b5fSEd Tanous| "$index"        | A run-tim enumeration. This template string is substituted with a unique index value when the "probe" command is successful. This allows multiple identical devices (e.g., HSBPs) to exist in a system but each with a unique name. |
106dfa14b5fSEd Tanous
107dfa14b5fSEd Tanous## Configuration HowTos
108dfa14b5fSEd Tanous
109dfa14b5fSEd TanousIf you're just getting started and your goal is to add sensors dynamically,
110dfa14b5fSEd Tanouscheck out [My First Sensors](docs/my_first_sensors.md)
111dfa14b5fSEd Tanous
112*edc46347SAlexander Hansen## When adding/moving/removing a configuration file
113*edc46347SAlexander Hansen
114*edc46347SAlexander HansenPlease run `scripts/generate_config_list.sh` from the root of the repository so
115*edc46347SAlexander Hansenthat configuration files are correctly referenced by meson.
116*edc46347SAlexander Hansen
11721608383SEd Tanous## Configuration schema
11821608383SEd Tanous
119c76e53a3SChris CainThe config schema is documented in [README.md](schemas/README.md)
120dfa14b5fSEd Tanous
121dfa14b5fSEd Tanous## Configuration Records - Baseboard Example
122dfa14b5fSEd Tanous
12321608383SEd TanousThe configuration JSON files attempt to model the actual hardware modules which
12421608383SEd Tanousmake up a complete system. An example baseboard JSON file shown below defines
12521608383SEd Tanoustwo fan connectors and two temperature sensors of TMP75 type. These objects are
12621608383SEd Tanousconsidered valid by BMC when the probe command (reads and compares the product
12721608383SEd Tanousname in FRU) is successful and this baseboard is named as "WFP baseboard".
128dfa14b5fSEd Tanous
129ec1137d5SPatrick Williams```json
130dfa14b5fSEd Tanous{
131dfa14b5fSEd Tanous  "Exposes": [
132dfa14b5fSEd Tanous    {
133dfa14b5fSEd Tanous      "Name": "1U System Fan connector 1",
134dfa14b5fSEd Tanous      "Pwm": 1,
135dfa14b5fSEd Tanous      "Status": "disabled",
136ec1137d5SPatrick Williams      "Tachs": [1, 2],
137dfa14b5fSEd Tanous      "Type": "IntelFanConnector"
138dfa14b5fSEd Tanous    },
139dfa14b5fSEd Tanous    {
140dfa14b5fSEd Tanous      "Name": "2U System Fan connector 1",
141dfa14b5fSEd Tanous      "Pwm": 1,
142dfa14b5fSEd Tanous      "Status": "disabled",
143ec1137d5SPatrick Williams      "Tachs": [1],
144dfa14b5fSEd Tanous      "Type": "IntelFanConnector"
145dfa14b5fSEd Tanous    },
146dfa14b5fSEd Tanous    {
147dfa14b5fSEd Tanous      "Address": "0x49",
148dfa14b5fSEd Tanous      "Bus": 6,
149dfa14b5fSEd Tanous      "Name": "Left Rear Temp",
150dfa14b5fSEd Tanous      "Thresholds": [
151dfa14b5fSEd Tanous        {
152dfa14b5fSEd Tanous          "Direction": "greater than",
153dfa14b5fSEd Tanous          "Name": "upper critical",
154dfa14b5fSEd Tanous          "Severity": 1,
155dfa14b5fSEd Tanous          "Value": 115
156dfa14b5fSEd Tanous        },
157dfa14b5fSEd Tanous        {
158dfa14b5fSEd Tanous          "Direction": "greater than",
159dfa14b5fSEd Tanous          "Name": "upper non critical",
160dfa14b5fSEd Tanous          "Severity": 0,
161dfa14b5fSEd Tanous          "Value": 110
162dfa14b5fSEd Tanous        },
163dfa14b5fSEd Tanous        {
164dfa14b5fSEd Tanous          "Direction": "less than",
165dfa14b5fSEd Tanous          "Name": "lower non critical",
166dfa14b5fSEd Tanous          "Severity": 0,
167dfa14b5fSEd Tanous          "Value": 5
168dfa14b5fSEd Tanous        },
169dfa14b5fSEd Tanous        {
170dfa14b5fSEd Tanous          "Direction": "less than",
171dfa14b5fSEd Tanous          "Name": "lower critical",
172dfa14b5fSEd Tanous          "Severity": 1,
173dfa14b5fSEd Tanous          "Value": 0
174dfa14b5fSEd Tanous        }
175dfa14b5fSEd Tanous      ],
176dfa14b5fSEd Tanous      "Type": "TMP75"
177dfa14b5fSEd Tanous    },
178dfa14b5fSEd Tanous    {
179dfa14b5fSEd Tanous      "Address": "0x48",
180dfa14b5fSEd Tanous      "Bus": 6,
181dfa14b5fSEd Tanous      "Name": "Voltage Regulator 1 Temp",
182dfa14b5fSEd Tanous      "Thresholds": [
183dfa14b5fSEd Tanous        {
184dfa14b5fSEd Tanous          "Direction": "greater than",
185dfa14b5fSEd Tanous          "Name": "upper critical",
186dfa14b5fSEd Tanous          "Severity": 1,
187dfa14b5fSEd Tanous          "Value": 115
188dfa14b5fSEd Tanous        },
189dfa14b5fSEd Tanous        {
190dfa14b5fSEd Tanous          "Direction": "greater than",
191dfa14b5fSEd Tanous          "Name": "upper non critical",
192dfa14b5fSEd Tanous          "Severity": 0,
193dfa14b5fSEd Tanous          "Value": 110
194dfa14b5fSEd Tanous        },
195dfa14b5fSEd Tanous        {
196dfa14b5fSEd Tanous          "Direction": "less than",
197dfa14b5fSEd Tanous          "Name": "lower non critical",
198dfa14b5fSEd Tanous          "Severity": 0,
199dfa14b5fSEd Tanous          "Value": 5
200dfa14b5fSEd Tanous        },
201dfa14b5fSEd Tanous        {
202dfa14b5fSEd Tanous          "Direction": "less than",
203dfa14b5fSEd Tanous          "Name": "lower critical",
204dfa14b5fSEd Tanous          "Severity": 1,
205dfa14b5fSEd Tanous          "Value": 0
206dfa14b5fSEd Tanous        }
207dfa14b5fSEd Tanous      ],
208dfa14b5fSEd Tanous      "Type": "TMP75"
209dfa14b5fSEd Tanous    }
210dfa14b5fSEd Tanous  ],
211dfa14b5fSEd Tanous  "Name": "WFP Baseboard",
212dfa14b5fSEd Tanous  "Probe": "xyz.openbmc_project.FruDevice({'BOARD_PRODUCT_NAME' : '.*WFT'})"
213dfa14b5fSEd Tanous}
214dfa14b5fSEd Tanous```
215dfa14b5fSEd Tanous
216394ea2b4SZev Weiss[Full Configuration](https://github.com/openbmc/entity-manager/blob/master/configurations/WFT_Baseboard.json)
217dfa14b5fSEd Tanous
218ec1137d5SPatrick Williams## Configuration Records - Chassis Example
219dfa14b5fSEd Tanous
220dfa14b5fSEd TanousAlthough fan connectors are considered a part of a baseboard, the physical fans
221dfa14b5fSEd Tanousthemselves are considered as a part of a chassis. In order for a fan to be
222dfa14b5fSEd Tanousmatched with a fan connector, the keyword "Bind" is used. The example below
223dfa14b5fSEd Tanousshows how a chassis fan named "Fan 1" is connected to the connector named "1U
224dfa14b5fSEd TanousSystem Fan connector 1". When the probe command finds the correct product name
225dfa14b5fSEd Tanousin baseboard FRU, the fan and the connector are considered as being joined
226dfa14b5fSEd Tanoustogether.
227dfa14b5fSEd Tanous
228ec1137d5SPatrick Williams```json
229dfa14b5fSEd Tanous{
230dfa14b5fSEd Tanous  "Exposes": [
231dfa14b5fSEd Tanous    {
232dfa14b5fSEd Tanous      "BindConnector": "1U System Fan connector 1",
233dfa14b5fSEd Tanous      "Name": "Fan 1",
234dfa14b5fSEd Tanous      "Thresholds": [
235dfa14b5fSEd Tanous        {
236dfa14b5fSEd Tanous          "Direction": "less than",
237dfa14b5fSEd Tanous          "Name": "lower critical",
238dfa14b5fSEd Tanous          "Severity": 1,
239dfa14b5fSEd Tanous          "Value": 1750
240dfa14b5fSEd Tanous        },
241dfa14b5fSEd Tanous        {
242dfa14b5fSEd Tanous          "Direction": "less than",
243dfa14b5fSEd Tanous          "Name": "lower non critical",
244dfa14b5fSEd Tanous          "Severity": 0,
245dfa14b5fSEd Tanous          "Value": 2000
246dfa14b5fSEd Tanous        }
247dfa14b5fSEd Tanous      ],
248dfa14b5fSEd Tanous      "Type": "AspeedFan"
249dfa14b5fSEd Tanous    }
250dfa14b5fSEd Tanous  ]
251dfa14b5fSEd Tanous}
252dfa14b5fSEd Tanous```
253dfa14b5fSEd Tanous
254dfa14b5fSEd Tanous## Enabling Sensors
255dfa14b5fSEd Tanous
256dfa14b5fSEd TanousAs daemons can trigger off of shared types, sometimes some handshaking will be
257dfa14b5fSEd Tanousneeded to enable sensors. Using the TMP75 sensor as an example, when the sensor
258dfa14b5fSEd Tanousobject is enabled, the device tree must be updated before scanning may begin.
259dfa14b5fSEd TanousThe entity-manager can key off of different types and export devices for
260dfa14b5fSEd Tanousspecific configurations. Once this is done, the baseboard temperature sensor
261dfa14b5fSEd Tanousdaemon can scan the sensors.
2620f3a4d99SPotin Lai
2630f3a4d99SPotin Lai## C-Style Comments Support
2640f3a4d99SPotin Lai
2650f3a4d99SPotin LaiThe configuration JSON file supports c-style comments base on the rules as
2660f3a4d99SPotin Laibelow:
2670f3a4d99SPotin Lai
2680f3a4d99SPotin Lai- Single-line style comments (//) can be on a new line or at the end of a line
2690f3a4d99SPotin Lai  with contents.
2700f3a4d99SPotin Lai
2710f3a4d99SPotin Lai```json5
2720f3a4d99SPotin Lai{
2730f3a4d99SPotin Lai  // Single-line style comment (new line)
2740f3a4d99SPotin Lai  Key: "Value", // Single-line comment (end of content)
2750f3a4d99SPotin Lai}
2760f3a4d99SPotin Lai```
2770f3a4d99SPotin Lai
2780f3a4d99SPotin Lai- Multi-line style comments (/\* \*/) use the must be free-standing.
2790f3a4d99SPotin Lai
2800f3a4d99SPotin Lai```json5
2810f3a4d99SPotin Lai{
2820f3a4d99SPotin Lai  /* Multi-line style comment */
2830f3a4d99SPotin Lai  /*
2840f3a4d99SPotin Lai   * Multi-line style comments
2850f3a4d99SPotin Lai   */
2860f3a4d99SPotin Lai}
2870f3a4d99SPotin Lai```
2880f3a4d99SPotin Lai
2890f3a4d99SPotin Lai- When running autojson.py on a configuration JSON file, the comments will be
2900f3a4d99SPotin Lai  removed first and then get inserted back into the file in the line they came
2910f3a4d99SPotin Lai  from. If keys are resorted or the number of lines change, all bets for
2920f3a4d99SPotin Lai  correctness are off.
2930f3a4d99SPotin Lai
2940f3a4d99SPotin Lai- No attempts to re-indent multi-line comments will be made.
2950f3a4d99SPotin Lai
2960f3a4d99SPotin LaiIn light of this, it is highly recommended to use a JSON formatter such as
2970f3a4d99SPotin Laiprettier before using this script and planning to move multi-line comments
2980f3a4d99SPotin Laiaround after key resorting.
299