summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChe-Liang Chiou <clchiou@chromium.org>2011-05-16 17:11:19 +0800
committerSimon Glass <sjg@chromium.org>2011-08-29 10:39:22 -0700
commit23a992341671a057ca1cacdad1d8e17031ec0267 (patch)
tree16c95695580abb78a7f866fb537634a0a1f67fd6 /lib
parent3e4b24987a58c62469877971e9f77a1d1e8793a9 (diff)
Refactor codes
This commits refactors the following aspects of codes: * Factor out common pattern of load and boot kernel from: + developer firmware + normal firmware + recovery firmware * Mark functions that are not used outside load_kernel_helper.c as static due to the above factorization: + boot_kernel() + load_kernel_config() + prepare_bootargs() * Remove unused first argument of reboot_to_recovery_mode() * Fix a compiler warning BUG=none TEST=CROSS_COMPILE=armv7a-cros-linux-gnueabi- ./MAKEALL chromeos Change-Id: I570b6ba1208772afbb4f26c0a74b83fa5375e29b Reviewed-on: http://gerrit.chromium.org/gerrit/920 Reviewed-by: Che-Liang Chiou <clchiou@chromium.org> Tested-by: Che-Liang Chiou <clchiou@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/chromeos/load_kernel_helper.c76
-rw-r--r--lib/chromeos/vboot_nvstorage_helper.c14
2 files changed, 63 insertions, 27 deletions
diff --git a/lib/chromeos/load_kernel_helper.c b/lib/chromeos/load_kernel_helper.c
index 63c6fe6dd62..adeed4e034e 100644
--- a/lib/chromeos/load_kernel_helper.c
+++ b/lib/chromeos/load_kernel_helper.c
@@ -14,6 +14,7 @@
#include <chromeos/kernel_shared_data.h>
#include <chromeos/load_kernel_helper.h>
#include <chromeos/os_storage.h>
+#include <chromeos/vboot_nvstorage_helper.h>
/* TODO For load fmap; remove when not used */
#include <chromeos/firmware_storage.h>
@@ -40,14 +41,6 @@ int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
#undef PREFIX
#define PREFIX "load_kernel_wrapper: "
-void prepare_bootargs(void)
-{
- /* TODO move to u-boot-config */
- run_command("setenv console console=ttyS0,115200n8", 0);
- run_command("setenv bootargs "
- "${bootargs} ${console} ${platform_extras}", 0);
-}
-
int load_kernel_wrapper_core(LoadKernelParams *params,
void *gbb_data, uint64_t gbb_size,
uint64_t boot_flags, VbNvContext *nvcxt,
@@ -239,13 +232,22 @@ EXIT:
return status;
}
+int load_kernel_wrapper(LoadKernelParams *params,
+ void *gbb_data, uint64_t gbb_size,
+ uint64_t boot_flags, VbNvContext *nvcxt,
+ uint8_t *shared_data_blob)
+{
+ return load_kernel_wrapper_core(params, gbb_data, gbb_size, boot_flags,
+ nvcxt, shared_data_blob, 0);
+}
+
/* Maximum kernel command-line size */
#define CROS_CONFIG_SIZE 4096
/* Size of the x86 zeropage table */
#define CROS_PARAMS_SIZE 4096
-int load_kernel_config(uint64_t bootloader_address)
+static int load_kernel_config(uint64_t bootloader_address)
{
char buf[80 + CROS_CONFIG_SIZE];
@@ -268,16 +270,7 @@ int load_kernel_config(uint64_t bootloader_address)
return 0;
}
-int load_kernel_wrapper(LoadKernelParams *params,
- void *gbb_data, uint64_t gbb_size,
- uint64_t boot_flags, VbNvContext *nvcxt,
- uint8_t *shared_data_blob)
-{
- return load_kernel_wrapper_core(params, gbb_data, gbb_size, boot_flags,
- nvcxt, shared_data_blob, 0);
-}
-
-void boot_kernel(LoadKernelParams *params)
+static void boot_kernel(LoadKernelParams *params)
{
char load_address[32];
char *argv[2] = { "bootm", load_address };
@@ -306,3 +299,48 @@ void boot_kernel(LoadKernelParams *params)
debug(PREFIX "error: do_bootm() returned\n");
while (1);
}
+
+static void prepare_bootargs(void)
+{
+ /* TODO move to u-boot-config */
+ run_command("setenv console console=ttyS0,115200n8", 0);
+ run_command("setenv bootargs "
+ "${bootargs} ${console} ${platform_extras}", 0);
+}
+
+int load_and_boot_kernel(void *gbb_data, uint64_t gbb_size,
+ uint64_t boot_flags)
+{
+ LoadKernelParams params;
+ VbNvContext nvcxt;
+ int status;
+
+ if (read_nvcontext(&nvcxt)) {
+ /*
+ * Even if we can't read nvcxt, we continue anyway because this
+ * is developer firmware
+ */
+ debug(PREFIX "fail to read nvcontext\n");
+ }
+
+ prepare_bootargs();
+
+ status = load_kernel_wrapper(&params, gbb_data, gbb_size,
+ boot_flags, &nvcxt, NULL);
+
+ debug(PREFIX "load_kernel_wrapper returns %d\n", status);
+
+ if (VbNvTeardown(&nvcxt) ||
+ (nvcxt.raw_changed && write_nvcontext(&nvcxt))) {
+ /*
+ * Even if we can't read nvcxt, we continue anyway because this
+ * is developer firmware
+ */
+ debug(PREFIX "fail to write nvcontext\n");
+ }
+
+ if (status == LOAD_KERNEL_SUCCESS)
+ boot_kernel(&params); /* this function never returns */
+
+ return status;
+}
diff --git a/lib/chromeos/vboot_nvstorage_helper.c b/lib/chromeos/vboot_nvstorage_helper.c
index d04ece1b800..7e326968ce9 100644
--- a/lib/chromeos/vboot_nvstorage_helper.c
+++ b/lib/chromeos/vboot_nvstorage_helper.c
@@ -190,16 +190,14 @@ int clear_recovery_request(void)
return 0;
}
-void reboot_to_recovery_mode(VbNvContext *nvcxt, uint32_t reason)
+void reboot_to_recovery_mode(uint32_t reason)
{
- VbNvContext nvcontext;
+ VbNvContext *nvcxt, nvcontext;
- if (!nvcxt) {
- nvcxt = &nvcontext;
- if (read_nvcontext(nvcxt) || VbNvSetup(nvcxt)) {
- debug(PREFIX "cannot read nvcxt\n");
- goto FAIL;
- }
+ nvcxt = &nvcontext;
+ if (read_nvcontext(nvcxt) || VbNvSetup(nvcxt)) {
+ debug(PREFIX "cannot read nvcxt\n");
+ goto FAIL;
}
debug(PREFIX "store recovery cookie in recovery field\n");