U-Boot: retry the selected slot when no committed alternative remains
ci / test (push) Canceled after 0s
ci / mcdc (push) Canceled after 0s
ci / bench (push) Canceled after 0s
ci / qemu-tools (push) Canceled after 0s
ci / kernel-symbols (push) Canceled after 0s
ci / patches-apply (push) Canceled after 0s
ci / prune-artifacts (push) Canceled after 0s
ci / quality (push) Canceled after 0s
ci / kernel-build (push) Canceled after 0s
ci / badges (push) Canceled after 0s
ci / test (push) Canceled after 0s
ci / mcdc (push) Canceled after 0s
ci / bench (push) Canceled after 0s
ci / qemu-tools (push) Canceled after 0s
ci / kernel-symbols (push) Canceled after 0s
ci / patches-apply (push) Canceled after 0s
ci / prune-artifacts (push) Canceled after 0s
ci / quality (push) Canceled after 0s
ci / kernel-build (push) Canceled after 0s
ci / badges (push) Canceled after 0s
flare_ab escalated a committed slot to the recovery FIT once the other slot was not committed (retired or unconfirmed). On p54 (flare-edge#3118) that branch ran with no watchdog armed, and the panel stopped at the boot splash until a hand power cycle. When no committed alternative remains after the selected slot's attempts, the ladder now clears the PMU attempt counter (OS_REG4), arms the DW watchdog (TORR=0xbb, CR=1: system reset, about 5.6 s) and waits for the reset, so the selected slot is retried at attempt 1 of the next power session. A CRU global reset follows if the watchdog does not fire. The recovery FIT is still reached once both committed slots have failed this power session. Only the common/flare_ab.c new-file hunk of 0003-flare-ab-slots.patch changes; the other hunks are untouched. The MC/DC harness in flare-edge tests/uboot-ab covers the new branches. Refs flare-edge#3118 (cause 3) Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B1W6qGbdxD3FcrGMcjLNhv
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
fc62400157
commit
d9b35861f3
@@ -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..6a5a07e37
|
||||
index 000000000..e55ac5d5b
|
||||
--- /dev/null
|
||||
+++ b/sysdrv/source/uboot/u-boot/common/flare_ab.c
|
||||
@@ -0,0 +1,642 @@
|
||||
@@ -0,0 +1,712 @@
|
||||
+// SPDX-License-Identifier: GPL-2.0+
|
||||
+/*
|
||||
+ * flare-edge A/B slot boot for U-Boot proper.
|
||||
@@ -212,6 +212,11 @@ index 000000000..6a5a07e37
|
||||
+ * 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 */
|
||||
@@ -224,6 +229,24 @@ index 000000000..6a5a07e37
|
||||
+/* 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);
|
||||
@@ -256,6 +279,13 @@ index 000000000..6a5a07e37
|
||||
+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.
|
||||
@@ -472,6 +502,25 @@ index 000000000..6a5a07e37
|
||||
+ 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;
|
||||
@@ -531,8 +580,10 @@ index 000000000..6a5a07e37
|
||||
+ /*
|
||||
+ * 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. A power
|
||||
+ * cycle (glb_rst_st==0) restarts at the selected slot.
|
||||
+ * 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.
|
||||
+ */
|
||||
+ session = flare_ab_bump_session();
|
||||
+
|
||||
@@ -542,24 +593,42 @@ index 000000000..6a5a07e37
|
||||
+ return pref;
|
||||
+ }
|
||||
+
|
||||
+ if (session <= 2 * FLARE_AB_SLOT_TRIES &&
|
||||
+ slot_is_bootable(&ab_data.slots[other]) &&
|
||||
+ if (slot_is_bootable(&ab_data.slots[other]) &&
|
||||
+ ab_data.slots[other].successful_boot) {
|
||||
+ 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;
|
||||
+ 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: both committed slots failed this power session, recovery\n");
|
||||
+ flare_ab_force_recovery = 1;
|
||||
+ /*
|
||||
+ * 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;
|
||||
+ 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;
|
||||
+}
|
||||
@@ -732,12 +801,13 @@ index 000000000..6a5a07e37
|
||||
+ * 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, 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.
|
||||
+ * 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.
|
||||
+ */
|
||||
+ printf("FLARE-AB: slot boot failed, resetting\n");
|
||||
+ do_reset(NULL, 0, 0, NULL);
|
||||
@@ -857,7 +927,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).
|
||||
+ */
|
||||
+
|
||||
@@ -891,7 +961,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