Skip to content

Commit 46c26f6

Browse files
committed
[lib][uefi] Allow load_pe_file to be called from other apps/libs
1 parent f2e7c19 commit 46c26f6

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

lib/uefi/include/uefi.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
#ifndef __LIB_UEFI_HEADER_
3+
#define __LIB_UEFI_HEADER_
4+
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
9+
int load_pe_file(const char *blkdev);
10+
11+
#ifdef __cplusplus
12+
}
13+
#endif
14+
15+
#endif

lib/uefi/uefi.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "system_table.h"
4242
#include "text_protocol.h"
4343

44+
#include <uefi.h>
45+
4446
namespace {
4547

4648
constexpr auto EFI_SYSTEM_TABLE_SIGNATURE =
@@ -130,6 +132,23 @@ int load_sections_and_execute(bdev_t *dev,
130132
return call_with_stack(stack + kStackSize, entry, image_base, &table);
131133
}
132134

135+
136+
int cmd_uefi_load(int argc, const console_cmd_args *argv) {
137+
if (argc != 2) {
138+
printf("Usage: %s <name of block device to load from>\n", argv[0].str);
139+
return 1;
140+
}
141+
load_pe_file(argv[1].str);
142+
return 0;
143+
}
144+
145+
STATIC_COMMAND_START
146+
STATIC_COMMAND("uefi_load", "load UEFI application and run it", &cmd_uefi_load)
147+
STATIC_COMMAND_END(uefi);
148+
149+
} // namespace
150+
151+
133152
int load_pe_file(const char *blkdev) {
134153
bdev_t *dev = bio_open(blkdev);
135154
if (!dev) {
@@ -186,18 +205,3 @@ int load_pe_file(const char *blkdev) {
186205
printf("UEFI Application return code: %d\n", ret);
187206
return ret;
188207
}
189-
190-
int cmd_uefi_load(int argc, const console_cmd_args *argv) {
191-
if (argc != 2) {
192-
printf("Usage: %s <name of block device to load from>\n", argv[0].str);
193-
return 1;
194-
}
195-
load_pe_file(argv[1].str);
196-
return 0;
197-
}
198-
199-
STATIC_COMMAND_START
200-
STATIC_COMMAND("uefi_load", "load UEFI application and run it", &cmd_uefi_load)
201-
STATIC_COMMAND_END(uefi);
202-
203-
} // namespace

0 commit comments

Comments
 (0)