xref: /openbmc/pldm/README.md (revision 27a022ca)
1# To Build
2Need `meson` and `ninja`. Alternatively, source an OpenBMC ARM/x86 SDK.
3```
4meson build && ninja -C build
5```
6## To run unit tests
7The simplest way of running the tests is as described by the meson man page:
8```
9meson builddir && meson test -C builddir
10```
11## To enable pldm verbosity
12pldm daemon accepts a command line argument `--verbose` or `--v` or `-v` to enable the
13daemon to run in verbose mode. It can be done via adding this option to the environment
14file that pldm service consumes.
15```
16echo 'PLDMD_ARGS="--verbose"' > /etc/default/pldmd
17systemctl restart pldmd
18```
19## To disable pldm verbosity
20```
21rm /etc/default/pldmd
22systemctl restart pldmd
23```
24
25Alternatively, tests can be run in the OpenBMC CI docker container, or with an
26OpenBMC x86 sdk(see below for x86 steps).
27```
28meson -Doe-sdk=enabled build
29ninja -C build test
30```
31
32# Code Organization
33At a high-level, code in this repository belongs to one of the following three
34components.
35
36## libpldm
37This is a library which deals with the encoding and decoding of PLDM messages.
38It should be possible to use this library by projects other than OpenBMC, and
39hence certain constraints apply to it:
40- keeping it light weight
41- implementation in C
42- minimal dynamic memory allocations
43- endian-safe
44- no OpenBMC specific dependencies
45
46Source files are named according to the PLDM Type, for eg base.[h/c], fru.[h/c],
47etc.
48
49Given a PLDM command "foo", the library will provide the following API:
50For the Requester function:
51```
52encode_foo_req() - encode a foo request
53decode_foo_resp() - decode a response to foo
54```
55For the Responder function:
56```
57decode_foo_req() - decode a foo request
58encode_foo_resp() - encode a response to foo
59```
60The library also provides API to pack and unpack PLDM headers.
61
62## libpldmresponder
63This library provides handlers for incoming PLDM request messages. It provides
64for a registration as well as a plug-in mechanism. The library is implemented in
65modern C++, and handles OpenBMC's platform specifics.
66
67The handlers are of the form
68```
69Response handler(Request payload, size_t payloadLen)
70```
71
72Source files are named according to the PLDM Type, for eg base.[hpp/cpp],
73fru.[hpp/cpp], etc.
74
75
76## OEM/vendor-specific functions
77This will support OEM or vendor-specific functions and semantic information.
78Following directory structure has to be used:
79```
80    pldm repo
81     |---- oem
82            |----<oem_name>
83                      |----libpldm
84                            |----<oem based encoding and decoding files>
85                      |----libpldmresponder
86                            |---<oem based handler files>
87
88```
89<oem_name> - This folder must be created with the name of the OEM/vendor
90in lower case. Folders named libpldm and libpldmresponder must be created under
91the folder <oem_name>
92
93Files having the oem functionality for the libpldm library should be placed
94under the folder oem/<oem_name>/libpldm. They must be adhering to the rules
95mentioned under the libpldm section above.
96
97Files having the oem functionality for the libpldmresponder library should be
98placed under the folder oem/<oem_name>/libpldmresponder. They must be adhering
99to the rules mentioned under the libpldmresponder section above.
100
101Once the above is done a meson option has to be created in
102`pldm/meson_options.txt` with its mapped compiler flag to enable conditional
103compilation.
104
105For consistency would recommend using "oem-<oem_name>".
106
107The `pldm/meson.build` and the corresponding source file(s) will need to
108incorporate the logic of adding its mapped compiler flag to allow conditional
109compilation of the code.
110
111## pldmtool
112For more information on pldmtool please refer to plmdtool/README.md.
113
114## TODO
115Consider hosting libpldm above in a repo of its own, probably even outside the
116OpenBMC project? A separate repo would enable something like git submodule.
117
118# Flows
119This section documents important code flow paths.
120
121## BMC as PLDM responder
122a) PLDM daemon receives PLDM request message from underlying transport (MCTP).
123
124b) PLDM daemon routes message to message handler, based on the PLDM command.
125
126c) Message handler decodes request payload into various field(s) of the request
127   message. It can make use of a decode_foo_req() API, and doesn't have to
128   perform deserialization of the request payload by itself.
129
130d) Message handler works with the request field(s) and generates response
131   field(s).
132
133e) Message handler prepares a response message. It can make use of an
134   encode_foo_resp() API, and doesn't have to perform the serialization of the
135   response field(s) by itself.
136
137f) The PLDM daemon sends the response message prepared at step e) to the remote
138   PLDM device.
139
140## BMC as PLDM requester
141a) A BMC PLDM requester app prepares a PLDM request message. There would be
142   several requester apps (based on functionality/PLDM remote device). Each of
143   them needn't bother with the serialization of request field(s), and can
144   instead make use of an encode_foo_req() API.
145
146b) BMC requester app requests PLDM daemon to send the request message to remote
147   PLDM device.
148
149c) Once the PLDM daemon receives a corresponding response message, it notifies
150   the requester app.
151
152d) The requester app has to work with the response field(s). It can make use of
153   a decode_foo_resp() API to deserialize the response message.
154
155# PDR Implementation
156While PLDM Platform Descriptor Records (PDRs) are mostly static information,
157they can vary across platforms and systems. For this reason, platform specific
158PDR information is encoded in platform specific JSON files. JSON files must be
159named based on the PDR type number. For example a state effecter PDR JSON file
160will be named 11.json. The JSON files may also include information to enable
161additional processing (apart from PDR creation) for specific PDR types, for eg
162mapping an effecter id to a D-Bus object.
163
164The PLDM responder implementation finds and parses PDR JSON files to create the
165PDR repository. Platform specific PDR modifications would likely just result in
166JSON updates. New PDR type support would require JSON updates as well as PDR
167generation code. The PDR generator is a map of PDR Type -> C++ lambda to create
168PDR entries for that type based on the JSON, and to update the central PDR repo.
169