| /* |
| * Copyright 2013 Google Inc. |
| * |
| * See file CREDITS for list of people who contributed to this |
| * project. |
| * |
| * 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 <stdio.h> |
| #include <stdlib.h> |
| |
| #include "drivers/net/net.h" |
| #include "drivers/timer/timer.h" |
| #include "module/module.h" |
| #include "module/uefi/fwdb.h" |
| #include "net/gigaboot/gigaboot.h" |
| #include "net/netboot/netboot.h" |
| #include "net/netboot/params.h" |
| |
| |
| void *gigaboot_allocate_buffer(size_t *size) |
| { |
| static const size_t PageSize = 4096; |
| |
| EFI_SYSTEM_TABLE *st = uefi_system_table_ptr(); |
| if (!st) |
| return NULL; |
| EFI_BOOT_SERVICES *bs = st->BootServices; |
| |
| *size = (*size + PageSize - 1) & ~(PageSize - 1); |
| |
| EFI_PHYSICAL_ADDRESS data = (EFI_PHYSICAL_ADDRESS)0xffffffff; |
| if (bs->AllocatePages(AllocateMaxAddress, EfiLoaderData, |
| *size / PageSize, &data)) { |
| printf("Failed to allocate gigaboot buffer of size %d.\n", |
| (int)(*size / PageSize)); |
| halt(); |
| return NULL; |
| } |
| |
| return (void *)(uintptr_t)data; |
| } |
| |
| int gigaboot_free_buffer(void *data, size_t size) |
| { |
| if (!data) |
| return 0; |
| |
| static const size_t PageSize = 4096; |
| |
| EFI_SYSTEM_TABLE *st = uefi_system_table_ptr(); |
| if (!st) |
| return 1; |
| EFI_BOOT_SERVICES *bs = st->BootServices; |
| |
| EFI_PHYSICAL_ADDRESS addr = (EFI_PHYSICAL_ADDRESS)(uintptr_t)data; |
| if (bs->FreePages(addr, size / PageSize)) { |
| printf("Could not free previous gigaboot buffer.\n"); |
| return 1; |
| } |
| return 0; |
| } |
| |
| void module_main(void) |
| { |
| static char cmd_line[4096]; |
| |
| srand(timer_raw_value()); |
| |
| if (uefi_prepare_fwdb_file(L"depthcharge\\netboot_params", |
| "netboot_params") || |
| uefi_prepare_fwdb_e820_map() || |
| uefi_prepare_fwdb_acpi_rsdp()) { |
| halt(); |
| } |
| |
| if (CONFIG_GIGABOOT) |
| gigaboot(); |
| else |
| netboot(cmd_line, sizeof(cmd_line)); |
| } |