summaryrefslogtreecommitdiff
path: root/core/sboot.c
blob: 53366a0ba6e7e3a8d9bc95a5b1e8e5d188515a85 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright (c) 2026, Apollo Telephone Laboratories.
 * Provided under the BSD-3 clause.
 */

#include <efi.h>
#include <efilib.h>
#include <sboot/sboot.h>
#include <sboot/config.h>
#include <sboot/memmap.h>
#include <sboot/fwi.h>
#include <sboot/file.h>

/* Private globals */
static UINT8 *KernelBin = NULL;
static PLATFORM_MEMMAP MemMap;

/* Globals */
EFI_FILE_HANDLE gBootVolume;

EFI_STATUS
EFIAPI
efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
    BOOT_ENTRY Entry;
    EFI_STATUS Status;

    InitializeLib(ImageHandle, SystemTable);

    /* Disable the watchdog timer */
    FwiSetWatchdogTimer(
        0,
        0,
        0,
        NULL
    );

    Status = FileGetVolume(ImageHandle, &gBootVolume);
    if (EFI_ERROR(Status)) {
        Hcf();
    }

    Print(
        L"SBOOT %s - %d boot entrie(s)\n",
        SBOOT_VERSION,
        NELEM(ConfigBootEntries) - 1
    );

    SBootMenu(&Entry);
    Status = FileReadToBuffer(Entry.BootPath, (VOID **)&KernelBin);
    if (EFI_ERROR(Status)) {
        Hcf();
    }

    Status = SBootGetMemmap(&MemMap);
    if (EFI_ERROR(Status)) {
        Hcf();
    }

    /* Get out of here! */
    Status = uefi_call_wrapper(
        gBS->ExitBootServices,
        2,
        ImageHandle,
        MemMap.MapKey
    );

    if (EFI_ERROR(Status)) {
        Hcf();
    }

    for (;;);
}