Skip to content
Closed
27 changes: 0 additions & 27 deletions .github/copilot-instructions.md

This file was deleted.

27 changes: 0 additions & 27 deletions AGENTS.md

This file was deleted.

27 changes: 0 additions & 27 deletions CLAUDE.md

This file was deleted.

27 changes: 0 additions & 27 deletions GEMINI.md

This file was deleted.

9 changes: 6 additions & 3 deletions docs/boot-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ and a guest at EL1 gets nothing.

A hibernation image restores every page the OS saved to the frame it came from, so the
boot that resumes it must give the OS the same RAM and keep the same ranges from it.
The payload line `hib=1`, in Stage 2's own lines (Stage 1 does not hand it on), asks
The hibernation layout is on by default on a production Stage 2, so Linux can
hibernate without a test payload line. `hib=0` turns it off. `hib=1`, in Stage 2's
own lines (Stage 1 does not hand it on), also keeps the boot watchdog armed
across the hand-off of a resume boot, and still asks
kboot for a fixed layout on T6040:

- the CTXR exec window is the part of CTXR_D that every placement of the boot object
Expand All @@ -86,8 +89,8 @@ tree in the slot.
kboot refuses the layout, says why, and boots without it when the window is not the
fixed one or is not below the slot, or when aura, the boot arguments, what iBoot and
Stage 1 placed, or the heap reach the slot, or when the fixed range meets a carveout or
a firmware range. Without the properties Linux refuses to hibernate. Without `hib=1`
nothing changes, the window included.
a firmware range. Without the properties Linux refuses to hibernate. `hib=0` turns the layout
off and leaves the window as it was without a fixed layout.

## DebugUSB interception (development builds)

Expand Down
21 changes: 21 additions & 0 deletions src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,27 @@ void kboot_request_hibernate_layout(bool on)
ctxr_exec_request_fixed_window(on && chip_id == T6040);
}

/* Whether this boot may resume from a hibernation image (the hib=1 payload line). */
static bool hib_resume_boot;

void kboot_request_hibernate_resume_boot(bool on)
{
hib_resume_boot = on;
if (on)
kboot_request_hibernate_layout(true);
}

bool kboot_hibernate_resume_boot(void)
{
return hib_resume_boot;
}

/* Whether this boot publishes the fixed hibernation layout to Linux. */
bool kboot_hibernate_layout_requested(void)
{
return hib_requested;
}

/* Whether [start, end) meets a range iBoot or the firmware owns, saying which. */
static bool hib_fixed_range_taken(u64 start, u64 end)
{
Expand Down
3 changes: 3 additions & 0 deletions src/kboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ struct kernel_header {

void kboot_set_initrd(void *start, size_t size);
void kboot_request_hibernate_layout(bool on);
bool kboot_hibernate_layout_requested(void);
void kboot_request_hibernate_resume_boot(bool on);
bool kboot_hibernate_resume_boot(void);
int kboot_set_chosen(const char *name, const char *value);
void kboot_delete_chosen(const char *name);
void kboot_set_config_lost(void);
Expand Down
22 changes: 21 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ void get_device_info(void)
printf("No chosen node!\n");
}

/*
* A production boot must publish the layout so Linux can hibernate, without
* a test payload line. hib=0 in the payload turns it off. The layout is
* still refused later if this chip or this placement cannot have it.
*/
kboot_request_hibernate_layout(true);

printf("\n");
}

Expand Down Expand Up @@ -544,7 +551,20 @@ void aura_main(void)
if (aura_trial_enabled() && wdt_arm_trial())
printf("WDT: could not arm the trial watchdog\n");
#if defined(CHAINLOADING) && defined(ESP_STAGE2)
/* A plain boot's next stage brings its own watchdog: leave the hardware as Stage 2 found it. */
/*
* A resume from hibernation (hib=1) hands to a kernel that must unfreeze its own devices
* before it can pet a watchdog; a step that wedges there would otherwise wait for the power
* button. Keep WD2 armed in reset mode across the hand-off, as a trial boot does: the kernel's
* driver finds it running and keeps it fed on a good resume, and a wedged one resets instead.
* The layout is on by default and is not itself a resume; only hib=1 keeps the watchdog.
*/
else if (kboot_hibernate_resume_boot() && wdt_arm_seconds(WDT_BOOT_SECONDS))
printf("WDT: could not arm the hibernation-resume watchdog\n");
else if (kboot_hibernate_resume_boot())
printf("WDT: hibernation-resume watchdog armed until the kernel takes it (%u s)\n",
WDT_BOOT_SECONDS);
/* A plain boot without hib=1 brings its own watchdog: leave the hardware as Stage 2 found it.
*/
else if (!aura_trial_enabled())
wdt_disarm_boot();
#endif
Expand Down
5 changes: 4 additions & 1 deletion src/payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ static bool check_var(u8 **p)
} else if (IS_VAR("tso=")) {
enable_tso = val[0] == '1';
} else if (IS_VAR("hib=")) {
kboot_request_hibernate_layout(val[0] == '1');
bool on = val[0] == '1';

kboot_request_hibernate_layout(on);
kboot_request_hibernate_resume_boot(on);
} else {
printf("Unknown variable %.*s\n", (int)(val - (char *)*p - 1), (char *)*p);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/python/test_m3_defaults_optout.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def harness():
/* kboot's handoff: /chosen as dt_set_chosen() writes it, then what the GPU code would see */
static void kboot_set_initrd(void *start, size_t size) {}
static void kboot_request_hibernate_layout(bool on) { printf("HIB %d\n", on); }
static void kboot_request_hibernate_resume_boot(bool on) { printf("HIBRESUME %d\n", on); }
static int kboot_prepare_dt(void *fdt)
{
assert(!fdt_open_into(fdt, dt, sizeof(blob)));
Expand Down Expand Up @@ -1029,9 +1030,11 @@ def test_hib_line_asks_for_the_layout_and_is_no_loss(tools, build):
b = boot(tools, build, b"hib=1\n")
booted(b)
assert hib_requests(b) == ["1"] and set(AIR) <= b.armed
assert [line[10:] for line in b.stdout.splitlines() if line.startswith("HIBRESUME ")] == ["1"]
b = boot(tools, build, b"hib=1\nhib=0\n")
booted(b)
assert hib_requests(b) == ["1", "0"]
assert [line[10:] for line in b.stdout.splitlines() if line.startswith("HIBRESUME ")] == ["1", "0"]


@pytest.mark.parametrize("build", STAGE2)
Expand Down
3 changes: 2 additions & 1 deletion tests/python/test_t6040_hibernate_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,5 @@ def test_hib_line_requests_the_layout():
names = payload[payload.index("static const char *const config_names[]"):]
assert '"hib="' in names[:names.index("};")]
var = payload[payload.index(' } else if (IS_VAR("hib=")) {'):]
assert var.split("\n")[1].strip() == "kboot_request_hibernate_layout(val[0] == '1');"
assert "kboot_request_hibernate_layout(on)" in var[:500]
assert "kboot_request_hibernate_resume_boot(on)" in var[:500]