| /* |
| * 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 <string.h> |
| #include <vboot_nvstorage.h> |
| #include <vboot_api.h> |
| |
| #include "base/init_funcs.h" |
| #include "base/power.h" |
| #include "drivers/board/board.h" |
| #include "drivers/console/display.h" |
| #include "drivers/keyboard/keyboard.h" |
| #include "drivers/net/net.h" |
| #include "drivers/timer/timer.h" |
| #include "module/module.h" |
| #include "net/gigaboot/gigaboot.h" |
| #include "net/netboot/netboot.h" |
| #include "net/netboot/params.h" |
| #include "vboot/vbnv.h" |
| |
| GigabootBuffer *gigaboot_get_buffer(const char *name, size_t size) |
| { |
| static GigabootBuffer kernel = { |
| .data = (void *)(uintptr_t)CONFIG_KERNEL_START, |
| .size = CONFIG_KERNEL_SIZE, |
| }; |
| |
| static char cmdline_buf[4096]; |
| static GigabootBuffer cmdline = { |
| .data = cmdline_buf, |
| .size = sizeof(cmdline_buf), |
| }; |
| |
| if (!strcmp(name, gigaboot_buffer_kernel)) |
| return &kernel; |
| if (!strcmp(name, gigaboot_buffer_cmdline)) |
| return &cmdline; |
| return NULL; |
| } |
| |
| static void enable_graphics(void) |
| { |
| if (CONFIG_DRIVER_CONSOLE_DISPLAY) |
| display_console_attach(); |
| |
| if (!CONFIG_OPROM_MATTERS) |
| return; |
| |
| // Manipulating vboot's internal data and calling its internal |
| // functions is NOT NICE and will give you athlete's foot and make |
| // you unpopular at parties. Right now it's the only way to ensure |
| // graphics are enabled, though, so it's a necessary evil. |
| if (!board_flag_option_roms_loaded()) { |
| printf("Enabling graphics.\n"); |
| |
| vbnv_write(VBNV_OPROM_NEEDED, 1); |
| |
| printf("Rebooting.\n"); |
| if (cold_reboot()) |
| halt(); |
| } |
| } |
| |
| static char cmd_line[4096] = "lsm.module_locking=0 cros_netboot_ramfs " |
| "cros_factory_install cros_secure cros_netboot"; |
| |
| void module_main(void) |
| { |
| // Make sure graphics are available if they aren't already. |
| enable_graphics(); |
| |
| srand(timer_raw_value()); |
| |
| if (CONFIG_GIGABOOT) |
| gigaboot(); |
| else |
| netboot(cmd_line, sizeof(cmd_line)); |
| } |