2525#include < uefi/protocols/loaded_image_protocol.h>
2626#include < uefi/types.h>
2727
28+ #include " charset.h"
2829#include " uefi_platform.h"
2930
3031struct EFI_DEVICE_PATH_FILE_PATH_PROTOCOL {
@@ -197,7 +198,7 @@ void efi_core_remove_debug_image_info_entry(EfiHandle image_handle)
197198EfiStatus 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 ;
0 commit comments