Skip to content

J207 (A10X / T8011): orchard launch with m1n1 6dde868 fails — USB serial string of exactly 64 bytes, and apcie-nvme completion cid mismatch after the queue wraps #570

Backlog

Description

@neatsorg

Follow-up to #553 / OrchardLinux/m1n1#24. Tested on an iPad Pro (10.5-inch, Wi-Fi) (J207, iPad7,3) with orchard 0.3.17, Omarchy A 0.4.8 installed with orchard install omarchy-a --split 45 --access palera1n --busy-cpu --ssh, and m1n1 main at 6dde868 built with boot/m1n1/Containerfile (CHAINLOADING=1, -DQUIET_BOOT) and passed with orchard launch --busy-cpu --m1n1 FILE. Host: Linux, Intel Alder Lake xHCI, Apple USB-A to Lightning cable.

With the three local changes below, orchard launch now starts the installed Omarchy A from internal storage on this unit (DFU to Linux USB in ~20 s). Without them, it failed in three different places.

1. m1n1 never finishes USB enumeration (ec086bf, ECID in the serial string)

On this unit the serial string becomes XXXXXXXXXXXX ECID:XXXXXXXXXXXXX (31 characters), so the string descriptor is 2 + 2 * 31 = 64 bytes, exactly the EP0 max packet size. The host stalls on the serial read and the configuration times out:

usb 3-2: New USB device found, idVendor=1209, idProduct=316d, bcdDevice= 1.00
(10 s gap)
usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 3-2: Product: m1n1 uartproxy 6dde868
usb 3-2: Manufacturer: Asahi Linux
usb 3-2: can't set config #1, error -110

orchard launch then fails with opening the m1n1 proxy: no serial port for the device at 3-2 after 4.5 s, and a replug does not recover it (device descriptor read/64, error -110, device not accepting address). m1n1 2a5fe33 (serial without the ECID) enumerated fine on the same unit and cable.

I suspect that the dwc2 EP0 IN path does not send a zero-length packet when a reply is an exact multiple of the max packet size and shorter than wLength. Locally I only dropped the ECID (if (0 && ecid)), which shortened the descriptor. A proper fix is probably a ZLP in usb_dwc2.c. Other boards whose serial and ECID lengths add up to 31 characters would hit the same problem.

2. apcie-nvme: sq_id in the completion is not reliable

apcie-nvme: initialized
apcie-nvme: opcode 0x2: unexpected completion (sqid 0/1 cid 4/4)

The cid matches but sq_id is 0. m1n1's own nvme.c notes u32 rsvd; // normal NVMe has the sq_head and sq_id here for Apple controllers, so locally submit() no longer compares sq_id.

3. apcie-nvme: completion cid mismatch after the I/O queue wraps

With 2 fixed, the boot manager read the GPT and the BLS entries, then failed on the 17th I/O command, the first one after the 16-entry queue wraps:

apcie-nvme: opcode 0x2: unexpected completion (sqid 1/1 cid 1/17)
apcie-nvme: disable after timeout timeout (0x3)
apcie-nvme: shut down
main_storage_read(4883468) failed (partition at block 4882944, byte 2146304)
bls: 1. omarchy-a-dbac00e3-7.3.0-rc1-orchard-apple-16k (...): not bootable: /loader/entries/omarchy-a-dbac00e3-7.3.0-rc1-orchard-apple-16k.conf: read error

orchard launch reported Nothing to start on this iPad. The phase bit matched, but the entry carried cid 1. On this unit the controller appears to report "SQ slot + 1" rather than the cid from the command. Locally submit() sets cmd->cid = q->sq_tail + 1, and after that the entry loaded and Omarchy A booted. I have not checked this against Apple's driver. It is an inference from this one failure. A larger queue would hide it only until it wraps.

Possibly related: iPadOS 14.6 iBoot

Before restoring to iPadOS 17.7.11 (21H461), this unit ran iPadOS 14.6 (OS FW version: 11.4 (iBoot-6723.120.36)). There, reads failed irregularly even with 2 applied: completions with cid 0 on the 1st or 5th read, and storage init sometimes refused outright. After the restore to 17.7.11, only 3 remained. It may be worth noting in the J207 docs that storage boot was verified on 17.7.x.

Local patch against m1n1 6dde868

