# `NervesSystemArduinoUnoQ.QDL`
[🔗](https://github.com/jimsynz/nerves_system_arduino_uno_q/blob/v0.1.1/lib/nerves_system_arduino_uno_q/qdl.ex#L1)

Builds a Qualcomm EDL (QDL) flash directory that provisions an Arduino UNO Q
with Nerves.

It starts from Arduino's eMMC bootloader bundle, keeps Qualcomm's partitions
1 to 66 and their boot firmware, replaces the last partitions of the GPT with
the Nerves layout and writes the Nerves firmware into them.

The Nerves firmware is written as regions cut from a disk image produced by
`fwup -t complete`, so fwup stays the only thing that knows how to lay out a
firmware update.

# `partition`

```elixir
@type partition() ::
  {pos_integer(), String.t(), String.t(), non_neg_integer(),
   pos_integer() | :rest}
```

The Nerves partitions as `{number, name, type GUID, first LBA, size}`

# `entry_position`

```elixir
@spec entry_position(pos_integer()) :: {non_neg_integer(), non_neg_integer()}
```

The sector within the partition array and byte offset of a partition's entry.

# `gpt`

```elixir
@spec gpt(binary(), binary()) :: {binary(), binary()}
```

Replaces Arduino's last partitions in its primary and backup GPT images with
the Nerves partitions. Header and partition array CRCs are fixed up by
`patch0.xml` while flashing, once the eMMC size is known.

# `image_slices`

```elixir
@spec image_slices() :: [{String.t(), non_neg_integer(), pos_integer()}]
```

The regions of the fwup image that get written to the eMMC.

# `partitions`

```elixir
@spec partitions() :: [partition()]
```

The Nerves partitions at the end of the GPT.

# `patch`

```elixir
@spec patch(String.t()) :: String.t()
```

Generates `patch0.xml` from Arduino's, pointing its "last partition" fix-ups
at the Nerves data partition instead of `userdata`.

# `rawprogram`

```elixir
@spec rawprogram(String.t()) :: String.t()
```

Generates `rawprogram0.xml` from Arduino's: Qualcomm's boot firmware and the
GPT as before, then the Nerves image slices instead of Arduino's U-Boot,
`efi`, `rootfs` and `userdata`.

# `write_flash_dir`

```elixir
@spec write_flash_dir(Path.t(), Path.t(), Path.t()) :: :ok
```

Writes a QDL flash directory to `out_dir`.

`bootloader_dir` is the extracted Arduino bootloader bundle and `image` is the
disk image from `fwup -t complete`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
