xref: /DragonStub/apps/stub.c (revision 78b790fa8bc8298f8bdfd5bd1945781650dbf361)
1 #include <efi.h>
2 #include <efilib.h>
3 #include <dragonstub/dragonstub.h>
4 
5 EFI_STATUS efi_handle_cmdline(EFI_LOADED_IMAGE *image, char **cmdline_ptr)
6 {
7 	int cmdline_size = 0;
8 	EFI_STATUS status;
9 	char *cmdline;
10 
11 	/*
12 	 * Get the command line from EFI, using the LOADED_IMAGE
13 	 * protocol. We are going to copy the command line into the
14 	 * device tree, so this can be allocated anywhere.
15 	 */
16 	cmdline = efi_convert_cmdline(image, &cmdline_size);
17 	if (!cmdline) {
18 		efi_err("getting command line via LOADED_IMAGE_PROTOCOL\n");
19 		return EFI_OUT_OF_RESOURCES;
20 	}
21 
22 	// 	if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
23 	// 	    IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
24 	// 	    cmdline_size == 0) {
25 	// 		status = efi_parse_options(CONFIG_CMDLINE);
26 	// 		if (status != EFI_SUCCESS) {
27 	// 			efi_err("Failed to parse options\n");
28 	// 			goto fail_free_cmdline;
29 	// 		}
30 	// 	}
31 
32 	// if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0) {
33 	if (cmdline_size > 0) {
34 		status = efi_parse_options(cmdline);
35 		if (status != EFI_SUCCESS) {
36 			efi_err("Failed to parse options\n");
37 			goto fail_free_cmdline;
38 		}
39 	}
40 
41 	*cmdline_ptr = cmdline;
42 	return EFI_SUCCESS;
43 
44 fail_free_cmdline:
45 	efi_bs_call(FreePool, cmdline_ptr);
46 	return status;
47 }