main: refactor booting logic

- Move main headers from include/ to include/main/
- Split booting logic to boot.c and boot-fdt.c to avoid cluttering main()
- Conditionally compile boot-fdt only if libfdt is used
- Add some better logging

Change was tested on qemu-virt, which succesfully booted a kernel:
$ qemu-system-aarch64 -machine virt -cpu cortex-a72 -nographic -m 512m -kernel uniLoader.o
[INFO]              .__.____                     .___
[INFO]  __ __  ____ |__|    |    _________     __| _/___________
[INFO] |  |  \/    \|  |    |   /  _ \__  \   / __ |/ __ \_  __\
[INFO] |  |  /   |  \  |    |__(  <_> ) __ \_/ /_/ \  ___/|  |\/
[INFO] |____/|___|  /__|_______ \____(____  /\____ |\___  >__|
[INFO]            \/           \/         \/      \/    \/
[INFO] passed board initialization
[INFO] welcome to uniLoader (e69eba1) - date 2026-02-21 14:01:34 on qemu-virt
[INFO] Booting kernel...
[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd083]
[    0.000000] Linux version 6.12.73+deb13-arm64 (debian-kernel@lists.debian.org) (aarch64-linux-gnu-gcc-14 (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44) #1 SMP Debian 6.12.73-1 (2026-02-17)
[    0.000000] KASLR enabled
[    0.000000] random: crng init done
[...]

Signed-off-by: Igor Belwon <igor.belwon@mentallysanemainliners.org>
This commit is contained in:
Igor Belwon
2026-02-21 13:19:20 +01:00
committed by Ивайло Иванов
parent ecd7ebf677
commit eaacd962db
7 changed files with 96 additions and 53 deletions

11
include/main/boot-fdt.h Normal file
View File

@@ -0,0 +1,11 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2026, Igor Belwon <igor.belwon@mentallysanemainliners.org>
*/
#ifndef BOOT_FDT_H_
#define BOOT_FDT_H_
void patch_dtb(void* dt);
#endif // BOOT_FDT_H_

23
include/main/boot.h Normal file
View File

@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2022, Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
* Copyright (c) 2026, Igor Belwon <igor.belwon@mentallysanemainliners.org>
*/
#ifndef BOOT_H_
#define BOOT_H_
extern unsigned long kernel_size;
extern unsigned long ramdisk_size;
#ifdef __aarch64__
extern void load_kernel_and_jump(void* dtb, void* x1, void* x2, void* x3,
void* kernel);
#elif __arm__
extern void load_kernel_and_jump(unsigned int r0, unsigned int r1,
void* dtb_addr, void* kernel_entry);
#endif
void boot_kernel(void* dt, void* kernel, void* ramdisk);
#endif // BOOT_H_

View File

@@ -3,14 +3,9 @@
* Copyright (c) 2022, Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
*/
#include <stddef.h>
#ifndef MAIN_H_ /* Include guard */
#define MAIN_H_
extern unsigned long kernel_size;
extern unsigned long ramdisk_size;
#define HANG() while(1) {}
/*
@@ -27,14 +22,6 @@ extern unsigned long ramdisk_size;
} \
} while (0)
#ifdef __aarch64__
extern void load_kernel_and_jump(void* dtb, void* x1, void* x2, void* x3,
void* kernel);
#elif __arm__
extern void load_kernel_and_jump(unsigned int r0, unsigned int r1,
void* dtb_addr, void* kernel_entry);
#endif
extern void soc_init(void);
#endif // MAIN_H_