|
@@ -16,6 +16,26 @@
|
|
|
|
|
|
static efi_system_table_t *sys_table;
|
|
static efi_system_table_t *sys_table;
|
|
|
|
|
|
|
|
+static void efi_printk(char *str)
|
|
|
|
+{
|
|
|
|
+ char *s8;
|
|
|
|
+
|
|
|
|
+ for (s8 = str; *s8; s8++) {
|
|
|
|
+ struct efi_simple_text_output_protocol *out;
|
|
|
|
+ efi_char16_t ch[2] = { 0 };
|
|
|
|
+
|
|
|
|
+ ch[0] = *s8;
|
|
|
|
+ out = (struct efi_simple_text_output_protocol *)sys_table->con_out;
|
|
|
|
+
|
|
|
|
+ if (*s8 == '\n') {
|
|
|
|
+ efi_char16_t nl[2] = { '\r', 0 };
|
|
|
|
+ efi_call_phys2(out->output_string, out, nl);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ efi_call_phys2(out->output_string, out, ch);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
static efi_status_t __get_map(efi_memory_desc_t **map, unsigned long *map_size,
|
|
static efi_status_t __get_map(efi_memory_desc_t **map, unsigned long *map_size,
|
|
unsigned long *desc_size)
|
|
unsigned long *desc_size)
|
|
{
|
|
{
|
|
@@ -531,8 +551,10 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
|
|
EFI_LOADER_DATA,
|
|
EFI_LOADER_DATA,
|
|
nr_initrds * sizeof(*initrds),
|
|
nr_initrds * sizeof(*initrds),
|
|
&initrds);
|
|
&initrds);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to alloc mem for initrds\n");
|
|
goto fail;
|
|
goto fail;
|
|
|
|
+ }
|
|
|
|
|
|
str = (char *)(unsigned long)hdr->cmd_line_ptr;
|
|
str = (char *)(unsigned long)hdr->cmd_line_ptr;
|
|
for (i = 0; i < nr_initrds; i++) {
|
|
for (i = 0; i < nr_initrds; i++) {
|
|
@@ -575,32 +597,42 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
|
|
|
|
|
|
status = efi_call_phys3(boottime->handle_protocol,
|
|
status = efi_call_phys3(boottime->handle_protocol,
|
|
image->device_handle, &fs_proto, &io);
|
|
image->device_handle, &fs_proto, &io);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to handle fs_proto\n");
|
|
goto free_initrds;
|
|
goto free_initrds;
|
|
|
|
+ }
|
|
|
|
|
|
status = efi_call_phys2(io->open_volume, io, &fh);
|
|
status = efi_call_phys2(io->open_volume, io, &fh);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to open volume\n");
|
|
goto free_initrds;
|
|
goto free_initrds;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
status = efi_call_phys5(fh->open, fh, &h, filename_16,
|
|
status = efi_call_phys5(fh->open, fh, &h, filename_16,
|
|
EFI_FILE_MODE_READ, (u64)0);
|
|
EFI_FILE_MODE_READ, (u64)0);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to open initrd file\n");
|
|
goto close_handles;
|
|
goto close_handles;
|
|
|
|
+ }
|
|
|
|
|
|
initrd->handle = h;
|
|
initrd->handle = h;
|
|
|
|
|
|
info_sz = 0;
|
|
info_sz = 0;
|
|
status = efi_call_phys4(h->get_info, h, &info_guid,
|
|
status = efi_call_phys4(h->get_info, h, &info_guid,
|
|
&info_sz, NULL);
|
|
&info_sz, NULL);
|
|
- if (status != EFI_BUFFER_TOO_SMALL)
|
|
|
|
|
|
+ if (status != EFI_BUFFER_TOO_SMALL) {
|
|
|
|
+ efi_printk("Failed to get initrd info size\n");
|
|
goto close_handles;
|
|
goto close_handles;
|
|
|
|
+ }
|
|
|
|
|
|
grow:
|
|
grow:
|
|
status = efi_call_phys3(sys_table->boottime->allocate_pool,
|
|
status = efi_call_phys3(sys_table->boottime->allocate_pool,
|
|
EFI_LOADER_DATA, info_sz, &info);
|
|
EFI_LOADER_DATA, info_sz, &info);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to alloc mem for initrd info\n");
|
|
goto close_handles;
|
|
goto close_handles;
|
|
|
|
+ }
|
|
|
|
|
|
status = efi_call_phys4(h->get_info, h, &info_guid,
|
|
status = efi_call_phys4(h->get_info, h, &info_guid,
|
|
&info_sz, info);
|
|
&info_sz, info);
|
|
@@ -612,8 +644,10 @@ grow:
|
|
file_sz = info->file_size;
|
|
file_sz = info->file_size;
|
|
efi_call_phys1(sys_table->boottime->free_pool, info);
|
|
efi_call_phys1(sys_table->boottime->free_pool, info);
|
|
|
|
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to get initrd info\n");
|
|
goto close_handles;
|
|
goto close_handles;
|
|
|
|
+ }
|
|
|
|
|
|
initrd->size = file_sz;
|
|
initrd->size = file_sz;
|
|
initrd_total += file_sz;
|
|
initrd_total += file_sz;
|
|
@@ -629,11 +663,14 @@ grow:
|
|
*/
|
|
*/
|
|
status = high_alloc(initrd_total, 0x1000,
|
|
status = high_alloc(initrd_total, 0x1000,
|
|
&initrd_addr, hdr->initrd_addr_max);
|
|
&initrd_addr, hdr->initrd_addr_max);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to alloc highmem for initrds\n");
|
|
goto close_handles;
|
|
goto close_handles;
|
|
|
|
+ }
|
|
|
|
|
|
/* We've run out of free low memory. */
|
|
/* We've run out of free low memory. */
|
|
if (initrd_addr > hdr->initrd_addr_max) {
|
|
if (initrd_addr > hdr->initrd_addr_max) {
|
|
|
|
+ efi_printk("We've run out of free low memory\n");
|
|
status = EFI_INVALID_PARAMETER;
|
|
status = EFI_INVALID_PARAMETER;
|
|
goto free_initrd_total;
|
|
goto free_initrd_total;
|
|
}
|
|
}
|
|
@@ -652,8 +689,10 @@ grow:
|
|
status = efi_call_phys3(fh->read,
|
|
status = efi_call_phys3(fh->read,
|
|
initrds[j].handle,
|
|
initrds[j].handle,
|
|
&chunksize, addr);
|
|
&chunksize, addr);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to read initrd\n");
|
|
goto free_initrd_total;
|
|
goto free_initrd_total;
|
|
|
|
+ }
|
|
addr += chunksize;
|
|
addr += chunksize;
|
|
size -= chunksize;
|
|
size -= chunksize;
|
|
}
|
|
}
|
|
@@ -732,8 +771,10 @@ static efi_status_t make_boot_params(struct boot_params *boot_params,
|
|
options_size++; /* NUL termination */
|
|
options_size++; /* NUL termination */
|
|
|
|
|
|
status = low_alloc(options_size, 1, &cmdline);
|
|
status = low_alloc(options_size, 1, &cmdline);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to alloc mem for cmdline\n");
|
|
goto fail;
|
|
goto fail;
|
|
|
|
+ }
|
|
|
|
|
|
s1 = (u8 *)(unsigned long)cmdline;
|
|
s1 = (u8 *)(unsigned long)cmdline;
|
|
s2 = (u16 *)options;
|
|
s2 = (u16 *)options;
|
|
@@ -895,12 +936,16 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
|
|
|
|
|
|
status = efi_call_phys3(sys_table->boottime->handle_protocol,
|
|
status = efi_call_phys3(sys_table->boottime->handle_protocol,
|
|
handle, &proto, (void *)&image);
|
|
handle, &proto, (void *)&image);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
|
|
goto fail;
|
|
goto fail;
|
|
|
|
+ }
|
|
|
|
|
|
status = low_alloc(0x4000, 1, (unsigned long *)&boot_params);
|
|
status = low_alloc(0x4000, 1, (unsigned long *)&boot_params);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to alloc lowmem for boot params\n");
|
|
goto fail;
|
|
goto fail;
|
|
|
|
+ }
|
|
|
|
|
|
memset(boot_params, 0x0, 0x4000);
|
|
memset(boot_params, 0x0, 0x4000);
|
|
|
|
|
|
@@ -933,8 +978,10 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
|
|
if (status != EFI_SUCCESS) {
|
|
if (status != EFI_SUCCESS) {
|
|
status = low_alloc(hdr->init_size, hdr->kernel_alignment,
|
|
status = low_alloc(hdr->init_size, hdr->kernel_alignment,
|
|
&start);
|
|
&start);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to alloc mem for kernel\n");
|
|
goto fail;
|
|
goto fail;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
hdr->code32_start = (__u32)start;
|
|
hdr->code32_start = (__u32)start;
|
|
@@ -945,19 +992,25 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
|
|
status = efi_call_phys3(sys_table->boottime->allocate_pool,
|
|
status = efi_call_phys3(sys_table->boottime->allocate_pool,
|
|
EFI_LOADER_DATA, sizeof(*gdt),
|
|
EFI_LOADER_DATA, sizeof(*gdt),
|
|
(void **)&gdt);
|
|
(void **)&gdt);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to alloc mem for gdt structure\n");
|
|
goto fail;
|
|
goto fail;
|
|
|
|
+ }
|
|
|
|
|
|
gdt->size = 0x800;
|
|
gdt->size = 0x800;
|
|
status = low_alloc(gdt->size, 8, (unsigned long *)&gdt->address);
|
|
status = low_alloc(gdt->size, 8, (unsigned long *)&gdt->address);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to alloc mem for gdt\n");
|
|
goto fail;
|
|
goto fail;
|
|
|
|
+ }
|
|
|
|
|
|
status = efi_call_phys3(sys_table->boottime->allocate_pool,
|
|
status = efi_call_phys3(sys_table->boottime->allocate_pool,
|
|
EFI_LOADER_DATA, sizeof(*idt),
|
|
EFI_LOADER_DATA, sizeof(*idt),
|
|
(void **)&idt);
|
|
(void **)&idt);
|
|
- if (status != EFI_SUCCESS)
|
|
|
|
|
|
+ if (status != EFI_SUCCESS) {
|
|
|
|
+ efi_printk("Failed to alloc mem for idt structure\n");
|
|
goto fail;
|
|
goto fail;
|
|
|
|
+ }
|
|
|
|
|
|
idt->size = 0;
|
|
idt->size = 0;
|
|
idt->address = 0;
|
|
idt->address = 0;
|