Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions docs/internals/installer.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ the others' recorded progress (the install starts afresh after a restore).
| Upgrade | Prepare the upgrade | the install's images from the backup; Valve's kernel and the boot image are made every time | not needed |
| Upgrade | Install the upgrade | an action ask without a row, answered before the start unless the look finds the headset there (switched on, on the cable); `dev flash` and `dev connect` as one task (this version's overpressure's recovery into `recovery`, whose tools the build and the write need), `dev install --only build` (the recovery builds on the data partition; data kept) and `--only start` (the build folder removed at the end); its page offers *Check the headset* too | installed system, fastboot, overpressure's recovery |
| Check | Check the headset | an action ask without a row, answered before the start: the headset on a stable table, its front cameras facing the room, the controllers on beside it if wanted, untouched until the last check; `dev installed`; `dev check --installer --part system`, `--part imu` and `--part session`, each its own task (controllers SteamVR does not see, missed performance limits, and a headset that moved during each of three IMU measurements 10 s apart are a warning in the window, not a failure; everything else counts as in `dev check`); the finished page says when they are done | installed system, on the cable |
| Restore | Check the backup | `tools`; `device verify-backup` of `PICO4_BACKUP`, which must be the headset `PICO4_IDENTITY` describes, and of the build PICO OS runs when it answers (another build's backup would put its system next to this build's firmware) | not needed |
| Restore | Check the backup | `tools`, `device fetch-unlock-files` (the backup over EDL needs the loader, its debug start the engineering ABL); `device verify-backup` of `PICO4_BACKUP`, which must be the headset `PICO4_IDENTITY` describes, and of the build PICO OS runs when it answers (another build's backup would put its system next to this build's firmware) | not needed |
| Restore | Restore PICO OS | one consent (it erases the system and its data), the choice *Keep USB debugging on in PICO OS* (a checkbox, off by default) and an action ask, all answered before the start, without a row of their own (the action not asked when the look finds the headset there); a headset that answers `adb devices` with its serial runs PICO OS already and is left alone, any other is taken into overpressure's recovery by the installer itself (`dev recovery`'s steps), then one task per part, `dev restore --installed --only system --debug-start`, `data` and `recovery` ([back to stock](#back-to-stock), [the debug start](#the-debug-start)): a retry goes on from the part that failed. A headset found in EDL mode gets *Your backup over EDL* instead, `cycle --restore-all` ([below](#the-whole-backup-over-edl)), which also writes its stock bootloader; one another computer installed goes through overpressure's recovery ([below](#a-headset-another-computer-installed)) | overpressure's recovery, fastboot, EDL |
| Restore | Back to PICO OS | *Wait for PICO OS's first start*, with nothing for the owner to do and no instruction shown (its progress says what it waits for): the debug start answers adb with nobody at the headset, also after *Your backup over EDL*, which writes it too (only where PICO OS's boot has no debug start does the owner turn developer mode and USB debugging on); exactly one `adb devices` entry, written to `PICO4_ADB_SERIAL`; then the wait for PICO OS's MCU check ([cooling.md](cooling.md#an-mcu-that-answers-f1)), shown as the task's progress; with the choice ticked, once PICO OS has finished starting (`sys.boot_completed`), USB debugging stored through the vendor's USB property, with no restart of adb. Then *Write the stock bootloader*, `cycle --restore-only`: boot read back whole and the backup's written back where it differs (the debug start's), stock ABL written back, then PICO OS waited for with or without USB debugging; *Finish the restore* switches USB debugging off as its own switch does, or, with the choice ticked, checks that it stayed on; it notes only what went otherwise than chosen, and the finished page says the end. The bootloader stays unlocked | PICO OS |

Expand Down Expand Up @@ -234,7 +234,7 @@ setting changes. So at the end the installer switches it off as PICO OS's own sw
(`settings put global adb_enabled 0`), or, when the owner ticked *Keep USB debugging on in PICO OS*, stores
USB debugging for every later start in the debug start and checks at the end that adb still answers. It switches
developer mode on and sets the vendor's USB property again (`setprop persist.vendor.usb.config mtp,adb`, then
`sync`): the vendor's init copies it to `persist.sys.usb.config`, the USB functions the framework starts with, and
`sync`), which SELinux allows adb's shell only under the engineering ABL, where PICO OS starts permissive: the vendor's init copies it to `persist.sys.usb.config`, the USB functions the framework starts with, and
init stores what it sets in `persist.` once the stored properties are loaded, which the debug start's own values
were not. PICO OS's switch in Developer settings cannot do this over adb: its off stops adbd, and with it every
process adb started (they share adbd's cgroup), before its on comes; sent together, the framework sees only the
Expand Down Expand Up @@ -285,9 +285,13 @@ the headset on the cable may start in PICO OS's charger mode; holding the power

The installer's restore runs it as `cycle --restore-all --debug-start` where PICO OS's boot image has a debug start
([the debug start](#the-debug-start)): `boot` gets the debug start's image instead of the backup's (`device restore-all
--image boot=FILE`, padded to the partition and read back as every other write), so PICO OS's first start answers adb
with USB debugging on, the owner's choice of USB debugging is stored then, and *Write the stock bootloader* writes the
backup's boot back, as after the restore through overpressure's recovery.
--image boot=FILE`, padded to the partition and read back as every other write), and `abl` the engineering ABL instead
of the stock one (`--image abl=FILE`, checked against `PICO4_ENGINEERING_ABL_SHA256` first). So PICO OS's first start
answers adb with USB debugging on, under the bootloader the restore through overpressure's recovery leaves for it, the
owner's choice of USB debugging is stored then, and *Write the stock bootloader* writes the backup's boot and ABL back,
as after the restore through overpressure's recovery. Under the stock ABL PICO OS starts with SELinux enforcing, which
refuses adb's shell the vendor's USB property (`avc: denied { set } … vendor_usb_prop`); under the engineering ABL it
starts permissive, and the property is stored.

### Without a backup: the rescue

Expand Down
28 changes: 27 additions & 1 deletion tests/installer/test_headset.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,19 @@ def test_the_whole_backup_goes_back_in_the_first_session_after_edl_by_hand(self)
cycle.pass_progress("edl-ng: 12345 sectors written")
self.assertEqual(out.getvalue().splitlines(), ["progress 42.0%: writing super (LUN 0)"])

def engineering_abl(self, expected: bytes = b"engineering abl") -> Path:
"""Put an engineering ABL in place; .env's hash is @p expected's (another file's: a mismatch)."""
abl = self.root / "engineering-abl.elf"
abl.write_bytes(b"engineering abl")
self.settings.engineering_abl = str(abl)
self.settings.engineering_abl_sha256 = hashlib.sha256(expected).hexdigest()
return abl

def test_the_whole_backup_can_start_pico_os_with_its_debug_start(self):
# #172: under the stock ABL PICO OS's SELinux refuses adb's shell the vendor's USB property; the first start
# runs under the engineering ABL, as after the restore through overpressure's recovery.
self.edl = 1
abl = self.engineering_abl()
first = self.folder / "first-start-boot.img"
with (
contextlib.redirect_stdout(io.StringIO()),
Expand All @@ -269,13 +280,28 @@ def test_the_whole_backup_can_start_pico_os_with_its_debug_start(self):
self.make().restore_all(debug_start=True)
build.assert_called_once()
command = next(w for w in self.calls if "restore-all" in w)
self.assertEqual(command[command.index("--image") + 1], f"boot={first}")
images = [command[i + 1] for i, word in enumerate(command) if word == "--image"]
self.assertEqual(images, [f"boot={first}", f"abl={abl}"])
self.calls.clear()
self.edl = 1 # the reset took it out of EDL mode
with contextlib.redirect_stdout(io.StringIO()):
self.make().restore_all()
self.assertNotIn("--image", next(w for w in self.calls if "restore-all" in w)) # the backup's own boot

def test_the_debug_start_writes_nothing_without_the_engineering_abl(self):
self.edl = 1
for abl in (None, self.engineering_abl(b"another file")):
if abl is None:
self.settings.engineering_abl = str(self.root / "missing.elf")
with (
contextlib.redirect_stdout(io.StringIO()),
patch.object(cycle.debugstart, "build") as build,
self.assertRaisesRegex(RuntimeError, "nothing was written"),
):
self.make().restore_all(debug_start=True)
build.assert_not_called()
self.assertEqual(self.calls, [])

def test_the_whole_backup_waits_for_the_headset_in_edl_and_writes_nothing_without_it(self):
self.edl = 0
with contextlib.redirect_stdout(io.StringIO()), self.assertRaisesRegex(RuntimeError, "nothing was written"):
Expand Down
7 changes: 6 additions & 1 deletion tests/installer/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ def test_the_restore_asks_once_and_writes_only_after_the_backup_is_checked(self)
writes, ["restore-all", "system", "data", roles.STOCK_RECOVERY, "bootloader-first", "restore-abl"]
)
ids = [t.id for t in tasks]
# The backup over EDL needs the loader, and its debug start the engineering ABL (#172), before any write.
self.assertEqual([t.id for t in stages[0].tasks], ["tools", "unlock-files", "verify-backup"])
self.assertLess(ids.index("verify-backup"), ids.index("consent"))
self.assertLess(ids.index("consent"), ids.index(roles.START_RECOVERY))
self.assertLess(ids.index(roles.START_RECOVERY), ids.index("system"))
Expand Down Expand Up @@ -884,7 +886,10 @@ def test_a_headset_found_in_edl_gets_its_whole_backup_over_edl_instead_of_the_ot
restore = self.plan
self.assertEqual(restore.EDL_RESTORE, texts.EDL_RESTORE)
tasks = {t.id: t for s in restore.restore_stages() for t in s.tasks}
done = {key: check(ctx) for key, task in tasks.items() if (check := task.done) is not None}
# The unlock files' check reads this computer's files: not a headset's route.
done = {
key: check(ctx) for key, task in tasks.items() if (check := task.done) is not None and key != "unlock-files"
}
self.assertFalse(done["restore-all"])
for key in (roles.START_RECOVERY, "system", "data", roles.STOCK_RECOVERY, "bootloader-first", "restore-abl"):
self.assertTrue(done[key], key)
Expand Down
15 changes: 11 additions & 4 deletions tooling/development/cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ def restore_all(self, *, debug_start: bool = False) -> None:
"""Write the whole backup back over EDL (device restore-all), then reset the headset into PICO OS's first setup.

With @p debug_start the boot partition gets PICO OS's debug start instead of the backup's boot image
(tooling/stock/debugstart.py): its first start answers adb with USB debugging on, as after the restore
through overpressure's recovery, and the restore's bootloader step writes the backup's boot back.
(tooling/stock/debugstart.py) and abl the engineering ABL instead of the stock one: its first start answers
adb with USB debugging on, under the bootloader the restore through overpressure's recovery leaves for it,
whose SELinux lets adb's shell store USB debugging (the stock one's refuses it); the restore's bootloader
step writes the backup's boot and ABL back.

For a headset no bootloader starts any more, in EDL mode entered by hand. The device command opens the
first session after that, whose handshake names the serial, and checks it before anything is written:
Expand All @@ -427,10 +429,15 @@ def restore_all(self, *, debug_start: bool = False) -> None:
print(">> the whole backup written back over EDL", flush=True)
images: list[str | Path] = []
if debug_start:
self.s.require("engineering_abl_sha256")
abl = self.s.path("engineering_abl")
if not abl.is_file() or backups.digest(abl)["sha256"] != self.s.engineering_abl_sha256.lower():
msg = f"{abl} is not the engineering ABL (fetch-unlock-files); nothing was written"
raise RuntimeError(msg)
stock, _boot = backups.verified_partition(self.s.path("backup"), "boot")
first = debugstart.build(self.s.path("backup"), stock, self.folder / debugstart.IMAGE)
images = ["--image", f"boot={first}"]
print(">> PICO OS's first start: its debug start, USB debugging on", flush=True)
images = ["--image", f"boot={first}", "--image", f"abl={abl}"]
print(">> PICO OS's first start: its debug start under the engineering ABL, USB debugging on", flush=True)
if self.edl_count() != 1:
msg = (
"the headset is not the one device in EDL mode: hold both volume buttons while plugging USB into "
Expand Down
19 changes: 14 additions & 5 deletions tooling/installer/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,18 @@ def restore_stages(self) -> tuple[Stage, ...]:
Stage(
"backup",
"Check the backup",
"The host tools, then every file of your headset's backup is checked against its manifest. The "
"headset is not needed yet.",
"The host tools and the unlock files, then every file of your headset's backup is checked against "
"its manifest. The headset is not needed yet.",
(
self.tools_task(),
# The backup over EDL needs the loader, and its debug start the engineering ABL (restore_all).
self.step_task(
"unlock-files",
"Download the unlock files",
"about 2 min",
done=self.unlock_files_there,
where=texts.UNCHANGED,
),
Task("verify-backup", "Check the backup", self.check_backup, "about 5 min", where=texts.UNCHANGED),
),
),
Expand Down Expand Up @@ -831,9 +839,10 @@ def debug_started(ctx: Context) -> bool:
def restore_everything(self, ctx: Context) -> None:
"""Write the whole backup over EDL, PICO OS's first start a debug start where its boot image has one.

As through overpressure's recovery (restore_system): PICO OS's first start answers adb by itself, the
owner's USB debugging choice is stored then, and the bootloader step writes the backup's boot back. A boot
image without one starts PICO OS the stock way, recorded, and the owner turns USB debugging on.
As through overpressure's recovery (restore_system): PICO OS's first start answers adb by itself, under the
engineering ABL, whose SELinux lets the owner's USB debugging choice be stored then (cycle.restore_all), and
the bootloader step writes the backup's boot and ABL back. A boot image without one starts PICO OS the stock
way, recorded, and the owner turns USB debugging on.
"""
_path, boot = backups.verified_partition(ctx.settings(Settings).path("backup"), "boot")
debug = debugstart.supported(boot)
Expand Down
6 changes: 4 additions & 2 deletions tooling/stock/debugstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
The image here is the backup's own boot image with those three files added: the properties turn adb on without an
authorization (the USB functions mtp,adb, which the vendor's init also copies to the framework's setting, and
ro.adb.secure 0); the policy is PICO OS's own platform policy, unchanged, so the start keeps the stock rules. The
engineering bootloader, under which the restore starts PICO OS first, starts it unlocked. The restore's bootloader
step writes the backup's boot image back (cycle --restore-only).
engineering bootloader, under which the restore starts PICO OS first (also over EDL: cycle.restore_all), starts it
unlocked and with SELinux permissive, which lets adb's shell set the vendor's USB property (SWITCH_ON); under the
stock bootloader SELinux enforces and refuses it. The restore's bootloader step writes the backup's boot image and
stock bootloader back (cycle --restore-only).

Nothing of it is kept: the properties are read at start-up only, and the framework stores no setting it did not
change. Setting the vendor's USB property again once PICO OS has started is what keeps USB debugging on
Expand Down