mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-02 19:09:16 +00:00
build: add initial Bootloader implementation
Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
64
Bootloader/firmware/aarch64/Makefile
Normal file
64
Bootloader/firmware/aarch64/Makefile
Normal file
@ -0,0 +1,64 @@
|
||||
define find-sources
|
||||
$(shell find ./ -type f -name '$1' $(shell echo $(foreach board,$(filter-out $(BOARD_TYPE),$(AVAILABLE_BOARDS)), -not -path \"./$(board)/*\")) -print0 | xargs -0)
|
||||
endef
|
||||
|
||||
S_SOURCES := $(call find-sources,*.S)
|
||||
s_SOURCES := $(call find-sources,*.s)
|
||||
C_SOURCES := $(call find-sources,*.c)
|
||||
|
||||
define find-common-sources
|
||||
$(shell find ../../common -type f -name '$1' -print0 | xargs -0)
|
||||
endef
|
||||
|
||||
C_COMMON_SOURCES := $(call find-common-sources,*.c)
|
||||
|
||||
OBJ = $(s_SOURCES:.s=.o) $(S_SOURCES:.S=.o) $(C_SOURCES:.c=.o) $(C_COMMON_SOURCES:.c=.o)
|
||||
|
||||
LDFLAGS = -static -nostdlib -nodefaultlibs -nolibc \
|
||||
-Wl,-static,--no-dynamic-linker,-ztext \
|
||||
-zmax-page-size=0x1000 \
|
||||
-Wl,-Map boot.map -fno-pic -fno-pie
|
||||
|
||||
CFLAGS := \
|
||||
$(INCLUDE_DIR) \
|
||||
-D__kernel__='1' \
|
||||
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
|
||||
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"' \
|
||||
-fno-pic -fno-pie -fno-builtin -I../../include
|
||||
|
||||
CFLAGS += -mcmodel=large
|
||||
LDFLAGS += -T$(BOARD_TYPE)/linker.ld
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always
|
||||
# CFLAGS += -fsanitize=undefined
|
||||
CFLAGS += -fstack-check -fverbose-asm
|
||||
LDFLAGS += -ggdb3 -O0
|
||||
ASFLAGS += -g --gstabs+ --gdwarf-5 -D
|
||||
endif # DEBUG
|
||||
|
||||
default:
|
||||
$(error Do not run this Makefile directly!)
|
||||
|
||||
build: boot.bin
|
||||
|
||||
boot.bin: $(OBJ)
|
||||
$(info Linking $@)
|
||||
$(CC) $(LDFLAGS) $(OBJ) -o tmp.elf
|
||||
$(OBJCOPY) tmp.elf -O binary ../../boot.bin
|
||||
# rm tmp.elf
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CC) $(CFLAGS) -fstack-protector-all -std=c17 -c $< -o $@
|
||||
|
||||
%.o: %.S
|
||||
$(info Compiling $<)
|
||||
$(AS) $(ASFLAGS) -c $< -o $@
|
||||
|
||||
%.o: %.s
|
||||
$(info Compiling $<)
|
||||
$(AS) $(ASFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) boot.map
|
1
Bootloader/firmware/aarch64/raspi3
Symbolic link
1
Bootloader/firmware/aarch64/raspi3
Symbolic link
@ -0,0 +1 @@
|
||||
./raspi4
|
49
Bootloader/firmware/aarch64/raspi4/boot.S
Normal file
49
Bootloader/firmware/aarch64/raspi4/boot.S
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
This file is part of Lynx Bootloader.
|
||||
|
||||
Lynx Bootloader is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Lynx Bootloader is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Lynx Bootloader. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
.section ".text.boot"
|
||||
|
||||
.extern __bss_start
|
||||
.extern __bss_end
|
||||
.extern __bss_size
|
||||
|
||||
.global _start
|
||||
_start:
|
||||
/* Keep only the main core */
|
||||
mrs x1, mpidr_el1
|
||||
and x1, x1, #3
|
||||
cbz x1, 2f
|
||||
|
||||
/* Halt */
|
||||
1: wfe
|
||||
b 1b
|
||||
|
||||
/* Initialize the stack */
|
||||
2: ldr x1, =_start
|
||||
mov sp, x1
|
||||
|
||||
/* Clear the BSS */
|
||||
ldr x1, =__bss_start
|
||||
ldr w2, =__bss_size
|
||||
3: cbz w2, 4f
|
||||
str xzr, [x1], #8
|
||||
sub w2, w2, #1
|
||||
cbnz w2, 3b
|
||||
|
||||
/* Start the kernel */
|
||||
4: bl _aarch64_start
|
||||
b 1b
|
32
Bootloader/firmware/aarch64/raspi4/init.c
Normal file
32
Bootloader/firmware/aarch64/raspi4/init.c
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
This file is part of Lynx Bootloader.
|
||||
|
||||
Lynx Bootloader is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Lynx Bootloader is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Lynx Bootloader. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <types.h>
|
||||
|
||||
uintptr_t __stack_chk_guard = 0;
|
||||
|
||||
__noreturn __no_stack_protector void __stack_chk_fail(void)
|
||||
{
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
int main();
|
||||
__attribute__((section(".bootstrap.text"))) void _aarch64_start(uint64_t dtb_ptr32, uint64_t x1, uint64_t x2, uint64_t x3)
|
||||
{
|
||||
main();
|
||||
}
|
70
Bootloader/firmware/aarch64/raspi4/linker.ld
Normal file
70
Bootloader/firmware/aarch64/raspi4/linker.ld
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
This file is part of Lynx Bootloader.
|
||||
|
||||
Lynx Bootloader is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Lynx Bootloader is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Lynx Bootloader. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
OUTPUT_FORMAT("elf64-littleaarch64")
|
||||
OUTPUT_ARCH(aarch64)
|
||||
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x80000;
|
||||
__start = .;
|
||||
__text_start = .;
|
||||
.text :
|
||||
{
|
||||
KEEP(*(.text.boot))
|
||||
*(.text)
|
||||
}
|
||||
. = ALIGN(4096);
|
||||
__text_end = .;
|
||||
|
||||
__rodata_start = .;
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata)
|
||||
}
|
||||
. = ALIGN(4096);
|
||||
__rodata_end = .;
|
||||
|
||||
__data_start = .;
|
||||
.data :
|
||||
{
|
||||
*(.data)
|
||||
}
|
||||
. = ALIGN(4096);
|
||||
__data_end = .;
|
||||
|
||||
__bss_start = .;
|
||||
.bss :
|
||||
{
|
||||
bss = .;
|
||||
*(.bss)
|
||||
}
|
||||
. = ALIGN(4096);
|
||||
__bss_end = .;
|
||||
__bss_size = __bss_end - __bss_start; /* SIZEOF(.bss); */
|
||||
__end = .;
|
||||
|
||||
/DISCARD/ :
|
||||
{
|
||||
*(.comment*)
|
||||
*(.gnu*)
|
||||
*(.note*)
|
||||
*(.eh_frame*)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user