Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 1 | // Copyright 2015 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 | |
Yi Chou | f964bab | 2020-12-10 11:50:28 +0800 | [diff] [blame] | 5 | #include <memory> |
| 6 | |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 7 | #include "tpm2-simulator/simulator.h" |
Yi Chou | f964bab | 2020-12-10 11:50:28 +0800 | [diff] [blame] | 8 | #include "tpm2-simulator/tpm_executor_tpm2_impl.h" |
Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 9 | |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame] | 10 | #include <base/at_exit.h> |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 11 | #include <base/logging.h> |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame] | 12 | #include <brillo/flag_helper.h> |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 13 | #include <brillo/syslog_logging.h> |
Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 14 | |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 15 | int main(int argc, char* argv[]) { |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame] | 16 | DEFINE_bool(sigstop, true, "raise SIGSTOP when TPM initialized"); |
| 17 | DEFINE_string(work_dir, "/mnt/stateful_partition/unencrypted/tpm2-simulator", |
| 18 | "Daemon data folder"); |
| 19 | |
| 20 | base::AtExitManager at_exit; |
| 21 | |
| 22 | brillo::FlagHelper::Init(argc, argv, "TPM2 simulator"); |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 23 | brillo::InitLog(brillo::kLogToSyslog | brillo::kLogToStderrIfTty); |
Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 24 | |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame] | 25 | if (chdir(FLAGS_work_dir.c_str()) < 0) { |
| 26 | PLOG(ERROR) << "Failed to change to current directory"; |
Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 27 | } |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 28 | |
Yi Chou | f964bab | 2020-12-10 11:50:28 +0800 | [diff] [blame] | 29 | auto tpm_executor_impl = |
| 30 | std::make_unique<tpm2_simulator::TpmExecutorTpm2Impl>(); |
| 31 | |
| 32 | tpm2_simulator::SimulatorDaemon daemon(tpm_executor_impl.get()); |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame] | 33 | daemon.set_sigstop_on_initialized(FLAGS_sigstop); |
| 34 | |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 35 | daemon.Run(); |
Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 36 | } |