not-a-feature / wd_fw_update

Updates the firmware of Western Digital SSDs on Ubuntu / Linux Mint.
https://wd-fw-update.readthedocs.io
GNU General Public License v3.0
22 stars 3 forks source link

Improve error message: add recursive resolver to check if current version is newer / equal than available versions #1

Closed nmasse-itix closed 4 months ago

nmasse-itix commented 7 months ago

Environment

cat /etc/redhat-release 
Fedora release 39 (Thirty Nine)

Hardware

$ cat /sys/class/nvme/nvme0/model
WD_BLACK SN850X 2000GB

$ cat /sys/class/nvme/nvme0/firmware_rev 
620361WD

Steps to reproduce the problem

sudo -i
python -m venv --prompt wd-fw-update $HOME/wd-fw-update
. $HOME/wd-fw-update/bin/activate
pip install wd-fw-update

Metadata from WD at present time

    <lista_device model="WD_BLACK SN850X 2000GB">
        <url>wdDashboard/firmware/WD_BLACK_SN850X_2000GB/620241WD/device_properties.xml</url>
        <url>wdDashboard/firmware/WD_BLACK_SN850X_2000GB/620361WD/device_properties.xml</url>
    </lista_device>

Observed behavior

[[2024-04-23 10:18:12]] DEBUG:wd_fw_update.main:Namespace(loglevel=10)
[[2024-04-23 10:18:12]] INFO:wd_fw_update.main:Starting firmware update process.
Western Digital SSD Firmware Update Tool

[[2024-04-23 10:18:12]] DEBUG:wd_fw_update.main:Getting device list.
[[2024-04-23 10:18:12]] DEBUG:wd_fw_update.main:Only one device found: ['/dev/nvme0n1']

[[2024-04-23 10:18:12]] DEBUG:wd_fw_update.main:Getting device properties.
[[2024-04-23 10:18:12]] DEBUG:wd_fw_update.main:Getting firmware url.
[[2024-04-23 10:18:12]] DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): wddashboarddownloads.wdc.com:443
[[2024-04-23 10:18:12]] DEBUG:urllib3.connectionpool:https://wddashboarddownloads.wdc.com:443 "GET /wdDashboard/config/devices/lista_devices.xml HTTP/1.1" 200 45945
[[2024-04-23 10:18:12]] DEBUG:wd_fw_update.main:Firmware versions: f['620241WD']
[[2024-04-23 10:18:12]] DEBUG:wd_fw_update.main:Only one firmware to select, skipping user-promt.
[[2024-04-23 10:18:12]] DEBUG:wd_fw_update.main:Firmware Log for device:nvme0n1
afi  : 0x2
frs1 : 0x4457313133303236 (620311WD)
frs2 : 0x4457313633303236 (620361WD)

Current Active Firmware Slot (afi): 2
[[2024-04-23 10:18:12]] DEBUG:wd_fw_update.main:Firmware slots: ['1 : 0x4457313133303236 (620311WD)', '2 : 0x4457313633303236 (620361WD)']
Select the slot to which the firmware should be installed.
[?] Slot ID: Current Firmware Version: 
 > 1 : 0x4457313133303236 (620311WD)
   2 : 0x4457313633303236 (620361WD)

[?] Select update action, Mode 2 is recommended: 
 > 0 Downloaded image replaces the image indicated by the Firmware Slot field. This image is not activated.
   1 Downloaded image replaces the image indicated by the Firmware Slot field. This image is activated at the next reset.
   2 The image indicated by the Firmware Slot field is activated at the next reset.
   3 The image specified by the Firmware Slot field is requested to be activated immediately without reset.

