bootinfo.c revision 199767f8919635c4928607450d9e0abb932109ce
/*-
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
* Copyright (c) 2004, 2006 Marcel Moolenaar
* Copyright (c) 2014 The FreeBSD Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
__FBSDID("$FreeBSD$");
#include <stand.h>
#include <string.h>
#include <machine/metadata.h>
#include <efi.h>
#include <efilib.h>
#include "bootstrap.h"
#include "loader_efi.h"
#if defined(__amd64__)
#include <machine/specialreg.h>
#include "framebuffer.h"
#endif
#if defined(LOADER_FDT_SUPPORT)
#include <fdt_platform.h>
#endif
extern EFI_SYSTEM_TABLE *ST;
static const char howto_switches[] = "aCdrgDmphsv";
static int howto_masks[] = {
};
static int
bi_getboothowto(char *kargs)
{
const char *sw;
char *opts;
char *console;
int howto, i;
howto = 0;
/* Get the boot options from the environment first. */
}
}
/* Parse kargs */
return (howto);
while (*(++opts) != '\0') {
break;
}
}
return (howto);
}
/*
* Copy the environment into the load area starting at (addr).
* Each variable is formatted as <name>=<value>, with a single nul
* separating each variable, and a double nul terminating the environment.
*/
static vm_offset_t
{
/* Traverse the environment. */
break;
break;
addr++;
break;
}
break;
}
return(last);
}
/*
* Copy module-related data into the load area, where it can be
* used as a directory for loaded modules.
*
* Module data is presented in a self-describing format. Each datum
* is preceded by a 32-bit identifier and a 32-bit size field.
*
* Currently, the following data are saved:
*
* MOD_NAME (variable) module name (string)
* MOD_TYPE (variable) module type (string)
* MOD_ARGS (variable) module parameters (string)
* MOD_ADDR sizeof(vm_offset_t) module load address
* MOD_SIZE sizeof(size_t) module size
* MOD_METADATA (variable) type-specific metadata
*/
#define COPY32(v, a, c) { \
uint32_t x = (v); \
if (c) \
archsw.arch_copyin(&x, a, sizeof(x)); \
a += sizeof(x); \
}
#define MOD_STR(t, a, s, c) { \
COPY32(t, a, c); \
if (c) \
}
#define MOD_VAR(t, a, s, c) { \
COPY32(t, a, c); \
COPY32(sizeof(s), a, c); \
if (c) \
archsw.arch_copyin(&s, a, sizeof(s)); \
}
#define MOD_METADATA(a, mm, c) { \
if (c) \
}
#define MOD_END(a, c) { \
COPY32(MODINFO_END, a, c); \
COPY32(0, a, c); \
}
static vm_offset_t
{
struct preloaded_file *fp;
struct file_metadata *md;
int c;
uint64_t v;
c = addr != 0;
/* Start with the first module on the list, should be the kernel. */
#if defined(__arm__)
v -= __elfN(relocation_offset);
#endif
}
return(addr);
}
static int
{
struct efi_map_header *efihdr;
#if defined(__amd64__)
if (efi_find_framebuffer(&efifb) == 0) {
printf("EFI framebuffer information:\n");
printf("masks 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
}
#endif
/*
* It is possible that the first call to ExitBootServices may change
* the map key. Fetch a new map key and retry ExitBootServices in that
* case.
*/
/*
* Allocate enough pages to hold the bootinfo block and the
* memory map EFI will return to us. The memory map has an
* unknown size, so we have to determine that first. Note that
* the AllocatePages call can itself modify the memory map, so
* we have to take that into account as well. The changes to
* the memory map are caused by splitting a range of free
* memory into two (AFAICT), so that one is marked as being
* loader data.
*/
sz = 0;
return (ENOMEM);
}
/*
* Read the memory map and stash it after bootinfo. Align the
* memory map on a 16-byte boundary (the bootinfo block is page
* aligned).
*/
return (EINVAL);
}
efihdr);
return (0);
}
}
return (EINVAL);
}
/*
* Load the information expected by an amd64 kernel.
*
* - The 'boothowto' argument is constructed.
* - The 'bootdev' argument is constructed.
* - The 'bootinfo' struct is constructed, and copied into the kernel space.
* - The kernel environment is copied into kernel space.
* - Module metadata are formatted and placed in kernel space.
*/
int
{
struct file_metadata *md;
char *rootdevname;
int howto;
#if defined(LOADER_FDT_SUPPORT)
int dtb_size;
#endif
#if defined(__arm__)
size_t i;
/*
* These metadata addreses must be converted for kernel after
* relocation.
*/
#if defined(LOADER_FDT_SUPPORT)
#endif
};
#endif
/*
* Allow the environment variable 'rootdev' to override the supplied
*/
printf("Can't determine root device.\n");
return(EINVAL);
}
addr = 0;
}
/* Pad to a page boundary. */
/* Copy our environment. */
/* Pad to a page boundary. */
#if defined(LOADER_FDT_SUPPORT)
/* Handle device tree blob */
/* Pad to a page boundary */
if (dtb_size)
#endif
panic("can't find kernel file");
kernend = 0; /* fill it in later */
#if defined(LOADER_FDT_SUPPORT)
if (dtb_size)
else
pager_output("WARNING! Trying to fire up the kernel, but no "
"device tree blob found!\n");
#endif
/* Figure out the size and location of the metadata. */
size = bi_copymodules(0);
/* patch MODINFOMD_KERNEND */
#if defined(__arm__)
/* Do relocation fixup on metadata of each module. */
if (md) {
}
}
}
#endif
/* Copy module list and metadata. */
(void)bi_copymodules(addr);
return (0);
}