|
试了一下,UEFI下还是有办法调用grub2的函数的。
大概就是写个grub2模块,安装一个protocol
- struct grub_efi_grub_protocol
- {
- /* file */
- grub_efi_status_t (*file_open) (grub_file_t *file, /* out */
- const char *name,
- enum grub_file_type type);
- grub_efi_status_t (*file_open_w) (grub_file_t *file, /* out */
- const grub_efi_char16_t *name,
- enum grub_file_type type);
- grub_efi_intn_t (*file_read) (grub_file_t *file /* in out */,
- void *buf /* out */,
- grub_efi_uintn_t len);
- grub_efi_uint64_t (*file_seek) (grub_file_t *file /* in out */,
- grub_efi_uint64_t offset);
- grub_efi_status_t (*file_close) (grub_file_t *file /* in out */);
- grub_efi_uint64_t (*file_size) (const grub_file_t file);
- grub_efi_uint64_t (*file_tell) (const grub_file_t file);
- /* command */
- grub_efi_status_t (*execute) (const char *name, int argc, char **argv);
- /* test */
- void (*test) (void);
- };
- typedef struct grub_efi_grub_protocol grub_efi_grub_protocol_t;
- ......
- static grub_efi_status_t
- prot_file_open (grub_file_t *file, const char *name, enum grub_file_type type)
- {
- *file = grub_file_open (name, type);
- if (!*file)
- return GRUB_EFI_NOT_FOUND;
- return GRUB_EFI_SUCCESS;
- }
- static grub_efi_status_t
- prot_file_open_w (grub_file_t *file, const grub_efi_char16_t *name,
- enum grub_file_type type)
- {
- grub_size_t s16_len = 0;
- unsigned char *file_name = NULL;
- s16_len = wcslen (name) + 1;
- file_name = grub_malloc (s16_len);
- if (!file_name)
- return GRUB_EFI_OUT_OF_RESOURCES;
- grub_utf16_to_utf8 (file_name, name, s16_len);
- *file = grub_file_open ((char *)file_name, type);
- grub_free (file_name);
- if (!*file)
- return GRUB_EFI_NOT_FOUND;
- return GRUB_EFI_SUCCESS;
- }
- static grub_efi_intn_t
- prot_file_read (grub_file_t *file, void *buf, grub_efi_uintn_t len)
- {
- return grub_file_read (*file, buf, len);
- }
- ......
- static grub_efi_grub_protocol_t grub_prot;
- static grub_efi_guid_t grub_prot_guid = GRUB_EFI_GRUB_PROTOCOL_GUID;
- static void
- grub_prot_init (void)
- {
- grub_prot.file_open = prot_file_open;
- grub_prot.file_open_w = prot_file_open_w;
- grub_prot.file_read = prot_file_read;
- ......
- grub_efi_boot_services_t *b;
- b = grub_efi_system_table->boot_services;
- efi_call_4 (b->install_protocol_interface,
- &grub_efi_image_handle, &grub_prot_guid,
- GRUB_EFI_NATIVE_INTERFACE, &grub_prot);
- }
- static void
- grub_prot_fini (void)
- {
- grub_efi_boot_services_t *b;
- b = grub_efi_system_table->boot_services;
- efi_call_3 (b->uninstall_protocol_interface,
- &grub_efi_image_handle, &grub_prot_guid, &grub_prot);
- }
- GRUB_MOD_INIT(grubprot)
- {
- grub_prot_init ();
- }
- GRUB_MOD_FINI(grubprot)
- {
- grub_prot_fini ();
- }
复制代码
|
|