1b9cd9914SPatrick Venture# BMC Handler Configuration 2b9cd9914SPatrick Venture 3b9cd9914SPatrick VentureThe BMC BLOB handler for the flash objects is configured at run-time via a json 4b9cd9914SPatrick Venturefile or multiple json files. The json fields detail every aspect of how the 5b9cd9914SPatrick Venturehandler should behave for a given blob id. 6b9cd9914SPatrick Venture 7b9cd9914SPatrick VentureThere are three json configurations available by default: 8b9cd9914SPatrick Venture 9*db45fd46SPatrick Williams- config-bios.json 10*db45fd46SPatrick Williams- config-static-bmc-reboot.json 11*db45fd46SPatrick Williams- config-static-bmc.json 12b9cd9914SPatrick Venture 13b9cd9914SPatrick VentureLet's break them down, what they contain and what it means, and then how to 14b9cd9914SPatrick Venturewrite your own. It's helpful to start here. 15b9cd9914SPatrick Venture 16b9cd9914SPatrick Venture## config-bios.json 17b9cd9914SPatrick Venture 18b9cd9914SPatrick VentureThis file is generated from configuration and therefore some values can be 19b9cd9914SPatrick Venturereplaced, here we're using the defaults. 20b9cd9914SPatrick Venture 21b9cd9914SPatrick Venture``` 22b9cd9914SPatrick Venture[{ 23b9cd9914SPatrick Venture "blob": "/flash/bios", 24b9cd9914SPatrick Venture "handler": { 25b9cd9914SPatrick Venture "type": "file", 26b9cd9914SPatrick Venture "path": "/tmp/bios-image" 27b9cd9914SPatrick Venture }, 28b9cd9914SPatrick Venture "actions": { 29b9cd9914SPatrick Venture "preparation": { 30b9cd9914SPatrick Venture "type": "systemd", 31b9cd9914SPatrick Venture "unit": "phosphor-ipmi-flash-bios-prepare.target" 32b9cd9914SPatrick Venture }, 33b9cd9914SPatrick Venture "verification": { 34fc5d8d2eSWilliam A. Kennington III "type": "systemd", 35fc5d8d2eSWilliam A. Kennington III "unit": "phosphor-ipmi-flash-bios-verify.target" 36b9cd9914SPatrick Venture }, 37b9cd9914SPatrick Venture "update": { 38b9cd9914SPatrick Venture "type": "systemd", 39b9cd9914SPatrick Venture "unit": "phosphor-ipmi-flash-bios-update.target" 40b9cd9914SPatrick Venture } 41b9cd9914SPatrick Venture } 42b9cd9914SPatrick Venture}] 43b9cd9914SPatrick Venture``` 44b9cd9914SPatrick Venture 45b9cd9914SPatrick VentureEach json file is expected to be an array of flash handler configurations. You 46b9cd9914SPatrick Venturecan define more than one handler inside a json file, or you can have one per 47b9cd9914SPatrick Venturefile. It will make no difference. The file though, must contain an array. 48b9cd9914SPatrick Venture 49b9cd9914SPatrick VentureBeyond this, the flash handler configuration is a dictionary or object with 50b9cd9914SPatrick Venturethree fields. 51b9cd9914SPatrick Venture 52*db45fd46SPatrick Williams- `blob` 53*db45fd46SPatrick Williams- `handler` 54*db45fd46SPatrick Williams- `actions` 55b9cd9914SPatrick Venture 56b9cd9914SPatrick Venture### `blob` 57b9cd9914SPatrick Venture 58b9cd9914SPatrick VentureThe `blob` field expects to hold a string. This string is the blob id that'll be 59b9cd9914SPatrick Venturepresented to the host and registered with the blob manager. It must be unique 60b9cd9914SPatrick Ventureamong all blobs on a system and must start with `/flash/`. The uniqueness is not 61b9cd9914SPatrick Venturepresently verified at any stage. If there is another blob id that matches, the 62b9cd9914SPatrick Venturefirst one loaded will be the first one hit during any calls from the host. It's 63b9cd9914SPatrick Venturegenerally unlikely that there will be a name collision. 64b9cd9914SPatrick Venture 65b9cd9914SPatrick Venture### `handler` 66b9cd9914SPatrick Venture 67b9cd9914SPatrick VentureThe `handler` field expects to hold a dictionary or object with at least one 68b9cd9914SPatrick Venturefield. 69b9cd9914SPatrick Venture 70*db45fd46SPatrick Williams- `type` 71b9cd9914SPatrick Venture 72b9cd9914SPatrick VentureThe `type` field expects a string and will control what other parameters are 73b9cd9914SPatrick Venturerequired. The type here refers to the handler for the incoming data associated 74b9cd9914SPatrick Venturewith the flash image contents. The hash data is always done as a file, but the 75b9cd9914SPatrick Ventureimage data is configurable via the json. 76b9cd9914SPatrick Venture 77b9cd9914SPatrick VentureIn the above configuration the `type` is set to `file`. The `file` type handler 78b9cd9914SPatrick Venturerequires one parameter: `path`. The `path` here is the full file system path to 79b9cd9914SPatrick Venturewhere to write the bytes received into a file. In this case specifically the 80b9cd9914SPatrick Venturebyte received will be written to `/tmp/bios-image`. 81b9cd9914SPatrick Venture 82b9cd9914SPatrick Venture### `actions` 83b9cd9914SPatrick Venture 84b9cd9914SPatrick VentureBecause `phosphor-ipmi-flash` is a framework for sending data from the host to 85b9cd9914SPatrick Venturethe BMC for updating various firmware, it needs to be told what to do to verify 86b9cd9914SPatrick Venturethe data and cause an update. It additionally provides a mechanism for preparing 87b9cd9914SPatrick Venturethe BMC to receive the data. On a low memory BMC, the preparation step can be 88b9cd9914SPatrick Ventureused to shut down unnecessary services, etc. 89b9cd9914SPatrick Venture 90b9cd9914SPatrick VentureThe actions are split into three fields: 91b9cd9914SPatrick Venture 92*db45fd46SPatrick Williams- `preparation` 93*db45fd46SPatrick Williams- `verification` 94*db45fd46SPatrick Williams- `update` 95b9cd9914SPatrick Venture 96b9cd9914SPatrick VentureThe `preparation`, `verification`, and `update` fields expect a `type` field, 97b9cd9914SPatrick Venturesimilarly to the `handler` field. This dictates what other parameters may be 98b9cd9914SPatrick Venturerequired. 99b9cd9914SPatrick Venture 100b9cd9914SPatrick VentureIn this configuration the `preparation` type is `systemd`. The `systemd` type 101b9cd9914SPatrick Ventureexpects to receive a `unit`. The `unit` value is expected to be a string that is 102b9cd9914SPatrick Venturethe name of the systemd unit to start. In this case, it'll start 103b9cd9914SPatrick Venture`phosphor-ipmi-flash-bios-prepare.target`. This can be a single service name, or 104b9cd9914SPatrick Venturea target. 105b9cd9914SPatrick Venture 106fc5d8d2eSWilliam A. Kennington IIIIn this configuration the `verification` type is `systemd`. This will query 107fc5d8d2eSWilliam A. Kennington IIIsystemd for the status of the verification unit to determine running, success, 108fc5d8d2eSWilliam A. Kennington IIIor failure. 109b9cd9914SPatrick Venture 110b9cd9914SPatrick VentureIn this configuration the `update` type is `systemd`. This is the same object as 111fc5d8d2eSWilliam A. Kennington IIIwith the `preparation` action. 112b9cd9914SPatrick Venture 113b9cd9914SPatrick Venture## config-static-bmc-reboot.json 114b9cd9914SPatrick Venture 115b9cd9914SPatrick VentureThis file is generated from configuration and therefore some values can be 116b9cd9914SPatrick Venturereplaced, here we're using the defaults. 117b9cd9914SPatrick Venture 118b9cd9914SPatrick Venture``` 119b9cd9914SPatrick Venture[{ 120b9cd9914SPatrick Venture "blob": "/flash/image", 121b9cd9914SPatrick Venture "handler": { 122b9cd9914SPatrick Venture "type": "file", 123b9cd9914SPatrick Venture "path": "/run/initramfs/bmc-image" 124b9cd9914SPatrick Venture }, 125b9cd9914SPatrick Venture "actions": { 126b9cd9914SPatrick Venture "preparation": { 127b9cd9914SPatrick Venture "type": "systemd", 128b9cd9914SPatrick Venture "unit": "phosphor-ipmi-flash-bmc-prepare.target" 129b9cd9914SPatrick Venture }, 130b9cd9914SPatrick Venture "verification": { 131fc5d8d2eSWilliam A. Kennington III "type": "systemd", 132fc5d8d2eSWilliam A. Kennington III "unit": "phosphor-ipmi-flash-bmc-verify.target" 133b9cd9914SPatrick Venture }, 134b9cd9914SPatrick Venture "update": { 135b9cd9914SPatrick Venture "type": "reboot" 136b9cd9914SPatrick Venture } 137b9cd9914SPatrick Venture } 138b9cd9914SPatrick Venture}] 139b9cd9914SPatrick Venture``` 140b9cd9914SPatrick Venture 141b9cd9914SPatrick VentureGiven the bios configuration, we can skip the parts of this configuration that 142b9cd9914SPatrick Ventureare already explained. The new action type is `reboot`. This is a special action 143b9cd9914SPatrick Venturetype that has no parameters. It will simply trigger a reboot via systemd. 144b9cd9914SPatrick Venture 145b9cd9914SPatrick Venture## config-static-bmc.json 146b9cd9914SPatrick Venture 147b9cd9914SPatrick VentureThis file is generated from configuration and therefore some values can be 148b9cd9914SPatrick Venturereplaced, here we're using the defaults. 149b9cd9914SPatrick Venture 150b9cd9914SPatrick Venture``` 151b9cd9914SPatrick Venture[{ 152b9cd9914SPatrick Venture "blob": "/flash/image", 153b9cd9914SPatrick Venture "handler": { 154b9cd9914SPatrick Venture "type": "file", 155b9cd9914SPatrick Venture "path": "/run/initramfs/bmc-image" 156b9cd9914SPatrick Venture }, 157b9cd9914SPatrick Venture "actions": { 158b9cd9914SPatrick Venture "preparation": { 159b9cd9914SPatrick Venture "type": "systemd", 160b9cd9914SPatrick Venture "unit": "phosphor-ipmi-flash-bmc-prepare.target" 161b9cd9914SPatrick Venture }, 162b9cd9914SPatrick Venture "verification": { 163fc5d8d2eSWilliam A. Kennington III "type": "systemd", 164fc5d8d2eSWilliam A. Kennington III "unit": "phosphor-ipmi-flash-bmc-verify.target" 165b9cd9914SPatrick Venture }, 166b9cd9914SPatrick Venture "update": { 167b9cd9914SPatrick Venture "type": "systemd", 168b9cd9914SPatrick Venture "unit": "phosphor-ipmi-flash-bmc-update.target" 169b9cd9914SPatrick Venture } 170b9cd9914SPatrick Venture } 171b9cd9914SPatrick Venture}] 172b9cd9914SPatrick Venture``` 173b9cd9914SPatrick Venture 174b9cd9914SPatrick VentureThis configuration is of no significance in its difference. 175b9cd9914SPatrick Venture 176b9cd9914SPatrick Venture## Writing your own json Configuration 177b9cd9914SPatrick Venture 178b9cd9914SPatrick VentureIf you wish to write your own json configuration, you simply create a legal json 179b9cd9914SPatrick Venturefile containing an array of at least one entry. This array will define any 180b9cd9914SPatrick Ventureentries you wish. You can provide multiple BMC update json configurations if you 181b9cd9914SPatrick Venturewish. There may be parameters you desire to pass to an update process, for 182b9cd9914SPatrick Ventureinstance, clearing the whitelisted files. In this case, it's trivial to create 183b9cd9914SPatrick Venturetwo targets. The first target performs a normal update, the second starts a 184b9cd9914SPatrick Ventureservice that performs the desired other update. You can leverage the 185b9cd9914SPatrick Venturedefault-provided configuration files, and also add your own to add additional 186b9cd9914SPatrick Venturesupport if desired. 187b9cd9914SPatrick Venture 188b9cd9914SPatrick VentureAn entry, regardless, must contain a `blob`, a `handler`, and `actions`. 189b9cd9914SPatrick Venture 190b9cd9914SPatrick Venture### Handler Types 191b9cd9914SPatrick Venture 192b9cd9914SPatrick VentureA handler determines how the bytes from the host are stored. 193b9cd9914SPatrick Venture 194b9cd9914SPatrick Venture#### `file` 195b9cd9914SPatrick Venture 196b9cd9914SPatrick VentureThe `file` handler type writes the bytes to a file path specified by the 197b9cd9914SPatrick Venturerequired parameter `path`. 198b9cd9914SPatrick Venture 199*db45fd46SPatrick Williams- `path` - full file system path to where to write bytes. 200b9cd9914SPatrick Venture 201b9cd9914SPatrick Venture### Action Types 202b9cd9914SPatrick Venture 203b9cd9914SPatrick VentureAction types are used to define what to do for a specific requested action, such 204b9cd9914SPatrick Ventureas "verify the blob contents." 205b9cd9914SPatrick Venture 206d53d60a4SPatrick Venture#### `skip` 207d53d60a4SPatrick Venture 208d53d60a4SPatrick VentureThe `skip` type will effectively make that action a no-op and always return 209d53d60a4SPatrick Venturesuccess. 210d53d60a4SPatrick Venture 211b9cd9914SPatrick Venture#### `systemd` 212b9cd9914SPatrick Venture 213b9cd9914SPatrick VentureThe `systemd` type should be used when you wish to start a systemd service or 214d9cc253aSWilliam A. Kennington IIItarget. For verification and update operations this will track the status of the 215d9cc253aSWilliam A. Kennington IIIsystemd service to determine success or failure. 216b9cd9914SPatrick Venture 217*db45fd46SPatrick Williams- `unit` - required - string - the systemd unit to start. 218*db45fd46SPatrick Williams- `mode` - optional - string - default: replace - the mode for starting the 219b9cd9914SPatrick Venture service. 220b9cd9914SPatrick Venture 221ffbd93ebSBrandon Kim#### `fileSystemdVerify` & `fileSystemdUpdate` 222b9cd9914SPatrick Venture 223b9cd9914SPatrick VentureBecause one may care about the result of their actions, the `fileSystemdVerify` 224ffbd93ebSBrandon Kimand `fileSystemdUpdate` action type exists. It will start the service and when 225ffbd93ebSBrandon Kimasked for a status, it'll read the contents of a file. Therefore, whatever is 226d9cc253aSWilliam A. Kennington IIIperforming the action will want to update that file. NOTE: Now that the systemd 227d9cc253aSWilliam A. Kennington IIItype action tracks unit status, that action is now preferred. 228b9cd9914SPatrick Venture 229*db45fd46SPatrick Williams- `path` - required - string - the full file system path to where one finds the 230*db45fd46SPatrick Williams status. 231*db45fd46SPatrick Williams- `unit` - required - string - the systemd unit to start 232*db45fd46SPatrick Williams- `mode` - optional - string - default: replace - the mode for starting the 233b9cd9914SPatrick Venture service. 234b9cd9914SPatrick Venture 235b9cd9914SPatrick Venture#### `reboot` 236b9cd9914SPatrick Venture 237b9cd9914SPatrick VentureThe `reboot` type causes a reboot via systemd. If this happens quickly enough, 238b9cd9914SPatrick Ventureyou may not receive a response over IPMI that your command succeeded. 239b9cd9914SPatrick Venture 240b9cd9914SPatrick Venture### Installing your own json configuration 241b9cd9914SPatrick Venture 242b9cd9914SPatrick VentureTo install your own configuration(s) you can add your own bbappend file that 243b9cd9914SPatrick Ventureappends to the install task. The json files are installed in 244b9cd9914SPatrick Venture`${D}${datadir}/phosphor-ipmi-flash/` 245b9cd9914SPatrick Venture 246b9cd9914SPatrick Venture## Adding your own handler type 247b9cd9914SPatrick Venture 248b9cd9914SPatrick VentureFirstly, welcome! The maintainers of this repository appreciate your 249b9cd9914SPatrick Venturecontribution. A handler is just an implementation of the 250b9cd9914SPatrick Venture`ImageHandlerInterface`. 251b9cd9914SPatrick Venture 252b9cd9914SPatrick VentureYour handler must implement: 253b9cd9914SPatrick Venture 254*db45fd46SPatrick Williams- `bool open(const std::string& path)` 255*db45fd46SPatrick Williams- `void close()` 256*db45fd46SPatrick Williams- `bool write(std::uint32_t offset, const std::vector<std::uint8_t>& data)` 257*db45fd46SPatrick Williams- `int getSize()` 258b9cd9914SPatrick Venture 259b9cd9914SPatrick VentureThe handler is meant to receive the bytes, and write the bytes. 260b9cd9914SPatrick Venture 261b9cd9914SPatrick VentureOnce the object is defined you can specify a type and parameters here and in the 262b9cd9914SPatrick Venture`buildjson` module. 263b9cd9914SPatrick Venture 264b9cd9914SPatrick Venture## Adding your own action type 265b9cd9914SPatrick Venture 266b9cd9914SPatrick VentureFirstly, welcome! The maintainers of this repository appreciate your 267b9cd9914SPatrick Venturecontribution. An action is just an implementation of the 268b9cd9914SPatrick Venture`TriggerableActionInterface`. 269b9cd9914SPatrick Venture 270b9cd9914SPatrick VentureYour action must implement: 271b9cd9914SPatrick Venture 272*db45fd46SPatrick Williams- `bool trigger()` 273*db45fd46SPatrick Williams- `void abort()` 274*db45fd46SPatrick Williams- `ActionStatus status()` 275b9cd9914SPatrick Venture 276b9cd9914SPatrick VentureThe abort method is not a guarantee. 277b9cd9914SPatrick Venture 278b9cd9914SPatrick VentureOnce the object is defined you can specify a type and parameters here and in the 279b9cd9914SPatrick Venture`buildjson` module. 280