xref: /openbmc/docs/designs/firmware-update-via-usb.md (revision f4febd002df578bad816239b70950f84ea4567e8)
146f84ae4SGeorge Liu# In-Band Update of BMC Firmware using USB
246f84ae4SGeorge Liu
346f84ae4SGeorge LiuAuthor: George Liu <liuxiwei!>
446f84ae4SGeorge Liu
546f84ae4SGeorge LiuCreated: 2021-10-12
646f84ae4SGeorge Liu
746f84ae4SGeorge Liu## Problem Description
846f84ae4SGeorge Liu
946f84ae4SGeorge LiuWhen Redfish or scp cannot be used, BMC needs a new mechanism for images to get
1046f84ae4SGeorge Liuinto the machine.
1146f84ae4SGeorge Liu
1246f84ae4SGeorge Liu## Background and References
1346f84ae4SGeorge Liu
1446f84ae4SGeorge LiuThe openbmc project currently has a [phosphor-software-manager][1] repository.
1546f84ae4SGeorge LiuIn order to perform an update, need first to bring the image into the BMC
1646f84ae4SGeorge Liudirectory (/tmp/images). However, only TFTP and HTTP are currently supported,
1746f84ae4SGeorge Liuand USB is not yet supported.
1846f84ae4SGeorge Liu
1946f84ae4SGeorge LiuThe intent of this new application design is to enable the USB driver of BMC to
2046f84ae4SGeorge Liuenter the new image into BMC.
2146f84ae4SGeorge Liu
2246f84ae4SGeorge Liu## Requirements
2346f84ae4SGeorge Liu
2446f84ae4SGeorge LiuThe following statements are reflective of the initial requirements.
25*f4febd00SPatrick Williams
26*f4febd00SPatrick Williams- Monitor whether the USB key is inserted.
27*f4febd00SPatrick Williams- The first tar file found in the sorted list of files on the USB device is
2846f84ae4SGeorge Liu  copied to `/tmp/images`.
29*f4febd00SPatrick Williams- Manually trigger firmware upgrade.
30*f4febd00SPatrick Williams- Disable automatic reboot the BMC firmware after upgrade is complete to prevent
31*f4febd00SPatrick Williams  a potential loop in the event of a key inserted.
32*f4febd00SPatrick Williams- This mechanism attempts to maintain security, for example this feature is
3346f84ae4SGeorge Liu  disabled by default or can be enabled or disabled via Redfish.
3446f84ae4SGeorge Liu
3546f84ae4SGeorge Liu## Proposed Design
3646f84ae4SGeorge Liu
37*f4febd00SPatrick WilliamsThe new code would be part of the phosphor-software-manager repository(eg:
38*f4febd00SPatrick Williamsphosphor-usb-code-update). The design process is as follows:
39*f4febd00SPatrick Williams
4046f84ae4SGeorge Liu- Define a macro switch (`usb-code-update`) in [phosphor-software-manager][1]
41*f4febd00SPatrick Williams  repository to identify whether to enable the USB Code Update function, which
42*f4febd00SPatrick Williams  is _enabled_ by default.
4346f84ae4SGeorge Liu- If `usb-code-update` enabled, install the udev rules file to
4446f84ae4SGeorge Liu  `/lib/udev/rules.d` during compilation.
4546f84ae4SGeorge Liu- Once the udev rules are met, the systemd service is directly triggered and
4646f84ae4SGeorge Liu  start the phosphor-usb-code-update daemon.
47*f4febd00SPatrick Williams- This daemon verifies the `/run/media/usb/sda1` directory and copies the first
48*f4febd00SPatrick Williams  `.tar` file in the directory to `/tmp/images` and starts verification.
4946f84ae4SGeorge Liu- Set ApplyTime to OnReset so that the proposed usb code update app does not
5046f84ae4SGeorge Liu  reboot the BMC after activation.
51*f4febd00SPatrick Williams- Set RequestedActivation to Active, follow the updated status, start to update
52*f4febd00SPatrick Williams  the firmware, and restart the BMC after completion.
5346f84ae4SGeorge Liu- Exit the phosphor-usb-code-update daemon.
5446f84ae4SGeorge Liu
5546f84ae4SGeorge Liu## Pseudocode
5646f84ae4SGeorge Liu
5746f84ae4SGeorge LiuThe udev rules files for example:
58*f4febd00SPatrick Williams
5946f84ae4SGeorge Liu```
6046f84ae4SGeorge LiuSUBSYSTEM=="block", ACTION=="add", ENV{ID_USB_DRIVER}=="usb-storage", ENV{DEVTYPE}=="partition", ENV{SYSTEMD_WANTS}="usb-code-update@%k", TAG+="systemd"
6146f84ae4SGeorge Liu```
6246f84ae4SGeorge Liu
6346f84ae4SGeorge Liu## Security
6446f84ae4SGeorge Liu
6546f84ae4SGeorge Liu- It is recommended to run a local CI run and analyze & avoid potential
6646f84ae4SGeorge Liu  vulnerabilities via cppcheck.
67*f4febd00SPatrick Williams- Assuming that the USB drive has a physical security vulnerability (such as
68*f4febd00SPatrick Williams  memory overflow, etc.), should disable "USB code update" via Redfish. After
69*f4febd00SPatrick Williams  the vulnerability is fixed, enable "USB code update" again via Redfish.
7046f84ae4SGeorge Liu
7146f84ae4SGeorge Liu## Alternatives Considered
7246f84ae4SGeorge Liu
7346f84ae4SGeorge LiuIf the OS fails to boot due to an error, so the firmware update cannot be done
7446f84ae4SGeorge Liuthrough the OS, or the network fails, and the update cannot be done through
7546f84ae4SGeorge LiuRedfish or scp, the server support staff can only uninstall the flash chip and
76*f4febd00SPatrick Williamsre-flashing, this is not Reasonably, service support should have local access to
77*f4febd00SPatrick Williamsthe machine and update the system to a working firmware level.
7846f84ae4SGeorge Liu
7946f84ae4SGeorge Liu## Impacts
8046f84ae4SGeorge Liu
8146f84ae4SGeorge LiuThis impacts security because it can copy files to the BMC via an external USB
82*f4febd00SPatrick Williamskey. There is no expected performance impact since the process just copies files
83*f4febd00SPatrick Williamsduring runtime and exits automatically after completion.
8446f84ae4SGeorge Liu
8546f84ae4SGeorge Liu## Testing
8646f84ae4SGeorge Liu
87*f4febd00SPatrick Williams- When the USB code update is disabled, the service will return directly without
88*f4febd00SPatrick Williams  any update.
8946f84ae4SGeorge Liu- Manually insert the USB key with the firmware upgrade package, and check
9046f84ae4SGeorge Liu  whether the upgrade file is correct through the log.
91*f4febd00SPatrick Williams- Simulate `dev/sda1` on qemu with some test scripts and start the service(eg:
92*f4febd00SPatrick Williams  `systemcl start usb-code-update@sda1.service`)
9346f84ae4SGeorge Liu- Verify that the ApplyTime attribute value is set to OnRest.
9446f84ae4SGeorge Liu- Verify that the RequestedActivation property value is set to Active.
9546f84ae4SGeorge Liu- Verify that the firmware update was successful.
9646f84ae4SGeorge Liu
9746f84ae4SGeorge Liu[1]: https://github.com/openbmc/phosphor-bmc-code-mgmt
98