--- a/src/apcie_nvme.c
+++ b/src/apcie_nvme.c
@@ static int submit(struct queue *q, struct nvme_sqe *cmd)
 {
-    cmd->cid = ++q->cid;
+    cmd->cid = q->sq_tail + 1;  /* the controller reports SQ slot + 1 */
+    q->cid = cmd->cid;
@@
-    if (cqe.sq_id != q->qid || cqe.cid != cmd->cid) {
+    if (cqe.cid != cmd->cid) {  /* sq_id is not filled in, as in nvme.c */
--- a/src/usb_dwc2.c
+++ b/src/usb_dwc2.c
@@ static void usb_build_serial(void)
-    if (ecid)
+    if (0 && ecid)  /* workaround: a 64-byte descriptor stalls enumeration */

(The local tree also re-reads the completion for up to 1 ms when the cid does not match yet. It was a diagnostic and did not fix anything on its own, so I left it out here.)

Happy to test a proper fix on this J207.

Activity

  1. johannSo commented on Dec 5, 2026

    @johannSo
    Contributor

    Note

    🤖 Claude Opus 5.5 responding on behalf of johannSo

    The cid mismatch (3 in your list) also hit my J120. I think the cause is a stale cache line in submit(), not the controller reporting the slot: OrchardLinux/m1n1#26.

    With the 0.3.24 m1n1 I got cid 27/43. Slot + 1 would have been 11, while 27 is what that slot held one pass earlier, as was your cid 1/17. Linux also uses ordinary command IDs on this controller and works. The PR waits for the phase, then re-reads the entry with the cache line invalidated each time until the ID matches. It also drops the sq_id check (2 in your list). With it, orchard launch --m1n1 boots my installed system.

    Could you try it on your J207 without your cid = sq_tail + 1 change? It doesn't touch the USB serial-string issue (1).

  2. neatsorg commented on Dec 6, 2026

    @neatsorg
    Author

    Thank you for the PR and the explanation! I tried it on the J207.

    I built OrchardLinux/m1n1#26 (38f3682) without my cid = sq_tail + 1 change. The only local change was the ECID workaround in usb_dwc2.c (1), because the unit doesn't enumerate without it. I used the same build settings as before (boot/m1n1/Containerfile, CHAINLOADING=1, -DQUIET_BOOT) and ran orchard launch --busy-cpu --m1n1 FILE.

    It booted. orchard launch listed all three BLS entries, and the installed Omarchy A started from internal storage, as it does with my sq_tail + 1 build. So on this unit, 2 and 3 are fixed by your PR, and I'll drop my cid change.

    Unfortunately, I closed the terminal before I copied the TTY output, so I don't have the shut down (N completions read again) count. I can boot it again and post it if that would help.

    One thing that might be worth knowing: my earlier local build (mentioned at the end of my first post) also re-read the entry with dc_civac_range() + dma_rmb() for up to 1 ms, with the original ++q->cid. On iPadOS 17.7.11 it still failed on the 17th command:

    apcie-nvme: opcode 0x2: completion not settled yet (sqid 1 cid 1), re-reading
    apcie-nvme: opcode 0x2: unexpected completion (sqid 1/1 cid 1/17)
    

    The main difference I can see is that it compared the phase from a memcpy() of the whole entry instead of from status alone. I haven't looked into why that made a difference.

  3. johannSo commented on Dec 6, 2026

    @johannSo
    Contributor

    Note

    🤖 Claude Opus 5.5 responding on behalf of johannSo

    Yes, please post the count. It would tell us whether m1n1#26's explanation is right, and your earlier build makes me doubt it.

    cid and the phase bit share one 32-bit word of the completion entry (u16 cid; u16 status;, DW3). A controller that makes the new phase visible while the old cid is still in that same word is unlikely. Your build also re-read the entry with dc_civac_range() + dma_rmb() for 1 ms and still saw cid 1, so there the ID did not just arrive late.

    The PR changed two things:

    1. It polls the phase by reading status through a volatile pointer, not from a memcpy() of the whole entry.
    2. Only after that does it re-read the entry until the ID matches (for up to 1 ms). That is what the count counts.
    • If the count is above 0, step 2 is the fix, and your earlier build failed for some other reason.
    • If it is 0, step 2 never ran and step 1 is what fixed it. Then the commit message describes the wrong cause, and it is worth a follow-up that says why the volatile read works.

    Our J120 run only logged orchard's side, not m1n1's console, so I don't have the count either. I'll take it on the next J120 boot.

    m1n1#26 is merged, and orchard took it in 5b1809b. So 2 and 3 in your list are done, and this issue only needs to stay open for the USB serial string (1).

  4. neatsorg commented on Dec 6, 2026

    @neatsorg
    Author

    Thank you for the detailed explanation! I got the count, and it's 0.

    shut down (N completions read again) only reaches m1n1's USB console. It runs before kboot_prepare_dt() sets up the log buffer, so it doesn't end up in m1n1_stage2.log either. So I made a diagnostic build: m1n1#26 (38f3682) + the ECID workaround (1) + a small patch that records every re-read (command cid, the cid seen on the first read, number of reads) and prints the totals in bootmgr_start() right before bootmgr: starting, so they land in m1n1_stage2.log. Same build settings as before.

    After orchard launch --busy-cpu --m1n1 FILE on the J207 (iPadOS 17.7.11), Linux's /dev/mtd0 had:

    apcie-nvme diag: 1 storage sessions, 5401 commands, 0 read again
    

    So the completion queue wrapped around many times (16 entries), and the ID loop never had to read again. On this unit, step 2 never ran, and step 1 (polling the phase from status through the volatile pointer) is what fixed it, as in your second case.

    This is from one boot so far. I can run more boots, or try another build if that would help you narrow down why the volatile read works.

    The diagnostic patch (on top of 38f3682, without the ECID workaround)
    diff --git i/src/apcie_nvme.c w/src/apcie_nvme.c
    index d0fb5de4..d5735da8 100644
    --- i/src/apcie_nvme.c
    +++ w/src/apcie_nvme.c
    @@ -402,6 +402,15 @@ static u32 max_blocks;
     /* Completions whose command ID landed after their phase */
     static u32 cqe_rereads;
     
    +/* Diagnostic: record re-reads across shutdowns and print them later, into m1n1_stage2.log */
    +#define DIAG_MAX 16
    +static struct {
    +    u16 cid, first_cid, slot;
    +    u32 loops;
    +    bool settled;
    +} diag_ev[DIAG_MAX];
    +static u32 diag_n, diag_total_rereads, diag_total_cmds, diag_sessions;
    +
     static int t8010_setup_link(void);
     
     static void apply_tunables(u64 base, const struct apcie_tunable *t, size_t count)
    @@ -1255,16 +1264,33 @@ static int submit(struct queue *q, struct nvme_sqe *cmd)
          */
         u64 settle = timeout_calculate(CQE_SETTLE_TIMEOUT);
         bool reread = false;
    +    u16 first_cid = 0;
    +    u32 loops = 0;
         while (true) {
             dc_civac_range((void *)slot, sizeof(cqe));
             dma_rmb();
             memcpy(&cqe, (void *)slot, sizeof(cqe));
    +        if (!loops)
    +            first_cid = cqe.cid;
    +        loops++;
             if (cqe.cid == cmd->cid || timeout_expired(settle))
                 break;
             reread = true;
         }
         if (reread && cqe.cid == cmd->cid)
             cqe_rereads++;
    +    diag_total_cmds++;
    +    if (reread) {
    +        diag_total_rereads++;
    +        if (diag_n < DIAG_MAX) {
    +            diag_ev[diag_n].cid = cmd->cid;
    +            diag_ev[diag_n].first_cid = first_cid;
    +            diag_ev[diag_n].slot = q->cq_head;
    +            diag_ev[diag_n].loops = loops;
    +            diag_ev[diag_n].settled = cqe.cid == cmd->cid;
    +        }
    +        diag_n++;
    +    }
     
         q->cq_head = (q->cq_head + 1) % QUEUE_DEPTH;
         if (!q->cq_head)
    @@ -1524,6 +1550,20 @@ void apcie_nvme_shutdown(void)
             false;
         printf("apcie-nvme: shut down (%u completions read again)\n", cqe_rereads);
         cqe_rereads = 0;
    +    diag_sessions++;
    +}
    +
    +/* Diagnostic: called after kboot_prepare_dt(), so the output reaches m1n1_stage2.log */
    +void apcie_nvme_diag_report(void)
    +{
    +    printf("apcie-nvme diag: %u storage sessions, %u commands, %u read again\n", diag_sessions,
    +           diag_total_cmds, diag_total_rereads);
    +    for (u32 i = 0; i < diag_n && i < DIAG_MAX; i++)
    +        printf("apcie-nvme diag: #%u cid %u slot %u: first read cid %u, %u reads, %s\n", i,
    +               diag_ev[i].cid, diag_ev[i].slot, diag_ev[i].first_cid, diag_ev[i].loops,
    +               diag_ev[i].settled ? "settled" : "timed out");
    +    if (diag_n > DIAG_MAX)
    +        printf("apcie-nvme diag: (%u more not recorded)\n", diag_n - DIAG_MAX);
     }
     
     bool apcie_nvme_init(void)
    diff --git i/src/apcie_nvme.h w/src/apcie_nvme.h
    index b9cebac2..be4f75a0 100644
    --- i/src/apcie_nvme.h
    +++ w/src/apcie_nvme.h
    @@ -6,6 +6,7 @@
     
     bool apcie_nvme_init(void);
     void apcie_nvme_shutdown(void);
    +void apcie_nvme_diag_report(void);
     bool apcie_nvme_read(u64 lba, void *buffer);
     bool apcie_nvme_read_blocks(u64 lba, u32 count, void *buffer);
     u32 apcie_nvme_max_blocks(void);
    diff --git i/src/bootmgr.c w/src/bootmgr.c
    index 5913b406..07d06ab3 100644
    --- i/src/bootmgr.c
    +++ w/src/bootmgr.c
    @@ -3,6 +3,7 @@
     #include "../build/build_cfg.h"
     
     #include "adt.h"
    +#include "apcie_nvme.h"
     #include "bootmgr.h"
     #include "cpufreq.h"
     #include "fb.h"
    @@ -169,6 +170,7 @@ int bootmgr_start(const char *id_arg, const char *devicetree_arg, u64 flags)
             printf("bootmgr: could not prepare the device tree; storage is shut down\n");
             return -1;
         }
    +    apcie_nvme_diag_report(); /* diagnostic */
         printf("bootmgr: starting %s\n", id_arg ? id : "the default entry");
         return kboot_boot(kernel);
     }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions