Skip to content

Commit

Permalink
support multi efi volumes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cupnes committed Sep 16, 2019
1 parent 4e96ac5 commit cb0b543
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 16 deletions.
21 changes: 19 additions & 2 deletions include/efi.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ struct EFI_MEMORY_DESCRIPTOR {
unsigned long long Attribute;
};

enum EFI_LOCATE_SEARCH_TYPE {
AllHandles,
ByRegisterNotify,
ByProtocol
};

struct EFI_SYSTEM_TABLE {
char _buf1[44];
struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL {
Expand Down Expand Up @@ -232,7 +238,11 @@ struct EFI_SYSTEM_TABLE {
//
// Protocol Handler Services
//
unsigned long long _buf5[9];
unsigned long long _buf5[3];
unsigned long long (*HandleProtocol)(void *Handle,
struct EFI_GUID *Protocol,
void **Interface);
unsigned long long _buf5_2[5];

//
// Image Services
Expand Down Expand Up @@ -283,7 +293,13 @@ struct EFI_SYSTEM_TABLE {
//
// Library Services
//
unsigned long long _buf10[2];
unsigned long long _buf10;
unsigned long long (*LocateHandleBuffer)(
enum EFI_LOCATE_SEARCH_TYPE SearchType,
struct EFI_GUID *Protocol,
void *SearchKey,
unsigned long long *NoHandles,
void ***Buffer);
unsigned long long (*LocateProtocol)(
struct EFI_GUID *Protocol,
void *Registration,
Expand Down Expand Up @@ -555,6 +571,7 @@ extern struct EFI_MP_SERVICES_PROTOCOL *MSP;
extern struct EFI_GUID lip_guid;
extern struct EFI_GUID dpp_guid;
extern struct EFI_GUID fi_guid;
extern struct EFI_GUID sfsp_guid;

void efi_init(struct EFI_SYSTEM_TABLE *SystemTable);
void dump_efi_configuration_table(void);
Expand Down
4 changes: 4 additions & 0 deletions include/file.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _FILE_H_
#define _FILE_H_

#include <efi.h>

#include "graphics.h"

#define MAX_FILE_NAME_LEN 4
Expand All @@ -16,6 +18,8 @@ struct FILE {

extern struct FILE file_list[MAX_FILE_NUM];

struct EFI_FILE_PROTOCOL *search_volume_contains_file(
unsigned short *target_filename);
unsigned long long get_file_size(struct EFI_FILE_PROTOCOL *file);
void safety_file_read(struct EFI_FILE_PROTOCOL *src, void *dst,
unsigned long long size);
Expand Down
8 changes: 3 additions & 5 deletions libuefi/efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
struct EFI_SYSTEM_TABLE *ST;
struct EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP;
struct EFI_SIMPLE_POINTER_PROTOCOL *SPP;
struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SFSP;
struct EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *STIEP;
struct EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DPTTP;
struct EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *DPFTP;
Expand All @@ -19,6 +18,9 @@ struct EFI_GUID dpp_guid = {0x09576e91, 0x6d3f, 0x11d2,
struct EFI_GUID fi_guid = {0x09576e92, 0x6d3f, 0x11d2,
{0x8e, 0x39, 0x00, 0xa0,
0xc9, 0x69, 0x72, 0x3b}};
struct EFI_GUID sfsp_guid = {0x0964e5b22, 0x6459, 0x11d2,
{0x8e, 0x39, 0x00, 0xa0,
0xc9, 0x69, 0x72, 0x3b}};

void efi_init(struct EFI_SYSTEM_TABLE *SystemTable)
{
Expand All @@ -28,9 +30,6 @@ void efi_init(struct EFI_SYSTEM_TABLE *SystemTable)
struct EFI_GUID spp_guid = {0x31878c87, 0xb75, 0x11d5,
{0x9a, 0x4f, 0x0, 0x90,
0x27, 0x3f, 0xc1, 0x4d}};
struct EFI_GUID sfsp_guid = {0x0964e5b22, 0x6459, 0x11d2,
{0x8e, 0x39, 0x00, 0xa0,
0xc9, 0x69, 0x72, 0x3b}};
struct EFI_GUID stiep_guid = {0xdd9e7534, 0x7762, 0x4698,
{0x8c, 0x14, 0xf5, 0x85,
0x17, 0xa6, 0x25, 0xaa}};
Expand All @@ -51,7 +50,6 @@ void efi_init(struct EFI_SYSTEM_TABLE *SystemTable)
ST->BootServices->SetWatchdogTimer(0, 0, 0, NULL);
ST->BootServices->LocateProtocol(&gop_guid, NULL, (void **)&GOP);
ST->BootServices->LocateProtocol(&spp_guid, NULL, (void **)&SPP);
ST->BootServices->LocateProtocol(&sfsp_guid, NULL, (void **)&SFSP);
ST->BootServices->LocateProtocol(&stiep_guid, NULL, (void **)&STIEP);
ST->BootServices->LocateProtocol(&dpttp_guid, NULL, (void **)&DPTTP);
ST->BootServices->LocateProtocol(&dpftp_guid, NULL, (void **)&DPFTP);
Expand Down
40 changes: 40 additions & 0 deletions libuefi/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,46 @@

struct FILE file_list[MAX_FILE_NUM];

struct EFI_FILE_PROTOCOL *search_volume_contains_file(
unsigned short *target_filename)
{
void **sfs_handles;
unsigned long long sfs_handles_num = 0;
unsigned long long status;
status = ST->BootServices->LocateHandleBuffer(
ByProtocol, &sfsp_guid, NULL, &sfs_handles_num,
(void ***)&sfs_handles);
assert(status, L"LocateHandleBuffer");

put_param(L"Number of volumes", sfs_handles_num);

unsigned char i;
struct EFI_FILE_PROTOCOL *fp;
for (i = 0; i < sfs_handles_num; i++) {
struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *tmp_sfsp;
status = ST->BootServices->HandleProtocol(
sfs_handles[i], &sfsp_guid, (void **)&tmp_sfsp);
if (!check_warn_error(status, L"HandleProtocol(sfs_handles)"))
continue;

status = tmp_sfsp->OpenVolume(tmp_sfsp, &fp);
if (!check_warn_error(status, L"OpenVolume(tmp_sfsp)"))
continue;

struct EFI_FILE_PROTOCOL *_target_fp;
status = fp->Open(
fp, &_target_fp, target_filename,
EFI_FILE_MODE_READ, 0);
if (!check_warn_error(
status, L"This volume don't have target file."))
continue;

return fp;
}

return NULL;
}

unsigned long long get_file_size(struct EFI_FILE_PROTOCOL *file)
{
unsigned long long status;
Expand Down
21 changes: 12 additions & 9 deletions poiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ struct ap_info {
struct EFI_SYSTEM_TABLE *system_table;
} ai;

void load_kernel(
struct EFI_FILE_PROTOCOL *root, unsigned short *kernel_file_name);
void load_kernel(struct EFI_FILE_PROTOCOL *root,
unsigned short *kernel_file_name);
unsigned char load_fs(
struct EFI_FILE_PROTOCOL *root, unsigned short *fs_file_name);
void put_n_bytes(unsigned char *addr, unsigned int num);
Expand All @@ -39,10 +39,12 @@ void efi_main(void *ImageHandle, struct EFI_SYSTEM_TABLE *SystemTable)

puts(L"Starting poiboot ...\r\n");

/* ボリュームのルートディレクトリを開く */
struct EFI_FILE_PROTOCOL *root;
unsigned long long status = SFSP->OpenVolume(SFSP, &root);
assert(status, L"SFSP->OpenVolume");
/* "kernel.bin"を含むボリュームを探す */
struct EFI_FILE_PROTOCOL *root =
search_volume_contains_file(KERNEL_FILE_NAME);
if (root == NULL) {
assert(1, L"No volume contains kernel.bin.");
}

/* コンフィグファイル・カーネルバイナリ・ファイルシステムイメージを
* 開き、コンフィグファイルの内容に従って
Expand All @@ -65,7 +67,8 @@ void efi_main(void *ImageHandle, struct EFI_SYSTEM_TABLE *SystemTable)
else
pi.fs_start = NULL;
unsigned long long nproc, nproc_en;
status = MSP->GetNumberOfProcessors(MSP, &nproc, &nproc_en);
unsigned long long status =
MSP->GetNumberOfProcessors(MSP, &nproc, &nproc_en);
assert(status, L"MSP->GetNumberOfProcessors");
pi.nproc = nproc_en;
unsigned long long kernel_arg2 = (unsigned long long)&pi;
Expand Down Expand Up @@ -104,8 +107,8 @@ void efi_main(void *ImageHandle, struct EFI_SYSTEM_TABLE *SystemTable)
while (TRUE);
}

void load_kernel(
struct EFI_FILE_PROTOCOL *root, unsigned short *kernel_file_name)
void load_kernel(struct EFI_FILE_PROTOCOL *root,
unsigned short *kernel_file_name)
{
struct EFI_FILE_PROTOCOL *file_kernel;
unsigned long long status = root->Open(
Expand Down

0 comments on commit cb0b543

Please sign in to comment.