Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize the kernel and module metadata types #1394

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stand/common/bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
struct preloaded_file
{
char *f_name; /* file name */
char *f_type; /* verbose file type, eg 'ELF kernel', 'pnptable', etc. */
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;
Expand Down Expand Up @@ -271,7 +271,7 @@
struct preloaded_file *file_alloc(void);
struct preloaded_file *file_findfile(const char *name, const char *type);
struct file_metadata *file_findmetadata(struct preloaded_file *fp, int type);
struct preloaded_file *file_loadraw(const char *name, char *type, int insert);
struct preloaded_file *file_loadraw(const char *name, const char *type, int insert);

Check warning on line 274 in stand/common/bootstrap.h

View workflow job for this annotation

GitHub Actions / Style Checker

line over 80 characters
void file_discard(struct preloaded_file *fp);
void file_addmetadata(struct preloaded_file *, int, size_t, void *);
int file_addmodule(struct preloaded_file *, char *, int,
Expand Down
10 changes: 4 additions & 6 deletions stand/common/gfx_fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
#include <vbe.h>
#endif

#include "modinfo.h"

/* VGA text mode does use bold font. */
#if !defined(VGA_8X16_FONT)
#define VGA_8X16_FONT "/boot/fonts/8x16b.fnt"
Expand Down Expand Up @@ -2982,9 +2984,7 @@ build_font_module(vm_offset_t addr)

fi.fi_checksum = -checksum;

fp = file_findfile(NULL, "elf kernel");
if (fp == NULL)
fp = file_findfile(NULL, "elf64 kernel");
fp = file_findfile(NULL, md_kerntype);
if (fp == NULL)
panic("can't find kernel file");

Expand Down Expand Up @@ -3026,9 +3026,7 @@ build_splash_module(vm_offset_t addr)
return (addr);
}

fp = file_findfile(NULL, "elf kernel");
if (fp == NULL)
fp = file_findfile(NULL, "elf64 kernel");
fp = file_findfile(NULL, md_kerntype);
if (fp == NULL)
panic("can't find kernel file");

Expand Down
12 changes: 5 additions & 7 deletions stand/common/load_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <sys/link_elf.h>

#include "bootstrap.h"
#include "modinfo.h"

#define COPYOUT(s,d,l) archsw.arch_copyout((vm_offset_t)(s), d, l)

Expand Down Expand Up @@ -89,9 +90,6 @@ static int __elfN(parse_modmetadata)(struct preloaded_file *mp, elf_file_t ef,
static symaddr_fn __elfN(symaddr);
static char *fake_modname(const char *name);

const char *__elfN(kerneltype) = "elf kernel";
const char *__elfN(moduletype) = "elf module";

uint64_t __elfN(relocation_offset) = 0;

#ifdef __powerpc__
Expand Down Expand Up @@ -384,7 +382,7 @@ __elfN(loadfile_raw)(char *filename, uint64_t dest,
/*
* Check to see what sort of module we are.
*/
kfp = file_findfile(NULL, __elfN(kerneltype));
kfp = file_findfile(NULL, md_kerntype);
#ifdef __powerpc__
/*
* Kernels can be ET_DYN, so just assume the first loaded object is the
Expand Down Expand Up @@ -435,7 +433,7 @@ __elfN(loadfile_raw)(char *filename, uint64_t dest,
err = EPERM;
goto oerr;
}
if (strcmp(__elfN(kerneltype), kfp->f_type)) {
if (strcmp(md_kerntype, kfp->f_type)) {
printf("elf" __XSTRING(__ELF_WORD_SIZE)
"_loadfile: can't load module with kernel type '%s'\n",
kfp->f_type);
Expand Down Expand Up @@ -470,9 +468,9 @@ __elfN(loadfile_raw)(char *filename, uint64_t dest,
fp->f_name = strdup(filename);
if (multiboot == 0)
fp->f_type = strdup(ef.kernel ?
__elfN(kerneltype) : __elfN(moduletype));
md_kerntype : md_modtype);
else
fp->f_type = strdup("elf multiboot kernel");
fp->f_type = strdup(md_kerntype_mb);

if (module_verbose >= MODULE_VERBOSE_FULL) {
if (ef.kernel)
Expand Down
8 changes: 3 additions & 5 deletions stand/common/load_elf_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <sys/link_elf.h>

#include "bootstrap.h"
#include "modinfo.h"

#define COPYOUT(s,d,l) archsw.arch_copyout((vm_offset_t)(s), d, l)

Expand Down Expand Up @@ -77,9 +78,6 @@ static int __elfN(obj_parse_modmetadata)(struct preloaded_file *mp,
elf_file_t ef);
static Elf_Addr __elfN(obj_symaddr)(struct elf_file *ef, Elf_Size symidx);

const char *__elfN(obj_kerneltype) = "elf kernel";
const char *__elfN(obj_moduletype) = "elf obj module";

/*
* Attempt to load the file (file) as an ELF module. It will be stored at
* (dest), and a pointer to a module structure describing the loaded object
Expand Down Expand Up @@ -154,7 +152,7 @@ __elfN(obj_loadfile)(char *filename, uint64_t dest,
}
#endif

kfp = file_findfile(NULL, __elfN(obj_kerneltype));
kfp = file_findfile(NULL, md_kerntype);
if (kfp == NULL) {
printf("elf" __XSTRING(__ELF_WORD_SIZE)
"_obj_loadfile: can't load module before kernel\n");
Expand All @@ -178,7 +176,7 @@ __elfN(obj_loadfile)(char *filename, uint64_t dest,
goto out;
}
fp->f_name = strdup(filename);
fp->f_type = strdup(__elfN(obj_moduletype));
fp->f_type = strdup(md_modtype_obj);

if (module_verbose > MODULE_VERBOSE_SILENT)
printf("%s ", filename);
Expand Down
4 changes: 1 addition & 3 deletions stand/common/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ md_load_dual(char *args, vm_offset_t *modulep, vm_offset_t *dtb, int kern64)
#endif

kernend = 0;
kfp = file_findfile(NULL, kern64 ? "elf64 kernel" : "elf32 kernel");
if (kfp == NULL)
kfp = file_findfile(NULL, "elf kernel");
kfp = file_findfile(NULL, md_kerntype);
if (kfp == NULL)
panic("can't find kernel file");
file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto);
Expand Down
5 changes: 5 additions & 0 deletions stand/common/modinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@

#define MOD_ALIGN(l) roundup(l, align)

const char md_modtype[] = MODTYPE;
const char md_kerntype[] = KERNTYPE;
const char md_modtype_obj[] = MODTYPE_OBJ;
const char md_kerntype_mb[] = KERNTYPE_MB;

vm_offset_t
md_copymodules(vm_offset_t addr, bool kern64)
{
Expand Down
5 changes: 5 additions & 0 deletions stand/common/modinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#ifndef COMMON_MODINFO_H
#define COMMON_MODINFO_H

extern const char md_modtype[];
extern const char md_kerntype[];
extern const char md_modtype_obj[];
extern const char md_kerntype_mb[];

int md_load(char *args, vm_offset_t *modulep, vm_offset_t *dtb);
int md_load64(char *args, vm_offset_t *modulep, vm_offset_t *dtb);

Expand Down
2 changes: 1 addition & 1 deletion stand/common/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,10 @@
* no arguments or anything.
*/
struct preloaded_file *
file_loadraw(const char *fname, char *type, int insert)
file_loadraw(const char *fname, const char *type, int insert)
{
struct preloaded_file *fp;
char *name;

Check warning on line 658 in stand/common/module.c

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
int fd, got;
vm_offset_t laddr;
#ifdef LOADER_VERIEXEC_VECTX
Expand Down
9 changes: 5 additions & 4 deletions stand/efi/loader/arch/amd64/multiboot2.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "bootstrap.h"
#include "multiboot2.h"
#include "loader_efi.h"
#include "modinfo.h"

extern int elf32_loadfile_raw(char *filename, uint64_t dest,
struct preloaded_file **result, int multiboot);
Expand Down Expand Up @@ -438,7 +439,7 @@ exec(struct preloaded_file *fp)
* module 0 module 1
*/

fp = file_findfile(NULL, "elf kernel");
fp = file_findfile(NULL, md_kerntype);
if (fp == NULL) {
printf("No FreeBSD kernel provided, aborting\n");
error = EINVAL;
Expand Down Expand Up @@ -500,22 +501,22 @@ obj_loadfile(char *filename, uint64_t dest, struct preloaded_file **result)
int error;

/* See if there's a multiboot kernel loaded */
mfp = file_findfile(NULL, "elf multiboot kernel");
mfp = file_findfile(NULL, md_kerntype_mb);
if (mfp == NULL)
return (EFTYPE);

/*
* We have a multiboot kernel loaded, see if there's a FreeBSD
* kernel loaded also.
*/
kfp = file_findfile(NULL, "elf kernel");
kfp = file_findfile(NULL, md_kerntype);
if (kfp == NULL) {
/*
* No kernel loaded, this must be it. The kernel has to
* be loaded as a raw file, it will be processed by
* Xen and correctly loaded as an ELF file.
*/
rfp = file_loadraw(filename, "elf kernel", 0);
rfp = file_loadraw(filename, md_kerntype, 0);
if (rfp == NULL) {
printf(
"Unable to load %s as a multiboot payload kernel\n",
Expand Down
4 changes: 1 addition & 3 deletions stand/efi/loader/bootinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,7 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs)
addr += roundup(dtb_size, PAGE_SIZE);
#endif

kfp = file_findfile(NULL, "elf kernel");
if (kfp == NULL)
kfp = file_findfile(NULL, "elf64 kernel");
kfp = file_findfile(NULL, md_kerntype);
if (kfp == NULL)
panic("can't find kernel file");
kernend = 0; /* fill it in later */
Expand Down
4 changes: 1 addition & 3 deletions stand/i386/libi386/bootinfo32.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t
/* pad to a page boundary */
addr = roundup(addr, PAGE_SIZE);

kfp = file_findfile(NULL, "elf kernel");
if (kfp == NULL)
kfp = file_findfile(NULL, "elf32 kernel");
kfp = file_findfile(NULL, md_kerntype);
if (kfp == NULL)
panic("can't find kernel file");
kernend = 0; /* fill it in later */
Expand Down
4 changes: 1 addition & 3 deletions stand/i386/libi386/bootinfo64.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ bi_load64(char *args, vm_offset_t *modulep,
/* place the metadata before anything */
module = *modulep = addr;

kfp = file_findfile(NULL, "elf kernel");
if (kfp == NULL)
kfp = file_findfile(NULL, "elf64 kernel");
kfp = file_findfile(NULL, md_kerntype);
if (kfp == NULL)
panic("can't find kernel file");
kernend = 0; /* fill it in later */
Expand Down
9 changes: 5 additions & 4 deletions stand/i386/libi386/multiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "bootstrap.h"
#include "multiboot.h"
#include "libi386.h"
#include "modinfo.h"
#include <btxv86.h>

#define MULTIBOOT_SUPPORTED_FLAGS \
Expand Down Expand Up @@ -256,7 +257,7 @@ multiboot_exec(struct preloaded_file *fp)
* module 0 module 1
*/

fp = file_findfile(NULL, "elf kernel");
fp = file_findfile(NULL, md_kerntype);
if (fp == NULL) {
printf("No FreeBSD kernel provided, aborting\n");
error = EINVAL;
Expand Down Expand Up @@ -324,22 +325,22 @@ multiboot_obj_loadfile(char *filename, uint64_t dest,
int error, mod_num;

/* See if there's a multiboot kernel loaded */
mfp = file_findfile(NULL, "elf multiboot kernel");
mfp = file_findfile(NULL, md_kerntype_mb);
if (mfp == NULL)
return (EFTYPE);

/*
* We have a multiboot kernel loaded, see if there's a FreeBSD
* kernel loaded also.
*/
kfp = file_findfile(NULL, "elf kernel");
kfp = file_findfile(NULL, md_kerntype);
if (kfp == NULL) {
/*
* No kernel loaded, this must be it. The kernel has to
* be loaded as a raw file, it will be processed by
* Xen and correctly loaded as an ELF file.
*/
rfp = file_loadraw(filename, "elf kernel", 0);
rfp = file_loadraw(filename, md_kerntype, 0);
if (rfp == NULL) {
printf(
"Unable to load %s as a multiboot payload kernel\n",
Expand Down
2 changes: 1 addition & 1 deletion stand/powerpc/ofw/elf_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ __elfN(ofw_loadfile)(char *filename, uint64_t dest,
* No need to sync the icache for modules: this will
* be done by the kernel after relocation.
*/
if (!strcmp((*result)->f_type, "elf kernel"))
if (!strcmp((*result)->f_type, md_kerntype))
__syncicache((void *) (*result)->f_addr, (*result)->f_size);
#endif
return (0);
Expand Down
2 changes: 1 addition & 1 deletion stand/powerpc/ofw/ppc64_elf_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ppc64_ofw_elf_loadfile(char *filename, uint64_t dest,
* No need to sync the icache for modules: this will
* be done by the kernel after relocation.
*/
if (!strcmp((*result)->f_type, "elf kernel"))
if (!strcmp((*result)->f_type, md_kerntype))
__syncicache((void *) (*result)->f_addr, (*result)->f_size);
return (0);
}
Expand Down
2 changes: 1 addition & 1 deletion stand/uboot/arch/powerpc/ppc64_elf_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ppc64_uboot_elf_loadfile(char *filename, uint64_t dest,
* No need to sync the icache for modules: this will
* be done by the kernel after relocation.
*/
if (!strcmp((*result)->f_type, "elf kernel"))
if (!strcmp((*result)->f_type, md_kerntype))
__syncicache((void *) (*result)->f_addr, (*result)->f_size);
return (0);
}
Expand Down
2 changes: 1 addition & 1 deletion stand/uboot/elf_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ __elfN(uboot_load)(char *filename, uint64_t dest,
* No need to sync the icache for modules: this will
* be done by the kernel after relocation.
*/
if (!strcmp((*result)->f_type, "elf kernel"))
if (!strcmp((*result)->f_type, md_kerntype))
__syncicache((void *) (*result)->f_addr, (*result)->f_size);
#endif
return (0);
Expand Down
4 changes: 1 addition & 3 deletions stand/userboot/userboot/bootinfo32.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t
/* pad to a page boundary */
addr = roundup(addr, PAGE_SIZE);

kfp = file_findfile(NULL, "elf kernel");
if (kfp == NULL)
kfp = file_findfile(NULL, "elf32 kernel");
kfp = file_findfile(NULL, md_kerntype);
if (kfp == NULL)
panic("can't find kernel file");
kernend = 0; /* fill it in later */
Expand Down
4 changes: 1 addition & 3 deletions stand/userboot/userboot/bootinfo64.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,10 @@
/* pad to a page boundary */
addr = roundup(addr, PAGE_SIZE);

kfp = file_findfile(NULL, "elf kernel");
if (kfp == NULL)
kfp = file_findfile(NULL, "elf64 kernel");
kfp = file_findfile(NULL, md_kerntype);
if (kfp == NULL)
panic("can't find kernel file");
kernend = 0; /* fill it in later */

Check warning on line 146 in stand/userboot/userboot/bootinfo64.c

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line

Check warning on line 146 in stand/userboot/userboot/bootinfo64.c

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto);
file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp);
file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend);
Expand Down
Loading
Loading