2013-04-07 00:41:07 +00:00
|
|
|
/* init.c - generic U-Boot initialization and finalization */
|
|
|
|
/*
|
|
|
|
* 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/offsets.h>
|
|
|
|
#include <grub/term.h>
|
|
|
|
#include <grub/time.h>
|
|
|
|
#include <grub/machine/kernel.h>
|
|
|
|
#include <grub/uboot/console.h>
|
|
|
|
#include <grub/uboot/disk.h>
|
|
|
|
#include <grub/uboot/uboot.h>
|
2013-05-03 13:07:39 +00:00
|
|
|
#include <grub/uboot/api_public.h>
|
2013-04-07 00:41:07 +00:00
|
|
|
|
|
|
|
extern char __bss_start[];
|
|
|
|
extern char _end[];
|
|
|
|
extern grub_size_t grub_total_module_size;
|
2013-05-03 13:07:39 +00:00
|
|
|
extern int (*grub_uboot_syscall_ptr) (int, int *, ...);
|
2013-04-07 00:41:07 +00:00
|
|
|
static unsigned long timer_start;
|
|
|
|
|
2013-11-13 05:28:15 +00:00
|
|
|
extern grub_uint32_t grub_uboot_machine_type;
|
|
|
|
extern grub_addr_t grub_uboot_boot_data;
|
|
|
|
|
2013-04-07 00:41:07 +00:00
|
|
|
void
|
|
|
|
grub_exit (void)
|
|
|
|
{
|
2013-05-03 13:07:39 +00:00
|
|
|
grub_uboot_return (0);
|
2013-04-07 00:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grub_uint32_t
|
2013-05-03 13:07:39 +00:00
|
|
|
grub_uboot_get_machine_type (void)
|
2013-04-07 00:41:07 +00:00
|
|
|
{
|
2013-05-03 13:07:39 +00:00
|
|
|
return grub_uboot_machine_type;
|
2013-04-07 00:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grub_addr_t
|
2013-05-03 13:07:39 +00:00
|
|
|
grub_uboot_get_boot_data (void)
|
2013-04-07 00:41:07 +00:00
|
|
|
{
|
2013-05-03 13:07:39 +00:00
|
|
|
return grub_uboot_boot_data;
|
2013-04-07 00:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static grub_uint64_t
|
|
|
|
uboot_timer_ms (void)
|
|
|
|
{
|
2013-12-04 07:26:13 +00:00
|
|
|
static grub_uint32_t last = 0, high = 0;
|
|
|
|
grub_uint32_t cur = grub_uboot_get_timer (timer_start);
|
|
|
|
if (cur < last)
|
|
|
|
high++;
|
|
|
|
last = cur;
|
2013-12-15 16:59:40 +00:00
|
|
|
return (((grub_uint64_t) high) << 32) | cur;
|
2013-04-07 00:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_machine_init (void)
|
|
|
|
{
|
|
|
|
int ver;
|
|
|
|
|
|
|
|
/* First of all - establish connection with U-Boot */
|
2013-05-03 13:07:39 +00:00
|
|
|
ver = grub_uboot_api_init ();
|
2013-04-07 00:41:07 +00:00
|
|
|
if (!ver)
|
|
|
|
{
|
|
|
|
/* Don't even have a console to log errors to... */
|
|
|
|
grub_exit ();
|
|
|
|
}
|
|
|
|
else if (ver > API_SIG_VERSION)
|
|
|
|
{
|
|
|
|
/* Try to print an error message */
|
2013-05-03 13:07:39 +00:00
|
|
|
grub_uboot_puts ("invalid U-Boot API version\n");
|
2013-04-07 00:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the console so that GRUB can display messages. */
|
|
|
|
grub_console_init_early ();
|
|
|
|
|
|
|
|
/* Enumerate memory and initialize the memory management system. */
|
|
|
|
grub_uboot_mm_init ();
|
|
|
|
|
2013-04-12 14:50:58 +00:00
|
|
|
grub_dprintf ("init", "__bss_start: %p\n", __bss_start);
|
|
|
|
grub_dprintf ("init", "_end: %p\n", _end);
|
2013-04-07 00:41:07 +00:00
|
|
|
grub_dprintf ("init", "grub_modbase: %p\n", (void *) grub_modbase);
|
|
|
|
grub_dprintf ("init", "grub_modules_get_end(): %p\n",
|
|
|
|
(void *) grub_modules_get_end ());
|
|
|
|
|
|
|
|
/* Initialise full terminfo support */
|
|
|
|
grub_console_init_lately ();
|
|
|
|
|
|
|
|
/* Enumerate uboot devices */
|
|
|
|
grub_uboot_probe_hardware ();
|
|
|
|
|
|
|
|
/* Initialise timer */
|
2013-05-03 13:07:39 +00:00
|
|
|
timer_start = grub_uboot_get_timer (0);
|
2013-04-07 00:41:07 +00:00
|
|
|
grub_install_get_time_ms (uboot_timer_ms);
|
|
|
|
|
|
|
|
/* Initialize */
|
|
|
|
grub_ubootdisk_init ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2013-11-10 12:33:26 +00:00
|
|
|
grub_machine_fini (int flags __attribute__ ((unused)))
|
2013-04-07 00:41:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* grub_machine_get_bootlocation():
|
|
|
|
* Called from kern/main.c, which expects a device name (minus parentheses)
|
|
|
|
* and a filesystem path back, if any are known.
|
|
|
|
* Any returned values must be pointers to dynamically allocated strings.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
grub_machine_get_bootlocation (char **device, char **path)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
2013-05-03 13:07:39 +00:00
|
|
|
tmp = grub_uboot_env_get ("grub_bootdev");
|
2013-04-07 00:41:07 +00:00
|
|
|
if (tmp)
|
|
|
|
{
|
2013-05-03 12:41:08 +00:00
|
|
|
*device = grub_strdup (tmp);
|
2013-04-07 00:41:07 +00:00
|
|
|
if (*device == NULL)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*device = NULL;
|
|
|
|
|
2013-05-03 13:07:39 +00:00
|
|
|
tmp = grub_uboot_env_get ("grub_bootpath");
|
2013-04-07 00:41:07 +00:00
|
|
|
if (tmp)
|
|
|
|
{
|
2013-05-03 12:41:08 +00:00
|
|
|
*path = grub_strdup (tmp);
|
2013-04-07 00:41:07 +00:00
|
|
|
if (*path == NULL)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*path = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_uboot_fini (void)
|
|
|
|
{
|
|
|
|
grub_ubootdisk_fini ();
|
|
|
|
grub_console_fini ();
|
|
|
|
}
|