1# OpenBMC Code Update 2 3Two BMC Code layouts are available: 4 5- Static, non-UBI layout 6- UBI layout - enabled via `obmc-ubi-fs` distro feature 7 8This document describes the code update that supports both layouts. 9 10### Steps to Update 11 12The following are the steps to update the BMC. 13 141. Get a BMC image tar: After building OpenBMC, you will end up with a set of 15 image files in `tmp/deploy/images/<platform>/`. 16 17- The UBI layout image is 18 `obmc-phosphor-image-<platform>-<timestamp>.ubi.mtd.tar` 19- The static layout image is 20 `obmc-phosphor-image-<platform>-<timestamp>.static.mtd.tar` 21 22The BMC tar image contains 5 files: u-boot, kernel, ro, and rw partitions and 23the MANIFEST file, which contains information about the image such as the image 24purpose, version, KeyType (Key type used for signature), HashType (SHA type used 25for key generation) and MachineName (name of machine used while building image, 26and this will be used for validation of image build). A MANIFEST file might look 27like 28 29``` 30purpose=xyz.openbmc_project.Software.Version.VersionPurpose.BMC 31version=2.7.0-dev 32KeyType=OpenBMC 33HashType=RSA-SHA256 34MachineName=tiogapass 35``` 36 372. Transfer the generated BMC image to the BMC via one of the following methods: 38 39- Method 1: Via Redfish Upload: 40 https://github.com/openbmc/docs/blob/master/REDFISH-cheatsheet.md#firmware-update. 41 If using this method skip ahead to step 5! 42- Method 2: Via scp: Copy the generated BMC image to the `/tmp/images/` 43 directory on the BMC. 44- Method 3: Via REST Upload: 45 https://github.com/openbmc/docs/blob/master/rest-api.md#uploading-images 46- Method 4: Via TFTP: Perform a POST request to call the `DownloadViaTFTP` 47 method of `/xyz/openbmc_project/software`. 48 49Methods 3 and 4 require additional options in bmcweb to be enabled. 50 513. Note the version id generated for that image file. The version id is a hash 52 value of 8 hexadecimal numbers, generated by SHA-512 hashing the version 53 string contained in the image and taking the first 8 characters. Get the 54 version id via one of the following methods: 55 56- Method 1: From the BMC command line, note the most recent directory name 57 created under `/tmp/images/`, in this example it'd be `2a1022fe`: 58 59 ``` 60 # ls -l /tmp/images/ 61 total 0 62 drwx------ 2 root root 80 Aug 22 07:54 2a1022fe 63 drwx------ 2 root root 80 Aug 22 07:53 488449a2 64 ``` 65 66- Method 2: This method _only_ works if there are no `Ready` images at the start 67 of transferring the image. Using the REST API, note the object that has its 68 Activation property set to Ready, in this example it'd be `2a1022fe`: 69 70 ``` 71 $ curl -b cjar -k https://${bmc}/xyz/openbmc_project/software/enumerate 72 { 73 "data": { 74 "/xyz/openbmc_project/software/2a1022fe": { 75 "Activation": "xyz.openbmc_project.Software.Activation.Activations.Ready", 76 ``` 77 78- Method 3: Calculate the version id beforehand from the image with: 79 80 ``` 81 tar xfO <BMC tar image> MANIFEST | sed -ne '/version=/ {s/version=//;p}' | head -n1 | tr -d '\n' | sha512sum | cut -b 1-8 82 ``` 83 844. To initiate the update, set the `RequestedActivation` property of the desired 85 image to `Active`, substitute `<id>` with the hash value noted on the 86 previous step, this will write the contents of the image to the BMC chip via 87 one of the following methods: 88 89- Method 1: From the BMC command line: 90 91 ``` 92 busctl set-property xyz.openbmc_project.Software.BMC.Updater \ 93 /xyz/openbmc_project/software/<id> \ 94 xyz.openbmc_project.Software.Activation RequestedActivation s \ 95 xyz.openbmc_project.Software.Activation.RequestedActivations.Active 96 97 ``` 98 99- Method 2: Using the REST API: 100 101 ``` 102 curl -b cjar -k -H "Content-Type: application/json" -X PUT \ 103 -d '{"data": 104 "xyz.openbmc_project.Software.Activation.RequestedActivations.Active"}' \ 105 https://${bmc}/xyz/openbmc_project/software/<id>/attr/RequestedActivation 106 ``` 107 1085. (Optional) Check the flash progress. This interface is only available during 109 the activation progress and is not present once the activation is completed 110 via one of the following: 111 112- Method 1: From Redfish: A task is returned from the Redfish upload. The task 113 can be used to monitor the progress. 114 115 ``` 116 curl -k https://${bmc}/redfish/v1/TaskService/Tasks/0 117 ``` 118 119- Method 2: From the BMC command line: 120 121 ``` 122 busctl get-property xyz.openbmc_project.Software.BMC.Updater \ 123 /xyz/openbmc_project/software/<id> \ 124 xyz.openbmc_project.Software.ActivationProgress Progress 125 ``` 126 127- Method 3: Using the REST API: 128 129 ``` 130 curl -b cjar -k https://${bmc}/xyz/openbmc_project/software/<id>/attr/Progress 131 ``` 132 1336. Check that the activation is complete by verifying the "Activation" property 134 is set to "Active" via one of the following methods: 135 136- Method 1: From Redfish: Check the task returned from the Redfish upload. 137 138 ``` 139 curl -k https://${bmc}/redfish/v1/TaskService/Tasks/0 140 ``` 141 142- Method 2: From the BMC command line: 143 144 ``` 145 busctl get-property xyz.openbmc_project.Software.BMC.Updater \ 146 /xyz/openbmc_project/software/<id> \ 147 xyz.openbmc_project.Software.Activation Activation 148 ``` 149 150- Method 3: Using the REST API: 151 152 ``` 153 curl -b cjar -k https://${bmc}/xyz/openbmc_project/software/<id> 154 ``` 155 1567. Reboot the BMC for the image to take effect. 157 158- Method 1: From Redfish: If ApplyTime was set to "Immediate", the BMC will 159 automatically reboot: 160 https://github.com/openbmc/docs/blob/master/REDFISH-cheatsheet.md#firmware-applytime. 161 To reboot the BMC manually see: 162 https://github.com/openbmc/docs/blob/master/REDFISH-cheatsheet.md#bmc-reboot. 163 164- Method 2: From the BMC command line: 165 166 ``` 167 reboot 168 ``` 169 170- Method 3: Using the REST API: 171 172 ``` 173 curl -c cjar -b cjar -k -H "Content-Type: application/json" -X PUT \ 174 -d '{"data": "xyz.openbmc_project.State.BMC.Transition.Reboot"}' \ 175 https://${bmc}/xyz/openbmc_project/state/bmc0/attr/RequestedBMCTransition 176 ``` 177 178### Associations 179 180In addition to all software images, several associations are listed at 181`/xyz/openbmc_project/software/`: 182 183``` 184curl -c cjar -b cjar -k -H "Content-Type: application/json" -X GET \ 185 https://${bmc}/xyz/openbmc_project/software/ 186{ 187 "data": [ 188 "/xyz/openbmc_project/software/46e65782", 189 "/xyz/openbmc_project/software/493a00ad", 190 "/xyz/openbmc_project/software/88c153b1", 191 "/xyz/openbmc_project/software/active", 192 "/xyz/openbmc_project/software/functional" 193 ], 194 "message": "200 OK", 195 "status": "ok" 196} 197``` 198 1991. A "functional" association to the "running" BMC and host images 200 201There is only one functional association per BMC and one functional association 202per host. The functional/running BMC image is the BMC image with the lowest 203priority when rebooting the BMC. The functional image does not update until the 204BMC is rebooted. The functional host image behaves the same way except that it 205updates on a power on or reboot of the host. 206 207``` 208curl -c cjar -b cjar -k -H "Content-Type: application/json" -X GET \ 209 https://${bmc}/xyz/openbmc_project/software/functional 210{ 211 "data": { 212 "endpoints": [ 213 "/xyz/openbmc_project/software/46e65782", 214 "/xyz/openbmc_project/software/493a00ad" 215 ] 216 }, 217 "message": "200 OK", 218 "status": "ok" 219} 220``` 221 2222. An "active" association to the active BMC and host images 223 224Note: Several BMC images might be active, this is true for the host images as 225well. 226 227``` 228curl -c cjar -b cjar -k -H "Content-Type: application/json" -X GET \ 229 https://${bmc}/xyz/openbmc_project/software/active 230{ 231 "data": { 232 "endpoints": [ 233 "/xyz/openbmc_project/software/46e65782", 234 "/xyz/openbmc_project/software/493a00ad", 235 "/xyz/openbmc_project/software/88c153b1" 236 ] 237 }, 238 "message": "200 OK", 239 "status": "ok" 240} 241``` 242 2433. An "updateable" association to the programmable components 244 245This is used for identifying firmware components which are programmable via BMC 246OOB interfaces like Redfish/IPMI. All updateable firmware components must expose 247the updateable association so that upper applications like Redfish/IPMI will 248know about updateable firmwares. 249 250To know the updateable software components: 251 252``` 253# busctl call xyz.openbmc_project.ObjectMapper \ 254 /xyz/openbmc_project/software/updatable org.freedesktop.DBus.Properties \ 255 Get ss xyz.openbmc_project.Association endpoints 256v as 1 "/xyz/openbmc_project/software/1201fc36" 257``` 258 259Redfish interface uses 'updateable' association in SoftwareInventory schema. 260 2614. An additional association is located at 262 `/xyz/openbmc_project/software/<id>/inventory` for "associating" a software 263 image with an inventory item. 264 265``` 266curl -c cjar -b cjar -k -H "Content-Type: application/json" -X GET \ 267 https://${bmc}/xyz/openbmc_project/software/493a00ad/inventory 268{ 269 "data": { 270 "endpoints": [ 271 "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc" 272 ] 273 }, 274 "message": "200 OK", 275 "status": "ok" 276} 277``` 278 279To get all software images associated with an inventory item: 280 281``` 282curl -c cjar -b cjar -k -H "Content-Type: application/json" -X GET \ 283 https://${bmc}/xyz/openbmc_project/inventory/system/chassis/activation 284{ 285 "data": { 286 "endpoints": [ 287 "/xyz/openbmc_project/software/46e65782" 288 ] 289 }, 290 "message": "200 OK", 291 "status": "ok" 292} 293``` 294 295### MANIFEST File 296 297A file named "MANIFEST" must be included in any image tar uploaded, downloaded 298via TFTP, or copied to the BMC. 299 300The MANIFEST file format must be key=value (e.g. version=v1.99.10). It should 301include the following fields: 302 303- version - The version of the image 304- purpose - The image's purpose (e.g. 305 xyz.openbmc_project.Software.Version.VersionPurpose.BMC or 306 xyz.openbmc_project.Software.Version.VersionPurpose.Host). Accepted purpose 307 values can be found at 308 [Version interface](https://github.com/openbmc/phosphor-dbus-interfaces/blob/6f69ae5b33ee224358cb4c2061f4ad44c6b36d70/xyz/openbmc_project/Software/Version.interface.yaml) 309 under "VersionPurpose" values. 310- MachineName - The name of machine (platform) for which this image is built 311 for. This value will be compared against OPENBMC_TARGET_MACHINE value defined 312 in os-release file of running image. Image will not be upgraded if this check 313 fails. For backward compatibility this check skips failure if MachineName is 314 not defined for current released images but it will be made mandatory field 315 from 2.9 onward releases. 316 317Other optional fields are: 318 319- extended_version - A more detailed version, which could include versions of 320 different components in the image. 321 322### Deleting an Image 323 324To delete an image: 325 326``` 327curl -c cjar -b cjar -k -H "Content-Type: application/json" \ 328 -X POST https://${bmc}/xyz/openbmc_project/software/<$id>/action/delete \ 329 -d "{\"data\": [] }" 330``` 331 332Note: The image must be non-functional ("non-running"). 333 334To delete all non-functional images, whether BMC or host images: 335 336``` 337curl -c cjar -b cjar -k -H "Content-Type: application/json" \ 338 -X POST https://${bmc}/xyz/openbmc_project/software/action/deleteAll \ 339 -d "{\"data\": [] }" 340``` 341 342### Software Field Mode 343 344Field mode is meant for systems shipped from manufacturing to a customer. Field 345mode offers a way to provide security and ensure incorrect patches don't get 346loaded on the system by accident. The software implementation of the field mode 347interface disables patching of the BMC by not mounting `/usr/local`, which in 348turn disables host patching at `/usr/local/share/pnor/`. Enabling field mode is 349intended to be a one-way operation which means that once enabled, there is no 350REST API provided to disable it. 351 352Field mode can be enabled by running the following command: 353 354``` 355curl -b cjar -k -H 'Content-Type: application/json' -X PUT -d '{"data":1}' \ 356 https://${bmc}/xyz/openbmc_project/software/attr/FieldModeEnabled 357 358``` 359 360Although field mode is meant to be a one-way operation, it can be disabled by a 361user with admin privileges by running the following commands on the BMC: 362 363``` 364fw_setenv fieldmode 365 366systemctl unmask usr-local.mount 367 368reboot 369``` 370 371More information on field mode can be found here: 372https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Control/FieldMode.interface.yaml 373 374### Software Factory Reset 375 376Software factory reset resets the BMC and host firmware to its factory state by 377clearing out any read/write data. To software factory reset run the following 378command and then reboot the BMC: 379 380``` 381curl -b cjar -k -H 'Content-Type: application/json' -X POST -d '{"data":[]}' \ 382 https://${bmc}/xyz/openbmc_project/software/action/Reset 383 384``` 385 386The factory reset on the BMC side will clear `/var`, `/home`, and `/etc`. On the 387host side, the factory reset will clear the read/write volume for each host 388image on the system, clear the shared preserve host volume, pnor-prsv, and clear 389any host patches located in `/usr/local/share/pnor/`. 390 391The factory reset interface can be found here: 392https://github.com/openbmc/phosphor-dbus-interfaces/blob/02b39246d45ea029a1652a49cc20eab7723dd63b/xyz/openbmc_project/Common/FactoryReset.interface.yaml 393 394### Image Storage Location 395 396#### Static layout 397 398When a BMC image is activated, each `image-<name>` is written to the BMC chip's 399partitions indicated by the `<name>`: 400 401- image-u-boot 402- image-kernel 403- image-rofs 404- image-rwfs 405 406#### UBI layout 407 408When a BMC image is activated (i.e. when "RequestedActivation" is set to 409"Active"), UBI volumes are created on the BMC chip for the image. The alternate 410BMC chip can also be used to store images. This is determined by "BMC_RO_MTD". 411Using both the alternate BMC chip and the BMC chip allows for multiple BMC 412images to be stored. By default, only the BMC chip is used. To use both, set 413"BMC_RO_MTD" to "alt-bmc+bmc". 414 415### Implementation 416 417More information about the implementation of the code update can be found at 418https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Software 419and https://github.com/openbmc/phosphor-bmc-code-mgmt 420