Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ OBJECTS := \
smc.o \
ctxr_exec.o \
smp.o \
spmi.o pmu_counter.o ace3.o \
spmi.o pmu_counter.o proxy_fallback.o ace3.o \
start.o \
startup.o \
string.o \
Expand Down
35 changes: 17 additions & 18 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "pcie.h"
#include "pmgr.h"
#include "pmu_counter.h"
#include "proxy_fallback.h"
#include "secboot.h"
#include "sep.h"
#include "smp.h"
Expand Down Expand Up @@ -269,19 +270,6 @@ void run_actions(void)
fb_set_active(true);

printf("No valid payload found\n");
/*
* An aura-try trial that cannot start its payload must not stop here: nobody may be at the
* Mac, and the proxy below is not guaranteed to keep the trial watchdog running. The trial
* marker was spent before this image was read, so a reboot lands on the configured Stage 2.
* Leave the error on the panel for a few seconds first.
*/
if (aura_trial_enabled()) {
printf("\naura-try: the trial could not start its payload; rebooting to the configured "
"Stage 2 in 10 s\n");
mdelay(10000);
pmu_chain_leave();
flush_and_reboot();
}
if (stage1_config_target())
/* Shown on the panel: this is where a user without a USB host ends up. */
printf("\nStage 1: could not start the configured Stage 2 from the EFI partition.\n"
Expand Down Expand Up @@ -310,6 +298,14 @@ void run_actions(void)
flush_and_reboot();
}

/*
* An aura-try trial, or a stage whose failed-boot count allows it, reboots after a bounded
* wait for a host instead of stopping here (proxy_fallback.c). It listens on the carriers
* already up and decides before USB is brought up below: that bring-up may reset a port
* controller and arm a watchdog of its own, which a stage on its way to a reboot must not do.
*/
proxy_fallback("no payload could be started");

#ifndef BRINGUP
/* A proxy window brought USB up already; a second bring-up would register its ports twice. */
if (!usb_up && !aura_debug_enabled() && !(stage1_window_done && chip_id != T8140)) {
Expand All @@ -320,7 +316,6 @@ void run_actions(void)

printf("Running proxy...\n");

pmu_chain_leave();
uartproxy_run(NULL);
}

Expand Down Expand Up @@ -498,9 +493,11 @@ void aura_main(void)

if (!nvme_shutdown()) {
printf("NVMe handoff failed; returning to proxy\n");
pmu_chain_leave();
if (!secboot_host_proxy_allowed())
if (!secboot_host_proxy_allowed()) {
pmu_chain_leave();
flush_and_reboot();
}
proxy_fallback("NVMe handoff failed");
uartproxy_run(NULL);
panic("NVMe handoff failed\n");
}
Expand All @@ -518,9 +515,11 @@ void aura_main(void)
/* Its firmware may still use memory the next stage will reuse. */
if (display_shutdown(DCP_SLEEP_IF_EXTERNAL) < 0) {
printf("Display handoff failed; returning to proxy\n");
pmu_chain_leave();
if (!secboot_host_proxy_allowed())
if (!secboot_host_proxy_allowed()) {
pmu_chain_leave();
flush_and_reboot();
}
proxy_fallback("Display handoff failed");
uartproxy_run(NULL);
panic("Display handoff failed\n");
}
Expand Down
36 changes: 5 additions & 31 deletions src/payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,40 +454,14 @@ bool payload_logo(void **custom_128, void **custom_256)
}

/*
* Reboot after a failed start while fewer than this many boots in a row have failed: an ANS that
* a Stage 2 couldn't start from off came up again after one or two reboots each time on the J713
* (about 1 start in 7 failed, 2026-11-21). iBoot counts each such reset as a failed boot, and no
* aura stage clears the count until the chain reaches an OS or the proxy (pmu_chain_leave()), so
* a failure that persists ends in the proxy after this many reboots.
*/
#define PAYLOAD_NVME_START_REBOOTS 2

/* The decision alone, from the count the earlier stages handed on. */
static bool payload_nvme_start_reboot(bool passed, u8 failed_boots)
{
return passed && failed_boots < PAYLOAD_NVME_START_REBOOTS;
}

/*
* A post-M4 ANS that didn't start from off stays down until a reboot. Rather than stop in the
* proxy, where only a tether can reboot it, reboot while the chain's failed-boot count allows it.
* Without a count from an earlier stage nothing bounds the reboots, and the proxy stays.
* A post-M4 ANS that didn't start from off stays down until a reboot. The stage ends up where
* every stage with no payload does: proxy_fallback() reboots while the chain's failed-boot count
* allows it (an ANS that failed to start came up again after one or two reboots each time on the
* J713, about 1 start in 7 failing, 2026-11-21) and stops in the proxy after that.
*/
static void payload_nvme_start_failed(void)
{
u8 failed = 0;
bool passed = pmu_failed_boots_passed(&failed);

if (!payload_nvme_start_reboot(passed, failed)) {
if (!passed)
printf("nvme: no failed-boot count from an earlier stage: no reboot, proxy\n");
else
printf("nvme: %u failed boots in a row already: no reboot, proxy\n", failed);
return;
}
printf("nvme: ANS start failed: rebooting (%u failed boots in a row before, limit %u)\n",
failed, PAYLOAD_NVME_START_REBOOTS);
flush_and_reboot();
printf("nvme: ANS didn't start from off\n");
}

int payload_run(void)
Expand Down
68 changes: 68 additions & 0 deletions src/proxy_fallback.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* SPDX-License-Identifier: MIT */

#include "proxy_fallback.h"
#include "boot_options.h"
#include "pmu_counter.h"
#include "uartproxy.h"
#include "utils.h"

