From: Zixuan Wang <zxwang42@xxxxxxxxx> This commit enables kvm-unit-tests to get args from the host through UEFI. Previously, when compiled to run under UEFI, kvm-unit-tests could not get args from the host through QEMU's '-append' argument. This is because kvm-unit-tests (under UEFI) does not rely on QEMU's '-kernel' argument, while without which, QEMU rejects the '-append' argument. This commit enables the host to pass the args through a file. This process is similar to the '-initrd' support introduced in the previous commit. Signed-off-by: Zixuan Wang <zxwang42@xxxxxxxxx> --- lib/efi.c | 24 ++++++++++++++++++++++++ x86/efi/run | 12 +++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/efi.c b/lib/efi.c index 4ddc3a4..dfde788 100644 --- a/lib/efi.c +++ b/lib/efi.c @@ -14,6 +14,7 @@ /* From lib/argv.c */ extern int __argc, __envc; +extern const char *__args; extern char *__argv[100]; extern char *__environ[200]; @@ -212,6 +213,28 @@ efi_set_up_envs_error: return EFI_ABORTED; } +static efi_status_t efi_set_up_args(efi_file_protocol_t *volume) +{ + efi_char16_t file_name[] = L"ARGS.TXT"; + unsigned long file_size; + char *file_data = NULL; + efi_status_t status; + + status = efi_read_file(volume, file_name, &file_size, &file_data); + if (status != EFI_SUCCESS) { + printf("Failed to read file\n"); + goto efi_set_up_envs_error; + } + + __args = file_data; + __setup_args(); + + return EFI_SUCCESS; + +efi_set_up_envs_error: + return EFI_ABORTED; +} + efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) { int ret; @@ -234,6 +257,7 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) } efi_set_up_envs(volume); + efi_set_up_args(volume); /* Set up efi_bootinfo */ efi_bootinfo.mem_map.map = ↦ diff --git a/x86/efi/run b/x86/efi/run index f4a5930..e02a6e1 100755 --- a/x86/efi/run +++ b/x86/efi/run @@ -44,9 +44,10 @@ fi mkdir -p "$EFI_CASE_DIR" cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_CASE_BINARY" -# Capture -initrd +# Capture -initrd and -append efi_qemu_args="" efi_qemu_initrd="" +efi_qemu_append="" while [[ -n "$1" ]]; do case "$1" in --initrd|-initrd) @@ -54,6 +55,11 @@ while [[ -n "$1" ]]; do efi_qemu_initrd="$1" shift 1 ;; + --append|-append) + shift 1 + efi_qemu_append="$1" + shift 1 + ;; *) efi_qemu_args+=" $1" shift 1 @@ -67,6 +73,10 @@ KVM_UNIT_TESTS_EFI_ENV="$EFI_TEST/$EFI_CASE/ENVS.TXT" mv "$KVM_UNIT_TESTS_ENV" "$KVM_UNIT_TESTS_EFI_ENV" [[ -f "$efi_qemu_initrd" ]] && cat "$efi_qemu_initrd" >> "$KVM_UNIT_TESTS_EFI_ENV" +# Create ARGS file +KVM_UNIT_TESTS_EFI_ARG="$EFI_TEST/$EFI_CASE/ARGS.TXT" +echo -n "$efi_qemu_append" > "$KVM_UNIT_TESTS_EFI_ARG" + # Run test case with 256MiB QEMU memory. QEMU default memory size is 128MiB. # After UEFI boot up and we call `LibMemoryMap()`, the largest consecutive # memory region is ~42MiB. Although this is sufficient for many test cases to -- 2.35.1