blob: 393dc7ec1d39d4c7a7faf009934ec07528b726a6 [file] [log] [blame]
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <flashupdate/args.hpp>
#include <flashupdate/logging.hpp>
#include <flashupdate/ops.hpp>
#include <iostream>
#include <vector>
namespace flashupdate
{
void main_wrapped(int argc, char* argv[])
{
auto args = Args::argsOrHelp(argc, argv);
reinterpret_cast<uint8_t&>(logLevel) += args.verbose;
switch (args.op)
{
case Args::Op::ValidateConfig:
{
LOG(LogLevel::Notice, "empty command to validate the json config.");
}
break;
case Args::Op::HashDescriptor:
{
ops::hashDescriptor(args);
}
break;
case Args::Op::Read:
{
ops::read(args);
}
break;
case Args::Op::Write:
{
ops::write(args);
}
break;
case Args::Op::UpdateState:
{
ops::updateState(args);
}
break;
case Args::Op::UpdateVersion:
{
ops::updateVersion(args);
}
break;
case Args::Op::Info:
{
ops::info(args);
}
break;
case Args::Op::Invalidate:
{
ops::invalidate(args);
}
break;
case Args::Op::VerifyStaging:
{
ops::verifyStaging(args);
}
break;
case Args::Op::FetchVersion:
{
ops::fetchVersion(args);
}
break;
case Args::Op::CopyPartition:
{
ops::copyPartition(args);
}
break;
case Args::Op::Erase:
{
ops::erase(args);
}
break;
}
}
int main(int argc, char* argv[])
{
try
{
main_wrapped(argc, argv);
return 0;
}
// Logic Errors are treated as hard error that can be used to indicate
// that the firmware update set should be updated to CORRUPTED
catch (const std::logic_error& e)
{
LOG(LogLevel::Error, "ERROR: logic_error: {}", e.what());
return 1;
}
catch (const std::exception& e)
{
LOG(LogLevel::Error, "ERROR: {}", e.what());
return 2;
}
}
} // namespace flashupdate
int main(int argc, char* argv[])
{
return flashupdate::main(argc, argv);
}