Most D-Link devices have an emergency recovery mode embedded on the bootloader. This recovery mode provides a basic web page that allows flashing a new firmware even when the device is bricked, which is very handy not only for recovering from bricks but also to install OpenWrt on supported D-Link devices. The emergency recovery mode is normally accessed by holding the reset button for a few seconds while powering up the device.
Before following the steps below, make sure you already have a local copy of the firmware file you want to flash, as you won't have any kind of internet connectivity while the device is in the emergency recovery mode. If the file you want to flash is from the stock firmware, make sure it is unencrypted (refer to the section below for more details). Also, the computer you'll use to access the recovery mode must be directly plugged to one of the LAN ports of the device.
curl -v -i -F "firmware=@my_firmware_file.bin" 192.168.0.1
Starting from 2018, D-Link added a layer of encryption to its stock firmware files. Most firmware updates published since then, both for new and for existing D-Link devices, are available only on this encrypted format, generally referenced as D-Link SHRS format. Although the stock firmware from D-Link can flash these SHRS files without issues, the emergency recovery mode from the bootloader only recognizes unencrypted firmware files, actively refusing SHRS firmware files if you try to flash them.
For some devices (like the DIR-878 and DIR-882), older firmware versions, from before the encryption was added, are often obtainable in unencrypted format directly from D-Link Support, and these can be flashed in emergency recovery mode without issues if you ever need to recover from a brick or want to go back from OpenWrt to the stock firmware.
For newer devices, however, this isn't an option, as only encrypted SHRS firmwares are publicly available. If you own one of these devices and needs the firmware in unencrypted format to use with the emergency recovery mode, you'll have to resort to tools like dlink-decrypt in order to manually decrypt the SHRS firmwares provided by D-Link.
As of November 2020, dlink-decrypt seems to successfully decrypt the stock firmware files of all devices currently using the D-Link SHRS format.
Devices listed on this table have the emergency recovery mode on their bootloaders and are able to use this recovery method not only to recover from bricks but also to install OpenWrt and even to go back to the stock firmware (as long as an unencrypted firmware file is provided).