diff options
author | Che-Liang Chiou <clchiou@chromium.org> | 2011-07-11 16:50:58 +0800 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2011-08-29 10:58:50 -0700 |
commit | 9775a77c8827c6bb23a1603c2a7e591d114b559a (patch) | |
tree | 3b9f1389cf6fa7ec2afd2b9502594805c4404a0e | |
parent | 78453835fffdaf5004872adde7e2efc7961ab493 (diff) |
CHROMIUM: remove unused old codes
The removed codes are based on prior-redesigned vboot_reference and not
even written for twostop firmware.
BUG=chromium-os:17424
TEST=build cleanly
Change-Id: Ifd869d80b7aa8e11ffe948516733e0f78b170d76
Reviewed-on: http://gerrit.chromium.org/gerrit/3849
Tested-by: Che-Liang Chiou <clchiou@chromium.org>
Reviewed-by: Tom Wai-Hong Tam <waihong@chromium.org>
-rw-r--r-- | common/Makefile | 6 | ||||
-rw-r--r-- | common/cmd_cros_bootstub.c | 189 | ||||
-rw-r--r-- | common/cmd_cros_developer_firmware.c | 158 | ||||
-rw-r--r-- | common/cmd_cros_normal_firmware.c | 100 | ||||
-rw-r--r-- | common/cmd_cros_rec.c | 290 | ||||
-rw-r--r-- | common/cmd_cros_tpm_test.c | 513 | ||||
-rw-r--r-- | include/config_cmd_all.h | 5 |
7 files changed, 0 insertions, 1261 deletions
diff --git a/common/Makefile b/common/Makefile index 768a9ff7f6..454b257570 100644 --- a/common/Makefile +++ b/common/Makefile @@ -74,13 +74,7 @@ COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o COBJS-$(CONFIG_CMD_CACHE) += cmd_cache.o COBJS-$(CONFIG_CMD_CONSOLE) += cmd_console.o COBJS-$(CONFIG_CMD_CPLBINFO) += cmd_cplbinfo.o -COBJS-$(CONFIG_CMD_CROS) += cmd_cros.o -COBJS-$(CONFIG_CMD_CROS_BOOTSTUB) += cmd_cros_bootstub.o -COBJS-$(CONFIG_CMD_CROS_DEVELOPER_FIRMWARE) += cmd_cros_developer_firmware.o -COBJS-$(CONFIG_CMD_CROS_NORMAL_FIRMWARE) += cmd_cros_normal_firmware.o -COBJS-$(CONFIG_CMD_CROS_REC) += cmd_cros_rec.o COBJS-$(CONFIG_CMD_CROS_ONESTOP_FIRMWARE) += cmd_cros_onestop_firmware.o -COBJS-$(CONFIG_CMD_CROS_TPM_TEST) += cmd_cros_tpm_test.o COBJS-$(CONFIG_CMD_VBEXPORT_TEST) += cmd_vbexport_test.o COBJS-$(CONFIG_CMD_VBOOT_BOOTSTUB) += cmd_vboot_bootstub.o COBJS-$(CONFIG_CMD_VBOOT_MAIN) += cmd_vboot_main.o diff --git a/common/cmd_cros_bootstub.c b/common/cmd_cros_bootstub.c deleted file mode 100644 index 6a40afd722..0000000000 --- a/common/cmd_cros_bootstub.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Alternatively, this software may be distributed under the terms of the - * GNU General Public License ("GPL") version 2 as published by the Free - * Software Foundation. - */ - -/* Implementation of boot stub of Chrome OS Verify Boot firmware */ - -#include <common.h> -#include <command.h> -#include <malloc.h> -#include <chromeos/common.h> -#include <chromeos/firmware_storage.h> -#include <chromeos/gpio.h> -#include <chromeos/kernel_shared_data.h> -#include <chromeos/load_firmware_helper.h> -#include <chromeos/power_management.h> -#include <chromeos/vboot_nvstorage_helper.h> - -/* Verify Boot interface */ -#include <gbb_header.h> -#include <load_firmware_fw.h> -#include <vboot_nvstorage.h> -#include <vboot_struct.h> - -#define PREFIX "cros_bootstub: " - -#define WARN_ON_FAILURE(action) do { \ - int return_code = (action); \ - if (return_code != 0) \ - printf(PREFIX "%s failed, returning %d\n", \ - #action, return_code); \ -} while (0) - -/* - * Read recovery firmware into <recovery_firmware_buffer>. - * - * Return 0 on success, non-zero on error. - */ -int load_recovery_firmware(firmware_storage_t *file, - uint8_t *recovery_firmware_buffer) -{ - int retval; - - retval = firmware_storage_read(file, - CONFIG_OFFSET_RECOVERY, CONFIG_LENGTH_RECOVERY, - recovery_firmware_buffer); - if (retval) { - VBDEBUG(PREFIX "cannot load recovery firmware\n"); - } - - return retval; -} - -void jump_to_firmware(void (*firmware_entry_point)(void)) -{ - VBDEBUG(PREFIX "jump to firmware %p\n", firmware_entry_point); - - cleanup_before_linux(); - - /* should never return! */ - firmware_entry_point(); - - /* FIXME(clchiou) Bring up a sad face as boot has failed */ - enable_interrupts(); - VBDEBUG(PREFIX "error: firmware returns\n"); - while (1); -} - -int do_cros_bootstub(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - int status = LOAD_FIRMWARE_RECOVERY; - firmware_storage_t file; - VbNvContext nvcxt; - uint64_t boot_flags = 0; - uint32_t recovery_request = 0; - uint32_t reason = VBNV_RECOVERY_NOT_REQUESTED; - uint8_t *firmware_data; - - if (firmware_storage_init(&file)) { - /* FIXME(clchiou) Bring up a sad face as boot has failed */ - VBDEBUG(PREFIX "init_firmware_storage fail\n"); - while (1); - } - - if (is_firmware_write_protect_gpio_asserted()) - WARN_ON_FAILURE(file.lock_device(file.context)); - - clear_kernel_shared_data(); - - /* Fill in the RO firmware ID */ - KernelSharedDataType *sd = get_kernel_shared_data(); - if (firmware_storage_read(&file, - (off_t)CONFIG_OFFSET_RO_FRID, - (size_t)CONFIG_LENGTH_RO_FRID, - sd->frid)) { - VBDEBUG(PREFIX "fail to read fwid\n"); - reason = VBNV_RECOVERY_US_UNSPECIFIED; - goto RECOVERY; - } - - if (read_nvcontext(&nvcxt) || VbNvGet(&nvcxt, VBNV_RECOVERY_REQUEST, - &recovery_request)) { - VBDEBUG(PREFIX "fail to read nvcontext\n"); - reason = VBNV_RECOVERY_US_UNSPECIFIED; - goto RECOVERY; - } - - /* clear VBNV_DEBUG_RESET_MODE after read */ - if (VbNvSet(&nvcxt, VBNV_DEBUG_RESET_MODE, 0)) { - VBDEBUG(PREFIX "fail to write nvcontext\n"); - reason = VBNV_RECOVERY_US_UNSPECIFIED; - goto RECOVERY; - } - - if (recovery_request != VBNV_RECOVERY_NOT_REQUESTED) { - VBDEBUG(PREFIX "boot recovery cookie set\n"); - reason = recovery_request; - goto RECOVERY; - } - - if (is_recovery_mode_gpio_asserted()) { - VBDEBUG(PREFIX "recovery button pressed\n"); - reason = VBNV_RECOVERY_RO_MANUAL; - goto RECOVERY; - } - - if (is_developer_mode_gpio_asserted()) - boot_flags |= BOOT_FLAG_DEVELOPER; - - status = load_firmware_wrapper(&file, - boot_flags, &nvcxt, NULL, &firmware_data); - - if (nvcxt.raw_changed && write_nvcontext(&nvcxt)) { - VBDEBUG(PREFIX "fail to write nvcontext\n"); - reason = VBNV_RECOVERY_US_UNSPECIFIED; - goto RECOVERY; - } - - if (status == LOAD_FIRMWARE_SUCCESS) { - jump_to_firmware((void (*)(void)) firmware_data); - } else if (status == LOAD_FIRMWARE_REBOOT) { - cold_reboot(); - } - - /* assert(status == LOAD_FIRMWARE_RECOVERY) */ - -RECOVERY: - VBDEBUG(PREFIX "write to recovery cookie\n"); - - /* - * Although writing back VbNvContext cookies may fail, we boot - * recovery firmware anyway. In this way, the recovery reason - * would be incorrect, but this is much better than not booting - * anything. - */ - - if (reason != VBNV_RECOVERY_NOT_REQUESTED && - VbNvSet(&nvcxt, VBNV_RECOVERY_REQUEST, reason)) { - /* FIXME: bring up a sad face? */ - VBDEBUG(PREFIX "error: cannot write recovery reason\n"); - } - - if (VbNvTeardown(&nvcxt)) { - /* FIXME: bring up a sad face? */ - VBDEBUG(PREFIX "error: cannot tear down cookie\n"); - } - - if (nvcxt.raw_changed && write_nvcontext(&nvcxt)) { - /* FIXME: bring up a sad face? */ - VBDEBUG(PREFIX "error: cannot write recovery cookie\n"); - } - - VBDEBUG(PREFIX "jump to recovery firmware and never return\n"); - - firmware_data = malloc(CONFIG_LENGTH_RECOVERY); - WARN_ON_FAILURE(load_recovery_firmware(&file, firmware_data)); - jump_to_firmware((void (*)(void)) firmware_data); - - /* never reach here */ - return 1; -} - -U_BOOT_CMD(cros_bootstub, 1, 1, do_cros_bootstub, "verified boot stub firmware", - NULL); diff --git a/common/cmd_cros_developer_firmware.c b/common/cmd_cros_developer_firmware.c deleted file mode 100644 index 106cd1987e..0000000000 --- a/common/cmd_cros_developer_firmware.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Alternatively, this software may be distributed under the terms of the - * GNU General Public License ("GPL") version 2 as published by the Free - * Software Foundation. - */ - -/* Implementation of developer firmware of Chrome OS Verify Boot */ - -#include <common.h> -#include <command.h> -#include <mmc.h> -#include <chromeos/common.h> -#include <chromeos/firmware_storage.h> -#include <chromeos/gbb_bmpblk.h> -#include <chromeos/gpio.h> -#include <chromeos/load_firmware_helper.h> -#include <chromeos/load_kernel_helper.h> -#include <chromeos/os_storage.h> -#include <chromeos/vboot_nvstorage_helper.h> - -#include <bmpblk_header.h> -#include <tss_constants.h> -#include <vboot_api.h> - -#define PREFIX "cros_developer_firmware: " - -/* TODO(clchiou): get this number from FDT? */ -#define MMC_EMMC_DEVNUM 0 -#define MMC_SD_DEVNUM 1 - -/* ASCII codes of characters */ -#define CTRL_D 0x04 -#define CTRL_U 0x15 -#define ESCAPE 0x1b - -int do_cros_normal_firmware(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]); - -static void beep(void) -{ - /* TODO: implement beep */ - VBDEBUG(PREFIX "beep\n"); -} - -static int unblocked_getc(int *c) -{ - /* TODO(crosbug/15243): Cannot read control-* from keyboard */ - - /* does not check whether we have console or not */ - if (tstc()) { - *c = getc(); - return 1; - } else - return 0; -} - -int do_cros_developer_firmware(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) -{ - firmware_storage_t file; - void *gbb_data = NULL; - uint64_t gbb_size = 0, - boot_flags = BOOT_FLAG_DEV_FIRMWARE | BOOT_FLAG_DEVELOPER; - ulong start = 0, time = 0, last_time = 0; - int c, is_after_20_seconds = 0; - - if (!is_developer_mode_gpio_asserted()) { - VBDEBUG(PREFIX "developer switch is off; reboot to recovery!\n"); - reboot_to_recovery_mode(VBNV_RECOVERY_RW_DEV_MISMATCH); - } - - if (VbExTpmInit() != TPM_SUCCESS) { - VBDEBUG(PREFIX "fail to init tpm\n"); - reboot_to_recovery_mode(VBNV_RECOVERY_RW_TPM_ERROR); - } - - if (firmware_storage_init(&file) || - load_gbb(&file, &gbb_data, &gbb_size)) { - /* - * FIXME: We can't read gbb and so can't show a face on screen; - * how should we do when this happen? Trap in infinite loop? - */ - VBDEBUG(PREFIX "cannot load gbb\n"); - while (1); - } - - /* we don't care whether close operation fails */ - if (file.close(file.context)) { - VBDEBUG(PREFIX "close firmware storage failed\n"); - } - - if (display_screen_in_bmpblk(gbb_data, SCREEN_DEVELOPER_MODE)) { - VBDEBUG(PREFIX "cannot display stuff on LCD screen\n"); - } - - start = get_timer(0); - while (1) { - udelay(100); - - last_time = time; - time = get_timer(start); -#ifdef DEBUG - /* only output when time advances at least 1 second */ - if (time / CONFIG_SYS_HZ > last_time / CONFIG_SYS_HZ) - VBDEBUG(PREFIX "time ~ %d sec\n", time / CONFIG_SYS_HZ); -#endif - - /* Beep twice when time > 20 seconds */ - if (!is_after_20_seconds && time > 20 * CONFIG_SYS_HZ) { - beep(); udelay(500); beep(); - is_after_20_seconds = 1; - continue; - } - - /* Boot from internal storage after 30 seconds */ - if (time > 30 * CONFIG_SYS_HZ) - break; - - if (!unblocked_getc(&c)) - continue; - - VBDEBUG(PREFIX "unblocked_getc() == 0x%x\n", c); - - /* Load and boot kernel from USB or SD card */ - if (CTRL_U == c) { - if (is_any_storage_device_plugged(BOOT_PROBED_DEVICE)) - load_and_boot_kernel(gbb_data, gbb_size, - boot_flags); - - VBDEBUG(PREFIX "Fail to probe usb and mmc\n"); - beep(); - } - - /* Boot from internal storage when user pressed Ctrl-D */ - if (CTRL_D == c) - break; - - if (c == ' ' || c == '\r' || c == '\n' || c == ESCAPE) { - VBDEBUG(PREFIX "reboot to recovery mode\n"); - reboot_to_recovery_mode(VBNV_RECOVERY_RW_DEV_SCREEN); - } - } - - VBDEBUG(PREFIX "boot from internal storage\n"); - if (is_mmc_storage_present(MMC_EMMC_DEVNUM) && - !set_bootdev("mmc", MMC_EMMC_DEVNUM, 0)) - load_and_boot_kernel(gbb_data, gbb_size, boot_flags); - - reboot_to_recovery_mode(VBNV_RECOVERY_RW_INVALID_OS); - return 0; -} - -U_BOOT_CMD(cros_developer_firmware, 1, 1, do_cros_developer_firmware, - "verified boot developer firmware", NULL); diff --git a/common/cmd_cros_normal_firmware.c b/common/cmd_cros_normal_firmware.c deleted file mode 100644 index f048ffa9ac..0000000000 --- a/common/cmd_cros_normal_firmware.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Alternatively, this software may be distributed under the terms of the - * GNU General Public License ("GPL") version 2 as published by the Free - * Software Foundation. - */ - -/* Implementation of normal firmware of Chrome OS Verify Boot */ - -#include <common.h> -#include <command.h> -#include <fat.h> -#include <malloc.h> -#include <mmc.h> -#include <chromeos/common.h> -#include <chromeos/firmware_storage.h> -#include <chromeos/load_firmware_helper.h> -#include <chromeos/load_kernel_helper.h> -#include <chromeos/os_storage.h> -#include <chromeos/power_management.h> -#include <chromeos/vboot_nvstorage_helper.h> - -#include <load_kernel_fw.h> -#include <tss_constants.h> -#include <vboot_nvstorage.h> -#include <vboot_struct.h> -#include <vboot_api.h> - -#define PREFIX "cros_normal_firmware: " - -#define DEVICE_TYPE "mmc" -#define DEVICE_NUMBER 0 - -/* Return 0 if success, non-zero on error */ -int initialize_drive(void) -{ - if (initialize_mmc_device(DEVICE_NUMBER)) { - VBDEBUG(PREFIX "mmc %d init fail\n", DEVICE_NUMBER); - return -1; - } - - VBDEBUG(PREFIX "set_bootdev %s %x:0\n", DEVICE_TYPE, DEVICE_NUMBER); - if (set_bootdev(DEVICE_TYPE, DEVICE_NUMBER, 0)) { - VBDEBUG(PREFIX "set_bootdev fail\n"); - return -1; - } - - return 0; -} - -int do_cros_normal_firmware(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) -{ - int status; - firmware_storage_t file; - void *gbb_data = NULL; - uint64_t gbb_size = 0; - uint32_t reason = VBNV_RECOVERY_RW_UNSPECIFIED; - - if (VbExTpmInit() != TPM_SUCCESS) { - VBDEBUG(PREFIX "fail to init tpm\n"); - reboot_to_recovery_mode(VBNV_RECOVERY_RW_TPM_ERROR); - } - - if (initialize_drive()) { - VBDEBUG(PREFIX "error: initialize fixed drive fail\n"); - reboot_to_recovery_mode(VBNV_RECOVERY_RW_NO_OS); - } - - if (firmware_storage_init(&file) || - load_gbb(&file, &gbb_data, &gbb_size)) { - VBDEBUG(PREFIX "error: cannot read gbb\n"); - reboot_to_recovery_mode(VBNV_RECOVERY_RO_SHARED_DATA); - } - - status = load_and_boot_kernel(gbb_data, gbb_size, 0ULL); - VBDEBUG(PREFIX "status == %d\n", status); - - if (status == LOAD_KERNEL_REBOOT) { - VBDEBUG(PREFIX "internal error: reboot to current mode\n"); - cold_reboot(); - } - - if (status == LOAD_KERNEL_NOT_FOUND) - reason = VBNV_RECOVERY_RW_NO_OS; - else if (status == LOAD_KERNEL_INVALID) - reason = VBNV_RECOVERY_RW_INVALID_OS; - reboot_to_recovery_mode(reason); - - /* never reach here */ - /* free(gbb_data); */ - /* file.close(file.context); */ - return 1; -} - -U_BOOT_CMD(cros_normal_firmware, 1, 1, do_cros_normal_firmware, - "verified boot normal firmware", NULL); diff --git a/common/cmd_cros_rec.c b/common/cmd_cros_rec.c deleted file mode 100644 index 28c71b6062..0000000000 --- a/common/cmd_cros_rec.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Alternatively, this software may be distributed under the terms of the - * GNU General Public License ("GPL") version 2 as published by the Free - * Software Foundation. - */ - -/* Debug commands for Chrome OS recovery mode firmware */ - -#include <common.h> -#include <command.h> -#include <fat.h> -#include <lcd.h> -#include <malloc.h> -#include <usb.h> /* for wait_ms() */ -#include <chromeos/common.h> -#include <chromeos/firmware_storage.h> -#include <chromeos/load_firmware_helper.h> -#include <chromeos/load_kernel_helper.h> -#include <chromeos/gbb_bmpblk.h> -#include <chromeos/gpio.h> -#include <chromeos/os_storage.h> -#include <chromeos/vboot_nvstorage_helper.h> - -#include <bmpblk_header.h> -#include <gbb_header.h> -#include <load_kernel_fw.h> -#include <vboot_nvstorage.h> - -DECLARE_GLOBAL_DATA_PTR; - -#define PREFIX "cros_rec: " - -#ifdef DEBUG -#define WARN_ON_FAILURE(action) do { \ - int return_code = (action); \ - if (return_code != 0) \ - VBDEBUG(PREFIX "%s failed, returning %d\n", \ - #action, return_code); \ -} while (0) -#else -#define WARN_ON_FAILURE(action) action -#endif - -#define WAIT_MS_BETWEEN_PROBING 400 -#define WAIT_MS_SHOW_ERROR 2000 - -#define STACK_MARGIN 256 -#define MAX_EXCLUDED_REGIONS 16 - -/* This is the data structure of the to-be-cleared memory region list. */ -struct MemRegion { - uint32_t start; - uint32_t end; -} g_memory_region, g_excluded_regions[MAX_EXCLUDED_REGIONS]; -int g_excluded_size = 0; - -uint8_t *g_gbb_base = NULL; -uint64_t g_gbb_size = 0; -int g_is_dev = 0; -ScreenIndex g_cur_scr = SCREEN_BLANK; - -static int write_log(void) -{ - /* TODO: Implement it when Chrome OS firmware logging is ready. */ - return 0; -} - -/* - * Initializes the memory region that needs to be cleared. - */ -static void init_mem_region(uint32_t start, uint32_t end) -{ - g_memory_region.start = start; - g_memory_region.end = end; - g_excluded_size = 0; -} - -/* - * Excludes a memory region from the to-be-cleared region. - * The function returns 0 on success; otherwise -1. - */ -static int exclude_mem_region(uint32_t start, uint32_t end) -{ - int i = g_excluded_size; - - if (g_excluded_size >= MAX_EXCLUDED_REGIONS) { - VBDEBUG(PREFIX "the number of excluded regions reaches" - "the maximum: %d\n", MAX_EXCLUDED_REGIONS); - return -1; - } - - while (i > 0 && g_excluded_regions[i - 1].start > start) { - g_excluded_regions[i].start = g_excluded_regions[i - 1].start; - g_excluded_regions[i].end = g_excluded_regions[i - 1].end; - i--; - } - g_excluded_regions[i].start = start; - g_excluded_regions[i].end = end; - g_excluded_size++; - - return 0; -} - -static void zero_mem(uint32_t start, uint32_t end) -{ - if (end > start) { - VBDEBUG(PREFIX "\t[0x%08x, 0x%08x)\n", start, end); - memset((void *)start, '\0', (size_t)(end - start)); - } -} - -/* - * Clears the memory not in excluded regions. - */ -static void clear_mem_regions(void) -{ - int i; - uint32_t addr = g_memory_region.start; - - VBDEBUG(PREFIX "clear memory regions:\n"); - for (i = 0; i < g_excluded_size; ++i) { - zero_mem(addr, g_excluded_regions[i].start); - if (g_excluded_regions[i].end > addr) - addr = g_excluded_regions[i].end; - } - zero_mem(addr, g_memory_region.end); -} - -#ifdef TEST_CLEAR_MEM_REGIONS -static int test_clear_mem_regions(void) -{ - int i; - char s[10] = "ABCDEFGHIJ"; - char r[10] = "\0BCDEFGH\0J"; - uint32_t base = (uint32_t)s; - - init_mem_region(base, base + 10); - /* Result: ---------- */ - exclude_mem_region(base + 1, base + 2); - /* Result: -B-------- */ - exclude_mem_region(base + 5, base + 7); - /* Result: -B---FG--- */ - exclude_mem_region(base + 2, base + 3); - /* Result: -BC--FG--- */ - exclude_mem_region(base + 9, base + 10); - /* Result: -BC--FG--J */ - exclude_mem_region(base + 4, base + 6); - /* Result: -BC-EFG--J */ - exclude_mem_region(base + 3, base + 5); - /* Result: -BCDEFG--J */ - exclude_mem_region(base + 2, base + 8); - /* Result: -BCDEFGH-J */ - clear_mem_regions(); - for (i = 0; i < 10; ++i) { - if (s[i] != r[i]) { - VBDEBUG(PREFIX "test_clear_mem_regions FAILED!\n"); - return -1; - } - } - return 0; -} -#endif - -/* - * Clears the memory regions that the recovery firmware not used. - * We do that to prevent cold boot attacks. - */ -static void clear_ram_not_in_use(void) -{ - init_mem_region(0, PHYS_SDRAM_1_SIZE); - - /* Excludes the firmware text + data + bss regions. */ - exclude_mem_region(TEXT_BASE, - TEXT_BASE + (_bss_end - _armboot_start)); - - /* TODO: Remove the GBB exclusion when we store it in SPI flash. */ - exclude_mem_region(TEXT_BASE + CONFIG_OFFSET_GBB, - TEXT_BASE + CONFIG_OFFSET_GBB + CONFIG_LENGTH_GBB); - - /* Excludes the global data. */ - exclude_mem_region((uint32_t)gd, (uint32_t)gd + sizeof(*gd)); - exclude_mem_region((uint32_t)gd->bd, - (uint32_t)gd->bd + sizeof(*gd->bd)); - - /* Excludes the whole heap. */ - exclude_mem_region(CONFIG_STACKBASE - CONFIG_SYS_MALLOC_LEN, - CONFIG_STACKBASE); - - /* TODO: Should excludes the in-used stack instead of the whole. */ - exclude_mem_region(CONFIG_STACKBASE, - CONFIG_STACKBASE + CONFIG_STACKSIZE); - - /* Excludes the framebuffer. */ - exclude_mem_region(gd->fb_base, gd->fb_base + panel_info.vl_col * - panel_info.vl_row * NBITS(panel_info.vl_bpix) / 8); - - clear_mem_regions(); -} - -static int init_gbb_in_ram(void) -{ - firmware_storage_t file; - void *gbb_base = NULL; - - if (firmware_storage_init(&file)) { - VBDEBUG(PREFIX "init firmware storage failed\n"); - return -1; - } - - if (load_gbb(&file, &gbb_base, &g_gbb_size)) { - VBDEBUG(PREFIX "Unable to load gbb\n"); - return -1; - } - - g_gbb_base = gbb_base; - return 0; -} - -static int clear_screen(void) -{ - g_cur_scr = SCREEN_BLANK; - return lcd_clear(); -} - -static int show_screen(ScreenIndex scr) -{ - if (g_cur_scr == scr) { - /* No need to update. Do nothing and return success. */ - return 0; - } else { - g_cur_scr = scr; - return display_screen_in_bmpblk(g_gbb_base, scr); - } -} - -int do_cros_rec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - uint64_t boot_flags = BOOT_FLAG_RECOVERY; - - WARN_ON_FAILURE(write_log()); - -#ifdef TEST_CLEAR_MEM_REGIONS - test_clear_mem_regions(); -#endif - - clear_ram_not_in_use(); - - clear_recovery_request(); - - WARN_ON_FAILURE(init_gbb_in_ram()); - - g_is_dev = is_developer_mode_gpio_asserted(); - if (g_is_dev) - boot_flags |= BOOT_FLAG_DEVELOPER; - - if (!g_is_dev) { - /* Wait for user to unplug SD card and USB storage device */ - while (is_any_storage_device_plugged(NOT_BOOT_PROBED_DEVICE)) { - show_screen(SCREEN_RECOVERY_MODE); - wait_ms(WAIT_MS_BETWEEN_PROBING); - } - } - - for (;;) { - /* Wait for user to plug in SD card or USB storage device */ - while (!is_any_storage_device_plugged(BOOT_PROBED_DEVICE)) { - show_screen(SCREEN_RECOVERY_MISSING_OS); - wait_ms(WAIT_MS_BETWEEN_PROBING); - } - - clear_screen(); - - load_and_boot_kernel((void*) g_gbb_base, g_gbb_size, - boot_flags); - - while (is_any_storage_device_plugged(NOT_BOOT_PROBED_DEVICE)) { - show_screen(SCREEN_RECOVERY_NO_OS); - wait_ms(WAIT_MS_SHOW_ERROR); - } - } - - /* This point is never reached */ - return 0; -} - -U_BOOT_CMD(cros_rec, 1, 1, do_cros_rec, "recovery mode firmware", NULL); diff --git a/common/cmd_cros_tpm_test.c b/common/cmd_cros_tpm_test.c deleted file mode 100644 index c76126950b..0000000000 --- a/common/cmd_cros_tpm_test.c +++ /dev/null @@ -1,513 +0,0 @@ -/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <common.h> -#include <command.h> -#include <environment.h> -#include <tlcl.h> - -/* Prints error and returns on failure */ -#define TPM_CHECK(tpm_command) do { \ - uint32_t result; \ - if ((result = (tpm_command)) != TPM_SUCCESS) { \ - printf("TEST FAILED: line %d: " #tpm_command ": 0x%x\n", \ - __LINE__, result); \ - return result; \ - } \ -} while (0) - -#define INDEX0 0xda70 -#define INDEX1 0xda71 -#define INDEX2 0xda72 -#define INDEX3 0xda73 -#define INDEX_INITIALIZED 0xda80 - -static uint32_t TlclStartupIfNeeded(void) { - uint32_t result = TlclStartup(); - return result == TPM_E_INVALID_POSTINIT ? TPM_SUCCESS : result; -} - -/* u-boot internal timer test - */ - -static int test_timer(void) -{ - printf("get_timer(0) = %lu\n", get_timer(0)); - return 0; -} - -/* vboot_reference/tests/tpm_lite tests - */ - -static int test_early_extend(void) -{ - uint8_t value_in[20]; - uint8_t value_out[20]; - printf("Testing earlyextend ..."); - TlclLibInit(); - TPM_CHECK(TlclStartup()); - TPM_CHECK(TlclContinueSelfTest()); - TPM_CHECK(TlclExtend(1, value_in, value_out)); - printf("done\n"); - return 0; -} - -static int test_early_nvram(void) -{ - uint32_t x; - printf("Testing earlynvram ..."); - TlclLibInit(); - TPM_CHECK(TlclStartup()); - TPM_CHECK(TlclContinueSelfTest()); - TPM_CHECK(TlclAssertPhysicalPresence()); - TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); - printf("done\n"); - return 0; -} - -static int test_early_nvram2(void) -{ - uint32_t x; - printf("Testing earlynvram2 ..."); - TlclLibInit(); - TPM_CHECK(TlclStartup()); - TPM_CHECK(TlclContinueSelfTest()); - TPM_CHECK(TlclAssertPhysicalPresence()); - TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x))); - printf("done\n"); - return 0; -} - -static int test_enable(void) -{ - uint8_t disable, deactivated; - printf("Testing enable ...\n"); - TlclLibInit(); - TPM_CHECK(TlclStartupIfNeeded()); - TPM_CHECK(TlclSelfTestFull()); - TPM_CHECK(TlclAssertPhysicalPresence()); - TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL)); - printf("\tdisable is %d, deactivated is %d\n", disable, deactivated); - TPM_CHECK(TlclSetEnable()); - TPM_CHECK(TlclSetDeactivated(0)); - TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL)); - printf("\tdisable is %d, deactivated is %d\n", disable, deactivated); - if (disable == 1 || deactivated == 1) { - printf("\tfailed to enable or activate\n"); - } - printf("\tdone\n"); - return 0; -} - -#define reboot() do { \ - printf("\trebooting...\n"); \ - reset_cpu(0); \ -} while (0) - -static int test_fast_enable(void) -{ - uint8_t disable, deactivated; - int i; - printf("Testing fastenable ...\n"); - TlclLibInit(); - TPM_CHECK(TlclStartupIfNeeded()); - TPM_CHECK(TlclSelfTestFull()); - TPM_CHECK(TlclAssertPhysicalPresence()); - TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL)); - printf("\tdisable is %d, deactivated is %d\n", disable, deactivated); - for (i = 0; i < 2; i++) { - TPM_CHECK(TlclForceClear()); - TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL)); - printf("\tdisable is %d, deactivated is %d\n", disable, - deactivated); - assert(disable == 1 && deactivated == 1); - TPM_CHECK(TlclSetEnable()); - TPM_CHECK(TlclSetDeactivated(0)); - TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL)); - printf("\tdisable is %d, deactivated is %d\n", disable, - deactivated); - assert(disable == 0 && deactivated == 0); - } - printf("\tdone\n"); - return 0; -} - -static int test_global_lock(void) -{ - uint32_t zero = 0; - uint32_t result; - uint32_t x; - printf("Testing globallock ...\n"); - TlclLibInit(); - TPM_CHECK(TlclStartupIfNeeded()); - TPM_CHECK(TlclSelfTestFull()); - TPM_CHECK(TlclAssertPhysicalPresence()); - TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); - TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &zero, sizeof(uint32_t))); - TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); - TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &zero, sizeof(uint32_t))); - TPM_CHECK(TlclSetGlobalLock()); - // Verifies that write to index0 fails. - x = 1; - result = TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)); - assert(result == TPM_E_AREA_LOCKED); - TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); - assert(x == 0); - // Verifies that write to index1 is still possible. - x = 2; - TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x))); - TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); - assert(x == 2); - // Turns off PP. - TlclLockPhysicalPresence(); - // Verifies that write to index1 fails. - x = 3; - result = TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)); - assert(result == TPM_E_BAD_PRESENCE); - TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); - assert(x == 2); - printf("\tdone\n"); - return 0; -} - -static int test_lock(void) -{ - printf("Testing lock ...\n"); - TlclLibInit(); - TlclStartup(); - TlclSelfTestFull(); - TlclAssertPhysicalPresence(); - TlclWriteLock(INDEX0); - printf("\tLocked 0x%x\n", INDEX0); - printf("\tdone\n"); - return 0; -} - -static void initialize_spaces(void) { - uint32_t zero = 0; - uint32_t perm = TPM_NV_PER_WRITE_STCLEAR | TPM_NV_PER_PPWRITE; - - printf("\tInitializing spaces\n"); - TlclSetNvLocked(); /* useful only the first time */ - TlclDefineSpace(INDEX0, perm, 4); - TlclWrite(INDEX0, (uint8_t *) &zero, 4); - TlclDefineSpace(INDEX1, perm, 4); - TlclWrite(INDEX1, (uint8_t *) &zero, 4); - TlclDefineSpace(INDEX2, perm, 4); - TlclWrite(INDEX2, (uint8_t *) &zero, 4); - TlclDefineSpace(INDEX3, perm, 4); - TlclWrite(INDEX3, (uint8_t *) &zero, 4); - perm = TPM_NV_PER_READ_STCLEAR | TPM_NV_PER_WRITE_STCLEAR | - TPM_NV_PER_PPWRITE; - TlclDefineSpace(INDEX_INITIALIZED, perm, 1); -} - - -static void enter_recovery_mode(void) { - printf("entering recovery mode"); - reboot(); -} - - -static int test_readonly(void) -{ - uint8_t c; - uint32_t index_0, index_1, index_2, index_3; - int read_0, read_1, read_2, read_3; - printf("Testing readonly ...\n"); - TlclLibInit(); - TlclStartup(); - TlclSelfTestFull(); - TlclAssertPhysicalPresence(); - /* Checks if initialization has completed by trying to read-lock a space - * that's created at the end of initialization. - */ - if (TlclRead(INDEX_INITIALIZED, &c, 0) == TPM_E_BADINDEX) { - /* The initialization did not complete. - */ - initialize_spaces(); - } - - /* Checks if spaces are OK or messed up. - */ - read_0 = TlclRead(INDEX0, (uint8_t*) &index_0, sizeof(index_0)); - read_1 = TlclRead(INDEX1, (uint8_t*) &index_1, sizeof(index_1)); - read_2 = TlclRead(INDEX2, (uint8_t*) &index_2, sizeof(index_2)); - read_3 = TlclRead(INDEX3, (uint8_t*) &index_3, sizeof(index_3)); - if (read_0 != TPM_SUCCESS || read_1 != TPM_SUCCESS || read_2 != - TPM_SUCCESS || read_3 != TPM_SUCCESS) { - enter_recovery_mode(); - } - - /* Writes space, and locks it. Then attempts to write again. - * I really wish I could use the imperative. - */ - index_0 += 1; - if (TlclWrite(INDEX0, (uint8_t*) &index_0, sizeof(index_0) != - TPM_SUCCESS)) { - error("\tcould not write index 0\n"); - } - TlclWriteLock(INDEX0); - if (TlclWrite(INDEX0, (uint8_t*) &index_0, sizeof(index_0)) == - TPM_SUCCESS) { - error("\tindex 0 is not locked\n"); - } - - printf("\tdone\n"); - return 0; -} - -static int test_redefine_unowned(void) -{ - uint32_t perm; - uint32_t result; - uint32_t x; - printf("Testing redefine_unowned ..."); - TlclLibInit(); - TPM_CHECK(TlclStartupIfNeeded()); - TPM_CHECK(TlclSelfTestFull()); - TPM_CHECK(TlclAssertPhysicalPresence()); - assert(!TlclIsOwned()); - - /* Ensures spaces exist. */ - TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); - TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); - - /* Redefines spaces a couple of times. */ - perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK; - TPM_CHECK(TlclDefineSpace(INDEX0, perm, 2 * sizeof(uint32_t))); - TPM_CHECK(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t))); - perm = TPM_NV_PER_PPWRITE; - TPM_CHECK(TlclDefineSpace(INDEX1, perm, 2 * sizeof(uint32_t))); - TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t))); - - // Sets the global lock. - TlclSetGlobalLock(); - - // Verifies that index0 cannot be redefined. - result = TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)); - assert(result == TPM_E_AREA_LOCKED); - - // Checks that index1 can. - TPM_CHECK(TlclDefineSpace(INDEX1, perm, 2 * sizeof(uint32_t))); - TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t))); - - // Turns off PP. - TlclLockPhysicalPresence(); - - // Verifies that neither index0 nor index1 can be redefined. - result = TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)); - assert(result == TPM_E_BAD_PRESENCE); - result = TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)); - assert(result == TPM_E_BAD_PRESENCE); - - printf("done\n"); - return 0; -} - -#define PERMPPGL (TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK) -#define PERMPP TPM_NV_PER_PPWRITE - -static int test_space_perm(void) -{ - uint32_t perm; - printf("Testing spaceperm ..."); - TlclLibInit(); - TPM_CHECK(TlclStartupIfNeeded()); - TPM_CHECK(TlclContinueSelfTest()); - TPM_CHECK(TlclAssertPhysicalPresence()); - TPM_CHECK(TlclGetPermissions(INDEX0, &perm)); - assert((perm & PERMPPGL) == PERMPPGL); - TPM_CHECK(TlclGetPermissions(INDEX1, &perm)); - assert((perm & PERMPP) == PERMPP); - printf("done\n"); - return 0; -} - -static int test_startup(void) -{ - uint32_t result; - printf("Testing startup ...\n"); - TlclLibInit(); - result = TlclStartup(); - if (result != 0) { - printf("\ttpm startup failed with 0x%x\n", result); - } - result = TlclGetFlags(NULL, NULL, NULL); - if (result != 0) { - printf("\ttpm getflags failed with 0x%x\n", result); - } - printf("\texecuting SelfTestFull\n"); - TlclSelfTestFull(); - result = TlclGetFlags(NULL, NULL, NULL); - if (result != 0) { - printf("\ttpm getflags failed with 0x%x\n", result); - } - printf("\tdone\n"); - return 0; -} - -/* Runs [op] and ensures it returns success and doesn't run longer than - * [time_limit] in milliseconds. - */ -#define TTPM_CHECK(op, time_limit) do { \ - ulong start, time; \ - uint32_t __result; \ - start = get_timer(0); \ - __result = op; \ - if (__result != TPM_SUCCESS) { \ - printf("\t" #op ": error 0x%x\n", __result); \ - return (-1); \ - } \ - time = get_timer(start); \ - printf("\t" #op ": %lu ms\n", time); \ - if (time > (ulong)time_limit) { \ - printf("\t" #op " exceeded " #time_limit " ms\n"); \ - } \ -} while (0) - - -static int test_timing(void) -{ - uint32_t x; - uint8_t in[20], out[20]; - printf("Testing timing ..."); - TlclLibInit(); - TTPM_CHECK(TlclStartupIfNeeded(), 50); - TTPM_CHECK(TlclContinueSelfTest(), 100); - TTPM_CHECK(TlclSelfTestFull(), 1000); - TTPM_CHECK(TlclAssertPhysicalPresence(), 100); - TTPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), 100); - TTPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)), 100); - TTPM_CHECK(TlclExtend(0, in, out), 200); - TTPM_CHECK(TlclSetGlobalLock(), 50); - TTPM_CHECK(TlclLockPhysicalPresence(), 100); - printf("done\n"); - return 0; -} - -#define TPM_MAX_NV_WRITES_NOOWNER 64 - -static int test_write_limit(void) -{ - printf("Testing writelimit ...\n"); - int i; - uint32_t result; - TlclLibInit(); - - TPM_CHECK(TlclStartupIfNeeded()); - TPM_CHECK(TlclSelfTestFull()); - TPM_CHECK(TlclAssertPhysicalPresence()); - TPM_CHECK(TlclForceClear()); - TPM_CHECK(TlclSetEnable()); - TPM_CHECK(TlclSetDeactivated(0)); - - for (i = 0; i < TPM_MAX_NV_WRITES_NOOWNER + 2; i++) { - printf("\twriting %d\n", i); - if ((result = TlclWrite(INDEX0, (uint8_t*)&i, sizeof(i))) != - TPM_SUCCESS) { - switch (result) { - case TPM_E_MAXNVWRITES: - assert(i >= TPM_MAX_NV_WRITES_NOOWNER); - default: - error("\tunexpected error code %d (0x%x)\n", - result, result); - } - } - } - - /* Reset write count */ - TPM_CHECK(TlclForceClear()); - TPM_CHECK(TlclSetEnable()); - TPM_CHECK(TlclSetDeactivated(0)); - - /* Try writing again. */ - TPM_CHECK(TlclWrite(INDEX0, (uint8_t*)&i, sizeof(i))); - printf("\tdone\n"); - return 0; -} - -/* u-boot command table (include/command.h) - */ - -#define VOIDTEST(XFUNC) \ - int do_test_##XFUNC(cmd_tbl_t *cmd_tbl, int flag, int argc, \ - char * const argv[]) \ - { \ - return test_##XFUNC(); \ - } \ - - /* above blank line is a part of the macro */ - -#define VOIDENT(XNAME) \ - U_BOOT_CMD_MKENT(XNAME, 0, 1, do_test_##XNAME, "", "") - -VOIDTEST(early_extend) -VOIDTEST(early_nvram) -VOIDTEST(early_nvram2) -VOIDTEST(enable) -VOIDTEST(fast_enable) -VOIDTEST(global_lock) -VOIDTEST(lock) -VOIDTEST(readonly) -VOIDTEST(redefine_unowned) -VOIDTEST(space_perm) -VOIDTEST(startup) -VOIDTEST(timing) -VOIDTEST(write_limit) -VOIDTEST(timer) - -static cmd_tbl_t cmd_cros_tpm_sub[] = { - VOIDENT(early_extend), - VOIDENT(early_nvram), - VOIDENT(early_nvram2), - VOIDENT(enable), - VOIDENT(fast_enable), - VOIDENT(global_lock), - VOIDENT(lock), - VOIDENT(readonly), - VOIDENT(redefine_unowned), - VOIDENT(space_perm), - VOIDENT(startup), - VOIDENT(timing), - VOIDENT(write_limit), - VOIDENT(timer) -}; - -/* u-boot shell commands - */ -static int do_cros_tpm_test(cmd_tbl_t * cmdtp, int flag, int argc, - char * const argv[]) -{ - cmd_tbl_t *c; - printf("argc = %d, argv = ", argc); - do { - int i = 0; - for (i = 0; i < argc; i++) - printf(" %s", argv[i]); - printf("\n------\n"); - } while(0); - argc--; - argv++; - c = find_cmd_tbl(argv[0], cmd_cros_tpm_sub, - ARRAY_SIZE(cmd_cros_tpm_sub)); - return c ? c->cmd(cmdtp, flag, argc, argv) : cmd_usage(cmdtp); -} - -U_BOOT_CMD(cros_tpm_test, 2, 1, do_cros_tpm_test, "TPM_Lite tests", - "\n\tearly_extend\n" - "\tearly_nvram\n" - "\tearly_nvram2\n" - "\tenable\n" - "\tfast_enable\n" - "\tglobal_lock\n" - "\tlock\n" - "\treadonly\n" - "\tredefine_unowned\n" - "\tspace_perm\n" - "\tstartup\n" - "\ttiming\n" - "\twrite_limit\n"); - diff --git a/include/config_cmd_all.h b/include/config_cmd_all.h index 59ff61cd99..aae6540b43 100644 --- a/include/config_cmd_all.h +++ b/include/config_cmd_all.h @@ -24,11 +24,6 @@ #define CONFIG_CMD_CACHE /* icache, dcache */ #define CONFIG_CMD_CDP /* Cisco Discovery Protocol */ #define CONFIG_CMD_CONSOLE /* coninfo */ -#define CONFIG_CMD_CROS /* Chrome OS verify boot (debug)*/ -#define CONFIG_CMD_CROS_BOOTSTUB/* Chrome OS verify boot stub */ -#define CONFIG_CMD_CROS_NORMAL_FIRMWARE - /* Chrome OS verify boot normal firmware */ -#define CONFIG_CMD_CROS_REC /* Chrome OS recovery mode */ #define CONFIG_CMD_DATE /* support for RTC, date/time...*/ #define CONFIG_CMD_DHCP /* DHCP Support */ #define CONFIG_CMD_DIAG /* Diagnostics */ |