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 19af69625fSPatrick Venture #include "bt.hpp" 20af69625fSPatrick Venture #include "interface.hpp" 21af69625fSPatrick Venture #include "lpc.hpp" 22af69625fSPatrick Venture 23*00887597SPatrick Venture #include <algorithm> 24af69625fSPatrick Venture #include <memory> 25af69625fSPatrick Venture 26*00887597SPatrick Venture int updaterMain(BlobInterface* blob, const std::string& interface, 27*00887597SPatrick Venture const std::string& imagePath, const std::string& signaturePath) 28bf58cd64SPatrick Venture { 29af69625fSPatrick Venture std::unique_ptr<DataInterface> handler; 30af69625fSPatrick Venture 31af69625fSPatrick Venture /* Input has already been validated in this case. */ 32af69625fSPatrick Venture if (interface == "ipmibt") 33af69625fSPatrick Venture { 34*00887597SPatrick Venture handler = std::make_unique<BtDataHandler>(blob); 35af69625fSPatrick Venture } 36af69625fSPatrick Venture else if (interface == "ipmilpc") 37af69625fSPatrick Venture { 38*00887597SPatrick Venture handler = std::make_unique<LpcDataHandler>(blob); 39af69625fSPatrick Venture } 40af69625fSPatrick Venture 41af69625fSPatrick Venture if (!handler) 42af69625fSPatrick Venture { 43af69625fSPatrick Venture /* TODO(venture): use a custom exception. */ 44af69625fSPatrick Venture std::fprintf(stderr, "Interface %s is unavailable\n", 45af69625fSPatrick Venture interface.c_str()); 46af69625fSPatrick Venture return -1; 47af69625fSPatrick Venture } 48af69625fSPatrick Venture 49af69625fSPatrick Venture /* TODO(venture): Add optional parameter to specify the flash type, default 50af69625fSPatrick Venture * to legacy for now. 51af69625fSPatrick Venture */ 52*00887597SPatrick Venture std::string goalFirmware = "/flash/image"; 53*00887597SPatrick Venture 54*00887597SPatrick Venture std::vector<std::string> blobs = blob->getBlobList(); 55*00887597SPatrick Venture 56*00887597SPatrick Venture auto blobInst = std::find(blobs.begin(), blobs.end(), goalFirmware); 57*00887597SPatrick Venture if (blobInst == blobs.end()) 58*00887597SPatrick Venture { 59*00887597SPatrick Venture std::fprintf(stderr, "firmware goal not found!\n"); 60*00887597SPatrick Venture return -1; /* throw custom exception. */ 61*00887597SPatrick Venture } 62af69625fSPatrick Venture 63af69625fSPatrick Venture /* Get list of blob_ids, check for /flash/image, or /flash/tarball. 64af69625fSPatrick Venture * TODO(venture) the mechanism doesn't care, but the caller of burn_my_bmc 65af69625fSPatrick Venture * will have in mind which they're sending and we need to verify it's 66af69625fSPatrick Venture * available and use it. 67af69625fSPatrick Venture */ 68af69625fSPatrick Venture 69af69625fSPatrick Venture /* Call stat on /flash/image (or /flash/tarball) and check if data interface 70*00887597SPatrick Venture * is supported. 71*00887597SPatrick Venture */ 72af69625fSPatrick Venture 73bf58cd64SPatrick Venture return 0; 74bf58cd64SPatrick Venture } 75