/* init.c - generic U-Boot initialization and finalization */ /* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * VAS_EBOOT 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. * * VAS_EBOOT 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 VAS_EBOOT. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include extern char __bss_start[]; extern char _end[]; extern VasEBoot_size_t VasEBoot_total_module_size; static unsigned long timer_start; void VasEBoot_exit (void) { VasEBoot_uboot_return (0); } static VasEBoot_uint64_t uboot_timer_ms (void) { static VasEBoot_uint32_t last = 0, high = 0; VasEBoot_uint32_t cur = VasEBoot_uboot_get_timer (timer_start); if (cur < last) high++; last = cur; return (((VasEBoot_uint64_t) high) << 32) | cur; } #ifdef __arm__ static VasEBoot_uint64_t rpi_timer_ms (void) { static VasEBoot_uint32_t last = 0, high = 0; VasEBoot_uint32_t cur = *(volatile VasEBoot_uint32_t *) 0x20003004; if (cur < last) high++; last = cur; return VasEBoot_divmod64 ((((VasEBoot_uint64_t) high) << 32) | cur, 1000, 0); } #endif void VasEBoot_machine_init (void) { int ver; /* First of all - establish connection with U-Boot */ ver = VasEBoot_uboot_api_init (); if (!ver) { /* Don't even have a console to log errors to... */ VasEBoot_exit (); } else if (ver > API_SIG_VERSION) { /* Try to print an error message */ VasEBoot_uboot_puts ("invalid U-Boot API version\n"); } /* Initialize the console so that VAS_EBOOT can display messages. */ VasEBoot_console_init_early (); /* Enumerate memory and initialize the memory management system. */ VasEBoot_uboot_mm_init (); /* Should be earlier but it needs memalign. */ #ifdef __arm__ VasEBoot_arm_enable_caches_mmu (); #endif VasEBoot_dprintf ("init", "__bss_start: %p\n", __bss_start); VasEBoot_dprintf ("init", "_end: %p\n", _end); VasEBoot_dprintf ("init", "VasEBoot_modbase: %p\n", (void *) VasEBoot_modbase); VasEBoot_dprintf ("init", "VasEBoot_modules_get_end(): %p\n", (void *) VasEBoot_modules_get_end ()); /* Initialise full terminfo support */ VasEBoot_console_init_lately (); /* Enumerate uboot devices */ VasEBoot_uboot_probe_hardware (); /* Initialise timer */ #ifdef __arm__ if (VasEBoot_uboot_get_machine_type () == VAS_EBOOT_ARM_MACHINE_TYPE_RASPBERRY_PI) { VasEBoot_install_get_time_ms (rpi_timer_ms); } else #endif { timer_start = VasEBoot_uboot_get_timer (0); VasEBoot_install_get_time_ms (uboot_timer_ms); } /* Initialize */ VasEBoot_ubootdisk_init (); } void VasEBoot_machine_fini (int flags __attribute__ ((unused))) { } /* * VasEBoot_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 VasEBoot_machine_get_bootlocation (char **device, char **path) { char *tmp; tmp = VasEBoot_uboot_env_get ("VasEBoot_bootdev"); if (tmp) { *device = VasEBoot_strdup (tmp); if (*device == NULL) return; } else *device = NULL; tmp = VasEBoot_uboot_env_get ("VasEBoot_bootpath"); if (tmp) { *path = VasEBoot_strdup (tmp); if (*path == NULL) return; } else *path = NULL; } void VasEBoot_uboot_fini (void) { VasEBoot_ubootdisk_fini (); VasEBoot_console_fini (); }