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