Squash commits for public release

This commit is contained in:
2025-02-12 09:54:05 -05:00
commit 7118adc514
1108 changed files with 80873 additions and 0 deletions

31
build/boot/arm64/BUILD.gn Normal file
View File

@@ -0,0 +1,31 @@
# Use a strange __EMPTY_PATH_, empty string can't be passed as an arg.
path_to_bins = "__EMPTY_PATH_"
if (host == "llvm") {
path_to_bins = llvm_bin_path
}
devtree_compile_script_args = [
rebase_path("//firmware/$target_arch/$target_board.odt", root_build_dir),
rebase_path("$root_out_dir/firmware/$target_board.obt", root_build_dir),
"$target_arch",
"$target_board",
"$host",
"$path_to_bins",
]
action("devtree_compile") {
script = "//build/kernel/devtree_compile.py"
inputs = [ "//firmware/$target_arch/$target_board.odt" ]
outputs = [
"$root_out_dir/firmware/$target_board.obt",
"$root_out_dir/firmware/$target_board.obto",
]
args = devtree_compile_script_args
}
group("bootarm64") {
deps = [
":devtree_compile",
"rawImage:rawImage",
]
}

View File

@@ -0,0 +1,63 @@
prekernel_c_flags = [
"-ffreestanding",
"-Werror",
"-Wno-address-of-packed-member",
"-fno-builtin",
"-mcpu=cortex-a53+nofp+nosimd+nocrypto+nocrc",
"-fpie",
]
prekernel_asm_flags = [ "-mcpu=cortex-a53+nofp+nosimd+nocrypto+nocrc" ]
prekernel_ld_flags = [ "-nostdlib" ]
if (kernel_symbols) {
prekernel_c_flags += [ "-ggdb" ]
}
if (host == "gnu") {
prekernel_ld_flags += [
"-nostdinc",
"-nodefaultlibs",
"-nostartfiles",
"-lgcc",
]
}
if (host == "llvm") {
prekernel_ld_flags += [
"--oformat",
"binary",
]
}
config("prekernel_flags") {
cflags = prekernel_c_flags
asmflags = prekernel_asm_flags
ldflags = prekernel_ld_flags
defines = [ "xOS_prekernel" ]
}
linker_script =
rebase_path("//build/boot/$target_arch/prekernel/prekernel_link.ld",
root_build_dir)
executable("prekernelarm64") {
output_name = "prekernelarm64.bin"
sources = [
"//boot/arm64/prekernel/drivers/fb.c",
"//boot/arm64/prekernel/drivers/uart.c",
"//boot/arm64/prekernel/entry.S",
"//boot/arm64/prekernel/main.c",
"//boot/arm64/prekernel/vm.c",
"//boot/libboot/devtree/devtree.c",
"//boot/libboot/elf/elf_lite.c",
"//boot/libboot/log/log.c",
"//boot/libboot/mem/alloc.c",
"//boot/libboot/mem/mem.c",
]
include_dirs = [ "//boot" ]
configs = [ ":prekernel_flags" ]
ldflags = [ "-T$linker_script" ]
}

View File

@@ -0,0 +1,45 @@
/* PIC */
_pa_base = 0x0;
ENTRY(_pa_base)
SECTIONS
{
. = _pa_base;
PREKERNEL_START_OFFSET = .;
.text :
{
*(.xos_boot_text)
*(.text)
*(.text.*)
}
.rodata :
{
*(.rodata)
*(.rodata.*)
}
.data :
{
*(.data)
*(.data.*)
}
.bss :
{
*(.bss)
*(.bss.*)
*(COMMON)
}
.stack ALIGN(4K) :
{
PREKERNEL_STACK_BASE_OFFSET = .;
. += 0x1000;
PREKERNEL_STACK_TOP_OFFSET = .;
}
PREKERNEL_END_OFFSET = .;
}

View File

@@ -0,0 +1,22 @@
if (target_arch == "arm64") {
action("rawImage") {
script = "make_raw_image.py"
sources = [
"$root_build_dir/base/boot/kernel.bin",
"$root_build_dir/prekernelarm64.bin",
]
outputs = [ "$root_build_dir/rawImage.bin" ]
args = [
rebase_path("$root_build_dir/prekernelarm64.bin", root_build_dir),
rebase_path("$root_build_dir/base/boot/kernel.bin", root_build_dir),
rebase_path("$root_out_dir/firmware/$target_board.obt", root_build_dir),
rebase_path("$root_build_dir/rawImage.bin", root_build_dir),
]
deps = [
"//build/boot/arm64:devtree_compile",
"//build/boot/arm64/prekernel:prekernelarm64",
"//build/kernel:kernel_build",
]
}
}

View File

@@ -0,0 +1,77 @@
import sys
import os
import subprocess
from construct import *
from elftools.elf.elffile import ELFFile
from elftools.elf.constants import SH_FLAGS
prekernel_path = sys.argv[1]
kernel_path = sys.argv[2]
devtree_path = sys.argv[3]
out_path = sys.argv[4]
build_dir_path = os.path.dirname(os.path.abspath(sys.argv[4]))
tmp_dir_path = build_dir_path + "/tmp"
rawimage_header_path = tmp_dir_path + "/rawimage_header.bin"
# GNU-LD can't convert ELF object format to Binary on the fly.
# Checking if output is an ELF and convertining it to binary.
prekernel_header = []
with open(prekernel_path, "rb") as f:
prekernel_header = f.read(4)
if prekernel_header == b'\x7fELF':
kernel_vaddr = 0
kernel_vaddr_end = 0
with open(prekernel_path, 'rb') as elffile:
signature_section = None
for section in ELFFile(elffile).iter_sections():
if (section['sh_flags'] & SH_FLAGS.SHF_ALLOC) == SH_FLAGS.SHF_ALLOC:
kernel_vaddr_end = max(
kernel_vaddr_end, section['sh_addr'] + section['sh_size'])
output = subprocess.check_output(
"aarch64-elf-objcopy -O binary {0} {0}".format(prekernel_path), shell=True)
binary_blob_size = os.path.getsize(prekernel_path)
assert(binary_blob_size <= kernel_vaddr_end)
need_to_append = kernel_vaddr_end - binary_blob_size
with open(prekernel_path, 'r+b') as file:
_ = file.read()
padding = [0x0 for _ in range(need_to_append)]
file.write(bytearray(padding))
prekernel_size = os.path.getsize(prekernel_path)
rawimage_header_size = 8 * 8
kernel_size = os.path.getsize(kernel_path)
devtree_size = os.path.getsize(devtree_path)
ramdisk_size = 0
result = {
"kern_off": rawimage_header_size + prekernel_size,
"kern_size": kernel_size,
"devtree_off": rawimage_header_size + prekernel_size + kernel_size,
"devtree_size": devtree_size,
"ramdisk_off": 0,
"ramdisk_size": 0,
"rawimage_size": rawimage_header_size + prekernel_size + kernel_size + devtree_size + ramdisk_size,
"padding": 0,
}
rawimage_header = Struct(
"kern_off" / Int64ul,
"kern_size" / Int64ul,
"devtree_off" / Int64ul,
"devtree_size" / Int64ul,
"ramdisk_off" / Int64ul,
"ramdisk_size" / Int64ul,
"rawimage_size" / Int64ul,
"padding" / Int64ul,
).build(result)
with open(rawimage_header_path, "wb") as binfile:
binfile.write(bytes(rawimage_header))
output = subprocess.check_output("cat {0} {1} {2} {3} > {4}".format(
prekernel_path, rawimage_header_path, kernel_path, devtree_path, out_path), shell=True)