]>
git.proxmox.com Git - efi-boot-shim.git/blob - lib/execute.c
2 * Copyright 2012 <James.Bottomley@HansenPartnership.com>
8 * generate_path is a cut and paste from
10 * git://github.com/mjg59/shim.git
12 * Code Copyright 2012 Red Hat, Inc <mjg@redhat.com>
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
18 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
21 * Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
37 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 generate_path(CHAR16
* name
, EFI_LOADED_IMAGE
*li
, EFI_DEVICE_PATH
**path
, CHAR16
**PathName
)
51 EFI_STATUS efi_status
= EFI_SUCCESS
;
52 CHAR16
*devpathstr
= DevicePathToStr(li
->FilePath
),
56 for (i
= 0; i
< StrLen(devpathstr
); i
++) {
57 if (devpathstr
[i
] == '/')
59 if (devpathstr
[i
] == '\\')
60 found
= &devpathstr
[i
];
65 while (*(found
- 1) == '\\')
68 pathlen
= StrLen(devpathstr
);
74 *PathName
= AllocatePool((pathlen
+ 1 + StrLen(name
))*sizeof(CHAR16
));
77 Print(L
"Failed to allocate path buffer\n");
78 efi_status
= EFI_OUT_OF_RESOURCES
;
82 StrCpy(*PathName
, devpathstr
);
85 StrCat(*PathName
, L
"\\");
86 StrCat(*PathName
, name
);
88 *path
= FileDevicePath(li
->DeviceHandle
, *PathName
);
97 execute(EFI_HANDLE image
, CHAR16
*name
)
101 EFI_LOADED_IMAGE
*li
;
102 EFI_DEVICE_PATH
*devpath
;
105 status
= uefi_call_wrapper(BS
->HandleProtocol
, 3, image
,
106 &IMAGE_PROTOCOL
, (void **)&li
);
107 if (status
!= EFI_SUCCESS
)
111 status
= generate_path(name
, li
, &devpath
, &PathName
);
112 if (status
!= EFI_SUCCESS
)
115 status
= uefi_call_wrapper(BS
->LoadImage
, 6, FALSE
, image
,
116 devpath
, NULL
, 0, &h
);
117 if (status
!= EFI_SUCCESS
)
120 status
= uefi_call_wrapper(BS
->StartImage
, 3, h
, NULL
, NULL
);
121 uefi_call_wrapper(BS
->UnloadImage
, 1, h
);