OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // BootloaderType implementation |
| 6 |
| 7 #include <stdio.h> |
| 8 #include <string.h> |
| 9 #include <sys/types.h> |
| 10 |
| 11 #include <string> |
| 12 |
| 13 #include "bootloader_type.h" |
| 14 |
| 15 namespace cros_boot_mode { |
| 16 |
| 17 const char *BootloaderType::kBootloaderTypeText[] = { |
| 18 "chromeos", // cros_fw (any platform) |
| 19 "efi", // cros_efi |
| 20 "legacy", // cros_legacy |
| 21 "debug", // cros_debug (cros_fw with developer override) |
| 22 }; |
| 23 const size_t BootloaderType::kBootloaderTypeCount = |
| 24 sizeof(kBootloaderTypeText) / sizeof(*kBootloaderTypeText); |
| 25 // These values are expected to be found in the kernel commandline with space |
| 26 // or '\0' word boundaries. The ordering of this array must correspond to |
| 27 // the array above and the defined enum. |
| 28 const char *BootloaderType::kSupportedBootloaders[] = { |
| 29 "cros_secure", |
| 30 "cros_efi", |
| 31 "cros_legacy", |
| 32 "cros_debug", |
| 33 }; |
| 34 |
| 35 const int BootloaderType::kMaxKernelCmdlineSize = 4096; // one page. |
| 36 |
| 37 BootloaderType::BootloaderType() { } |
| 38 BootloaderType::~BootloaderType() { } |
| 39 |
| 40 // This function looks for given argument space or nul delimited in |
| 41 // a /proc/cmdline style char array. See bootloader_type.h for details. |
| 42 int BootloaderType::Process(const char *contents, size_t length) { |
| 43 if (!length || !contents) |
| 44 return kUnsupported; |
| 45 |
| 46 static const char kDelimiter = ' '; |
| 47 static const char kTerminal = '\0'; |
| 48 for (unsigned i = 0; i < kBootloaderTypeCount; ++i) { |
| 49 const char *candidate = kSupportedBootloaders[i]; |
| 50 const char *start = strstr(contents, candidate); |
| 51 while (start) { |
| 52 const char *end = start + strlen(candidate); |
| 53 if ((*end == kTerminal || *end == kDelimiter) && |
| 54 (start == contents || *(start - 1) == kDelimiter)) |
| 55 return i; |
| 56 start = strstr(end, candidate); |
| 57 } |
| 58 } |
| 59 return kUnsupported; |
| 60 } |
| 61 |
| 62 } // namespace cros_boot_mode |
OLD | NEW |