From 01d7be06ec559922be32a0a218f335da572bf07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Tue, 1 Dec 2026 15:13:17 +0100 Subject: [PATCH 1/7] Installer: with the device named, other devices don't hold it up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the device named (--ecid, --location), the installer still waited for other Apple devices to go: a second phone running iOS held up a launch by the ibss route, and a device elsewhere running m1n1 or an installed system held up any run. People who work on several devices keep them plugged in. With the target named, the driver no longer lists other devices as in the way, and a device elsewhere in m1n1 or Linux doesn't count as another device: palera1n and checkra1n only take devices in DFU, recovery, Pongo or iOS, and everything of ours follows the target by its ECID or port. What can't be addressed is guarded where it runs (palera1n's start, and checkra1n's in the next commits). Unnamed, every device still counts, and one in DFU mode always does. Watcher::is_target says whether a listed device is the target itself (by ECID, else by its last port), not merely one the rule ignores; the list of devices in the way uses it to show the target beside them. Assisted-by: LLM Signed-off-by: Berkay Kösebay Co-Authored-By: Claude Opus 5.5 --- crates/runtime/src/driver.rs | 27 ++++++++++++++++++++++----- crates/runtime/src/lib.rs | 12 ++++++++++++ crates/usb/src/others.rs | 27 ++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/crates/runtime/src/driver.rs b/crates/runtime/src/driver.rs index 07e49b0d..09350f65 100644 --- a/crates/runtime/src/driver.rs +++ b/crates/runtime/src/driver.rs @@ -583,7 +583,20 @@ impl Driver { && self.only.as_ref().is_some_and(|only| only.ecid.is_some()) && watcher.ecid(d).is_none() }; - let mut unnamed: Vec<_> = unnamed.into_iter().filter(|d| orchard_usb::apple_device(d) && !asked(d)).collect(); + // With the device named (--ecid, --location) the flow never + // waits for other devices to go: it knows which one is its own, + // and everything of ours is addressed to it (its ECID, its port). + // What can't be addressed is guarded where it runs, not here: + // palera1n and checkra1n take the first device they find, so + // their starts check for a device they could take right before + // and while they run (chain::alone, access_checkra1n::start_ios). + // Refusing the whole flow instead stopped runs that were safe: + // a second phone in iOS held up a launch by the ibss route. + let target_named = self.only.is_some(); + let mut unnamed: Vec<_> = unnamed + .into_iter() + .filter(|d| orchard_usb::apple_device(d) && !asked(d)) + .collect(); // One piece of work on a device at a time: a device in // DFU mode is taken before the flow hears of it, and one // that other work holds is left to it. @@ -633,10 +646,14 @@ impl Driver { let mut others = if target.is_none() && !unnamed.is_empty() { // Only devices that were not named are there. listed_devices(&catalog, &watcher, &unnamed, None) - } else if watcher.others(&devices, target.as_ref()).is_empty() { - Vec::new() } else { - listed_devices(&catalog, &watcher, &devices, flow.state.device()) + // The ones in the way, and the target with them: + // not the devices the rule leaves alone. + let mut shown = if target_named { Vec::new() } else { watcher.others(&devices, target.as_ref()) }; + if !shown.is_empty() { + shown.extend(devices.iter().filter(|d| target.as_ref().is_some_and(|t| watcher.is_target(d, t))).cloned()); + } + listed_devices(&catalog, &watcher, &shown, flow.state.device()) }; // A device other work holds says so in place of its mode. for (device, holder) in &in_use { @@ -730,7 +747,7 @@ fn listed_devices( target: Option<&orchard_flow::Device>, ) -> Vec { // Whether a listed device is the one being installed on (orchard_usb::others). - let is_target = |d: &orchard_usb::Device| target.is_some_and(|t| watcher.others(std::slice::from_ref(d), Some(&t.id)).is_empty()); + let is_target = |d: &orchard_usb::Device| target.is_some_and(|t| watcher.is_target(d, &t.id)); devices .iter() .filter(|d| orchard_usb::apple_device(d)) diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 974f19f3..bf9f2888 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -366,6 +366,18 @@ impl Watcher { orchard_usb::others(&listing, target).into_iter().cloned().collect() } + /// Whether a listed device is `target` itself: by its ECID where both + /// are known, else by the port the target was last seen at. Unlike an + /// empty `others`, this is not true of a device the rule merely ignores. + pub fn is_target(&self, device: &orchard_usb::Device, target: &DeviceId) -> bool { + let told = device.identity.udid.as_deref().and_then(|u| self.told.get(u)).and_then(|t| t.ecid.clone()); + let ecid = device.identity.ecid.clone().or(told); + match (ecid.as_deref(), (!target.0.contains('-')).then_some(target.0.as_str())) { + (Some(a), Some(b)) => orchard_usb::ecid_key(a) == orchard_usb::ecid_key(b), + _ => self.locations.get(target).is_some_and(|at| *at == device.location), + } + } + /// Identifies a listing and returns the events since the last one. pub fn see(&mut self, catalog: &Catalog, listing: &[orchard_usb::Device]) -> Vec { let mut now = Vec::new(); diff --git a/crates/usb/src/others.rs b/crates/usb/src/others.rs index e736e53e..1219e366 100644 --- a/crates/usb/src/others.rs +++ b/crates/usb/src/others.rs @@ -35,6 +35,18 @@ pub fn others<'a>(listing: &'a [Device], target: Option) -> Vec<&'a Devi let Some(target) = target else { return if devices.len() > 1 { devices } else { Vec::new() }; }; + // With the target named (--ecid, --location), a device elsewhere that + // runs m1n1 or an Orchard system is no danger and doesn't count: + // palera1n and checkra1n only take devices in DFU, recovery, Pongo or + // iOS, and everything of ours follows the target by its port. People + // who work on several devices keep them plugged in. + let named = target.ecid.is_some() || target.location.is_some(); + let known_target = |d: &Device| match (d.identity.ecid.as_deref(), target.ecid) { + (Some(a), Some(b)) => ecid_key(a) == ecid_key(b), + _ => target.location.is_some_and(|at| d.location == at), + }; + let devices: Vec<&Device> = + devices.into_iter().filter(|d| known_target(d) || !(named && matches!(d.mode, Mode::Linux | Mode::M1n1))).collect(); let lone = devices.len() == 1; let is_target = |d: &Device| match (d.identity.ecid.as_deref(), target.ecid) { (Some(a), Some(b)) => ecid_key(a) == ecid_key(b), @@ -125,7 +137,20 @@ mod tests { fn without_a_known_port_a_lone_device_is_the_target() { let t = Some(Target { ecid: Some("11223344556677"), location: None }); assert!(others(&[device(Mode::Normal, "x", None)], t).is_empty()); - let two = [device(Mode::Normal, "x", None), device(Mode::M1n1, "y", None)]; + let two = [device(Mode::Normal, "x", None), device(Mode::Recovery, "y", None)]; assert_eq!(others(&two, t).len(), 2); } + + #[test] + fn with_the_target_named_devices_in_m1n1_or_linux_elsewhere_dont_count() { + let mut system = device(Mode::Linux, "0x100000", None); + system.system = Some(crate::System::Installed); + let listing = [device(Mode::Normal, "x", None), device(Mode::M1n1, "y", None), system]; + let t = Some(Target { ecid: Some("11223344556677"), location: None }); + assert!(others(&listing, t).is_empty()); + // Unnamed, they still count; and one in DFU mode always does. + assert_eq!(others(&listing, None).len(), 3); + let dfu = [device(Mode::Normal, "x", None), device(Mode::Dfu, "y", Some("99"))]; + assert_eq!(others(&dfu, t).len(), 2); + } } From 877a5cb18c80097de205f4b345cfa6899c65f43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Tue, 1 Dec 2026 15:13:17 +0100 Subject: [PATCH 2/7] Installer: starts addressed to the device don't wait for other devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The flow held every start (the install system, the launcher's entries, iOS with the helper) while other Apple devices were on USB. Some starts are addressed to the device itself and can't take another one: the ibss route (gaster's worker matches the ECID, chip and board, and everything after it goes to the device's port), and checkra1n's start of iOS, which waits for the devices checkra1n could take by itself. Those no longer wait; palera1n and checkra1n as boot routes still do. The command line's install passes the route named with --boot (or ORCHARD_BOOT) to the flow, which decides by it. Assisted-by: LLM Signed-off-by: Berkay Kösebay Co-Authored-By: Claude Opus 5.5 --- crates/cli/src/commands/install.rs | 10 +++++++++- crates/flow/src/lib.rs | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/cli/src/commands/install.rs b/crates/cli/src/commands/install.rs index 72fce4a0..9ca5f986 100644 --- a/crates/cli/src/commands/install.rs +++ b/crates/cli/src/commands/install.rs @@ -179,7 +179,15 @@ fn flow_options(access: Option<&str>, tool: &ToolFlags, busy_cpu: bool) -> Resul let seconds = tool.port_reset.or_else(|| env("ORCHARD_PORT_RESET_SECONDS")?.parse::().ok().map(|s| s.clamp(0., 15.).round() as u8)).unwrap_or(10); Ok(Some(orchard_flow::Options { helper, - start: None, + // The route named with --boot (or its short forms, or ORCHARD_BOOT): + // the flow has to know it too, since it decides by it whether other + // devices on USB hold a start up (the ibss route is addressed). + start: orchard_runtime::flags::chosen_boot().or_else(|| env("ORCHARD_BOOT")).and_then(|b| match b.as_str() { + "ibss" => Some(orchard_flow::Start::Ibss), + "checkra1n" => Some(orchard_flow::Start::Checkra1n), + "palera1n" => Some(orchard_flow::Start::Palera1n), + _ => None, + }), palera1n: if two { Palera1n::Two } else { Palera1n::Three }, port_reset: (seconds > 0).then_some(seconds), busy_cpu: busy_cpu || orchard_runtime::flags::busy_cpu(), diff --git a/crates/flow/src/lib.rs b/crates/flow/src/lib.rs index de0149d9..985c6c51 100644 --- a/crates/flow/src/lib.rs +++ b/crates/flow/src/lib.rs @@ -1172,9 +1172,22 @@ fn step_inner(app: App, mut flow: Flow, event: Event) -> (Flow, Vec) { /// start of the device while other Apple devices are on USB. fn route(flow: &mut Flow, effects: Vec, out: &mut Vec) { let fetch = |assets: Vec| assets.into_iter().map(Effect::Fetch); + // Starts that are addressed to the device itself don't wait for other + // devices to go: the ibss route (gaster's worker matches the ECID, chip + // and board, and everything after it goes to the device's port), and + // checkra1n's start of iOS, which waits by itself for the devices + // checkra1n could take (access_checkra1n::start_ios). palera1n and + // checkra1n as boot routes take the first device they find, and wait. + let own_start = flow.state.device().is_some_and(|d| rules::start(&flow.options, d, false) == Some(Start::Ibss)); + let own_helper = flow.helper() == Some(Helper::Checkra1n); for effect in effects { + let addressed = match effect { + Effect::BootIpadosWithOverlay(_) => own_helper, + Effect::BootInstallEnv(_) | Effect::ListEntries(_) => own_start, + _ => false, + }; match effect { - Effect::BootIpadosWithOverlay(_) | Effect::BootInstallEnv(_) | Effect::ListEntries(_) if !flow.others.is_empty() => { + Effect::BootIpadosWithOverlay(_) | Effect::BootInstallEnv(_) | Effect::ListEntries(_) if !flow.others.is_empty() && !addressed => { if matches!(effect, Effect::BootIpadosWithOverlay(_)) { out.extend(fetch(flow.assets.start(&[Asset::Overlay]))); } From 0792c8a0f9b324debfb874ca31cd5fb51b5f24c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Tue, 1 Dec 2026 15:13:17 +0100 Subject: [PATCH 3/7] checkra1n: start the named device only, and never another MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit checkra1n can't be told which device to start: it takes any device in DFU mode, and after it is done it waits for the next one. Its start of iOS for the split needed exactly one device running iOS on USB, and could take a second device that came into DFU mode meanwhile. The start now knows the target's ECID (and its port while in DFU mode): - before checkra1n runs, it waits up to a minute until no other device is in DFU, recovery or Pongo mode, and refuses with the devices' names after that; - while it runs, another device coming into one of those modes stops it at once; - once its log says "All Done" it is stopped, so it doesn't wait for the next device; - only the device that tells the target's ECID over lockdown is asked for checkra1n's SSH greeting; other devices running iOS may stay. Without an ECID there must still be one device running iOS, as before. Assisted-by: LLM Signed-off-by: Berkay Kösebay Co-Authored-By: Claude Opus 5.5 --- crates/runtime/src/access_checkra1n.rs | 128 ++++++++++++++++++++----- crates/runtime/src/driver.rs | 3 +- 2 files changed, 104 insertions(+), 27 deletions(-) diff --git a/crates/runtime/src/access_checkra1n.rs b/crates/runtime/src/access_checkra1n.rs index 39c37189..e92c6a16 100644 --- a/crates/runtime/src/access_checkra1n.rs +++ b/crates/runtime/src/access_checkra1n.rs @@ -69,30 +69,65 @@ fn on_host(mut error: Error, soc: &str, linux: bool) -> Error { /// checkra1n's start on the device, and the SSH connection it brings; a /// failure of either says what helps on this host. -fn start(executor: &Executor, soc: &str) -> Result<(String, Ssh)> { - let started = start_ios(executor).and_then(|udid| Ssh::open(&udid).map(|ssh| (udid, ssh))); +fn start(executor: &Executor, soc: &str, ecid: Option<&str>) -> Result<(String, Ssh)> { + let started = start_ios(executor, ecid).and_then(|udid| Ssh::open(&udid).map(|ssh| (udid, ssh))); started.map_err(|e| on_host(e, soc, cfg!(target_os = "linux"))) } -/// The one device running iOS on USB, by its UDID. -fn udid() -> Result> { - let mut usb: Vec<_> = usbmux::devices(Path::new(usbmux::SOCKET))?.into_iter().filter(|d| d.usb).collect(); - match usb.len() { - 0 => Ok(None), - 1 => Ok(Some(usb.remove(0).udid)), - _ => Err(fail("more than one device running iOS is connected; connect only the one to resize")), - } +/// The devices running iOS on USB, by their UDIDs. +fn udids() -> Result> { + Ok(usbmux::devices(Path::new(usbmux::SOCKET))?.into_iter().filter(|d| d.usb).map(|d| d.udid).collect()) +} + +/// Whether checkra1n's SSH server greets on this device. +fn greets(udid: &str) -> bool { + let Ok(mut stream) = usbmux::connect(Path::new(usbmux::SOCKET), udid, SSH_PORT) else { return false }; + let _ = stream.set_read_timeout(Some(Duration::from_secs(5))); + let mut greeting = [0u8; 4]; + stream.read_exact(&mut greeting).is_ok() && &greeting == b"SSH-" } /// The device whose SSH server sends its greeting over the cable: that, not /// checkra1n's exit, is the start having worked (its command line goes on /// waiting for the next DFU device). -fn ssh_answers() -> Result> { - let Some(udid) = udid()? else { return Ok(None) }; - let Ok(mut stream) = usbmux::connect(Path::new(usbmux::SOCKET), &udid, SSH_PORT) else { return Ok(None) }; - let _ = stream.set_read_timeout(Some(Duration::from_secs(5))); - let mut greeting = [0u8; 4]; - Ok((stream.read_exact(&mut greeting).is_ok() && &greeting == b"SSH-").then_some(udid)) +/// +/// With the target's ECID (`ecid`), other devices running iOS may stay +/// connected: only the device that tells this ECID over lockdown is asked +/// for the greeting, and nothing is sent to port 44 of any other. Without +/// an ECID there must be one device running iOS, as before. +fn ssh_answers(ecid: Option<&str>) -> Result> { + let mut usb = udids()?; + let udid = match ecid { + Some(wanted) => { + let is = |udid: &String| { + crate::lockdown::ask(Path::new(usbmux::SOCKET), udid).ok().and_then(|a| a.ecid).is_some_and(|e| crate::ecid_key(&e) == crate::ecid_key(wanted)) + }; + usb.into_iter().find(is) + } + None => match usb.len() { + 0 => None, + 1 => Some(usb.remove(0)), + _ => return Err(fail("more than one device running iOS is connected; connect only the one to resize, or name it with --ecid")), + }, + }; + Ok(udid.filter(|u| greets(u))) +} + +/// Other devices checkra1n would take or disturb: it has no way to be told +/// which device it is for, and goes for any in DFU mode. Recovery mode and +/// Pongo count too (it starts devices from there). `ecid` and `at` (the +/// target's port) say which one is ours. +fn in_checkra1ns_way(ecid: Option<&str>, at: Option<&str>) -> Vec { + let ours = |d: &orchard_usb::Device| match (d.identity.ecid.as_deref(), ecid) { + (Some(a), Some(b)) => crate::ecid_key(a) == crate::ecid_key(b), + _ => at.is_some_and(|at| d.location == at), + }; + orchard_usb::list() + .unwrap_or_default() + .into_iter() + .filter(|d| matches!(d.mode, orchard_usb::Mode::Dfu | orchard_usb::Mode::Recovery | orchard_usb::Mode::Pongo) && !ours(d)) + .map(|d| format!("{} in {} mode at {}", d.product.clone().unwrap_or_else(|| "a device".into()), d.mode.as_str(), d.location)) + .collect() } /// usbmuxd is not running: on Linux it may start only once iOS is on USB. @@ -128,7 +163,26 @@ fn timed_out(log: &str, usbmuxd_down: Option) -> Error { /// Runs checkra1n until the device's SSH server answers, and returns the /// device's UDID. -fn start_ios(executor: &Executor) -> Result { +fn start_ios(executor: &Executor, ecid: Option<&str>) -> Result { + // The target's port, while it is in DFU mode: what it is known by in + // the modes that don't tell an ECID. + let at: Option = orchard_usb::list().unwrap_or_default().into_iter().find_map(|d| { + let named = ecid.is_some_and(|e| d.identity.ecid.as_deref().is_some_and(|k| crate::ecid_key(k) == crate::ecid_key(e))); + (d.mode == orchard_usb::Mode::Dfu && named).then(|| d.location.clone()) + }); + // checkra1n takes any device in DFU mode: it only starts once ours is + // the only one it could take. Others are waited for, a minute at most. + let clear = Instant::now() + Duration::from_secs(60); + loop { + let others = in_checkra1ns_way(ecid, at.as_deref()); + if others.is_empty() { + break; + } + if Instant::now() > clear { + return Err(fail(format!("checkra1n would also take another device ({}); it can't be told which one to start. Start again once that device has left DFU and recovery mode", others.join(", ")))); + } + std::thread::sleep(Duration::from_secs(1)); + } // 0.12.4: the build whose start brings its loader and SSH server. let (pin, release) = crate::flags::checkra1n_jailbreak_pin().ok_or_else(|| Error::new(Code::NotFound, "checkra1n publishes no build for this computer"))?; let checkra1n = executor.palera1n(pin, release)?; @@ -167,16 +221,38 @@ fn start_ios(executor: &Executor) -> Result { let until = Instant::now() + BOOT; let read_log = || std::fs::read(&log_path).map(|t| String::from_utf8_lossy(&t).into_owned()).unwrap_or_default(); let (mut seen, mut changed) = (0usize, Instant::now()); + // Once checkra1n says it is done with our device it is stopped: left + // running, it waits for the next device in DFU mode and takes it. + let mut done = false; + let mut ticks = 0u32; let outcome = loop { - std::thread::sleep(Duration::from_secs(3)); - let usbmuxd_down = match ssh_answers() { + std::thread::sleep(Duration::from_secs(1)); + ticks += 1; + if !done { + // Another device came into its reach while it runs: stop it at once. + let others = in_checkra1ns_way(ecid, at.as_deref()); + if !others.is_empty() { + break Err(fail(format!("another device came into DFU or recovery mode while checkra1n ran ({}); checkra1n was stopped so that it does not start that one", others.join(", ")))); + } + if std::fs::read_to_string(&log_path).is_ok_and(|l| l.contains("All Done")) { + done = true; + let _ = child.kill(); + let _ = child.wait(); + } + } + if ticks % 3 != 0 { + continue; + } + let usbmuxd_down = match ssh_answers(ecid) { Ok(Some(udid)) => break Ok(udid), Err(e) if !not_running(&e) => break Err(e), waiting => waiting.err(), }; - if let Ok(Some(status)) = child.try_wait() { - if !status.success() { - break Err(fail(format!("checkra1n failed ({status}); its log: {}", log_path.display()))); + if !done { + if let Ok(Some(status)) = child.try_wait() { + if !status.success() { + break Err(fail(format!("checkra1n failed ({status}); its log: {}", log_path.display()))); + } } } let text = read_log(); @@ -404,9 +480,9 @@ const COMPANION: &str = "/private/var/OrchardCompanion"; /// Starts iOS on the device in DFU mode, on a chip with `soc`, with /// checkra1n and the companion's `helper` there, taking `token` and saying -/// `system` for what is installed. -pub fn companion(executor: &Executor, soc: &str, helper: &[u8], token: &str, system: &str) -> Result { - let (udid, ssh) = start(executor, soc)?; +/// `system` for what is installed. With `ecid`, only that device is started. +pub fn companion(executor: &Executor, soc: &str, ecid: Option<&str>, helper: &[u8], token: &str, system: &str) -> Result { + let (udid, ssh) = start(executor, soc, ecid)?; let (program, pidfile) = (format!("{COMPANION}/orchard-companion"), format!("{COMPANION}/helper.pid")); ssh.must( &format!("if [ -f {pidfile} ]; then kill \"$(cat {pidfile})\" 2>/dev/null; fi; rm -rf {COMPANION}; umask 077; mkdir -p {COMPANION}"), @@ -485,7 +561,7 @@ pub fn run(executor: &Executor, soc: &str, app: &Older, say: &dyn Fn(&str), done /// One checkra1n start and one session. fn round(executor: &Executor, soc: &str, app: &Older, say: &dyn Fn(&str), done: &mut dyn FnMut(&dyn Fn() -> bool) -> Result) -> Result { say("Starting iOS with checkra1n"); - let (udid, ssh) = start(executor, soc)?; + let (udid, ssh) = start(executor, soc, None)?; say("iOS is up; copying Resize APFS"); ssh.must(&format!("{}; {}", leftover(OLD_SESSION, OLD_APP), leftover(SESSION, APP)), "Removing an earlier session", None)?; // 755: the app runs as mobile and must read its bundle; the helper trusts diff --git a/crates/runtime/src/driver.rs b/crates/runtime/src/driver.rs index 09350f65..a66d206e 100644 --- a/crates/runtime/src/driver.rs +++ b/crates/runtime/src/driver.rs @@ -350,8 +350,9 @@ impl Driver { .and_then(|d| Catalog::open(&executor.data().ok()?).and_then(|c| c.chip(c.board(&d.board)?.chip)).ok()) .map(|chip| chip.soc) .unwrap_or_default(); + let ecid = device.as_ref().map(|d| d.id.0.clone()); let started = crate::overlay::Companion::embedded() - .and_then(|companion| crate::access_checkra1n::companion(&executor, &soc, &companion.helper, &token, orchard_flow::system_name())); + .and_then(|companion| crate::access_checkra1n::companion(&executor, &soc, ecid.as_deref(), &companion.helper, &token, orchard_flow::system_name())); match (started, device) { (Ok(session), Some(device)) => { let _ = jobs.send(CompanionJob::Attach { udid: session.udid.clone(), device, token }); From 50d3631d2546aab46a07d0df5ae27dc7e6282332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Fri, 4 Dec 2026 12:38:32 +0100 Subject: [PATCH 4/7] Changelog: a named device works beside other devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assisted-by: LLM Signed-off-by: Berkay Kösebay Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 060985a9..9eedb3e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ is on main, the release is published with that section as its notes (AGENTS.md, - On Linux, running Orchard as root leaves the USB access rule for your regular account in place. +- With the device named (`--ecid`, `--location`), other devices on USB no + longer hold the install or launch up: devices running m1n1 or Linux + elsewhere don't count, and the ibss route and checkra1n's start of iOS + go ahead beside them. checkra1n waits, and stops, while another device + it could take is in DFU, recovery or Pongo mode. ### Command line From f0870f36f530cd780b7c6497210ff25dc9b80cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Tue, 1 Dec 2026 15:13:59 +0100 Subject: [PATCH 5/7] Installer: pick up iOS that checkra1n started in an earlier session MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closing and starting the installer again while the device runs iOS as checkra1n started it (its SSH server answers) sent it through another round into DFU mode, which restarts the device, possibly under a split that is running. With the device named by its ECID and checkra1n chosen as the helper, the driver now asks whether checkra1n's SSH server answers on that device. If it does, the companion's helper is put there again (an earlier helper is stopped first; a split it was doing is in the engine's journal, and the new helper goes on with it), and the flow picks up at the split when the helper answers. One pick-up runs at a time, and none while this run already holds a checkra1n session. access_checkra1n::companion splits into running() and companion_on() for this. Assisted-by: LLM Signed-off-by: Berkay Kösebay Co-Authored-By: Claude Opus 5.5 --- crates/runtime/src/access_checkra1n.rs | 20 ++++++++++++++ crates/runtime/src/driver.rs | 37 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/crates/runtime/src/access_checkra1n.rs b/crates/runtime/src/access_checkra1n.rs index e92c6a16..c60616dc 100644 --- a/crates/runtime/src/access_checkra1n.rs +++ b/crates/runtime/src/access_checkra1n.rs @@ -483,6 +483,26 @@ const COMPANION: &str = "/private/var/OrchardCompanion"; /// `system` for what is installed. With `ecid`, only that device is started. pub fn companion(executor: &Executor, soc: &str, ecid: Option<&str>, helper: &[u8], token: &str, system: &str) -> Result { let (udid, ssh) = start(executor, soc, ecid)?; + put_helper(udid, ssh, helper, token, system) +} + +/// The UDID of the device with this ECID when iOS on it already runs as +/// checkra1n started it (its SSH server answers): an installer started again +/// goes on from there, without another round through DFU mode. +pub fn running(ecid: &str) -> Option { + ssh_answers(Some(ecid)).ok().flatten() +} + +/// Puts the companion's helper on a device checkra1n has started and starts +/// it. A helper an earlier session left is stopped first; a split it was +/// doing is in the engine's journal, and the new helper goes on with it. +pub fn companion_on(udid: String, helper: &[u8], token: &str, system: &str) -> Result { + let ssh = Ssh::open(&udid)?; + put_helper(udid, ssh, helper, token, system) +} + +/// The helper onto the device over `ssh`, and started there. +fn put_helper(udid: String, ssh: Ssh, helper: &[u8], token: &str, system: &str) -> Result { let (program, pidfile) = (format!("{COMPANION}/orchard-companion"), format!("{COMPANION}/helper.pid")); ssh.must( &format!("if [ -f {pidfile} ]; then kill \"$(cat {pidfile})\" 2>/dev/null; fi; rm -rf {COMPANION}; umask 077; mkdir -p {COMPANION}"), diff --git a/crates/runtime/src/driver.rs b/crates/runtime/src/driver.rs index a66d206e..d8f032f2 100644 --- a/crates/runtime/src/driver.rs +++ b/crates/runtime/src/driver.rs @@ -11,6 +11,7 @@ use orchard_boards::catalog::Catalog; use orchard_cache::Result; use orchard_flow::{step, App, Effect, Event, Flow, UsbMode}; use std::path::PathBuf; +use std::sync::atomic::Ordering::SeqCst; use std::sync::mpsc::{self, Receiver, Sender}; use std::time::{Duration, Instant}; @@ -173,6 +174,7 @@ pub fn start(options: Options, observer: impl Observer) -> Result { app_options: orchard_flow::Options::default(), login: Default::default(), checkra1n: Default::default(), + picking_up: Default::default(), executor, events: tx, observer, @@ -245,6 +247,7 @@ struct Driver { login: std::sync::Arc>>, /// The session of checkra1n's helper, until it is taken off again. checkra1n: std::sync::Arc>>, + picking_up: std::sync::Arc, observer: O, } @@ -638,6 +641,40 @@ impl Driver { if let Some(udid) = watcher.udid(&device.id) { self.udids.insert(device.id.clone(), udid); } + // iOS as checkra1n started it, from a session before this + // one (the installer was started again): the helper is put + // there now, and the flow picks up at the split when it + // answers, without another round through DFU mode, which + // would restart the device under a split that may be running. + let ours = self.only.as_ref().is_some_and(|only| only.ecid.is_some()); + if ours && flow.options.helper == Some(orchard_flow::Helper::Checkra1n) && { + let slot = self.checkra1n.lock().expect("checkra1n"); + slot.is_none() && self.picking_up.compare_exchange(false, true, SeqCst, SeqCst).is_ok() + } { + let (events, jobs, slot, device) = (self.events.clone(), self.companion_jobs.clone(), self.checkra1n.clone(), device.clone()); + let picking_up = self.picking_up.clone(); + std::thread::spawn(move || { + let Some(udid) = crate::access_checkra1n::running(&device.id.0) else { + picking_up.store(false, SeqCst); + return; + }; + let token = crate::overlay::Identity::random().token_hex(); + let started = crate::overlay::Companion::embedded() + .and_then(|companion| crate::access_checkra1n::companion_on(udid, &companion.helper, &token, orchard_flow::system_name())); + match started { + Ok(session) => { + let mut slot = slot.lock().expect("checkra1n"); + if slot.is_none() { + let udid = session.udid.clone(); + *slot = Some(session); + let _ = jobs.send(CompanionJob::Attach { udid, device, token }); + } + } + Err(e) => drop(events.send(Event::ChainFailed(e.to_string()))), + } + picking_up.store(false, SeqCst); + }); + } } } // Other Apple devices besides the one being worked on: From fa26ec8da3632e96f5d724b04db33506b41c1f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Tue, 1 Dec 2026 15:14:25 +0100 Subject: [PATCH 6/7] Installer: the companion's token is the one of the helper this run started MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The driver picked the companion's token by the helper the flow names. Before the device's iOS version is known the flow names none, so the overlay's token was sent to the helper this run had started through checkra1n's SSH, and that helper refused every connection. A helper this run put on the device through checkra1n has its own token, and that token is used whatever the flow names. With checkra1n chosen there is no overlay, so no token is sent until that helper runs. Assisted-by: LLM Signed-off-by: Berkay Kösebay Co-Authored-By: Claude Opus 5.5 --- crates/runtime/src/driver.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/runtime/src/driver.rs b/crates/runtime/src/driver.rs index d8f032f2..bd766930 100644 --- a/crates/runtime/src/driver.rs +++ b/crates/runtime/src/driver.rs @@ -738,9 +738,19 @@ impl Driver { // The token of the helper that runs there: the // helper app's on the route without DFU, else // the overlay's. + // A helper this run put there through checkra1n's SSH has its + // own token, whatever the flow makes of the helper just now + // (before the device's version is known it names none, and + // the overlay's token then took the place of the right one: + // the helper refused every connection). With checkra1n chosen + // there is no overlay, so no token until that helper runs. + let ours = self.checkra1n.lock().expect("checkra1n").as_ref().map(|s| s.token.clone()); + let chosen = flow.options.helper == Some(orchard_flow::Helper::Checkra1n); let token = |udid: &str| match flow.helper() { + _ if ours.is_some() => ours.clone(), Some(orchard_flow::Helper::Dopamine) => crate::helper_app::token(&self.executor, udid), - Some(orchard_flow::Helper::Checkra1n) => self.checkra1n.lock().expect("checkra1n").as_ref().map(|s| s.token.clone()), + Some(orchard_flow::Helper::Checkra1n) => None, + _ if chosen => None, _ => self.executor.companion_token(), }; if let Some((udid, token)) = udid.and_then(|udid| token(&udid).map(|token| (udid, token))) { From cc7131193829c6d3ad4441a3e8b3843fe4dacf52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Fri, 4 Dec 2026 12:39:53 +0100 Subject: [PATCH 7/7] Changelog: picking up a checkra1n start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assisted-by: LLM Signed-off-by: Berkay Kösebay Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eedb3e9..2120a600 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ is on main, the release is published with that section as its notes (AGENTS.md, elsewhere don't count, and the ibss route and checkra1n's start of iOS go ahead beside them. checkra1n waits, and stops, while another device it could take is in DFU, recovery or Pongo mode. +- On iOS 12 to 14, an installer started again while iOS runs as + checkra1n started it goes on at the split, without another round + through DFU mode. ### Command line