From: Sergiu Moga Date: Tue, 28 Mar 2023 14:20:01 +0000 (+0300) Subject: plat/kvm/efi.c: Add support for initial RAM disk file X-Git-Tag: RELEASE-0.14.0~78 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=618a71d9668bc44ac5cc95e2c9001863f9dec070;p=unikraft%2Funikraft.git plat/kvm/efi.c: Add support for initial RAM disk file This enables the EFI stub to load an initial RAM disk file from the same filesystem that the Unikraft image was loaded from (the EFI System Partition) and register it as a `Memory Region Descriptor`. The name of the `initrd` file is given through the `CONFIG_UK_EFI_STUB_INITRD_FNAME` configuration entry and it tells the loader the name of the file to load from the `\EFI\BOOT` directory of the EFI System Partition. Signed-off-by: Sergiu Moga Reviewed-by: Michalis Pappas Approved-by: Razvan Deaconescu Tested-by: Unikraft CI GitHub-Closes: #909 --- diff --git a/plat/kvm/Config.uk b/plat/kvm/Config.uk index 2e8f7b278..9b2ef33c4 100644 --- a/plat/kvm/Config.uk +++ b/plat/kvm/Config.uk @@ -49,6 +49,10 @@ config KVM_BOOT_EFI_STUB_CMDLINE_FNAME string "Name of the command line arguments file" default "$(UK_NAME).cmdl" +config KVM_BOOT_EFI_STUB_INITRD_FNAME + string "Name of the initial RAM disk file" + default "$(UK_NAME).initrd" + endif choice diff --git a/plat/kvm/efi.c b/plat/kvm/efi.c index 648bca6b4..60fedcd1b 100644 --- a/plat/kvm/efi.c +++ b/plat/kvm/efi.c @@ -482,6 +482,33 @@ static void uk_efi_setup_bootinfo_cmdl(struct ukplat_bootinfo *bi) bi->cmdline_len = len; } +static void uk_efi_setup_bootinfo_initrd(struct ukplat_bootinfo *bi) +{ + struct ukplat_memregion_desc mrd = {0}; + struct uk_efi_ld_img_hndl *uk_img_hndl; + char *initrd; + __sz len; + int rc; + + if (sizeof(CONFIG_KVM_BOOT_EFI_STUB_INITRD_FNAME) <= 1) + return; + + uk_img_hndl = uk_efi_get_uk_img_hndl(); + + uk_efi_read_file(uk_img_hndl->device_handle, + UK_EFI_ABS_FNAME(CONFIG_KVM_BOOT_EFI_STUB_INITRD_FNAME), + (char **)&initrd, &len); + + mrd.pbase = (__paddr_t)initrd; + mrd.vbase = (__vaddr_t)initrd; + mrd.len = PAGE_ALIGN_UP(len); + mrd.type = UKPLAT_MEMRT_INITRD; + mrd.flags = UKPLAT_MEMRF_READ | UKPLAT_MEMRF_MAP; + rc = ukplat_memregion_list_insert(&bi->mrds, &mrd); + if (unlikely(rc < 0)) + uk_efi_crash("Failed to insert initrd mrd\n"); +} + static void uk_efi_setup_bootinfo(void) { const char bl[] = "EFI_STUB"; @@ -495,6 +522,7 @@ static void uk_efi_setup_bootinfo(void) memcpy(bi->bootloader, bl, sizeof(bl)); memcpy(bi->bootprotocol, bp, sizeof(bp)); uk_efi_setup_bootinfo_cmdl(bi); + uk_efi_setup_bootinfo_initrd(bi); uk_efi_setup_bootinfo_mrds(bi); bi->efi_st = (__u64)uk_efi_st;