Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions src/nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,15 @@ void nvme_ensure_shutdown(void)
nvme_asc = NULL;
}

/*
* Post-M4: an earlier stage powered ANS off and passed its SART entries on (nvme.sart=), and this
* stage hasn't started it again.
*/
bool nvme_post_m4_passed_off(void)
{
return !nvme_initialized && nvme_sart_saved_cnt && nvme_post_m4();
}

bool nvme_shutdown(void)
{
if (nvme_reboot_required) {
Expand Down
1 change: 1 addition & 0 deletions src/nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern bool nvme_keep_running_for_linux;
bool nvme_shutdown(void);
/* Post-M4: how a stage that powered ANS off tells the next one to start it again. */
bool nvme_post_m4(void);
bool nvme_post_m4_passed_off(void);
int nvme_sart_entries(struct sart_entry *entries, int max, bool *off);
char *nvme_sart_var(void);
bool nvme_set_sart_var(const char *val);
Expand Down
18 changes: 12 additions & 6 deletions src/payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,17 @@ int payload_run(void)

if (kernel && fdt) {
/*
* Linux adopts a running post-M4 ANS from boot=. Any other payload starts ANS itself:
* power it off before kboot's pcie_init(), which brings its PCIe block and the radio's
* link back up, and kboot_prepare_dt() passes the SART entries on.
* Linux adopts a running post-M4 ANS from boot=. The U-Boot we embed adopts a running
* post-M4 ANS too, and can't start one from off: if an earlier stage powered ANS off
* (nvme.sart=), start it here and hand it on running, as for boot=. Otherwise any other
* payload gets ANS as this stage found it, or powered off with the SART entries passed
* on if this stage used it.
*/
nvme_keep_running_for_linux = boot_spec != NULL;
if (!boot_spec && !nvme_shutdown())
bool nvme_started = !boot_spec && nvme_post_m4_passed_off();
if (nvme_started && !nvme_init())
goto boot_failed;
nvme_keep_running_for_linux = boot_spec || nvme_started;
if (!nvme_keep_running_for_linux && !nvme_shutdown())
goto boot_failed;
cpufreq_init();
if (smp_start_secondaries() && chip_id == T8140) {
Expand Down Expand Up @@ -593,8 +598,9 @@ int payload_run(void)

boot_failed:
next_stage.entry = NULL;
if (boot_spec) {
if (boot_spec)
kboot_set_initrd(NULL, 0);
if (nvme_keep_running_for_linux) {
nvme_keep_running_for_linux = false;
nvme_shutdown();
}
Expand Down
74 changes: 70 additions & 4 deletions tests/python/test_m3_defaults_optout.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,13 @@ def harness():
printf("SELECT %s\n", selected);
return 0;
}
static int kboot_boot(void *kernel) { printf("RESULT booted=1\n"); return 0; }
static bool nvme_keep_running_for_linux;
static int kboot_boot(void *kernel)
{
printf("NVME handoff keep=%d\n", nvme_keep_running_for_linux);
printf("RESULT booted=1\n");
return 0;
}

/* The rest of the machine payload_run() talks to */
static const char *target_type;
Expand All @@ -239,9 +245,28 @@ def harness():
static bool smp_is_alive(int cpu) { return false; }
static int smp_call_sync0(int cpu, void (*fn)(void)) { return 0; }
static void do_enable_tso(void) {}
static bool nvme_shutdown(void) { return true; }
static bool nvme_keep_running_for_linux;
static bool nvme_set_sart_var(const char *v) { return true; }
/* Post-M4 ANS (M1N1_TEST_POST_M4): powered off by an earlier stage once nvme.sart= arrives */
static bool nvme_sart_passed, nvme_started;
static bool nvme_init(void)
{
printf("NVME init\n");
nvme_started = true;
return !getenv("M1N1_TEST_NVME_INIT_FAIL");
}
static bool nvme_shutdown(void)
{
printf("NVME shutdown keep=%d\n", nvme_keep_running_for_linux);
return true;
}
static bool nvme_set_sart_var(const char *v)
{
nvme_sart_passed = true;
return true;
}
static bool nvme_post_m4_passed_off(void)
{
return getenv("M1N1_TEST_POST_M4") && nvme_sart_passed && !nvme_started;
}
static int display_configure(const char *s) { printf("DISPLAY %s\n", s); return 0; }
static int display_configure_second(const char *s) { printf("DISPLAY2 %s\n", s); return 0; }
#define T8132 0x8132
Expand Down Expand Up @@ -928,3 +953,44 @@ def test_a_swallowed_hib_line_is_a_lost_line(tools, build):

def test_stage1_does_not_hand_hib_on(tools):
assert b"hib=" not in stage1(tools, b"hib=1\n")


# ---- post-M4 ANS: the embedded U-Boot adopts a running ANS and can't start one from off ----

SART = b"nvme.sart=" + b"0" * 48 + b"\n"


def nvme_events(r):
return [line[5:] for line in r.stdout.splitlines() if line.startswith("NVME ")]


@pytest.mark.parametrize("build", STAGE2)
def test_post_m4_ans_passed_off_is_started_for_the_payload(tools, build, monkeypatch):
monkeypatch.setenv("M1N1_TEST_POST_M4", "1")
b = boot(tools, build, b"", trailer=SART)
booted(b)
assert nvme_events(b) == ["init", "handoff keep=1"], b.stdout


@pytest.mark.parametrize("build", STAGE2)
def test_post_m4_ans_start_failure_stops_the_handoff(tools, build, monkeypatch):
monkeypatch.setenv("M1N1_TEST_POST_M4", "1")
monkeypatch.setenv("M1N1_TEST_NVME_INIT_FAIL", "1")
b = boot(tools, build, b"", trailer=SART)
assert b.rc == -1 and not b.booted, b.stdout
assert nvme_events(b)[0] == "init" and "handoff keep=1" not in nvme_events(b)


@pytest.mark.parametrize("build", STAGE2)
def test_ans_left_as_found_without_sart_entries(tools, build, monkeypatch):
monkeypatch.setenv("M1N1_TEST_POST_M4", "1")
b = boot(tools, build, b"")
booted(b)
assert nvme_events(b) == ["shutdown keep=0", "handoff keep=0"], b.stdout


@pytest.mark.parametrize("build", STAGE2)
def test_pre_m4_ignores_sart_entries(tools, build):
b = boot(tools, build, b"", trailer=SART)
booted(b)
assert nvme_events(b) == ["shutdown keep=0", "handoff keep=0"], b.stdout
Loading