| 1 | # MAOS OTA |
| 2 | |
| 3 | How over-the-air updates flow. There are no standalone OTA scripts in this |
| 4 | directory: building and publishing OTAs is the `release` and `publish` phases |
| 5 | of `../build-maos.sh`. |
| 6 | |
| 7 | ## Pipeline |
| 8 | |
| 9 | ``` |
| 10 | build-maos.sh build ──▶ target-files ──release──▶ signed OTA zip + factory image |
| 11 | │ |
| 12 | publish (per device) |
| 13 | ▼ |
| 14 | Cloudflare R2 bucket `maos` |
| 15 | │ |
| 16 | ota.maproj.org (custom domain) |
| 17 | │ |
| 18 | ▼ |
| 19 | MA Updater on device |
| 20 | ``` |
| 21 | |
| 22 | - **`release`** signs the staged target-files with the MAOS key set and |
| 23 | generates the factory image + full OTA zip (`script/generate-release.sh` |
| 24 | in the AOSP tree). |
| 25 | - **`publish`** uploads the OTA zip first with an immutable cache header, |
| 26 | then the `<device>-<channel>` metadata file with `no-store`, so a device |
| 27 | polling mid-publish never sees metadata referencing a zip that isn't |
| 28 | there yet. It also prepares/uploads the web-installer factory artifacts |
| 29 | via `../installer/prepare-factory.sh`. |
| 30 | - **`ota.maproj.org`** is the R2 bucket `maos` exposed via a Cloudflare |
| 31 | custom domain: an object keyed `<file>` is served at |
| 32 | `https://ota.maproj.org/<file>`. Devices download straight from R2 — no |
| 33 | GitHub Release and no server proxy are involved. |
| 34 | - The **MA Updater** app polls `https://ota.maproj.org/<device>-<channel>` |
| 35 | (from `ro.maos.ota.server`; see `../updater/README.md`). |
| 36 | |
| 37 | ## Credentials (never commit) |
| 38 | |
| 39 | The `publish` phase reads R2 credentials from the environment: |
| 40 | |
| 41 | | Var | Meaning | |
| 42 | | --- | --- | |
| 43 | | `R2_ACCOUNT_ID` | Cloudflare account id (builds the R2 endpoint) | |
| 44 | | `R2_ACCESS_KEY_ID` | R2 API token access key id | |
| 45 | | `R2_SECRET_ACCESS_KEY` | R2 API token secret | |
| 46 | |
| 47 | The bucket is fixed to `maos` in `build-maos.sh`. Create the API token in |
| 48 | the Cloudflare dashboard (R2 → Manage API Tokens) with **Object Read & |
| 49 | Write** on that bucket. |
| 50 | |
| 51 | ## Cloudflare setup (one-time) |
| 52 | |
| 53 | 1. Create the R2 bucket `maos`. |
| 54 | 2. Attach the custom domain `ota.maproj.org` to it (R2 → Settings → Custom |
| 55 | Domains). Cloudflare provisions TLS automatically. |
| 56 | 3. Add a bucket CORS policy so the installer page (`ma.vayunmathur.com`) |
| 57 | can fetch factory images (see `../docs/BUILD_RUNBOOK.md`). |
| 58 | 4. Add a Cache Rule that bypasses cache for the channel-metadata files |
| 59 | (paths not ending in `.zip`) so devices never see a stale build pointer. |
| 60 | |
| 61 | See `../docs/BUILD_RUNBOOK.md` for the full build → sign → OTA → publish |
| 62 | sequence. |