]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - wimboot/wimboot-2.7.3/src/efimain.c
1.1.07 release
[Ventoy.git] / wimboot / wimboot-2.7.3 / src / efimain.c
1 /*
2 * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 */
19
20 /**
21 * @file
22 *
23 * EFI entry point
24 *
25 */
26
27 #include <stdio.h>
28 #include "wimboot.h"
29 #include "cmdline.h"
30 #include "efi.h"
31 #include "efifile.h"
32 #include "efiblock.h"
33 #include "efiboot.h"
34
35 /**
36 * Process command line
37 *
38 * @v loaded Loaded image protocol
39 */
40 static void efi_cmdline ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
41 size_t cmdline_len = ( loaded->LoadOptionsSize / sizeof ( wchar_t ) );
42 char cmdline[ cmdline_len + 1 /* NUL */ ];
43 const wchar_t *wcmdline = loaded->LoadOptions;
44
45 /* Convert command line to ASCII */
46 snprintf ( cmdline, sizeof ( cmdline ), "%ls", wcmdline );
47
48 /* Process command line */
49 process_cmdline ( cmdline );
50 }
51
52 /**
53 * EFI entry point
54 *
55 * @v image_handle Image handle
56 * @v systab EFI system table
57 * @ret efirc EFI status code
58 */
59 EFI_STATUS EFIAPI efi_main ( EFI_HANDLE image_handle,
60 EFI_SYSTEM_TABLE *systab ) {
61 EFI_BOOT_SERVICES *bs;
62 union {
63 EFI_LOADED_IMAGE_PROTOCOL *image;
64 void *interface;
65 } loaded;
66 EFI_HANDLE vdisk = NULL;
67 EFI_HANDLE vpartition = NULL;
68 EFI_STATUS efirc;
69
70 /* Record EFI handle and system table */
71 efi_image_handle = image_handle;
72 efi_systab = systab;
73 bs = systab->BootServices;
74
75 /* Initialise stack cookie */
76 init_cookie();
77
78 /* Print welcome banner */
79 printf ( "\n\nBooting wim file...... (This may take a few minutes, please wait)\n\n");
80 // printf ( "\n\nwimboot " VERSION " -- Windows Imaging Format "
81 // "bootloader -- https://ipxe.org/wimboot\n\n" );
82
83 /* Get loaded image protocol */
84 if ( ( efirc = bs->OpenProtocol ( image_handle,
85 &efi_loaded_image_protocol_guid,
86 &loaded.interface, image_handle, NULL,
87 EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
88 die ( "Could not open loaded image protocol: %#lx\n",
89 ( ( unsigned long ) efirc ) );
90 }
91
92 /* Process command line */
93 efi_cmdline ( loaded.image );
94
95 /* Extract files from file system */
96 efi_extract ( loaded.image->DeviceHandle );
97
98 /* Install virtual disk */
99 efi_install ( &vdisk, &vpartition );
100
101 /* Invoke boot manager */
102 efi_boot ( bootmgfw, bootmgfw_path, vpartition );
103
104 return 0;
105 }