Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Unified Diff: bootloader_type.cc

Issue 3530001: first cut: establishes base helper classes and main (Closed) Base URL: http://git.chromium.org/git/cros_boot_mode.git
Patch Set: truncation is bad, m'kay. . . Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bootloader_type.h ('k') | bootloader_type_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bootloader_type.cc
diff --git a/bootloader_type.cc b/bootloader_type.cc
new file mode 100644
index 0000000000000000000000000000000000000000..41a5fd8eafb624ee9c943270d34db306750677c2
--- /dev/null
+++ b/bootloader_type.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2010 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.
+//
+// BootloaderType implementation
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <string>
+
+#include "bootloader_type.h"
+
+namespace cros_boot_mode {
+
+const char *BootloaderType::kBootloaderTypeText[] = {
+ "chromeos", // cros_fw (any platform)
+ "efi", // cros_efi
+ "legacy", // cros_legacy
+ "debug", // cros_debug (cros_fw with developer override)
+};
+const size_t BootloaderType::kBootloaderTypeCount =
+ sizeof(kBootloaderTypeText) / sizeof(*kBootloaderTypeText);
+// These values are expected to be found in the kernel commandline with space
+// or '\0' word boundaries. The ordering of this array must correspond to
+// the array above and the defined enum.
+const char *BootloaderType::kSupportedBootloaders[] = {
+ "cros_secure",
+ "cros_efi",
+ "cros_legacy",
+ "cros_debug",
+};
+
+const int BootloaderType::kMaxKernelCmdlineSize = 4096; // one page.
+
+BootloaderType::BootloaderType() { }
+BootloaderType::~BootloaderType() { }
+
+// This function looks for given argument space or nul delimited in
+// a /proc/cmdline style char array. See bootloader_type.h for details.
+int BootloaderType::Process(const char *contents, size_t length) {
+ if (!length || !contents)
+ return kUnsupported;
+
+ static const char kDelimiter = ' ';
+ static const char kTerminal = '\0';
+ for (unsigned i = 0; i < kBootloaderTypeCount; ++i) {
+ const char *candidate = kSupportedBootloaders[i];
+ const char *start = strstr(contents, candidate);
+ while (start) {
+ const char *end = start + strlen(candidate);
+ if ((*end == kTerminal || *end == kDelimiter) &&
+ (start == contents || *(start - 1) == kDelimiter))
+ return i;
+ start = strstr(end, candidate);
+ }
+ }
+ return kUnsupported;
+}
+
+} // namespace cros_boot_mode
« no previous file with comments | « bootloader_type.h ('k') | bootloader_type_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698