Changeset cfdeedc in mainline for boot


Ignore:
Timestamp:
2018-10-21T23:12:23Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bf05c74
Parents:
d59718e
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-21 22:53:48)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-21 23:12:23)
Message:

Keep kernel in ELF format

By keeping kernel in an ELF file (instead of converting it to
a flat binary), we can use the information it contains, like
symbol table and debug info.

We can also later implement more advanced functionality, like
loading kernel at multiple discontiguous blocks, or loading
a position-independent kernel at a randomized address.

Currently the functionality is quite restricted, to keep changes
to a minimum. Code in boot/generic/src/kernel.c validates that
the kernel image was built with the same addresses as the boot
loader uses, giving an extra level of sanity checking compared
to a flat binary.

Location:
boot
Files:
2 added
19 edited

Legend:

Unmodified
Added
Removed
  • boot/Makefile.common

    rd59718e rcfdeedc  
    250250
    251251COMPONENTS = \
    252         $(KERNEL_PATH)/kernel.bin \
     252        $(KERNEL_PATH)/kernel.elf \
    253253        $(INIT_TASKS) \
    254254        $(INITRD).img
  • boot/Makefile.grub

    rd59718e rcfdeedc  
    8585        for module in $(MODULES) ; do \
    8686                echo "  echo 'Loading $$module'" >> $(BOOT_CONFIG) ; \
    87                 if [ "$$module" = "kernel.bin" ] ; then \
     87                if [ "$$module" = "kernel.elf" ] ; then \
    8888                        echo "  $(MULTIBOOT_CMD) /boot/$$module" >> $(BOOT_CONFIG) ; \
    8989                else \
  • boot/arch/arm32/Makefile.inc

    rd59718e rcfdeedc  
    107107        generic/src/gzip.c \
    108108        generic/src/tar.c \
     109        generic/src/kernel.c \
    109110        generic/src/payload.c
  • boot/arch/arm32/src/main.c

    rd59718e rcfdeedc  
    5050#include <arch/cp15.h>
    5151#include <payload.h>
     52#include <kernel.h>
    5253
    5354static void clean_dcache_poc(void *address, size_t size)
     
    104105        clean_dcache_poc(boot_pt, PTL0_ENTRIES * PTL0_ENTRY_SIZE);
    105106
     107        uintptr_t entry = check_kernel((void *) PA2KA(BOOT_OFFSET));
     108
    106109        printf("Booting the kernel...\n");
    107         jump_to_kernel((void *) PA2KA(BOOT_OFFSET), &bootinfo);
     110        jump_to_kernel((void *) entry, &bootinfo);
    108111}
    109112
  • boot/arch/ia64/Makefile.inc

    rd59718e rcfdeedc  
    6161        generic/src/tar.c \
    6262        generic/src/gzip.c \
     63        generic/src/kernel.c \
    6364        generic/src/payload.c
    6465
  • boot/arch/ia64/include/arch/arch.h

    rd59718e rcfdeedc  
    3636#define LOADER_ADDRESS  0x4400000
    3737#define KERNEL_ADDRESS  0x4800000
     38#define KERNEL_VADDRESS 0xe000000004800000
    3839
    3940#define STACK_SIZE                   8192
  • boot/arch/ia64/src/main.c

    rd59718e rcfdeedc  
    4444#include <errno.h>
    4545#include <payload.h>
     46#include <kernel.h>
    4647
    4748#define DEFAULT_MEMORY_BASE             0x4000000ULL
     
    182183            (uintptr_t) kernel_start, NULL);
    183184
    184         printf("Booting the kernel ...\n");
    185         jump_to_kernel(&bootinfo, kernel_start);
     185        uintptr_t entry = check_kernel(kernel_start);
     186
     187        // FIXME: kernel's entry point is linked at a different address than
     188        //        where it is run from.
     189        entry = entry - KERNEL_VADDRESS + KERNEL_ADDRESS;
     190
     191        printf("Booting the kernel at %p...\n", (void *) entry);
     192        jump_to_kernel(&bootinfo, (void *) entry);
    186193}
  • boot/arch/mips32/Makefile.inc

    rd59718e rcfdeedc  
    8888        generic/src/gzip.c \
    8989        generic/src/tar.c \
     90        generic/src/kernel.c \
    9091        generic/src/payload.c
  • boot/arch/mips32/src/main.c

    rd59718e rcfdeedc  
    4040#include <errno.h>
    4141#include <payload.h>
     42#include <kernel.h>
    4243
    4344static bootinfo_t *bootinfo = (bootinfo_t *) PA2KA(BOOTINFO_OFFSET);
     
    7879        }
    7980
    80         printf("Booting the kernel ... \n");
    81         jump_to_kernel((void *) PA2KA(BOOT_OFFSET), bootinfo);
     81        uintptr_t entry = check_kernel(kernel_start);
     82
     83        printf("Booting the kernel...\n");
     84        jump_to_kernel((void *) entry, bootinfo);
    8285}
  • boot/arch/ppc32/Makefile.inc

    rd59718e rcfdeedc  
    7676        generic/src/gzip.c \
    7777        generic/src/tar.c \
     78        generic/src/kernel.c \
    7879        generic/src/payload.c
  • boot/arch/ppc32/_link.ld.in

    rd59718e rcfdeedc  
    66                loader_start = .;
    77                *(BOOTSTRAP);
    8                 *(REALMODE);
    98                *(.text);
    109        }
  • boot/arch/ppc32/src/asm.S

    rd59718e rcfdeedc  
    152152FUNCTION_END(jump_to_kernel)
    153153
    154 .section REALMODE, "ax"
    155 
    156 .align PAGE_WIDTH
    157154SYMBOL(real_mode)
    158155
  • boot/arch/ppc32/src/main.c

    rd59718e rcfdeedc  
    4242#include <errno.h>
    4343#include <payload.h>
     44#include <kernel.h>
    4445
    4546#define BALLOC_MAX_SIZE  131072
     
    6869        printf(" %p|%p: real mode trampoline\n", &real_mode, real_mode_pa);
    6970        printf(" %p|%p: boot info structure\n", &bootinfo, bootinfo_pa);
    70         printf(" %p|%p: kernel entry point\n",
    71             (void *) PA2KA(BOOT_OFFSET), (void *) BOOT_OFFSET);
    7271        printf(" %p|%p: loader entry point\n",
    7372            (void *) LOADER_ADDRESS, loader_address_pa);
     
    144143        }
    145144
     145        uintptr_t entry = check_kernel_translated(inflate_base, 0);
     146
    146147        printf("Booting the kernel...\n");
    147         jump_to_kernel(bootinfo_pa, transtable_pa, pages, real_mode_pa,
    148             PA2KA(BOOT_OFFSET));
     148        jump_to_kernel(bootinfo_pa, transtable_pa, pages, real_mode_pa, entry);
    149149}
  • boot/arch/riscv64/Makefile.inc

    rd59718e rcfdeedc  
    3030BFD_OUTPUT = $(BFD_NAME)
    3131BFD_ARCH = riscv
    32 BFD = binary
    3332
    3433BITS = 64
     
    5150        generic/src/gzip.c \
    5251        generic/src/tar.c \
     52        generic/src/kernel.c \
    5353        generic/src/payload.c
  • boot/arch/riscv64/include/arch/asm.h

    rd59718e rcfdeedc  
    3636extern char pt_page[];
    3737
    38 extern _Noreturn void jump_to_kernel(uintptr_t);
     38extern _Noreturn void jump_to_kernel(uintptr_t, uintptr_t);
    3939
    4040#endif
  • boot/arch/riscv64/src/asm.S

    rd59718e rcfdeedc  
    125125        csrw mstatus, t0
    126126
    127         li ra, PA2KA(BOOT_OFFSET)
     127        /* Entry point address is in a1. */
     128        mv ra, a1
    128129        csrw mepc, ra
    129130
  • boot/arch/riscv64/src/main.c

    rd59718e rcfdeedc  
    4242#include <halt.h>
    4343#include <payload.h>
     44#include <kernel.h>
    4445
    4546static bootinfo_t bootinfo;
     
    8889        extract_payload(&bootinfo.taskmap, load_addr, end, kernel_addr, NULL);
    8990
     91        uintptr_t entry = check_kernel(load_addr);
     92
    9093        printf("Booting the kernel...\n");
    91         jump_to_kernel(PA2KA(&bootinfo));
     94        jump_to_kernel(PA2KA(&bootinfo), entry);
    9295}
  • boot/arch/sparc64/Makefile.inc

    rd59718e rcfdeedc  
    7272        generic/src/gzip.c \
    7373        generic/src/tar.c \
     74        generic/src/kernel.c \
    7475        generic/src/payload.c
  • boot/arch/sparc64/src/main.c

    rd59718e rcfdeedc  
    4343#include <errno.h>
    4444#include <payload.h>
     45#include <kernel.h>
    4546
    4647/* The lowest ID (read from the VER register) of some US3 CPU model */
     
    257258                sun4u_smp();
    258259
     260        uintptr_t entry = check_kernel((void *) KERNEL_ADDRESS);
     261
    259262        printf("Booting the kernel ...\n");
    260         jump_to_kernel(bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo, subarch,
    261             (void *) KERNEL_ADDRESS);
    262 }
     263        jump_to_kernel(bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo,
     264            subarch, (void *) entry);
     265}
Note: See TracChangeset for help on using the changeset viewer.