# Building and Flashing PX4 Firmware

### Preparations

In order to build PX4 locally, you first need to [set up the PX4 toolchain](https://docs.px4.io/main/en/dev_setup/dev_env.html#setting-up-a-developer-environment-toolchain).

### Customizing Auterion PX4 (APX4)

{% hint style="warning" %}
SLA required to get access to source code
{% endhint %}

Please contact <success@auterion.com> to get access to the APX4 repository.

### Work with open source PX4

Open source ("upstream") PX4 will generally work on Skynodes, with the following caveats:

* Configuration and drivers for components of your exact product may not be present. You may encounter missing configuration or functionality for ESCs, batteries, sensors, and so on.
* Some parameters might have different default values compared to APX4 releases.
* Features accessed by vendor-specific customizations running on the companion computer may not be present in PX4.
* Upstream PX4 is not supported on Skynode S.

### Building and uploading Firmware

PX4 firmware binaries can be built with the PX4 developer environment and uploaded to Skynode via USB or Wi-Fi (if available).

{% hint style="info" %}
SSH and TAR are needed to use these upload targets, but are expected to be present by default on Ubuntu and Ubuntu running on Windows in WSL2. On macOS you should first install [gnu-tar](https://formulae.brew.sh/formula/gnu-tar).
{% endhint %}

If not already present, get the PX4 source code using the command:

```bash
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
cd PX4-Autopilot
```

Then build and upload the binary using the matching command for your hardware and connection. You will need to enter the password for the Skynode developer image twice during upload.

#### Skynode ENT/GOV

{% tabs %}
{% tab title="Skynode connected via USB" %}

```bash
make px4_fmu-v5x upload_skynode_usb
```

{% endtab %}

{% tab title="Skynode connected via WiFi" %}

```bash
make px4_fmu-v5x upload_skynode_wifi
```

{% endtab %}
{% endtabs %}

#### Skynode X/GX

{% tabs %}
{% tab title="Skynode connected via USB" %}

```bash
make auterion_fmu-v6x upload_skynode_usb
```

{% hint style="info" %}
For Auterion PX4 3.3 based releases the previous target name has to be used:

```bash
make px4_fmu-v6x upload_skynode_usb
```

{% endhint %}
{% endtab %}

{% tab title="Skynode connected via WiFi" %}

```bash
make auterion_fmu-v6x upload_skynode_wifi
```

{% hint style="info" %}
For Auterion PX4 3.3 based releases the previous target name has to be used:

```bash
make px4_fmu-v6x upload_skynode_usb
```

{% endhint %}
{% endtab %}
{% endtabs %}

#### Skynode S

{% tabs %}
{% tab title="Skynode connected via USB" %}

```bash
make auterion_fmu-v6s upload_skynode_usb
```

{% hint style="info" %}
For Auterion PX4 3.2 based releases the previous target name has to be used:

```bash
make px4_fmu-v6s upload_skynode_usb
```

{% endhint %}
{% endtab %}
{% endtabs %}

### Restoring the Default Skynode APX4 Firmware

To reinstall the original version of Auterion PX4 that shipped with your Auterion OS release, run the following command in the root of the PX4 repository:

{% tabs %}
{% tab title="Skynode connected via USB" %}

<pre class="language-bash"><code class="lang-bash"><strong>./Tools/auterion/upload_skynode.sh --revert
</strong></code></pre>

{% hint style="info" %}
For Auterion PX4 3.1 and 3.2 based releases the command is:

```bash
./Tools/auterion/ssh_upload.sh --revert
```

{% endhint %}
{% endtab %}

{% tab title="Skynode connected via WiFi" %}

```bash
./Tools/auterion/upload_skynode.sh --revert --wifi
```

{% hint style="info" %}
For Auterion PX4 3.1 and 3.2 based releases the command is:

```bash
./Tools/auterion/ssh_upload.sh --revert --wifi
```

{% endhint %}
{% endtab %}
{% endtabs %}
