# Bootloader Update

The *PX4 Bootloader* is used to load firmware for [Pixhawk boards](https://px4.gitbook.io/px4-user-guide/drone_parts/flight_controller/pixhawk_series) (PX4FMU, PX4IO).

Pixhawk controllers usually comes with an appropriate bootloader version pre-installed. However in some case it is not present, or an older version is present that needs to be updated.

This topic explains several methods for updating the Pixhawk bootloader.

:::note A case where you may need to update Pixhawk boards that install FMUv2 firmware: [Firmware > FMUv2 Bootloader Update](https://px4.gitbook.io/px4-user-guide/config/firmware#bootloader). :::

## Building the PX4 Bootloader

Boards starting with FMUv6X (STM32H7) use the in-tree PX4 bootloader.

This can be built from within the PX4-Autopilot folder using the `make` command and the board-specific target with a `_bootloader` suffix. For FMUv6X the command is:

```
make px4_fmu-v6x_bootloader
```

This will build the bootloader binary as `build/px4_fmu-v6x_bootloader/px4_fmu-v6x_bootloader.elf`, which can be flashed via SWD or DFU. If you are building the bootloader you should be familiar with one of these options already.

If you need a HEX file instead of an ELF file, use objcopy:

```
arm-none-eabi-objcopy -O ihex build/px4_fmu-v6x_bootloader/px4_fmu-v6x_bootloader.elf px4_fmu-v6x_bootloader.hex
```

## Building the Legacy PX4 Bootloader

PX4 boards up to FMUv5X (before STM32H7) used a legacy [PX4 bootloader](https://github.com/PX4/Bootloader) repository.

Please refer to the instructions in the README to learn how to use it.

## QGC Bootloader Update

The easiest approach is to first use *QGroundControl* to install firmware that contains the desired/latest bootloader. You can then initiate bootloader update on next restart by setting the parameter: [SYS\_BL\_UPDATE](https://px4.gitbook.io/px4-user-guide/parameter_reference#SYS_BL_UPDATE).

:::note This approach can only be used if [SYS\_BL\_UPDATE](https://px4.gitbook.io/px4-user-guide/parameter_reference#SYS_BL_UPDATE) is present in firmware (currently just FMUv2 and some custom firmware). :::

The steps are:

1. Insert an SD card (enables boot logging to debug any problems).
2. [Update the Firmware](https://px4.gitbook.io/px4-user-guide/config/firmware#custom) with an image containing the new/desired bootloader.

   :::note The updated bootloader might be supplied in custom firmware (i.e. from the dev team), or it or may be included in the latest master. :::
3. Wait for the vehicle to reboot.
4. [Find and enable](https://px4.gitbook.io/px4-user-guide/advanced_config/parameters) the parameter [SYS\_BL\_UPDATE](https://px4.gitbook.io/px4-user-guide/parameter_reference#SYS_BL_UPDATE).
5. Reboot (disconnect/reconnect the board). The bootloader update will only take a few seconds.

Generally at this point you may then want to [update the firmware](https://px4.gitbook.io/px4-user-guide/config/firmware) again using the correct/newly installed bootloader.

An specific example of this process for updating the FMUv2 bootloader is given below.

### FMUv2 Bootloader Update

If *QGroundControl* installs the FMUv2 target (see console during installation), and you have a newer board, you may need to update the bootloader in order to access all the memory on your flight controller.

:::note Early FMUv2 [Pixhawk-series](https://px4.gitbook.io/px4-user-guide/drone_parts/flight_controller/pixhawk_series#fmu_versions) flight controllers had a [hardware issue](https://px4.gitbook.io/px4-user-guide/drone_parts/flight_controller/pixhawk_series/silicon_errata#fmuv2-pixhawk-silicon-errata) that restricted them to using 1MB of flash memory. The problem is fixed on newer boards, but you may need to update the factory-provided bootloader in order to install FMUv3 Firmware and access all 2MB available memory. :::

To update the bootloader:

1. Insert an SD card (enables boot logging to debug any problems).
2. [Update the Firmware](https://px4.gitbook.io/px4-user-guide/config/firmware) to PX4 *master* version (when updating the firmware, check **Advanced settings** and then select **Developer Build (master)** from the dropdown list). *QGroundControl* will automatically detect that the hardware supports FMUv2 and install the appropriate Firmware.

   ![FMUv2 update](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-4d441d163e44c358ee9026f5a4f3502a17d42e34%2Fbootloader_update.jpg?alt=media)

   Wait for the vehicle to reboot.
3. [Find and enable](https://px4.gitbook.io/px4-user-guide/advanced_config/parameters) the parameter [SYS\_BL\_UPDATE](https://px4.gitbook.io/px4-user-guide/parameter_reference#SYS_BL_UPDATE).
4. Reboot (disconnect/reconnect the board). The bootloader update will only take a few seconds.
5. Then [Update the Firmware](https://px4.gitbook.io/px4-user-guide/config/firmware) again. This time *QGroundControl* should autodetect the hardware as FMUv3 and update the Firmware appropriately.

   ![FMUv3 update](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-d7a36ae64b1daae61591ea6299881a980fad1f40%2Fbootloader_fmu_v3_update.jpg?alt=media)

   :::note If the hardware has the [Silicon Errata](https://px4.gitbook.io/px4-user-guide/drone_parts/flight_controller/pixhawk_series/silicon_errata#fmuv2-pixhawk-silicon-errata) it will still be detected as FMUv2 and you will see that FMUv2 was re-installed (in console). In this case you will not be able to install FMUv3 hardware. :::

## Dronecode Probe Bootloader Update

The following steps explain how you can "manually" update the bootloader using the dronecode probe:

1. Get a binary containing the bootloader (either from dev team or build it yourself).
2. Connect the Dronecode probe to your PC via USB.
3. Go into the directory containing the binary and run the following command in the terminal:

   ```bash
   arm-none-eabi-gdb px4fmuv5_bl.elf
   ```
4. The *gdb terminal* appears and it should display the following output:

   ```bash
   GNU gdb (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 8.0.50.20171128-git
   Copyright (C) 2017 Free Software Foundation, Inc.
   License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
   This is free software: you are free to change and redistribute it.
   There is NO WARRANTY, to the extent permitted by law.
   Type "show copying"    and "show warranty" for details.
   This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
   Type "show configuration" for configuration details.
   For bug reporting instructions, please see:
   <http://www.gnu.org/software/gdb/bugs/>.
   Find the GDB manual and other documentation resources online at:
   <http://www.gnu.org/software/gdb/documentation/>.
   For help, type "help".
   Type "apropos word" to search for commands related to "word"...
   Reading symbols from px4fmuv5_bl.elf...done.
   ```
5. Find your `<dronecode-probe-id>` by running an ls command in the **/dev/serial/by-id** directory.
6. Now connect to the Dronecode probe with the following command:

   ```bash
   tar ext /dev/serial/by-id/<dronecode-probe-id>
   ```
7. Power on the Pixhawk with another USB cable and connect the Dronecode probe to the FMU-DEBUG port.

   :::note To be able to connect the Dronecode probe to the FMU-DEBUG port, you may need to remove the case (e.g. on Pixhawk 4 you would do this using a T6 Torx screwdriver). :::
8. Use the following command to scan for the Pixhawk’s swd and connect to it:

   ```bash
   (gdb) mon swdp_scan
   (gdb) attach 1
   ```
9. Load the binary into the Pixhawk:

   ```bash
   (gdb) load
   ```

After the bootloader has updated you can [Load PX4 Firmware](https://px4.gitbook.io/px4-user-guide/config/firmware) using *QGroundControl*.

## Other Boards (Non-Pixhawk)

Boards that are not part of the [Pixhawk Series](https://px4.gitbook.io/px4-user-guide/drone_parts/flight_controller/pixhawk_series) will have their own mechanisms for bootloader update.

For boards that are preflashed with Betaflight, see [Bootloader Flashing onto Betaflight Systems](https://px4.gitbook.io/px4-user-guide/advanced_config/bootloader_update_from_betaflight).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://px4.gitbook.io/px4-user-guide/advanced_config/bootloader_update.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
