1# Firmware update over Redfish
2
3Author: Andrew Geissler (geissonator)
4
5Created: 2019-02-11
6
7## Problem Description
8OpenBMC is moving to [Redfish][1] as its standard for out of band management.
9Redfish has its own API's and methods for updating firmware on a system and
10implementing those is going to require some changes (and potential upstream work
11with the DMTF).
12
13The goal of this design document is to lay out the required changes of moving
14OpenBMC's existing firmware update implementation over to Redfish.
15
16## Background and References
17The existing firmware update details for OpenBMC can be found [here][2].
18It uses a custom REST api for uploading and then activating the input image.
19
20The Redfish schema for firmware update can be found [here][3]. Note the
21referenced doc points to the most recent version of the schema and that is
22what you'll want to load into your browser (at the time of this writing it is
23[v1_4_0][4]).
24
25Some differences between the Redfish API and OpenBMC's existing API:
26- Redfish has a single upload and update API. OpenBMC has a concept of uploading
27  an image with one API and then activating with another.
28- Redfish does not support multiple firmware images being associated with the
29  same target. OpenBMC does have support for this concept (for example when a
30  target like the BMC has multiple flash chips associated with it). A discussion
31  has been started with the DMTF on this within [Issue 3357][10]
32  - OpenBMC has the concept of a priority that allows a user to chose an
33    image associated with a target for activation. This allows a user to easily
34    switch back and forth between multiple images for a single target without
35    uploading each image every time.
36- Redfish does not support deleting a firmware image (this happens by default
37  when a new image is uploaded)
38- Redfish does support the ability to update multiple targets with the same
39  image with the same command. OpenBMC does not support this currently.
40- Redfish has support via a SimpleUpdate action which allows the user to
41  pass in a variety of remote locations to retrieve a file from
42  (FTP, HTTP, SCP, ...). Existing OpenBMC only has support for TFTP.
43- Redfish has the ability to schedule when a firmware update is applied
44  (Immediate, OnReset, AtMaintenanceWindowStart...). Existing OpenBMC firmware
45  has no concept of this.
46
47A lot of companies that are implementing Redfish have chosen to create OEM
48commands for their firmware update implementations ([ref a][5], [ref b][6]).
49
50Redfish firmware update within OpenBMC has already started within [bmcweb][7]
51and this design will be proposing enhancements to that as a base.
52
53## Requirements
54
55Breaking this into two sections. The first is what should be done for the next
56OpenBMC 2.7 release. The other section is future items that will get done, but
57not guaranteed for the 2.7 release. The goal with 2.7 is to have feature parity
58with what the existing OpenBMC REST api's provide.
59
60### 2.7 Requirements
61- Support FirmwareInventory definition for BMC and BIOS under UpdateService
62  - Support FirmwareVersion under Managers/BMC
63  - Support BiosVersion under Systems/system
64- Support firmware update for all supported targets (BMC, BIOS) using existing
65  Redfish API's (/redfish/v1/UpdateService)
66  - Note that after further discussion with the DMTF, the existing UpdateService
67    is considered to be OEM. [Issue 3296][11] addresses this and will be
68    implemented by OpenBMC once approved. The existing API will continue to be
69    supported within the Redfish specification so the OpenBMC 2.7 release will
70    support this.
71  - Must provide status to user on their image during an update
72- Support a subset of ApplyTime (Immediate, OnReset)
73- Support a TFTP based SimpleUpdate
74  - This must be configurable (enable/disable) via compile option within bmcweb
75
76### Future Requirements
77
78**Note:** TODO: The goal of this section is to document at a high
79level what will be required post 2.7 release. An update to this design document
80will be required before these requirements are implemented. They are here to
81ensure nothing in the base design would inhibit the ability to implement these
82later.
83
84- Support new concept defined in [PR 3420][12] to be able to support multiple
85  firmware images for a single target.
86- Support new UpdateService firmware update implementation defined in
87  [Issue 3296][11]
88- Support firmware update for other targets (power supplies, voltage regulators,
89  ...)
90- Support to update multiple targets with the same firmware image at once
91- Support scheduling of when update occurs (Maintenance windows)
92- Support remaining TransferProtocolTypes in UpdateService (CIFS, FTP, SFTP,
93  HTTP, HTTPS, NSF, SCP, NFS)
94  - TODO: Any update mechanism that doesn't have transport security on its own,
95    like FTP, needs a secondary verification mechanism. Update mechanisms that
96    have transport security need a way to adjust the trusted root certificates.
97- Support the Task schema to provide progress to user during upload and
98  activation phases
99
100## Proposed Design
101
102### Update An Image
103
104The pseudo flow for an update is:
105```
106Discover UpdateService location
107HttpPushUri = GET https://${bmc}/redfish/v1/UpdateService
108POST ApplyTime property in
109  UpdateService/HttpPushUriOptions->HttpPushUriApplyTime object
110  (Immediate or OnReset)
111POST <image> https://${bmc}/${HttpPushUri}
112```
113This will cause the following on the back-end:
114- Receive the image
115- Copy it internally to the required location in the filesystem (/tmp/images)
116- Wait for the InterfacesAdded signal from /xyz/openbmc_project/software
117- Activate the new image
118- If ApplyTime is Immediate, reboot the BMC or Host
119- If ApplyTime is OnReset, do nothing (user will need to initiate host or bmc
120    reboot to apply image)
121
122Note that the ApplyTime property will be processed by the software management
123stack at the end of the activation.
124Note that the ApplyTime property is global to all firmware update packages and
125will be used for all subsequent firmware update packages.
126
127### Status of an Image
128
129The user needs to know the status of their firmware images, especially during
130an update. The Task concept is still being defined within the DMTF and will
131provide the full status of an image during upload and activate.
132Using the Status object associated with the software inventory items will be
133used as a mechanism to provide status of inventory items back to the user.
134Here is the mapping of [phosphor activation states][13] to
135[Redfish Status States][14].
136```
137NotReady   -> Disabled
138Invalid    -> Disabled
139Ready      -> Disabled
140Activating -> Updating
141Active     -> Enabled
142Failed     -> Disabled
143```
144
145### Change the Priority of an Image
146
147On OpenBMC systems that support multiple flash images for one target, there will
148still be pseudo support for this using Redfish. The first image will be uploaded
149to a system, written to flash chip 0, and activated. If another image is
150uploaded, it will be written to flash chip 1 and activated. The first image
151still exists in flash chip 0 and could be re-activated by the user.
152
153As defined in DMTF issue [3357][10], use the ActiveSoftwareImage concept within
154the Redfish Settings object to allow the user to select the image to activate
155during the next activation window. Internally OpenBMC has the concept of a
156priority being assigned to each image associated with a target. OpenBMC firmware
157will continue to do this, but will simply set the "ActiveSoftwareImage" image to
158priority 0 (highest) to ensure it is activated during the next activation
159window. After setting the priority to 0, the software manager automatically
160updates the priority of the other images as needed.
161
162### Remote Image Download Based Update ###
163
164As noted above, Redfish supports a SimpleUpdate object under the UpdateService.
165The SimpleUpdate schema supports a variety of transfer protocols (CIFS, FTP,
166TFTP, ...). The existing back end of OpenBMC only supports TFTP so initially
167that is all that will be supported via Redfish on OpenBMC.
168
169The Redfish API takes a parameter, ImageURI, which contains both the server
170address information and the name of the file. The back end software manager
171interface on OpenBMC requires two parameters, the TFTP server address and the
172file name so there will be some parsing required.
173
174The pseudo flow for an update is:
175```
176# Discover SimpleUpdate URI Action location
177GET https://${bmc}/redfish/v1/UpdateService
178
179# Configure when the new image should be applied
180POST ApplyTime property in
181  UpdateService/HttpPushUriOptions->HttpPushUriApplyTime object
182  (Immediate or OnReset)
183
184# Request OpenBMC to download from TFTP server and activate the image
185POST https://${bmc}/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate
186    [ImageURI=<tftp server ip>/<file name>, TransferProtocol=TFTP]
187```
188
189TFTP is an insecure protocol. There is no username or password associated with
190it and no validation of the input URL. OpenBMC does have signed image support
191which is, by default, part of the update process. The user must have
192administration authority to request this update so it is assumed they know what
193they are doing and the level of security available with TFTP.
194
195Due to the security concerns with TFTP, this feature will be disabled by default
196within bmcweb but can be enabled via a compile flag (see CMakeLists.txt within
197bmcweb repository for details).
198
199### Delete an Image
200No support for deleting an image will be provided (until the DMTF provides it).
201When new images are uploaded, they by default have no priority. When they are
202activated, they are given the highest priority and all other images have their
203priority updated as needed. When no more space is available in flash filesystem,
204the lowest priority image will be deleted when a new one is uploaded and
205activated.
206
207## Alternatives Considered
208Could simply create Redfish OEM api's that look like OpenBMC's current custom
209REST api's. The porting would be minimal but then OpenBMC would not conform
210to any standard Redfish API's. Other vendors have done this but the Redfish
211DMTF is making strides towards enhancing the UpdateService to contain the
212features required to make an enterprise based firmware update API. OpenBMC
213should just stay at the forefront of these DMTF changes and ensure they are
214implemented as they are released.
215
216## Impacts
217This will be using the existing D-Bus API's for firmware update internally so
218there should be minimal impact between the previous REST implementation.
219
220OpenBMC has two implementations of firmware update. Different systems have
221implemented different implementations. To be clear, this design will be using
222the D-Bus API's behind the [Software Version Management][8] implementation.
223
224## Testing
225End to end [tests][9] are being written for the firmware update of BMC and BIOS
226firmware, these must pass. Also unit tests must be written with the required
227D-Bus API's mocked to ensure proper code coverage.
228
229[1]: https://redfish.dmtf.org/
230[2]: https://github.com/openbmc/docs/blob/master/architecture/code-update/code-update.md#steps-to-update
231[3]: http://redfish.dmtf.org/schemas/v1/UpdateService.json
232[4]: http://redfish.dmtf.org/schemas/v1/UpdateService.v1_4_0.json#/definitions/UpdateService
233[5]: https://www.supermicro.com/manuals/other/RedfishRefGuide.pdf
234[6]: https://github.com/dell/iDRAC-Redfish-Scripting/blob/master/Redfish%20Python/DeviceFirmwareDellUpdateServiceREDFISH.py
235[7]: https://github.com/openbmc/bmcweb/blob/master/redfish-core/lib/update_service.hpp
236[8]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Software/README.md
237[9]: https://github.com/openbmc/openbmc-test-automation
238[10]: https://github.com/DMTF/Redfish/issues/3357
239[11]: https://github.com/DMTF/Redfish/pull/3296
240[12]: https://github.com/DMTF/Redfish/pull/3420
241[13]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Software/Activation.interface.yaml
242[14]: http://redfish.dmtf.org/schemas/v1/Resource.json#/definitions/Status
243