Skip to content

Commit b300554

Browse files
grandpaulzhangxp1998
authored andcommitted
[lib][uefi][debug_support]: re-factoring debug support code.
We modify the debug support code to support directly given the path. Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
1 parent 5f91198 commit b300554

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/uefi/debug_support.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <uefi/protocols/loaded_image_protocol.h>
2626
#include <uefi/types.h>
2727

28+
#include "charset.h"
2829
#include "uefi_platform.h"
2930

3031
struct EFI_DEVICE_PATH_FILE_PATH_PROTOCOL {
@@ -197,7 +198,7 @@ void efi_core_remove_debug_image_info_entry(EfiHandle image_handle)
197198
EfiStatus setup_debug_support(EfiSystemTable &table,
198199
char *image_base,
199200
size_t virtual_size,
200-
bdev_t *dev) {
201+
const char *dev_name) {
201202
EfiLoadedImageProtocol *efiLoadedImageProtocol = nullptr;
202203

203204
allocate_pool(EFI_MEMORY_TYPE_BOOT_SERVICES_DATA,
@@ -210,7 +211,11 @@ EfiStatus setup_debug_support(EfiSystemTable &table,
210211
efiLoadedImageProtocol->image_base = reinterpret_cast<void *>(image_base);
211212
efiLoadedImageProtocol->image_size = virtual_size;
212213
char *device_buf = nullptr;
213-
size_t fpsize = sizeof(EfiDevicePathProtocol) + 2 * (strlen(dev->name) + 2);
214+
/* fpsize is the size of the struct that EfiDevicePathProtocol stores the
215+
dev_name. And dev_name will be converted to UTF-16, and ended by null
216+
character. So the size is the length of dev_name plus one, and multiply
217+
by 2 */
218+
size_t fpsize = sizeof(EfiDevicePathProtocol) + 2 * (strlen(dev_name) + 1);
214219
allocate_pool(EFI_MEMORY_TYPE_BOOT_SERVICES_DATA,
215220
fpsize + sizeof(EfiDevicePathProtocol),
216221
reinterpret_cast<void **>(&device_buf));
@@ -221,10 +226,7 @@ EfiStatus setup_debug_support(EfiSystemTable &table,
221226
fp->dp.sub_type = EFI_DEVICE_PATH_SUB_TYPE_FILE_PATH;
222227
fp->dp.length[0] = fpsize % 256;
223228
fp->dp.length[1] = fpsize / 256;
224-
fp->str[0] = '\\';
225-
for (size_t i = 0; i < strlen(dev->name); i++) {
226-
fp->str[i+1] = dev->name[i];
227-
}
229+
utf8_to_utf16(reinterpret_cast<char16_t *>(&fp->str), dev_name, strlen(dev_name) + 1);
228230
dp_end->type = EFI_DEVICE_PATH_TYPE_END;
229231
dp_end->sub_type = EFI_DEVICE_PATH_SUB_TYPE_END;
230232
dp_end->length[0] = sizeof(EfiDevicePathProtocol) % 256;

lib/uefi/debug_support.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void efi_core_remove_debug_image_info_entry(EfiHandle image_handle);
6565
EfiStatus setup_debug_support(EfiSystemTable &table,
6666
char *image_base,
6767
size_t virtual_size,
68-
bdev_t *dev);
68+
const char *dev_name);
6969

7070
void teardown_debug_support(char *image_base);
7171

0 commit comments

Comments
 (0)