Initial import of Leif's work
This commit is contained in:
parent
21026747df
commit
389b31cd71
65 changed files with 7311 additions and 13 deletions
68
grub-core/kern/arm/efi/init.c
Normal file
68
grub-core/kern/arm/efi/init.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* init.c - initialize an arm-based EFI system */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/env.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/efi/efi.h>
|
||||
|
||||
/*
|
||||
* A bit ugly, but functional - and should be completely portable.
|
||||
*/
|
||||
static grub_uint64_t
|
||||
grub_efi_get_time_ms(void)
|
||||
{
|
||||
grub_efi_time_t now;
|
||||
grub_uint64_t retval;
|
||||
grub_efi_status_t status;
|
||||
|
||||
status = efi_call_2 (grub_efi_system_table->runtime_services->get_time,
|
||||
&now, NULL);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
{
|
||||
grub_printf("No time!\n");
|
||||
return 0;
|
||||
}
|
||||
retval = now.year * 365 * 24 * 60 * 60 * 1000;
|
||||
retval += now.month * 30 * 24 * 60 * 60 * 1000;
|
||||
retval += now.day * 24 * 60 * 60 * 1000;
|
||||
retval += now.hour * 60 * 60 * 1000;
|
||||
retval += now.minute * 60 * 1000;
|
||||
retval += now.second * 1000;
|
||||
retval += now.nanosecond / 1000;
|
||||
|
||||
grub_dprintf("timer", "timestamp: 0x%llx\n", retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
grub_machine_init (void)
|
||||
{
|
||||
grub_efi_init ();
|
||||
grub_install_get_time_ms (grub_efi_get_time_ms);
|
||||
}
|
||||
|
||||
void
|
||||
grub_machine_fini (void)
|
||||
{
|
||||
grub_efi_fini ();
|
||||
}
|
203
grub-core/kern/arm/efi/misc.c
Normal file
203
grub-core/kern/arm/efi/misc.c
Normal file
|
@ -0,0 +1,203 @@
|
|||
/* misc.c - various system functions for an arm-based EFI system */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/cpu/linux.h>
|
||||
#include <grub/cpu/system.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/machine/loader.h>
|
||||
|
||||
static inline grub_size_t
|
||||
page_align (grub_size_t size)
|
||||
{
|
||||
return (size + (1 << 12) - 1) & (~((1 << 12) - 1));
|
||||
}
|
||||
|
||||
/* Find the optimal number of pages for the memory map. Is it better to
|
||||
move this code to efi/mm.c? */
|
||||
static grub_efi_uintn_t
|
||||
find_mmap_size (void)
|
||||
{
|
||||
static grub_efi_uintn_t mmap_size = 0;
|
||||
|
||||
if (mmap_size != 0)
|
||||
return mmap_size;
|
||||
|
||||
mmap_size = (1 << 12);
|
||||
while (1)
|
||||
{
|
||||
int ret;
|
||||
grub_efi_memory_descriptor_t *mmap;
|
||||
grub_efi_uintn_t desc_size;
|
||||
|
||||
mmap = grub_malloc (mmap_size);
|
||||
if (! mmap)
|
||||
return 0;
|
||||
|
||||
ret = grub_efi_get_memory_map (&mmap_size, mmap, 0, &desc_size, 0);
|
||||
grub_free (mmap);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_IO, "cannot get memory map");
|
||||
return 0;
|
||||
}
|
||||
else if (ret > 0)
|
||||
break;
|
||||
|
||||
mmap_size += (1 << 12);
|
||||
}
|
||||
|
||||
/* Increase the size a bit for safety, because GRUB allocates more on
|
||||
later, and EFI itself may allocate more. */
|
||||
mmap_size += (1 << 12);
|
||||
|
||||
return page_align (mmap_size);
|
||||
}
|
||||
|
||||
#define NEXT_MEMORY_DESCRIPTOR(desc, size) \
|
||||
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
|
||||
#define PAGE_SHIFT 12
|
||||
|
||||
void *
|
||||
grub_efi_allocate_loader_memory (grub_uint32_t min_offset, grub_uint32_t size)
|
||||
{
|
||||
grub_efi_uintn_t desc_size;
|
||||
grub_efi_memory_descriptor_t *mmap, *mmap_end;
|
||||
grub_efi_uintn_t mmap_size, tmp_mmap_size;
|
||||
grub_efi_memory_descriptor_t *desc;
|
||||
void *mem = NULL;
|
||||
grub_addr_t min_start = 0;
|
||||
|
||||
mmap_size = find_mmap_size();
|
||||
if (!mmap_size)
|
||||
return NULL;
|
||||
|
||||
mmap = grub_malloc(mmap_size);
|
||||
if (!mmap)
|
||||
return NULL;
|
||||
|
||||
tmp_mmap_size = mmap_size;
|
||||
if (grub_efi_get_memory_map (&tmp_mmap_size, mmap, 0, &desc_size, 0) <= 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_IO, "cannot get memory map");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
mmap_end = NEXT_MEMORY_DESCRIPTOR (mmap, tmp_mmap_size);
|
||||
/* Find lowest accessible RAM location */
|
||||
{
|
||||
int found = 0;
|
||||
for (desc = mmap ; !found && (desc < mmap_end) ;
|
||||
desc = NEXT_MEMORY_DESCRIPTOR(desc, desc_size))
|
||||
{
|
||||
switch (desc->type)
|
||||
{
|
||||
case GRUB_EFI_CONVENTIONAL_MEMORY:
|
||||
case GRUB_EFI_LOADER_CODE:
|
||||
case GRUB_EFI_LOADER_DATA:
|
||||
min_start = desc->physical_start + min_offset;
|
||||
found = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* First, find free pages for the real mode code
|
||||
and the memory map buffer. */
|
||||
for (desc = mmap ; desc < mmap_end ;
|
||||
desc = NEXT_MEMORY_DESCRIPTOR(desc, desc_size))
|
||||
{
|
||||
grub_uint64_t start, end;
|
||||
|
||||
grub_dprintf("mm", "%s: 0x%08x bytes @ 0x%08x\n",
|
||||
__FUNCTION__,
|
||||
(grub_uint32_t) (desc->num_pages << PAGE_SHIFT),
|
||||
(grub_uint32_t) (desc->physical_start));
|
||||
|
||||
if (desc->type != GRUB_EFI_CONVENTIONAL_MEMORY)
|
||||
continue;
|
||||
|
||||
start = desc->physical_start;
|
||||
end = start + (desc->num_pages << PAGE_SHIFT);
|
||||
grub_dprintf("mm", "%s: start=0x%016llx, end=0x%016llx\n",
|
||||
__FUNCTION__, start, end);
|
||||
start = start < min_start ? min_start : start;
|
||||
if (start + size > end)
|
||||
continue;
|
||||
grub_dprintf("mm", "%s: let's allocate some (0x%x) pages @ 0x%08x...\n",
|
||||
__FUNCTION__, (size >> PAGE_SHIFT), (grub_addr_t) start);
|
||||
mem = grub_efi_allocate_pages (start, (size >> PAGE_SHIFT) + 1);
|
||||
grub_dprintf("mm", "%s: retval=0x%08x\n",
|
||||
__FUNCTION__, (grub_addr_t) mem);
|
||||
if (! mem)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory");
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (! mem)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
grub_free (mmap);
|
||||
return mem;
|
||||
|
||||
fail:
|
||||
grub_free (mmap);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_efi_prepare_platform (void)
|
||||
{
|
||||
grub_efi_uintn_t mmap_size;
|
||||
grub_efi_uintn_t map_key;
|
||||
grub_efi_uintn_t desc_size;
|
||||
grub_efi_uint32_t desc_version;
|
||||
grub_efi_memory_descriptor_t *mmap_buf;
|
||||
grub_err_t err;
|
||||
|
||||
/*
|
||||
* Cloned from IA64
|
||||
* Must be done after grub_machine_fini because map_key is used by
|
||||
*exit_boot_services.
|
||||
*/
|
||||
mmap_size = find_mmap_size ();
|
||||
if (! mmap_size)
|
||||
return GRUB_ERR_OUT_OF_MEMORY;
|
||||
mmap_buf = grub_efi_allocate_pages (0, page_align (mmap_size) >> 12);
|
||||
if (! mmap_buf)
|
||||
return GRUB_ERR_OUT_OF_MEMORY;
|
||||
|
||||
err = grub_efi_finish_boot_services (&mmap_size, mmap_buf, &map_key,
|
||||
&desc_size, &desc_version);
|
||||
if (err != GRUB_ERR_NONE)
|
||||
return err;
|
||||
|
||||
grub_arm_disable_caches_mmu();
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
38
grub-core/kern/arm/efi/startup.S
Normal file
38
grub-core/kern/arm/efi/startup.S
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* (C) Copyright 2013 Free Software Foundation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <grub/symbol.h>
|
||||
|
||||
.file "startup.S"
|
||||
.text
|
||||
.arm
|
||||
FUNCTION(_start)
|
||||
/*
|
||||
* EFI_SYSTEM_TABLE and EFI_HANDLE are passed in r1/r0.
|
||||
*/
|
||||
ldr ip, =EXT_C(grub_efi_image_handle)
|
||||
str r0, [ip]
|
||||
ldr ip, =EXT_C(grub_efi_system_table)
|
||||
str r1, [ip]
|
||||
ldr ip, =EXT_C(grub_main)
|
||||
bx ip
|
||||
.thumb @ For relocation debugging
|
||||
blx _start
|
||||
.end
|
Loading…
Add table
Add a link
Reference in a new issue