1998-08-21 03:17:42 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
|
|
|
|
* 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
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1998-08-21 03:17:42 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-29 15:54:40 +00:00
|
|
|
#ifndef _BOOTSTRAP_H_
|
|
|
|
#define _BOOTSTRAP_H_
|
|
|
|
|
2021-08-12 05:45:52 +00:00
|
|
|
#include <stand.h>
|
1998-08-21 03:17:42 +00:00
|
|
|
#include <sys/types.h>
|
1998-10-21 20:07:05 +00:00
|
|
|
#include <sys/queue.h>
|
2001-06-14 01:23:57 +00:00
|
|
|
#include <sys/linker_set.h>
|
2020-12-21 05:31:16 +00:00
|
|
|
#include <stdbool.h>
|
1998-08-21 03:17:42 +00:00
|
|
|
|
2020-03-08 17:42:42 +00:00
|
|
|
#include "readin.h"
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/* Commands and return values; nonzero return sets command_errmsg != NULL */
|
|
|
|
typedef int (bootblk_cmd_t)(int argc, char *argv[]);
|
2016-08-20 16:23:19 +00:00
|
|
|
#define COMMAND_ERRBUFSZ (256)
|
2018-04-16 08:41:44 +00:00
|
|
|
extern const char *command_errmsg;
|
2016-08-20 16:23:19 +00:00
|
|
|
extern char command_errbuf[COMMAND_ERRBUFSZ];
|
2020-11-08 09:35:41 +00:00
|
|
|
#define CMD_OK 0
|
|
|
|
#define CMD_WARN 1
|
|
|
|
#define CMD_ERROR 2
|
|
|
|
#define CMD_CRIT 3
|
|
|
|
#define CMD_FATAL 4
|
1998-08-21 03:17:42 +00:00
|
|
|
|
|
|
|
/* interp.c */
|
2017-12-19 04:05:55 +00:00
|
|
|
void interact(void);
|
2018-01-31 22:46:05 +00:00
|
|
|
void interp_emit_prompt(void);
|
2018-02-07 23:27:38 +00:00
|
|
|
int interp_builtin_cmd(int argc, char *argv[]);
|
|
|
|
|
2018-01-31 22:46:05 +00:00
|
|
|
/* Called by interp.c for interp_*.c embedded interpreters */
|
2020-11-08 09:35:41 +00:00
|
|
|
int interp_include(const char *); /* Execute commands from filename */
|
|
|
|
void interp_init(void); /* Initialize interpreater */
|
|
|
|
int interp_run(const char *); /* Run a single command */
|
2000-08-03 09:14:02 +00:00
|
|
|
|
|
|
|
/* interp_backslash.c */
|
2017-12-08 19:57:11 +00:00
|
|
|
char *backslash(const char *str);
|
1998-08-21 03:17:42 +00:00
|
|
|
|
1998-09-14 18:27:06 +00:00
|
|
|
/* interp_parse.c */
|
2017-12-08 19:57:11 +00:00
|
|
|
int parse(int *argc, char ***argv, const char *str);
|
1998-09-14 18:27:06 +00:00
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/* boot.c */
|
2000-08-03 09:14:02 +00:00
|
|
|
void autoboot_maybe(void);
|
|
|
|
int getrootmount(char *rootdev);
|
1998-08-21 03:17:42 +00:00
|
|
|
|
|
|
|
/* misc.c */
|
2000-08-03 09:14:02 +00:00
|
|
|
char *unargv(int argc, char *argv[]);
|
|
|
|
size_t strlenout(vm_offset_t str);
|
|
|
|
char *strdupout(vm_offset_t str);
|
2004-08-28 14:57:34 +00:00
|
|
|
void kern_bzero(vm_offset_t dest, size_t len);
|
2020-03-08 17:42:42 +00:00
|
|
|
int kern_pread(readin_handle_t fd, vm_offset_t dest, size_t len, off_t off);
|
|
|
|
void *alloc_pread(readin_handle_t fd, off_t off, size_t len);
|
1998-08-21 03:17:42 +00:00
|
|
|
|
1999-02-04 17:06:46 +00:00
|
|
|
/* bcache.c */
|
loader: bcache read ahead block count should take account the large sectors
The loader bcache is implementing simple read-ahead to boost the cache.
The bcache is built based on 512B block sizes, and the read ahead is attempting
to read number of cache blocks, based on amount of the free bcache space.
However, there are devices using larger sector sizes than 512B, most obviously
the CD media is based on 2k sectors. This means the read-ahead can not be just
random number of blocks, but we should use value suitable also for use with
larger sectors, as for example, with CD devices, we should read multiple of 2KB.
Since the sector size from disk interface is not too reliable, i guess we can
just use "good enough" value, so the implementation is rounding down the read
ahead block count to be multiple of 16.
This means we have covered sector sizes to 8k.
In addition, the update does implement the end of cache marker, to help to
detect the possible memory corruption - I have not seen it happening so far,
but it does not hurt to have the detection mechanism in place.
Reviewed by: allanjude
Approved by: allanjude (mentor)
Differential Revision: https://reviews.freebsd.org/D9179
2017-02-06 08:58:40 +00:00
|
|
|
void bcache_init(size_t nblks, size_t bsize);
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
void bcache_add_dev(int);
|
|
|
|
void *bcache_allocate(void);
|
|
|
|
void bcache_free(void *);
|
2016-12-30 19:06:29 +00:00
|
|
|
int bcache_strategy(void *devdata, int rw, daddr_t blk, size_t size,
|
|
|
|
char *buf, size_t *rsize);
|
1999-02-04 17:06:46 +00:00
|
|
|
|
1998-11-02 23:28:11 +00:00
|
|
|
/*
|
|
|
|
* Disk block cache
|
|
|
|
*/
|
|
|
|
struct bcache_devdata
|
|
|
|
{
|
2020-11-08 09:35:41 +00:00
|
|
|
int (*dv_strategy)(void *, int, daddr_t, size_t, char *, size_t *);
|
|
|
|
void *dv_devdata;
|
|
|
|
void *dv_cache;
|
1998-11-02 23:28:11 +00:00
|
|
|
};
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/*
|
|
|
|
* Modular console support.
|
|
|
|
*/
|
2020-11-08 09:35:41 +00:00
|
|
|
struct console
|
1998-08-21 03:17:42 +00:00
|
|
|
{
|
2020-11-08 09:35:41 +00:00
|
|
|
const char *c_name;
|
|
|
|
const char *c_desc;
|
|
|
|
int c_flags;
|
|
|
|
#define C_PRESENTIN (1<<0) /* console can provide input */
|
|
|
|
#define C_PRESENTOUT (1<<1) /* console can provide output */
|
|
|
|
#define C_ACTIVEIN (1<<2) /* user wants input from console */
|
|
|
|
#define C_ACTIVEOUT (1<<3) /* user wants output to console */
|
2016-05-17 14:10:45 +00:00
|
|
|
#define C_WIDEOUT (1<<4) /* c_out routine groks wide chars */
|
2020-11-08 09:35:41 +00:00
|
|
|
|
|
|
|
/* set c_flags to match hardware */
|
|
|
|
void (* c_probe)(struct console *cp);
|
|
|
|
/* reinit XXX may need more args */
|
|
|
|
int (* c_init)(int arg);
|
|
|
|
/* emit c */
|
2020-11-08 09:49:51 +00:00
|
|
|
void (* c_out)(int c);
|
2020-11-08 09:35:41 +00:00
|
|
|
/* wait for and return input */
|
2020-11-08 09:49:51 +00:00
|
|
|
int (* c_in)(void);
|
|
|
|
/* return nonzero if input waiting */
|
2020-11-08 09:35:41 +00:00
|
|
|
int (* c_ready)(void);
|
1998-08-21 03:17:42 +00:00
|
|
|
};
|
2020-11-08 09:35:41 +00:00
|
|
|
extern struct console *consoles[];
|
|
|
|
void cons_probe(void);
|
2020-12-21 05:31:16 +00:00
|
|
|
bool cons_update_mode(bool);
|
|
|
|
void autoload_font(bool);
|
1998-08-21 03:17:42 +00:00
|
|
|
|
1998-09-04 02:43:26 +00:00
|
|
|
/*
|
|
|
|
* Plug-and-play enumerator/configurator interface.
|
|
|
|
*/
|
2020-11-08 09:35:41 +00:00
|
|
|
struct pnphandler
|
1998-09-14 18:27:06 +00:00
|
|
|
{
|
2020-11-08 09:35:41 +00:00
|
|
|
const char *pp_name; /* handler/bus name */
|
|
|
|
void (*pp_enumerate)(void); /* enumerate PnP devices, add to chain */
|
1998-09-14 18:27:06 +00:00
|
|
|
};
|
|
|
|
|
1998-10-21 20:07:05 +00:00
|
|
|
struct pnpident
|
1998-09-04 02:43:26 +00:00
|
|
|
{
|
2020-11-08 09:35:41 +00:00
|
|
|
/* ASCII identifier, actual format varies with bus/handler */
|
|
|
|
char *id_ident;
|
|
|
|
STAILQ_ENTRY(pnpident) id_link;
|
1998-09-14 18:27:06 +00:00
|
|
|
};
|
1998-09-04 02:43:26 +00:00
|
|
|
|
1998-10-21 20:07:05 +00:00
|
|
|
struct pnpinfo
|
1998-09-04 02:43:26 +00:00
|
|
|
{
|
2020-11-08 09:35:41 +00:00
|
|
|
char *pi_desc; /* ASCII description, optional */
|
|
|
|
int pi_revision; /* optional revision (or -1) if not supported */
|
|
|
|
char *pi_module; /* module/args nominated to handle device */
|
|
|
|
int pi_argc; /* module arguments */
|
|
|
|
char **pi_argv;
|
|
|
|
struct pnphandler *pi_handler; /* handler which detected this device */
|
|
|
|
STAILQ_HEAD(, pnpident) pi_ident; /* list of identifiers */
|
|
|
|
STAILQ_ENTRY(pnpinfo) pi_link;
|
1998-09-04 02:43:26 +00:00
|
|
|
};
|
|
|
|
|
2000-09-08 16:51:29 +00:00
|
|
|
STAILQ_HEAD(pnpinfo_stql, pnpinfo);
|
|
|
|
|
2020-11-08 09:35:41 +00:00
|
|
|
extern struct pnphandler *pnphandlers[]; /* provided by MD code */
|
1998-09-14 18:27:06 +00:00
|
|
|
|
2000-08-03 09:14:02 +00:00
|
|
|
void pnp_addident(struct pnpinfo *pi, char *ident);
|
|
|
|
struct pnpinfo *pnp_allocinfo(void);
|
|
|
|
void pnp_freeinfo(struct pnpinfo *pi);
|
|
|
|
void pnp_addinfo(struct pnpinfo *pi);
|
2018-03-13 16:33:00 +00:00
|
|
|
char *pnp_eisaformat(uint8_t *data);
|
1998-10-22 20:20:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* < 0 - No ISA in system
|
|
|
|
* == 0 - Maybe ISA, search for read data port
|
|
|
|
* > 0 - ISA in system, value is read data port address
|
|
|
|
*/
|
2020-11-08 09:35:41 +00:00
|
|
|
extern int isapnp_readport;
|
1998-09-04 02:43:26 +00:00
|
|
|
|
2018-06-14 06:41:33 +00:00
|
|
|
/*
|
|
|
|
* Version information
|
|
|
|
*/
|
|
|
|
extern char bootprog_info[];
|
|
|
|
|
userboot: handle guest interpreter mismatches more intelligently
The switch to lualoader creates a problem with userboot: the host is
inclined to build userboot with Lua, but the host userboot's interpreter
must match what's available on the guest. For almost all FreeBSD guests in
the wild, Lua is not yet available and a Lua-based userboot will fail.
This revision updates userboot protocol to version 5, which adds a
swap_interpreter callback to request a different interpreter, and tries to
determine the proper interpreter to be used based on how the guest
/boot/loader is compiled. This is still a bit of a guess, but it's likely
the best possible guess we can make in order to get it right. The
interpreter is now embedded in the resulting executable, so we can open
/boot/loader on the guest and hunt that down to derive the interpreter it
was built with.
Using -l with bhyveload will not allow an intepreter swap, even if the
loader specified happens to be a userboot with the wrong interpreter. We'll
simply complain about the mismatch and bail out.
For legacy guests without the interpreter marker, we assume they're 4th.
For new guests with the interpreter marker, we'll read it and swap over
to the proper interpreter if it doesn't match what the userboot we're using
was compiled with.
Both flavors of userboot are installed by default, userboot_4th.so and
userboot_lua.so. This fixes the build WITHOUT_FORTH as a coincidence, which
was broken by userboot being forced to 4th.
Reviewed by: imp, jhb, araujo (earlier version)
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D16945
2018-09-01 02:23:45 +00:00
|
|
|
/*
|
|
|
|
* Interpreter information
|
|
|
|
*/
|
|
|
|
extern const char bootprog_interp[];
|
|
|
|
#define INTERP_DEFINE(interpstr) \
|
|
|
|
const char bootprog_interp[] = "$Interpreter:" interpstr
|
|
|
|
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/*
|
2000-05-01 17:41:25 +00:00
|
|
|
* Preloaded file metadata header.
|
1998-08-21 03:17:42 +00:00
|
|
|
*
|
|
|
|
* Metadata are allocated on our heap, and copied into kernel space
|
|
|
|
* before executing the kernel.
|
|
|
|
*/
|
2020-11-08 09:35:41 +00:00
|
|
|
struct file_metadata
|
1998-08-21 03:17:42 +00:00
|
|
|
{
|
2020-11-08 09:35:41 +00:00
|
|
|
size_t md_size;
|
|
|
|
uint16_t md_type;
|
|
|
|
struct file_metadata *md_next;
|
|
|
|
char md_data[1]; /* data are immediately appended */
|
1998-08-21 03:17:42 +00:00
|
|
|
};
|
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file;
|
2001-09-11 01:09:24 +00:00
|
|
|
struct mod_depend;
|
2000-05-01 17:41:25 +00:00
|
|
|
|
|
|
|
struct kernel_module
|
|
|
|
{
|
2020-11-08 09:35:41 +00:00
|
|
|
char *m_name; /* module name */
|
|
|
|
int m_version; /* module version */
|
|
|
|
/* char *m_args; */ /* arguments for the module */
|
|
|
|
struct preloaded_file *m_fp;
|
|
|
|
struct kernel_module *m_next;
|
2000-05-01 17:41:25 +00:00
|
|
|
};
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/*
|
2000-05-01 17:41:25 +00:00
|
|
|
* Preloaded file information. Depending on type, file can contain
|
|
|
|
* additional units called 'modules'.
|
1998-08-21 03:17:42 +00:00
|
|
|
*
|
2000-05-01 17:41:25 +00:00
|
|
|
* At least one file (the kernel) must be loaded in order to boot.
|
1998-08-21 03:17:42 +00:00
|
|
|
* The kernel is always loaded first.
|
1998-08-31 21:10:43 +00:00
|
|
|
*
|
|
|
|
* String fields (m_name, m_type) should be dynamically allocated.
|
1998-08-21 03:17:42 +00:00
|
|
|
*/
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file
|
1998-08-21 03:17:42 +00:00
|
|
|
{
|
2020-11-08 09:35:41 +00:00
|
|
|
char *f_name; /* file name */
|
|
|
|
char *f_type; /* verbose file type, eg 'ELF kernel', 'pnptable', etc. */
|
|
|
|
char *f_args; /* arguments for the file */
|
|
|
|
/* metadata that will be placed in the module directory */
|
|
|
|
struct file_metadata *f_metadata;
|
|
|
|
int f_loader; /* index of the loader that read the file */
|
|
|
|
vm_offset_t f_addr; /* load address */
|
|
|
|
size_t f_size; /* file size */
|
|
|
|
struct kernel_module *f_modules; /* list of modules if any */
|
|
|
|
struct preloaded_file *f_next; /* next file */
|
2021-07-10 19:55:56 +00:00
|
|
|
#ifdef __amd64__
|
|
|
|
bool f_kernphys_relocatable;
|
|
|
|
#endif
|
1998-08-21 03:17:42 +00:00
|
|
|
};
|
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
struct file_format
|
1998-08-21 03:17:42 +00:00
|
|
|
{
|
2020-11-08 09:35:41 +00:00
|
|
|
/*
|
|
|
|
* Load function must return EFTYPE if it can't handle
|
|
|
|
* the module supplied
|
|
|
|
*/
|
|
|
|
int (*l_load)(char *, uint64_t, struct preloaded_file **);
|
|
|
|
/*
|
|
|
|
* Only a loader that will load a kernel (first module)
|
|
|
|
* should have an exec handler
|
|
|
|
*/
|
|
|
|
int (*l_exec)(struct preloaded_file *);
|
1998-08-21 03:17:42 +00:00
|
|
|
};
|
2000-05-01 17:41:25 +00:00
|
|
|
|
2020-11-08 09:35:41 +00:00
|
|
|
extern struct file_format *file_formats[]; /* supplied by consumer */
|
|
|
|
extern struct preloaded_file *preloaded_files;
|
2000-05-01 17:41:25 +00:00
|
|
|
|
2020-11-08 09:35:41 +00:00
|
|
|
int mod_load(char *name, struct mod_depend *verinfo, int argc, char *argv[]);
|
|
|
|
int mod_loadkld(const char *name, int argc, char *argv[]);
|
|
|
|
void unload(void);
|
2000-05-01 17:41:25 +00:00
|
|
|
|
|
|
|
struct preloaded_file *file_alloc(void);
|
loader: implement multiboot support for Xen Dom0
Implement a subset of the multiboot specification in order to boot Xen
and a FreeBSD Dom0 from the FreeBSD bootloader. This multiboot
implementation is tailored to boot Xen and FreeBSD Dom0, and it will
most surely fail to boot any other multiboot compilant kernel.
In order to detect and boot the Xen microkernel, two new file formats
are added to the bootloader, multiboot and multiboot_obj. Multiboot
support must be tested before regular ELF support, since Xen is a
multiboot kernel that also uses ELF. After a multiboot kernel is
detected, all the other loaded kernels/modules are parsed by the
multiboot_obj format.
The layout of the loaded objects in memory is the following; first the
Xen kernel is loaded as a 32bit ELF into memory (Xen will switch to
long mode by itself), after that the FreeBSD kernel is loaded as a RAW
file (Xen will parse and load it using it's internal ELF loader), and
finally the metadata and the modules are loaded using the native
FreeBSD way. After everything is loaded we jump into Xen's entry point
using a small trampoline. The order of the multiboot modules passed to
Xen is the following, the first module is the RAW FreeBSD kernel, and
the second module is the metadata and the FreeBSD modules.
Since Xen will relocate the memory position of the second
multiboot module (the one that contains the metadata and native
FreeBSD modules), we need to stash the original modulep address inside
of the metadata itself in order to recalculate its position once
booted. This also means the metadata must come before the loaded
modules, so after loading the FreeBSD kernel a portion of memory is
reserved in order to place the metadata before booting.
In order to tell the loader to boot Xen and then the FreeBSD kernel the
following has to be added to the /boot/loader.conf file:
xen_cmdline="dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga"
xen_kernel="/boot/xen"
The first argument contains the command line that will be passed to the Xen
kernel, while the second argument is the path to the Xen kernel itself. This
can also be done manually from the loader command line, by for example
typing the following set of commands:
OK unload
OK load /boot/xen dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga
OK load kernel
OK load zfs
OK load if_tap
OK load ...
OK boot
Sponsored by: Citrix Systems R&D
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D517
For the Forth bits:
Submitted by: Julien Grall <julien.grall AT citrix.com>
2015-01-15 16:27:20 +00:00
|
|
|
struct preloaded_file *file_findfile(const char *name, const char *type);
|
2000-05-01 17:41:25 +00:00
|
|
|
struct file_metadata *file_findmetadata(struct preloaded_file *fp, int type);
|
2016-01-15 00:55:36 +00:00
|
|
|
struct preloaded_file *file_loadraw(const char *name, char *type, int insert);
|
2000-05-01 17:41:25 +00:00
|
|
|
void file_discard(struct preloaded_file *fp);
|
2020-11-08 09:35:41 +00:00
|
|
|
void file_addmetadata(struct preloaded_file *, int, size_t, void *);
|
|
|
|
int file_addmodule(struct preloaded_file *, char *, int,
|
|
|
|
struct kernel_module **);
|
2017-04-13 09:59:12 +00:00
|
|
|
void file_removemetadata(struct preloaded_file *fp);
|
2021-05-30 20:17:11 +00:00
|
|
|
int file_addbuf(const char *name, const char *type, size_t len, void *buf);
|
2021-05-30 20:30:28 +00:00
|
|
|
int tslog_init(void);
|
|
|
|
int tslog_publish(void);
|
1998-09-14 18:27:06 +00:00
|
|
|
|
2020-12-21 05:31:16 +00:00
|
|
|
vm_offset_t build_font_module(vm_offset_t);
|
|
|
|
|
1998-09-14 18:27:06 +00:00
|
|
|
/* MI module loaders */
|
2003-05-01 03:56:30 +00:00
|
|
|
#ifdef __elfN
|
2004-08-28 23:03:05 +00:00
|
|
|
/* Relocation types. */
|
2020-11-08 09:35:41 +00:00
|
|
|
#define ELF_RELOC_REL 1
|
|
|
|
#define ELF_RELOC_RELA 2
|
2004-08-28 23:03:05 +00:00
|
|
|
|
2008-02-23 18:33:50 +00:00
|
|
|
/* Relocation offset for some architectures */
|
2018-03-13 16:33:00 +00:00
|
|
|
extern uint64_t __elfN(relocation_offset);
|
2008-02-23 18:33:50 +00:00
|
|
|
|
2004-08-28 23:03:05 +00:00
|
|
|
struct elf_file;
|
2005-12-18 04:52:37 +00:00
|
|
|
typedef Elf_Addr (symaddr_fn)(struct elf_file *ef, Elf_Size symidx);
|
2004-08-28 23:03:05 +00:00
|
|
|
|
2020-11-08 09:35:41 +00:00
|
|
|
int __elfN(loadfile)(char *, uint64_t, struct preloaded_file **);
|
|
|
|
int __elfN(obj_loadfile)(char *, uint64_t, struct preloaded_file **);
|
2004-08-28 23:03:05 +00:00
|
|
|
int __elfN(reloc)(struct elf_file *ef, symaddr_fn *symaddr,
|
|
|
|
const void *reldata, int reltype, Elf_Addr relbase,
|
|
|
|
Elf_Addr dataaddr, void *data, size_t len);
|
2020-11-08 09:35:41 +00:00
|
|
|
int __elfN(loadfile_raw)(char *, uint64_t, struct preloaded_file **, int);
|
|
|
|
int __elfN(load_modmetadata)(struct preloaded_file *, uint64_t);
|
2003-05-01 03:56:30 +00:00
|
|
|
#endif
|
1998-08-21 03:17:42 +00:00
|
|
|
|
|
|
|
/*
|
2020-11-08 09:35:41 +00:00
|
|
|
* Support for commands
|
1998-08-21 03:17:42 +00:00
|
|
|
*/
|
2020-11-08 09:35:41 +00:00
|
|
|
struct bootblk_command
|
1998-08-21 03:17:42 +00:00
|
|
|
{
|
|
|
|
const char *c_name;
|
|
|
|
const char *c_desc;
|
|
|
|
bootblk_cmd_t *c_fn;
|
|
|
|
};
|
|
|
|
|
2020-11-08 09:35:41 +00:00
|
|
|
#define COMMAND_SET(tag, key, desc, func) \
|
1998-08-21 03:17:42 +00:00
|
|
|
static bootblk_cmd_t func; \
|
|
|
|
static struct bootblk_command _cmd_ ## tag = { key, desc, func }; \
|
2000-08-03 09:14:02 +00:00
|
|
|
DATA_SET(Xcommand_set, _cmd_ ## tag)
|
1998-08-21 03:17:42 +00:00
|
|
|
|
2001-06-14 01:23:57 +00:00
|
|
|
SET_DECLARE(Xcommand_set, struct bootblk_command);
|
1998-08-21 03:17:42 +00:00
|
|
|
|
2020-11-08 09:35:41 +00:00
|
|
|
/*
|
1998-08-31 21:10:43 +00:00
|
|
|
* The intention of the architecture switch is to provide a convenient
|
|
|
|
* encapsulation of the interface between the bootstrap MI and MD code.
|
|
|
|
* MD code may selectively populate the switch at runtime based on the
|
|
|
|
* actual configuration of the target system.
|
1998-08-21 03:17:42 +00:00
|
|
|
*/
|
|
|
|
struct arch_switch
|
|
|
|
{
|
2020-11-08 09:35:41 +00:00
|
|
|
/* Automatically load modules as required by detected hardware */
|
|
|
|
int (*arch_autoload)(void);
|
|
|
|
/* Locate the device for (name), return pointer to tail in (*path) */
|
|
|
|
int (*arch_getdev)(void **dev, const char *name, const char **path);
|
|
|
|
/*
|
|
|
|
* Copy from local address space to module address space,
|
|
|
|
* similar to bcopy()
|
|
|
|
*/
|
|
|
|
ssize_t (*arch_copyin)(const void *, vm_offset_t, const size_t);
|
|
|
|
/*
|
|
|
|
* Copy to local address space from module address space,
|
|
|
|
* similar to bcopy()
|
|
|
|
*/
|
|
|
|
ssize_t (*arch_copyout)(const vm_offset_t, void *, const size_t);
|
|
|
|
/* Read from file to module address space, same semantics as read() */
|
|
|
|
ssize_t (*arch_readin)(readin_handle_t, vm_offset_t, const size_t);
|
|
|
|
/* Perform ISA byte port I/O (only for systems with ISA) */
|
|
|
|
int (*arch_isainb)(int port);
|
|
|
|
void (*arch_isaoutb)(int port, int value);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interface to adjust the load address according to the "object"
|
|
|
|
* being loaded.
|
|
|
|
*/
|
|
|
|
uint64_t (*arch_loadaddr)(u_int type, void *data, uint64_t addr);
|
2011-04-03 22:31:51 +00:00
|
|
|
#define LOAD_ELF 1 /* data points to the ELF header. */
|
|
|
|
#define LOAD_RAW 2 /* data points to the file name. */
|
|
|
|
|
2020-11-08 09:35:41 +00:00
|
|
|
/*
|
|
|
|
* Interface to inform MD code about a loaded (ELF) segment. This
|
|
|
|
* can be used to flush caches and/or set up translations.
|
|
|
|
*/
|
2011-04-03 22:31:51 +00:00
|
|
|
#ifdef __elfN
|
2020-11-08 09:35:41 +00:00
|
|
|
void (*arch_loadseg)(Elf_Ehdr *eh, Elf_Phdr *ph, uint64_t delta);
|
2011-04-03 22:31:51 +00:00
|
|
|
#else
|
2020-11-08 09:35:41 +00:00
|
|
|
void (*arch_loadseg)(void *eh, void *ph, uint64_t delta);
|
2011-04-03 22:31:51 +00:00
|
|
|
#endif
|
2012-05-12 09:03:30 +00:00
|
|
|
|
2020-11-08 09:35:41 +00:00
|
|
|
/* Probe ZFS pool(s), if needed. */
|
|
|
|
void (*arch_zfs_probe)(void);
|
2018-01-29 09:24:28 +00:00
|
|
|
|
2020-11-08 09:35:41 +00:00
|
|
|
/* Return the hypervisor name/type or NULL if not virtualized. */
|
|
|
|
const char *(*arch_hypervisor)(void);
|
2019-02-26 06:22:10 +00:00
|
|
|
|
2020-11-08 09:35:41 +00:00
|
|
|
/* For kexec-type loaders, get ksegment structure */
|
|
|
|
void (*arch_kexec_kseg_get)(int *nseg, void **kseg);
|
1998-08-21 03:17:42 +00:00
|
|
|
};
|
|
|
|
extern struct arch_switch archsw;
|
|
|
|
|
1998-09-14 18:27:06 +00:00
|
|
|
/* This must be provided by the MD code, but should it be in the archsw? */
|
2000-08-03 09:14:02 +00:00
|
|
|
void delay(int delay);
|
2000-06-14 10:34:29 +00:00
|
|
|
|
2000-08-03 09:14:02 +00:00
|
|
|
void dev_cleanup(void);
|
2002-02-25 04:31:25 +00:00
|
|
|
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
/*
|
|
|
|
* nvstore API.
|
|
|
|
*/
|
|
|
|
typedef int (nvstore_getter_cb_t)(void *, const char *, void **);
|
|
|
|
typedef int (nvstore_setter_cb_t)(void *, int, const char *,
|
|
|
|
const void *, size_t);
|
|
|
|
typedef int (nvstore_setter_str_cb_t)(void *, const char *, const char *,
|
|
|
|
const char *);
|
|
|
|
typedef int (nvstore_unset_cb_t)(void *, const char *);
|
|
|
|
typedef int (nvstore_print_cb_t)(void *, void *);
|
|
|
|
typedef int (nvstore_iterate_cb_t)(void *, int (*)(void *, void *));
|
|
|
|
|
|
|
|
typedef struct nvs_callbacks {
|
|
|
|
nvstore_getter_cb_t *nvs_getter;
|
|
|
|
nvstore_setter_cb_t *nvs_setter;
|
|
|
|
nvstore_setter_str_cb_t *nvs_setter_str;
|
|
|
|
nvstore_unset_cb_t *nvs_unset;
|
|
|
|
nvstore_print_cb_t *nvs_print;
|
|
|
|
nvstore_iterate_cb_t *nvs_iterate;
|
|
|
|
} nvs_callbacks_t;
|
|
|
|
|
|
|
|
int nvstore_init(const char *, nvs_callbacks_t *, void *);
|
|
|
|
int nvstore_fini(const char *);
|
|
|
|
void *nvstore_get_store(const char *);
|
|
|
|
int nvstore_print(void *);
|
|
|
|
int nvstore_get_var(void *, const char *, void **);
|
|
|
|
int nvstore_set_var(void *, int, const char *, void *, size_t);
|
|
|
|
int nvstore_set_var_from_string(void *, const char *, const char *,
|
|
|
|
const char *);
|
|
|
|
int nvstore_unset_var(void *, const char *);
|
|
|
|
|
2021-08-12 05:45:52 +00:00
|
|
|
/* common code to set currdev variable. */
|
|
|
|
extern int mount_currdev(struct env_var *, int, const void *);
|
|
|
|
|
2018-03-21 23:46:26 +00:00
|
|
|
#ifndef CTASSERT
|
|
|
|
#define CTASSERT(x) _Static_assert(x, "compile-time assertion failed")
|
2012-05-09 07:55:42 +00:00
|
|
|
#endif
|
|
|
|
|
2012-04-29 15:54:40 +00:00
|
|
|
#endif /* !_BOOTSTRAP_H_ */
|