coreboot-v3/arch/x86/archelfboot.c
<<
>>
Prefs
   1#include <console.h>
   2// #include <ip_checksum.h>
   3#include <elf.h>
   4#include <elf_boot.h>
   5#include <string.h>
   6
   7
   8#ifndef CMD_LINE
   9#define CMD_LINE ""
  10#endif
  11
  12
  13
  14#define UPSZ(X) ((sizeof(X) + 3) &~3)
  15
  16static struct {
  17        Elf_Bhdr hdr;
  18        Elf_Nhdr ft_hdr;
  19        unsigned char ft_desc[UPSZ(FIRMWARE_TYPE)];
  20        Elf_Nhdr bl_hdr;
  21        unsigned char bl_desc[UPSZ(BOOTLOADER)];
  22        Elf_Nhdr blv_hdr;
  23        unsigned char blv_desc[UPSZ(BOOTLOADER_VERSION)];
  24        Elf_Nhdr cmd_hdr;
  25        unsigned char cmd_desc[UPSZ(CMD_LINE)];
  26} elf_boot_notes = {
  27        .hdr = {
  28                .b_signature = 0x0E1FB007,
  29                .b_size = sizeof(elf_boot_notes),
  30                .b_checksum = 0,
  31                .b_records = 4,
  32        },
  33        .ft_hdr = {
  34                .n_namesz = 0,
  35                .n_descsz = sizeof(FIRMWARE_TYPE),
  36                .n_type = EBN_FIRMWARE_TYPE,
  37        },
  38        .ft_desc = FIRMWARE_TYPE,
  39        .bl_hdr = {
  40                .n_namesz = 0,
  41                .n_descsz = sizeof(BOOTLOADER),
  42                .n_type = EBN_BOOTLOADER_NAME,
  43        },
  44        .bl_desc = BOOTLOADER,
  45        .blv_hdr = {
  46                .n_namesz = 0,
  47                .n_descsz = sizeof(BOOTLOADER_VERSION),
  48                .n_type = EBN_BOOTLOADER_VERSION,
  49        },
  50        .blv_desc = BOOTLOADER_VERSION,
  51        .cmd_hdr = {
  52                .n_namesz = 0,
  53                .n_descsz = sizeof(CMD_LINE),
  54                .n_type = EBN_COMMAND_LINE,
  55        },
  56        .cmd_desc = CMD_LINE,
  57};
  58
  59
  60int elf_check_arch(Elf_ehdr *ehdr)
  61{
  62        return (
  63                ((ehdr->e_machine == EM_386) || (ehdr->e_machine == EM_486)) &&
  64                (ehdr->e_ident[EI_CLASS] == ELFCLASS32) &&
  65                (ehdr->e_ident[EI_DATA] == ELFDATA2LSB) 
  66                );
  67        
  68}
  69
  70/* there used to be lots of complexity here to deal with the fact that this code ran in 
  71  * RAM. The code was awesome in its power, incomprehensible to most. 
  72  * But this code runs in ROM now, so the complexity went away 
  73  */
  74void jmp_to_elf_entry(void *entry)
  75{
  76        int (*v)(void) = entry;
  77        v();
  78}
  79
  80
  81
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.