morpheus_bootloader/tui/distro_launcher/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use super::ui::DistroLauncher;
use crate::boot::loader::BootError;
use crate::tui::input::Keyboard;
use crate::tui::renderer::{Screen, EFI_BLACK, EFI_DARKGREEN, EFI_GREEN, EFI_LIGHTGREEN, EFI_RED};
use alloc::string::String;

const MAX_KERNEL_BYTES: usize = 64 * 1024 * 1024;

impl DistroLauncher {
    pub(super) fn await_failure(
        screen: &mut Screen,
        keyboard: &mut Keyboard,
        start_line: usize,
        message: &str,
        log_tag: &'static str,
    ) {
        morpheus_core::logger::log(log_tag);
        screen.put_str_at(5, start_line, message, EFI_RED, EFI_BLACK);
        screen.put_str_at(
            5,
            start_line + 2,
            "Press any key to return...",
            EFI_DARKGREEN,
            EFI_BLACK,
        );
        keyboard.wait_for_key();
    }
    pub(super) fn dump_logs_to_screen(screen: &mut Screen) {
        let start_y = 20;

        screen.put_str_at(5, start_y, "=== DEBUG LOGS ===", EFI_LIGHTGREEN, EFI_BLACK);

        // Show the last N logs that fit on screen
        let max_logs_to_show = (screen.height() - start_y - 2).min(30);

        for (i, log_msg) in morpheus_core::logger::get_last_n_logs(max_logs_to_show).enumerate() {
            let y = start_y + 1 + i;
            if y >= screen.height() - 1 {
                break;
            }
            screen.put_str_at(7, y, log_msg, EFI_GREEN, EFI_BLACK);
        }
    }
    pub(super) fn describe_boot_error(error: &BootError) -> alloc::string::String {
        match error {
            BootError::KernelParse(e) => alloc::format!("Kernel parse failed: {:?}", e),
            BootError::KernelAllocation(e) => alloc::format!("Kernel allocation failed: {:?}", e),
            BootError::KernelLoad(e) => alloc::format!("Kernel load failed: {:?}", e),
            BootError::BootParamsAllocation(e) => {
                alloc::format!("Boot params allocation failed: {:?}", e)
            }
            BootError::CmdlineAllocation(e) => alloc::format!("Cmdline allocation failed: {:?}", e),
            BootError::InitrdAllocation(e) => alloc::format!("Initrd allocation failed: {:?}", e),
            BootError::MemorySnapshot(e) => alloc::format!("Memory map build failed: {:?}", e),
            BootError::ExitBootServices(e) => alloc::format!("ExitBootServices failed: {:?}", e),
        }
    }
}