/*
* Nobody may be at the Mac when a stage would stop in the proxy, and only a USB host can drive it
* or reboot it there. Reboot instead where a reboot is known to end:
* - An aura-try trial spent its marker on the ESP before its image was read, so the reboot lands
* on the configured image. This needs nothing from Stage 1 beyond the trial itself.
* - Otherwise, while the failed-boot count the earlier stages handed on is under the limit. iBoot
* counts each such reset, and no stage clears the count before the chain leaves aura, so a
* failure that persists ends in the proxy after PROXY_FALLBACK_REBOOTS reboots. A stage handed
* no count (an older Stage 1 clears it at start) can't tell a first failure from a cleared
* count, and keeps the proxy.
*/
enum proxy_fallback_action proxy_fallback_decide(bool trial, bool count_passed, u8 failed_boots)
{
if (trial)
return PROXY_FALLBACK_REBOOT_TRIAL;
if (count_passed && failed_boots < PROXY_FALLBACK_REBOOTS)
return PROXY_FALLBACK_REBOOT_COUNTED;
return PROXY_FALLBACK_PROXY;
}

void proxy_fallback(const char *why)
{
u8 failed = 0;
bool passed = pmu_failed_boots_passed(&failed);
enum proxy_fallback_action action = proxy_fallback_decide(aura_trial_enabled(), passed, failed);

if (action == PROXY_FALLBACK_PROXY) {
if (!passed)
printf("%s: no failed-boot count from an earlier stage: no reboot, proxy\n", why);
else
printf("%s: %u failed boots in a row already: no reboot, proxy\n", why, failed);
pmu_chain_leave();
return;
}

/* Shown on the panel */
if (action == PROXY_FALLBACK_REBOOT_TRIAL)
printf("\naura-try: %s; waiting %u s for a host, then rebooting to the configured "
"image\n",
why, PROXY_FALLBACK_HOST_MS / 1000);
else
printf("\n%s; waiting %u s for a host, then rebooting (%u failed boots in a row before, "
"limit %u)\n",
why, PROXY_FALLBACK_HOST_MS / 1000, failed, PROXY_FALLBACK_REBOOTS);

if (uartproxy_wait_host(PROXY_FALLBACK_HOST_MS)) {
printf("Proxy: host attached, no reboot\n");
pmu_chain_leave();
return;
}

/*
* A trial's reboot is a deliberate one, so clear the count first, as run_actions() does before
* its other deliberate reboots: the configured image then starts with only this reset counted.
*/
if (action == PROXY_FALLBACK_REBOOT_TRIAL)
pmu_chain_leave();
printf("No host: rebooting\n");
flush_and_reboot();
}
36 changes: 36 additions & 0 deletions src/proxy_fallback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* SPDX-License-Identifier: MIT */

#ifndef PROXY_FALLBACK_H
#define PROXY_FALLBACK_H

#include "types.h"

/*
* At most this many self-reboots in a row before a stage stops in the proxy: the chain's
* failed-boot count (aura.failed-boots=) bounds them.
*/
#define PROXY_FALLBACK_REBOOTS 2

/* How long a stage that falls back waits for a host before it reboots */
#define PROXY_FALLBACK_HOST_MS 15000

enum proxy_fallback_action {
/* Stop in the proxy, as before */
PROXY_FALLBACK_PROXY,
/* An aura-try trial: reboot to the configured image, the trial marker is spent */
PROXY_FALLBACK_REBOOT_TRIAL,
/* Reboot, and let iBoot count it: the chain's failed-boot count is under the limit */
PROXY_FALLBACK_REBOOT_COUNTED,
};

enum proxy_fallback_action proxy_fallback_decide(bool trial, bool count_passed, u8 failed_boots);

/*
* A stage that would stop in the proxy calls this first, with the reason. It waits a bounded
* time for a host and reboots if none came and the decision above allows it. It returns, with
* the chain left (pmu_chain_leave()), when the proxy should run: a host is attached, or no reboot
* is allowed.
*/
void proxy_fallback(const char *why);

#endif
25 changes: 25 additions & 0 deletions src/uartproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,31 @@ enum stage1_proxy_result uartproxy_wait_stage1(unsigned int timeout_ms)
}
}

/*
* A bounded wait for a host on any proxy iodev, for a stage that would otherwise stop in the proxy
* with nobody to drive it (proxy_fallback.c). A host's sync word ends it early, and the proxy then
* runs presynced on that iodev.
*/
bool uartproxy_wait_host(unsigned int timeout_ms)
{
u64 start = ticks_to_msecs(get_ticks());

while (ticks_to_msecs(get_ticks()) - start < timeout_ms) {
usb_cdc_poll();
for (iodev_id_t i = 0; i < IODEV_MAX; i++) {
if (i == IODEV_DOCKCHANNEL_UART && usb_cdc_owns_carrier())
continue;
if (uartproxy_sync_iodev(i)) {
presynced_iodev = i;
wdt_host_attached();
return true;
}
}
mdelay(1);
}
return false;
}

int uartproxy_run_presynced(void)
{
if (presynced_iodev == IODEV_MAX)
Expand Down
1 change: 1 addition & 0 deletions src/uartproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct uartproxy_msg_start {
int uartproxy_run(struct uartproxy_msg_start *start);
bool uartproxy_wait_dockchannel(unsigned int timeout_ms);
enum stage1_proxy_result uartproxy_wait_stage1(unsigned int timeout_ms);
bool uartproxy_wait_host(unsigned int timeout_ms);
int uartproxy_run_presynced(void);
void uartproxy_send_event(u16 event_type, void *data, u16 length);

Expand Down
Loading