0001 .. SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
0002
0003 .. _devlink_flash:
0004
0005 =============
0006 Devlink Flash
0007 =============
0008
0009 The ``devlink-flash`` API allows updating device firmware. It replaces the
0010 older ``ethtool-flash`` mechanism, and doesn't require taking any
0011 networking locks in the kernel to perform the flash update. Example use::
0012
0013 $ devlink dev flash pci/0000:05:00.0 file flash-boot.bin
0014
0015 Note that the file name is a path relative to the firmware loading path
0016 (usually ``/lib/firmware/``). Drivers may send status updates to inform
0017 user space about the progress of the update operation.
0018
0019 Overwrite Mask
0020 ==============
0021
0022 The ``devlink-flash`` command allows optionally specifying a mask indicating
0023 how the device should handle subsections of flash components when updating.
0024 This mask indicates the set of sections which are allowed to be overwritten.
0025
0026 .. list-table:: List of overwrite mask bits
0027 :widths: 5 95
0028
0029 * - Name
0030 - Description
0031 * - ``DEVLINK_FLASH_OVERWRITE_SETTINGS``
0032 - Indicates that the device should overwrite settings in the components
0033 being updated with the settings found in the provided image.
0034 * - ``DEVLINK_FLASH_OVERWRITE_IDENTIFIERS``
0035 - Indicates that the device should overwrite identifiers in the
0036 components being updated with the identifiers found in the provided
0037 image. This includes MAC addresses, serial IDs, and similar device
0038 identifiers.
0039
0040 Multiple overwrite bits may be combined and requested together. If no bits
0041 are provided, it is expected that the device only update firmware binaries
0042 in the components being updated. Settings and identifiers are expected to be
0043 preserved across the update. A device may not support every combination and
0044 the driver for such a device must reject any combination which cannot be
0045 faithfully implemented.
0046
0047 Firmware Loading
0048 ================
0049
0050 Devices which require firmware to operate usually store it in non-volatile
0051 memory on the board, e.g. flash. Some devices store only basic firmware on
0052 the board, and the driver loads the rest from disk during probing.
0053 ``devlink-info`` allows users to query firmware information (loaded
0054 components and versions).
0055
0056 In other cases the device can both store the image on the board, load from
0057 disk, or automatically flash a new image from disk. The ``fw_load_policy``
0058 devlink parameter can be used to control this behavior
0059 (:ref:`Documentation/networking/devlink/devlink-params.rst <devlink_params_generic>`).
0060
0061 On-disk firmware files are usually stored in ``/lib/firmware/``.
0062
0063 Firmware Version Management
0064 ===========================
0065
0066 Drivers are expected to implement ``devlink-flash`` and ``devlink-info``
0067 functionality, which together allow for implementing vendor-independent
0068 automated firmware update facilities.
0069
0070 ``devlink-info`` exposes the ``driver`` name and three version groups
0071 (``fixed``, ``running``, ``stored``).
0072
0073 The ``driver`` attribute and ``fixed`` group identify the specific device
0074 design, e.g. for looking up applicable firmware updates. This is why
0075 ``serial_number`` is not part of the ``fixed`` versions (even though it
0076 is fixed) - ``fixed`` versions should identify the design, not a single
0077 device.
0078
0079 ``running`` and ``stored`` firmware versions identify the firmware running
0080 on the device, and firmware which will be activated after reboot or device
0081 reset.
0082
0083 The firmware update agent is supposed to be able to follow this simple
0084 algorithm to update firmware contents, regardless of the device vendor:
0085
0086 .. code-block:: sh
0087
0088 # Get unique HW design identifier
0089 $hw_id = devlink-dev-info['fixed']
0090
0091 # Find out which FW flash we want to use for this NIC
0092 $want_flash_vers = some-db-backed.lookup($hw_id, 'flash')
0093
0094 # Update flash if necessary
0095 if $want_flash_vers != devlink-dev-info['stored']:
0096 $file = some-db-backed.download($hw_id, 'flash')
0097 devlink-dev-flash($file)
0098
0099 # Find out the expected overall firmware versions
0100 $want_fw_vers = some-db-backed.lookup($hw_id, 'all')
0101
0102 # Update on-disk file if necessary
0103 if $want_fw_vers != devlink-dev-info['running']:
0104 $file = some-db-backed.download($hw_id, 'disk')
0105 write($file, '/lib/firmware/')
0106
0107 # Try device reset, if available
0108 if $want_fw_vers != devlink-dev-info['running']:
0109 devlink-reset()
0110
0111 # Reboot, if reset wasn't enough
0112 if $want_fw_vers != devlink-dev-info['running']:
0113 reboot()
0114
0115 Note that each reference to ``devlink-dev-info`` in this pseudo-code
0116 is expected to fetch up-to-date information from the kernel.
0117
0118 For the convenience of identifying firmware files some vendors add
0119 ``bundle_id`` information to the firmware versions. This meta-version covers
0120 multiple per-component versions and can be used e.g. in firmware file names
0121 (all component versions could get rather long.)