Skip to content

Commit

Permalink
efi: Move relocate_kernel() to shared file.
Browse files Browse the repository at this point in the history
The relocate_kernel() function will be generalized and used
by all architectures, as they all have similar requirements.

Signed-off-by: Roy Franz <roy.franz@linaro.org>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
  • Loading branch information
Roy Franz authored and Matt Fleming committed Sep 25, 2013
1 parent 38dd9c0 commit c6866d7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
34 changes: 0 additions & 34 deletions arch/x86/boot/compressed/eboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,40 +677,6 @@ static efi_status_t exit_boot(struct boot_params *boot_params,
return status;
}

static efi_status_t relocate_kernel(struct setup_header *hdr)
{
unsigned long start, nr_pages;
efi_status_t status;

/*
* The EFI firmware loader could have placed the kernel image
* anywhere in memory, but the kernel has various restrictions
* on the max physical address it can run at. Attempt to move
* the kernel to boot_params.pref_address, or as low as
* possible.
*/
start = hdr->pref_address;
nr_pages = round_up(hdr->init_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;

status = efi_call_phys4(sys_table->boottime->allocate_pages,
EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
nr_pages, &start);
if (status != EFI_SUCCESS) {
status = efi_low_alloc(sys_table, hdr->init_size,
hdr->kernel_alignment, &start);
if (status != EFI_SUCCESS)
efi_printk(sys_table, "Failed to alloc mem for kernel\n");
}

if (status == EFI_SUCCESS)
memcpy((void *)start, (void *)(unsigned long)hdr->code32_start,
hdr->init_size);

hdr->pref_address = hdr->code32_start;
hdr->code32_start = (__u32)start;

return status;
}

/*
* On success we return a pointer to a boot_params structure, and NULL
Expand Down
35 changes: 35 additions & 0 deletions drivers/firmware/efi/efi-stub-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,38 @@ static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg,

return status;
}

static efi_status_t relocate_kernel(struct setup_header *hdr)
{
unsigned long start, nr_pages;
efi_status_t status;

/*
* The EFI firmware loader could have placed the kernel image
* anywhere in memory, but the kernel has various restrictions
* on the max physical address it can run at. Attempt to move
* the kernel to boot_params.pref_address, or as low as
* possible.
*/
start = hdr->pref_address;
nr_pages = round_up(hdr->init_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;

status = efi_call_phys4(sys_table->boottime->allocate_pages,
EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
nr_pages, &start);
if (status != EFI_SUCCESS) {
status = efi_low_alloc(sys_table, hdr->init_size,
hdr->kernel_alignment, &start);
if (status != EFI_SUCCESS)
efi_printk(sys_table, "Failed to alloc mem for kernel\n");
}

if (status == EFI_SUCCESS)
memcpy((void *)start, (void *)(unsigned long)hdr->code32_start,
hdr->init_size);

hdr->pref_address = hdr->code32_start;
hdr->code32_start = (__u32)start;

return status;
}

0 comments on commit c6866d7

Please sign in to comment.