1# PSU firmware update
2
3Author:
4   Lei YU <mine260309@gmail.com> <LeiYU>
5
6Other contributors:
7   Su Xiao <suxiao@inspur.com>
8   Derek Howard <derekh@us.ibm.com>
9
10Created:
11   2019-06-03
12
13
14## Problem Description
15
16There is no support in OpenBMC to update the firmware for PSUs.
17
18
19## Background and References
20
21In OpenBMC, there is an existing interface for [software update][1].
22
23The update process consists of:
241. Uploading an image to the BMC;
252. Processing the image to check the version and purpose of the image;
263. Verifying and activating the image.
27
28Currently, BMC and BIOS firmware update are supported:
29* [phosphor-bmc-code-mgmt][2] implements BMC code update, and it supports all
30  the above 3 processes.
31* [openpower-pnor-code-mgmt][3] implements BIOS code update, and it only
32  implements "verifying and activating" the image. It shares the function of
33  the above 1 & 2 processes.
34* Both of the above use the same [Software DBus interface][1].
35
36For PSU firmware update, it is preferred to re-use the same function for the
37above 1 & 2.
38
39
40## Requirements
41
42The PSU firmware shall be updated in the below cases:
431. The user manually invokes the APIs to do the update;
442. After BMC code update and if there is a newer PSU image in the BMC's
45   filesystem, BMC shall update the PSU firmware;
463. When a PSU is replaced and the version is older than the one in BMC's
47   filesystem, BMC shall update the PSU firmware.
484. There are cases that a system could use different models of PSUs, and thus
49   different PSU firmware images need to be supported.
50
51For some PSUs, it is risky to do PSU code update while the host is running to
52avoid power loss. This shall be handled by PSU vendor-specific tools, but not
53in the generic framework.
54
55Note: The "vendor-specific" referred below is the PSU vendor-specific.
56
57So the below checks are optional and expected to be handled by vendor-specific
58tool:
591. If the host is powered off;
602. If the redundant PSUs are all connected;
613. If the AC input and DC standby output is OK on all the PSUs;
62
63
64## Proposed Design
65
66As described in the above requirements, there are different cases where the
67PSU firmware is updated:
68* When the APIs are invoked;
69* When a new version is updated together with BMC code update;
70* When a PSU is replaced with an old version of the firmware.
71
72### Update by API
73
74This method is usually used by users who manually update PSU firmware.
75
76It will re-use the current interfaces to upload, verify, and activate the
77image.
78
791. The "Version" interface needs to be extended:
80   * Add a new [VersionPurpose][4] for PSU;
81   * Re-use the existing `ExtendedVersion` as an additional string for
82     vendor-specific purpose, e.g. to indicate the PSU model.
832. Re-use the existing functions implemented by [phosphor-bmc-code-mgmt][2] for
84   uploading and processing the image.
85   * The PSU update image shall be a tarball that consists of a MANIFEST,
86     images, and signatures.
87   * When the PSU image is uploaded and processed, a `VersionObject` shall be
88     created to indicate the version and its purpose.
893. There will be a new service that implements the [Activation][5] interface to
90   update the PSU firmware.
91   * The service will be started by default when BMC starts;
92   * On start, the service will check the PSU's existing firmware and create
93     the `Version` and `Activation` interfaces.
94   * The service shall watch the interface added on
95     `/xyz/openbmc_project/Software`.
96   * When a new object with PSU `VersionPurpose` is added, the service will
97     verify the signature of the image;
98   * The service shall check the `ExtendedVersion` to make sure the image
99     matches the PSU model.
100   * The service will have a configuration file to describe the PSU model and
101     its related vendor-specific tools.
102   * The service will find the matched vendor-specific tool to perform the code
103     update.
104     For example, if a vendor specific tool `foo` is configured in
105     `psu-update@foo.service` which executes `foo psu.bin`, the service will
106     find the `psu-update@foo.service` and start it by systemd, which performs
107     the update.
108   * When the PSU code update is completed, an informational event log shall be
109     created.
110   * When the PSU code update is completed, the image, MANIFEST, and optionally
111     the signature will be saved to a pre-defined directory in read-write
112     filesystem for future use, in case a new PSU with old firmware is plugged.
1134. The vendor-specific tool shall run all the checks it needs to be run, before
114   and after the PSU update, and return a status to the above service to
115   indicate the result.
1165. When the vendor-specific tool returns errors, the PSU update will be aborted
117   and an error event log shall be created.
1186. During the update, the service shall set the related sensors to
119   non-functional, and when the update is done, it shall set the related
120   sensors back to functional.
121
122### Update by new BMC image
123
124When BMC is updated and a new version of PSU firmware is included, it shall be
125updated to the PSU.
126This will be done by the same service described above.
127
1281. On start, the service will check the PSU image, model and version in its
129   filesystem, compare with the ones in PSU hardware and decide if PSU firmware
130   update shall be performed.
1312. There could be two places containing the PSU images:
132   * The pre-defined directory in read-only filesystem, which is part of BMC
133     image.
134   * The other pre-defined directory in read-write filesystem, which is the
135     location for the saved PSU images by API update.
136   Both places shall be checked and a newer version will be selected to compare
137   with the PSU hardware.
1383. If PSU update is needed, the service will find the matched vendor-specific
139   tool to perform the code update.
1404. The following process will be the same as [Update by API].
141
142### Update on replaced PSU
143
144When a PSU is replaced, and the firmware version is older than the one in BMC
145filesystem, it shall be updated.
146This will be done by the same service described above.
147
1481. On start, the service will subscribe to the PropertiesChanged signal to
149   the PSU object path to monitor the PSU presence status.
150   (Or maybe subscribe the InterfacesAdded/Removed signal?)
1512. When a PSU's presence status is changed from false to true (or the
152   InterfacesAdded event occurs), the service will check the new PSU's model,
153   firmware version to decide if the firmware needs to be updated.
1543. If yes, the service will find the matched vendor-specific tool to perform
155   the code update.
1564. The following process will be the same as [Update by API].
157
158## Alternatives Considered
159
160### General implementation
161
162The PSU firmware update could be implemented by separated recipes that only
163call vendor-specific tools.
164It will be a bit simpler but loses the unified interface provided by OpenBMC's
165existing [software update interface][1], and thus it will become difficult to
166use a standard API to the PSU firmware update.
167
168### VersionPurpose
169It is possible to re-use the `VersionPurpose.Other` to represent the PSU
170image's version purpose.
171But that requires additional information about the image, otherwise, there is
172no way to tell if the image is for PSU, or CPLD, or other peripherals.
173A new `VersionPurpose.PSU` is more specific and makes it easier to implement
174and friendly for the user.
175
176### Additional string
177The design proposal uses `ExtendedVersion` as the additional string for
178vendor-specific purpose, e.g. to indicate the PSU model, so the implementation
179could check and compare if the image matches the PSU model.
180It is possible to make it optional or remove this additional string, then the
181implementation will not verify if the image matches the PSU. It could be OK if
182we trust the user who is uploading the correct image, especially the image
183shall be signed.
184But it is always risky in case the image does not match the PSU, and cause
185unintended damage if the incorrect PSU firmware is updated.
186
187
188## Impacts
189
190This design only introduces a new `VersionPurpose` enum into the dbus
191interfaces.
192The newly introduced PSU firmware update service will be a new service that
193implements existing [Activation][5] interface.
194There will be new configuration files for the service to:
195* Link the vendor specific tool with PSU models.
196* Get the sensors related to the PSU.
197* etc.
198
199So the impacts are minimal to existing systems.
200
201
202## Testing
203
204It requires the manual tests to verify the PSU code update process.
205* Verify the PSU code update is done on all PSUs successfully;
206* Verify the PSU code update will fail if the vendor-specific tool fails on
207  pre-condition check, of fails on updating PSU.
208* Verify the PSU code update is performed after a new BMC image is updated
209  containing a new version of PSU firmware.
210* Verify the PSU code update is performed after a PSU with old firmware is
211  plugged in.
212
213
214[1]: https://github.com/openbmc/phosphor-dbus-interfaces/tree/master/yaml/xyz/openbmc_project/Software
215[2]: https://github.com/openbmc/phosphor-bmc-code-mgmt/
216[3]: https://github.com/openbmc/openpower-pnor-code-mgmt/
217[4]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/57b878d048f929643276f1bf7fdf750abc4bde8b/xyz/openbmc_project/Software/Version.interface.yaml#L14
218[5]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Software/Activation.interface.yaml
219
220