Skip to content

Add Bootloader#42

Open
GoscZnickiem wants to merge 72 commits intoOperacja-System:mainfrom
GoscZnickiem:bootloader
Open

Add Bootloader#42
GoscZnickiem wants to merge 72 commits intoOperacja-System:mainfrom
GoscZnickiem:bootloader

Conversation

@GoscZnickiem
Copy link
Copy Markdown
Collaborator

@GoscZnickiem GoscZnickiem commented Jun 10, 2025

A simple bootloader with basic kernel loading capabilities.

@GoscZnickiem GoscZnickiem changed the title Bootloader Add Bootloader Jun 10, 2025
@GoscZnickiem GoscZnickiem force-pushed the bootloader branch 3 times, most recently from 13044f7 to f991767 Compare June 12, 2025 10:45
@GoscZnickiem GoscZnickiem requested a review from Kamilosok August 16, 2025 16:54
Copy link
Copy Markdown
Collaborator

@qbojj qbojj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toolchain change should be in separate PR.
There are still some style guide inconsistencies.
In multiple places the cleanup code is incomplete or non-existent.
From what I remember only u-boot.bin is required so you can try to remove everything else from external/u-boot

Comment thread disk_creation/qemu.log
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this file even here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question. No idea. Love git sneaking in files that should never appear.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sneaky file in the pocket
image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in a separate PR.

Comment thread src/bootloader/config.c
Comment thread src/bootloader/config.c
#include "log.h"
#include "partition.h"

#define META_CONFIG_PATH L"EFI\\BOOT\\conf.meta"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a TODO to change this to be runtime configurable or to support (so multiple installations could be run with only one bootloader binary instance)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

Comment thread src/bootloader/config.h
Comment on lines +31 to +32
// EFI_FILE_PROTOCOL** required;
// UINTN required_count;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are meant to comment on something and not remove unwanted code. We use git for a reason.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or it's something that can only be implemented with further development from other groups, either way you're right about this needing to be adressed in some way, maybe an explanation?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is something to be implemented, just add a TODO: ...

Comment thread src/bootloader/loader.c

loader_t g_loader;

status_t initialize_loader(void) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

g_loader.* are not closed on failure

EFI_FILE_SYSTEM_INFO* file_system_info = nullptr;
UINTN file_system_info_size = 0;
EFI_GUID file_system_info_guid = EFI_FILE_SYSTEM_INFO_ID;
status = root->GetInfo(root, &file_system_info_guid, &file_system_info_size, file_system_info);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be clearer if the last arg here would be explicitly nullptr and just later defined and assigned

#include "error.h"

typedef struct {
UINTN flags;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either document flags or you can use bitfields with normal names

Copy link
Copy Markdown
Collaborator

@Kamilosok Kamilosok Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah bit more info ✔️

Comment thread src/bootloader/kernel.c
Comment on lines +56 to +74
status = g_system_table->BootServices->GetMemoryMap(&map_size, nullptr, &map_key, &desc_size, &desc_version);
if (status != EFI_BUFFER_TOO_SMALL) {
err(L"Failed to get memory map size. BootServices.GetMemoryMap() return code: %u", status);
exit();
}

map_size += 8 * desc_size;

mem_map = AllocatePool(map_size);
if (mem_map == nullptr) {
err(L"Failed to allocate memory map");
exit();
}

status = g_system_table->BootServices->GetMemoryMap(&map_size, mem_map, &map_key, &desc_size, &desc_version);
if (EFI_ERROR(status)) {
err(L"Failed to create memory map. BootServices.GetMemoryMap() return code: %u", status);
exit();
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part should be in a loop untill success, as allocating memory may change the mem map

Comment thread src/bootloader/elf/elf.c
Copy link
Copy Markdown
Collaborator

@Kamilosok Kamilosok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a bit to say

Comment thread src/bootloader/error.h
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe expanding the types of errors would be useful.

Comment thread src/bootloader/ext2.c
#include "error.h"
#include "log.h"

#define EXT2_DRIVER_PATH L"EFI\\BOOT\\ext2.efi"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this always going to be the same?

Comment thread src/bootloader/kernel.c
exit();
}

map_size += 8 * desc_size;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't using sizeof(...) be better?

Comment thread src/bootloader/kernel.c
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no ending of logging when an error occurs, or before getting to the final loop.

Comment thread src/bootloader/main.c

log(L"Starting kernel...");
kernel_start();
err(L"Kernel returned");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we can't do anything more with a returning kernel?

#include "error.h"

typedef struct {
UINTN flags;
Copy link
Copy Markdown
Collaborator

@Kamilosok Kamilosok Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah bit more info ✔️

@Kamilosok Kamilosok assigned Kamilosok and GoscZnickiem and unassigned Kamilosok Jan 27, 2026
@Kamilosok Kamilosok added enhancement help wanted Extra attention is needed labels Jan 27, 2026
@frogrammer9 frogrammer9 added new feature Added new functionality and removed enhancement labels Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed new feature Added new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants