2 * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
36 * Process command line
38 * @v loaded Loaded image protocol
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
;
45 /* Convert command line to ASCII */
46 snprintf ( cmdline
, sizeof ( cmdline
), "%ls", wcmdline
);
48 /* Process command line */
49 process_cmdline ( cmdline
);
55 * @v image_handle Image handle
56 * @v systab EFI system table
57 * @ret efirc EFI status code
59 EFI_STATUS EFIAPI
efi_main ( EFI_HANDLE image_handle
,
60 EFI_SYSTEM_TABLE
*systab
) {
61 EFI_BOOT_SERVICES
*bs
;
63 EFI_LOADED_IMAGE_PROTOCOL
*image
;
66 EFI_HANDLE vdisk
= NULL
;
67 EFI_HANDLE vpartition
= NULL
;
70 /* Record EFI handle and system table */
71 efi_image_handle
= image_handle
;
73 bs
= systab
->BootServices
;
75 /* Initialise stack cookie */
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" );
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
) );
92 /* Process command line */
93 efi_cmdline ( loaded
.image
);
95 /* Extract files from file system */
96 efi_extract ( loaded
.image
->DeviceHandle
);
98 /* Install virtual disk */
99 efi_install ( &vdisk
, &vpartition
);
101 /* Invoke boot manager */
102 efi_boot ( bootmgfw
, bootmgfw_path
, vpartition
);