无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
楼主: dido0379
打印 上一主题 下一主题

[发布] UEFI下利用ixpe远程加载isoboot直接启动PE光盘镜像

    [复制链接]
1#
发表于 2019-10-25 19:10:07 | 显示全部楼层
试了一下,UEFI下还是有办法调用grub2的函数的。

大概就是写个grub2模块,安装一个protocol
  1. struct grub_efi_grub_protocol
  2. {
  3.   /* file */
  4.   grub_efi_status_t (*file_open) (grub_file_t *file, /* out */
  5.                                   const char *name,
  6.                                   enum grub_file_type type);
  7.   grub_efi_status_t (*file_open_w) (grub_file_t *file, /* out */
  8.                                     const grub_efi_char16_t *name,
  9.                                     enum grub_file_type type);
  10.   grub_efi_intn_t (*file_read) (grub_file_t *file /* in out */,
  11.                                 void *buf /* out */,
  12.                                 grub_efi_uintn_t len);
  13.   grub_efi_uint64_t (*file_seek) (grub_file_t *file /* in out */,
  14.                                   grub_efi_uint64_t offset);
  15.   grub_efi_status_t (*file_close) (grub_file_t *file /* in out */);
  16.   grub_efi_uint64_t (*file_size) (const grub_file_t file);
  17.   grub_efi_uint64_t (*file_tell) (const grub_file_t file);
  18.   /* command */
  19.   grub_efi_status_t (*execute) (const char *name, int argc, char **argv);
  20.   /* test */
  21.   void (*test) (void);
  22. };
  23. typedef struct grub_efi_grub_protocol grub_efi_grub_protocol_t;
  24. ......
  25. static grub_efi_status_t
  26. prot_file_open (grub_file_t *file, const char *name, enum grub_file_type type)
  27. {
  28.   *file = grub_file_open (name, type);
  29.   if (!*file)
  30.     return GRUB_EFI_NOT_FOUND;
  31.   return GRUB_EFI_SUCCESS;
  32. }

  33. static grub_efi_status_t
  34. prot_file_open_w (grub_file_t *file, const grub_efi_char16_t *name,
  35.                   enum grub_file_type type)
  36. {
  37.   grub_size_t s16_len = 0;
  38.   unsigned char *file_name = NULL;

  39.   s16_len = wcslen (name) + 1;
  40.   file_name = grub_malloc (s16_len);
  41.   if (!file_name)
  42.     return GRUB_EFI_OUT_OF_RESOURCES;
  43.   grub_utf16_to_utf8 (file_name, name, s16_len);
  44.   *file = grub_file_open ((char *)file_name, type);
  45.   grub_free (file_name);
  46.   if (!*file)
  47.     return GRUB_EFI_NOT_FOUND;
  48.   return GRUB_EFI_SUCCESS;
  49. }

  50. static grub_efi_intn_t
  51. prot_file_read (grub_file_t *file, void *buf, grub_efi_uintn_t len)
  52. {
  53.   return grub_file_read (*file, buf, len);
  54. }
  55. ......
  56. static grub_efi_grub_protocol_t grub_prot;
  57. static grub_efi_guid_t grub_prot_guid = GRUB_EFI_GRUB_PROTOCOL_GUID;

  58. static void
  59. grub_prot_init (void)
  60. {
  61.   grub_prot.file_open = prot_file_open;
  62.   grub_prot.file_open_w = prot_file_open_w;
  63.   grub_prot.file_read = prot_file_read;
  64. ......
  65.   grub_efi_boot_services_t *b;

  66.   b = grub_efi_system_table->boot_services;
  67.   efi_call_4 (b->install_protocol_interface,
  68.               &grub_efi_image_handle, &grub_prot_guid,
  69.               GRUB_EFI_NATIVE_INTERFACE, &grub_prot);
  70. }

  71. static void
  72. grub_prot_fini (void)
  73. {
  74.   grub_efi_boot_services_t *b;

  75.   b = grub_efi_system_table->boot_services;
  76.   efi_call_3 (b->uninstall_protocol_interface,
  77.               &grub_efi_image_handle, &grub_prot_guid, &grub_prot);
  78. }

  79. GRUB_MOD_INIT(grubprot)
  80. {
  81.   grub_prot_init ();
  82. }

  83. GRUB_MOD_FINI(grubprot)
  84. {
  85.   grub_prot_fini ();
  86. }
复制代码

点评

牛,那GRUB_PROTOCOL是本来就有还是w大你自己设计的?  详情 回复 发表于 2019-10-27 16:03
回复

使用道具 举报

2#
发表于 2019-10-27 17:45:33 | 显示全部楼层
dido0379 发表于 2019-10-27 16:03
牛,那GRUB_PROTOCOL是本来就有还是w大你自己设计的?

自己设计的。
话说loaded_image_protocol在低版本uefi下是不是不好用?
通过自己写的protocol传递cmdline是不是更靠谱?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-6-18 23:45

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表