1 /*
2  * Copyright 2018 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "updater.hpp"
18 
19 #include "bt.hpp"
20 #include "interface.hpp"
21 #include "lpc.hpp"
22 
23 #include <memory>
24 
25 int updaterMain(const std::string& interface, const std::string& imagePath,
26                 const std::string& signaturePath)
27 {
28     std::unique_ptr<DataInterface> handler;
29 
30     /* Input has already been validated in this case. */
31     if (interface == "ipmibt")
32     {
33         handler = std::make_unique<BtDataHandler>();
34     }
35     else if (interface == "ipmilpc")
36     {
37         handler = std::make_unique<LpcDataHandler>();
38     }
39 
40     if (!handler)
41     {
42         /* TODO(venture): use a custom exception. */
43         std::fprintf(stderr, "Interface %s is unavailable\n",
44                      interface.c_str());
45         return -1;
46     }
47 
48     /* TODO(venture): Add optional parameter to specify the flash type, default
49      * to legacy for now.
50      */
51     std::string goalfirmware = "/flash/image";
52 
53     /* Get list of blob_ids, check for /flash/image, or /flash/tarball.
54      * TODO(venture) the mechanism doesn't care, but the caller of burn_my_bmc
55      * will have in mind which they're sending and we need to verify it's
56      * available and use it.
57      */
58 
59     /* Call stat on /flash/image (or /flash/tarball) and check if data interface
60      * is supported. */
61 
62     return 0;
63 }
64