Skip to content

Commit cca8757

Browse files
ZideChen0wenlingz
authored andcommitted
hv: remove the duplicated init_vm_boot_info() for partition mode
In terms of parsing multboot info, the differences between pre-launched VM and SOS are minor: - pre-launched VMs don't take bootargs from multiboot info. - The kernel_load_addr is different between pre-launched VMs and SOS. This patch removes the partition mode specific init_vm_boot_info(), and handle SOS and pre-launched VMs differently in one single init_vm_boot_info(). Also, this makes ramdisk available for pre-launched VMs. Tracked-On: #2587 Signed-off-by: Zide Chen <zide.chen@intel.com> Reviewed-by: Eddie Dong <eddie.dong@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent cf1515d commit cca8757

File tree

1 file changed

+56
-92
lines changed

1 file changed

+56
-92
lines changed

hypervisor/boot/sbl/multiboot.c

Lines changed: 56 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,6 @@
1414

1515
#define MAX_BOOT_PARAMS_LEN 64U
1616

17-
#ifdef CONFIG_PARTITION_MODE
18-
int32_t init_vm_boot_info(struct acrn_vm *vm)
19-
{
20-
struct multiboot_module *mods = NULL;
21-
struct multiboot_info *mbi = NULL;
22-
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
23-
int32_t ret = -EINVAL;
24-
25-
if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) {
26-
panic("no multiboot info found");
27-
} else {
28-
mbi = hpa2hva((uint64_t)boot_regs[1]);
29-
if (mbi != NULL) {
30-
stac();
31-
dev_dbg(ACRN_DBG_BOOT, "Multiboot detected, flag=0x%x", mbi->mi_flags);
32-
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_MODS) == 0U) {
33-
clac();
34-
panic("no kernel info found");
35-
} else {
36-
dev_dbg(ACRN_DBG_BOOT, "mod counts=%d\n", mbi->mi_mods_count);
37-
38-
/* mod[0] is for kernel&cmdline, other mod for ramdisk/firmware info*/
39-
mods = (struct multiboot_module *)(uint64_t)mbi->mi_mods_addr;
40-
41-
dev_dbg(ACRN_DBG_BOOT, "mod0 start=0x%x, end=0x%x",
42-
mods[0].mm_mod_start, mods[0].mm_mod_end);
43-
dev_dbg(ACRN_DBG_BOOT, "cmd addr=0x%x, str=%s",
44-
mods[0].mm_string, (char *)(uint64_t)mods[0].mm_string);
45-
46-
vm->sw.kernel_type = VM_LINUX_GUEST;
47-
vm->sw.kernel_info.kernel_src_addr = hpa2hva((uint64_t)mods[0].mm_mod_start);
48-
vm->sw.kernel_info.kernel_size = mods[0].mm_mod_end - mods[0].mm_mod_start;
49-
vm->sw.kernel_info.kernel_load_addr = (void *)(MEM_1M * 16U);
50-
vm->sw.linux_info.bootargs_src_addr = (void *)vm_config->os_config.bootargs;
51-
vm->sw.linux_info.bootargs_size = strnlen_s(vm_config->os_config.bootargs, MEM_2K);
52-
vm->sw.linux_info.bootargs_load_addr =
53-
vm->sw.kernel_info.kernel_load_addr - (MEM_1K * 8U);
54-
clac();
55-
ret = 0;
56-
}
57-
}
58-
}
59-
return ret;
60-
}
61-
62-
#else
6317
/* There are two sources for sos_vm kernel cmdline:
6418
* - cmdline from sbl. mbi->cmdline
6519
* - cmdline from acrn stitching tool. mod[0].mm_string
@@ -189,59 +143,70 @@ int32_t init_vm_boot_info(struct acrn_vm *vm)
189143
vm->sw.kernel_type = VM_LINUX_GUEST;
190144
vm->sw.kernel_info.kernel_src_addr = hpa2hva((uint64_t)mods[0].mm_mod_start);
191145
vm->sw.kernel_info.kernel_size = mods[0].mm_mod_end - mods[0].mm_mod_start;
192-
vm->sw.kernel_info.kernel_load_addr =
193-
(void *)hva2gpa(vm, get_kernel_load_addr(vm->sw.kernel_info.kernel_src_addr));
194-
195-
/*
196-
* If there is cmdline from mbi->mi_cmdline, merge it with
197-
* mods[0].mm_string
198-
*/
199-
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0U) {
200-
char *cmd_src, *cmd_dst;
201-
uint32_t off = 0U;
202-
bool status = false;
203-
char buf[MAX_BOOT_PARAMS_LEN];
204-
205-
cmd_dst = kernel_cmdline;
206-
cmd_src = (char *)hpa2hva((uint64_t)mbi->mi_cmdline);
207-
208-
(void)memset(buf, 0U, sizeof(buf));
146+
147+
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
148+
149+
if (vm_config->type == PRE_LAUNCHED_VM) {
150+
vm->sw.kernel_info.kernel_load_addr = (void *)(MEM_1M * 16U);
151+
vm->sw.linux_info.bootargs_src_addr = (void *)vm_config->os_config.bootargs;
152+
vm->sw.linux_info.bootargs_size =
153+
strnlen_s(vm_config->os_config.bootargs, MEM_2K);
154+
} else {
155+
vm->sw.kernel_info.kernel_load_addr = (void *)hva2gpa(vm,
156+
get_kernel_load_addr(vm->sw.kernel_info.kernel_src_addr));
157+
209158
/*
210-
* The seed passing interface is different for ABL and SBL,
211-
* so here first try to get seed from SBL, if fail then try
212-
* ABL.
159+
* If there is cmdline from mbi->mi_cmdline, merge it with
160+
* mods[0].mm_string
213161
*/
214-
status = sbl_seed_parse(vm, cmd_src, buf, sizeof(buf));
215-
if (!status) {
216-
status = abl_seed_parse(vm, cmd_src, buf, sizeof(buf));
217-
}
162+
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0U) {
163+
char *cmd_src, *cmd_dst;
164+
uint32_t off = 0U;
165+
bool status = false;
166+
char buf[MAX_BOOT_PARAMS_LEN];
167+
168+
cmd_dst = kernel_cmdline;
169+
cmd_src = (char *)hpa2hva((uint64_t)mbi->mi_cmdline);
218170

219-
if (status) {
171+
(void)memset(buf, 0U, sizeof(buf));
220172
/*
221-
* append the seed argument to kernel cmdline
173+
* The seed passing interface is different for ABL and SBL,
174+
* so here first try to get seed from SBL, if fail then try
175+
* ABL.
222176
*/
223-
(void)strncpy_s(cmd_dst, MEM_2K, buf, MAX_BOOT_PARAMS_LEN);
224-
off = strnlen_s(cmd_dst, MEM_2K);
225-
}
226-
227-
cmd_dst += off;
228-
(void)strncpy_s(cmd_dst, MEM_2K - off, (const char *)cmd_src,
229-
strnlen_s(cmd_src, MEM_2K - off));
230-
off = strnlen_s(cmd_dst, MEM_2K - off);
231-
cmd_dst[off] = ' '; /* insert space */
232-
off += 1U;
177+
status = sbl_seed_parse(vm, cmd_src, buf, sizeof(buf));
178+
if (!status) {
179+
status = abl_seed_parse(vm, cmd_src, buf, sizeof(buf));
180+
}
181+
182+
if (status) {
183+
/*
184+
* append the seed argument to kernel cmdline
185+
*/
186+
(void)strncpy_s(cmd_dst, MEM_2K, buf, MAX_BOOT_PARAMS_LEN);
187+
off = strnlen_s(cmd_dst, MEM_2K);
188+
}
189+
190+
cmd_dst += off;
191+
(void)strncpy_s(cmd_dst, MEM_2K - off, (const char *)cmd_src,
192+
strnlen_s(cmd_src, MEM_2K - off));
193+
off = strnlen_s(cmd_dst, MEM_2K - off);
194+
cmd_dst[off] = ' '; /* insert space */
195+
off += 1U;
233196

234-
cmd_dst += off;
235-
cmd_src = (char *)hpa2hva((uint64_t)mods[0].mm_string);
236-
(void)strncpy_s(cmd_dst, MEM_2K - off, cmd_src,
197+
cmd_dst += off;
198+
cmd_src = (char *)hpa2hva((uint64_t)mods[0].mm_string);
199+
(void)strncpy_s(cmd_dst, MEM_2K - off, cmd_src,
237200
strnlen_s(cmd_src, MEM_2K - off));
238201

239-
vm->sw.linux_info.bootargs_src_addr = kernel_cmdline;
240-
vm->sw.linux_info.bootargs_size = strnlen_s(kernel_cmdline, MEM_2K);
241-
} else {
242-
vm->sw.linux_info.bootargs_src_addr = hpa2hva((uint64_t)mods[0].mm_string);
243-
vm->sw.linux_info.bootargs_size =
244-
strnlen_s(hpa2hva((uint64_t)mods[0].mm_string), MEM_2K);
202+
vm->sw.linux_info.bootargs_src_addr = kernel_cmdline;
203+
vm->sw.linux_info.bootargs_size = strnlen_s(kernel_cmdline, MEM_2K);
204+
} else {
205+
vm->sw.linux_info.bootargs_src_addr =
206+
hpa2hva((uint64_t)mods[0].mm_string);
207+
vm->sw.linux_info.bootargs_size =
208+
strnlen_s(hpa2hva((uint64_t)mods[0].mm_string), MEM_2K);
209+
}
245210
}
246211

247212
/* Kernel bootarg and zero page are right before the kernel image */
@@ -259,4 +224,3 @@ int32_t init_vm_boot_info(struct acrn_vm *vm)
259224
}
260225
return ret;
261226
}
262-
#endif

0 commit comments

Comments
 (0)