U-Boot: reset a failed slot with the CRU global reset [skip ci]
flare_ab keeps the frozen steady-state ladder. The selected committed slot gets FLARE_AB_SLOT_TRIES (2) boot attempts per power session, then the other committed slot, then the recovery FIT, then USB download. With no committed alternative the escalation goes from the two attempts to the recovery FIT. The timed retry from the earlier attempt (arm the DW watchdog, clear OS_REG4) was rejected by the item decision of 2026-11-06 and is removed here. The stall was the failed-boot reset. flare_ab_boot_failed() called do_reset(), which reaches reset_cpu() and the rockchip sysreset WARM request. On RV1106 that request writes CRU glb_srst_snd (0xeca8), which does not reset the chip, so sysreset_walk_halt() ends in hang() at the boot splash and the recovery screens are never reached. flare_ab_global_reset() writes the CRU glb_srst_fst poke (0xfdb9 to 0xff3b0c08), the reset the bench scenarios already use. It is a warm reset: glb_rst_st stays nonzero and OS_REG4 carries the attempt count. If the chip does not reset within 100 ms, the code enters the USB download screens instead of spinning silently. Only the common/flare_ab.c hunk of 0003-flare-ab-slots.patch changes, plus two ASCII fixes to comments in its flare_ab.h hunk. The MC/DC harness and the docs follow in flare-edge. Refs flare-edge#3118 (cause 3), flare-edge#4554 Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdKQBPu4qHGnopkHjchmwz
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
48d20fd662
commit
34d383e1ed
@@ -142,10 +142,10 @@ index 52cd612d1..a81071566 100644
|
||||
obj-$(CONFIG_AUTOBOOT) += autoboot.o
|
||||
diff --git a/sysdrv/source/uboot/u-boot/common/flare_ab.c b/sysdrv/source/uboot/u-boot/common/flare_ab.c
|
||||
new file mode 100644
|
||||
index 000000000..e55ac5d5b
|
||||
index 000000000..903f5b66f
|
||||
--- /dev/null
|
||||
+++ b/sysdrv/source/uboot/u-boot/common/flare_ab.c
|
||||
@@ -0,0 +1,712 @@
|
||||
@@ -0,0 +1,673 @@
|
||||
+// SPDX-License-Identifier: GPL-2.0+
|
||||
+/*
|
||||
+ * flare-edge A/B slot boot for U-Boot proper.
|
||||
@@ -212,14 +212,11 @@ index 000000000..e55ac5d5b
|
||||
+ * free on power loss. So only CONSECUTIVE unhealthy boots within one power
|
||||
+ * session escalate; a healthy boot, or a power cycle, restarts at the selected
|
||||
+ * slot.
|
||||
+ *
|
||||
+ * When the other slot is not committed there is nothing to fail over to, and
|
||||
+ * the escalation does not go to the recovery FIT: it retries the selected slot
|
||||
+ * after a DW-watchdog reset (flare_ab_timed_retry_reset). Recovery is reached
|
||||
+ * only once both committed slots have failed this power session.
|
||||
+ */
|
||||
+#define FLARE_AB_GLB_RST_ST 0xff3b0c04u /* CRU reset-status: 0 on POR */
|
||||
+#define FLARE_AB_SESSION_REG 0xff020210u /* PMU GRF OS_REG4: attempt count */
|
||||
+#define FLARE_AB_GLB_SRST_FST 0xff3b0c08u /* CRU glb_srst_fst: global reset */
|
||||
+#define FLARE_AB_GLB_SRST_KEY 0xfdb9u /* poke value that starts the reset */
|
||||
+/*
|
||||
+ * Attempts on the selected committed slot before failing over to the other
|
||||
+ * committed slot; the other slot then gets the same budget before recovery.
|
||||
@@ -229,24 +226,6 @@ index 000000000..e55ac5d5b
|
||||
+/* Clamp against a garbage register value (validated free, so belt-only). */
|
||||
+#define FLARE_AB_MAX_SESSION 250
|
||||
+
|
||||
+/*
|
||||
+ * DesignWare watchdog (rv1106-wdt at watchdog@ff5a0000), used only by the
|
||||
+ * timed retry. CR bit0 enables it and RMOD (bit1) clear selects the system
|
||||
+ * reset response. TORR sets the timeout to 2^(16+TOP) watchdog cycles, TOP
|
||||
+ * in bits 3:0 and TOP_INIT in bits 7:4; TOP = 11 is about 5.6 s at the
|
||||
+ * 24 MHz tclk given in the luckfox wiki (dw-watchdog). CRR takes the 0x76
|
||||
+ * restart kick. The same register sequence has reset bench panels into a
|
||||
+ * normal boot (luckfox wiki, flashing-recovery).
|
||||
+ */
|
||||
+#define FLARE_AB_WDT_CR 0xff5a0000u
|
||||
+#define FLARE_AB_WDT_TORR 0xff5a0004u
|
||||
+#define FLARE_AB_WDT_CRR 0xff5a000cu
|
||||
+#define FLARE_AB_WDT_EN 0x1u
|
||||
+#define FLARE_AB_WDT_TOP 0xbbu /* TOP_INIT = TOP = 11 */
|
||||
+#define FLARE_AB_WDT_KICK 0x76u
|
||||
+/* Wait longer than the watchdog period, so the timed reset always comes first. */
|
||||
+#define FLARE_AB_WDT_WAIT_US 8000000ul
|
||||
+
|
||||
+static u32 flare_ab_reg_read(u32 addr)
|
||||
+{
|
||||
+ return readl((void __iomem *)(uintptr_t)addr);
|
||||
@@ -279,13 +258,6 @@ index 000000000..e55ac5d5b
|
||||
+static int flare_ab_force_recovery;
|
||||
+
|
||||
+/*
|
||||
+ * Set during slot selection when no committed alternative is left after the
|
||||
+ * selected slot's attempts. flare_ab_enabled() then runs the timed retry, so
|
||||
+ * the reset happens once, at the same early point as the selection itself.
|
||||
+ */
|
||||
+static int flare_ab_retry_pending;
|
||||
+
|
||||
+/*
|
||||
+ * The serialized metadata must fit in the single 512-byte sector we read and
|
||||
+ * write. This is a build invariant, not a runtime condition (the struct is a
|
||||
+ * fixed 32 bytes), so assert it at compile time instead of branching on it.
|
||||
@@ -502,25 +474,6 @@ index 000000000..e55ac5d5b
|
||||
+ return (int)prior;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Timed retry of the selected slot, used when no committed alternative is
|
||||
+ * left. The attempt counter is cleared and the DW watchdog armed for about
|
||||
+ * 5.6 s in system-reset mode, so the reset starts the next power session at
|
||||
+ * attempt 1 on the selected slot instead of the recovery FIT. Nothing here
|
||||
+ * depends on the Linux side. If the watchdog has not reset the board within
|
||||
+ * the wait, a CRU global reset is the fallback. The caller halts if that
|
||||
+ * reset returns.
|
||||
+ */
|
||||
+static void flare_ab_timed_retry_reset(void)
|
||||
+{
|
||||
+ flare_ab_reg_write(FLARE_AB_SESSION_REG, 0);
|
||||
+ flare_ab_reg_write(FLARE_AB_WDT_TORR, FLARE_AB_WDT_TOP);
|
||||
+ flare_ab_reg_write(FLARE_AB_WDT_CR, FLARE_AB_WDT_EN);
|
||||
+ flare_ab_reg_write(FLARE_AB_WDT_CRR, FLARE_AB_WDT_KICK);
|
||||
+ udelay(FLARE_AB_WDT_WAIT_US);
|
||||
+ do_reset(NULL, 0, 0, NULL);
|
||||
+}
|
||||
+
|
||||
+static int ab_select_slot(void)
|
||||
+{
|
||||
+ struct blk_desc *dev_desc;
|
||||
@@ -580,10 +533,8 @@ index 000000000..e55ac5d5b
|
||||
+ /*
|
||||
+ * STEADY-STATE regime: the selected slot is committed. Escalate per
|
||||
+ * power session -- selected slot for FLARE_AB_SLOT_TRIES attempts, then
|
||||
+ * the other slot if it too is committed, then the recovery FIT. With no
|
||||
+ * committed other slot the selected slot is retried after a watchdog
|
||||
+ * reset instead. A power cycle (glb_rst_st==0) restarts at the selected
|
||||
+ * slot.
|
||||
+ * the other slot if it too is committed, then the recovery FIT. A power
|
||||
+ * cycle (glb_rst_st==0) restarts at the selected slot.
|
||||
+ */
|
||||
+ session = flare_ab_bump_session();
|
||||
+
|
||||
@@ -593,42 +544,24 @@ index 000000000..e55ac5d5b
|
||||
+ return pref;
|
||||
+ }
|
||||
+
|
||||
+ if (slot_is_bootable(&ab_data.slots[other]) &&
|
||||
+ if (session <= 2 * FLARE_AB_SLOT_TRIES &&
|
||||
+ slot_is_bootable(&ab_data.slots[other]) &&
|
||||
+ ab_data.slots[other].successful_boot) {
|
||||
+ if (session <= 2 * FLARE_AB_SLOT_TRIES) {
|
||||
+ printf("FLARE-AB: slot %s failed %d attempts this session, trying %s\n",
|
||||
+ pref ? "_b" : "_a", FLARE_AB_SLOT_TRIES,
|
||||
+ other ? "_b" : "_a");
|
||||
+ return other;
|
||||
+ }
|
||||
+
|
||||
+ printf("FLARE-AB: both committed slots failed this power session, recovery\n");
|
||||
+ flare_ab_force_recovery = 1;
|
||||
+ return pref;
|
||||
+ printf("FLARE-AB: slot %s failed %d attempts this session, trying %s\n",
|
||||
+ pref ? "_b" : "_a", FLARE_AB_SLOT_TRIES,
|
||||
+ other ? "_b" : "_a");
|
||||
+ return other;
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * No committed alternative. The recovery FIT is not a retry of this
|
||||
+ * slot, and the silent recovery path is what stranded p54 at the splash,
|
||||
+ * so retry the selected slot through a watchdog-timed reset instead. The
|
||||
+ * reset itself is made by flare_ab_enabled().
|
||||
+ */
|
||||
+ printf("FLARE-AB: slot %s failed %d attempts, no committed alternative, "
|
||||
+ "retrying after a watchdog reset\n",
|
||||
+ pref ? "_b" : "_a", FLARE_AB_SLOT_TRIES);
|
||||
+ flare_ab_retry_pending = 1;
|
||||
+ printf("FLARE-AB: both committed slots failed this power session, recovery\n");
|
||||
+ flare_ab_force_recovery = 1;
|
||||
+ return pref;
|
||||
+}
|
||||
+
|
||||
+int flare_ab_enabled(void)
|
||||
+{
|
||||
+ if (flare_ab_cached_slot == -1) {
|
||||
+ if (flare_ab_cached_slot == -1)
|
||||
+ flare_ab_cached_slot = ab_select_slot();
|
||||
+ if (flare_ab_retry_pending) {
|
||||
+ flare_ab_timed_retry_reset();
|
||||
+ hang(); /* reached only if the CRU reset returned */
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return flare_ab_cached_slot >= 0;
|
||||
+}
|
||||
@@ -776,6 +709,28 @@ index 000000000..e55ac5d5b
|
||||
+ ab_data_write(dev_desc, &ab_data);
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Escalating reset after a failed storage boot.
|
||||
+ *
|
||||
+ * Do not call do_reset() here. On this SoC the U-Boot WARM request
|
||||
+ * (sysreset_rockchip, ARM32 path) writes CRU glb_srst_snd (0xeca8), which does
|
||||
+ * not reset the chip, and reset_cpu() then ends in hang() at the boot splash:
|
||||
+ * the stall the p54 record shows (flare-edge#3118). The reset that works is the
|
||||
+ * CRU glb_srst_fst poke that the Linux restart path and the bench scenarios
|
||||
+ * use (docs/boot-flow.md, "Watchdog / reset facts"). It is a warm reset, so
|
||||
+ * glb_rst_st stays nonzero and OS_REG4 carries the attempt count.
|
||||
+ */
|
||||
+static void flare_ab_global_reset(void)
|
||||
+{
|
||||
+ flare_ab_reg_write(FLARE_AB_GLB_SRST_FST, FLARE_AB_GLB_SRST_KEY);
|
||||
+ /*
|
||||
+ * A taken reset never returns. Reaching the next statement means the
|
||||
+ * chip did not reset, so give the reset time to land before the caller
|
||||
+ * falls through to the USB download screens.
|
||||
+ */
|
||||
+ udelay(100000);
|
||||
+}
|
||||
+
|
||||
+void flare_ab_boot_failed(void)
|
||||
+{
|
||||
+ if (!flare_ab_enabled())
|
||||
@@ -801,16 +756,22 @@ index 000000000..e55ac5d5b
|
||||
+ * makes forward progress. This is a WARM reset, so glb_rst_st stays
|
||||
+ * nonzero and OS_REG4 carries the attempt count: the next boot
|
||||
+ * escalates -- retry the same committed slot up to FLARE_AB_SLOT_TRIES,
|
||||
+ * then the other committed slot, else a timed retry of the selected
|
||||
+ * slot; the recovery FIT and USB download follow only when both
|
||||
+ * committed slots have failed. In the update regime the per-attempt
|
||||
+ * persistent-tries decrement (flare_ab_boot_attempt) has already run, so
|
||||
+ * the same reset drives the persistent revert to the other slot. A power
|
||||
+ * cycle (glb_rst_st==0) restarts at the selected slot -- no failure state
|
||||
+ * is written to flash for a committed slot.
|
||||
+ * then the other committed slot, then the recovery FIT, then USB
|
||||
+ * download. In the update regime the per-attempt persistent-tries
|
||||
+ * decrement (flare_ab_boot_attempt) has already run, so the same reset
|
||||
+ * drives the persistent revert to the other slot. A power cycle
|
||||
+ * (glb_rst_st==0) restarts at the selected slot -- no failure state is
|
||||
+ * written to flash for a committed slot.
|
||||
+ */
|
||||
+ printf("FLARE-AB: slot boot failed, resetting\n");
|
||||
+ do_reset(NULL, 0, 0, NULL);
|
||||
+ flare_ab_global_reset();
|
||||
+ /*
|
||||
+ * The reset did not take. Do not spin silently at the splash: enter the
|
||||
+ * same USB download screens as the recovery branch above (sad face and
|
||||
+ * USB plug, logo_recovery.bmp), where a host can reflash the unit.
|
||||
+ */
|
||||
+ printf("FLARE-AB: reset did not take, entering USB download\n");
|
||||
+ run_command("download", 0);
|
||||
+ hang();
|
||||
+}
|
||||
+
|
||||
@@ -927,7 +888,7 @@ index 000000000..d009525e0
|
||||
+ * per-attempt tries decrement, and fallback to the recovery FIT when
|
||||
+ * both slots are exhausted.
|
||||
+ *
|
||||
+ * Linux-side counterpart: flared's slotctl module -- the ONLY writer of
|
||||
+ * Linux-side counterpart: flared's slotctl module, the ONLY writer of
|
||||
+ * this metadata from userspace (CI-enforced).
|
||||
+ */
|
||||
+
|
||||
@@ -961,7 +922,7 @@ index 000000000..d009525e0
|
||||
+/*
|
||||
+ * One boot attempt against the selected slot: decrement tries_remaining
|
||||
+ * iff the slot is not yet successful (single-sector write, and no write
|
||||
+ * at all in the successful steady state -- spec fault 14 by construction).
|
||||
+ * at all in the successful steady state, spec fault 14 by construction).
|
||||
+ * No-op in recovery fallback mode or on a non-A/B layout.
|
||||
+ */
|
||||
+void flare_ab_boot_attempt(void);
|
||||
|
||||
Reference in New Issue
Block a user