How to flash your BIOS on a HP Laptop

Having a HP Laptop for a while now, I was confronted with the challenge of updating its BIOS without having a Windows OS at hand. Searching through WWW didn't bring satisfying results at all. There was not a single howto that helped me to sucessfully updating my Laptop's BIOS.
What I found instead was a Website from HP that provides tools for Linux to flash the BIOS of your HP Laptop.
Unfortunately, HP only provides the BIOS file inside of a Windows .exe file - at least fo my Laptop model. So in order to get the real BIOS binary, you first need to extract that binary out of the .exe file. I found the 7z tool from p7zip to be of good help here.

If you happen to be using Gentoo, you are lucky because you can simply use the Gentoo packages I created to install the HP tools that are required for flashing the BIOS. Simply add my overlay and run the following:
emerge -anv app-arch/p7zip sys-apps/hp-flash

Non-Gentoo Linux users need to install the tools by themselves. This is explained quite thoroughly on the HP Website I linked to above so I won't go into details about this here.

Once you have downloaded the correct firmware .exe file from HP, you need to extract the .bin firmware image file:
mkdir hp_bios
cd hp_bios
7z e /path/to/the/downloaded/hp_firmware.exe

Now you should have the firmware image binary file. For my laptop its name is something like VXX_XXXXXXXX.bin where X needs to be replaced with digits.
Next step is to load the hpuefi module which is required to flash the BIOS to HP's UEFI system:
modprobe hpuefi

Create the device node that is needed to communicate with hpuefi module. When using my Gentoo packages, you can find the script that creates the node in /opt/hp/hp-flash:
bash /opt/hp/hp-flash/mkdevhpuefi

Now you can finally flash your BIOS. Keep in mind, when you have locked your BIOS with a password, you need to give that password to hp-flash as well. If you haven't set a password in your BIOS, simply omit the -p option:
/opt/hp/hp-flash/bin/hp-flash -p "yoursupersecretBIOSpassword" VXX_XXXXXXXX.bin

Do NOT turn off your laptop until the flashing procedure has finished. Once the flash process has sucessfully finished, reboot your device. And don't be surprised if your laptop turns off even though you wanted it to reboot. It seems like HP devices prefer to shut off once they got a new BIOS image flashed. Just switch the device back on and let it apply the freshly flashed BIOS image.