From 7872ea06818d994a69b8a954f799a4f695c187b8 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/5] 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 58bf98f8..89ec7385 100644 --- a/crates/runtime/src/driver.rs +++ b/crates/runtime/src/driver.rs @@ -585,7 +585,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. @@ -635,10 +648,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 { @@ -732,7 +749,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 99237c8199fa962c55b8c6ecaa130f3303260aee 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/5] 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 aa5d3b25..14802b20 100644 --- a/crates/cli/src/commands/install.rs +++ b/crates/cli/src/commands/install.rs @@ -184,7 +184,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 b30fa70d..a9964ef1 100644 --- a/crates/flow/src/lib.rs +++ b/crates/flow/src/lib.rs @@ -1449,9 +1449,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 d41e84a687e6dc1968528433d1c7a804f8a8e564 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/5] 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 89ec7385..bb621fd7 100644 --- a/crates/runtime/src/driver.rs +++ b/crates/runtime/src/driver.rs @@ -352,8 +352,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 0960461df6f5f27fe3f2fd7c5863b86e20084684 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/5] 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 cca7f56c..1ac6f557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,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 9370badb54591434d05653d772b326e98a0f5594 Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 07:55:58 +0800 Subject: [PATCH 5/5] checkra1n: never count the target as a device in the way Without a named device (no ECID, as `orchard resize` on iOS 12 to 14 starts it), the check for other devices checkra1n could take had no way to know the target and counted it too: every start waited a minute and then failed with "checkra1n would also take another device". Without an ECID the target is the one device checkra1n could take, known by its port from then on; a second such device still counts. The checks are plain functions over a listing now, with tests for both cases. Assisted-by: LLM --- crates/runtime/src/access_checkra1n.rs | 100 +++++++++++++++++++++---- 1 file changed, 85 insertions(+), 15 deletions(-) diff --git a/crates/runtime/src/access_checkra1n.rs b/crates/runtime/src/access_checkra1n.rs index e92c6a16..a851f8b4 100644 --- a/crates/runtime/src/access_checkra1n.rs +++ b/crates/runtime/src/access_checkra1n.rs @@ -113,23 +113,53 @@ fn ssh_answers(ecid: Option<&str>) -> Result> { 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 { +/// The modes checkra1n takes a device in, or starts it from. +fn checkra1n_takes(mode: orchard_usb::Mode) -> bool { + matches!(mode, orchard_usb::Mode::Dfu | orchard_usb::Mode::Recovery | orchard_usb::Mode::Pongo) +} + +/// The target's port in `listing`, what it is known by in the modes that +/// don't tell an ECID: the device in DFU mode with `ecid`, or, without an +/// ECID, the one device checkra1n could take (the target, as the route +/// has always required one there). +fn target_port(listing: &[orchard_usb::Device], ecid: Option<&str>) -> Option { + match ecid { + Some(e) => listing + .iter() + .find(|d| d.mode == orchard_usb::Mode::Dfu && d.identity.ecid.as_deref().is_some_and(|k| crate::ecid_key(k) == crate::ecid_key(e))) + .map(|d| d.location.clone()), + None => { + let mut takeable = listing.iter().filter(|d| checkra1n_takes(d.mode)); + match (takeable.next(), takeable.next()) { + (Some(d), None) => Some(d.location.clone()), + _ => None, + } + } + } +} + +/// Other devices in `listing` 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; the target itself is +/// never counted. +fn in_the_way(listing: &[orchard_usb::Device], 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)) + listing + .iter() + .filter(|d| checkra1n_takes(d.mode) && !ours(d)) .map(|d| format!("{} in {} mode at {}", d.product.clone().unwrap_or_else(|| "a device".into()), d.mode.as_str(), d.location)) .collect() } +/// [`in_the_way`], on the devices on USB now. +fn in_checkra1ns_way(ecid: Option<&str>, at: Option<&str>) -> Vec { + in_the_way(&orchard_usb::list().unwrap_or_default(), ecid, at) +} + /// usbmuxd is not running: on Linux it may start only once iOS is on USB. fn not_running(error: &Error) -> bool { error.code == Code::NotFound @@ -164,12 +194,9 @@ 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, 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()) - }); + // The target's port: what it is known by in the modes that don't tell + // an ECID. Without it, the target would count as a device in the way. + let at = target_port(&orchard_usb::list().unwrap_or_default(), ecid); // 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); @@ -634,6 +661,49 @@ fn round(executor: &Executor, soc: &str, app: &Older, say: &dyn Fn(&str), done: mod tests { use super::*; + fn usb(mode: orchard_usb::Mode, location: &str, ecid: Option<&str>) -> orchard_usb::Device { + orchard_usb::Device { + mode, + system: None, + location: location.into(), + product: None, + identity: orchard_usb::Identity { ecid: ecid.map(str::to_owned), ..Default::default() }, + } + } + + #[test] + fn without_an_ecid_the_lone_device_in_dfu_mode_is_the_target() { + use orchard_usb::Mode; + // orchard resize on iOS 12 to 14 names no device: the one in DFU + // mode is the target, also once it is in Pongo or recovery mode. + let listing = [usb(Mode::Dfu, "0x1100000", None), usb(Mode::Normal, "0x1200000", Some("0xAA"))]; + let at = target_port(&listing, None); + assert_eq!(at.as_deref(), Some("0x1100000")); + assert!(in_the_way(&listing, None, at.as_deref()).is_empty()); + assert!(in_the_way(&[usb(Mode::Pongo, "0x1100000", None)], None, at.as_deref()).is_empty()); + // A second device checkra1n could take still counts. + let two = [usb(Mode::Dfu, "0x1100000", None), usb(Mode::Recovery, "0x1300000", None)]; + assert_eq!(target_port(&two, None), None); + assert_eq!(in_the_way(&two, None, at.as_deref()).len(), 1); + } + + #[test] + fn with_an_ecid_only_other_devices_checkra1n_could_take_count() { + use orchard_usb::Mode; + let listing = [ + usb(Mode::Dfu, "0x1100000", Some("0x0011223344556677")), + usb(Mode::Dfu, "0x1200000", Some("0x00AABBCCDDEEFF00")), + usb(Mode::Normal, "0x1300000", Some("0x0099887766554433")), + usb(Mode::M1n1, "0x1400000", None), + ]; + let at = target_port(&listing, Some("11223344556677")); + assert_eq!(at.as_deref(), Some("0x1100000")); + let way = in_the_way(&listing, Some("11223344556677"), at.as_deref()); + assert_eq!(way, ["a device in dfu mode at 0x1200000"]); + // The target in Pongo, which tells no ECID, is known by its port. + assert!(in_the_way(&[usb(Mode::Pongo, "0x1100000", None)], Some("11223344556677"), at.as_deref()).is_empty()); + } + #[test] fn device_paths_are_quoted_and_executables_told_apart() { assert_eq!(quote("/a b/it's"), "'/a b/it'\\''s'");