summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorChe-Liang Chiou <clchiou@chromium.org>2011-05-10 15:07:57 +0800
committerSimon Glass <sjg@chromium.org>2011-08-29 10:39:21 -0700
commitbdfc6085f392252b2b900af4ff3e04c70d39b406 (patch)
tree71b9e361eba7fb01780c847184c50be9f00f83fa /common
parent7f88d17a7e3a94c2bfde724ebdf810ae67eb8df1 (diff)
Developer firmware template and refactor common codes
This commit defines a template of developer firmware, and factors out common codes that will be used between normal and developer firmware. BUG=chromium-os:12191 TEST=manual 1. CROSS_COMPILE=armv7a-cros-linux-gnueabi- ./MAKEALL chromeos 2. Run normal and recovery boot flow on kaen Change-Id: Ib3db0aaa09a5ca964d521af6323ab4366fb7c9bd Reviewed-on: http://gerrit.chromium.org/gerrit/586 Reviewed-by: Che-Liang Chiou <clchiou@chromium.org> Tested-by: Che-Liang Chiou <clchiou@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/Makefile1
-rw-r--r--common/cmd_cros.c1
-rw-r--r--common/cmd_cros_developer_firmware.c124
-rw-r--r--common/cmd_cros_normal_firmware.c58
-rw-r--r--common/cmd_cros_rec.c11
5 files changed, 128 insertions, 67 deletions
diff --git a/common/Makefile b/common/Makefile
index e4c989c4c21..bff84c97b5f 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -76,6 +76,7 @@ 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_TPM) += cmd_vboot.o
diff --git a/common/cmd_cros.c b/common/cmd_cros.c
index 6deab3171b5..71bcb7de78d 100644
--- a/common/cmd_cros.c
+++ b/common/cmd_cros.c
@@ -19,6 +19,7 @@
#include <chromeos/gbb_bmpblk.h>
#include <chromeos/gpio.h>
#include <chromeos/load_firmware_helper.h>
+#include <chromeos/load_kernel_helper.h>
#include <chromeos/vboot_nvstorage_helper.h>
#include <chromeos/os_storage.h>
diff --git a/common/cmd_cros_developer_firmware.c b/common/cmd_cros_developer_firmware.c
new file mode 100644
index 00000000000..3d044905a85
--- /dev/null
+++ b/common/cmd_cros_developer_firmware.c
@@ -0,0 +1,124 @@
+/*
+ * 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/firmware_storage.h>
+#include <chromeos/gbb_bmpblk.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>
+
+#define PREFIX "cros_developer_firmware: "
+
+int do_cros_normal_firmware(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[]);
+
+static void beep(void)
+{
+ /* TODO: implement beep */
+ debug(PREFIX "beep\n");
+}
+
+static int is_ctrlu(int c)
+{
+ return 0;
+}
+
+static int is_ctrld(int c)
+{
+ return 0;
+}
+
+static int is_escape(int c)
+{
+ return 0;
+}
+
+static int is_space(int c)
+{
+ return 0;
+}
+
+static int is_enter(int c)
+{
+ 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;
+ ulong start = 0, time = 0;
+ int c, is_after_20_seconds = 0;
+
+ 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?
+ */
+ debug(PREFIX "cannot load gbb\n");
+ while (1);
+ }
+
+ /* we don't care whether close operation fails */
+ file.close(file.context);
+
+ if (display_screen_in_bmpblk(gbb_data, SCREEN_DEVELOPER_MODE)) {
+ debug(PREFIX "cannot display stuff on LCD screen\n");
+ }
+
+ start = get_timer(0);
+ while (1) {
+ time = get_timer(start);
+
+ /* 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;
+ }
+
+ /* Fall back to normal firmware when time > 30 seconds */
+ if (time > 30 * CONFIG_SYS_HZ)
+ break;
+
+ c = getc();
+ debug(PREFIX "getc() == 0x%x\n", c);
+
+ if (is_ctrlu(c)) {
+ /* TODO: load and boot kernel from USB or SD card */
+ }
+
+ /* Fall back to normal firmware when user pressed Ctrl-D */
+ if (is_ctrld(c))
+ break;
+
+ if (is_space(c) || is_enter(c) || is_escape(c))
+ reboot_to_recovery_mode(NULL,
+ VBNV_RECOVERY_RW_DEV_SCREEN);
+
+ udelay(100);
+ }
+
+ return do_cros_normal_firmware(NULL, 0, 0, NULL);
+}
+
+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
index eb51aedf2ad..392faeecffc 100644
--- a/common/cmd_cros_normal_firmware.c
+++ b/common/cmd_cros_normal_firmware.c
@@ -18,6 +18,7 @@
#include <chromeos/firmware_storage.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>
@@ -29,12 +30,6 @@
#define PREFIX "cros_normal_firmware: "
-/* defined in common/cmd_source.c */
-int source(ulong addr, const char *fit_uname);
-
-/* defined in common/cmd_bootm.c */
-int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
-
#define DEVICE_TYPE "mmc"
#define DEVICE_NAME "mmcblk" DEVICE_NUMBER_STRING "p"
#define DEVICE_NUMBER_STRING "0"
@@ -67,57 +62,6 @@ int initialize_drive(void)
return 0;
}
-/* This function should never return */
-static void reboot_to_recovery_mode(VbNvContext *nvcxt, uint32_t reason)
-{
- debug(PREFIX "store recovery cookie in recovery field\n");
- if (VbNvSet(nvcxt, VBNV_RECOVERY_REQUEST, reason) ||
- VbNvTeardown(nvcxt) ||
- (nvcxt->raw_changed && write_nvcontext(nvcxt))) {
- /* FIXME: bring up a sad face? */
- debug(PREFIX "error: cannot write recovery cookie");
- printf("Please reset and press recovery button when reboot.\n");
- while (1);
- }
-
- debug(PREFIX "reboot to recovery mode\n");
- reset_cpu(0);
-
- debug(PREFIX "error: reset_cpu() returned\n");
- while (1);
-}
-
-/* This function should never return */
-void boot_kernel(LoadKernelParams *params)
-{
- char load_address[32];
- char *argv[2] = { "bootm", load_address };
-
- debug(PREFIX "boot_kernel\n");
- debug(PREFIX "kernel_buffer: 0x%p\n",
- params->kernel_buffer);
- debug(PREFIX "bootloader_address: 0x%08x\n",
- (int) params->bootloader_address);
-
- if (load_kernel_config(params->bootloader_address)) {
- debug(PREFIX "error: load kernel config failed\n");
- return;
- }
-
- /*
- * FIXME: So far bootloader in kernel partition isn't really a
- * bootloader; instead, it is merely a u-boot scripts that sets kernel
- * parameters. And therefore we still have to boot kernel to here
- * by calling do_bootm.
- */
- sprintf(load_address, "0x%p", params->kernel_buffer);
- debug(PREFIX "run command: %s %s\n", argv[0], argv[1]);
- do_bootm(NULL, 0, sizeof(argv)/sizeof(*argv), argv);
-
- debug(PREFIX "error: do_bootm() returned\n");
- while (1);
-}
-
int do_cros_normal_firmware(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
diff --git a/common/cmd_cros_rec.c b/common/cmd_cros_rec.c
index 0da55d3c77a..f05819491d3 100644
--- a/common/cmd_cros_rec.c
+++ b/common/cmd_cros_rec.c
@@ -19,6 +19,7 @@
#include <usb.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>
@@ -93,14 +94,6 @@ static int write_log(void)
return 0;
}
-static uint32_t get_cur_stack_addr(void)
-{
- uint32_t local_var;
- uint32_t addr = (uint32_t)&local_var;
-
- return addr;
-}
-
/*
* Initializes the memory region that needs to be cleared.
*/
@@ -203,8 +196,6 @@ static int test_clear_mem_regions(void)
*/
static void clear_ram_not_in_use(void)
{
- uint32_t stack_top = get_cur_stack_addr();
-
init_mem_region(0, PHYS_SDRAM_1_SIZE);
/* Excludes the firmware text + data + bss regions. */