[[2024-04-23 10:21:13]] DEBUG:wd_fw_update.main:Firmware properties url: https://wddashboarddownloads.wdc.com/wdDashboard/firmware/WD_BLACK_SN850X_2000GB/620241WD/device_properties.xml
[[2024-04-23 10:21:13]] DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): wddashboarddownloads.wdc.com:443
[[2024-04-23 10:21:13]] DEBUG:urllib3.connectionpool:https://wddashboarddownloads.wdc.com:443 "GET /wdDashboard/firmware/WD_BLACK_SN850X_2000GB/620241WD/device_properties.xml HTTP/1.1" 200 264
[[2024-04-23 10:21:13]] DEBUG:wd_fw_update.main:Firmware dependencies: ['620211WD']
Current firmware version is not in the dependencies.
Traceback (most recent call last):
  File "/root/wd-fw-update/bin/wd_fw_update", line 8, in <module>
    sys.exit(run())
             ^^^^^
  File "/root/wd-fw-update/lib64/python3.12/site-packages/wd_fw_update/main.py", line 508, in run
    main(sys.argv[1:])
  File "/root/wd-fw-update/lib64/python3.12/site-packages/wd_fw_update/main.py", line 498, in main
    wd_fw_update()
  File "/root/wd-fw-update/lib64/python3.12/site-packages/wd_fw_update/main.py", line 460, in wd_fw_update
    result = update_fw(
             ^^^^^^^^^^
  File "/root/wd-fw-update/lib64/python3.12/site-packages/wd_fw_update/main.py", line 335, in update_fw
    raise RuntimeError(f"Please upgrade to one of these versions first: {dependencies_list}")
RuntimeError: Please upgrade to one of these versions first: ['620211WD']

Expected behavior

A user friendly message saying that my firmware is already at the latest version available.

Somethink like the previous script that you wrote ?

# ./wd_ssd_fw_update.sh 
Model: WD_BLACK SN850X 2000GB
Firmware Revision: 620361WD

Already on latest firmware.

Thanks for your attention and the time you devote to the community ! 👏

not-a-feature commented 7 months ago

Hi,

First of all, I would like to thank you for this thorough report, it made debugging easy.

The error message is actually expected as upgrading to "620241WD" requires "620211WD" to be currently active / installed firmware. See dependency list

BUT: The tool should have prompted a selection between "620241WD" and "620361WD" as those are the currently supported versions:

<lista_device model="WD_BLACK SN850X 2000GB">
        <url>wdDashboard/firmware/WD_BLACK_SN850X_2000GB/620241WD/device_properties.xml</url>
        <url>wdDashboard/firmware/WD_BLACK_SN850X_2000GB/620361WD/device_properties.xml</url>
</lista_device>

For some reason it only detected the first one, thus skipping the selection.

[[2024-04-23 10:18:12]] DEBUG:wd_fw_update.main:Firmware versions: f['620241WD']

I've testes the parser and it works fine by prompting the selection of both versions. Nevertheless I've refactored the code s.t. it fails early and improved the error message.

I would be happy if you could upgrade to the new release v1.2.0 and report if the error persists.

nmasse-itix commented 7 months ago

I tested the latest release. Observed a change in the behavior: this time I did not had the choice of the slot nor the choice of the action. I am directly notified with the same error message.

$ sudo -i
# . wd-fw-update/bin/activate
# pip install --upgrade wd-fw-update
[...]
Downloading wd_fw_update-1.2.0-py3-none-any.whl (8.4 kB)
Installing collected packages: wd-fw-update
  Attempting uninstall: wd-fw-update
    Found existing installation: wd_fw_update 1.1.1
    Uninstalling wd_fw_update-1.1.1:
      Successfully uninstalled wd_fw_update-1.1.1
Successfully installed wd-fw-update-1.2.0

# wd_fw_update -vv
[[2024-04-23 12:48:30]] DEBUG:wd_fw_update.main:Namespace(loglevel=10)
[[2024-04-23 12:48:30]] INFO:wd_fw_update.main:Starting firmware update process.
Western Digital SSD Firmware Update Tool

[[2024-04-23 12:48:30]] DEBUG:wd_fw_update.main:Getting device list.
[[2024-04-23 12:48:30]] DEBUG:wd_fw_update.main:Only one device found: ['/dev/nvme0n1']

[[2024-04-23 12:48:30]] DEBUG:wd_fw_update.main:Getting device properties.
[[2024-04-23 12:48:30]] INFO:wd_fw_update.main:Model name: WD_BLACK SN850X 2000GB
[[2024-04-23 12:48:30]] DEBUG:wd_fw_update.main:Getting firmware url.
[[2024-04-23 12:48:30]] DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): wddashboarddownloads.wdc.com:443
[[2024-04-23 12:48:30]] DEBUG:urllib3.connectionpool:https://wddashboarddownloads.wdc.com:443 "GET /wdDashboard/config/devices/lista_devices.xml HTTP/1.1" 200 45945
[[2024-04-23 12:48:30]] DEBUG:wd_fw_update.main:Firmware versions: f['620241WD']
[[2024-04-23 12:48:30]] DEBUG:wd_fw_update.main:Only one firmware to select, skipping user-promt.
[[2024-04-23 12:48:30]] DEBUG:wd_fw_update.main:Firmware properties url: https://wddashboarddownloads.wdc.com/wdDashboard/firmware/WD_BLACK_SN850X_2000GB/620241WD/device_properties.xml
[[2024-04-23 12:48:30]] DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): wddashboarddownloads.wdc.com:443
[[2024-04-23 12:48:30]] DEBUG:urllib3.connectionpool:https://wddashboarddownloads.wdc.com:443 "GET /wdDashboard/firmware/WD_BLACK_SN850X_2000GB/620241WD/device_properties.xml HTTP/1.1" 200 264
[[2024-04-23 12:48:30]] DEBUG:wd_fw_update.main:Firmware dependencies: ['620211WD']
The current firmware version 620361WD is not in the dependency
list of the new firmware. In order to upgrade to 620241WD, please
upgrade to one of these versions first: ['620211WD']
not-a-feature commented 7 months ago

Then everything works as expected. But i need to adapt the error message / userflow to make it clearer. You are currently on fw version 620361WD which is together with 620241WD the currently supported version. As the function ask_fw_version filters out the current version (as updating to it would not change anything) 620361WD is not shown --> the promt is skipped.

(I overlooked that you are already on the newest version in my last message)

nmasse-itix commented 7 months ago

Thanks for your quick response and your help !

not-a-feature commented 7 months ago

TODO for me: