Skip to content

Commit

Permalink
multiboot: set bootloader cmdline
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianfreyer committed Feb 22, 2018
1 parent 4a9747c commit 1fc95a3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bhyveload -h <hostbase> -m <memsize> -l /path/to/multiboot.so [[-e <key>=<value>

With the following environment variables specified with -e:

| name | optional | description |
|----------|----------|---------------------------------------------------------------------------------|
| `kernel` | no | Path to the kernel image relative to `hostbase`. Must start with a leading `/`. |
| name | optional | description |
|-----------|----------|---------------------------------------------------------------------------------|
| `kernel` | no | Path to the kernel image relative to `hostbase`. Must start with a leading `/`. |
| `cmdline` | yes | command line to pass to the kernel |
14 changes: 13 additions & 1 deletion loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ size_t highmem = 0;
jmp_buf jb;

struct args loader_args = {
.kernel_filename = NULL
.kernel_filename = NULL,
.cmdline = NULL,
};

uint32_t
Expand Down Expand Up @@ -47,6 +48,10 @@ parse_args(struct args* args)

args->kernel_filename = value;
}

if (!strncmp(var, "cmdline", delim-var)) {
args->cmdline = value;
}
}

return 0;
Expand Down Expand Up @@ -124,6 +129,13 @@ loader_main(struct loader_callbacks *cb, void *arg, int version, int ndisks)
if (multiboot_load(kernel, kernsz, mb)) {
goto error;
}

if (loader_args.cmdline &&
multiboot_info_set_cmdline(&mb->info, loader_args.cmdline))
{
ERROR(EINVAL, "Could not set kernel command line");
goto error;
}
}

/* Cleanup. */
Expand Down
1 change: 1 addition & 0 deletions loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extern jmp_buf jb;

struct args {
const char* kernel_filename;
const char* cmdline;
};

extern struct loader_args args;
Expand Down
17 changes: 17 additions & 0 deletions multiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <sys/types.h>
Expand All @@ -41,6 +42,22 @@

void *entry = NULL;

uint32_t
multiboot_info_set_cmdline(struct multiboot_info* info, const char* cmdline)
{
uint32_t error = 0;
size_t length = strlen(cmdline);
void* p_addr = allocate(length+1);

if (!p_addr)
return ENOMEM;

error = CALLBACK(copyin, cmdline, p_addr, length+1);
info->cmdline = p_addr;
info->flags |= MULTIBOOT_CMDLINE;
return error;
}

struct multiboot*
mb_scan(void *kernel, size_t kernsz)
{
Expand Down
9 changes: 9 additions & 0 deletions multiboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,13 @@ multiboot_load_elf(void *kernel, size_t kernsz, Elf *kernel_elf);
uint32_t
multiboot_load(void* kernel, size_t kernsz, struct multiboot *mb);

/**
* @brief Set multiboot info command line
*
* @param info pointer to the multiboot_info struct
* @param cmdline command line to set
* @return uint32_t 0 on success, error code on failure
*/
uint32_t
multiboot_info_set_cmdline(struct multiboot_info* info, const char* cmdline);
/* vim: set noexpandtab ts=4 : */

0 comments on commit 1fc95a3

Please sign in to comment.