1# In-Band Update of BMC Firmware using USB 2 3Author: George Liu <liuxiwei!> 4 5Created: 2021-10-12 6 7## Problem Description 8 9When Redfish or scp cannot be used, BMC needs a new mechanism for images to get 10into the machine. 11 12## Background and References 13 14The openbmc project currently has a [phosphor-software-manager][1] repository. 15In order to perform an update, need first to bring the image into the BMC 16directory (/tmp/images). However, only TFTP and HTTP are currently supported, 17and USB is not yet supported. 18 19The intent of this new application design is to enable the USB driver of BMC to 20enter the new image into BMC. 21 22## Requirements 23 24The following statements are reflective of the initial requirements. 25 * Monitor whether the USB key is inserted. 26 * The first tar file found in the sorted list of files on the USB device is 27copied to `/tmp/images`. 28 * Manually trigger firmware upgrade. 29 * Disable automatic reboot the BMC firmware after upgrade is complete to 30prevent a potential loop in the event of a key inserted. 31 * This mechanism attempts to maintain security, for example this feature is 32disabled by default or can be enabled or disabled via Redfish. 33 34## Proposed Design 35 36The new code would be part of the phosphor-software-manager 37repository(eg: phosphor-usb-code-update). 38The design process is as follows: 39 - Define a macro switch (`usb-code-update`) in [phosphor-software-manager][1] 40repository to identify whether to enable the USB Code Update function, 41which is _enabled_ by default. 42 - If `usb-code-update` enabled, install the udev rules file to 43`/lib/udev/rules.d` during compilation. 44 - Once the udev rules are met, the systemd service is directly triggered and 45start the phosphor-usb-code-update daemon. 46 - This daemon verifies the `/run/media/usb/sda1` directory and copies 47the first `.tar` file in the directory to `/tmp/images` and starts 48verification. 49 - Set ApplyTime to OnReset so that the proposed usb code update app does not 50reboot the BMC after activation. 51 - Set RequestedActivation to Active, follow the updated status, start to 52update the firmware, and restart the BMC after completion. 53 - Exit the phosphor-usb-code-update daemon. 54 55## Pseudocode 56 57The udev rules files for example: 58``` 59SUBSYSTEM=="block", ACTION=="add", ENV{ID_USB_DRIVER}=="usb-storage", ENV{DEVTYPE}=="partition", ENV{SYSTEMD_WANTS}="usb-code-update@%k", TAG+="systemd" 60``` 61 62## Security 63 64 - It is recommended to run a local CI run and analyze & avoid potential 65vulnerabilities via cppcheck. 66 - Assuming that the USB drive has a physical security vulnerability 67(such as memory overflow, etc.), should disable "USB code update" via Redfish. 68After the vulnerability is fixed, enable "USB code update" again via Redfish. 69 70## Alternatives Considered 71 72If the OS fails to boot due to an error, so the firmware update cannot be done 73through the OS, or the network fails, and the update cannot be done through 74Redfish or scp, the server support staff can only uninstall the flash chip and 75re-flashing, this is not Reasonably, service support should have local access 76to the machine and update the system to a working firmware level. 77 78## Impacts 79 80This impacts security because it can copy files to the BMC via an external USB 81key. There is no expected performance impact since the process just copies 82files during runtime and exits automatically after completion. 83 84## Testing 85 86 - When the USB code update is disabled, the service will return directly 87without any update. 88 - Manually insert the USB key with the firmware upgrade package, and check 89whether the upgrade file is correct through the log. 90 - Simulate `dev/sda1` on qemu with some test scripts and start the 91service(eg: `systemcl start usb-code-update@sda1.service`) 92 - Verify that the ApplyTime attribute value is set to OnRest. 93 - Verify that the RequestedActivation property value is set to Active. 94 - Verify that the firmware update was successful. 95 96[1]: https://github.com/openbmc/phosphor-bmc-code-mgmt 97