19b846121SLei YU# phosphor-psu-code-mgmt
29b846121SLei YU
39b846121SLei YUphosphor-psu-code-mgmt is a service to provide management for PSU code,
49b846121SLei YUincluding:
59b846121SLei YU
69b846121SLei YU* PSU code version
79b846121SLei YU* PSU code update
89b846121SLei YU
99b846121SLei YU
109b846121SLei YU## Building
119b846121SLei YU
129b846121SLei YU```
139b846121SLei YUmeson build/ && ninja -C build
149b846121SLei YU```
159b846121SLei YU
169b846121SLei YU## Unit test
179b846121SLei YU
189b846121SLei YU* Run it in OpenBMC CI, refer to [local-ci-build.md][1]
199b846121SLei YU* Run it in [OE SDK][2], run below commands in a x86-64 SDK env:
209b846121SLei YU   ```
219b846121SLei YU   meson -Doe-sdk=enabled -Dtests=enabled build/
229b846121SLei YU   ninja -C build/ test  # Meson skips running the case due to it thinks it's cross compiling
239b846121SLei YU   # Manually run the tests
249b846121SLei YU   for t in `find build/test/ -maxdepth 1 -name "test_*"`; do ./$t || break ; done
259b846121SLei YU   ```
269b846121SLei YU
278ccc653eSLei YU## Vendor-specific tools
288ccc653eSLei YU
298ccc653eSLei YUThis repo contains generic code to handle the PSU versions and
308ccc653eSLei YUupdates. It depends on vendor-specific tools to provide the below
318ccc653eSLei YUfunctions on the real PSU hardware:
328ccc653eSLei YU* Get PSU firmware version
338ccc653eSLei YU* Compare the firmware version
348ccc653eSLei YU* Update the PSU firmware
358ccc653eSLei YU
368ccc653eSLei YUIt provides configure options for vendor-specific tools for the above functions:
378ccc653eSLei YU* `PSU_VERSION_UTIL`: It shall be defined as a command-line tool that
388ccc653eSLei YUaccepts the PSU inventory path as input, and outputs the PSU version
398ccc653eSLei YUstring to stdout.
408ccc653eSLei YU* `PSU_VERSION_COMPARE_UTIL`: It shall be defined as a command-line
418ccc653eSLei YUtool that accepts one or more PSU version strings, and outputs the
428ccc653eSLei YUlatest version string to stdout.
438ccc653eSLei YU* `PSU_UPDATE_SERVICE`: It shall be defined as a systemd service that
448ccc653eSLei YUaccepts two arguments:
458ccc653eSLei YU   * The PSU inventory DBus object;
468ccc653eSLei YU   * The path of the PSU image(s).
478ccc653eSLei YU
488ccc653eSLei YUFor example:
498ccc653eSLei YU```
508ccc653eSLei YUmeson -Dtests=disabled \
518ccc653eSLei YU    '-DPSU_VERSION_UTIL=/usr/bin/psutils --raw --get-version' \
528ccc653eSLei YU    '-DPSU_VERSION_COMPARE_UTIL=/usr/bin/psutils --raw --compare' \
538ccc653eSLei YU    '-DPSU_UPDATE_SERVICE=psu-update@.service' \
548ccc653eSLei YU    build
558ccc653eSLei YU```
568ccc653eSLei YU
578ccc653eSLei YUThe above configures the vendor-specific tools to use `psutils` from
588ccc653eSLei YU[phosphor-power][3] to get and compare the PSU versions, and use
598ccc653eSLei YU`psu-update@.service` to perform the PSU firmware update, where
608ccc653eSLei YUinternally it invokes `psutils` as well.
618ccc653eSLei YU
62*c6db1142SLei YU
63*c6db1142SLei YU## Usage
64*c6db1142SLei YU
65*c6db1142SLei YU### PSU version
66*c6db1142SLei YU
67*c6db1142SLei YUWhen the service starts, it queries the inventory to get all the PSU inventory
68*c6db1142SLei YUpaths, invokes the vendor-specific tool to get the versions, and creates
69*c6db1142SLei YUversion objects under `/xyz/openbmc_project/software` that are associated with
70*c6db1142SLei YUthe PSU inventory path.
71*c6db1142SLei YUIf multiple PSUs are using the same version, multiple PSU inventory paths are
72*c6db1142SLei YUassociated.
73*c6db1142SLei YU
74*c6db1142SLei YUE.g.
75*c6db1142SLei YU* Example of system with two PSUs that have different versions:
76*c6db1142SLei YU   ```
77*c6db1142SLei YU    "/xyz/openbmc_project/software/02572429": {
78*c6db1142SLei YU      "Activation": "xyz.openbmc_project.Software.Activation.Activations.Active",
79*c6db1142SLei YU      "Associations": [
80*c6db1142SLei YU        [
81*c6db1142SLei YU          "inventory",
82*c6db1142SLei YU          "activation",
83*c6db1142SLei YU          "/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply1"
84*c6db1142SLei YU        ]
85*c6db1142SLei YU      ],
86*c6db1142SLei YU      "ExtendedVersion": "",
87*c6db1142SLei YU      "Path": "",
88*c6db1142SLei YU      "Purpose": "xyz.openbmc_project.Software.Version.VersionPurpose.PSU",
89*c6db1142SLei YU      "RequestedActivation": "xyz.openbmc_project.Software.Activation.RequestedActivations.None",
90*c6db1142SLei YU      "Version": "01120114"
91*c6db1142SLei YU    },
92*c6db1142SLei YU    "/xyz/openbmc_project/software/7094f612": {
93*c6db1142SLei YU      "Activation": "xyz.openbmc_project.Software.Activation.Activations.Active",
94*c6db1142SLei YU      "Associations": [
95*c6db1142SLei YU        [
96*c6db1142SLei YU          "inventory",
97*c6db1142SLei YU          "activation",
98*c6db1142SLei YU          "/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0"
99*c6db1142SLei YU        ]
100*c6db1142SLei YU      ],
101*c6db1142SLei YU      "ExtendedVersion": "",
102*c6db1142SLei YU      "Path": "",
103*c6db1142SLei YU      "Purpose": "xyz.openbmc_project.Software.Version.VersionPurpose.PSU",
104*c6db1142SLei YU      "RequestedActivation": "xyz.openbmc_project.Software.Activation.RequestedActivations.None",
105*c6db1142SLei YU      "Version": "00000110"
106*c6db1142SLei YU    },
107*c6db1142SLei YU   ```
108*c6db1142SLei YU* Example of system with two PSUs that have the same version:
109*c6db1142SLei YU   ```
110*c6db1142SLei YU    "/xyz/openbmc_project/software/9463c2ad": {
111*c6db1142SLei YU      "Activation": "xyz.openbmc_project.Software.Activation.Activations.Active",
112*c6db1142SLei YU      "Associations": [
113*c6db1142SLei YU        [
114*c6db1142SLei YU          "inventory",
115*c6db1142SLei YU          "activation",
116*c6db1142SLei YU          "/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0"
117*c6db1142SLei YU        ],
118*c6db1142SLei YU        [
119*c6db1142SLei YU          "inventory",
120*c6db1142SLei YU          "activation",
121*c6db1142SLei YU          "/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply1"
122*c6db1142SLei YU        ]
123*c6db1142SLei YU      ],
124*c6db1142SLei YU      "ExtendedVersion": "",
125*c6db1142SLei YU      "Path": "",
126*c6db1142SLei YU      "Purpose": "xyz.openbmc_project.Software.Version.VersionPurpose.PSU",
127*c6db1142SLei YU      "RequestedActivation": "xyz.openbmc_project.Software.Activation.RequestedActivations.None",
128*c6db1142SLei YU      "Version": "01100110"
129*c6db1142SLei YU    },
130*c6db1142SLei YU   ```
131*c6db1142SLei YU
132*c6db1142SLei YU### PSU update
133*c6db1142SLei YU
134*c6db1142SLei YU1. Generate a tarball of PSU firmware image by [generate-psu-tar tool][4].
135*c6db1142SLei YU   ```
136*c6db1142SLei YU   ./generate-psu-tar -i <psu-image> -v <version> -model <model> -mf \
137*c6db1142SLei YU   <manufacture> -o <psu.tar> -s
138*c6db1142SLei YU   ```
139*c6db1142SLei YU2. To update the PSU firmware, follow the same steps as described in
140*c6db1142SLei YU   [code-update.md][5]:
141*c6db1142SLei YU   * Upload a PSU image tarball and get the version ID;
142*c6db1142SLei YU   * Set the RequestedActivation state of the uploaded image's version ID.
143*c6db1142SLei YU   * Check the state and wait for the activation to be completed.
144*c6db1142SLei YU3. After a successful update, the PSU image and the manifest is stored
145*c6db1142SLei YU   in BMC's persistent storage defined by `IMG_DIR_PERSIST`. When a PSU
146*c6db1142SLei YU   is replaced, the PSU's firmware version will be checked and updated if
147*c6db1142SLei YU   it's older than the one stored in BMC.
148*c6db1142SLei YU4. It is possible to put a PSU image and MANIFEST in the built-bin
149*c6db1142SLei YU   OpenBMC image in BMC's read-only filesystem defined by
150*c6db1142SLei YU   `IMG_DIR_BUILTIN`. When the service starts, it will compare the
151*c6db1142SLei YU   versions of the built-in image, the stored image (after PSU update),
152*c6db1142SLei YU   and the existing PSUs, if there is any PSU that has an older firmware,
153*c6db1142SLei YU   it will be updated to the newest one.
154*c6db1142SLei YU
155*c6db1142SLei YU
1561799f381SGunnar Mills[1]: https://github.com/openbmc/docs/blob/master/testing/local-ci-build.md
1579b846121SLei YU[2]: https://github.com/openbmc/docs/blob/master/cheatsheet.md#building-the-openbmc-sdk
1588ccc653eSLei YU[3]: https://github.com/openbmc/phosphor-power/tree/master/tools/power-utils
159*c6db1142SLei YU[4]: https://github.com/openbmc/phosphor-psu-code-mgmt/blob/master/tools/generate-psu-tar
160*c6db1142SLei YU[5]: https://github.com/openbmc/docs/blob/master/code-update/code-update.md
161