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

Side by Side Diff: boot_mode.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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « boot_mode.h ('k') | boot_mode_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // Relies on underlying platform classes to determine the system state.
6 // In particular, this class orders the current active firmware,
7 // developer mode switch value, and the bootloader kernel commandline
8 // boot parameter to determine the "boot mode".
9
10 #include <sys/types.h>
11
12 #include "active_main_firmware.h"
13 #include "bootloader_type.h"
14 #include "developer_switch.h"
15
16 #include "boot_mode.h"
17
18 namespace cros_boot_mode {
19
20 const char *BootMode::kBootModeText[] = {
21 "normal",
22 "developer",
23 "normal recovery",
24 "developer recovery",
25 };
26 const size_t BootMode::kBootModeCount =
27 sizeof(kBootModeText) / sizeof(*kBootModeText);
28
29 BootMode::BootMode() :
30 mode_(kUnsupported),
31 developer_switch_(&default_developer_switch_),
32 active_main_firmware_(&default_active_main_firmware_),
33 bootloader_type_(&default_bootloader_type_) { }
34 BootMode::~BootMode() { }
35
36 void BootMode::Initialize(bool unsupported_is_developer, bool use_bootloader) {
37 if (use_bootloader) {
38 // For now, we treat the bootloader mode as priority over the
39 // firmware-supplied values. This allows for the kernel commandline to
40 // allow testing different behaviors changing only the kernel and not
41 // the switch positions or system image.
42 bootloader_type_->Initialize();
43 // TODO(wad) potentially create a standalone debug mode. TBD.
44 if (bootloader_type_->value() == BootloaderType::kDebug) {
45 mode_ = kDeveloper;
46 return;
47 }
48 if (bootloader_type_->value() != BootloaderType::kChromeOS) {
49 if (unsupported_is_developer)
50 mode_ = kDeveloper;
51 return;
52 }
53 }
54
55 // After the bootloader, the developer switch position guides the primary
56 // decision around current mode.
57 developer_switch_->Initialize();
58 switch (developer_switch_->value()) {
59 case PlatformSwitch::kEnabled:
60 mode_ = kDeveloper;
61 break;
62 case PlatformSwitch::kDisabled:
63 mode_ = kNormal;
64 break;
65 default:
66 // If we're using the bootloader, rely on it if there's no dev switch.
67 if (use_bootloader)
68 return;
69 // Otherwise, a missing dev switch can be mapped to developer.
70 if (unsupported_is_developer)
71 mode_ = kDeveloper;
72 return;
73 }
74
75 // The sub-mode of "recovery" can be determined by checking if the firmware
76 // booted via the recovery firmware.
77 active_main_firmware_->Initialize();
78 if (active_main_firmware_->value() == ActiveMainFirmware::kRecovery) {
79 if (mode_ == kNormal) {
80 mode_ = kNormalRecovery;
81 } else if (mode_ == kDeveloper) {
82 mode_ = kDeveloperRecovery;
83 }
84 }
85 return;
86 }
87
88
89 void BootMode::set_developer_switch(DeveloperSwitch *ds) {
90 if (ds)
91 developer_switch_ = ds;
92 else
93 developer_switch_ = &default_developer_switch_;
94 }
95
96 void BootMode::set_active_main_firmware(ActiveMainFirmware *amf) {
97 if (amf)
98 active_main_firmware_ = amf;
99 else
100 active_main_firmware_ = &default_active_main_firmware_;
101 }
102
103 void BootMode::set_bootloader_type(BootloaderType *bt) {
104 if (bt)
105 bootloader_type_ = bt;
106 else
107 bootloader_type_ = &default_bootloader_type_;
108 }
109
110 } // namespace cros_boot_mode
OLDNEW
« no previous file with comments | « boot_mode.h ('k') | boot_mode_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698