From 6538e70b391ab51896ee3c9f7bb7a5cc4b249373 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Thu, 17 Sep 2009 19:19:03 +0300 Subject: [PATCH] Fixed few issues with loader and basic image loading. Declaring section of the form: .align 4 .section "kernel" .incbin "path-to-kernel" And defining a linker variable before the section output does not always seem to work. The linker seems to add padding even though .align directive comes before .section modified: SConstruct.loader modified: loader/linker.lds modified: loader/main.c --- SConstruct.loader | 7 +++++-- loader/linker.lds | 2 +- loader/main.c | 26 ++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/SConstruct.loader b/SConstruct.loader index fc63086..58ab851 100644 --- a/SConstruct.loader +++ b/SConstruct.loader @@ -33,7 +33,8 @@ env = Environment(CC = 'arm-none-eabi-gcc', ASFLAGS = ['-D__ASSEMBLY__'], PROGSUFFIX = '.elf', ENV = {'PATH' : os.environ['PATH']}, - LIBS = ['gcc'], + LIBS = ['gcc', 'elf', 'c-baremetal', 'gcc'], + LIBPATH = [join('build', LIBELF_PATH), join('build', LIBC_PATH)], CPPPATH = ['#include', LIBC_INCPATH, LIBELF_INCPATH]) libc = SConscript('loader/libs/c/SConscript', \ @@ -45,4 +46,6 @@ libelf = SConscript('loader/libs/elf/SConscript', exports = { 'env' : env }, \ loader_objs = SConscript('loader/SConscript', exports = { 'env' : env }, \ duplicate = 0, variant_dir = 'build/loader') -env.Program('build/final.elf', [loader_objs + libc + libelf]) +env.Program('build/final.elf', [libelf + libc + loader_objs]) +Depends(loader_objs, libelf) +Depends(loader_objs, libc) diff --git a/loader/linker.lds b/loader/linker.lds index f25b5db..81a630d 100644 --- a/loader/linker.lds +++ b/loader/linker.lds @@ -13,7 +13,6 @@ SECTIONS .rodata1 : { *(.rodata1) } .data : { - *(.data) _start_kernel = .; *(.kernel) _end_kernel = .; @@ -21,6 +20,7 @@ SECTIONS _start_containers = .; *(.containers) _end_containers = .; + *(.data) } .got : { *(.got) *(.got.plt) } .bss : { *(.bss) } diff --git a/loader/main.c b/loader/main.c index 988305e..148da7e 100644 --- a/loader/main.c +++ b/loader/main.c @@ -1,4 +1,5 @@ #include +#include #include #include #include "arch.h" @@ -22,24 +23,41 @@ void load_container_images(unsigned long start, unsigned long end) } */ + +int load_elf_image(unsigned long **entry, void *filebuf) +{ + if (!elf32_checkFile((struct Elf32_Header *)filebuf)) { + **entry = (unsigned long)elf32_getEntryPoint((struct Elf32_Header *)filebuf); + printf("Entry point: %lx\n", **entry); + } else { + printf("Not a valid elf image.\n"); + return -1; + } + if (!elf_loadFile(filebuf, 1)) { + printf("Elf image seems valid, but unable to load.\n"); + return -1; + } + return 0; +} + int main(void) { - void *kernel_entry = 0; + unsigned long *kernel_entry; arch_init(); printf("ELF Loader: Started.\n"); printf("Loading the kernel...\n"); -// load_elf_image(&kernel_entry, _start_kernel, _end_kernel); + load_elf_image(&kernel_entry, (void *)_start_kernel); printf("Loading containers...\n"); // load_container_images(_start_containers, _end_containers) - printf("elf-loader:\tkernel entry point is %p\n", kernel_entry); + printf("elf-loader:\tkernel entry point is %lx\n", *kernel_entry); // arch_start_kernel(kernel_entry); - printf("elf-loader:\tKernel start failed!\n"); +// printf("elf-loader:\tKernel start failed!\n"); return -1; }