# `mix openwrt_one.firmware_post`
[🔗](https://github.com/Hermanverschooten/nerves_system_openwrt_one/blob/v0.5.2/lib/mix/tasks/openwrt_one.firmware_post.ex#L1)

Post-process a `mix firmware` .fw so it ships the correct
user-merged initramfs/UBI rather than the system-only versions
baked in at system build time.

Designed to be chained after `firmware` via a mix alias:

    defp aliases do
      [
        firmware: ["firmware", "openwrt_one.firmware_post"]
      ]
    end

With the alias in place:

  * `mix firmware` produces a `.fw` whose `data/openwrt-one-initramfs.itb`
    and `data/openwrt-one-nand.ubi` are derived from the .fw's own
    combined squashfs — i.e. they contain `/srv/erlang`.
  * `mix burn` works directly: fwup writes the spliced UBI to the
    recovery USB stick, so the first boot after the USB dance finds
    the Erlang release.
  * `mix upload` can extract `data/openwrt-one-initramfs.itb` straight
    out of the `.fw` (no on-the-fly rebuild needed).

Without the alias, `mix firmware` ships the stale system-only
resources and the device boots with `erlinit: No release found in
/srv/erlang.`

## What it does

  1. Calls `scripts/wrap-firmware.sh` from the system, which extracts
     the .fw's squashfs, unsquashes it, repacks as cpio.gz, and runs
     `mkimage` + `ubinize` to produce a fresh `.itb` and `.ubi`.
  2. Replaces `data/openwrt-one-initramfs.itb` and
     `data/openwrt-one-nand.ubi` inside the .fw zip with those fresh
     artifacts.
  3. Rewrites the matching `length` and `blake2b-256` entries in
     `meta.conf` so fwup's integrity check still passes.
  4. Preserves the original zip entry ordering (fwup expects
     resources to appear in the order their `on-resource` clauses
     are declared).

## Requirements

  * `b2sum` (GNU coreutils ≥ 8.26) — `apt install coreutils` on
    Linux, `brew install coreutils` on macOS (binary is `gb2sum`).
  * Everything `scripts/wrap-firmware.sh` needs: `unzip`,
    `unsquashfs`, `cpio`, `gzip`, `mkimage`, `dtc`, `ubinize`.

---

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