Skip to content

Commit

Permalink
vm_arm: add support for multiple OSs
Browse files Browse the repository at this point in the history
This commit allows the vm_arm component to run multiple OSs by removing
cmake variables and replacing them with camkes variables. Since cmake
variables apply to the entire project, this forces a system with two
VMs to each apply the CMake variables, which could break one of the
VMs. By replacing the variables with camkes flags, the functionality
remains, while allowing for more flexibility.

Signed-off-by: Chris Guikema <chris.guikema@dornerworks.com>
  • Loading branch information
chrisguikema committed Oct 26, 2022
1 parent 6156b25 commit 6a4faa1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
16 changes: 0 additions & 16 deletions components/VM_Arm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,6 @@ config_option(
OFF
)

config_option(
VmInitRdFile
VM_INITRD_FILE
"Enables the option for the VM to open and load a seperate initrd file"
DEFAULT
OFF
)

config_option(
VmDtbFile
VM_DTB_FILE
"Enables the option for the VM to open and load a seperate dtb file"
DEFAULT
OFF
)

add_config_library(arm_vm "${configure_string}")

DeclareCAmkESARMVM(VM)
6 changes: 6 additions & 0 deletions components/VM_Arm/configurations/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
string dtb_addr; \
string initrd_max_size; \
string initrd_addr; \
string kernel_entry_addr = "0"; \
} vm_address_config; \
attribute { \
string kernel_name = "linux"; \
Expand All @@ -79,6 +80,11 @@
string kernel_bootcmdline = ""; \
string kernel_stdout = ""; \
string dtb_base_name = ""; \
int provide_dtb = true; \
int generate_dtb = false; \
int provide_initrd = true; \
int clean_cache = false; \
int map_unity = false; \
} vm_image_config; \


Expand Down
27 changes: 23 additions & 4 deletions components/VM_Arm/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ unsigned long ram_offset;
unsigned long dtb_addr;
unsigned long initrd_max_size;
unsigned long initrd_addr;
unsigned long entry_addr;

void camkes_make_simple(simple_t *simple);

Expand Down Expand Up @@ -788,7 +789,7 @@ static int generate_fdt(vm_t *vm, void *fdt_ori, void *gen_fdt, int buf_size, si
return -1;
}

if (config_set(CONFIG_VM_INITRD_FILE)) {
if (vm_image_config.provide_initrd) {
err = fdt_append_chosen_node_with_initrd_info(gen_fdt, initrd_addr, initrd_size);
if (err) {
return -1;
Expand Down Expand Up @@ -820,13 +821,29 @@ static int load_vm(vm_t *vm, const char *kernel_name, const char *dtb_name, cons
seL4_Word dtb;
int err;

vm->mem.unity = vm_image_config.map_unity; /* Map memory 1:1 if configured to do so */

/* Install devices */
err = install_vm_devices(vm);
if (err) {
printf("Error: Failed to install Linux devices\n");
return -1;
}

/* If the entry_addr isn't set, just use the previous default logic */
if (!entry_addr) {
if (config_set(CONFIG_PLAT_TX1) || config_set(CONFIG_PLAT_TX2) || config_set(CONFIG_PLAT_QEMU_ARM_VIRT) ||
config_set(CONFIG_PLAT_ODROIDC2) || config_set(CONFIG_PLAT_ZYNQMP)) {
/* This is likely an aarch64/aarch32 linux difference */
vm->entry = ram_base + 0x80000;
} else {
vm->entry = ram_base + 0x8000;
}
} else {
vm->entry = entry_addr;
}
vm->mem.clean_cache = vm_image_config.clean_cache;

printf("Loading Kernel: \'%s\'\n", kernel_name);

/* Load kernel */
Expand All @@ -839,7 +856,7 @@ static int load_vm(vm_t *vm, const char *kernel_name, const char *dtb_name, cons

/* Attempt to load initrd if provided */
guest_image_t initrd_image;
if (config_set(CONFIG_VM_INITRD_FILE)) {
if (vm_image_config.provide_initrd) {
printf("Loading Initrd: \'%s\'\n", initrd_name);
err = vm_load_guest_module(vm, initrd_name, initrd_addr, 0, &initrd_image);
void *initrd = (void *)initrd_image.load_paddr;
Expand All @@ -848,8 +865,9 @@ static int load_vm(vm_t *vm, const char *kernel_name, const char *dtb_name, cons
}
}

if (!config_set(CONFIG_VM_DTB_FILE)) {
if (vm_image_config.generate_dtb) {
void *fdt_ori;

void *gen_fdt = linux_gen_dtb_buf;
int size_gen = PLAT_LINUX_DTB_SIZE;
int num_paths = 0;
Expand Down Expand Up @@ -882,7 +900,7 @@ static int load_vm(vm_t *vm, const char *kernel_name, const char *dtb_name, cons
vm_ram_touch(vm, dtb_addr, size_gen, load_generated_dtb, gen_fdt);
printf("Loading Generated DTB");
dtb = dtb_addr;
} else {
} else if (vm_image_config.provide_dtb) {
printf("Loading DTB: \'%s\'\n", dtb_name);

/* Load device tree */
Expand Down Expand Up @@ -913,6 +931,7 @@ void parse_camkes_vm_attributes(void)
dtb_addr = strtoul(vm_address_config.dtb_addr, NULL, 0);
initrd_max_size = strtoul(vm_address_config.initrd_max_size, NULL, 0);
initrd_addr = strtoul(vm_address_config.initrd_addr, NULL, 0);
entry_addr = strtoul(vm_address_config.kernel_entry_addr, NULL, 0);
}

/* Async event handling registration implementation */
Expand Down
9 changes: 1 addition & 8 deletions components/VM_Arm/src/modules/init_ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ extern unsigned long ram_size;

void WEAK init_ram_module(vm_t *vm, void *cookie)
{
int err;

if (config_set(CONFIG_PLAT_EXYNOS5) || config_set(CONFIG_PLAT_QEMU_ARM_VIRT) || config_set(CONFIG_PLAT_TX2)) {
err = vm_ram_register_at(vm, ram_base, ram_size, true);
} else {
err = vm_ram_register_at(vm, ram_base, ram_size, false);
}
assert(!err);
assert(!vm_ram_register_at(vm, ram_base, ram_size, vm->mem.unity));
}

DEFINE_MODULE(init_ram, NULL, init_ram_module)

0 comments on commit 6a4faa1

Please sign in to comment.